chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r927468 - in /incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src: main/java/org/apache/opencmis/inmemory/ main/java/org/apache/opencmis/inmemory/storedobj/api/ main/java/org/apache/opencmis/inmemory/storedobj/im...
Date Thu, 25 Mar 2010 16:08:47 GMT
Author: jens
Date: Thu Mar 25 16:08:46 2010
New Revision: 927468

URL: http://svn.apache.org/viewvc?rev=927468&view=rev
Log:
make allowable actions more context specific, set only those actions that are applicable

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/storedobj/api/Content.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.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=927468&r1=927467&r2=927468&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
Thu Mar 25 16:08:46 2010
@@ -58,7 +58,8 @@ public class DataObjectCreator {
     boolean canCheckOut = false;
     boolean canCheckIn = false;
     boolean isVersioned = so instanceof Version || so instanceof VersionedDocument;
-    
+    boolean hasContent = so instanceof Content && ((Content) so).hasContent();
+      
     String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
     if (so instanceof Version) {
       isCheckedOut = ((Version)so).isPwc();
@@ -73,33 +74,51 @@ public class DataObjectCreator {
     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.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, 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, 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_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);
+
+    if (isFolder || isDocument) {
+      actions.put(AllowableActionsData.ACTION_CAN_CREATE_RELATIONSHIP, Boolean.FALSE);
+      actions.put(AllowableActionsData.ACTION_CAN_GET_PROPERTIES, 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_MOVE_OBJECT, Boolean.TRUE);      
+    }
+
+    if (isFolder) {
+      actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_PARENT, !so.equals(objStore.getRootFolder()));
+      actions.put(AllowableActionsData.ACTION_CAN_GET_FOLDER_TREE, true);
+      actions.put(AllowableActionsData.ACTION_CAN_GET_DESCENDANTS, true);
+      actions.put(AllowableActionsData.ACTION_CAN_ADD_OBJECT_TO_FOLDER, true);
+      actions.put(AllowableActionsData.ACTION_CAN_REMOVE_OBJECT_FROM_FOLDER, true);
+      actions.put(AllowableActionsData.ACTION_CAN_CREATE_DOCUMENT, true);
+      actions.put(AllowableActionsData.ACTION_CAN_CREATE_FOLDER, true);
+      actions.put(AllowableActionsData.ACTION_CAN_GET_CHILDREN, true);
+      actions.put(AllowableActionsData.ACTION_CAN_DELETE_TREE, isFolder);
+    }
+    
+    if (hasContent) { 
+      actions.put(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM, isDocument);
+      actions.put(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM, isDocument);
+      actions.put(AllowableActionsData.ACTION_CAN_GET_RENDITIONS, Boolean.FALSE);
+    }        
+
+   if (isVersioned) { 
+      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_GET_ALL_VERSIONS, so instanceof VersionedDocument);
+    }
+    
+    if (isDocument) {
+      actions.put(AllowableActionsData.ACTION_CAN_SET_CONTENT_STREAM, isVersioned ? canCheckIn:
isDocument);      
+    }
+    
     allowableActions.setAllowableActions(actions);
     return allowableActions;
   }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Content.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Content.java?rev=927468&r1=927467&r2=927468&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Content.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Content.java
Thu Mar 25 16:08:46 2010
@@ -21,6 +21,13 @@ package org.apache.opencmis.inmemory.sto
 import org.apache.opencmis.commons.provider.ContentStreamData;
 
 public interface Content {
+  
+  /** 
+   * return true if this object has content or false if there is no content attached.
+   * @return
+   */
+  boolean hasContent();
+  
   /**
    * retrieve the content of a document
    * @return

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentImpl.java?rev=927468&r1=927467&r2=927468&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentImpl.java
Thu Mar 25 16:08:46 2010
@@ -53,7 +53,9 @@ public class DocumentImpl extends Abstra
    * @see org.opencmis.client.provider.spi.inmemory.IDocument#getContent()
    */
   public ContentStreamData getContent(long offset, long length) {
-    if (offset<=0 && length<0)
+    if (null == fContent)
+      return null;
+    else if (offset<=0 && length<0)
       return fContent;
     else
       return fContent.getCloneWithLimits(offset, length);
@@ -115,4 +117,9 @@ public class DocumentImpl extends Abstra
     }
   }
 
