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.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.Response;
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.TypeCache;
37  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
38  import org.apache.chemistry.opencmis.commons.spi.NavigationService;
39  
40  /**
41   * Navigation Service Browser Binding client.
42   */
43  public class NavigationServiceImpl extends AbstractBrowserBindingService implements NavigationService {
44  
45      /**
46       * Constructor.
47       */
48      public NavigationServiceImpl(BindingSession session) {
49          setSession(session);
50      }
51  
52      @Override
53      public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy,
54              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
55              Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
56          // build URL
57          UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_CHILDREN);
58          url.addParameter(Constants.PARAM_FILTER, filter);
59          url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
60          url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
61          url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
62          url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
63          url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
64          url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
65          url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
66          url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
67          url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
68  
69          // read and parse
70          Response resp = read(url);
71          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
72  
73          TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
74  
75          return JSONConverter.convertObjectInFolderList(json, typeCache);
76      }
77  
78      @Override
79      public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId, BigInteger depth,
80              String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
81              String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
82          // build URL
83          UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_DESCENDANTS);
84          url.addParameter(Constants.PARAM_DEPTH, depth);
85          url.addParameter(Constants.PARAM_FILTER, filter);
86          url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
87          url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
88          url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
89          url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
90          url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
91          url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
92  
93          // read and parse
94          Response resp = read(url);
95          List<Object> json = parseArray(resp.getStream(), resp.getCharset());
96  
97          TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
98  
99          return JSONConverter.convertDescendants(json, typeCache);
100     }
101 
102     @Override
103     public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId, BigInteger depth,
104             String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
105             String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
106         // build URL
107         UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_FOLDER_TREE);
108         url.addParameter(Constants.PARAM_DEPTH, depth);
109         url.addParameter(Constants.PARAM_FILTER, filter);
110         url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
111         url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
112         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
113         url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
114         url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
115         url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
116 
117         // read and parse
118         Response resp = read(url);
119         List<Object> json = parseArray(resp.getStream(), resp.getCharset());
120 
121         TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
122 
123         return JSONConverter.convertDescendants(json, typeCache);
124     }
125 
126     @Override
127     public List<ObjectParentData> getObjectParents(String repositoryId, String objectId, String filter,
128             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
129             Boolean includeRelativePathSegment, ExtensionsData extension) {
130         // build URL
131         UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_PARENTS);
132         url.addParameter(Constants.PARAM_FILTER, filter);
133         url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
134         url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
135         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
136         url.addParameter(Constants.PARAM_RELATIVE_PATH_SEGMENT, includeRelativePathSegment);
137         url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
138         url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
139 
140         // read and parse
141         Response resp = read(url);
142         List<Object> json = parseArray(resp.getStream(), resp.getCharset());
143 
144         TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
145 
146         return JSONConverter.convertObjectParents(json, typeCache);
147     }
148 
149     @Override
150     public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) {
151         // build URL
152         UrlBuilder url = getObjectUrl(repositoryId, folderId, Constants.SELECTOR_PARENT);
153         url.addParameter(Constants.PARAM_FILTER, filter);
154         url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
155         url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
156 
157         // read and parse
158         Response resp = read(url);
159         Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
160 
161         TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
162 
163         return JSONConverter.convertObject(json, typeCache);
164     }
165 
166     @Override
167     public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy,
168             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
169             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
170         // build URL
171         UrlBuilder url = (folderId != null ? getObjectUrl(repositoryId, folderId, Constants.SELECTOR_CHECKEDOUT)
172                 : getRepositoryUrl(repositoryId, Constants.SELECTOR_CHECKEDOUT));
173         url.addParameter(Constants.PARAM_FILTER, filter);
174         url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
175         url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
176         url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
177         url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
178         url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
179         url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
180         url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
181         url.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
182 
183         // read and parse
184         Response resp = read(url);
185         Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
186 
187         TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
188 
189         return JSONConverter.convertObjectList(json, typeCache, false);
190     }
191 }