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/11 13:46:31 UTC
svn commit: r1033918 [1/3] - 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/chemistry-opencmis-...
Author: fmui
Date: Thu Nov 11 12:46:30 2010
New Revision: 1033918
URL: http://svn.apache.org/viewvc?rev=1033918&view=rev
Log:
client API refactoring - first stint
Added:
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObjectAdapter.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientCmisObject.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractFilableCmisObject.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/FolderImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PolicyImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PropertyImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/RelationshipImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java (with props)
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java (with props)
Removed:
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentFilableCmisObject.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentDocumentImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentPolicyImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentPropertyImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentRelationshipImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/enums/SessionType.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/CmisObject.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionFactoryImpl.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/CmisObjectMock.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/AbstractWriteObjectIT.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/AbstractWriteObjectRelationIT.java
incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-test/chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit/runtime/misc/AbstractReadOnlyCreateSessionIT.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/CmisObject.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/CmisObject.java?rev=1033918&r1=1033917&r2=1033918&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/CmisObject.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/CmisObject.java Thu Nov 11 12:46:30 2010
@@ -29,11 +29,10 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
-import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
/**
* Base CMIS object.
- *
+ *
* See CMIS Domain Model - section 2.1.2.
*/
public interface CmisObject extends ObjectId {
@@ -46,11 +45,6 @@ public interface CmisObject extends Obje
String getName();
/**
- * Set the name of this object. {@code Property<String> 'cmis:name'}
- */
- void setName(String name);
-
- /**
* Get the id of the user who created the object (maintained by the
* repository). {@code Property<String> 'cmis:createdBy'}
*/
@@ -88,7 +82,7 @@ public interface CmisObject extends Obje
/**
* Get the type's base type id.
- *
+ *
* @return
*/
BaseTypeId getBaseTypeId();
@@ -110,10 +104,10 @@ public interface CmisObject extends Obje
/**
* Returns a property by id.
- *
+ *
* @param id
* the property id
- *
+ *
* @return the property or <code>null</code> if the property does not exist
* or is not available
*/
@@ -121,10 +115,10 @@ public interface CmisObject extends Obje
/**
* Returns a property value by id.
- *
+ *
* @param id
* the property id
- *
+ *
* @return the property value or <code>null</code> if the property does not
* exist or is not available
*/
@@ -149,7 +143,7 @@ public interface CmisObject extends Obje
/**
* Deletes this object.
- *
+ *
* @param allVersions
* if this object is a document this parameter defines if just
* this version or all versions should be deleted
@@ -157,32 +151,25 @@ public interface CmisObject extends Obje
void delete(boolean allVersions);
/**
- * Updates the properties that have been set with
- * {@link #setProperty(String, Object)}.
- *
- * @return the object id of the updated object (a repository might have
- * created a new object)
+ * Updates the properties that are provided.
+ *
+ * @param properties
+ * the properties to update
+ *
+ * @return the updated object (a repository might have created a new object)
*/
- ObjectId updateProperties();
+ CmisObject updateProperties(Map<String, ?> properties);
/**
* Updates the properties that are provided.
- *
+ *
* @param properties
* the properties to update
- *
+ *
* @return the object id of the updated object (a repository might have
* created a new object)
*/
- ObjectId updateProperties(Map<String, ?> properties);
-
- // relationship service
-
- /**
- * Fetches the relationships from or to this object from the repository.
- */
- ItemIterable<Relationship> getRelationships(boolean includeSubRelationshipTypes,
- RelationshipDirection relationshipDirection, ObjectType type, OperationContext context);
+ ObjectId updatePropertiesOnly(Map<String, ?> properties);
// renditions
@@ -194,14 +181,14 @@ public interface CmisObject extends Obje
// policy service
/**
- * Applies a policy to this object.
+ * Applies policies to this object.
*/
- void applyPolicy(ObjectId policyId);
+ void applyPolicy(ObjectId... policyIds);
/**
- * Remove a policy from this object.
+ * Remove policies from this object.
*/
- void removePolicy(ObjectId policyId);
+ void removePolicy(ObjectId... policyIds);
/**
* Returns the applied policies if they have been fetched for this object.
@@ -211,13 +198,8 @@ public interface CmisObject extends Obje
// ACL service
/**
- * Fetches the ACL of this object from the repository.
- */
- Acl getAcl(boolean onlyBasicPermissions);
-
- /**
* Adds and removes ACEs to the object.
- *
+ *
* @return the new ACL of this object
*/
Acl applyAcl(List<Ace> addAces, List<Ace> removeAces, AclPropagation aclPropagation);
@@ -225,35 +207,35 @@ public interface CmisObject extends Obje
/**
* Adds ACEs to the object.
*/
- void addAcl(List<Ace> addAces, AclPropagation aclPropagation);
+ Acl addAcl(List<Ace> addAces, AclPropagation aclPropagation);
/**
* Removes ACEs to the object.
*/
- void removeAcl(List<Ace> removeAces, AclPropagation aclPropagation);
+ Acl removeAcl(List<Ace> removeAces, AclPropagation aclPropagation);
- // buffered stuff
+ // extensions
/**
- * Sets a new property value.
- * <p>
- * The value may be a single value or a list.
- *
- * Use {@link #updateProperties()} to store the new value in the repository.
+ * Returns the extensions for the given level.
*/
- <T> void setProperty(String id, Object value);
-
- // extensions
-
List<CmisExtensionElement> getExtensions(ExtensionLevel level);
- // session handling
+ // adapters
+
+ /**
+ * Returns an adapter based on the given interface.
+ */
+ CmisObjectAdapter getAdapter(Class<? extends CmisObjectAdapter> adapterInterface);
/**
- * Returns true, if this object has pending changes which are not synced
- * with the backend.
+ * Returns a transient object adapter.
+ *
+ * @see TransientCmisObject
*/
- boolean isChanged();
+ TransientCmisObject getTransientObject();
+
+ // session handling
/**
* Returns the timestamp (in milliseconds) of the last refresh.
Added: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObjectAdapter.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/CmisObjectAdapter.java?rev=1033918&view=auto
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObjectAdapter.java (added)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObjectAdapter.java Thu Nov 11 12:46:30 2010
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.api;
+
+/**
+ * Marker interface for adapters.
+ */
+public interface CmisObjectAdapter {
+}
Propchange: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/CmisObjectAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.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/Document.java?rev=1033918&r1=1033917&r2=1033918&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/Document.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/Document.java Thu Nov 11 12:46:30 2010
@@ -27,7 +27,7 @@ import org.apache.chemistry.opencmis.com
/**
* CMIS Document.
- *
+ *
* Domain Model 2.4
*/
public interface Document extends FileableCmisObject {
@@ -41,7 +41,7 @@ public interface Document extends Fileab
/**
* Retrieves the content stream of this document.
- *
+ *
* @return the content stream, or {@code null}
*/
ContentStream getContentStream();
@@ -49,7 +49,7 @@ public interface Document extends Fileab
/**
* Retrieves the content stream that is associated with the given stream id.
* This is usually a rendition of the document.
- *
+ *
* @return the content stream, or {@code null}
*/
ContentStream getContentStream(String streamId);
@@ -57,19 +57,29 @@ public interface Document extends Fileab
/**
* Sets a new content stream for the document.
*/
- ObjectId setContentStream(ContentStream contentStream, boolean overwrite);
+ Document setContentStream(ContentStream contentStream, boolean overwrite);
+
+ /**
+ * Sets a new content stream for the document.
+ */
+ ObjectId setContentStreamOnly(ContentStream contentStream, boolean overwrite);
+
+ /**
+ * Removes the current content stream from the document.
+ */
+ Document deleteContentStream();
/**
* Removes the current content stream from the document.
*/
- ObjectId deleteContentStream();
+ ObjectId deleteContentStreamOnly();
// versioning service
/**
* Checks out the document and returns the object id of the PWC (private
* working copy).
- *
+ *
* @return PWC id
*/
ObjectId checkOut(); // returns the PWC id
@@ -83,7 +93,7 @@ public interface Document extends Fileab
/**
* If this is a PWC (private working copy) it performs a check in. If this
* is not a PWC it an exception will be thrown.
- *
+ *
* @return new document id
*/
ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream, String checkinComment,
@@ -92,18 +102,18 @@ public interface Document extends Fileab
/**
* If this is a PWC (private working copy) it performs a check in. If this
* is not a PWC it an exception will be thrown.
- *
+ *
* @return new document id
*/
ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream, String checkinComment);
/**
* Fetches the latest major or minor version of this document.
- *
+ *
* @param major
* if <code>true</code> the latest major version will be
* returned, otherwise the very last version will be returned
- *
+ *
* @return the latest document object
*/
Document getObjectOfLatestVersion(boolean major);
@@ -111,11 +121,11 @@ public interface Document extends Fileab
/**
* Fetches the latest major or minor version of this document using the
* given {@link OperationContext}.
- *
+ *
* @param major
* if <code>true</code> the latest major version will be
* returned, otherwise the very last version will be returned
- *
+ *
* @return the latest document object
*/
Document getObjectOfLatestVersion(boolean major, OperationContext context);
@@ -133,20 +143,19 @@ public interface Document extends Fileab
/**
* Creates a copy of this document, including content.
- *
+ *
* @return the new document object
*/
Document copy(ObjectId targetFolderId);
/**
* Creates a copy of this document, including content.
- *
+ *
* @return the new document object or {@code null} if the parameter
* {@code context} was set to {@code null}
*/
- Document copy(ObjectId targetFolderId, Map<String, ?> properties,
- VersioningState versioningState, List<Policy> policies,
- List<Ace> addACEs, List<Ace> removeACEs, OperationContext context);
+ Document copy(ObjectId targetFolderId, Map<String, ?> properties, VersioningState versioningState,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs, OperationContext context);
// document specific properties
Modified: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.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/Session.java?rev=1033918&r1=1033917&r2=1033918&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/Session.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/Session.java Thu Nov 11 12:46:30 2010
@@ -24,9 +24,12 @@ import java.util.Map;
import java.util.Set;
import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
@@ -63,26 +66,6 @@ public interface Session {
*/
void clear();
- /**
- * Saves all pending actions for this session. Corresponds to a
- * <code>commit</code> if the CMIS provider supports transactions. If
- * transactions are not supported by the CMIS provider, changes might be
- * applied only partially.
- *
- * <em>Not all session implementations require this method!</em>
- */
- void save();
-
- /**
- * Cancels all pending actions for this session. Corresponds to a
- * <code>rollback</code> if the CMIS provider supports transactions. If
- * transactions are not supported by the CMIS provider, some changes might
- * already be applied and therefore not rolled back.
- *
- * <em>Not all session implementations require this method!</em>
- */
- void cancel();
-
// session context
/**
@@ -388,4 +371,30 @@ public interface Session {
* @return the object id of the new relationship
*/
ObjectId createRelationship(Map<String, ?> properties);
+
+ /**
+ * Fetches the relationships from or to an object from the repository.
+ */
+ ItemIterable<Relationship> getRelationships(ObjectId objectId, boolean includeSubRelationshipTypes,
+ RelationshipDirection relationshipDirection, ObjectType type, OperationContext context);
+
+ /**
+ * Fetches the ACL of an object from the repository.
+ */
+ Acl getAcl(ObjectId objectId, boolean onlyBasicPermissions);
+
+ /**
+ * Applies an ACL to an object.
+ */
+ Acl applyAcl(ObjectId objectId, List<Ace> addAces, List<Ace> removeAces, AclPropagation aclPropagation);
+
+ /**
+ * Applies a set of policies to an object.
+ */
+ void applyPolicy(ObjectId objectId, ObjectId... policyIds);
+
+ /**
+ * Removes a set of policies from an object.
+ */
+ void removePolicy(ObjectId objectId, ObjectId... policyIds);
}
Added: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientCmisObject.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/TransientCmisObject.java?rev=1033918&view=auto
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientCmisObject.java (added)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientCmisObject.java Thu Nov 11 12:46:30 2010
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.api;
+
+public interface TransientCmisObject extends CmisObjectAdapter {
+
+}
Propchange: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/TransientCmisObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.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/AbstractCmisObject.java?rev=1033918&view=auto
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java (added)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java Thu Nov 11 12:46:30 2010
@@ -0,0 +1,585 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.runtime;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.CmisObjectAdapter;
+import org.apache.chemistry.opencmis.client.api.ObjectFactory;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.OperationContext;
+import org.apache.chemistry.opencmis.client.api.Policy;
+import org.apache.chemistry.opencmis.client.api.Property;
+import org.apache.chemistry.opencmis.client.api.Relationship;
+import org.apache.chemistry.opencmis.client.api.Rendition;
+import org.apache.chemistry.opencmis.client.api.TransientCmisObject;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.AllowableActions;
+import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
+import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
+
+/**
+ * Base class for all persistent session object impl classes.
+ */
+public abstract class AbstractCmisObject implements CmisObject {
+
+ private SessionImpl session;
+ private ObjectType objectType;
+ private Map<String, Property<?>> properties;
+ private AllowableActions allowableActions;
+ private List<Rendition> renditions;
+ private Acl acl;
+ private List<Policy> policies;
+ private List<Relationship> relationships;
+ private Map<ExtensionLevel, List<CmisExtensionElement>> extensions;
+ private OperationContext creationContext;
+ private long refreshTimestamp;
+
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+ /**
+ * Initializes the object.
+ */
+ protected void initialize(SessionImpl session, ObjectType objectType, ObjectData objectData,
+ OperationContext context) {
+ if (session == null) {
+ throw new IllegalArgumentException("Session must be set!");
+ }
+
+ if (objectType == null) {
+ throw new IllegalArgumentException("Object type must be set!");
+ }
+
+ 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 defintions!");
+ }
+
+ this.session = session;
+ this.objectType = objectType;
+ this.extensions = new HashMap<ExtensionLevel, List<CmisExtensionElement>>();
+ this.creationContext = new OperationContextImpl(context);
+ this.refreshTimestamp = System.currentTimeMillis();
+
+ ObjectFactory of = getObjectFactory();
+
+ if (objectData != null) {
+ // handle properties
+ if (objectData.getProperties() != null) {
+ this.properties = of.convertProperties(objectType, 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 ACL
+ if (objectData.getAcl() != null) {
+ acl = objectData.getAcl();
+ extensions.put(ExtensionLevel.ACL, objectData.getAcl().getExtensions());
+ }
+
+ // handle policies
+ if ((objectData.getPolicyIds() != null) && (objectData.getPolicyIds().getPolicyIds() != null)) {
+ policies = new ArrayList<Policy>();
+ for (String pid : objectData.getPolicyIds().getPolicyIds()) {
+ CmisObject policy = session.getObject(getSession().createObjectId(pid));
+ if (policy instanceof Policy) {
+ policies.add((Policy) policy);
+ }
+ }
+ 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);
+ }
+ }
+ }
+
+ extensions.put(ExtensionLevel.OBJECT, objectData.getExtensions());
+ }
+ }
+
+ /**
+ * Acquires a write lock.
+ */
+ protected void writeLock() {
+ lock.writeLock().lock();
+ }
+
+ /**
+ * Releases a write lock.
+ */
+ protected void writeUnlock() {
+ lock.writeLock().unlock();
+ }
+
+ /**
+ * Acquires a read lock.
+ */
+ protected void readLock() {
+ lock.readLock().lock();
+ }
+
+ /**
+ * Releases a read lock.
+ */
+ protected void readUnlock() {
+ lock.readLock().unlock();
+ }
+
+ /**
+ * Returns the session object.
+ */
+ protected SessionImpl getSession() {
+ return this.session;
+ }
+
+ /**
+ * Returns the repository id.
+ */
+ protected String getRepositoryId() {
+ return getSession().getRepositoryId();
+ }
+
+ /**
+ * Returns the object type.
+ */
+ protected ObjectType getObjectType() {
+ readLock();
+ try {
+ return this.objectType;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ /**
+ * Returns the binding object.
+ */
+ protected CmisBinding getBinding() {
+ return getSession().getBinding();
+ }
+
+ /**
+ * 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() {
+ String objectId = getId();
+ if (objectId == null) {
+ throw new IllegalStateException("Object Id is unknown!");
+ }
+
+ return objectId;
+ }
+
+ /**
+ * Returns the {@link OperationContext} that was used to create this object.
+ */
+ protected OperationContext getCreationContext() {
+ return creationContext;
+ }
+
+ /**
+ * Returns the query name of a property.
+ */
+ protected String getPropertyQueryName(String propertyId) {
+ readLock();
+ try {
+ PropertyDefinition<?> propDef = objectType.getPropertyDefinitions().get(propertyId);
+ if (propDef == null) {
+ return null;
+ }
+
+ return propDef.getQueryName();
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- properties ---
+
+ public void delete(boolean allVersions) {
+ String objectId = getObjectId();
+ getBinding().getObjectService().deleteObject(getRepositoryId(), objectId, allVersions, null);
+ }
+
+ public CmisObject updateProperties(Map<String, ?> properties) {
+ readLock();
+ try {
+ ObjectId objectId = updatePropertiesOnly(properties);
+ if (objectId == null) {
+ return null;
+ }
+
+ if (!getObjectId().equals(objectId.getId())) {
+ return getSession().getObject(objectId, getCreationContext());
+ }
+ } finally {
+ readUnlock();
+ }
+
+ refresh();
+
+ return this;
+ }
+
+ public ObjectId updatePropertiesOnly(Map<String, ?> properties) {
+ if ((properties == null) || (properties.isEmpty())) {
+ throw new IllegalArgumentException("Properties must not be empty!");
+ }
+
+ readLock();
+ try {
+ String objectId = getObjectId();
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+
+ String changeToken = getChangeToken();
+ Holder<String> changeTokenHolder = new Holder<String>(changeToken);
+
+ 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);
+ }
+
+ // it's time to update
+ getBinding().getObjectService().updateProperties(getRepositoryId(), objectIdHolder, changeTokenHolder,
+ getObjectFactory().convertProperties(properties, this.objectType, updatebility), null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ return getSession().createObjectId(objectIdHolder.getValue());
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- properties ---
+
+ public ObjectType getBaseType() {
+ BaseTypeId baseTypeId = getBaseTypeId();
+ if (baseTypeId == null) {
+ return null;
+ }
+
+ return getSession().getTypeDefinition(baseTypeId.value());
+ }
+
+ public BaseTypeId getBaseTypeId() {
+ String baseType = getPropertyValue(PropertyIds.BASE_TYPE_ID);
+ if (baseType == null) {
+ return null;
+ }
+
+ return BaseTypeId.fromValue(baseType);
+ }
+
+ public String getChangeToken() {
+ return getPropertyValue(PropertyIds.CHANGE_TOKEN);
+ }
+
+ public String getCreatedBy() {
+ return getPropertyValue(PropertyIds.CREATED_BY);
+ }
+
+ public GregorianCalendar getCreationDate() {
+ return getPropertyValue(PropertyIds.CREATION_DATE);
+ }
+
+ public String getId() {
+ return getPropertyValue(PropertyIds.OBJECT_ID);
+ }
+
+ public GregorianCalendar getLastModificationDate() {
+ return getPropertyValue(PropertyIds.LAST_MODIFICATION_DATE);
+ }
+
+ public String getLastModifiedBy() {
+ return getPropertyValue(PropertyIds.LAST_MODIFIED_BY);
+ }
+
+ public String getName() {
+ return getPropertyValue(PropertyIds.NAME);
+ }
+
+ public List<Property<?>> getProperties() {
+ readLock();
+ try {
+ return Collections.unmodifiableList(new ArrayList<Property<?>>(this.properties.values()));
+ } finally {
+ readUnlock();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> Property<T> getProperty(String id) {
+ readLock();
+ try {
+ return (Property<T>) this.properties.get(id);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getPropertyValue(String id) {
+ Property<T> property = getProperty(id);
+ if (property == null) {
+ return null;
+ }
+ // explicit cast needed by the Sun compiler
+ return (T) property.getValue();
+ }
+
+ public ObjectType getType() {
+ readLock();
+ try {
+ return this.objectType;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- allowable actions ---
+
+ public AllowableActions getAllowableActions() {
+ readLock();
+ try {
+ return this.allowableActions;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- renditions ---
+
+ public List<Rendition> getRenditions() {
+ readLock();
+ try {
+ return this.renditions;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- ACL ---
+
+ public Acl getAcl(boolean onlyBasicPermissions) {
+ String objectId = getObjectId();
+ return getBinding().getAclService().getAcl(getRepositoryId(), objectId, onlyBasicPermissions, null);
+ }
+
+ public Acl applyAcl(List<Ace> addAces, List<Ace> removeAces, AclPropagation aclPropagation) {
+ Acl result = getSession().applyAcl(this, addAces, removeAces, aclPropagation);
+
+ refresh();
+
+ return result;
+ }
+
+ public Acl addAcl(List<Ace> addAces, AclPropagation aclPropagation) {
+ return applyAcl(addAces, null, aclPropagation);
+ }
+
+ public Acl removeAcl(List<Ace> removeAces, AclPropagation aclPropagation) {
+ return applyAcl(null, removeAces, aclPropagation);
+ }
+
+ public Acl getAcl() {
+ readLock();
+ try {
+ return this.acl;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- policies ---
+
+ public void applyPolicy(ObjectId... policyIds) {
+ readLock();
+ try {
+ getSession().applyPolicy(this, policyIds);
+ } finally {
+ readUnlock();
+ }
+
+ refresh();
+ }
+
+ public void removePolicy(ObjectId... policyIds) {
+ readLock();
+ try {
+ getSession().removePolicy(this, policyIds);
+ } finally {
+ readUnlock();
+ }
+
+ refresh();
+ }
+
+ public List<Policy> getPolicies() {
+ readLock();
+ try {
+ return this.policies;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- relationships ---
+
+ public List<Relationship> getRelationships() {
+ readLock();
+ try {
+ return this.relationships;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ // --- extensions ---
+
+ public List<CmisExtensionElement> getExtensions(ExtensionLevel level) {
+ List<CmisExtensionElement> ext = extensions.get(level);
+ if (ext == null) {
+ return null;
+ }
+
+ return Collections.unmodifiableList(ext);
+ }
+
+ // --- adapters ---
+
+ public CmisObjectAdapter getAdapter(Class<? extends CmisObjectAdapter> adapterInterface) {
+ if (adapterInterface == null) {
+ return null;
+ }
+
+ if (adapterInterface.equals(TransientCmisObject.class)) {
+ return createTransientCmisObject();
+ }
+
+ return null;
+ }
+
+ public TransientCmisObject getTransientObject() {
+ return (TransientCmisObject) getAdapter(TransientCmisObject.class);
+ }
+
+ protected TransientCmisObject createTransientCmisObject() {
+ return null;
+ }
+
+ // --- other ---
+
+ public long getRefreshTimestamp() {
+ readLock();
+ try {
+ return this.refreshTimestamp;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public void refresh() {
+ writeLock();
+ try {
+ String objectId = getObjectId();
+
+ OperationContext oc = getCreationContext();
+
+ // get the latest data from the repository
+ ObjectData objectData = getSession()
+ .getBinding()
+ .getObjectService()
+ .getObject(getRepositoryId(), objectId, oc.getFilterString(), oc.isIncludeAllowableActions(),
+ oc.getIncludeRelationships(), oc.getRenditionFilterString(), oc.isIncludePolicies(),
+ oc.isIncludeAcls(), null);
+
+ // reset this object
+ initialize(getSession(), getObjectType(), objectData, this.creationContext);
+ } finally {
+ writeUnlock();
+ }
+ }
+
+ public void refreshIfOld(long durationInMillis) {
+ writeLock();
+ try {
+ if (this.refreshTimestamp < System.currentTimeMillis() - durationInMillis) {
+ refresh();
+ }
+ } finally {
+ writeUnlock();
+ }
+ }
+}
Propchange: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractFilableCmisObject.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/AbstractFilableCmisObject.java?rev=1033918&view=auto
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractFilableCmisObject.java (added)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractFilableCmisObject.java Thu Nov 11 12:46:30 2010
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.data.PropertyString;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
+
+/**
+ * Base class for all filable persistent session object impl classes.
+ */
+public abstract class AbstractFilableCmisObject extends AbstractCmisObject implements
+ FileableCmisObject {
+
+ public List<Folder> getParents() {
+ String objectId = getObjectId();
+
+ // get object ids of the parent folders
+ List<ObjectParentData> providerParents = getBinding().getNavigationService().getObjectParents(
+ getRepositoryId(), objectId, getPropertyQueryName(PropertyIds.OBJECT_ID), false,
+ IncludeRelationships.NONE, null, false, null);
+
+ List<Folder> parents = new ArrayList<Folder>();
+
+ for (ObjectParentData p : providerParents) {
+ if ((p == null) || (p.getObject() == null) || (p.getObject().getProperties() == null)) {
+ // should not happen...
+ throw new CmisRuntimeException("Repository sent invalid data!");
+ }
+
+ // get id property
+ PropertyData<?> idProperty = p.getObject().getProperties().getProperties().get(PropertyIds.OBJECT_ID);
+ if (!(idProperty instanceof PropertyId)) {
+ // the repository sent an object without a valid object id...
+ throw new CmisRuntimeException("Repository sent invalid data! No object id!");
+ }
+
+ // fetch the object and make sure it is a folder
+ ObjectId parentId = getSession().createObjectId((String) idProperty.getFirstValue());
+ CmisObject parentFolder = getSession().getObject(parentId);
+ if (!(parentFolder instanceof Folder)) {
+ // the repository sent an object that is not a folder...
+ throw new CmisRuntimeException("Repository sent invalid data! Object is not a folder!");
+ }
+
+ parents.add((Folder) parentFolder);
+ }
+
+ return parents;
+ }
+
+ public List<String> getPaths() {
+ String objectId = getObjectId();
+
+ // get object paths of the parent folders
+ List<ObjectParentData> providerParents = getBinding().getNavigationService().getObjectParents(
+ getRepositoryId(), objectId, getPropertyQueryName(PropertyIds.PATH), false, IncludeRelationships.NONE,
+ null, true, null);
+
+ List<String> paths = new ArrayList<String>();
+
+ for (ObjectParentData p : providerParents) {
+ if ((p == null) || (p.getObject() == null) || (p.getObject().getProperties() == null)) {
+ // should not happen...
+ throw new CmisRuntimeException("Repository sent invalid data!");
+ }
+
+ // get path property
+ PropertyData<?> pathProperty = p.getObject().getProperties().getProperties().get(PropertyIds.PATH);
+ if (!(pathProperty instanceof PropertyString)) {
+ // the repository sent a folder without a valid path...
+ throw new CmisRuntimeException("Repository sent invalid data! No path property!");
+ }
+
+ if (p.getRelativePathSegment() == null) {
+ // the repository didn't send a relative path segment
+ throw new CmisRuntimeException("Repository sent invalid data! No relative path segement!");
+ }
+
+ String folderPath = ((String) pathProperty.getFirstValue());
+ paths.add(folderPath + (folderPath.endsWith("/") ? "" : "/") + p.getRelativePathSegment());
+ }
+
+ return paths;
+ }
+
+ public FileableCmisObject move(ObjectId sourceFolderId, ObjectId targetFolderId) {
+ String objectId = getObjectId();
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+
+ if ((sourceFolderId == null) || (sourceFolderId.getId() == null)) {
+ throw new IllegalArgumentException("Source folder id must be set!");
+ }
+
+ if ((targetFolderId == null) || (targetFolderId.getId() == null)) {
+ throw new IllegalArgumentException("Target folder id must be set!");
+ }
+
+ getBinding().getObjectService().moveObject(getRepositoryId(), objectIdHolder, targetFolderId.getId(),
+ sourceFolderId.getId(), null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ CmisObject movedObject = getSession().getObject(getSession().createObjectId(objectIdHolder.getValue()));
+ if (!(movedObject instanceof FileableCmisObject)) {
+ throw new CmisRuntimeException("Moved object is invalid!");
+ }
+
+ return (FileableCmisObject) movedObject;
+ }
+
+ public void addToFolder(ObjectId folderId, boolean allVersions) {
+ String objectId = getObjectId();
+
+ if ((folderId == null) || (folderId.getId() == null)) {
+ throw new IllegalArgumentException("Folder Id must be set!");
+ }
+
+ getBinding().getMultiFilingService().addObjectToFolder(getRepositoryId(), objectId, folderId.getId(),
+ allVersions, null);
+ }
+
+ public void removeFromFolder(ObjectId folderId) {
+ String objectId = getObjectId();
+
+ if ((folderId == null) || (folderId.getId() == null)) {
+ throw new IllegalArgumentException("Folder Id must be set!");
+ }
+
+ getBinding().getMultiFilingService()
+ .removeObjectFromFolder(getRepositoryId(), objectId, folderId.getId(), null);
+ }
+}
Propchange: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractFilableCmisObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.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/DocumentImpl.java?rev=1033918&view=auto
==============================================================================
--- incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java (added)
+++ incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java Thu Nov 11 12:46:30 2010
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.runtime;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.ObjectFactory;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.OperationContext;
+import org.apache.chemistry.opencmis.client.api.Policy;
+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.ObjectData;
+import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
+
+public class DocumentImpl extends AbstractFilableCmisObject implements Document {
+
+ /**
+ * Constructor.
+ */
+ public DocumentImpl(SessionImpl session, ObjectType objectType, ObjectData objectData,
+ OperationContext context) {
+ initialize(session, objectType, objectData, 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);
+ }
+
+ // operations
+
+ public Document copy(ObjectId targetFolderId, Map<String, ?> properties, VersioningState versioningState,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs, OperationContext context) {
+ if (targetFolderId == null || targetFolderId.getId() == null) {
+ throw new CmisInvalidArgumentException("Target must be set");
+ }
+
+ ObjectFactory factory = getObjectFactory();
+ Set<Updatability> updatability = new HashSet<Updatability>();
+ updatability.add(Updatability.READWRITE);
+
+ String newId = getBinding().getObjectService().createDocumentFromSource(getRepositoryId(), getId(),
+ factory.convertProperties(properties, getType(), updatability), targetFolderId.getId(),
+ versioningState, factory.convertPolicies(policies), factory.convertAces(addACEs),
+ factory.convertAces(removeACEs), null);
+
+ // if no context is provided the object will not be fetched
+ if (context == null || newId == null) {
+ return null;
+ }
+ // get the new object
+ CmisObject object = getSession().getObject(getSession().createObjectId(newId), context);
+ if (!(object instanceof Document)) {
+ throw new CmisRuntimeException("Newly created object is not a document! New id: " + newId);
+ }
+ return (Document) object;
+ }
+
+ public Document copy(ObjectId targetFolderId) {
+ return copy(targetFolderId, null, null, null, null, null, getSession().getDefaultContext());
+ }
+
+ public void deleteAllVersions() {
+ delete(true);
+ }
+
+ // versioning
+
+ public ObjectId checkOut() {
+ String objectId = getObjectId();
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+
+ getBinding().getVersioningService().checkOut(getRepositoryId(), objectIdHolder, null, null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ return getSession().createObjectId(objectIdHolder.getValue());
+ }
+
+ public void cancelCheckOut() {
+ String objectId = getObjectId();
+
+ getBinding().getVersioningService().cancelCheckOut(getRepositoryId(), objectId, null);
+ }
+
+ public ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream,
+ String checkinComment, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces) {
+ String objectId;
+ ObjectType type;
+ readLock();
+ try {
+ objectId = getObjectId();
+ type = getType();
+ } finally {
+ readUnlock();
+ }
+
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+
+ ObjectFactory of = getObjectFactory();
+
+ Set<Updatability> updatebility = new HashSet<Updatability>();
+ updatebility.add(Updatability.READWRITE);
+ updatebility.add(Updatability.WHENCHECKEDOUT);
+
+ getBinding().getVersioningService()
+ .checkIn(getRepositoryId(), objectIdHolder, major,
+ of.convertProperties(properties, type, updatebility), of.convertContentStream(contentStream),
+ checkinComment, of.convertPolicies(policies), of.convertAces(addAces),
+ of.convertAces(removeAces), null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ return getSession().createObjectId(objectIdHolder.getValue());
+
+ }
+
+ public List<Document> getAllVersions() {
+ return getAllVersions(getSession().getDefaultContext());
+ }
+
+ public List<Document> getAllVersions(OperationContext context) {
+ String objectId;
+ String versionSeriesId;
+
+ readLock();
+ try {
+ objectId = getObjectId();
+ versionSeriesId = getVersionSeriesId();
+ } finally {
+ readUnlock();
+ }
+
+ List<ObjectData> versions = getBinding().getVersioningService().getAllVersions(getRepositoryId(), objectId,
+ versionSeriesId, context.getFilterString(), context.isIncludeAllowableActions(), null);
+
+ ObjectFactory objectFactory = getSession().getObjectFactory();
+
+ List<Document> result = new ArrayList<Document>();
+ if (versions != null) {
+ for (ObjectData objectData : versions) {
+ CmisObject doc = objectFactory.convertObject(objectData, context);
+ if (!(doc instanceof Document)) {
+ // should not happen...
+ continue;
+ }
+
+ result.add((Document) doc);
+ }
+ }
+
+ return result;
+
+ }
+
+ public Document getObjectOfLatestVersion(boolean major) {
+ return getObjectOfLatestVersion(major, getSession().getDefaultContext());
+ }
+
+ public Document getObjectOfLatestVersion(boolean major, OperationContext context) {
+ String objectId;
+ String versionSeriesId;
+
+ readLock();
+ try {
+ objectId = getObjectId();
+ versionSeriesId = getVersionSeriesId();
+ } finally {
+ readUnlock();
+ }
+
+ if (versionSeriesId == null) {
+ throw new CmisRuntimeException("Version series id is unknown!");
+ }
+
+ ObjectData objectData = getBinding().getVersioningService().getObjectOfLatestVersion(getRepositoryId(),
+ objectId, versionSeriesId, major, context.getFilterString(), context.isIncludeAllowableActions(),
+ context.getIncludeRelationships(), context.getRenditionFilterString(), context.isIncludePolicies(),
+ context.isIncludeAcls(), null);
+
+ ObjectFactory objectFactory = getSession().getObjectFactory();
+
+ CmisObject result = objectFactory.convertObject(objectData, context);
+ if (!(result instanceof Document)) {
+ throw new CmisRuntimeException("Latest version is not a document!");
+ }
+
+ return (Document) result;
+ }
+
+ // content operations
+
+ public ContentStream getContentStream() {
+ return getContentStream(null);
+ }
+
+ public ContentStream getContentStream(String streamId) {
+ String objectId = getObjectId();
+
+ // get the stream
+ ContentStream contentStream;
+ try {
+ contentStream = getBinding().getObjectService().getContentStream(getRepositoryId(), objectId, streamId,
+ null, null, null);
+ } catch (CmisConstraintException e) {
+ // no content stream
+ return null;
+ }
+
+ // the AtomPub binding doesn't return a file name
+ // -> get the file name from properties, if present
+ String filename = contentStream.getFileName();
+ if (filename == null) {
+ filename = getContentStreamFileName();
+ }
+
+ // TODO: what should happen if the length is not set?
+ long length = (contentStream.getBigLength() == null ? -1 : contentStream.getBigLength().longValue());
+
+ // convert and return stream object
+ return getSession().getObjectFactory().createContentStream(filename, length, contentStream.getMimeType(),
+ contentStream.getStream());
+ }
+
+ public Document setContentStream(ContentStream contentStream, boolean overwrite) {
+ readLock();
+ try {
+ ObjectId objectId = setContentStreamOnly(contentStream, overwrite);
+ if (objectId == null) {
+ return null;
+ }
+
+ if (!getObjectId().equals(objectId.getId())) {
+ return (Document) getSession().getObject(objectId, getCreationContext());
+ }
+ } finally {
+ readUnlock();
+ }
+
+ refresh();
+
+ return this;
+ }
+
+ public ObjectId setContentStreamOnly(ContentStream contentStream, boolean overwrite) {
+ String objectId;
+ String changeToken;
+
+ readLock();
+ try {
+ objectId = getObjectId();
+ changeToken = getPropertyValue(PropertyIds.CHANGE_TOKEN);
+ } finally {
+ readUnlock();
+ }
+
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+ Holder<String> changeTokenHolder = new Holder<String>(changeToken);
+
+ getBinding().getObjectService().setContentStream(getRepositoryId(), objectIdHolder, overwrite,
+ changeTokenHolder, getObjectFactory().convertContentStream(contentStream), null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ return getSession().createObjectId(objectIdHolder.getValue());
+ }
+
+ public Document deleteContentStream() {
+ readLock();
+ try {
+ ObjectId objectId = deleteContentStreamOnly();
+ if (objectId == null) {
+ return null;
+ }
+
+ if (!getObjectId().equals(objectId.getId())) {
+ return (Document) getSession().getObject(objectId, getCreationContext());
+ }
+ } finally {
+ readUnlock();
+ }
+
+ refresh();
+
+ return this;
+ }
+
+ public ObjectId deleteContentStreamOnly() {
+ String objectId;
+ String changeToken;
+
+ readLock();
+ try {
+ objectId = getObjectId();
+ changeToken = getPropertyValue(PropertyIds.CHANGE_TOKEN);
+ } finally {
+ readUnlock();
+ }
+
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+ Holder<String> changeTokenHolder = new Holder<String>(changeToken);
+
+ getBinding().getObjectService().deleteContentStream(getRepositoryId(), objectIdHolder, changeTokenHolder, null);
+
+ if (objectIdHolder.getValue() == null) {
+ return null;
+ }
+
+ return getSession().createObjectId(objectIdHolder.getValue());
+ }
+
+ public ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream, String checkinComment) {
+ return this.checkIn(major, properties, contentStream, checkinComment, null, null, null);
+ }
+}
Propchange: incubator/chemistry/opencmis/branches/client-api-refactoring/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java
------------------------------------------------------------------------------
svn:eol-style = native