+  public boolean hasContent() {
+    return null != fContent;
+  }
+
+
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java?rev=927468&r1=927467&r2=927468&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
Thu Mar 25 16:08:46 2010
@@ -236,5 +236,8 @@ public class DocumentVersionImpl extends
     fContainer.removeParent(parent);
   }
 
- 
+  public boolean hasContent() {
+    return null != fContent;
+  }
+
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java?rev=927468&r1=927467&r2=927468&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
Thu Mar 25 16:08:46 2010
@@ -636,7 +636,8 @@ public class ObjectServiceTest extends A
   @Test
   public void testAllowableActions() {
     log.info("starting testAllowableActions() ...");
-    String id = createDocument(fRootFolderId, false);
+    final boolean withContent = false;
+    String id = createDocument(fRootFolderId, withContent);
     
     // get allowable actions via getObject
     ObjectData res = fObjSvc.getObject(fRepositoryId, id, "*", true, IncludeRelationships.NONE,
@@ -644,48 +645,64 @@ public class ObjectServiceTest extends A
     assertNotNull(res.getAllowableActions());
     Map<String, Boolean> actions = res.getAllowableActions().getAllowableActions();
     assertNotNull(actions);
-    verifyAllowableActions(actions);
+    verifyAllowableActionsDocument(actions, false, withContent);
     
     // get allowable actions via getAllowableActions
     AllowableActionsData allowableActions = fObjSvc.getAllowableActions(fRepositoryId, id,
null);
     assertNotNull(allowableActions);
     actions = allowableActions.getAllowableActions();
     assertNotNull(actions);
-    verifyAllowableActions(actions);
+    verifyAllowableActionsDocument(actions, false, withContent);
 
     // cleanup
     fObjSvc.deleteObject(fRepositoryId, id, true, null);
     log.info("... testAllowableActions() finished.");    
   }
   
-  private void verifyAllowableActions(Map<String, Boolean> actions) {
+  private void verifyAllowableActionsDocument(Map<String, Boolean> actions, boolean
isVersioned, boolean hasContent) {
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_OBJECT));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_UPDATE_PROPERTIES));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_PROPERTIES));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_OBJECT_RELATIONSHIPS));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_OBJECT_PARENTS));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_FOLDER_PARENT));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_FOLDER_TREE));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_DESCENDANTS));
+    
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_FOLDER_PARENT));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_FOLDER_TREE));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_DESCENDANTS));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_MOVE_OBJECT));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_OUT));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CANCEL_CHECK_OUT));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_IN));
+    if (hasContent) {
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM));
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM));
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_RENDITIONS));
+    } else {
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_CONTENT_STREAM));
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM));
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_RENDITIONS));
+    }
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_ADD_OBJECT_TO_FOLDER));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_REMOVE_OBJECT_FROM_FOLDER));
+    
+    if (isVersioned) {
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CANCEL_CHECK_OUT));
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_IN));      
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_OUT));
+      assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_ALL_VERSIONS));
+
+    } else {
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_CANCEL_CHECK_OUT));
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_IN));      
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_CHECK_OUT));
+      assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_ALL_VERSIONS));
+    }
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_SET_CONTENT_STREAM));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_ALL_VERSIONS));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_ADD_OBJECT_TO_FOLDER));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_REMOVE_OBJECT_FROM_FOLDER));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_APPLY_POLICY));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_APPLIED_POLICIES));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_REMOVE_POLICY));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_CHILDREN));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CREATE_DOCUMENT));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CREATE_FOLDER));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_GET_CHILDREN));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_CREATE_DOCUMENT));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_CREATE_FOLDER));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_CREATE_RELATIONSHIP));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_TREE));
-    assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_RENDITIONS));
+    assertNull(actions.get(AllowableActionsData.ACTION_CAN_DELETE_TREE));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_GET_ACL));
     assertNotNull(actions.get(AllowableActionsData.ACTION_CAN_APPLY_ACL));
   }



Mime
View raw message