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 2010/11/12 17:54:19 UTC

svn commit: r1034469 - in /incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client: chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client-impl/src/main/java/org/ap...

Author: fmui
Date: Fri Nov 12 16:54:18 2010
New Revision: 1034469

URL: http://svn.apache.org/viewvc?rev=1034469&view=rev
Log:
even more refactoring

Modified:
    incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientDocument.java
    incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractTransientCmisObject.java
    incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/TransientDocumentImpl.java

Modified: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientDocument.java?rev=1034469&r1=1034468&r2=1034469&view=diff
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientDocument.java (original)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientDocument.java Fri Nov 12 16:54:18 2010
@@ -18,6 +18,67 @@
  */
 package org.apache.chemistry.opencmis.client.api;
 
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+
 public interface TransientDocument extends TransientCmisObject {
 
+    void deleteAllVersions();
+
+    ContentStream getContentStream();
+
+    ContentStream getContentStream(String streamId);
+
+    void setContentStream(ContentStream contentStream, boolean overwrite);
+
+    void deleteContentStream();
+
+    Document getObjectOfLatestVersion(boolean major);
+
+    Document getObjectOfLatestVersion(boolean major, OperationContext context);
+
+    List<Document> getAllVersions();
+
+    List<Document> getAllVersions(OperationContext context);
+
+    Document copy(ObjectId targetFolderId);
+
+    Document copy(ObjectId targetFolderId, Map<String, ?> properties, VersioningState versioningState,
+            List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs, OperationContext context);
+
+    // document specific properties
+
+    Boolean isImmutable(); // cmis:isImmutable
+
+    Boolean isLatestVersion(); // cmis:isLatestVersion
+
+    Boolean isMajorVersion(); // cmis:isMajorVersion
+
+    Boolean isLatestMajorVersion(); // cmis:isLatestMajorVersion
+
+    String getVersionLabel(); // cmis:versionLabel
+
+    String getVersionSeriesId(); // cmis:versionSeriesId
+
+    Boolean isVersionSeriesCheckedOut(); // cmis:isVersionSeriesCheckedOut
+
+    String getVersionSeriesCheckedOutBy(); // cmis:versionSeriesCheckedOutBy
+
+    String getVersionSeriesCheckedOutId(); // cmis:versionSeriesCheckedOutId
+
+    String getCheckinComment(); // cmis:checkinComment
+
+    long getContentStreamLength(); // cmis:contentStreamLength
+
+    String getContentStreamMimeType(); // cmis:contentStreamMimeType
+
+    String getContentStreamFileName(); // cmis:contentStreamFileName
+
+    String getContentStreamId(); // cmis:contentStreamId
+
+    ObjectId checkIn(boolean major, String checkinComment);
 }

