Author: jens
Date: Mon Feb 22 11:38:06 2010
New Revision: 912538
URL: http://svn.apache.org/viewvc?rev=912538&view=rev
Log:
InMemory impl: make allowable actions more dynamic
Modified:
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/DataObjectCreator.java
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/PropertyCreationHelper.java
Modified:
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/DataObjectCreator.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/DataObjectCreator.java?rev=912538&r1=912537&r2=912538&view=diff
==============================================================================
---
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/DataObjectCreator.java
(original)
+++
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/DataObjectCreator.java
Mon Feb 22 11:38:06 2010
@@ -35,7 +35,14 @@
import org.apache.opencmis.commons.provider.ObjectData;
import org.apache.opencmis.commons.provider.PolicyIdListData;
import org.apache.opencmis.commons.provider.RenditionData;
+import org.apache.opencmis.inmemory.server.RuntimeContext;
+import org.apache.opencmis.inmemory.storedobj.api.Content;
+import org.apache.opencmis.inmemory.storedobj.api.Folder;
+import org.apache.opencmis.inmemory.storedobj.api.ObjectStore;
import org.apache.opencmis.inmemory.storedobj.api.StoredObject;
+import org.apache.opencmis.inmemory.storedobj.api.Version;
+import org.apache.opencmis.inmemory.storedobj.api.VersionedDocument;
+import org.apache.opencmis.server.spi.CallContext;
/**
* @author Jens A collection of utility functions to fill the data objects
used as return values for
@@ -43,37 +50,54 @@
*/
public class DataObjectCreator {
- public static AllowableActionsData fillAllowableActions(StoredObject so) {
+ public static AllowableActionsData fillAllowableActions(ObjectStore
objStore, StoredObject so) {
+ boolean isFolder = so instanceof Folder;
+ boolean isDocument = so instanceof Content;
+ boolean isCheckedOut = false;
+ boolean canCheckOut = false;
+ boolean canCheckIn = false;
+ boolean isVersioned = so instanceof Version || so instanceof
VersionedDocument;
+
+ String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
+ if (so instanceof Version) {
+ isCheckedOut = ((Version)so).isPwc();
+ canCheckIn = isCheckedOut &&
((Version)so).getParentDocument().getCheckedOutBy().equals(user);
+ } else if (so instanceof VersionedDocument) {
+ isCheckedOut = ((VersionedDocument)so).isCheckedOut();
+ canCheckOut = (so instanceof VersionedDocument) &&
!((VersionedDocument)so).isCheckedOut();
+ canCheckIn = isCheckedOut &&
((VersionedDocument)so).getCheckedOutBy().equals(user);
+ }
+
AllowableActionsDataImpl allowableActions = new AllowableActionsDataImpl();
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put(AllowableActionsData.ACTION_CAN_DELETE_OBJECT, Boolean.TRUE);
actions.put(AllowableActionsData.ACTION_CAN_UPDATE_PROPERTIES,
Boolean.TRUE);
actions.put(AllowableActionsData.ACTION_CAN_GET_PROPERTIES, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_OBJECT_RELATIONSHIPS,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_OBJECT_PARENTS,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_PARENT,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_TREE, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_DESCENDANTS, Boolean.TRUE);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_OBJECT_RELATIONSHIPS,
Boolean.FALSE);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_OBJECT_PARENTS,
!so.equals(objStore.getRootFolder()));
+ actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_PARENT,
!so.equals(objStore.getRootFolder()));
+ actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_TREE, isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_DESCENDANTS, isFolder);
actions.put(AllowableActionsData.ACTION_CAN_MOVE_OBJECT, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CHECK_OUT, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CANCEL_CHECK_OUT,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CHECK_IN, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_SET_CONTENT_STREAM,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_ALL_VERSIONS,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_ADD_OBJECT_TO_FOLDER,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_REMOVE_OBJECT_FROM_FOLDER,
Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM,
Boolean.TRUE);
+ actions.put(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM,
isDocument);
+ actions.put(AllowableActionsData.ACTION_CAN_CHECK_OUT, canCheckOut);
+ actions.put(AllowableActionsData.ACTION_CAN_CANCEL_CHECK_OUT,
isCheckedOut);
+ actions.put(AllowableActionsData.ACTION_CAN_CHECK_IN, canCheckIn);
+ actions.put(AllowableActionsData.ACTION_CAN_SET_CONTENT_STREAM,
isVersioned ? canCheckIn: isDocument);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_ALL_VERSIONS, so
instanceof VersionedDocument);
+ actions.put(AllowableActionsData.ACTION_CAN_ADD_OBJECT_TO_FOLDER,
isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_REMOVE_OBJECT_FROM_FOLDER,
isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM,
isDocument);
actions.put(AllowableActionsData.ACTION_CAN_APPLY_POLICY, Boolean.FALSE);
actions.put(AllowableActionsData.ACTION_CAN_GET_APPLIED_POLICIES,
Boolean.FALSE);
actions.put(AllowableActionsData.ACTION_CAN_REMOVE_POLICY, Boolean.FALSE);
- actions.put(AllowableActionsData.ACTION_CAN_GET_CHILDREN, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CREATE_DOCUMENT, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CREATE_FOLDER, Boolean.TRUE);
- actions.put(AllowableActionsData.ACTION_CAN_CREATE_RELATIONSHIP,
Boolean.TRUE);
+ actions.put(AllowableActionsData.ACTION_CAN_GET_CHILDREN, isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_CREATE_DOCUMENT, isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_CREATE_FOLDER, isFolder);
+ actions.put(AllowableActionsData.ACTION_CAN_CREATE_RELATIONSHIP,
Boolean.FALSE);
actions.put(AllowableActionsData.ACTION_CAN_CREATE_POLICY, Boolean.FALSE);
- actions.put(AllowableActionsData.ACTION_CAN_DELETE_TREE, Boolean.TRUE);
+ actions.put(AllowableActionsData.ACTION_CAN_DELETE_TREE, isFolder);
actions.put(AllowableActionsData.ACTION_CAN_GET_RENDITIONS, Boolean.FALSE);
actions.put(AllowableActionsData.ACTION_CAN_GET_ACL, Boolean.FALSE);
actions.put(AllowableActionsData.ACTION_CAN_APPLY_ACL, Boolean.FALSE);
Modified:
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java?rev=912538&r1=912537&r2=912538&view=diff
==============================================================================
---
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
(original)
+++
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
Mon Feb 22 11:38:06 2010
@@ -29,12 +29,14 @@
import org.apache.opencmis.commons.api.ExtensionsData;
import org.apache.opencmis.commons.enums.IncludeRelationships;
import org.apache.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.opencmis.commons.impl.dataobjects.ObjectDataImpl;
import
org.apache.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl;
import org.apache.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl;
import org.apache.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl;
import org.apache.opencmis.commons.impl.dataobjects.ObjectListImpl;
import org.apache.opencmis.commons.impl.dataobjects.ObjectParentDataImpl;
+import org.apache.opencmis.commons.provider.AllowableActionsData;
import org.apache.opencmis.commons.provider.NavigationService;
import org.apache.opencmis.commons.provider.ObjectData;
import org.apache.opencmis.commons.provider.ObjectInFolderContainer;
@@ -250,6 +252,9 @@
StoredObject so = fs.getObjectById(folderId);
Folder folder = null;
+ if (so == null)
+ throw new CmisObjectNotFoundException("Unknown object id: " +
folderId);
+
if (so instanceof Folder)
folder = (Folder) so;
else
@@ -266,7 +271,8 @@
if (includePathSegments!=null && includePathSegments)
oifd.setPathSegment(spo.getName());
if (includeAllowableActions!=null && includeAllowableActions) {
- objectData.setAllowableActions(null /*f.getAllowableActions()*/);
+ AllowableActionsData allowableActions =
DataObjectCreator.fillAllowableActions(fs, spo);
+ objectData.setAllowableActions(allowableActions);
}
if (includeRelationships!=null && includeRelationships !=
IncludeRelationships.NONE) {
objectData.setRelationships(null /*f.getRelationships()*/);
Modified:
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java?rev=912538&r1=912537&r2=912538&view=diff
==============================================================================
---
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
(original)
+++
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
Mon Feb 22 11:38:06 2010
@@ -438,13 +438,13 @@
ExtensionsData extension) {
log.debug("start getAllowableActions()");
checkStandardParameters(repositoryId, objectId);
- ObjectStore folderStore = fStoreManager.getObjectStore(repositoryId);
- StoredObject so = folderStore.getObjectById(objectId);
+ ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
+ StoredObject so = objectStore.getObjectById(objectId);
if (so == null)
throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
- AllowableActionsData allowableActions =
DataObjectCreator.fillAllowableActions(so);
+ AllowableActionsData allowableActions =
DataObjectCreator.fillAllowableActions(objectStore, so);
log.debug("stop getAllowableActions()");
return allowableActions;
}
Modified:
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/PropertyCreationHelper.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/PropertyCreationHelper.java?rev=912538&r1=912537&r2=912538&view=diff
==============================================================================
---
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/PropertyCreationHelper.java
(original)
+++
incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/types/PropertyCreationHelper.java
Mon Feb 22 11:38:06 2010
@@ -55,6 +55,7 @@
import org.apache.opencmis.inmemory.DataObjectCreator;
import org.apache.opencmis.inmemory.FilterParser;
import org.apache.opencmis.inmemory.NameValidator;
+import org.apache.opencmis.inmemory.storedobj.api.ObjectStore;
import org.apache.opencmis.inmemory.storedobj.api.StoreManager;
import org.apache.opencmis.inmemory.storedobj.api.StoredObject;
@@ -245,7 +246,8 @@
// fill output object
if (null != includeAllowableActions && includeAllowableActions) {
- AllowableActionsData allowableActions =
DataObjectCreator.fillAllowableActions(so);
+ ObjectStore objectStore = sm.getObjectStore(so.getRepositoryId());
+ AllowableActionsData allowableActions =
DataObjectCreator.fillAllowableActions(objectStore, so);
od.setAllowableActions(allowableActions);
}
if (null != includeACL && includeACL)