chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1787163 - 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 Thu, 16 Mar 2017 12:03:46 GMT
Author: fmui
Date: Thu Mar 16 12:03:46 2017
New Revision: 1787163

URL: http://svn.apache.org/viewvc?rev=1787163&view=rev
Log:
introduced lazy loading of policies

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/tests/crud/CreateAndDeletePolicyTest.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=1787163&r1=1787162&r2=1787163&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
Thu Mar 16 12:03:46 2017
@@ -112,9 +112,9 @@ public interface CmisObject extends Obje
      * 
      * @param allVersions
      *            if this object is a document this parameter defines whether
-     *            only this version ({@code false}) or all versions ({@code true}
-     *            ) should be deleted, the parameter is ignored for all other
-     *            object types
+     *            only this version ({@code false}) or all versions
+     *            ({@code true} ) should be deleted, the parameter is ignored
+     *            for all other object types
      * 
      * @cmis 1.0
      */
@@ -296,15 +296,35 @@ public interface CmisObject extends Obje
 
     /**
      * Returns the applied policies if they have been fetched for this object.
+     * This method fetches the policy objects from the repository when this
+     * method is called for the first time. Policy objects that don't exist are
+     * ignored.
      * 
      * @return the list of policies applied to this object or {@code null} if
      *         the policies have not been requested or no policies are applied
      *         to this object
      * 
+     * @see #getPolicyIds()
+     * 
      * @cmis 1.0
      */
     List<Policy> getPolicies();
 
+    /**
+     * Returns the applied policy IDs if they have been fetched for this object.
+     * All applied policy IDs are returned, even IDs of policies that don't
+     * exist.
+     * 
+     * @return the list of IDs of applied policies or {@code null} if the
+     *         policies have not been requested or no policies are applied to
+     *         this object
+     * 
+     * @see #getPolicies()
+     * 
+     * @cmis 1.0
+     */
+    List<ObjectId> getPolicyIds();
+
     // ACL 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=1787163&r1=1787162&r2=1787163&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
Thu Mar 16 12:03:46 2017
@@ -57,6 +57,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 
@@ -74,6 +75,7 @@ public abstract class AbstractCmisObject
     private AllowableActions allowableActions;
     private List<Rendition> renditions;
     private Acl acl;
+    private List<String> policyIds;
     private List<Policy> policies;
     private List<Relationship> relationships;
     private Map<ExtensionLevel, List<CmisExtensionElement>> extensions;
