You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2015/05/12 17:53:45 UTC

svn commit: r1678988 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/...

Author: fmui
Date: Tue May 12 15:53:45 2015
New Revision: 1678988

URL: http://svn.apache.org/r1678988
Log:
Client: catch CmisObjects without properties and object ID

Modified:
    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/main/java/org/apache/chemistry/opencmis/client/runtime/SessionFactoryImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/checks/TypeComplianceCheck.java

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=1678988&r1=1678987&r2=1678988&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 Tue May 12 15:53:45 2015
@@ -95,12 +95,24 @@ public abstract class AbstractCmisObject
             throw new IllegalArgumentException("Object type must be set!");
         }
 
-        if ((objectType.getPropertyDefinitions() == null) || objectType.getPropertyDefinitions().size() < 9) {
+        if (objectType.getPropertyDefinitions() == null || objectType.getPropertyDefinitions().size() < 9) {
             // there must be at least the 9 standard properties that all objects
             // have
             throw new IllegalArgumentException("Object type must have property definitions!");
         }
 
+        if (objectData == null) {
+            throw new IllegalArgumentException("Object data must be set!");
+        }
+
+        if (objectData.getProperties() == null) {
+            throw new IllegalArgumentException("Properties must be set!");
+        }
+
+        if (objectData.getId() == null) {
+            throw new IllegalArgumentException("Object ID must be set!");
+        }
+
         this.session = session;
         this.objectType = objectType;
         this.secondaryTypes = null;
@@ -110,108 +122,100 @@ public abstract class AbstractCmisObject
 
         ObjectFactory of = getObjectFactory();
 
-        if (objectData != null) {
-
-            // handle properties
-            if (objectData.getProperties() != null) {
-
-                // get secondary types
-                if (objectData.getProperties().getProperties() != null
-                        && objectData.getProperties().getProperties()
-                                .containsKey(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
-                    @SuppressWarnings("unchecked")
-                    List<String> stids = (List<String>) objectData.getProperties().getProperties()
-                            .get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
-                    if (isNotEmpty(stids)) {
-                        secondaryTypes = new ArrayList<SecondaryType>();
-                        for (String stid : stids) {
-                            if (stid != null) {
-                                ObjectType type = session.getTypeDefinition(stid);
-                                if (type instanceof SecondaryType) {
-                                    secondaryTypes.add((SecondaryType) type);
-                                }
-                            }
+        // get secondary types
+        if (objectData.getProperties().getProperties() != null
+                && objectData.getProperties().getProperties().containsKey(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
+            @SuppressWarnings("unchecked")
+            List<String> stids = (List<String>) objectData.getProperties().getProperties()
+                    .get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
+            if (isNotEmpty(stids)) {
+                secondaryTypes = new ArrayList<SecondaryType>();
+                for (String stid : stids) {
+                    if (stid != null) {
+                        ObjectType type = session.getTypeDefinition(stid);
+                        if (type instanceof SecondaryType) {
+                            secondaryTypes.add((SecondaryType) type);
                         }
                     }
                 }
-
-                this.properties = of.convertProperties(objectType, secondaryTypes, objectData.getProperties());
-                extensions.put(ExtensionLevel.PROPERTIES, objectData.getProperties().getExtensions());
             }
+        }
 
-            // handle allowable actions
-            if (objectData.getAllowableActions() != null) {
-                this.allowableActions = objectData.getAllowableActions();
-                extensions.put(ExtensionLevel.ALLOWABLE_ACTIONS, objectData.getAllowableActions().getExtensions());
-            }
+        // handle properties
+        this.properties = of.convertProperties(objectType, secondaryTypes, objectData.getProperties());
+        extensions.put(ExtensionLevel.PROPERTIES, objectData.getProperties().getExtensions());
+
+        // handle allowable actions
+        if (objectData.getAllowableActions() != null) {
+            this.allowableActions = objectData.getAllowableActions();
+            extensions.put(ExtensionLevel.ALLOWABLE_ACTIONS, objectData.getAllowableActions().getExtensions());
+        }
 
-            // handle renditions
-            if (objectData.getRenditions() != null) {
-                this.renditions = new ArrayList<Rendition>();
-                for (RenditionData rd : objectData.getRenditions()) {
-                    this.renditions.add(of.convertRendition(getId(), rd));
-                }
+        // handle renditions
+        if (objectData.getRenditions() != null) {
+            this.renditions = new ArrayList<Rendition>();
+            for (RenditionData rd : objectData.getRenditions()) {
+                this.renditions.add(of.convertRendition(getId(), rd));
             }
+        }
 
-            // handle ACL
-            if (objectData.getAcl() != null) {
-                acl = objectData.getAcl();
-                extensions.put(ExtensionLevel.ACL, objectData.getAcl().getExtensions());
-
-                if (objectData.isExactAcl() != null) {
-                    final Acl objectAcl = objectData.getAcl();
-                    final Boolean isExact = objectData.isExactAcl();
-                    acl = new Acl() {
-
-                        @Override
-                        public void setExtensions(List<CmisExtensionElement> extensions) {
-                            objectAcl.setExtensions(extensions);
-                        }
+        // handle ACL
+        if (objectData.getAcl() != null) {
+            acl = objectData.getAcl();
+            extensions.put(ExtensionLevel.ACL, objectData.getAcl().getExtensions());
+
+            if (objectData.isExactAcl() != null) {
+                final Acl objectAcl = objectData.getAcl();
+                final Boolean isExact = objectData.isExactAcl();
+                acl = new Acl() {
+
+                    @Override
+                    public void setExtensions(List<CmisExtensionElement> extensions) {
+                        objectAcl.setExtensions(extensions);
+                    }
 
-                        @Override
-                        public List<CmisExtensionElement> getExtensions() {
-                            return objectAcl.getExtensions();
-                        }
+                    @Override
+                    public List<CmisExtensionElement> getExtensions() {
+                        return objectAcl.getExtensions();
+                    }
 
-                        @Override
-                        public Boolean isExact() {
-                            return isExact;
-                        }
+                    @Override
+                    public Boolean isExact() {
+                        return isExact;
+                    }
 
-                        @Override
-                        public List<Ace> getAces() {
-                            return objectAcl.getAces();
-                        }
-                    };
-                }
+                    @Override
+                    public List<Ace> getAces() {
+                        return objectAcl.getAces();
+                    }
+                };
             }
+        }
 
-            // handle policies
-            if ((objectData.getPolicyIds() != null) && (objectData.getPolicyIds().getPolicyIds() != null)) {
-                policies = new ArrayList<Policy>();
-                for (String pid : objectData.getPolicyIds().getPolicyIds()) {
-                    CmisObject policy = session.getObject(pid);
-                    if (policy instanceof Policy) {
-                        policies.add((Policy) policy);
-                    }
+        // handle policies
+        if ((objectData.getPolicyIds() != null) && (objectData.getPolicyIds().getPolicyIds() != null)) {
+            policies = new ArrayList<Policy>();
+            for (String pid : objectData.getPolicyIds().getPolicyIds()) {
+                CmisObject policy = session.getObject(pid);
+                if (policy instanceof Policy) {
+                    policies.add((Policy) policy);
                 }
-                extensions.put(ExtensionLevel.POLICIES, objectData.getPolicyIds().getExtensions());
             }
+            extensions.put(ExtensionLevel.POLICIES, objectData.getPolicyIds().getExtensions());
+        }
 
-            // handle relationships
-            if (objectData.getRelationships() != null) {
-                relationships = new ArrayList<Relationship>();
-                for (ObjectData rod : objectData.getRelationships()) {
-                    CmisObject relationship = of.convertObject(rod, this.creationContext);
-                    if (relationship instanceof Relationship) {
-                        relationships.add((Relationship) relationship);
-                    }
+        // handle relationships
+        if (objectData.getRelationships() != null) {
+            relationships = new ArrayList<Relationship>();
+            for (ObjectData rod : objectData.getRelationships()) {
+                CmisObject relationship = of.convertObject(rod, this.creationContext);
+                if (relationship instanceof Relationship) {
+                    relationships.add((Relationship) relationship);
                 }
             }
-
-            extensions.put(ExtensionLevel.OBJECT, objectData.getExtensions());
         }
 
+        extensions.put(ExtensionLevel.OBJECT, objectData.getExtensions());
     }
 
     /**
@@ -476,7 +480,7 @@ public abstract class AbstractCmisObject
     public List<Property<?>> getProperties() {
         readLock();
         try {
-            return Collections.unmodifiableList(new ArrayList<Property<?>>(this.properties.values()));
+            return Collections.unmodifiableList(new ArrayList<Property<?>>(properties.values()));
         } finally {
             readUnlock();
         }
@@ -486,7 +490,7 @@ public abstract class AbstractCmisObject
     public <T> Property<T> getProperty(String id) {
         readLock();
         try {
-            return (Property<T>) this.properties.get(id);
+            return (Property<T>) properties.get(id);
         } finally {
             readUnlock();
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionFactoryImpl.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/SessionFactoryImpl.java?rev=1678988&r1=1678987&r2=1678988&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionFactoryImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionFactoryImpl.java Tue May 12 15:53:45 2015
@@ -50,7 +50,7 @@ import org.apache.chemistry.opencmis.com
  * <p>
  * <code>
  * Context ctx = new DefaultContext();<br>
- * SessionFactory = ctx.lookup(jndi_key);
+ * SessionFactory sf = ctx.lookup(jndi_key);
  * </code>
  */
 public class SessionFactoryImpl implements SessionFactory, Serializable {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.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/repository/ObjectFactoryImpl.java?rev=1678988&r1=1678987&r2=1678988&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java Tue May 12 15:53:45 2015
@@ -18,7 +18,8 @@
  */
 package org.apache.chemistry.opencmis.client.runtime.repository;
 
-import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.*;
+import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNotEmpty;
+import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNullOrEmpty;
 
 import java.io.InputStream;
 import java.io.Serializable;
@@ -590,6 +591,10 @@ public class ObjectFactoryImpl implement
             throw new IllegalArgumentException("Object data is null!");
         }
 
+        if (objectData.getId() == null) {
+            throw new IllegalArgumentException("Object ID property not set!");
+        }
+
         if (objectData.getBaseTypeId() == null) {
             throw new IllegalArgumentException("Base type ID property not set!");
         }
@@ -599,15 +604,15 @@ public class ObjectFactoryImpl implement
         /* determine type */
         switch (objectData.getBaseTypeId()) {
         case CMIS_DOCUMENT:
-            return new DocumentImpl((SessionImpl) this.session, type, objectData, context);
+            return new DocumentImpl((SessionImpl) session, type, objectData, context);
         case CMIS_FOLDER:
-            return new FolderImpl((SessionImpl) this.session, type, objectData, context);
+            return new FolderImpl((SessionImpl) session, type, objectData, context);
         case CMIS_POLICY:
-            return new PolicyImpl((SessionImpl) this.session, type, objectData, context);
+            return new PolicyImpl((SessionImpl) session, type, objectData, context);
         case CMIS_RELATIONSHIP:
-            return new RelationshipImpl((SessionImpl) this.session, type, objectData, context);
+            return new RelationshipImpl((SessionImpl) session, type, objectData, context);
         case CMIS_ITEM:
-            return new ItemImpl((SessionImpl) this.session, type, objectData, context);
+            return new ItemImpl((SessionImpl) session, type, objectData, context);
         case CMIS_SECONDARY:
             throw new CmisRuntimeException("Secondary type is used as object type: " + objectData.getBaseTypeId());
         default:

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/checks/TypeComplianceCheck.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/checks/TypeComplianceCheck.java?rev=1678988&r1=1678987&r2=1678988&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/checks/TypeComplianceCheck.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/checks/TypeComplianceCheck.java Tue May 12 15:53:45 2015
@@ -46,7 +46,7 @@ public class TypeComplianceCheck extends
     public final void run(Session session) {
         ObjectType type = session.getTypeDefinition(typeId);
 
-        addResult(checkTypeDefinition(session, type, "Type check:" + type.getId()));
+        addResult(checkTypeDefinition(session, type, "Type check: " + type.getId()));
 
         if (getResults().isEmpty()) {
             addResult(createResult(CmisTestResultStatus.OK, "Type seems to be compliant! ID: " + type.getId()));