chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r921267 - in /incubator/chemistry/trunk/opencmis/opencmis-client: opencmis-client-api/src/main/java/org/apache/opencmis/client/api/ opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ opencmis-client-api/src/main/ja...
Date Wed, 10 Mar 2010 09:28:00 GMT
Author: fmui
Date: Wed Mar 10 09:28:00 2010
New Revision: 921267

URL: http://svn.apache.org/viewvc?rev=921267&view=rev
Log:
client API clean up and refactoring

Removed:
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/PropertyFactory.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Testable.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentPropertyFactoryImpl.java
Modified:
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/Fixture.java

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java Wed Mar 10 09:28:00 2010
@@ -24,7 +24,6 @@ import java.util.Set;
 
 import org.apache.opencmis.client.api.objecttype.ObjectType;
 import org.apache.opencmis.client.api.repository.ObjectFactory;
-import org.apache.opencmis.client.api.repository.PropertyFactory;
 import org.apache.opencmis.client.api.repository.RepositoryInfo;
 import org.apache.opencmis.client.api.util.Container;
 import org.apache.opencmis.client.api.util.PagingList;
@@ -98,11 +97,6 @@ public interface Session {
    */
   ObjectFactory getObjectFactory();
 
-  /**
-   * Gets the factory for <code>Property</code> objects.
-   */
-  PropertyFactory getPropertyFactory();
-
   // types
 
   /**

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java Wed Mar 10 09:28:00 2010
@@ -19,6 +19,7 @@
 package org.apache.opencmis.client.api.repository;
 
 import java.io.InputStream;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -27,15 +28,21 @@ import org.apache.opencmis.client.api.Ac
 import org.apache.opencmis.client.api.AllowableActions;
 import org.apache.opencmis.client.api.CmisObject;
 import org.apache.opencmis.client.api.ContentStream;
-import org.apache.opencmis.client.api.Document;
-import org.apache.opencmis.client.api.Folder;
 import org.apache.opencmis.client.api.OperationContext;
 import org.apache.opencmis.client.api.Policy;
 import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.QueryProperty;
 import org.apache.opencmis.client.api.QueryResult;
-import org.apache.opencmis.client.api.Relationship;
-import org.apache.opencmis.commons.enums.VersioningState;
+import org.apache.opencmis.client.api.Rendition;
+import org.apache.opencmis.client.api.objecttype.ObjectType;
+import org.apache.opencmis.commons.api.PropertyDefinition;
+import org.apache.opencmis.commons.api.TypeDefinition;
+import org.apache.opencmis.commons.provider.AccessControlList;
+import org.apache.opencmis.commons.provider.AllowableActionsData;
+import org.apache.opencmis.commons.provider.ContentStreamData;
 import org.apache.opencmis.commons.provider.ObjectData;
+import org.apache.opencmis.commons.provider.PropertiesData;
+import org.apache.opencmis.commons.provider.RenditionData;
 
 /**
  * A factory to create CMIS objects.
@@ -44,18 +51,56 @@ import org.apache.opencmis.commons.provi
  */
 public interface ObjectFactory {
 
-  // object factory
+  // allowable actions
 
   AllowableActions createAllowableAction(Map<String, Boolean> actions);
 
+  AllowableActions convertAllowableActions(AllowableActionsData allowableActions);
+
+  // ACL and ACE
+
   Ace createAce(String principal, List<String> permissions, boolean isDirect);
 
   Acl createAcl(List<Ace> aces, Boolean isExact);
 
+  AccessControlList convertAces(List<Ace> aces);
+
+  Acl convertAcl(AccessControlList acl);
+
+  // policies
+
+  List<String> convertPolicies(List<Policy> policies);
+
+  // renditions
+
+  Rendition convertRendition(String objectId, RenditionData rendition);
+
+  // content stream
+
   ContentStream createContentStream(String filename, long length, String mimetype,
       InputStream stream);
 
-  // object service
+  ContentStreamData convertContentStream(ContentStream contentStream);
+
+  // types
+
+  ObjectType convertTypeDefinition(TypeDefinition typeDefinition);
+
+  ObjectType getTypeFromObjectData(ObjectData objectData);
+
+  // properties
+
+  <T> Property<T> createProperty(PropertyDefinition<T> type, T value);
+
+  <T> Property<T> createPropertyMultivalue(PropertyDefinition<T> type, List<T> values);
+
+  Map<String, Property<?>> convertProperties(ObjectType objectType, PropertiesData properties);
+
+  PropertiesData convertProperties(Collection<Property<?>> properties);
+
+  List<QueryProperty<?>> convertQueryProperties(PropertiesData properties);
+
+  // objects
 
   CmisObject convertObject(ObjectData objectData, OperationContext context);
 

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java Wed Mar 10 09:28:00 2010
@@ -91,30 +91,30 @@ public abstract class AbstractPersistent
     this.objectType = objectType;
     this.creationContext = new OperationContextImpl(context);
 
+    ObjectFactory of = getObjectFactory();
+
     if (objectData != null) {
       // handle properties
       if (objectData.getProperties() != null) {
-        this.properties = SessionUtil.convertProperties(session, objectType, objectData
-            .getProperties());
+        this.properties = of.convertProperties(objectType, objectData.getProperties());
       }
 
       // handle allowable actions
       if (objectData.getAllowableActions() != null) {
-        this.allowableActions = SessionUtil.convertAllowableActions(session, objectData
-            .getAllowableActions());
+        this.allowableActions = of.convertAllowableActions(objectData.getAllowableActions());
       }
 
       // handle renditions
       if (objectData.getRenditions() != null) {
         this.renditions = new ArrayList<Rendition>();
         for (RenditionData rd : objectData.getRenditions()) {
-          this.renditions.add(SessionUtil.convertRendition(session, getId(), rd));
+          this.renditions.add(of.convertRendition(getId(), rd));
         }
       }
 
       // handle ACL
       if (objectData.getAcl() != null) {
-        acl = SessionUtil.convertAcl(session, objectData.getAcl());
+        acl = of.convertAcl(objectData.getAcl());
       }
 
       // handle policies
@@ -131,7 +131,6 @@ public abstract class AbstractPersistent
       // handle relationships
       if (objectData.getRelationships() != null) {
         relationships = new ArrayList<Relationship>();
-        ObjectFactory of = session.getObjectFactory();
         for (ObjectData rod : objectData.getRelationships()) {
           CmisObject relationship = of.convertObject(rod, this.creationContext);
           if (relationship instanceof Relationship) {
@@ -173,6 +172,13 @@ public abstract class AbstractPersistent
   }
 
   /**
+   * Returns the object factory.
+   */
+  protected ObjectFactory getObjectFactory() {
+    return getSession().getObjectFactory();
+  }
+
+  /**
    * Returns the id of this object or throws an exception if the id is unknown.
    */
   protected String getObjectId() {
@@ -209,7 +215,7 @@ public abstract class AbstractPersistent
     Holder<String> changeTokenHolder = new Holder<String>(changeToken);
 
     getProvider().getObjectService().updateProperties(getRepositoryId(), objectIdHolder,
-        changeTokenHolder, SessionUtil.convertProperties(getSession(), properties.values()), null);
+        changeTokenHolder, getObjectFactory().convertProperties(properties.values()), null);
   }
 
   // --- properties ---
@@ -234,7 +240,12 @@ public abstract class AbstractPersistent
    * @see org.apache.opencmis.client.api.CmisObject#getBaseTypeId()
    */
   public BaseObjectTypeIds getBaseTypeId() {
-    return BaseObjectTypeIds.fromValue((String) getPropertyValue(PropertyIds.CMIS_BASE_TYPE_ID));
+    String baseType = getPropertyValue(PropertyIds.CMIS_BASE_TYPE_ID);
+    if (baseType == null) {
+      return null;
+    }
+
+    return BaseObjectTypeIds.fromValue(baseType);
   }
 
   /*
@@ -429,7 +440,7 @@ public abstract class AbstractPersistent
       throw new IllegalArgumentException("Value does not match property type!");
     }
 
-    Property<T> newProperty = (Property<T>) getSession().getPropertyFactory()
+    Property<T> newProperty = (Property<T>) getSession().getObjectFactory()
         .createPropertyMultivalue((PropertyDefinition<T>) propertyDefinition, value);
 
     setChanged();
@@ -476,8 +487,11 @@ public abstract class AbstractPersistent
    */
   public Acl getAcl(boolean onlyBasicPermissions) {
     String objectId = getObjectId();
-    return SessionUtil.convertAcl(getSession(), getProvider().getAclService().getAcl(
-        getRepositoryId(), objectId, onlyBasicPermissions, null));
+
+    ObjectFactory of = getObjectFactory();
+
+    return of.convertAcl(getProvider().getAclService().getAcl(getRepositoryId(), objectId,
+        onlyBasicPermissions, null));
   }
 
   /*
@@ -488,9 +502,11 @@ public abstract class AbstractPersistent
    */
   public Acl applyAcl(List<Ace> addAces, List<Ace> removeAces, AclPropagation aclPropagation) {
     String objectId = getObjectId();
-    return SessionUtil.convertAcl(getSession(), getProvider().getAclService().applyAcl(
-        getRepositoryId(), objectId, SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), aclPropagation, null));
+
+    ObjectFactory of = getObjectFactory();
+
+    return of.convertAcl(getProvider().getAclService().applyAcl(getRepositoryId(), objectId,
+        of.convertAces(addAces), of.convertAces(removeAces), aclPropagation, null));
   }
 
   /*
@@ -531,11 +547,8 @@ public abstract class AbstractPersistent
    * org.apache.opencmis.client.api.CmisObject#applyPolicy(org.apache.opencmis.client.api.ObjectId)
    */
   public void applyPolicy(ObjectId policyId) {
-    if (policyId == null) {
-      throw new IllegalArgumentException("Policy is not set!");
-    }
-    if (policyId.getId() == null) {
-      throw new IllegalArgumentException("Policy id is not set!");
+    if ((policyId == null) || (policyId.getId() == null)) {
+      throw new IllegalArgumentException("Policy Id is not set!");
     }
 
     String objectId = getObjectId();
@@ -550,11 +563,8 @@ public abstract class AbstractPersistent
    * org.apache.opencmis.client.api.CmisObject#removePolicy(org.apache.opencmis.client.api.ObjectId)
    */
   public void removePolicy(ObjectId policyId) {
-    if (policyId == null) {
-      throw new IllegalArgumentException("Policy is not set!");
-    }
-    if (policyId.getId() == null) {
-      throw new IllegalArgumentException("Policy id is not set!");
+    if ((policyId == null) || (policyId.getId() == null)) {
+      throw new IllegalArgumentException("Policy Id is not set!");
     }
 
     String objectId = getObjectId();
@@ -619,8 +629,8 @@ public abstract class AbstractPersistent
         List<Relationship> page = new ArrayList<Relationship>();
         if (relList.getObjects() != null) {
           for (ObjectData rod : relList.getObjects()) {
-            Relationship relationship = new PersistentRelationshipImpl(getSession(), SessionUtil
-                .getTypeFromObjectData(getSession(), rod), rod, ctxt);
+            Relationship relationship = new PersistentRelationshipImpl(getSession(),
+                getObjectFactory().getTypeFromObjectData(rod), rod, ctxt);
 
             page.add(relationship);
           }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java Wed Mar 10 09:28:00 2010
@@ -46,8 +46,9 @@ public abstract class AbstractPersistent
    * @see org.apache.opencmis.client.api.FileableCmisObject#getParents()
    */
   public List<Folder> getParents() {
-    // get object ids of the parent folders
     String objectId = getObjectId();
+
+    // get object ids of the parent folders
     List<ObjectParentData> providerParents = getProvider().getNavigationService().getObjectParents(
         getRepositoryId(), objectId, PropertyIds.CMIS_OBJECT_ID, false, IncludeRelationships.NONE,
         null, false, null);
@@ -88,8 +89,9 @@ public abstract class AbstractPersistent
    * @see org.apache.opencmis.client.api.FileableCmisObject#getPaths()
    */
   public List<String> getPaths() {
-    // get object paths of the parent folders
     String objectId = getObjectId();
+
+    // get object paths of the parent folders
     List<ObjectParentData> providerParents = getProvider().getNavigationService().getObjectParents(
         getRepositoryId(), objectId, PropertyIds.CMIS_PATH, false, IncludeRelationships.NONE, null,
         true, null);

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentDocumentImpl.java Wed Mar 10 09:28:00 2010
@@ -167,11 +167,11 @@ public class PersistentDocumentImpl exte
     String objectId = getObjectId();
     Holder<String> objectIdHolder = new Holder<String>(objectId);
 
+    ObjectFactory of = getObjectFactory();
+
     getProvider().getVersioningService().checkIn(getRepositoryId(), objectIdHolder, major,
-        SessionUtil.convertProperties(getSession(), properties),
-        SessionUtil.convertContentStream(getSession(), contentStream), checkinComment,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), null);
+        of.convertProperties(properties), of.convertContentStream(contentStream), checkinComment,
+        of.convertPolicies(policies), of.convertAces(addAces), of.convertAces(removeAces), null);
 
     if (objectIdHolder.getValue() == null) {
       return null;
@@ -293,7 +293,7 @@ public class PersistentDocumentImpl exte
     Holder<String> changeTokenHolder = new Holder<String>(changeToken);
 
     getProvider().getObjectService().setContentStream(getRepositoryId(), objectIdHolder, overwrite,
-        changeTokenHolder, SessionUtil.convertContentStream(getSession(), contentStream), null);
+        changeTokenHolder, getObjectFactory().convertContentStream(contentStream), null);
 
     if (objectIdHolder.getValue() == null) {
       return null;

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java Wed Mar 10 09:28:00 2010
@@ -77,11 +77,12 @@ public class PersistentFolderImpl extend
       List<Ace> removeAces, OperationContext context) {
     String objectId = getObjectId();
 
+    ObjectFactory of = getObjectFactory();
+
     String newId = getProvider().getObjectService().createDocument(getRepositoryId(),
-        SessionUtil.convertProperties(getSession(), properties), objectId,
-        SessionUtil.convertContentStream(getSession(), contentStream), versioningState,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), null);
+        of.convertProperties(properties), objectId, of.convertContentStream(contentStream),
+        versioningState, of.convertPolicies(policies), of.convertAces(addAces),
+        of.convertAces(removeAces), null);
 
     // if no context is provided the object will not be fetched
     if ((context == null) || (newId == null)) {
@@ -114,11 +115,11 @@ public class PersistentFolderImpl extend
       throw new IllegalArgumentException("Source must be set!");
     }
 
+    ObjectFactory of = getObjectFactory();
+
     String newId = getProvider().getObjectService().createDocumentFromSource(getRepositoryId(),
-        source.getId(), SessionUtil.convertProperties(getSession(), properties), objectId,
-        versioningState, SessionUtil.convertPolicies(policies),
-        SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), null);
+        source.getId(), of.convertProperties(properties), objectId, versioningState,
+        of.convertPolicies(policies), of.convertAces(addAces), of.convertAces(removeAces), null);
 
     // if no context is provided the object will not be fetched
     if ((context == null) || (newId == null)) {
@@ -144,10 +145,11 @@ public class PersistentFolderImpl extend
       List<Ace> addAces, List<Ace> removeAces, OperationContext context) {
     String objectId = getObjectId();
 
+    ObjectFactory of = getObjectFactory();
+
     String newId = getProvider().getObjectService().createFolder(getRepositoryId(),
-        SessionUtil.convertProperties(getSession(), properties), objectId,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), null);
+        of.convertProperties(properties), objectId, of.convertPolicies(policies),
+        of.convertAces(addAces), of.convertAces(removeAces), null);
 
     // if no context is provided the object will not be fetched
     if ((context == null) || (newId == null)) {
@@ -173,10 +175,11 @@ public class PersistentFolderImpl extend
       List<Ace> addAces, List<Ace> removeAces, OperationContext context) {
     String objectId = getObjectId();
 
+    ObjectFactory of = getObjectFactory();
+
     String newId = getProvider().getObjectService().createPolicy(getRepositoryId(),
-        SessionUtil.convertProperties(getSession(), properties), objectId,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(getSession(), addAces),
-        SessionUtil.convertAces(getSession(), removeAces), null);
+        of.convertProperties(properties), objectId, of.convertPolicies(policies),
+        of.convertAces(addAces), of.convertAces(removeAces), null);
 
     // if no context is provided the object will not be fetched
     if ((context == null) || (newId == null)) {

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java Wed Mar 10 09:28:00 2010
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
-import java.util.UUID;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -42,19 +41,15 @@ import org.apache.opencmis.client.api.Pe
 import org.apache.opencmis.client.api.Policy;
 import org.apache.opencmis.client.api.Property;
 import org.apache.opencmis.client.api.QueryResult;
-import org.apache.opencmis.client.api.Session;
 import org.apache.opencmis.client.api.objecttype.ObjectType;
 import org.apache.opencmis.client.api.repository.ObjectFactory;
-import org.apache.opencmis.client.api.repository.PropertyFactory;
 import org.apache.opencmis.client.api.repository.RepositoryInfo;
 import org.apache.opencmis.client.api.util.Container;
 import org.apache.opencmis.client.api.util.PagingList;
-import org.apache.opencmis.client.api.util.Testable;
 import org.apache.opencmis.client.provider.factory.CmisProviderFactory;
 import org.apache.opencmis.client.runtime.cache.Cache;
 import org.apache.opencmis.client.runtime.cache.CacheImpl;
 import org.apache.opencmis.client.runtime.repository.PersistentObjectFactoryImpl;
-import org.apache.opencmis.client.runtime.repository.PersistentPropertyFactoryImpl;
 import org.apache.opencmis.client.runtime.util.AbstractPagingList;
 import org.apache.opencmis.client.runtime.util.ContainerImpl;
 import org.apache.opencmis.commons.SessionParameter;
@@ -62,23 +57,20 @@ import org.apache.opencmis.commons.api.T
 import org.apache.opencmis.commons.api.TypeDefinitionContainer;
 import org.apache.opencmis.commons.api.TypeDefinitionList;
 import org.apache.opencmis.commons.enums.BindingType;
-import org.apache.opencmis.commons.enums.Cardinality;
-import org.apache.opencmis.commons.enums.CmisProperties;
 import org.apache.opencmis.commons.enums.IncludeRelationships;
-import org.apache.opencmis.commons.enums.UnfileObjects;
 import org.apache.opencmis.commons.enums.VersioningState;
 import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
-import org.apache.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
-import org.apache.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
 import org.apache.opencmis.commons.provider.CmisProvider;
 import org.apache.opencmis.commons.provider.DiscoveryService;
 import org.apache.opencmis.commons.provider.NavigationService;
 import org.apache.opencmis.commons.provider.ObjectData;
 import org.apache.opencmis.commons.provider.ObjectList;
 import org.apache.opencmis.commons.provider.RepositoryService;
-import org.apache.opencmis.util.repository.ObjectGenerator;
 
-public class PersistentSessionImpl implements PersistentSession, Testable, Serializable {
+/**
+ * Persistent model session.
+ */
+public class PersistentSessionImpl implements PersistentSession, Serializable {
 
   private static final OperationContext DEFAULT_CONTEXT = new OperationContextImpl(null, false,
       true, false, IncludeRelationships.NONE, null, true, null, true);
@@ -91,11 +83,6 @@ public class PersistentSessionImpl imple
   private OperationContext context = DEFAULT_CONTEXT;
 
   /*
-   * root folder containing generated test data (not serializable)
-   */
-  private transient Folder testRootFolder = null;
-
-  /*
    * session parameter (serializable)
    */
   private Map<String, String> parameters = null;
@@ -111,12 +98,6 @@ public class PersistentSessionImpl imple
   private Locale locale = null;
 
   /*
-   * helper factory (non serializable)
-   */
-  private transient PropertyFactory propertyFactory = PersistentPropertyFactoryImpl
-      .newInstance(this);
-
-  /*
    * Object cache (serializable)
    */
   private Cache cache = null;
@@ -137,6 +118,9 @@ public class PersistentSessionImpl imple
    */
   private static final long serialVersionUID = -4287481628831198383L;
 
+  /**
+   * Constructor.
+   */
   public PersistentSessionImpl(Map<String, String> parameters) {
     this.parameters = parameters;
     PersistentSessionImpl.log.info("Session Parameters: " + parameters);
@@ -224,6 +208,15 @@ public class PersistentSessionImpl imple
   /*
    * (non-Javadoc)
    * 
+   * @see org.apache.opencmis.client.api.Session#getObjectFactory()
+   */
+  public ObjectFactory getObjectFactory() {
+    return this.objectFactory;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
    * @see org.apache.opencmis.client.api.Session#getCheckedOutDocs(int)
    */
   public PagingList<Document> getCheckedOutDocs(int itemsPerPage) {
@@ -435,14 +428,6 @@ public class PersistentSessionImpl imple
     return result;
   }
 
-  public ObjectFactory getObjectFactory() {
-    return this.objectFactory;
-  }
-
-  public PropertyFactory getPropertyFactory() {
-    return this.propertyFactory;
-  }
-
   /*
    * (non-Javadoc)
    * 
@@ -495,7 +480,6 @@ public class PersistentSessionImpl imple
       throw new IllegalArgumentException("itemsPerPage must be > 0!");
     }
 
-    final Session thisSession = this;
     final String repositoryId = getRepositoryId();
     final RepositoryService repositoryService = getProvider().getRepositoryService();
 
@@ -514,7 +498,7 @@ public class PersistentSessionImpl imple
         // convert type definitions
         List<ObjectType> page = new ArrayList<ObjectType>(tdl.getList().size());
         for (TypeDefinition typeDefinition : tdl.getList()) {
-          page.add(SessionUtil.convertTypeDefinition(thisSession, typeDefinition));
+          page.add(objectFactory.convertTypeDefinition(typeDefinition));
         }
 
         return new FetchResult(page, tdl.getNumItems(), tdl.hasMoreItems());
@@ -535,7 +519,7 @@ public class PersistentSessionImpl imple
   public ObjectType getTypeDefinition(String typeId) {
     TypeDefinition typeDefinition = getProvider().getRepositoryService().getTypeDefinition(
         getRepositoryId(), typeId, null);
-    return SessionUtil.convertTypeDefinition(this, typeDefinition);
+    return objectFactory.convertTypeDefinition(typeDefinition);
   }
 
   /*
@@ -560,8 +544,7 @@ public class PersistentSessionImpl imple
     List<Container<ObjectType>> result = new ArrayList<Container<ObjectType>>();
 
     for (TypeDefinitionContainer container : descendantsList) {
-      ObjectType objectType = SessionUtil
-          .convertTypeDefinition(this, container.getTypeDefinition());
+      ObjectType objectType = objectFactory.convertTypeDefinition(container.getTypeDefinition());
       List<Container<ObjectType>> children = convertTypeDescendants(container.getChildren());
 
       result.add(new ContainerImpl<ObjectType>(objectType, children));
@@ -636,78 +619,6 @@ public class PersistentSessionImpl imple
     throw new CmisRuntimeException("not implemented");
   }
 
-  public void generateTestData(Map<String, String> parameter) {
-    String repositoryId = this.getRepositoryId();
-    ObjectGenerator og = new ObjectGenerator(this.provider.getObjectFactory(), this.provider
-        .getNavigationService(), this.provider.getObjectService(), repositoryId);
-    Folder rootFolder = null;
-    String documentTypeId = null;
-    String folderTypeId = null;
-
-    // check preconditions (mandatory parameter)
-    if (!parameter.containsKey(Testable.DOCUMENT_TYPE_ID_PARAMETER)) {
-      throw new CmisRuntimeException("Can't genereate test data! Paramter missing: "
-          + Testable.DOCUMENT_TYPE_ID_PARAMETER);
-    }
-    else {
-      documentTypeId = parameter.get(Testable.DOCUMENT_TYPE_ID_PARAMETER);
-    }
-    if (!parameter.containsKey(Testable.FOLDER_TYPE_ID_PARAMETER)) {
-      throw new CmisRuntimeException("Can't genereate test data! Paramter missing: "
-          + Testable.FOLDER_TYPE_ID_PARAMETER);
-    }
-    else {
-      folderTypeId = parameter.get(Testable.FOLDER_TYPE_ID_PARAMETER);
-    }
-
-    // optional test root folder:
-    if (parameter.containsKey(Testable.ROOT_FOLDER_ID_PARAMETER)) {
-      // test root folder
-      String testRootId = parameter.get(Testable.ROOT_FOLDER_ID_PARAMETER);
-      rootFolder = (Folder) this.getObject(createObjectId(testRootId));
-    }
-    else {
-      // repository root
-      rootFolder = this.getRootFolder();
-    }
-
-    PropertyIdDefinitionImpl objectTypeIdPropertyType = new PropertyIdDefinitionImpl();
-    objectTypeIdPropertyType.setId(CmisProperties.OBJECT_TYPE_ID.value());
-    objectTypeIdPropertyType.setCardinality(Cardinality.SINGLE);
-
-    PropertyStringDefinitionImpl namePropertyType = new PropertyStringDefinitionImpl();
-    namePropertyType.setId(CmisProperties.NAME.value());
-    namePropertyType.setCardinality(Cardinality.SINGLE);
-
-    // create test root folder
-    List<Property<?>> properties = new ArrayList<Property<?>>();
-    Property<String> nameProperty = this.getPropertyFactory().createProperty(namePropertyType,
-        UUID.randomUUID().toString());
-    properties.add(nameProperty);
-    Property<String> typeProperty = this.getPropertyFactory().createProperty(
-        objectTypeIdPropertyType, folderTypeId);
-    properties.add(typeProperty);
-
-    this.testRootFolder = rootFolder
-        .createFolder(properties, null, null, null, getDefaultContext());
-
-    og.setContentSizeInKB(10);
-    og.setDocumentTypeId(documentTypeId);
-    og.setFolderTypeId(folderTypeId);
-    og.setNumberOfDocumentsToCreatePerFolder(2);
-    og.setDocumentPropertiesToGenerate(new ArrayList<String>());
-    og.setFolderPropertiesToGenerate(new ArrayList<String>());
-
-    og.createFolderHierachy(2, 2, this.testRootFolder.getId());
-  }
-
-  public void cleanUpTestData() {
-    if (this.testRootFolder != null) {
-      this.testRootFolder.deleteTree(true, UnfileObjects.DELETE, true);
-      this.testRootFolder = null;
-    }
-  }
-
   /**
    * Connect session object to the provider. This is the very first call after a session is created.
    * <p>
@@ -775,7 +686,7 @@ public class PersistentSessionImpl imple
   }
 
   public Cache getCache() {
-    return null; // this.cache;
+    return this.cache;
   }
 
   /**
@@ -803,11 +714,10 @@ public class PersistentSessionImpl imple
     }
 
     String newId = getProvider().getObjectService().createDocument(getRepositoryId(),
-        SessionUtil.convertProperties(this, properties),
-        (folderId == null ? null : folderId.getId()),
-        SessionUtil.convertContentStream(this, contentStream), versioningState,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(this, addAces),
-        SessionUtil.convertAces(this, removeAces), null);
+        objectFactory.convertProperties(properties), (folderId == null ? null : folderId.getId()),
+        objectFactory.convertContentStream(contentStream), versioningState,
+        objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces),
+        objectFactory.convertAces(removeAces), null);
 
     if (newId == null) {
       return null;
@@ -833,10 +743,10 @@ public class PersistentSessionImpl imple
     }
 
     String newId = getProvider().getObjectService().createDocumentFromSource(getRepositoryId(),
-        source.getId(), SessionUtil.convertProperties(this, properties),
+        source.getId(), objectFactory.convertProperties(properties),
         (folderId == null ? null : folderId.getId()), versioningState,
-        SessionUtil.convertPolicies(policies), SessionUtil.convertAces(this, addAces),
-        SessionUtil.convertAces(this, removeAces), null);
+        objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces),
+        objectFactory.convertAces(removeAces), null);
 
     if (newId == null) {
       return null;
@@ -858,9 +768,9 @@ public class PersistentSessionImpl imple
     }
 
     String newId = getProvider().getObjectService().createFolder(getRepositoryId(),
-        SessionUtil.convertProperties(this, properties),
-        (folderId == null ? null : folderId.getId()), SessionUtil.convertPolicies(policies),
-        SessionUtil.convertAces(this, addAces), SessionUtil.convertAces(this, removeAces), null);
+        objectFactory.convertProperties(properties), (folderId == null ? null : folderId.getId()),
+        objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces),
+        objectFactory.convertAces(removeAces), null);
 
     if (newId == null) {
       return null;
@@ -882,9 +792,9 @@ public class PersistentSessionImpl imple
     }
 
     String newId = getProvider().getObjectService().createPolicy(getRepositoryId(),
-        SessionUtil.convertProperties(this, properties),
-        (folderId == null ? null : folderId.getId()), SessionUtil.convertPolicies(policies),
-        SessionUtil.convertAces(this, addAces), SessionUtil.convertAces(this, removeAces), null);
+        objectFactory.convertProperties(properties), (folderId == null ? null : folderId.getId()),
+        objectFactory.convertPolicies(policies), objectFactory.convertAces(addAces),
+        objectFactory.convertAces(removeAces), null);
 
     if (newId == null) {
       return null;
@@ -902,8 +812,8 @@ public class PersistentSessionImpl imple
   public ObjectId createRelationship(List<Property<?>> properties, List<Policy> policies,
       List<Ace> addAces, List<Ace> removeAces) {
     String newId = getProvider().getObjectService().createRelationship(getRepositoryId(),
-        SessionUtil.convertProperties(this, properties), SessionUtil.convertPolicies(policies),
-        SessionUtil.convertAces(this, addAces), SessionUtil.convertAces(this, removeAces), null);
+        objectFactory.convertProperties(properties), objectFactory.convertPolicies(policies),
+        objectFactory.convertAces(addAces), objectFactory.convertAces(removeAces), null);
 
     if (newId == null) {
       return null;

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/QueryResultImpl.java Wed Mar 10 09:28:00 2010
@@ -54,13 +54,15 @@ public class QueryResultImpl implements 
   public QueryResultImpl(Session session, ObjectData objectData) {
     if (objectData != null) {
 
+      ObjectFactory of = session.getObjectFactory();
+
       // handle properties
       if (objectData.getProperties() != null) {
         propertiesById = new LinkedHashMap<String, QueryProperty<?>>();
         propertiesByQueryName = new LinkedHashMap<String, QueryProperty<?>>();
 
-        List<QueryProperty<?>> queryProperties = SessionUtil.convertQueryProperties(session,
-            objectData.getProperties());
+        List<QueryProperty<?>> queryProperties = of.convertQueryProperties(objectData
+            .getProperties());
 
         for (QueryProperty<?> property : queryProperties) {
           propertiesById.put(property.getId(), property);
@@ -70,14 +72,12 @@ public class QueryResultImpl implements 
 
       // handle allowable actions
       if (objectData.getAllowableActions() != null) {
-        this.allowableActions = SessionUtil.convertAllowableActions(session, objectData
-            .getAllowableActions());
+        this.allowableActions = of.convertAllowableActions(objectData.getAllowableActions());
       }
 
       // handle relationships
       if (objectData.getRelationships() != null) {
         relationships = new ArrayList<Relationship>();
-        ObjectFactory of = session.getObjectFactory();
         for (ObjectData rod : objectData.getRelationships()) {
           CmisObject relationship = of.convertObject(rod, session.getDefaultContext());
           if (relationship instanceof Relationship) {
@@ -90,7 +90,7 @@ public class QueryResultImpl implements 
       if (objectData.getRenditions() != null) {
         this.renditions = new ArrayList<Rendition>();
         for (RenditionData rd : objectData.getRenditions()) {
-          this.renditions.add(SessionUtil.convertRendition(session, null, rd));
+          this.renditions.add(of.convertRendition(null, rd));
         }
       }
     }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java Wed Mar 10 09:28:00 2010
@@ -19,6 +19,12 @@
 package org.apache.opencmis.client.runtime.repository;
 
 import java.io.InputStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.GregorianCalendar;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -28,7 +34,11 @@ import org.apache.opencmis.client.api.Al
 import org.apache.opencmis.client.api.CmisObject;
 import org.apache.opencmis.client.api.ContentStream;
 import org.apache.opencmis.client.api.OperationContext;
+import org.apache.opencmis.client.api.Policy;
+import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.QueryProperty;
 import org.apache.opencmis.client.api.QueryResult;
+import org.apache.opencmis.client.api.Rendition;
 import org.apache.opencmis.client.api.objecttype.ObjectType;
 import org.apache.opencmis.client.api.repository.ObjectFactory;
 import org.apache.opencmis.client.runtime.AceImpl;
@@ -38,52 +48,491 @@ import org.apache.opencmis.client.runtim
 import org.apache.opencmis.client.runtime.PersistentDocumentImpl;
 import org.apache.opencmis.client.runtime.PersistentFolderImpl;
 import org.apache.opencmis.client.runtime.PersistentPolicyImpl;
+import org.apache.opencmis.client.runtime.PersistentPropertyImpl;
 import org.apache.opencmis.client.runtime.PersistentRelationshipImpl;
 import org.apache.opencmis.client.runtime.PersistentSessionImpl;
+import org.apache.opencmis.client.runtime.QueryPropertyImpl;
 import org.apache.opencmis.client.runtime.QueryResultImpl;
-import org.apache.opencmis.client.runtime.SessionUtil;
+import org.apache.opencmis.client.runtime.RenditionImpl;
+import org.apache.opencmis.client.runtime.objecttype.DocumentTypeImpl;
+import org.apache.opencmis.client.runtime.objecttype.FolderTypeImpl;
+import org.apache.opencmis.client.runtime.objecttype.PolicyTypeImpl;
+import org.apache.opencmis.client.runtime.objecttype.RelationshipTypeImpl;
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.api.DocumentTypeDefinition;
+import org.apache.opencmis.commons.api.FolderTypeDefinition;
+import org.apache.opencmis.commons.api.PolicyTypeDefinition;
+import org.apache.opencmis.commons.api.PropertyBooleanDefinition;
+import org.apache.opencmis.commons.api.PropertyDateTimeDefinition;
+import org.apache.opencmis.commons.api.PropertyDecimalDefinition;
+import org.apache.opencmis.commons.api.PropertyDefinition;
+import org.apache.opencmis.commons.api.PropertyHtmlDefinition;
+import org.apache.opencmis.commons.api.PropertyIdDefinition;
+import org.apache.opencmis.commons.api.PropertyIntegerDefinition;
+import org.apache.opencmis.commons.api.PropertyStringDefinition;
+import org.apache.opencmis.commons.api.PropertyUriDefinition;
+import org.apache.opencmis.commons.api.RelationshipTypeDefinition;
+import org.apache.opencmis.commons.api.TypeDefinition;
 import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.opencmis.commons.provider.AccessControlEntry;
+import org.apache.opencmis.commons.provider.AccessControlList;
+import org.apache.opencmis.commons.provider.AllowableActionsData;
+import org.apache.opencmis.commons.provider.ContentStreamData;
 import org.apache.opencmis.commons.provider.ObjectData;
-
+import org.apache.opencmis.commons.provider.PropertiesData;
+import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.PropertyIdData;
+import org.apache.opencmis.commons.provider.ProviderObjectFactory;
+import org.apache.opencmis.commons.provider.RenditionData;
+
+/**
+ * Persistent model object factory.
+ */
 public class PersistentObjectFactoryImpl implements ObjectFactory {
 
   private PersistentSessionImpl session = null;
 
+  /**
+   * Constructor.
+   */
   protected PersistentObjectFactoryImpl(PersistentSessionImpl session) {
+    if (session == null) {
+      throw new IllegalArgumentException("Session must be set!");
+    }
+
     this.session = session;
   }
 
+  /**
+   * Creates a new factory instance.
+   */
   public static ObjectFactory newInstance(PersistentSessionImpl session) {
-    ObjectFactory f = new PersistentObjectFactoryImpl(session);
-    return f;
+    return new PersistentObjectFactoryImpl(session);
   }
 
+  /**
+   * Returns the provider object factory.
+   */
+  protected ProviderObjectFactory getProviderObjectFactory() {
+    return session.getProvider().getObjectFactory();
+  }
+
+  // allowable actions
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#createAllowableAction(java.util.Map)
+   */
   public AllowableActions createAllowableAction(Map<String, Boolean> actions) {
     return new AllowableActionsImpl(actions);
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertAllowableActions(org.apache.
+   * opencmis.commons.provider.AllowableActionsData)
+   */
+  public AllowableActions convertAllowableActions(AllowableActionsData allowableActions) {
+    if ((allowableActions == null) || (allowableActions.getAllowableActions() == null)) {
+      throw new IllegalArgumentException("Allowable actions must be set!");
+    }
+
+    return createAllowableAction(allowableActions.getAllowableActions());
+  }
+
+  // ACL and ACE
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.repository.ObjectFactory#createAce(java.lang.String,
+   * java.util.List, boolean)
+   */
   public Ace createAce(String principalId, List<String> permissions, boolean isDirect) {
     return new AceImpl(principalId, permissions, isDirect);
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.repository.ObjectFactory#createAcl(java.util.List,
+   * java.lang.Boolean)
+   */
   public Acl createAcl(List<Ace> aces, Boolean isExact) {
     return new AclImpl(aces, isExact);
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.repository.ObjectFactory#convertAces(java.util.List)
+   */
+  public AccessControlList convertAces(List<Ace> aces) {
+    if (aces == null) {
+      throw new IllegalArgumentException("ACEs must be set!");
+    }
+
+    ProviderObjectFactory pof = getProviderObjectFactory();
+
+    List<AccessControlEntry> providerAces = new ArrayList<AccessControlEntry>();
+    for (Ace ace : aces) {
+      providerAces.add(pof.createAccessControlEntry(ace.getPrincipalId(), ace.getPermissions()));
+    }
+
+    return pof.createAccessControlList(providerAces);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertAcl(org.apache.opencmis.commons
+   * .provider.AccessControlList)
+   */
+  public Acl convertAcl(AccessControlList acl) {
+    if (acl == null) {
+      throw new IllegalArgumentException("ACL must be set!");
+    }
+
+    List<Ace> aces = new ArrayList<Ace>();
+    if (acl.getAces() != null) {
+      for (AccessControlEntry ace : acl.getAces()) {
+        if (ace.getPrincipal() == null) {
+          continue;
+        }
+        aces.add(createAce(ace.getPrincipal().getPrincipalId(), ace.getPermissions(), ace
+            .isDirect()));
+      }
+    }
+
+    return createAcl(aces, acl.isExact());
+  }
+
+  // policies
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.repository.ObjectFactory#convertPolicies(java.util.List)
+   */
+  public List<String> convertPolicies(List<Policy> policies) {
+    if (policies == null) {
+      return null;
+    }
+
+    List<String> result = new ArrayList<String>();
+
+    for (Policy policy : policies) {
+      if ((policy != null) && (policy.getId() != null)) {
+        result.add(policy.getId());
+      }
+    }
+
+    return result;
+  }
+
+  // renditions
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.repository.ObjectFactory#convertRendition(java.lang.String,
+   * org.apache.opencmis.commons.provider.RenditionData)
+   */
+  public Rendition convertRendition(String objectId, RenditionData rendition) {
+    if (rendition == null) {
+      throw new IllegalArgumentException("Rendition must be set!");
+    }
+
+    // TODO: what should happen if the length is not set?
+    long length = (rendition.getLength() == null ? -1 : rendition.getLength().longValue());
+    int height = (rendition.getHeight() == null ? -1 : rendition.getHeight().intValue());
+    int width = (rendition.getWidth() == null ? -1 : rendition.getWidth().intValue());
+
+    return new RenditionImpl(this.session, objectId, rendition.getStreamId(), rendition
+        .getRenditionDocumentId(), rendition.getKind(), length, rendition.getMimeType(), rendition
+        .getTitle(), height, width);
+  }
+
+  // content stream
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#createContentStream(java.lang.String,
+   * long, java.lang.String, java.io.InputStream)
+   */
   public ContentStream createContentStream(String filename, long length, String mimetype,
       InputStream stream) {
     return new ContentStreamImpl(filename, length, mimetype, stream);
   }
-  
-  /**
-   * Converts object data into an API object.
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertContentStream(org.apache.opencmis
+   * .client.api.ContentStream)
+   */
+  public ContentStreamData convertContentStream(ContentStream contentStream) {
+    if (contentStream == null) {
+      return null;
+    }
+
+    BigInteger length = (contentStream.getLength() < 0 ? null : BigInteger.valueOf(contentStream
+        .getLength()));
+
+    return getProviderObjectFactory().createContentStream(length, contentStream.getMimeType(),
+        contentStream.getFileName(), contentStream.getStream());
+  }
+
+  // types
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertTypeDefinition(org.apache.opencmis
+   * .commons.api.TypeDefinition)
+   */
+  public ObjectType convertTypeDefinition(TypeDefinition typeDefinition) {
+    if (typeDefinition instanceof DocumentTypeDefinition) {
+      return new DocumentTypeImpl(this.session, typeDefinition);
+    }
+    else if (typeDefinition instanceof FolderTypeDefinition) {
+      return new FolderTypeImpl(this.session, typeDefinition);
+    }
+    else if (typeDefinition instanceof RelationshipTypeDefinition) {
+      return new RelationshipTypeImpl(this.session, typeDefinition);
+    }
+    else if (typeDefinition instanceof PolicyTypeDefinition) {
+      return new PolicyTypeImpl(this.session, typeDefinition);
+    }
+    else {
+      throw new CmisRuntimeException("Unknown base type!");
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#getTypeFromObjectData(org.apache.opencmis
+   * .commons.provider.ObjectData)
+   */
+  public ObjectType getTypeFromObjectData(ObjectData objectData) {
+    if ((objectData == null) || (objectData.getProperties() == null)
+        || (objectData.getProperties().getProperties() == null)) {
+      return null;
+    }
+
+    PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(
+        PropertyIds.CMIS_OBJECT_TYPE_ID);
+    if (!(typeProperty instanceof PropertyIdData)) {
+      return null;
+    }
+
+    return this.session.getTypeDefinition((String) typeProperty.getFirstValue());
+  }
+
+  // properties
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#createProperty(org.apache.opencmis.
+   * commons.api.PropertyDefinition, java.lang.Object)
+   */
+  public <T> Property<T> createProperty(PropertyDefinition<T> type, T value) {
+    return new PersistentPropertyImpl<T>(type, value);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#createPropertyMultivalue(org.apache
+   * .opencmis.commons.api.PropertyDefinition, java.util.List)
+   */
+  public <T> Property<T> createPropertyMultivalue(PropertyDefinition<T> type, List<T> values) {
+    return new PersistentPropertyImpl<T>(type, values);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertProperties(org.apache.opencmis
+   * .client.api.objecttype.ObjectType, org.apache.opencmis.commons.provider.PropertiesData)
+   */
+  @SuppressWarnings("unchecked")
+  public Map<String, Property<?>> convertProperties(ObjectType objectType, PropertiesData properties) {
+    // check input
+    if (objectType == null) {
+      throw new IllegalArgumentException("Object type must set!");
+    }
+
+    if (objectType.getPropertyDefintions() == null) {
+      throw new IllegalArgumentException("Object type has no property defintions!");
+    }
+
+    if ((properties == null) || (properties.getProperties() == null)) {
+      throw new IllegalArgumentException("Properties must be set!");
+    }
+
+    // iterate through properties and convert them
+    Map<String, Property<?>> result = new LinkedHashMap<String, Property<?>>();
+    for (Map.Entry<String, PropertyData<?>> property : properties.getProperties().entrySet()) {
+      // find property definition
+      PropertyDefinition<?> definition = objectType.getPropertyDefintions().get(property.getKey());
+      if (definition == null) {
+        // property without definition
+        throw new CmisRuntimeException("Property '" + property.getKey() + "' doesn't exist!");
+      }
+
+      Property<?> apiProperty = null;
+
+      if (definition instanceof PropertyStringDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyStringDefinition) definition,
+            (List<String>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyIdDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyIdDefinition) definition,
+            (List<String>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyHtmlDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyHtmlDefinition) definition,
+            (List<String>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyUriDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyUriDefinition) definition,
+            (List<String>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyIntegerDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyIntegerDefinition) definition,
+            (List<BigInteger>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyBooleanDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyBooleanDefinition) definition,
+            (List<Boolean>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyDecimalDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyDecimalDefinition) definition,
+            (List<BigDecimal>) property.getValue().getValues());
+      }
+      else if (definition instanceof PropertyDateTimeDefinition) {
+        apiProperty = createPropertyMultivalue((PropertyDateTimeDefinition) definition,
+            (List<GregorianCalendar>) property.getValue().getValues());
+      }
+
+      result.put(property.getKey(), apiProperty);
+    }
+
+    return result;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertProperties(java.util.Collection)
+   */
+  @SuppressWarnings("unchecked")
+  public PropertiesData convertProperties(Collection<Property<?>> properties) {
+    // check input
+    if (properties == null) {
+      throw new IllegalArgumentException("Properties must be set!");
+    }
+
+    ProviderObjectFactory pof = getProviderObjectFactory();
+
+    // iterate through properties and convert them
+    List<PropertyData<?>> propertyList = new ArrayList<PropertyData<?>>();
+    for (Property<?> property : properties) {
+
+      PropertyDefinition<?> definition = property.getDefinition();
+      if (definition instanceof PropertyStringDefinition) {
+        propertyList.add(pof.createPropertyStringData(property.getId(), (List<String>) property
+            .getValues()));
+      }
+      else if (definition instanceof PropertyIdDefinition) {
+        propertyList.add(pof.createPropertyIdData(property.getId(), (List<String>) property
+            .getValues()));
+      }
+      else if (definition instanceof PropertyHtmlDefinition) {
+        propertyList.add(pof.createPropertyHtmlData(property.getId(), (List<String>) property
+            .getValues()));
+      }
+      else if (definition instanceof PropertyUriDefinition) {
+        propertyList.add(pof.createPropertyUriData(property.getId(), (List<String>) property
+            .getValues()));
+      }
+      else if (definition instanceof PropertyIntegerDefinition) {
+        propertyList.add(pof.createPropertyIntegerData(property.getId(),
+            (List<BigInteger>) property.getValues()));
+      }
+      else if (definition instanceof PropertyBooleanDefinition) {
+        propertyList.add(pof.createPropertyBooleanData(property.getId(), (List<Boolean>) property
+            .getValues()));
+      }
+      else if (definition instanceof PropertyDecimalDefinition) {
+        propertyList.add(pof.createPropertyDecimalData(property.getId(),
+            (List<BigDecimal>) property.getValues()));
+      }
+      else if (definition instanceof PropertyDateTimeDefinition) {
+        propertyList.add(pof.createPropertyDateTimeData(property.getId(),
+            (List<GregorianCalendar>) property.getValues()));
+      }
+    }
+
+    return pof.createPropertiesData(propertyList);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertQueryProperties(org.apache.opencmis
+   * .commons.provider.PropertiesData)
+   */
+  @SuppressWarnings("unchecked")
+  public List<QueryProperty<?>> convertQueryProperties(PropertiesData properties) {
+    // check input
+    if ((properties == null) || (properties.getProperties() == null)) {
+      throw new IllegalArgumentException("Properties must be set!");
+    }
+
+    // iterate through properties and convert them
+    List<QueryProperty<?>> result = new ArrayList<QueryProperty<?>>();
+    for (PropertyData<?> property : properties.getProperties().values()) {
+      result.add(new QueryPropertyImpl(property.getId(), property.getQueryName(), property
+          .getValues()));
+    }
+
+    return result;
+  }
+
+  // objects
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertObject(org.apache.opencmis.commons
+   * .provider.ObjectData, org.apache.opencmis.client.api.OperationContext)
    */
   public CmisObject convertObject(ObjectData objectData, OperationContext context) {
     if (objectData == null) {
       throw new IllegalArgumentException("Object data is null!");
     }
 
-    ObjectType type = SessionUtil.getTypeFromObjectData(this.session, objectData);
+    ObjectType type = getTypeFromObjectData(objectData);
 
     /* determine type */
     switch (objectData.getBaseTypeId()) {
@@ -100,6 +549,13 @@ public class PersistentObjectFactoryImpl
     }
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.opencmis.client.api.repository.ObjectFactory#convertQueryResult(org.apache.opencmis
+   * .commons.provider.ObjectData)
+   */
   public QueryResult convertQueryResult(ObjectData objectData) {
     if (objectData == null) {
       throw new IllegalArgumentException("Object data is null!");

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/Fixture.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/Fixture.java?rev=921267&r1=921266&r2=921267&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/Fixture.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/Fixture.java Wed Mar 10 09:28:00 2010
@@ -35,7 +35,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.opencmis.client.api.Session;
 import org.apache.opencmis.client.api.SessionFactory;
-import org.apache.opencmis.client.api.util.Testable;
 import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
 
 /**
@@ -217,20 +216,20 @@ public class Fixture {
 	}
 
 	public static void setUpTestData(Session session) {
-		if (session instanceof Testable) {
-			Map<String, String> p = new Hashtable<String, String>();
-			p.put(Testable.FOLDER_TYPE_ID_PARAMETER, Fixture.FOLDER_TYPE_ID);
-			p
-					.put(Testable.DOCUMENT_TYPE_ID_PARAMETER,
-							Fixture.DOCUMENT_TYPE_ID);
-			((Testable) session).generateTestData(p);
-		}
+//		if (session instanceof Testable) {
+//			Map<String, String> p = new Hashtable<String, String>();
+//			p.put(Testable.FOLDER_TYPE_ID_PARAMETER, Fixture.FOLDER_TYPE_ID);
+//			p
+//					.put(Testable.DOCUMENT_TYPE_ID_PARAMETER,
+//							Fixture.DOCUMENT_TYPE_ID);
+//			((Testable) session).generateTestData(p);
+//		}
 	}
 
 	public static void teardownTestData(Session session) {
-		if (session instanceof Testable) {
-			((Testable) session).cleanUpTestData();
-		}
+//		if (session instanceof Testable) {
+//			((Testable) session).cleanUpTestData();
+//		}
 	}
 
 	private static boolean isLogged = false;



Mime
View raw message