This project has retired. For details please refer to its Attic page.
NavigationServiceImpl 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.browser;
20  
21  import java.math.BigInteger;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
26  import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpUtils;
27  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
28  import org.apache.chemistry.opencmis.commons.data.ObjectData;
29  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer;
30  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
31  import org.apache.chemistry.opencmis.commons.data.ObjectList;
32  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
33  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
34  import org.apache.chemistry.opencmis.commons.impl.Constants;
35  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
36  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
37  import org.apache.chemistry.opencmis.commons.spi.NavigationService;
38  
39  /**
40   * Navigation Service Browser Binding client.
41   */
42  public class NavigationServiceImpl extends AbstractBrowserBindingService implements NavigationService {
43  
44      /**
45       * Constructor.
46       */
47      public NavigationServiceImpl(BindingSession session) {
48          setSession(session);
49      }
50  
51      public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy,
52              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
53              Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
54          // build URL
55          UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_CHILDREN);
56          url.addParameter(Constants.PARAM_FILTER, filter);
57          url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
58          url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
59          url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
60          url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
61          url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
62          url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
63          url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
64  
65          // read and parse
66          HttpUtils.Response resp = read(url);
67          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
68  
69          return JSONConverter.convertObjectInFolderList(json);
70      }
71  
72      public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId, BigInteger depth,
73              String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
74              String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
75          // build URL
76          UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_DESCENDANTS);
77          url.addParameter(Constants.PARAM_DEPTH, depth);
78          url.addParameter(Constants.PARAM_FILTER, filter);
79          url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
80          url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
81          url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
82          url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
83  
84          // read and parse
85          HttpUtils.Response resp = read(url);
86          List<Object> json = parseArray(resp.getStream(), resp.getCharset());
87  
88          return JSONConverter.convertDescendants(json);
89      }
90  
91      public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId, BigInteger depth,
92              String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
93              String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
94          // build URL
95          UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_FOLDER_TREE);
96          url.addParameter(Constants.PARAM_DEPTH, depth);
97          url.addParameter(Constants.PARAM_FILTER, filter);
98          url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
99          url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
100         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
101         url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
102 
103         // read and parse
104         HttpUtils.Response resp = read(url);
105         List<Object> json = parseArray(resp.getStream(), resp.getCharset());
106 
107         return JSONConverter.convertDescendants(json);
108     }
109 
110     public List<ObjectParentData> getObjectParents(String repositoryId, String objectId, String filter,
111             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
112             Boolean includeRelativePathSegment, ExtensionsData extension) {
113         // build URL
114         UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_PARENTS);
115         url.addParameter(Constants.PARAM_FILTER, filter);
116         url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
117         url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
118         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
119         url.addParameter(Constants.PARAM_RELATIVE_PATH_SEGMENT, includeRelativePathSegment);
120 
121         // read and parse
122         HttpUtils.Response resp = read(url);
123         List<Object> json = parseArray(resp.getStream(), resp.getCharset());
124 
125         return JSONConverter.convertObjectParents(json);
126     }
127 
128     public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) {
129         // build URL
130         UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_PARENT);
131         url.addParameter(Constants.PARAM_FILTER, filter);
132 
133         // read and parse
134         HttpUtils.Response resp = read(url);
135         Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
136 
137         return JSONConverter.convertObject(json);
138     }
139 
140     public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy,
141             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
142             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
143         // build URL
144         UrlBuilder url = (folderId != null ? getObjectUrl(repositoryId, folderId, Constants.SELECTOR_CHECKEDOUT)
145                 : getRepositoryUrl(repositoryId, Constants.SELECTOR_CHECKEDOUT));
146         url.addParameter(Constants.PARAM_FILTER, filter);
147         url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
148         url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
149         url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
150         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
151         url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
152         url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
153 
154         // read and parse
155         HttpUtils.Response resp = read(url);
156         Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
157 
158         return JSONConverter.convertObjectList(json, false);
159     }
160 }