This project has retired. For details please refer to its
Attic page.
StoreManagerImpl xref
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.storedobj.impl;
20
21 import java.math.BigInteger;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import org.apache.chemistry.opencmis.commons.data.ObjectList;
33 import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
34 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
35 import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
36 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
37 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
38 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
39 import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;
40 import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;
41 import org.apache.chemistry.opencmis.commons.enums.CapabilityContentStreamUpdates;
42 import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
43 import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
44 import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions;
45 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
46 import org.apache.chemistry.opencmis.commons.enums.SupportedPermissions;
47 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
48 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractTypeDefinition;
49 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AclCapabilitiesDataImpl;
50 import org.apache.chemistry.opencmis.commons.impl.dataobjects.BindingsObjectFactoryImpl;
51 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PermissionDefinitionDataImpl;
52 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PermissionMappingDataImpl;
53 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl;
54 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoImpl;
55 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
56 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
57 import org.apache.chemistry.opencmis.inmemory.RepositoryInfoCreator;
58 import org.apache.chemistry.opencmis.inmemory.TypeCreator;
59 import org.apache.chemistry.opencmis.inmemory.TypeManagerImpl;
60 import org.apache.chemistry.opencmis.inmemory.query.InMemoryQueryProcessor;
61 import org.apache.chemistry.opencmis.inmemory.storedobj.api.CmisServiceValidator;
62 import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
63 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
64 import org.apache.chemistry.opencmis.inmemory.storedobj.api.TypeManagerCreatable;
65 import org.apache.chemistry.opencmis.server.support.TypeManager;
66 import org.apache.commons.logging.Log;
67 import org.apache.commons.logging.LogFactory;
68
69
70
71
72
73
74 public class StoreManagerImpl implements StoreManager {
75
76 private static final Log LOG = LogFactory.getLog(StoreManagerImpl.class);
77
78 private static final String CMIS_READ = "cmis:read";
79 private static final String CMIS_WRITE = "cmis:write";
80 private static final String CMIS_ALL = "cmis:all";
81
82 protected final BindingsObjectFactory fObjectFactory;
83 protected RepositoryInfo fRepositoryInfo;
84 protected CmisServiceValidator validator;
85
86 private static final String OPENCMIS_VERSION;
87 private static final String OPENCMIS_SERVER;
88
89 static {
90 Package p = Package.getPackage("org.apache.chemistry.opencmis.inmemory");
91 if (p == null) {
92 OPENCMIS_VERSION = "?";
93 OPENCMIS_SERVER = "Apache-Chemistry-OpenCMIS-InMemory";
94 } else {
95 String ver = p.getImplementationVersion();
96 OPENCMIS_VERSION = (null == ver ? "?" : ver);
97 OPENCMIS_SERVER = "Apache-Chemistry-OpenCMIS-InMemory/" + OPENCMIS_VERSION;
98 }
99 }
100
101
102
103
104 private final Map<String, TypeManagerImpl> fMapRepositoryToTypeManager = new HashMap<String, TypeManagerImpl>();
105
106
107
108
109 private final Map<String, ObjectStore> fMapRepositoryToObjectStore = new HashMap<String, ObjectStore>();
110
111 public ObjectStoreImpl getStore(String repositoryId) {
112 return (ObjectStoreImpl) fMapRepositoryToObjectStore.get(repositoryId);
113 }
114
115 public StoreManagerImpl() {
116 fObjectFactory = new BindingsObjectFactoryImpl();
117 }
118
119 public List<String> getAllRepositoryIds() {
120 Set<String> repIds = fMapRepositoryToObjectStore.keySet();
121 List<String> result = new ArrayList<String>();
122 result.addAll(repIds);
123 return result;
124 }
125
126 public void initRepository(String repositoryId) {
127 fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));
128 fMapRepositoryToTypeManager.put(repositoryId, new TypeManagerImpl());
129 }
130
131 public void createAndInitRepository(String repositoryId, String typeCreatorClassName) {
132 if (fMapRepositoryToObjectStore.containsKey(repositoryId)
133 || fMapRepositoryToTypeManager.containsKey(repositoryId)) {
134 throw new RuntimeException("Cannot add repository, repository " + repositoryId + " already exists.");
135 }
136
137 fMapRepositoryToObjectStore.put(repositoryId, new ObjectStoreImpl(repositoryId));
138 fMapRepositoryToTypeManager.put(repositoryId, new TypeManagerImpl());
139
140
141 initTypeSystem(repositoryId, typeCreatorClassName);
142 }
143
144 public ObjectStore getObjectStore(String repositoryId) {
145 return fMapRepositoryToObjectStore.get(repositoryId);
146 }
147
148 public CmisServiceValidator getServiceValidator() {
149 return new InMemoryServiceValidatorImpl(this);
150 }
151
152 public BindingsObjectFactory getObjectFactory() {
153 return fObjectFactory;
154 }
155
156 public TypeDefinitionContainer getTypeById(String repositoryId, String typeId) {
157 TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
158 if (null == typeManager) {
159 throw new RuntimeException("Unknown repository " + repositoryId);
160 }
161
162 return typeManager.getTypeById(typeId);
163 }
164
165 public TypeDefinitionContainer getTypeById(String repositoryId, String typeId, boolean includePropertyDefinitions,
166 int depth) {
167 TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
168 if (null == typeManager) {
169 throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
170 }
171
172 TypeDefinitionContainer tc = typeManager.getTypeById(typeId);
173
174 if (tc != null) {
175 if (depth == -1) {
176 if (includePropertyDefinitions)
177 return tc;
178 else
179 depth = Integer.MAX_VALUE;
180 } else if (depth == 0 || depth < -1)
181 throw new CmisInvalidArgumentException("illegal depth value: " + depth);
182
183 return cloneTypeList(depth, includePropertyDefinitions, tc, null);
184 } else
185 return null;
186 }
187
188 public Collection<TypeDefinitionContainer> getTypeDefinitionList(String repositoryId,
189 boolean includePropertyDefinitions) {
190 Collection<TypeDefinitionContainer> result;
191 TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
192 if (null == typeManager) {
193 throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
194 }
195 Collection<TypeDefinitionContainer> typeColl = typeManager.getTypeDefinitionList();
196 if (includePropertyDefinitions) {
197 result = typeColl;
198 } else {
199 result = new ArrayList<TypeDefinitionContainer>(typeColl.size());
200
201 for (TypeDefinitionContainer c : typeColl) {
202 AbstractTypeDefinition td = ((AbstractTypeDefinition) c.getTypeDefinition()).clone();
203 TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
204 tdc.setChildren(c.getChildren());
205 td.setPropertyDefinitions(null);
206 result.add(tdc);
207 }
208 }
209 return result;
210 }
211
212 public Map<String, TypeDefinitionContainer> getTypeDefinitionMap(String repositoryId) {
213 return null;
214 }
215
216 public List<TypeDefinitionContainer> getRootTypes(String repositoryId) {
217 TypeManager typeManager = fMapRepositoryToTypeManager.get(repositoryId);
218 if (null == typeManager) {
219 throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
220 }
221 List<TypeDefinitionContainer> rootTypes = typeManager.getRootTypes();
222
223 return rootTypes;
224 }
225
226 public RepositoryInfo getRepositoryInfo(String repositoryId) {
227 ObjectStore sm = fMapRepositoryToObjectStore.get(repositoryId);
228 if (null == sm) {
229 return null;
230 }
231
232 RepositoryInfo repoInfo = createRepositoryInfo(repositoryId);
233
234 return repoInfo;
235 }
236
237 public void clearTypeSystem(String repositoryId) {
238 TypeManagerImpl typeManager = fMapRepositoryToTypeManager.get(repositoryId);
239 if (null == typeManager) {
240 throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
241 }
242
243 typeManager.clearTypeSystem();
244 }
245
246 public void initRepositoryInfo(String repositoryId, String repoInfoCreatorClassName) {
247 RepositoryInfoCreator repoCreator = null;
248
249 if (repoInfoCreatorClassName != null) {
250 Object obj = null;
251 try {
252 obj = Class.forName(repoInfoCreatorClassName).newInstance();
253 } catch (InstantiationException e) {
254 throw new RuntimeException(
255 "Illegal class to create type system, must implement RepositoryInfoCreator interface.", e);
256 } catch (IllegalAccessException e) {
257 throw new RuntimeException(
258 "Illegal class to create type system, must implement RepositoryInfoCreator interface.", e);
259 } catch (ClassNotFoundException e) {
260 throw new RuntimeException(
261 "Illegal class to create type system, must implement RepositoryInfoCreator interface.", e);
262 }
263
264 if (obj instanceof RepositoryInfoCreator) {
265 repoCreator = (RepositoryInfoCreator) obj;
266 fRepositoryInfo = repoCreator.createRepositoryInfo();
267 } else {
268 throw new RuntimeException(
269 "Illegal class to create repository info, must implement RepositoryInfoCreator interface.");
270 }
271 } else {
272
273 createRepositoryInfo(repositoryId);
274 }
275 }
276
277 public List<TypeDefinition> initTypeSystem(String typeCreatorClassName) {
278
279 List<TypeDefinition> typesList = null;
280
281 if (typeCreatorClassName != null) {
282 Object obj = null;
283 TypeCreator typeCreator = null;
284
285 try {
286 obj = Class.forName(typeCreatorClassName).newInstance();
287 } catch (InstantiationException e) {
288 throw new RuntimeException(
289 "Illegal class to create type system, must implement TypeCreator interface.", e);
290 } catch (IllegalAccessException e) {
291 throw new RuntimeException(
292 "Illegal class to create type system, must implement TypeCreator interface.", e);
293 } catch (ClassNotFoundException e) {
294 throw new RuntimeException(
295 "Illegal class to create type system, must implement TypeCreator interface.", e);
296 }
297
298 if (obj instanceof TypeCreator) {
299 typeCreator = (TypeCreator) obj;
300 } else {
301 throw new RuntimeException("Illegal class to create type system, must implement TypeCreator interface.");
302 }
303
304
305
306 typesList = typeCreator.createTypesList();
307 }
308
309 return typesList;
310 }
311
312 private void initTypeSystem(String repositoryId, String typeCreatorClassName) {
313
314 List<TypeDefinition> typeDefs = null;
315 TypeManagerImpl typeManager = fMapRepositoryToTypeManager.get(repositoryId);
316 if (null == typeManager) {
317 throw new RuntimeException("Unknown repository " + repositoryId);
318 }
319
320 if (null != typeCreatorClassName) {
321 typeDefs = initTypeSystem(typeCreatorClassName);
322 }
323
324 typeManager.initTypeSystem(typeDefs);
325 }
326
327 private RepositoryInfo createRepositoryInfo(String repositoryId) {
328 ObjectStore objStore = getObjectStore(repositoryId);
329 String rootFolderId = objStore.getRootFolder().getId();
330
331 RepositoryInfoImpl repoInfo;
332 repoInfo = new RepositoryInfoImpl();
333 repoInfo.setId(repositoryId == null ? "inMem" : repositoryId);
334 repoInfo.setName("Apache Chemistry OpenCMIS InMemory Repository");
335 repoInfo.setDescription("Apache Chemistry OpenCMIS InMemory Repository (Version: " + OPENCMIS_VERSION + ")");
336 repoInfo.setCmisVersionSupported("1.0");
337 repoInfo.setRootFolder(rootFolderId);
338 repoInfo.setPrincipalAnonymous(InMemoryAce.getAnonymousUser());
339 repoInfo.setPrincipalAnyone(InMemoryAce.getAnyoneUser());
340 repoInfo.setThinClientUri("");
341 repoInfo.setChangesIncomplete(Boolean.TRUE);
342 repoInfo.setChangesOnType(null);
343 repoInfo.setLatestChangeLogToken(Long.valueOf(new Date(0).getTime()).toString());
344 repoInfo.setVendorName("Apache Chemistry");
345 repoInfo.setProductName("OpenCMIS InMemory-Server");
346 repoInfo.setProductVersion(OPENCMIS_VERSION);
347
348
349 RepositoryCapabilitiesImpl caps = new RepositoryCapabilitiesImpl();
350 caps.setAllVersionsSearchable(false);
351 caps.setCapabilityAcl(CapabilityAcl.MANAGE);
352 caps.setCapabilityChanges(CapabilityChanges.NONE);
353 caps.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.ANYTIME);
354 caps.setCapabilityJoin(CapabilityJoin.NONE);
355 caps.setCapabilityQuery(CapabilityQuery.BOTHCOMBINED);
356 caps.setCapabilityRendition(CapabilityRenditions.NONE);
357 caps.setIsPwcSearchable(false);
358 caps.setIsPwcUpdatable(true);
359 caps.setSupportsGetDescendants(true);
360 caps.setSupportsGetFolderTree(true);
361 caps.setSupportsMultifiling(true);
362 caps.setSupportsUnfiling(true);
363 caps.setSupportsVersionSpecificFiling(false);
364 caps.setCapabilityAcl(CapabilityAcl.MANAGE);
365
366 AclCapabilitiesDataImpl aclCaps = new AclCapabilitiesDataImpl();
367 aclCaps.setAclPropagation(AclPropagation.OBJECTONLY);
368 aclCaps.setSupportedPermissions(SupportedPermissions.BASIC);
369
370
371 List<PermissionDefinition> permissions = new ArrayList<PermissionDefinition>();
372 permissions.add(createPermission(CMIS_READ, "Read"));
373 permissions.add(createPermission(CMIS_WRITE, "Write"));
374 permissions.add(createPermission(CMIS_ALL, "All"));
375 aclCaps.setPermissionDefinitionData(permissions);
376
377
378 List<PermissionMapping> list = new ArrayList<PermissionMapping>();
379 list.add(createMapping(PermissionMapping.CAN_GET_DESCENDENTS_FOLDER, CMIS_READ));
380 list.add(createMapping(PermissionMapping.CAN_GET_CHILDREN_FOLDER, CMIS_READ));
381 list.add(createMapping(PermissionMapping.CAN_GET_PARENTS_FOLDER, CMIS_READ));
382 list.add(createMapping(PermissionMapping.CAN_GET_FOLDER_PARENT_OBJECT, CMIS_READ));
383 list.add(createMapping(PermissionMapping.CAN_CREATE_DOCUMENT_FOLDER, CMIS_WRITE));
384 list.add(createMapping(PermissionMapping.CAN_CREATE_FOLDER_FOLDER, CMIS_WRITE));
385 list.add(createMapping(PermissionMapping.CAN_CREATE_RELATIONSHIP_SOURCE, CMIS_READ));
386 list.add(createMapping(PermissionMapping.CAN_CREATE_RELATIONSHIP_TARGET, CMIS_READ));
387 list.add(createMapping(PermissionMapping.CAN_GET_PROPERTIES_OBJECT, CMIS_READ));
388 list.add(createMapping(PermissionMapping.CAN_VIEW_CONTENT_OBJECT, CMIS_READ));
389 list.add(createMapping(PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT, CMIS_WRITE));
390 list.add(createMapping(PermissionMapping.CAN_MOVE_OBJECT, CMIS_WRITE));
391 list.add(createMapping(PermissionMapping.CAN_MOVE_TARGET, CMIS_WRITE));
392 list.add(createMapping(PermissionMapping.CAN_MOVE_SOURCE, CMIS_WRITE));
393 list.add(createMapping(PermissionMapping.CAN_DELETE_OBJECT, CMIS_WRITE));
394 ;
395 list.add(createMapping(PermissionMapping.CAN_DELETE_TREE_FOLDER, CMIS_WRITE));
396 list.add(createMapping(PermissionMapping.CAN_SET_CONTENT_DOCUMENT, CMIS_WRITE));
397 list.add(createMapping(PermissionMapping.CAN_DELETE_CONTENT_DOCUMENT, CMIS_WRITE));
398 list.add(createMapping(PermissionMapping.CAN_ADD_TO_FOLDER_OBJECT, CMIS_WRITE));
399 ;
400 list.add(createMapping(PermissionMapping.CAN_ADD_TO_FOLDER_FOLDER, CMIS_WRITE));
401 list.add(createMapping(PermissionMapping.CAN_REMOVE_FROM_FOLDER_OBJECT, CMIS_WRITE));
402 list.add(createMapping(PermissionMapping.CAN_REMOVE_FROM_FOLDER_FOLDER, CMIS_WRITE));
403 list.add(createMapping(PermissionMapping.CAN_CHECKOUT_DOCUMENT, CMIS_WRITE));
404 list.add(createMapping(PermissionMapping.CAN_CANCEL_CHECKOUT_DOCUMENT, CMIS_WRITE));
405 ;
406 list.add(createMapping(PermissionMapping.CAN_CHECKIN_DOCUMENT, CMIS_WRITE));
407 list.add(createMapping(PermissionMapping.CAN_GET_ALL_VERSIONS_VERSION_SERIES, CMIS_READ));
408 list.add(createMapping(PermissionMapping.CAN_GET_OBJECT_RELATIONSHIPS_OBJECT, CMIS_READ));
409 list.add(createMapping(PermissionMapping.CAN_ADD_POLICY_OBJECT, CMIS_WRITE));
410 list.add(createMapping(PermissionMapping.CAN_ADD_POLICY_POLICY, CMIS_WRITE));
411 list.add(createMapping(PermissionMapping.CAN_REMOVE_POLICY_OBJECT, CMIS_WRITE));
412 list.add(createMapping(PermissionMapping.CAN_REMOVE_POLICY_POLICY, CMIS_WRITE));
413 ;
414 list.add(createMapping(PermissionMapping.CAN_GET_APPLIED_POLICIES_OBJECT, CMIS_READ));
415 list.add(createMapping(PermissionMapping.CAN_GET_ACL_OBJECT, CMIS_READ));
416 list.add(createMapping(PermissionMapping.CAN_APPLY_ACL_OBJECT, CMIS_ALL));
417
418 Map<String, PermissionMapping> map = new LinkedHashMap<String, PermissionMapping>();
419 for (PermissionMapping pm : list) {
420 map.put(pm.getKey(), pm);
421 }
422
423 aclCaps.setPermissionMappingData(map);
424
425 repoInfo.setAclCapabilities(aclCaps);
426
427 repoInfo.setCapabilities(caps);
428
429 fRepositoryInfo = repoInfo;
430 return repoInfo;
431 }
432
433 private static PermissionDefinition createPermission(String permission, String description) {
434 PermissionDefinitionDataImpl pd = new PermissionDefinitionDataImpl();
435 pd.setPermission(permission);
436 pd.setDescription(description);
437
438 return pd;
439 }
440
441 private static PermissionMapping createMapping(String key, String permission) {
442 PermissionMappingDataImpl pm = new PermissionMappingDataImpl();
443 pm.setKey(key);
444 pm.setPermissions(Collections.singletonList(permission));
445
446 return pm;
447 }
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463 private static TypeDefinitionContainer cloneTypeList(int depth, boolean includePropertyDefinitions,
464 TypeDefinitionContainer tdc, TypeDefinitionContainer parent) {
465
466 AbstractTypeDefinition tdClone = ((AbstractTypeDefinition) tdc.getTypeDefinition()).clone();
467 if (!includePropertyDefinitions) {
468 tdClone.setPropertyDefinitions(null);
469 }
470
471 TypeDefinitionContainerImpl tdcClone = new TypeDefinitionContainerImpl(tdClone);
472 if (null != parent)
473 parent.getChildren().add(tdcClone);
474
475 if (depth > 0) {
476 List<TypeDefinitionContainer> children = tdc.getChildren();
477 for (TypeDefinitionContainer child : children) {
478 cloneTypeList(depth - 1, includePropertyDefinitions, child, tdcClone);
479 }
480 }
481 return tdcClone;
482 }
483
484 public TypeManagerCreatable getTypeManager(String repositoryId) {
485 TypeManagerCreatable typeManager = fMapRepositoryToTypeManager.get(repositoryId);
486 return typeManager;
487 }
488
489 public ObjectList query(String user, String repositoryId, String statement, Boolean searchAllVersions,
490 Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
491 BigInteger maxItems, BigInteger skipCount) {
492 TypeManager tm = getTypeManager(repositoryId);
493 ObjectStore objectStore = getObjectStore(repositoryId);
494
495 InMemoryQueryProcessor queryProcessor = new InMemoryQueryProcessor(getStore(repositoryId));
496 ObjectList objList = queryProcessor.query(tm, objectStore, user, repositoryId, statement, searchAllVersions,
497 includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount);
498
499
500
501 return objList;
502 }
503
504 }