@@ -129,7 +131,7 @@ public abstract class AbstractCmisObject
             List<String> stids = (List<String>) objectData.getProperties().getProperties()
                     .get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
             if (isNotEmpty(stids)) {
-                secondaryTypes = new ArrayList<SecondaryType>();
+                secondaryTypes = new ArrayList<SecondaryType>(stids.size());
                 for (String stid : stids) {
                     if (stid != null) {
                         ObjectType type = session.getTypeDefinition(stid);
@@ -157,7 +159,7 @@ public abstract class AbstractCmisObject
 
         // handle renditions
         if (objectData.getRenditions() != null && !objectData.getRenditions().isEmpty())
{
-            renditions = new ArrayList<Rendition>();
+            renditions = new ArrayList<Rendition>(objectData.getRenditions().size());
             for (RenditionData rd : objectData.getRenditions()) {
                 renditions.add(of.convertRendition(getId(), rd));
             }
@@ -201,26 +203,21 @@ public abstract class AbstractCmisObject
         }
 
         // handle policies
+        policies = null;
         if (objectData.getPolicyIds() != null && objectData.getPolicyIds().getPolicyIds()
!= null) {
             if (objectData.getPolicyIds().getPolicyIds().isEmpty()) {
-                policies = null;
+                policyIds = null;
             } else {
-                policies = new ArrayList<Policy>();
-                for (String pid : objectData.getPolicyIds().getPolicyIds()) {
-                    CmisObject policy = session.getObject(pid);
-                    if (policy instanceof Policy) {
-                        policies.add((Policy) policy);
-                    }
-                }
+                policyIds = objectData.getPolicyIds().getPolicyIds();
             }
             extensions.put(ExtensionLevel.POLICIES, objectData.getPolicyIds().getExtensions());
         } else {
-            policies = null;
+            policyIds = null;
         }
 
         // handle relationships
         if (objectData.getRelationships() != null && !objectData.getRelationships().isEmpty())
{
-            relationships = new ArrayList<Relationship>();
+            relationships = new ArrayList<Relationship>(objectData.getRelationships().size());
             for (ObjectData rod : objectData.getRelationships()) {
                 CmisObject relationship = of.convertObject(rod, this.creationContext);
                 if (relationship instanceof Relationship) {
@@ -397,12 +394,10 @@ public abstract class AbstractCmisObject
             }
 
             // it's time to update
-            getBinding().getObjectService().updateProperties(
-                    getRepositoryId(),
-                    objectIdHolder,
-                    changeTokenHolder,
-                    getObjectFactory()
-                            .convertProperties(properties, this.objectType, this.secondaryTypes,
updatebility), null);
+            getBinding().getObjectService().updateProperties(getRepositoryId(), objectIdHolder,
changeTokenHolder,
+                    getObjectFactory().convertProperties(properties, this.objectType, this.secondaryTypes,
+                            updatebility),
+                    null);
 
             newObjectId = objectIdHolder.getValue();
 
@@ -607,7 +602,7 @@ public abstract class AbstractCmisObject
     public ObjectType getType() {
         readLock();
         try {
-            return this.objectType;
+            return objectType;
         } finally {
             readUnlock();
         }
@@ -658,7 +653,7 @@ public abstract class AbstractCmisObject
     public AllowableActions getAllowableActions() {
         readLock();
         try {
-            return this.allowableActions;
+            return allowableActions;
         } finally {
             readUnlock();
         }
@@ -684,7 +679,7 @@ public abstract class AbstractCmisObject
     public List<Rendition> getRenditions() {
         readLock();
         try {
-            return this.renditions;
+            return renditions;
         } finally {
             readUnlock();
         }
@@ -820,8 +815,50 @@ public abstract class AbstractCmisObject
     public List<Policy> getPolicies() {
         readLock();
         try {
+            if (policies != null || policyIds == null) {
+                return policies;
+            }
+        } finally {
+            readUnlock();
+        }
+
+        writeLock();
+        try {
+            if (policies == null) {
+                policies = new ArrayList<Policy>(policyIds.size());
+                for (String pid : policyIds) {
+                    try {
+                        CmisObject policy = session.getObject(pid);
+                        if (policy instanceof Policy) {
+                            policies.add((Policy) policy);
+                        }
+                    } catch (CmisObjectNotFoundException nfe) {
+                        // ignore
+                    }
+                }
+            }
+
             return policies;
         } finally {
+            writeUnlock();
+        }
+    }
+
+    @Override
+    public List<ObjectId> getPolicyIds() {
+        readLock();
+        try {
+            if (policyIds == null) {
+                return null;
+            }
+
+            List<ObjectId> result = new ArrayList<ObjectId>(policyIds.size());
+            for (String pid : policyIds) {
+                result.add(session.createObjectId(pid));
+            }
+
+            return result;
+        } finally {
             readUnlock();
         }
     }
@@ -878,12 +915,9 @@ public abstract class AbstractCmisObject
             OperationContext oc = getCreationContext();
 
             // get the latest data from the repository
-            ObjectData objectData = getSession()
-                    .getBinding()
-                    .getObjectService()
-                    .getObject(getRepositoryId(), objectId, oc.getFilterString(), oc.isIncludeAllowableActions(),
-                            oc.getIncludeRelationships(), oc.getRenditionFilterString(),
oc.isIncludePolicies(),
-                            oc.isIncludeAcls(), null);
+            ObjectData objectData = getSession().getBinding().getObjectService().getObject(getRepositoryId(),
objectId,
+                    oc.getFilterString(), oc.isIncludeAllowableActions(), oc.getIncludeRelationships(),
+                    oc.getRenditionFilterString(), oc.isIncludePolicies(), oc.isIncludeAcls(),
null);
 
             // reset this object
             initialize(session, session.getTypeDefinition(objectType.getId()), objectData,
creationContext);

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=1787163&r1=1787162&r2=1787163&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
Thu Mar 16 12:03:46 2017
@@ -148,6 +148,11 @@ public class CmisObjectMock implements C
     }
 
     @Override
+    public List<ObjectId> getPolicyIds() {
+        return null;
+    }
+
+    @Override
     public List<Property<?>> getProperties() {
         return null;
     }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeletePolicyTest.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/tests/crud/CreateAndDeletePolicyTest.java?rev=1787163&r1=1787162&r2=1787163&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeletePolicyTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateAndDeletePolicyTest.java
Thu Mar 16 12:03:46 2017
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.tc
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.INFO;
 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
 
 import java.util.List;
 import java.util.Map;
@@ -42,7 +43,8 @@ public class CreateAndDeletePolicyTest e
     public void init(Map<String, String> parameters) {
         super.init(parameters);
         setName("Create and Delete Policy Test");
-        setDescription("Creates a policy object, checks the newly created policy object,
applys and removes it from a document, and finally deletes the created policy object.");
+        setDescription(
+                "Creates a policy object, checks the newly created policy object, applys
and removes it from a document, and finally deletes the created policy object.");
     }
 
     @Override
@@ -78,6 +80,10 @@ public class CreateAndDeletePolicyTest e
                             + ", Doc Id: " + doc.getId());
                     addResult(assertIsTrue(found1, null, f));
 
+                    // check if policy IDs and policy object match
+                    f = createResult(WARNING, "Not all policy IDs can be resolved to policy
objects.");
+                    addResult(assertEquals(doc.getPolicyIds().size(), doc.getPolicies().size(),
null, f));
+
                     // get the policies
                     List<ObjectData> policiesData2 = session.getBinding().getPolicyService()
                             .getAppliedPolicies(session.getRepositoryInfo().getId(), doc.getId(),
"*", null);
@@ -92,9 +98,8 @@ public class CreateAndDeletePolicyTest e
                         }
                     }
 
-                    f = createResult(FAILURE,
-                            "Applied policy is not returned by the repository! Policy Id:
" + policy.getId()
-                                    + ", Doc Id: " + doc.getId());
+                    f = createResult(FAILURE, "Applied policy is not returned by the repository!
Policy Id: "
+                            + policy.getId() + ", Doc Id: " + doc.getId());
                     addResult(assertIsTrue(found2, null, f));
 
                     // remove policy
@@ -111,17 +116,13 @@ public class CreateAndDeletePolicyTest e
                             }
                         }
 
-                        f = createResult(FAILURE,
-                                "Policy has not been removed from document! Policy Id: "
+ policy.getId()
-                                        + ", Doc Id: " + doc.getId());
+                        f = createResult(FAILURE, "Policy has not been removed from document!
Policy Id: "
+                                + policy.getId() + ", Doc Id: " + doc.getId());
                         addResult(assertIsFalse(found3, null, f));
                     }
                 } else {
-                    addResult(createResult(
-                            INFO,
-                            "Document type "
-                                    + doc.getType().getId()
-                                    + " does not allow applying and removing policies. Choose
a different document type for this test."));
+                    addResult(createResult(INFO, "Document type " + doc.getType().getId()
+                            + " does not allow applying and removing policies. Choose a different
document type for this test."));
                 }
 
                 // delete document



Mime
View raw message