This project has retired. For details please refer to its Attic page.
NavigationService 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.server.impl.browser;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_ALLOWABLE_ACTIONS;
22  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_DEPTH;
23  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_FILTER;
24  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_MAX_ITEMS;
25  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_ORDER_BY;
26  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_PATH_SEGMENT;
27  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_RELATIONSHIPS;
28  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_RELATIVE_PATH_SEGMENT;
29  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_RENDITION_FILTER;
30  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_SKIP_COUNT;
31  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
32  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
33  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
34  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
35  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
36  
37  import java.math.BigInteger;
38  import java.util.List;
39  
40  import javax.servlet.http.HttpServletRequest;
41  import javax.servlet.http.HttpServletResponse;
42  
43  import org.apache.chemistry.opencmis.commons.data.ObjectData;
44  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer;
45  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
46  import org.apache.chemistry.opencmis.commons.data.ObjectList;
47  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
48  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
49  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
50  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
51  import org.apache.chemistry.opencmis.commons.impl.TypeCache;
52  import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
53  import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
54  import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
55  import org.apache.chemistry.opencmis.commons.server.CallContext;
56  import org.apache.chemistry.opencmis.commons.server.CmisService;
57  
58  /**
59   * Navigation Service operations.
60   */
61  public final class NavigationService {
62  
63      private NavigationService() {
64      }
65  
66      /**
67       * getChildren.
68       */
69      public static void getChildren(CallContext context, CmisService service, String repositoryId,
70              HttpServletRequest request, HttpServletResponse response) throws Exception {
71          // get parameters
72          String folderId = (String) context.get(CONTEXT_OBJECT_ID);
73          String filter = getStringParameter(request, PARAM_FILTER);
74          String orderBy = getStringParameter(request, PARAM_ORDER_BY);
75          Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
76          IncludeRelationships includeRelationships = getEnumParameter(request, PARAM_RELATIONSHIPS,
77                  IncludeRelationships.class);
78          String renditionFilter = getStringParameter(request, PARAM_RENDITION_FILTER);
79          Boolean includePathSegment = getBooleanParameter(request, PARAM_PATH_SEGMENT);
80          BigInteger maxItems = getBigIntegerParameter(request, PARAM_MAX_ITEMS);
81          BigInteger skipCount = getBigIntegerParameter(request, PARAM_SKIP_COUNT);
82  
83          // execute
84          ObjectInFolderList children = service.getChildren(repositoryId, folderId, filter, orderBy,
85                  includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, maxItems,
86                  skipCount, null);
87  
88          if (children == null) {
89              throw new CmisRuntimeException("Children are null!");
90          }
91  
92          TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
93          JSONObject jsonChildren = JSONConverter.convert(children, typeCache);
94  
95          response.setStatus(HttpServletResponse.SC_OK);
96          BrowserBindingUtils.writeJSON(jsonChildren, request, response);
97      }
98  
99      /**
100      * getDescendants.
101      */
102     public static void getDescendants(CallContext context, CmisService service, String repositoryId,
103             HttpServletRequest request, HttpServletResponse response) throws Exception {
104         // get parameters
105         String folderId = (String) context.get(CONTEXT_OBJECT_ID);
106         BigInteger depth = getBigIntegerParameter(request, PARAM_DEPTH);
107         String filter = getStringParameter(request, PARAM_FILTER);
108         Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
109         IncludeRelationships includeRelationships = getEnumParameter(request, PARAM_RELATIONSHIPS,
110                 IncludeRelationships.class);
111         String renditionFilter = getStringParameter(request, PARAM_RENDITION_FILTER);
112         Boolean includePathSegment = getBooleanParameter(request, PARAM_PATH_SEGMENT);
113 
114         // execute
115         List<ObjectInFolderContainer> descendants = service.getDescendants(repositoryId, folderId, depth, filter,
116                 includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null);
117 
118         if (descendants == null) {
119             throw new CmisRuntimeException("Descendants are null!");
120         }
121 
122         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
123         JSONArray jsonDescendants = new JSONArray();
124         for (ObjectInFolderContainer descendant : descendants) {
125             jsonDescendants.add(JSONConverter.convert(descendant, typeCache));
126         }
127 
128         response.setStatus(HttpServletResponse.SC_OK);
129         BrowserBindingUtils.writeJSON(jsonDescendants, request, response);
130     }
131 
132     /**
133      * getFolderTree.
134      */
135     public static void getFolderTree(CallContext context, CmisService service, String repositoryId,
136             HttpServletRequest request, HttpServletResponse response) throws Exception {
137         // get parameters
138         String folderId = (String) context.get(CONTEXT_OBJECT_ID);
139         BigInteger depth = getBigIntegerParameter(request, PARAM_DEPTH);
140         String filter = getStringParameter(request, PARAM_FILTER);
141         Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
142         IncludeRelationships includeRelationships = getEnumParameter(request, PARAM_RELATIONSHIPS,
143                 IncludeRelationships.class);
144         String renditionFilter = getStringParameter(request, PARAM_RENDITION_FILTER);
145         Boolean includePathSegment = getBooleanParameter(request, PARAM_PATH_SEGMENT);
146 
147         // execute
148         List<ObjectInFolderContainer> folderTree = service.getFolderTree(repositoryId, folderId, depth, filter,
149                 includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null);
150 
151         if (folderTree == null) {
152             throw new CmisRuntimeException("Folder Tree are null!");
153         }
154 
155         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
156         JSONArray jsonDescendants = new JSONArray();
157         for (ObjectInFolderContainer descendant : folderTree) {
158             jsonDescendants.add(JSONConverter.convert(descendant, typeCache));
159         }
160 
161         response.setStatus(HttpServletResponse.SC_OK);
162         BrowserBindingUtils.writeJSON(jsonDescendants, request, response);
163     }
164 
165     /**
166      * getFolderParent.
167      */
168     public static void getFolderParent(CallContext context, CmisService service, String repositoryId,
169             HttpServletRequest request, HttpServletResponse response) throws Exception {
170         // get parameters
171         String objectId = (String) context.get(CONTEXT_OBJECT_ID);
172         String filter = getStringParameter(request, PARAM_FILTER);
173 
174         // execute
175         ObjectData parent = service.getFolderParent(repositoryId, objectId, filter, null);
176 
177         if (parent == null) {
178             throw new CmisRuntimeException("Parent is null!");
179         }
180 
181         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
182         JSONObject jsonObject = JSONConverter.convert(parent, typeCache, false);
183 
184         response.setStatus(HttpServletResponse.SC_OK);
185         BrowserBindingUtils.writeJSON(jsonObject, request, response);
186     }
187 
188     /**
189      * getObjectParents.
190      */
191     public static void getObjectParents(CallContext context, CmisService service, String repositoryId,
192             HttpServletRequest request, HttpServletResponse response) throws Exception {
193         // get parameters
194         String objectId = (String) context.get(CONTEXT_OBJECT_ID);
195         String filter = getStringParameter(request, PARAM_FILTER);
196         Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
197         IncludeRelationships includeRelationships = getEnumParameter(request, PARAM_RELATIONSHIPS,
198                 IncludeRelationships.class);
199         String renditionFilter = getStringParameter(request, PARAM_RENDITION_FILTER);
200         Boolean includeRelativePathSegment = getBooleanParameter(request, PARAM_RELATIVE_PATH_SEGMENT);
201 
202         // execute
203         List<ObjectParentData> parents = service.getObjectParents(repositoryId, objectId, filter,
204                 includeAllowableActions, includeRelationships, renditionFilter, includeRelativePathSegment, null);
205 
206         if (parents == null) {
207             throw new CmisRuntimeException("Parents are null!");
208         }
209 
210         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
211         JSONArray jsonParents = new JSONArray();
212         for (ObjectParentData parent : parents) {
213             jsonParents.add(JSONConverter.convert(parent, typeCache));
214         }
215 
216         response.setStatus(HttpServletResponse.SC_OK);
217         BrowserBindingUtils.writeJSON(jsonParents, request, response);
218     }
219 
220     /**
221      * getCheckedOutDocs.
222      */
223     public static void getCheckedOutDocs(CallContext context, CmisService service, String repositoryId,
224             HttpServletRequest request, HttpServletResponse response) throws Exception {
225         // get parameters
226         String folderId = (String) context.get(CONTEXT_OBJECT_ID);
227         String filter = getStringParameter(request, PARAM_FILTER);
228         String orderBy = getStringParameter(request, PARAM_ORDER_BY);
229         Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
230         IncludeRelationships includeRelationships = getEnumParameter(request, PARAM_RELATIONSHIPS,
231                 IncludeRelationships.class);
232         String renditionFilter = getStringParameter(request, PARAM_RENDITION_FILTER);
233         BigInteger maxItems = getBigIntegerParameter(request, PARAM_MAX_ITEMS);
234         BigInteger skipCount = getBigIntegerParameter(request, PARAM_SKIP_COUNT);
235 
236         // execute
237         ObjectList checkedout = service.getCheckedOutDocs(repositoryId, folderId, filter, orderBy,
238                 includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, null);
239 
240         if (checkedout == null) {
241             throw new CmisRuntimeException("Checked out list is null!");
242         }
243 
244         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
245         JSONObject jsonCheckedOut = JSONConverter.convert(checkedout, typeCache, false);
246 
247         response.setStatus(HttpServletResponse.SC_OK);
248         BrowserBindingUtils.writeJSON(jsonCheckedOut, request, response);
249     }
250 }