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