chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1597992 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemi...
Date Wed, 28 May 2014 12:38:19 GMT
Author: fmui
Date: Wed May 28 12:38:19 2014
New Revision: 1597992

URL: http://svn.apache.org/r1597992
Log:
CMIS-774: added hasAllowableAction and getPermissonsForPrincipal

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObject.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObject.java?rev=1597992&r1=1597991&r2=1597992&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObject.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObject.java
Wed May 28 12:38:19 2014
@@ -20,12 +20,14 @@ package org.apache.chemistry.opencmis.cl
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.chemistry.opencmis.commons.data.Ace;
 import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
 import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 
@@ -44,6 +46,22 @@ public interface CmisObject extends Obje
     AllowableActions getAllowableActions();
 
     /**
+     * Returns if a given action in the Allowable Actions.
+     * 
+     * @param action
+     *            the action to test, must not be {@code null}
+     * @return {@code true} if the action was found in the Allowable Actions,
+     *         {@code false} if the action was not found in the Allowable
+     *         Actions
+     * @throws IllegalStateException
+     *             if the Allowable Actions haven't been fetched or provided by
+     *             the repository
+     * 
+     * @cmis 1.0
+     */
+    boolean hasAllowableAction(Action action);
+
+    /**
      * Returns the relationships if they have been fetched for this object.
      * 
      * @cmis 1.0
@@ -57,6 +75,20 @@ public interface CmisObject extends Obje
      */
     Acl getAcl();
 
+    /**
+     * Returns all permissions for the given user from the ACL.
+     * 
+     * @param principalId
+     *            the principal ID, must not be {@code null}
+     * @return the set of permissions for this user, or an empty set if
+     *         principal is not in the ACL
+     * @throws IllegalStateException
+     *             if the ACL hasn't been fetched or provided by the repository
+     * 
+     * @cmis 1.0
+     */
+    Set<String> getPermissonsForPrincipal(String principalId);
+
     // object service
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java?rev=1597992&r1=1597991&r2=1597992&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
Wed May 28 12:38:19 2014
@@ -25,6 +25,7 @@ import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -49,6 +50,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
@@ -527,6 +529,19 @@ public abstract class AbstractCmisObject
         }
     }
 
+    public boolean hasAllowableAction(Action action) {
+        if (action == null) {
+            throw new IllegalArgumentException("Action must be set!");
+        }
+
+        AllowableActions currentAllowableActions = getAllowableActions();
+        if (currentAllowableActions == null || currentAllowableActions.getAllowableActions()
== null) {
+            throw new IllegalStateException("Allowable Actions are not available!");
+        }
+
+        return currentAllowableActions.getAllowableActions().contains(action);
+    }
+
     // --- renditions ---
 
     public List<Rendition> getRenditions() {
@@ -578,6 +593,32 @@ public abstract class AbstractCmisObject
         }
     }
 
+    public Set<String> getPermissonsForPrincipal(String principalId) {
+        if (principalId == null) {
+            throw new IllegalArgumentException("Principal must be set!");
+        }
+
+        Acl currentAcl = getAcl();
+
+        if (currentAcl == null) {
+            throw new IllegalStateException("ACLs are not available!");
+        }
+
+        if (acl.getAces() == null || acl.getAces().isEmpty()) {
+            return Collections.emptySet();
+        }
+
+        HashSet<String> result = new HashSet<String>();
+
+        for (Ace ace : acl.getAces()) {
+            if (principalId.equals(ace.getPrincipalId()) && ace.getPermissions()
!= null) {
+                result.addAll(ace.getPermissions());
+            }
+        }
+
+        return result;
+    }
+
     // --- policies ---
 
     public void applyPolicy(ObjectId... policyIds) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java?rev=1597992&r1=1597991&r2=1597992&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java
Wed May 28 12:38:19 2014
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import java.util.GregorianCalendar;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.ItemIterable;
@@ -38,6 +39,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
 import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
 import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
@@ -79,6 +81,10 @@ public class CmisObjectMock implements C
     public Acl getAcl() {
         return null;
     }
+    
+    public Set<String> getPermissonsForPrincipal(String principalId) {
+        return null;
+    }
 
     public Acl getAcl(boolean onlyBasicPermissions) {
         return null;
@@ -87,6 +93,10 @@ public class CmisObjectMock implements C
     public AllowableActions getAllowableActions() {
         return null;
     }
+    
+    public boolean hasAllowableAction(Action action) {
+        return false;
+    }
 
     public ObjectType getBaseType() {
         return null;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1597992&r1=1597991&r2=1597992&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
Wed May 28 12:38:19 2014
@@ -967,6 +967,7 @@ public abstract class AbstractSessionTes
 
                 f = createResult(FAILURE, "Object has no CAN_GET_PROPERTIES allowable action!");
                 addResult(results, assertAllowableAction(object, Action.CAN_GET_PROPERTIES,
null, f));
+                addResult(results, assertIsTrue(object.hasAllowableAction(Action.CAN_GET_PROPERTIES),
null, f));
 
                 if (object instanceof Document) {
                     if (actions.contains(Action.CAN_CHECK_OUT) && actions.contains(Action.CAN_CHECK_IN))
{



Mime
View raw message