Author: fmui
Date: Fri Aug  5 15:41:51 2016
New Revision: 1755353

URL: http://svn.apache.org/viewvc?rev=1755353&view=rev
Log:
Client: added new convenience methods to CmisObject (updating secondary types)

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/types/SecondaryTypesTest.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=1755353&r1=1755352&r2=1755353&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
 Fri Aug  5 15:41:51 2016
@@ -152,6 +152,57 @@ public interface CmisObject extends Obje
     ObjectId updateProperties(Map<String, ?> properties, boolean refresh);
 
     /**
+     * Updates the provided properties and refreshes this object afterwards. If
+     * the repository created a new object, for example a new version, this new
+     * object is returned. Otherwise the current object is returned.
+     * 
+     * Secondary types must be supported by the repository and must have been
+     * retrieved for this object.
+     * 
+     * @param properties
+     *            the properties to update
+     * @param addSecondaryTypeIds
+     *            list of secondary type IDs that should be added, may be
+     *            {@code null}
+     * @param removeSecondaryTypeIds
+     *            list of secondary type IDs that should be removed, may be
+     *            {@code null}
+     * 
+     * @return the updated object
+     * 
+     * @cmis 1.1
+     */
+    CmisObject updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds);
+
+    /**
+     * Updates the provided properties. If the repository created a new object,
+     * for example a new version, the object ID of the new object is returned.
+     * Otherwise the object ID of the current object is returned.
+     * 
+     * Secondary types must be supported by the repository and must have been
+     * retrieved for this object.
+     * 
+     * @param properties
+     *            the properties to update
+     * @param addSecondaryTypeIds
+     *            list of secondary type IDs that should be added, may be
+     *            {@code null}
+     * @param removeSecondaryTypeIds
+     *            list of secondary type IDs that should be removed, may be
+     *            {@code null}
+     * @param refresh
+     *            {@code true} if this object should be refreshed after the
+     *            update, {@code false} if not
+     * 
+     * @return the object ID of the updated object
+     * 
+     * @cmis 1.1
+     */
+    ObjectId updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds, boolean refresh);
+
+    /**
      * Renames this object (changes the value of {@code cmis:name}). If the
      * repository created a new object, for example a new version, this new
      * object is returned. Otherwise the current object is returned.

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=1755353&r1=1755352&r2=1755353&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
 Fri Aug  5 15:41:51 2016
@@ -424,6 +424,68 @@ public abstract class AbstractCmisObject
     }
 
     @Override
+    public CmisObject updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds) {
+        ObjectId objectId = updateProperties(properties, addSecondaryTypeIds, 
removeSecondaryTypeIds, true);
+        if (objectId == null) {
+            return null;
+        }
+
+        if (!getObjectId().equals(objectId.getId())) {
+            return getSession().getObject(objectId, getCreationContext());
+        }
+
+        return this;
+    }
+
+    @Override
+    public ObjectId updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds, boolean refresh) {
+        if ((addSecondaryTypeIds == null || addSecondaryTypeIds.isEmpty())
+                && (removeSecondaryTypeIds == null || 
removeSecondaryTypeIds.isEmpty())) {
+            return updateProperties(properties, refresh);
+        }
+
+        List<String> secondaryTypeIds = new ArrayList<String>();
+
+        readLock();
+        try {
+            // check if secondary types have been fetched
+            if 
(!this.properties.containsKey(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
+                throw new IllegalStateException("Secondary Object Type Ids are 
not available!");
+            }
+
+            // compile new list of secondary type IDs
+            if (secondaryTypes != null) {
+                for (SecondaryType type : secondaryTypes) {
+                    if (removeSecondaryTypeIds == null || 
!removeSecondaryTypeIds.contains(type.getId())) {
+                        secondaryTypeIds.add(type.getId());
+                    }
+                }
+            }
+
+            if (addSecondaryTypeIds != null) {
+                for (String addId : addSecondaryTypeIds) {
+                    if (!secondaryTypeIds.contains(addId)) {
+                        secondaryTypeIds.add(addId);
+                    }
+                }
+            }
+        } finally {
+            readUnlock();
+        }
+
+        // set up properties
+        Map<String, Object> newProperties = new HashMap<String, Object>();
+        if (properties != null) {
+            newProperties.putAll(properties);
+        }
+        newProperties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, 
secondaryTypeIds);
+
+        return updateProperties(newProperties, refresh);
+    }
+
+    @Override
     public CmisObject rename(String newName) {
         if (newName == null || newName.length() == 0) {
             throw new IllegalArgumentException("New name must not be empty!");

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=1755353&r1=1755352&r2=1755353&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
 Fri Aug  5 15:41:51 2016
@@ -223,6 +223,18 @@ public class CmisObjectMock implements C
     }
 
     @Override
+    public CmisObject updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds) {
+        return null;
+    }
+
+    @Override
+    public ObjectId updateProperties(Map<String, ?> properties, List<String> 
addSecondaryTypeIds,
+            List<String> removeSecondaryTypeIds, boolean refresh) {
+        return null;
+    }
+
+    @Override
     public CmisObject rename(String newName) {
         return null;
     }

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.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/types/SecondaryTypesTest.java?rev=1755353&r1=1755352&r2=1755353&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java
 Fri Aug  5 15:41:51 2016
@@ -21,8 +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.SKIPPED;
 
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -105,24 +104,8 @@ public class SecondaryTypesTest extends
                 checkedout = true;
             }
 
-            // -- attach secondary type
-            List<String> secondaryTypes = new ArrayList<String>();
-
-            // copy already attached secondary types, if there are any
-            if (workDoc.getSecondaryTypes() != null) {
-                for (SecondaryType secType : workDoc.getSecondaryTypes()) {
-                    secondaryTypes.add(secType.getId());
-                }
-            }
-
-            // add the new secondary type
-            secondaryTypes.add(secondaryTestType.getId());
-
-            Map<String, Object> properties = new HashMap<String, Object>();
-            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, 
secondaryTypes);
-
             // attach secondary type
-            ObjectId newId = workDoc.updateProperties(properties);
+            ObjectId newId = workDoc.updateProperties(null, 
Collections.singletonList(secondaryTestType.getId()), null);
             Document newDoc = (Document) session.getObject(newId, 
SELECT_ALL_NO_CACHE_OC);
 
             // check if the secondary type is there
@@ -213,19 +196,8 @@ public class SecondaryTypesTest extends
     private void detachSecondaryType(Session session, Document doc, ObjectType 
secondaryTestType) {
         CmisTestResult f;
 
-        List<String> secondaryTypesId = new ArrayList<String>();
-
-        for (SecondaryType secType : doc.getSecondaryTypes()) {
-            if (!secondaryTestType.getId().equals(secType.getId())) {
-                secondaryTypesId.add(secType.getId());
-            }
-        }
-
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, 
secondaryTypesId);
-
         // detach secondary type
-        ObjectId newId = doc.updateProperties(properties);
+        ObjectId newId = doc.updateProperties(null, null, 
Collections.singletonList(secondaryTestType.getId()));
         Document newDoc = (Document) session.getObject(newId, 
SELECT_ALL_NO_CACHE_OC);
 
         boolean found = false;


Reply via email to