1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory.server;
20
21 import org.apache.chemistry.opencmis.commons.data.Acl;
22 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
23 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
24 import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
25 import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
26 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
27 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
28 import org.apache.chemistry.opencmis.commons.server.CallContext;
29 import org.apache.chemistry.opencmis.commons.spi.Holder;
30 import org.apache.chemistry.opencmis.inmemory.storedobj.api.CmisServiceValidator;
31 import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
32 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
33 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
34
35 public class BaseServiceValidatorImpl implements CmisServiceValidator {
36
37 protected final StoreManager fStoreManager;
38
39 public BaseServiceValidatorImpl(StoreManager sm) {
40 fStoreManager = sm;
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54 protected StoredObject checkStandardParameters(String repositoryId, String objectId) {
55 if (null == repositoryId) {
56 throw new CmisInvalidArgumentException("Repository Id cannot be null.");
57 }
58
59 if (null == objectId) {
60 throw new CmisInvalidArgumentException("Object Id cannot be null.");
61 }
62
63 ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
64
65 if (objStore == null) {
66 throw new CmisObjectNotFoundException("Unknown repository id: " + repositoryId);
67 }
68
69 StoredObject so = objStore.getObjectById(objectId);
70
71 if (so == null) {
72 throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
73 }
74
75 return so;
76 }
77
78 protected StoredObject checkStandardParametersByPath(String repositoryId, String path, String user) {
79 if (null == repositoryId) {
80 throw new CmisInvalidArgumentException("Repository Id cannot be null.");
81 }
82
83 if (null == path) {
84 throw new CmisInvalidArgumentException("Path parameter cannot be null.");
85 }
86
87 ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
88
89 if (objStore == null) {
90 throw new CmisObjectNotFoundException("Unknown repository id: " + repositoryId);
91 }
92
93 StoredObject so = objStore.getObjectByPath(path, user);
94
95 if (so == null) {
96 throw new CmisObjectNotFoundException("Unknown path: " + path);
97 }
98
99 return so;
100 }
101
102 protected StoredObject checkStandardParametersAllowNull(String repositoryId, String objectId) {
103
104 StoredObject so = null;
105
106 if (null == repositoryId) {
107 throw new CmisInvalidArgumentException("Repository Id cannot be null.");
108 }
109
110 if (null != objectId) {
111
112 ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
113
114 if (objStore == null) {
115 throw new CmisObjectNotFoundException("Unknown repository id: " + repositoryId);
116 }
117
118 so = objStore.getObjectById(objectId);
119
120 if (so == null) {
121 throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
122 }
123 }
124
125 return so;
126 }
127
128 protected StoredObject checkExistingObjectId(ObjectStore objStore, String objectId) {
129
130 if (null == objectId) {
131 throw new CmisInvalidArgumentException("Object Id cannot be null.");
132 }
133
134 StoredObject so = objStore.getObjectById(objectId);
135
136 if (so == null) {
137 throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
138 }
139
140 return so;
141 }
142
143 protected void checkRepositoryId(String repositoryId) {
144 if (null == repositoryId) {
145 throw new CmisInvalidArgumentException("Repository Id cannot be null.");
146 }
147
148 ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
149
150 if (objStore == null) {
151 throw new CmisInvalidArgumentException("Unknown repository id: " + repositoryId);
152 }
153 }
154
155 protected StoredObject[] checkParams(String repositoryId, String objectId1, String objectId2) {
156 StoredObject[] so = new StoredObject[2];
157 so[0] = checkStandardParameters(repositoryId, objectId1);
158 ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
159 so[1] = checkExistingObjectId(objectStore, objectId2);
160 return so;
161 }
162
163 public void getRepositoryInfos(CallContext context, ExtensionsData extension) {
164 }
165
166 public void getRepositoryInfo(CallContext context, String repositoryId, ExtensionsData extension) {
167
168 checkRepositoryId(repositoryId);
169 }
170
171 public void getTypeChildren(CallContext context, String repositoryId, String typeId,
172 ExtensionsData extension) {
173
174 checkRepositoryId(repositoryId);
175 }
176
177 public void getTypeDescendants(CallContext context, String repositoryId, String typeId,
178 ExtensionsData extension) {
179
180 checkRepositoryId(repositoryId);
181 }
182
183 public void getTypeDefinition(CallContext context, String repositoryId, String typeId,
184 ExtensionsData extension) {
185
186 checkRepositoryId(repositoryId);
187 }
188
189 public StoredObject getChildren(CallContext context, String repositoryId, String folderId, ExtensionsData extension) {
190
191 return checkStandardParameters(repositoryId, folderId);
192 }
193
194 public StoredObject getDescendants(CallContext context, String repositoryId, String folderId,
195 ExtensionsData extension) {
196
197 return checkStandardParameters(repositoryId, folderId);
198 }
199
200 public StoredObject getFolderTree(CallContext context, String repositoryId, String folderId,
201 ExtensionsData extension) {
202
203 return checkStandardParameters(repositoryId, folderId);
204 }
205
206 public StoredObject getObjectParents(CallContext context, String repositoryId, String objectId,
207 ExtensionsData extension) {
208
209 return checkStandardParameters(repositoryId, objectId);
210 }
211
212 public StoredObject getFolderParent(CallContext context, String repositoryId, String folderId,
213 ExtensionsData extension) {
214
215 return checkStandardParameters(repositoryId, folderId);
216 }
217
218 public StoredObject getCheckedOutDocs(CallContext context, String repositoryId, String folderId,
219 ExtensionsData extension) {
220
221 if (null != folderId) {
222 return checkStandardParameters(repositoryId, folderId);
223 } else {
224 checkRepositoryId(repositoryId);
225 return null;
226 }
227
228 }
229
230 public StoredObject createDocument(CallContext context, String repositoryId, String folderId,
231 ExtensionsData extension) {
232 return checkStandardParametersAllowNull(repositoryId, folderId);
233 }
234
235 public StoredObject createDocumentFromSource(CallContext context, String repositoryId, String sourceId,
236 String folderId, ExtensionsData extension) {
237
238 return checkStandardParametersAllowNull(repositoryId, sourceId);
239 }
240
241 public StoredObject createFolder(CallContext context, String repositoryId, String folderId, ExtensionsData extension) {
242 return checkStandardParameters(repositoryId, folderId);
243 }
244
245 public StoredObject[] createRelationship(CallContext context, String repositoryId, String sourceId,
246 String targetId, ExtensionsData extension) {
247 checkRepositoryId(repositoryId);
248 checkStandardParametersAllowNull(repositoryId, null);
249 return checkParams(repositoryId, sourceId, targetId);
250 }
251
252 public StoredObject createPolicy(CallContext context, String repositoryId, String folderId, ExtensionsData extension) {
253 return checkStandardParameters(repositoryId, folderId);
254 }
255
256 public StoredObject getAllowableActions(CallContext context, String repositoryId, String objectId,
257 ExtensionsData extension) {
258
259 return checkStandardParameters(repositoryId, objectId);
260 }
261
262 public StoredObject getObject(CallContext context, String repositoryId, String objectId, ExtensionsData extension) {
263
264 String principalId = context.getUsername();
265 StoredObject so = checkStandardParameters(repositoryId, objectId);
266 return so;
267 }
268
269 public StoredObject getProperties(CallContext context, String repositoryId, String objectId,
270 ExtensionsData extension) {
271
272 return checkStandardParameters(repositoryId, objectId);
273 }
274
275 public StoredObject getRenditions(CallContext context, String repositoryId, String objectId,
276 ExtensionsData extension) {
277
278 return checkStandardParameters(repositoryId, objectId);
279 }
280
281 public StoredObject getObjectByPath(CallContext context, String repositoryId, String path, ExtensionsData extension) {
282
283 return checkStandardParametersByPath(repositoryId, path, context.getUsername());
284 }
285
286 public StoredObject getContentStream(CallContext context, String repositoryId, String objectId, String streamId,
287 ExtensionsData extension) {
288
289 return checkStandardParameters(repositoryId, objectId);
290 }
291
292 public StoredObject updateProperties(CallContext context, String repositoryId, Holder<String> objectId,
293 ExtensionsData extension) {
294
295 return checkStandardParameters(repositoryId, objectId.getValue());
296 }
297
298 public StoredObject[] moveObject(CallContext context, String repositoryId, Holder<String> objectId,
299 String targetFolderId, String sourceFolderId, ExtensionsData extension) {
300
301 StoredObject[] res = new StoredObject[3];
302 res [0] = checkStandardParameters(repositoryId, objectId.getValue());
303 res[1] = checkExistingObjectId(fStoreManager.getObjectStore(repositoryId), sourceFolderId);
304 res[2] = checkExistingObjectId(fStoreManager.getObjectStore(repositoryId), targetFolderId);
305 return res;
306 }
307
308 public StoredObject deleteObject(CallContext context, String repositoryId, String objectId, Boolean allVersions,
309 ExtensionsData extension) {
310
311 return checkStandardParameters(repositoryId, objectId);
312 }
313
314 public StoredObject deleteTree(CallContext context, String repositoryId, String folderId, Boolean allVersions,
315 UnfileObject unfileObjects, ExtensionsData extension) {
316 return checkStandardParameters(repositoryId, folderId);
317 }
318
319 public StoredObject setContentStream(CallContext context, String repositoryId, Holder<String> objectId,
320 Boolean overwriteFlag, ExtensionsData extension) {
321
322 return checkStandardParameters(repositoryId, objectId.getValue());
323 }
324
325 public StoredObject deleteContentStream(CallContext context, String repositoryId, Holder<String> objectId,
326 ExtensionsData extension) {
327 return checkStandardParameters(repositoryId, objectId.getValue());
328 }
329
330 public StoredObject checkOut(CallContext context, String repositoryId, Holder<String> objectId,
331 ExtensionsData extension, Holder<Boolean> contentCopied) {
332
333 return checkStandardParameters(repositoryId, objectId.getValue());
334 }
335
336 public StoredObject cancelCheckOut(CallContext context, String repositoryId, String objectId,
337 ExtensionsData extension) {
338
339 return checkStandardParameters(repositoryId, objectId);
340 }
341
342 public StoredObject checkIn(CallContext context, String repositoryId, Holder<String> objectId,
343 Acl addAces, Acl removeAces, ExtensionsData extension) {
344 return checkStandardParameters(repositoryId, objectId.getValue());
345 }
346
347 public StoredObject getObjectOfLatestVersion(CallContext context, String repositoryId, String objectId,
348 String versionSeriesId, ExtensionsData extension) {
349
350 return checkStandardParameters(repositoryId, versionSeriesId == null ? objectId : versionSeriesId);
351 }
352
353 public StoredObject getPropertiesOfLatestVersion(CallContext context, String repositoryId, String objectId,
354 String versionSeriesId, ExtensionsData extension) {
355
356 return checkStandardParameters(repositoryId, versionSeriesId == null ? objectId : versionSeriesId);
357 }
358
359 public StoredObject getAllVersions(CallContext context, String repositoryId, String objectId,
360 String versionSeriesId, ExtensionsData extension) {
361
362 return checkStandardParameters(repositoryId, versionSeriesId == null ? objectId : versionSeriesId);
363 }
364
365 public void query(CallContext context, String repositoryId, ExtensionsData extension) {
366
367 checkRepositoryId(repositoryId);
368 }
369
370 public void getContentChanges(CallContext context, String repositoryId, ExtensionsData extension) {
371
372 checkRepositoryId(repositoryId);
373 }
374
375 public StoredObject[] addObjectToFolder(CallContext context, String repositoryId, String objectId, String folderId,
376 Boolean allVersions, ExtensionsData extension) {
377
378 return checkParams(repositoryId, objectId, folderId);
379 }
380
381 public StoredObject[] removeObjectFromFolder(CallContext context, String repositoryId, String objectId,
382 String folderId, ExtensionsData extension) {
383
384 return checkParams(repositoryId, objectId, folderId);
385 }
386
387 public StoredObject getObjectRelationships(CallContext context, String repositoryId, String objectId,
388 RelationshipDirection relationshipDirection, String typeId, ExtensionsData extension) {
389
390 return checkStandardParameters(repositoryId, objectId);
391 }
392
393 public StoredObject getAcl(CallContext context, String repositoryId, String objectId, ExtensionsData extension) {
394
395 return checkStandardParameters(repositoryId, objectId);
396 }
397
398 public StoredObject applyAcl(CallContext context, String repositoryId, String objectId,
399 AclPropagation aclPropagation, ExtensionsData extension) {
400
401 return checkStandardParameters(repositoryId, objectId);
402 }
403
404 public StoredObject[] applyPolicy(CallContext context, String repositoryId, String policyId, String objectId,
405 ExtensionsData extension) {
406
407 return checkParams(repositoryId, policyId, objectId);
408 }
409
410 public StoredObject[] removePolicy(CallContext context, String repositoryId, String policyId, String objectId,
411 ExtensionsData extension) {
412
413 return checkParams(repositoryId, policyId, objectId);
414 }
415
416 public StoredObject getAppliedPolicies(CallContext context, String repositoryId, String objectId,
417 ExtensionsData extension) {
418
419 return checkStandardParameters(repositoryId, objectId);
420 }
421
422 public StoredObject create(CallContext context, String repositoryId, String folderId, ExtensionsData extension) {
423
424 return checkStandardParameters(repositoryId, folderId);
425 }
426
427 public StoredObject deleteObjectOrCancelCheckOut(CallContext context, String repositoryId, String objectId,
428 ExtensionsData extension) {
429
430 return checkStandardParameters(repositoryId, objectId);
431 }
432
433 public StoredObject applyAcl(CallContext context, String repositoryId, String objectId) {
434
435 return checkStandardParameters(repositoryId, objectId);
436 }
437 }