Modified: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractTransientCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractTransientCmisObject.java?rev=1034469&r1=1034468&r2=1034469&view=diff
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractTransientCmisObject.java (original)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractTransientCmisObject.java Fri Nov 12 16:54:18 2010
@@ -58,26 +58,26 @@ import org.apache.chemistry.opencmis.com
 
 public abstract class AbstractTransientCmisObject implements TransientCmisObject {
 
-    private Session session;
-    private CmisObject object;
+    protected Session session;
+    protected CmisObject object;
 
-    private Map<String, Property<?>> properties;
-    private AllowableActions allowableActions;
-    private List<Rendition> renditions;
-    private Acl acl;
-    private Map<AclPropagation, List<AceChangeHolder>> addAces;
-    private Map<AclPropagation, List<AceChangeHolder>> removeAces;
-    private List<Policy> policies;
-    private Set<String> addPolicies;
-    private Set<String> removePolicies;
-    private List<Relationship> relationships;
-    private Map<ExtensionLevel, List<CmisExtensionElement>> inputExtensions;
-    private Map<ExtensionLevel, List<CmisExtensionElement>> ouputExtensions;
+    protected Map<String, Property<?>> properties;
+    protected AllowableActions allowableActions;
+    protected List<Rendition> renditions;
+    protected Acl acl;
+    protected Map<AclPropagation, List<AceChangeHolder>> addAces;
+    protected Map<AclPropagation, List<AceChangeHolder>> removeAces;
+    protected List<Policy> policies;
+    protected Set<String> addPolicies;
+    protected Set<String> removePolicies;
+    protected List<Relationship> relationships;
+    protected Map<ExtensionLevel, List<CmisExtensionElement>> inputExtensions;
+    protected Map<ExtensionLevel, List<CmisExtensionElement>> ouputExtensions;
 
     protected boolean isModified;
     protected boolean isPropertyUpdateRequired;
     protected boolean isMarkedForDelete;
-    private boolean deleteAllVersions;
+    protected boolean deleteAllVersions;
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     protected void initialize(Session session, CmisObject object) {
@@ -403,28 +403,35 @@ public abstract class AbstractTransientC
         return objectId;
     }
 
+    protected Properties prepareProperties() {
+        Set<Updatability> updatebility = new HashSet<Updatability>();
+        updatebility.add(Updatability.READWRITE);
+
+        // check if checked out
+        Boolean isCheckedOut = getPropertyValue(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
+        if ((isCheckedOut != null) && isCheckedOut.booleanValue()) {
+            updatebility.add(Updatability.WHENCHECKEDOUT);
+        }
+
+        // convert properties
+        Properties result = getObjectFactory().convertProperties(properties, getType(), updatebility);
+
+        // extensions
+        List<CmisExtensionElement> extensions = ouputExtensions.get(ExtensionLevel.PROPERTIES);
+        if (extensions != null) {
+            result.setExtensions(extensions);
+        }
+
+        return result;
+    }
+
     protected String saveProperties(String objectId) {
         if (isPropertyUpdateRequired) {
             Holder<String> objectIdHolder = new Holder<String>(objectId);
             Holder<String> changeTokenHolder = new Holder<String>(getChangeToken());
 
-            Set<Updatability> updatebility = new HashSet<Updatability>();
-            updatebility.add(Updatability.READWRITE);
-
-            // check if checked out
-            Boolean isCheckedOut = getPropertyValue(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
-            if ((isCheckedOut != null) && isCheckedOut.booleanValue()) {
-                updatebility.add(Updatability.WHENCHECKEDOUT);
-            }
-
             // convert properties
-            Properties props = getObjectFactory().convertProperties(properties, getType(), updatebility);
-
-            // extensions
-            List<CmisExtensionElement> extensions = ouputExtensions.get(ExtensionLevel.PROPERTIES);
-            if (extensions != null) {
-                props.setExtensions(extensions);
-            }
+            Properties props = prepareProperties();
 
             // it's time to update
             getBinding().getObjectService().updateProperties(getRepositoryId(), objectIdHolder, changeTokenHolder,
@@ -452,36 +459,34 @@ public abstract class AbstractTransientC
         return objectId;
     }
 
-    protected String saveACL(String objectId) {
+    protected Acl prepareAcl(List<AceChangeHolder> achList) {
+        if ((achList == null) || (achList.isEmpty())) {
+            return null;
+        }
 
         ObjectFactory of = getObjectFactory();
 
+        List<Ace> aces = new ArrayList<Ace>();
+        for (AceChangeHolder ach : achList) {
+            aces.add(of.createAce(ach.getPrincipalId(), ach.getPermissions()));
+        }
+
+        return of.createAcl(aces);
+    }
+
+    protected String saveACL(String objectId) {
         for (AclPropagation ap : AclPropagation.values()) {
             if (!addAces.containsKey(ap) && !removeAces.containsKey(ap)) {
                 continue;
             }
 
-            Acl addAcl = null;
-            if (addAces.containsKey(ap)) {
-                List<Ace> aces = new ArrayList<Ace>();
-                for (AceChangeHolder ach : addAces.get(ap)) {
-                    aces.add(of.createAce(ach.getPrincipalId(), ach.getPermissions()));
-                }
-
-                addAcl = of.createAcl(aces);
-            }
-
-            Acl removeAcl = null;
-            if (removeAces.containsKey(ap)) {
-                List<Ace> aces = new ArrayList<Ace>();
-                for (AceChangeHolder ach : removeAces.get(ap)) {
-                    aces.add(of.createAce(ach.getPrincipalId(), ach.getPermissions()));
-                }
-
-                removeAcl = of.createAcl(aces);
-            }
+            getBinding().getAclService().applyAcl(getRepositoryId(), objectId, prepareAcl(addAces.get(ap)),
+                    prepareAcl(removeAces.get(ap)), ap, null);
+        }
 
-            getBinding().getAclService().applyAcl(getRepositoryId(), objectId, addAcl, removeAcl, ap, null);
+        if (addAces.containsKey(null) || removeAces.containsKey(null)) {
+            getBinding().getAclService().applyAcl(getRepositoryId(), objectId, prepareAcl(addAces.get(null)),
+                    prepareAcl(removeAces.get(null)), null, null);
         }
 
         return objectId;

Modified: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/TransientDocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/TransientDocumentImpl.java?rev=1034469&r1=1034468&r2=1034469&view=diff
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/TransientDocumentImpl.java (original)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/TransientDocumentImpl.java Fri Nov 12 16:54:18 2010
@@ -18,8 +18,235 @@
  */
 package org.apache.chemistry.opencmis.client.runtime;
 
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.client.api.OperationContext;
+import org.apache.chemistry.opencmis.client.api.Policy;
+import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.client.api.TransientDocument;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
 
 public class TransientDocumentImpl extends AbstractTransientCmisObject implements TransientDocument {
 
+    private ContentStream contentStream;
+    private boolean contentOverwrite;
+    private boolean deleteContent;
+
+    @Override
+    protected void initialize(Session session, CmisObject object) {
+        super.initialize(session, object);
+
+        contentStream = null;
+        contentOverwrite = false;
+        deleteContent = false;
+    }
+
+    public void deleteAllVersions() {
+        delete(true);
+    }
+
+    public ContentStream getContentStream() {
+        return ((Document) getCmisObject()).getContentStream();
+    }
+
+    public ContentStream getContentStream(String streamId) {
+        return ((Document) getCmisObject()).getContentStream(streamId);
+    }
+
+    public void setContentStream(ContentStream contentStream, boolean overwrite) {
+        this.contentStream = contentStream;
+        this.contentOverwrite = overwrite;
+
+        deleteContent = false;
+    }
+
+    public void deleteContentStream() {
+        deleteContent = true;
+
+        contentStream = null;
+    }
+
+    public Document getObjectOfLatestVersion(boolean major) {
+        return ((Document) getCmisObject()).getObjectOfLatestVersion(major);
+    }
+
+    public Document getObjectOfLatestVersion(boolean major, OperationContext context) {
+        return ((Document) getCmisObject()).getObjectOfLatestVersion(major, context);
+    }
+
+    public List<Document> getAllVersions() {
+        return ((Document) getCmisObject()).getAllVersions();
+    }
+
+    public List<Document> getAllVersions(OperationContext context) {
+        return ((Document) getCmisObject()).getAllVersions(context);
+    }
+
+    public Document copy(ObjectId targetFolderId) {
+        return ((Document) getCmisObject()).copy(targetFolderId);
+    }
+
+    public Document copy(ObjectId targetFolderId, Map<String, ?> properties, VersioningState versioningState,
+            List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs, OperationContext context) {
+        return ((Document) getCmisObject()).copy(targetFolderId, properties, versioningState, policies, addACEs,
+                removeACEs, context);
+    }
+
+    // properties
+
+    public String getCheckinComment() {
+        return getPropertyValue(PropertyIds.CHECKIN_COMMENT);
+    }
+
+    public String getVersionLabel() {
+        return getPropertyValue(PropertyIds.VERSION_LABEL);
+    }
+
+    public String getVersionSeriesId() {
+        return getPropertyValue(PropertyIds.VERSION_SERIES_ID);
+    }
+
+    public String getVersionSeriesCheckedOutId() {
+        return getPropertyValue(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID);
+    }
+
+    public String getVersionSeriesCheckedOutBy() {
+        return getPropertyValue(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY);
+    }
+
+    public Boolean isImmutable() {
+        return getPropertyValue(PropertyIds.IS_IMMUTABLE);
+    }
+
+    public Boolean isLatestMajorVersion() {
+        return getPropertyValue(PropertyIds.IS_LATEST_MAJOR_VERSION);
+    }
+
+    public Boolean isLatestVersion() {
+        return getPropertyValue(PropertyIds.IS_LATEST_VERSION);
+    }
+
+    public Boolean isMajorVersion() {
+        return getPropertyValue(PropertyIds.IS_MAJOR_VERSION);
+    }
+
+    public Boolean isVersionSeriesCheckedOut() {
+        return getPropertyValue(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
+    }
+
+    public long getContentStreamLength() {
+        BigInteger bigInt = getPropertyValue(PropertyIds.CONTENT_STREAM_LENGTH);
+        return (bigInt == null) ? (long) -1 : bigInt.longValue();
+    }
+
+    public String getContentStreamMimeType() {
+        return getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE);
+    }
+
+    public String getContentStreamFileName() {
+        return getPropertyValue(PropertyIds.CONTENT_STREAM_FILE_NAME);
+    }
+
+    public String getContentStreamId() {
+        return getPropertyValue(PropertyIds.CONTENT_STREAM_ID);
+    }
+
+    // override save()
+
+    @Override
+    public ObjectId save() {
+        if (!isModified()) {
+            // nothing has change, so there is nothing to do
+            return getObjectId();
+        }
+
+        String newObjectId = getId();
+
+        newObjectId = saveDelete(newObjectId);
+        if (newObjectId == null) {
+            // object has been deleted, there is nothing else to do
+            // ... and there is no object id anymore
+            return null;
+        }
+
+        newObjectId = saveProperties(newObjectId);
+        newObjectId = saveContent(newObjectId);
+        newObjectId = savePolicies(newObjectId);
+        newObjectId = saveACL(newObjectId);
+
+        return getSession().createObjectId(newObjectId);
+    }
+
+    protected String saveContent(String objectId) {
+        Holder<String> objectIdHolder = new Holder<String>(objectId);
+        Holder<String> changeTokenHolder = new Holder<String>(getChangeToken());
+
+        if (contentStream != null) {
+            getBinding().getObjectService().setContentStream(getRepositoryId(), objectIdHolder, contentOverwrite,
+                    changeTokenHolder, contentStream, null);
+        } else if (deleteContent) {
+            getBinding().getObjectService().deleteContentStream(getRepositoryId(), objectIdHolder, changeTokenHolder,
+                    null);
+        }
+
+        if (objectIdHolder.getValue() != null) {
+            return objectIdHolder.getValue();
+        }
+
+        return objectId;
+    }
+
+    public ObjectId checkIn(boolean major, String checkinComment) {
+        Holder<String> objectIdHolder = new Holder<String>(getId());
+
+        // convert properties
+        Properties checkinProperties = prepareProperties();
+
+        // prepare policies
+        List<String> checkinPolicies = null;
+        if ((addPolicies != null) && (!addPolicies.isEmpty())) {
+            checkinPolicies = new ArrayList<String>(addPolicies);
+        }
+
+        // prepare ACLs
+        List<AceChangeHolder> checkinAddAces = new ArrayList<AceChangeHolder>();
+        List<AceChangeHolder> checkinRemoveAces = new ArrayList<AceChangeHolder>();
+        for (AclPropagation ap : AclPropagation.values()) {
+            if (addAces.containsKey(ap)) {
+                checkinAddAces.addAll(addAces.get(ap));
+            }
+            if (removeAces.containsKey(ap)) {
+                checkinAddAces.addAll(removeAces.get(ap));
+            }
+        }
+        if (addAces.containsKey(null)) {
+            checkinAddAces.addAll(addAces.get(null));
+        }
+        if (removeAces.containsKey(null)) {
+            checkinAddAces.addAll(removeAces.get(null));
+        }
+
+        // check in
+        getBinding().getVersioningService().checkIn(getRepositoryId(), objectIdHolder, major, checkinProperties,
+                contentStream, checkinComment, checkinPolicies, prepareAcl(checkinAddAces),
+                prepareAcl(checkinRemoveAces), null);
+
+        if (objectIdHolder.getValue() != null) {
+            return getSession().createObjectId(objectIdHolder.getValue());
+        }
+
+        return getObjectId();
+    }
 }