This project has retired. For details please refer to its Attic page.
RepositoryServiceImpl xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.bindings.spi.webservices;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
22  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertTypeContainerList;
23  
24  import java.math.BigInteger;
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
29  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
30  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
31  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
32  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
33  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
34  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
36  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryEntryType;
37  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
38  import org.apache.chemistry.opencmis.commons.impl.jaxb.RepositoryServicePort;
39  import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
40  
41  /**
42   * Repository Service Web Services client.
43   */
44  public class RepositoryServiceImpl extends AbstractWebServicesService implements RepositoryService {
45  
46      private final AbstractPortProvider portProvider;
47  
48      /**
49       * Constructor.
50       */
51      public RepositoryServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
52          setSession(session);
53          this.portProvider = portProvider;
54      }
55  
56      public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
57          RepositoryServicePort port = portProvider.getRepositoryServicePort();
58  
59          List<RepositoryInfo> infos = null;
60          try {
61              // get the list of repositories
62              List<CmisRepositoryEntryType> entries = port.getRepositories(convert(extension));
63  
64              if (entries != null) {
65                  infos = new ArrayList<RepositoryInfo>();
66  
67                  // iterate through the list and fetch repository infos
68                  for (CmisRepositoryEntryType entry : entries) {
69                      CmisRepositoryInfoType info = port.getRepositoryInfo(entry.getRepositoryId(), null);
70                      infos.add(convert(info));
71                  }
72              }
73          } catch (CmisException e) {
74              throw convertException(e);
75          } catch (Exception e) {
76              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
77          } finally {
78              portProvider.endCall(port);
79          }
80  
81          return infos;
82      }
83  
84      public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension) {
85          RepositoryServicePort port = portProvider.getRepositoryServicePort();
86  
87          try {
88              return convert(port.getRepositoryInfo(repositoryId, convert(extension)));
89          } catch (CmisException e) {
90              throw convertException(e);
91          } catch (Exception e) {
92              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
93          } finally {
94              portProvider.endCall(port);
95          }
96      }
97  
98      public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension) {
99          RepositoryServicePort port = portProvider.getRepositoryServicePort();
100 
101         try {
102             return convert(port.getTypeDefinition(repositoryId, typeId, convert(extension)));
103         } catch (CmisException e) {
104             throw convertException(e);
105         } catch (Exception e) {
106             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
107         } finally {
108             portProvider.endCall(port);
109         }
110     }
111 
112     public TypeDefinitionList getTypeChildren(String repositoryId, String typeId, Boolean includePropertyDefinitions,
113             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
114         RepositoryServicePort port = portProvider.getRepositoryServicePort();
115 
116         try {
117             return convert(port.getTypeChildren(repositoryId, typeId, includePropertyDefinitions, maxItems, skipCount,
118                     convert(extension)));
119         } catch (CmisException e) {
120             throw convertException(e);
121         } catch (Exception e) {
122             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
123         } finally {
124             portProvider.endCall(port);
125         }
126     }
127 
128     public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth,
129             Boolean includePropertyDefinitions, ExtensionsData extension) {
130         RepositoryServicePort port = portProvider.getRepositoryServicePort();
131 
132         try {
133             return convertTypeContainerList(port.getTypeDescendants(repositoryId, typeId, depth,
134                     includePropertyDefinitions, convert(extension)));
135         } catch (CmisException e) {
136             throw convertException(e);
137         } catch (Exception e) {
138             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
139         } finally {
140             portProvider.endCall(port);
141         }
142     }
143 }