View Javadoc

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.WSConverter.convert;
22  
23  import java.math.BigInteger;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
28  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
29  import org.apache.chemistry.opencmis.commons.data.ObjectData;
30  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer;
31  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
32  import org.apache.chemistry.opencmis.commons.data.ObjectList;
33  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
34  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
35  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
36  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
37  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectInFolderContainerType;
38  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectParentsType;
39  import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumIncludeRelationships;
40  import org.apache.chemistry.opencmis.commons.impl.jaxb.NavigationServicePort;
41  import org.apache.chemistry.opencmis.commons.spi.NavigationService;
42  
43  /**
44   * Navigation Service Web Services client.
45   */
46  public class NavigationServiceImpl extends AbstractWebServicesService implements NavigationService {
47  
48      private final AbstractPortProvider portProvider;
49  
50      /**
51       * Constructor.
52       */
53      public NavigationServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
54          setSession(session);
55          this.portProvider = portProvider;
56      }
57  
58      @Override
59      public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy,
60              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
61              Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
62          NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId), "getChildren");
63  
64          try {
65              return convert(port.getChildren(repositoryId, folderId, filter, orderBy, includeAllowableActions,
66                      convert(EnumIncludeRelationships.class, includeRelationships), renditionFilter, includePathSegment,
67                      maxItems, skipCount, convert(extension)));
68          } catch (CmisException e) {
69              throw convertException(e);
70          } catch (Exception e) {
71              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
72          } finally {
73              portProvider.endCall(port);
74          }
75      }
76  
77      @Override
78      public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId, BigInteger depth,
79              String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
80              String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
81          NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId),
82                  "getDescendants");
83  
84          try {
85              List<CmisObjectInFolderContainerType> containerList = port.getDescendants(repositoryId, folderId, depth,
86                      filter, includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships),
87                      renditionFilter, includePathSegment, convert(extension));
88  
89              // no list?
90              if (containerList == null) {
91                  return null;
92              }
93  
94              // convert list
95              List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
96              for (CmisObjectInFolderContainerType container : containerList) {
97                  result.add(convert(container));
98              }
99  
100             return result;
101         } catch (CmisException e) {
102             throw convertException(e);
103         } catch (Exception e) {
104             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
105         } finally {
106             portProvider.endCall(port);
107         }
108     }
109 
110     @Override
111     public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) {
112         NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId),
113                 "getFolderParent");
114 
115         try {
116             return convert(port.getFolderParent(repositoryId, folderId, filter, convert(extension)));
117         } catch (CmisException e) {
118             throw convertException(e);
119         } catch (Exception e) {
120             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
121         } finally {
122             portProvider.endCall(port);
123         }
124     }
125 
126     @Override
127     public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId, BigInteger depth,
128             String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
129             String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
130         NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId),
131                 "getFolderTree");
132 
133         try {
134             List<CmisObjectInFolderContainerType> containerList = port.getFolderTree(repositoryId, folderId, depth,
135                     filter, includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships),
136                     renditionFilter, includePathSegment, convert(extension));
137 
138             // no list?
139             if (containerList == null) {
140                 return null;
141             }
142 
143             // convert list
144             List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
145             for (CmisObjectInFolderContainerType container : containerList) {
146                 result.add(convert(container));
147             }
148 
149             return result;
150         } catch (CmisException e) {
151             throw convertException(e);
152         } catch (Exception e) {
153             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
154         } finally {
155             portProvider.endCall(port);
156         }
157     }
158 
159     @Override
160     public List<ObjectParentData> getObjectParents(String repositoryId, String objectId, String filter,
161             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
162             Boolean includeRelativePathSegment, ExtensionsData extension) {
163         NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId),
164                 "getObjectParents");
165 
166         try {
167             List<CmisObjectParentsType> parentsList = port.getObjectParents(repositoryId, objectId, filter,
168                     includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships),
169                     renditionFilter, includeRelativePathSegment, convert(extension));
170 
171             // no list?
172             if (parentsList == null) {
173                 return null;
174             }
175 
176             // convert list
177             List<ObjectParentData> result = new ArrayList<ObjectParentData>();
178             for (CmisObjectParentsType parent : parentsList) {
179                 result.add(convert(parent));
180             }
181 
182             return result;
183         } catch (CmisException e) {
184             throw convertException(e);
185         } catch (Exception e) {
186             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
187         } finally {
188             portProvider.endCall(port);
189         }
190     }
191 
192     @Override
193     public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy,
194             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
195             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
196         NavigationServicePort port = portProvider.getNavigationServicePort(getCmisVersion(repositoryId),
197                 "getCheckedOutDocs");
198 
199         try {
200             return convert(port.getCheckedOutDocs(repositoryId, folderId, filter, orderBy, includeAllowableActions,
201                     convert(EnumIncludeRelationships.class, includeRelationships), renditionFilter, maxItems,
202                     skipCount, convert(extension)));
203         } catch (CmisException e) {
204             throw convertException(e);
205         } catch (Exception e) {
206             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
207         } finally {
208             portProvider.endCall(port);
209         }
210     }
211 }