[alfresco-opencmis-extension] r13 committed - - Issue 5: added object type that has all property definitions (object...

17 views
Skip to first unread message

alfresco-opencmis-exte...@codespot.com

unread,
Nov 7, 2011, 1:54:30 PM11/7/11
to alfresco-opencmis...@googlegroups.com
Revision: 13
Author: flor...@gmail.com
Date: Mon Nov 7 10:53:15 2011
Log: - Issue 5: added object type that has all property definitions
(object + aspects)
- added methods to assign aspects and set aspect properties in one call
http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/source/detail?r=13

Added:
/trunk/src/main/java/org/alfresco/cmis/client/AlfrescoDocumentType.java
/trunk/src/main/java/org/alfresco/cmis/client/AlfrescoFolderType.java
/trunk/src/main/java/org/alfresco/cmis/client/AlfrescoObjectType.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentTypeImpl.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderTypeImpl.java
Modified:
/trunk/pom.xml
/trunk/src/main/java/org/alfresco/cmis/client/AlfrescoAspects.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsUtils.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentImpl.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderImpl.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoDocumentImpl.java

/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoFolderImpl.java
/trunk/src/test/org/alfresco/cmis/client/test/CMISClientTest.java
/trunk/src/test/org/alfresco/cmis/client/test/Test.java

=======================================
--- /dev/null
+++ /trunk/src/main/java/org/alfresco/cmis/client/AlfrescoDocumentType.java
Mon Nov 7 10:53:15 2011
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2005-2011 Alfresco Software Limited.
+ *
+ * Licensed 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.alfresco.cmis.client;
+
+import
org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
+
+public interface AlfrescoDocumentType extends DocumentTypeDefinition,
AlfrescoObjectType
+{
+}
=======================================
--- /dev/null
+++ /trunk/src/main/java/org/alfresco/cmis/client/AlfrescoFolderType.java
Mon Nov 7 10:53:15 2011
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2005-2011 Alfresco Software Limited.
+ *
+ * Licensed 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.alfresco.cmis.client;
+
+import
org.apache.chemistry.opencmis.commons.definitions.FolderTypeDefinition;
+
+public interface AlfrescoFolderType extends FolderTypeDefinition,
AlfrescoObjectType
+{
+}
=======================================
--- /dev/null
+++ /trunk/src/main/java/org/alfresco/cmis/client/AlfrescoObjectType.java
Mon Nov 7 10:53:15 2011
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2005-2011 Alfresco Software Limited.
+ *
+ * Licensed 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.alfresco.cmis.client;
+
+import java.util.Collection;
+
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+
+public interface AlfrescoObjectType extends ObjectType
+{
+ /**
+ * Returns the aspects that are assigned to the object this type
belongs to.
+ */
+ Collection<ObjectType> getAspects();
+}
=======================================
--- /dev/null
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentTypeImpl.java
Mon Nov 7 10:53:15 2011
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2005-2011 Alfresco Software Limited.
+ *
+ * Licensed 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.alfresco.cmis.client.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.cmis.client.AlfrescoDocument;
+import org.alfresco.cmis.client.AlfrescoDocumentType;
+import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.Tree;
+import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
+import
org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
+import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+
+public class AlfrescoDocumentTypeImpl implements AlfrescoDocumentType {
+ private static final long serialVersionUID = 1L;
+
+ private AlfrescoDocument doc;
+
+ public AlfrescoDocumentTypeImpl(AlfrescoDocument doc) {
+ this.doc = doc;
+ }
+
+ public Boolean isVersionable() {
+ return ((DocumentTypeDefinition) doc.getType()).isVersionable();
+ }
+
+ public ContentStreamAllowed getContentStreamAllowed() {
+ return ((DocumentTypeDefinition) doc.getType())
+ .getContentStreamAllowed();
+ }
+
+ public List<CmisExtensionElement> getExtensions()
+ {
+ return doc.getType().getExtensions();
+ }
+
+ public void setExtensions(List<CmisExtensionElement> extensions)
+ {
+ doc.getType().setExtensions(extensions);
+ }
+
+ public String getId() {
+ return doc.getType().getId();
+ }
+
+ public String getLocalName() {
+ return doc.getType().getLocalName();
+ }
+
+ public String getLocalNamespace() {
+ return doc.getType().getLocalNamespace();
+ }
+
+ public String getDisplayName() {
+ return doc.getType().getDisplayName();
+ }
+
+ public String getQueryName() {
+ return doc.getType().getQueryName();
+ }
+
+ public String getDescription() {
+ return doc.getType().getDescription();
+ }
+
+ public BaseTypeId getBaseTypeId() {
+ return doc.getType().getBaseTypeId();
+ }
+
+ public String getParentTypeId() {
+ return doc.getType().getParentTypeId();
+ }
+
+ public Boolean isCreatable() {
+ return doc.getType().isCreatable();
+ }
+
+ public Boolean isFileable() {
+ return doc.getType().isFileable();
+ }
+
+ public Boolean isQueryable() {
+ return doc.getType().isQueryable();
+ }
+
+ public Boolean isFulltextIndexed() {
+ return doc.getType().isFulltextIndexed();
+ }
+
+ public Boolean isIncludedInSupertypeQuery() {
+ return doc.getType().isIncludedInSupertypeQuery();
+ }
+
+ public Boolean isControllablePolicy() {
+ return doc.getType().isControllablePolicy();
+ }
+
+ public Boolean isControllableAcl() {
+ return doc.getType().isControllableAcl();
+ }
+
+ public Map<String, PropertyDefinition<?>> getPropertyDefinitions() {
+
+ Map<String, PropertyDefinition<?>> result = new HashMap<String,
PropertyDefinition<?>>(
+ doc.getType().getPropertyDefinitions());
+
+ for (ObjectType aspect : doc.getAspects()) {
+ result.putAll(aspect.getPropertyDefinitions());
+ }
+
+ return result;
+ }
+
+ public Collection<ObjectType> getAspects() {
+ return doc.getAspects();
+ }
+
+ public boolean isBaseType() {
+ return doc.getType().isBaseType();
+ }
+
+ public ObjectType getBaseType() {
+ return doc.getType().getBaseType();
+ }
+
+ public ObjectType getParentType() {
+ return doc.getType().getParentType();
+ }
+
+ public ItemIterable<ObjectType> getChildren() {
+ return doc.getType().getChildren();
+ }
+
+ public List<Tree<ObjectType>> getDescendants(int depth) {
+ return doc.getType().getDescendants(depth);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderTypeImpl.java
Mon Nov 7 10:53:15 2011
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2005-2011 Alfresco Software Limited.
+ *
+ * Licensed 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.alfresco.cmis.client.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.cmis.client.AlfrescoFolder;
+import org.alfresco.cmis.client.AlfrescoFolderType;
+import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.Tree;
+import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
+import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+
+public class AlfrescoFolderTypeImpl implements AlfrescoFolderType
+{
+ private static final long serialVersionUID = 1L;
+
+ private AlfrescoFolder folder;
+
+ public AlfrescoFolderTypeImpl(AlfrescoFolder folder)
+ {
+ this.folder = folder;
+ }
+
+ public List<CmisExtensionElement> getExtensions()
+ {
+ return folder.getType().getExtensions();
+ }
+
+ public void setExtensions(List<CmisExtensionElement> extensions)
+ {
+ folder.getType().setExtensions(extensions);
+ }
+
+ public String getId()
+ {
+ return folder.getType().getId();
+ }
+
+ public String getLocalName()
+ {
+ return folder.getType().getLocalName();
+ }
+
+ public String getLocalNamespace()
+ {
+ return folder.getType().getLocalNamespace();
+ }
+
+ public String getDisplayName()
+ {
+ return folder.getType().getDisplayName();
+ }
+
+ public String getQueryName()
+ {
+ return folder.getType().getQueryName();
+ }
+
+ public String getDescription()
+ {
+ return folder.getType().getDescription();
+ }
+
+ public BaseTypeId getBaseTypeId()
+ {
+ return folder.getType().getBaseTypeId();
+ }
+
+ public String getParentTypeId()
+ {
+ return folder.getType().getParentTypeId();
+ }
+
+ public Boolean isCreatable()
+ {
+ return folder.getType().isCreatable();
+ }
+
+ public Boolean isFileable()
+ {
+ return folder.getType().isFileable();
+ }
+
+ public Boolean isQueryable()
+ {
+ return folder.getType().isQueryable();
+ }
+
+ public Boolean isFulltextIndexed()
+ {
+ return folder.getType().isFulltextIndexed();
+ }
+
+ public Boolean isIncludedInSupertypeQuery()
+ {
+ return folder.getType().isIncludedInSupertypeQuery();
+ }
+
+ public Boolean isControllablePolicy()
+ {
+ return folder.getType().isControllablePolicy();
+ }
+
+ public Boolean isControllableAcl()
+ {
+ return folder.getType().isControllableAcl();
+ }
+
+ public Map<String, PropertyDefinition<?>> getPropertyDefinitions()
+ {
+
+ Map<String, PropertyDefinition<?>> result = new HashMap<String,
PropertyDefinition<?>>(folder.getType()
+ .getPropertyDefinitions());
+
+ for (ObjectType aspect : folder.getAspects())
+ {
+ result.putAll(aspect.getPropertyDefinitions());
+ }
+
+ return result;
+ }
+
+ public Collection<ObjectType> getAspects()
+ {
+ return folder.getAspects();
+ }
+
+ public boolean isBaseType()
+ {
+ return folder.getType().isBaseType();
+ }
+
+ public ObjectType getBaseType()
+ {
+ return folder.getType().getBaseType();
+ }
+
+ public ObjectType getParentType()
+ {
+ return folder.getType().getParentType();
+ }
+
+ public ItemIterable<ObjectType> getChildren()
+ {
+ return folder.getType().getChildren();
+ }
+
+ public List<Tree<ObjectType>> getDescendants(int depth)
+ {
+ return folder.getType().getDescendants(depth);
+ }
+}
=======================================
--- /trunk/pom.xml Mon Apr 4 06:16:31 2011
+++ /trunk/pom.xml Mon Nov 7 10:53:15 2011
@@ -20,7 +20,7 @@
<groupId>org.alfresco.cmis.client</groupId>
<artifactId>alfresco-opencmis-extension</artifactId>
<name>Alfresco OpenCMIS Extension</name>
- <version>0.2</version>
+ <version>0.3</version>
<packaging>jar</packaging>

<organization>
@@ -134,7 +134,7 @@
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl</artifactId>
- <version>0.3.0</version>
+ <version>0.5.0</version>
</dependency>
</dependencies>
</project>
=======================================
--- /trunk/src/main/java/org/alfresco/cmis/client/AlfrescoAspects.java Mon
Apr 4 04:55:46 2011
+++ /trunk/src/main/java/org/alfresco/cmis/client/AlfrescoAspects.java Mon
Nov 7 10:53:15 2011
@@ -16,84 +16,133 @@
package org.alfresco.cmis.client;

import java.util.Collection;
+import java.util.Map;

import org.apache.chemistry.opencmis.client.api.ObjectType;

/**
* Alfresco aspects interface.
*/
-public interface AlfrescoAspects
-{
- /**
- * Returns if the given aspect is applied to this object.
- *
- * @param id
- * the aspect id
- *
- * @return <code>true</code> if the aspect is applied,
<code>false</code>
- * otherwise
- */
- boolean hasAspect(String id);
-
- /**
- * Returns if the given aspect is applied to this object.
- *
- * @param type
- * the aspect object type
- *
- * @return <code>true</code> if the aspect is applied,
<code>false</code>
- * otherwise
- */
- boolean hasAspect(ObjectType type);
-
- /**
- * Returns all applied aspects. If no aspect is applied, an empty
collection
- * is returned.
- *
- * @return collection of the applied aspects
- */
- Collection<ObjectType> getAspects();
-
- /**
- * Returns the aspect type that defines the given property.
- *
- * @param propertyId
- * the property id
- *
- * @return the aspect type if the property id is defined in an applied
- * aspect, <code>null</code> otherwise
- */
- ObjectType findAspect(String propertyId);
-
- /**
- * Adds one or more aspects to the object.
- *
- * @param id
- * the aspect id or ids
- */
- void addAspect(String... id);
-
- /**
- * Adds one or more aspects to the object.
- *
- * @param id
- * the aspect type or types
- */
- void addAspect(ObjectType... type);
-
- /**
- * Removes one or more aspects from the object.
- *
- * @param id
- * the aspect id or ids
- */
- void removeAspect(String... id);
-
- /**
- * Removes one or more aspects from the object.
- *
- * @param id
- * the aspect type or types
- */
- void removeAspect(ObjectType... type);
-}
+public interface AlfrescoAspects {
+
+ /**
+ * Returns a type definition with the applied aspects.
+ *
+ * @return an object type with all property definitions (object and aspect
+ * properties).
+ */
+ ObjectType getTypeWithAspects();
+
+ /**
+ * Returns if the given aspect is applied to this object.
+ *
+ * @param id
+ * the aspect id
+ *
+ * @return <code>true</code> if the aspect is applied, <code>false</code>
+ * otherwise
+ */
+ boolean hasAspect(String id);
+
+ /**
+ * Returns if the given aspect is applied to this object.
+ *
+ * @param type
+ * the aspect object type
+ *
+ * @return <code>true</code> if the aspect is applied, <code>false</code>
+ * otherwise
+ */
+ boolean hasAspect(ObjectType type);
+
+ /**
+ * Returns all applied aspects. If no aspect is applied, an empty
collection
+ * is returned.
+ *
+ * @return collection of the applied aspects
+ */
+ Collection<ObjectType> getAspects();
+
+ /**
+ * Returns the aspect type that defines the given property.
+ *
+ * @param propertyId
+ * the property id
+ *
+ * @return the aspect type if the property id is defined in an applied
+ * aspect, <code>null</code> otherwise
+ */
+ ObjectType findAspect(String propertyId);
+
+ /**
+ * Adds one or more aspects to the object.
+ *
+ * @param id
+ * the aspect id or ids
+ */
+ void addAspect(String... id);
+
+ /**
+ * Adds one or more aspects to the object.
+ *
+ * @param type
+ * the aspect type or types
+ */
+ void addAspect(ObjectType... type);
+
+ /**
+ * Adds an aspect and sets aspect properties.
+ *
+ * @param type
+ * the aspect type
+ * @param properties
+ * the aspect properties
+ */
+ void addAspect(ObjectType type, Map<String, ?> properties);
+
+ /**
+ * Adds aspects and sets aspect properties.
+ *
+ * @param type
+ * the aspect types
+ * @param properties
+ * the aspect properties
+ */
+ void addAspect(ObjectType[] type, Map<String, ?> properties);
+
+ /**
+ * Adds an aspect and sets aspect properties.
+ *
+ * @param id
+ * the aspect type
+ * @param properties
+ * the aspect properties
+ */
+ void addAspect(String id, Map<String, ?> properties);
+
+ /**
+ * Adds aspects and sets aspect properties.
+ *
+ * @param id
+ * the aspect types
+ * @param properties
+ * the aspect properties
+ */
+ void addAspect(String[] id, Map<String, ?> properties);
+
+ /**
+ * Removes one or more aspects from the object.
+ *
+ * @param id
+ * the aspect id or ids
+ */
+ void removeAspect(String... id);
+
+ /**
+ * Removes one or more aspects from the object.
+ *
+ * @param id
+ * the aspect type or types
+ */
+ void removeAspect(ObjectType... type);
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Mon Nov 7 10:53:15 2011
@@ -22,111 +22,138 @@
import java.util.Map;

import org.alfresco.cmis.client.AlfrescoAspects;
+import org.alfresco.cmis.client.AlfrescoDocument;
+import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;

-public class AlfrescoAspectsImpl implements AlfrescoAspects
-{
- private Session session;
- private CmisObject object;
- private Map<String, ObjectType> aspectTypes;
-
- public AlfrescoAspectsImpl(Session session, CmisObject object)
- {
- this.session = session;
- this.object = object;
-
- List<CmisExtensionElement> alfrescoExtensions =
AlfrescoAspectsUtils.findAlfrescoExtensions(object
- .getExtensions(ExtensionLevel.PROPERTIES));
-
- if (alfrescoExtensions == null)
- {
- aspectTypes = Collections.emptyMap();
- } else
- {
- aspectTypes = new HashMap<String, ObjectType>();
- for (ObjectType type :
AlfrescoAspectsUtils.getAspectTypes(session, alfrescoExtensions))
- {
- if (type != null)
- {
- aspectTypes.put(type.getId(), type);
- }
- }
- }
- }
-
- public boolean hasAspect(String id)
- {
- return aspectTypes.containsKey(id);
- }
-
- public boolean hasAspect(ObjectType type)
- {
- return type == null ? false : hasAspect(type.getId());
- }
-
- public Collection<ObjectType> getAspects()
- {
- return aspectTypes.values();
- }
-
- public ObjectType findAspect(String propertyId)
- {
- return AlfrescoAspectsUtils.findAspect(aspectTypes.values(),
propertyId);
- }
-
- public void addAspect(String... id)
- {
- if (id == null || id.length == 0)
- {
- throw new IllegalArgumentException("Id must be set!");
- }
-
- ObjectType[] types = new ObjectType[id.length];
- for (int i = 0; i < id.length; i++)
- {
- types[i] = session.getTypeDefinition(id[i]);
- }
-
- addAspect(types);
- }
-
- public void addAspect(ObjectType... type)
- {
- if (type == null || type.length == 0)
- {
- throw new IllegalArgumentException("Type must be set!");
- }
-
- AlfrescoAspectsUtils.updateAspects(session, object.getId(), type,
null);
- }
-
- public void removeAspect(String... id)
- {
- if (id == null || id.length == 0)
- {
- throw new IllegalArgumentException("Id must be set!");
- }
-
- ObjectType[] types = new ObjectType[id.length];
- for (int i = 0; i < id.length; i++)
- {
- types[i] = session.getTypeDefinition(id[i]);
- }
-
- removeAspect(types);
- }
-
- public void removeAspect(ObjectType... type)
- {
- if (type == null || type.length == 0)
- {
- throw new IllegalArgumentException("Type must be set!");
- }
-
- AlfrescoAspectsUtils.updateAspects(session, object.getId(), null,
type);
- }
-}
+public class AlfrescoAspectsImpl implements AlfrescoAspects {
+ private Session session;
+ private CmisObject object;
+ private Map<String, ObjectType> aspectTypes;
+
+ public AlfrescoAspectsImpl(Session session, CmisObject object) {
+ this.session = session;
+ this.object = object;
+
+ List<CmisExtensionElement> alfrescoExtensions = AlfrescoAspectsUtils
+ .findAlfrescoExtensions(object
+ .getExtensions(ExtensionLevel.PROPERTIES));
+
+ if (alfrescoExtensions == null) {
+ aspectTypes = Collections.emptyMap();
+ } else {
+ aspectTypes = new HashMap<String, ObjectType>();
+ for (ObjectType type : AlfrescoAspectsUtils.getAspectTypes(session,
+ alfrescoExtensions)) {
+ if (type != null) {
+ aspectTypes.put(type.getId(), type);
+ }
+ }
+ }
+ }
+
+ public ObjectType getTypeWithAspects() {
+ if (object instanceof AlfrescoDocument) {
+ return new AlfrescoDocumentTypeImpl((AlfrescoDocument) object);
+ } else if (object instanceof AlfrescoFolder) {
+ return new AlfrescoFolderTypeImpl((AlfrescoFolder) object);
+ } else {
+ return object.getType();
+ }
+ }
+
+ public boolean hasAspect(String id) {
+ return aspectTypes.containsKey(id);
+ }
+
+ public boolean hasAspect(ObjectType type) {
+ return type == null ? false : hasAspect(type.getId());
+ }
+
+ public Collection<ObjectType> getAspects() {
+ return aspectTypes.values();
+ }
+
+ public ObjectType findAspect(String propertyId) {
+ return AlfrescoAspectsUtils
+ .findAspect(aspectTypes.values(), propertyId);
+ }
+
+ public void addAspect(String... id) {
+ if (id == null || id.length == 0) {
+ throw new IllegalArgumentException("Id must be set!");
+ }
+
+ ObjectType[] types = new ObjectType[id.length];
+ for (int i = 0; i < id.length; i++) {
+ types[i] = session.getTypeDefinition(id[i]);
+ }
+
+ addAspect(types);
+ }
+
+ public void addAspect(ObjectType... type) {
+ if (type == null || type.length == 0) {
+ throw new IllegalArgumentException("Type must be set!");
+ }
+
+ AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null,
+ null);
+ }
+
+ public void addAspect(ObjectType type, Map<String, ?> properties) {
+ addAspect(new ObjectType[] { type }, properties);
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties) {
+ if (type == null || type.length == 0) {
+ throw new IllegalArgumentException("Type must be set!");
+ }
+
+ AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null,
+ properties);
+ }
+
+ public void addAspect(String id, Map<String, ?> properties) {
+ addAspect(new String[] { id }, properties);
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties) {
+ if (id == null || id.length == 0) {
+ throw new IllegalArgumentException("Id must be set!");
+ }
+
+ ObjectType[] types = new ObjectType[id.length];
+ for (int i = 0; i < id.length; i++) {
+ types[i] = session.getTypeDefinition(id[i]);
+ }
+
+ addAspect(types, properties);
+ }
+
+ public void removeAspect(String... id) {
+ if (id == null || id.length == 0) {
+ throw new IllegalArgumentException("Id must be set!");
+ }
+
+ ObjectType[] types = new ObjectType[id.length];
+ for (int i = 0; i < id.length; i++) {
+ types[i] = session.getTypeDefinition(id[i]);
+ }
+
+ removeAspect(types);
+ }
+
+ public void removeAspect(ObjectType... type) {
+ if (type == null || type.length == 0) {
+ throw new IllegalArgumentException("Type must be set!");
+ }
+
+ AlfrescoAspectsUtils.updateAspects(session, object.getId(), null, type,
+ null);
+ }
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsUtils.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsUtils.java
Mon Nov 7 10:53:15 2011
@@ -232,7 +232,7 @@
return df.newXMLGregorianCalendar((GregorianCalendar)
value).toXMLFormat();
} else if (!(value instanceof String) && !(value instanceof
Number) && !(value instanceof Boolean))
{
- throw new IllegalArgumentException("Invalid ascpect value!");
+ throw new IllegalArgumentException("Invalid aspect value!");
}

return value.toString();
@@ -354,20 +354,27 @@
* Adds and removes aspects.
*/
public static void updateAspects(Session session, String objectId,
ObjectType[] addAspectIds,
- ObjectType[] removeAspectIds)
+ ObjectType[] removeAspectIds, Map<String, ?> properties)
{
String repId = session.getRepositoryInfo().getId();
Holder<String> objectIdHolder = new Holder<String>(objectId);
+ Map<String, PropertyDefinition<?>> aspectPropertyDefinition = null;

List<CmisExtensionElement> alfrescoExtensionList = new
ArrayList<CmisExtensionElement>();

if (addAspectIds != null)
{
+ aspectPropertyDefinition = new HashMap<String,
PropertyDefinition<?>>();
for (ObjectType type : addAspectIds)
{
if (type != null)
{

alfrescoExtensionList.add(AlfrescoAspectsUtils.createAspectsToAddExtension(type));
+
+ if (type.getPropertyDefinitions() != null)
+ {
+
aspectPropertyDefinition.putAll(type.getPropertyDefinitions());
+ }
}
}
}
@@ -388,10 +395,37 @@
return;
}

- Properties properties = new PropertiesImpl();
-
properties.setExtensions(Collections.singletonList(AlfrescoAspectsUtils
+ // add property values
+ if (addAspectIds != null && properties != null
&& !properties.isEmpty())
+ {
+ List<CmisExtensionElement> aspectProperties = new
ArrayList<CmisExtensionElement>(properties.size());
+
+ for (Map.Entry<String, ?> property : properties.entrySet())
+ {
+ if ((property == null) || (property.getKey() == null))
+ {
+ continue;
+ }
+
+ String id = property.getKey();
+ Object value = property.getValue();
+
+ if (!aspectPropertyDefinition.containsKey(id))
+ {
+ throw new IllegalArgumentException("Property '" + id
+ "' is not an aspect property!");
+ }
+
+
aspectProperties.add(createAspectPropertyExtension(aspectPropertyDefinition.get(id),
value));
+ }
+
+
alfrescoExtensionList.add(AlfrescoAspectsUtils.createAspectPropertiesExtension(aspectProperties));
+ }
+
+ // create properties object
+ Properties cmisProperties = new PropertiesImpl();
+
cmisProperties.setExtensions(Collections.singletonList(AlfrescoAspectsUtils
.createSetAspectsExtension(alfrescoExtensionList)));

- session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, properties, null);
+ session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, cmisProperties, null);
}
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentImpl.java
Mon Nov 7 10:53:15 2011
@@ -20,6 +20,7 @@
import java.util.Map;

import org.alfresco.cmis.client.AlfrescoDocument;
+import org.alfresco.cmis.client.AlfrescoDocumentType;
import org.apache.chemistry.opencmis.client.api.ObjectId;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.OperationContext;
@@ -31,148 +32,171 @@
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.data.ObjectData;

-public class AlfrescoDocumentImpl extends DocumentImpl implements
AlfrescoDocument
-{
- private static final long serialVersionUID = 1L;
-
- protected AlfrescoAspectsImpl aspects;
-
- public AlfrescoDocumentImpl(SessionImpl session, ObjectType
objectType, ObjectData objectData,
- OperationContext context)
- {
- super(session, objectType, objectData, context);
- }
-
- @Override
- protected void initialize(SessionImpl session, ObjectType objectType,
ObjectData objectData,
- OperationContext context)
- {
- super.initialize(session, objectType, objectData, context);
- aspects = new AlfrescoAspectsImpl(session, this);
- }
-
- @Override
- protected TransientCmisObject createTransientCmisObject()
- {
- TransientAlfrescoDocumentImpl td = new
TransientAlfrescoDocumentImpl();
- td.initialize(getSession(), this);
-
- return td;
- }
-
- @Override
- public ObjectId updateProperties(Map<String, ?> properties, boolean
refresh)
- {
- return super.updateProperties(
-
AlfrescoAspectsUtils.preparePropertiesForUpdate(properties, getType(),
getAspects()), refresh);
- }
-
- @Override
- public ObjectId checkIn(boolean major, Map<String, ?> properties,
ContentStream contentStream,
- String checkinComment, List<Policy> policies, List<Ace>
addAces, List<Ace> removeAces)
- {
- return super.checkIn(major,
-
AlfrescoAspectsUtils.preparePropertiesForUpdate(properties, getType(),
getAspects()), contentStream,
- checkinComment, policies, addAces, addAces);
- }
-
- public boolean hasAspect(String id)
- {
- readLock();
- try
- {
- return aspects.hasAspect(id);
- } finally
- {
- readUnlock();
- }
- }
-
- public boolean hasAspect(ObjectType type)
- {
- readLock();
- try
- {
- return aspects.hasAspect(type);
- } finally
- {
- readUnlock();
- }
- }
-
- public Collection<ObjectType> getAspects()
- {
- readLock();
- try
- {
- return aspects.getAspects();
- } finally
- {
- readUnlock();
- }
- }
-
- public ObjectType findAspect(String propertyId)
- {
- readLock();
- try
- {
- return aspects.findAspect(propertyId);
- } finally
- {
- readUnlock();
- }
- }
-
- public void addAspect(String... id)
- {
- readLock();
- try
- {
- aspects.addAspect(id);
- } finally
- {
- readUnlock();
- }
- refresh();
- }
-
- public void addAspect(ObjectType... type)
- {
- readLock();
- try
- {
- aspects.addAspect(type);
- } finally
- {
- readUnlock();
- }
- refresh();
- }
-
- public void removeAspect(String... id)
- {
- readLock();
- try
- {
- aspects.removeAspect(id);
- } finally
- {
- readUnlock();
- }
- refresh();
- }
-
- public void removeAspect(ObjectType... type)
- {
- readLock();
- try
- {
- aspects.removeAspect(type);
- } finally
- {
- readUnlock();
- }
- refresh();
- }
-}
+public class AlfrescoDocumentImpl extends DocumentImpl implements
+ AlfrescoDocument {
+ private static final long serialVersionUID = 1L;
+
+ protected AlfrescoAspectsImpl aspects;
+
+ public AlfrescoDocumentImpl(SessionImpl session, ObjectType objectType,
+ ObjectData objectData, OperationContext context) {
+ super(session, objectType, objectData, context);
+ }
+
+ @Override
+ protected void initialize(SessionImpl session, ObjectType objectType,
+ ObjectData objectData, OperationContext context) {
+ super.initialize(session, objectType, objectData, context);
+ aspects = new AlfrescoAspectsImpl(session, this);
+ }
+
+ @Override
+ protected TransientCmisObject createTransientCmisObject() {
+ TransientAlfrescoDocumentImpl td = new TransientAlfrescoDocumentImpl();
+ td.initialize(getSession(), this);
+
+ return td;
+ }
+
+ public AlfrescoDocumentType getTypeWithAspects() {
+ readLock();
+ try {
+ return new AlfrescoDocumentTypeImpl(this);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ @Override
+ public ObjectId updateProperties(Map<String, ?> properties, boolean
refresh) {
+ return super.updateProperties(
+ AlfrescoAspectsUtils.preparePropertiesForUpdate(properties,
+ getType(), getAspects()), refresh);
+ }
+
+ @Override
+ public ObjectId checkIn(boolean major, Map<String, ?> properties,
+ ContentStream contentStream, String checkinComment,
+ List<Policy> policies, List<Ace> addAces, List<Ace> removeAces) {
+ return super.checkIn(major,
+ AlfrescoAspectsUtils.preparePropertiesForUpdate(properties,
+ getType(), getAspects()), contentStream,
+ checkinComment, policies, addAces, addAces);
+ }
+
+ public boolean hasAspect(String id) {
+ readLock();
+ try {
+ return aspects.hasAspect(id);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public boolean hasAspect(ObjectType type) {
+ readLock();
+ try {
+ return aspects.hasAspect(type);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public Collection<ObjectType> getAspects() {
+ readLock();
+ try {
+ return aspects.getAspects();
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public ObjectType findAspect(String propertyId) {
+ readLock();
+ try {
+ return aspects.findAspect(propertyId);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public void addAspect(String... id) {
+ readLock();
+ try {
+ aspects.addAspect(id);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(ObjectType... type) {
+ readLock();
+ try {
+ aspects.addAspect(type);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(ObjectType type, Map<String, ?> properties) {
+ readLock();
+ try {
+ aspects.addAspect(type, properties);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties) {
+ readLock();
+ try {
+ aspects.addAspect(type, properties);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(String id, Map<String, ?> properties) {
+ readLock();
+ try {
+ aspects.addAspect(id, properties);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties) {
+ readLock();
+ try {
+ aspects.addAspect(id, properties);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void removeAspect(String... id) {
+ readLock();
+ try {
+ aspects.removeAspect(id);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void removeAspect(ObjectType... type) {
+ readLock();
+ try {
+ aspects.removeAspect(type);
+ } finally {
+ readUnlock();
+ }
+ refresh();
+ }
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderImpl.java
Mon Nov 7 10:53:15 2011
@@ -55,6 +55,18 @@

return td;
}
+
+ public ObjectType getTypeWithAspects()
+ {
+ readLock();
+ try
+ {
+ return aspects.getTypeWithAspects();
+ } finally
+ {
+ readUnlock();
+ }
+ }

@Override
public ObjectId updateProperties(Map<String, ?> properties, boolean
refresh)
@@ -136,6 +148,58 @@
}
refresh();
}
+
+ public void addAspect(ObjectType type, Map<String, ?> properties)
+ {
+ readLock();
+ try
+ {
+ aspects.addAspect(type, properties);
+ } finally
+ {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties)
+ {
+ readLock();
+ try
+ {
+ aspects.addAspect(type, properties);
+ } finally
+ {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(String id, Map<String, ?> properties)
+ {
+ readLock();
+ try
+ {
+ aspects.addAspect(id, properties);
+ } finally
+ {
+ readUnlock();
+ }
+ refresh();
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties)
+ {
+ readLock();
+ try
+ {
+ aspects.addAspect(id, properties);
+ } finally
+ {
+ readUnlock();
+ }
+ refresh();
+ }

public void removeAspect(String... id)
{
@@ -162,5 +226,4 @@
}
refresh();
}
-
-}
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Mon Nov 7 10:53:15 2011
@@ -25,158 +25,173 @@
import java.util.Set;

import org.alfresco.cmis.client.AlfrescoAspects;
+import org.alfresco.cmis.client.AlfrescoDocument;
+import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.client.api.TransientCmisObject;
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;

-public class TransientAlfrescoAspectsImpl implements AlfrescoAspects
-{
- private Session session;
- private CmisObject object;
- private Map<String, ObjectType> aspectTypes;
- private Map<String, ObjectType> addAspectTypes;
- private Map<String, ObjectType> removeAspectTypes;
-
- public TransientAlfrescoAspectsImpl(Session session, CmisObject object)
- {
- this.session = session;
- this.object = object;
-
- List<CmisExtensionElement> alfrescoExtensions =
AlfrescoAspectsUtils.findAlfrescoExtensions(object
- .getExtensions(ExtensionLevel.PROPERTIES));
-
- if (alfrescoExtensions == null)
- {
- aspectTypes = Collections.emptyMap();
- } else
- {
- aspectTypes = new HashMap<String, ObjectType>();
- for (ObjectType type :
AlfrescoAspectsUtils.getAspectTypes(session, alfrescoExtensions))
- {
- if (type != null)
- {
- aspectTypes.put(type.getId(), type);
- }
- }
- }
-
- addAspectTypes = new HashMap<String, ObjectType>();
- removeAspectTypes = new HashMap<String, ObjectType>();
- }
-
- public boolean hasAspect(String id)
- {
- return (aspectTypes.containsKey(id) ||
addAspectTypes.containsKey(id)) && (!removeAspectTypes.containsKey(id));
- }
-
- public boolean hasAspect(ObjectType type)
- {
- return type == null ? false : hasAspect(type.getId());
- }
-
- public Collection<ObjectType> getAspects()
- {
- Collection<ObjectType> result = new ArrayList<ObjectType>();
- Set<String> addTypes = new
HashSet<String>(addAspectTypes.keySet());
-
- for (String typeId : aspectTypes.keySet())
- {
- if (!removeAspectTypes.containsKey(typeId))
- {
- result.add(aspectTypes.get(typeId));
- }
- addTypes.remove(typeId);
- }
-
- for (String typeId : addTypes)
- {
- result.add(addAspectTypes.get(typeId));
- }
-
- return result;
- }
-
- public ObjectType findAspect(String propertyId)
- {
- return AlfrescoAspectsUtils.findAspect(getAspects(), propertyId);
- }
-
- public void addAspect(String... id)
- {
- if (id == null || id.length == 0)
- {
- throw new IllegalArgumentException("Id must be set!");
- }
-
- ObjectType[] types = new ObjectType[id.length];
- for (int i = 0; i < id.length; i++)
- {
- types[i] = session.getTypeDefinition(id[i]);
- }
-
- addAspect(types);
- }
-
- public void addAspect(ObjectType... type)
- {
- if (type == null || type.length == 0)
- {
- throw new IllegalArgumentException("Type must be set!");
- }
-
- for (ObjectType t : type)
- {
- if (t != null)
- {
- addAspectTypes.put(t.getId(), t);
- removeAspectTypes.remove(t.getId());
- }
- }
- }
-
- public void removeAspect(String... id)
- {
- if (id == null || id.length == 0)
- {
- throw new IllegalArgumentException("Id must be set!");
- }
-
- ObjectType[] types = new ObjectType[id.length];
- for (int i = 0; i < id.length; i++)
- {
- types[i] = session.getTypeDefinition(id[i]);
- }
-
- removeAspect(types);
- }
-
- public void removeAspect(ObjectType... type)
- {
- if (type == null || type.length == 0)
- {
- throw new IllegalArgumentException("Type must be set!");
- }
-
- for (ObjectType t : type)
- {
- if (t != null)
- {
- addAspectTypes.remove(t.getId());
- removeAspectTypes.put(t.getId(), t);
- }
- }
- }
-
- public void save()
- {
- if (addAspectTypes.isEmpty() && removeAspectTypes.isEmpty())
- {
- return;
- }
-
- AlfrescoAspectsUtils.updateAspects(session, object.getId(),
addAspectTypes.values().toArray(new ObjectType[0]),
- removeAspectTypes.values().toArray(new ObjectType[0]));
- }
-}
+public class TransientAlfrescoAspectsImpl implements AlfrescoAspects {
+ private Session session;
+ private CmisObject object;
+ private Map<String, ObjectType> aspectTypes;
+ private Map<String, ObjectType> addAspectTypes;
+ private Map<String, ObjectType> removeAspectTypes;
+
+ public TransientAlfrescoAspectsImpl(Session session, CmisObject object) {
+ this.session = session;
+ this.object = object;
+
+ List<CmisExtensionElement> alfrescoExtensions = AlfrescoAspectsUtils
+ .findAlfrescoExtensions(object
+ .getExtensions(ExtensionLevel.PROPERTIES));
+
+ if (alfrescoExtensions == null) {
+ aspectTypes = Collections.emptyMap();
+ } else {
+ aspectTypes = new HashMap<String, ObjectType>();
+ for (ObjectType type : AlfrescoAspectsUtils.getAspectTypes(session,
+ alfrescoExtensions)) {
+ if (type != null) {
+ aspectTypes.put(type.getId(), type);
+ }
+ }
+ }
+
+ addAspectTypes = new HashMap<String, ObjectType>();
+ removeAspectTypes = new HashMap<String, ObjectType>();
+ }
+
+ public ObjectType getTypeWithAspects() {
+ if (object instanceof AlfrescoDocument) {
+ return new AlfrescoDocumentTypeImpl((AlfrescoDocument) object);
+ } else if (object instanceof AlfrescoFolder) {
+ return new AlfrescoFolderTypeImpl((AlfrescoFolder) object);
+ } else {
+ return object.getType();
+ }
+ }
+
+ public boolean hasAspect(String id) {
+ return (aspectTypes.containsKey(id) || addAspectTypes.containsKey(id))
+ && (!removeAspectTypes.containsKey(id));
+ }
+
+ public boolean hasAspect(ObjectType type) {
+ return type == null ? false : hasAspect(type.getId());
+ }
+
+ public Collection<ObjectType> getAspects() {
+ Collection<ObjectType> result = new ArrayList<ObjectType>();
+ Set<String> addTypes = new HashSet<String>(addAspectTypes.keySet());
+
+ for (String typeId : aspectTypes.keySet()) {
+ if (!removeAspectTypes.containsKey(typeId)) {
+ result.add(aspectTypes.get(typeId));
+ }
+ addTypes.remove(typeId);
+ }
+
+ for (String typeId : addTypes) {
+ result.add(addAspectTypes.get(typeId));
+ }
+
+ return result;
+ }
+
+ public ObjectType findAspect(String propertyId) {
+ return AlfrescoAspectsUtils.findAspect(getAspects(), propertyId);
+ }
+
+ public void addAspect(String... id) {
+ if (id == null || id.length == 0) {
+ throw new IllegalArgumentException("Id must be set!");
+ }
+
+ ObjectType[] types = new ObjectType[id.length];
+ for (int i = 0; i < id.length; i++) {
+ types[i] = session.getTypeDefinition(id[i]);
+ }
+
+ addAspect(types);
+ }
+
+ public void addAspect(ObjectType... type) {
+ if (type == null || type.length == 0) {
+ throw new IllegalArgumentException("Type must be set!");
+ }
+
+ for (ObjectType t : type) {
+ if (t != null) {
+ addAspectTypes.put(t.getId(), t);
+ removeAspectTypes.remove(t.getId());
+ }
+ }
+ }
+
+ public void setPropertyValues(TransientCmisObject object,
+ Map<String, ?> properties) {
+ if (properties == null || properties.isEmpty()) {
+ return;
+ }
+
+ for (Map.Entry<String, ?> property : properties.entrySet()) {
+ object.setPropertyValue(property.getKey(), property.getValue());
+ }
+ }
+
+ public void addAspect(ObjectType type, Map<String, ?> properties) {
+ addAspect(type);
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties) {
+ addAspect(type);
+ }
+
+ public void addAspect(String id, Map<String, ?> properties) {
+ addAspect(id);
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties) {
+ addAspect(id);
+ }
+
+ public void removeAspect(String... id) {
+ if (id == null || id.length == 0) {
+ throw new IllegalArgumentException("Id must be set!");
+ }
+
+ ObjectType[] types = new ObjectType[id.length];
+ for (int i = 0; i < id.length; i++) {
+ types[i] = session.getTypeDefinition(id[i]);
+ }
+
+ removeAspect(types);
+ }
+
+ public void removeAspect(ObjectType... type) {
+ if (type == null || type.length == 0) {
+ throw new IllegalArgumentException("Type must be set!");
+ }
+
+ for (ObjectType t : type) {
+ if (t != null) {
+ addAspectTypes.remove(t.getId());
+ removeAspectTypes.put(t.getId(), t);
+ }
+ }
+ }
+
+ public void save() {
+ if (addAspectTypes.isEmpty() && removeAspectTypes.isEmpty()) {
+ return;
+ }
+
+ AlfrescoAspectsUtils.updateAspects(session, object.getId(),
+ addAspectTypes.values().toArray(new ObjectType[0]),
+ removeAspectTypes.values().toArray(new ObjectType[0]), null);
+ }
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoDocumentImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoDocumentImpl.java
Mon Nov 7 10:53:15 2011
@@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;

import org.alfresco.cmis.client.TransientAlfrescoDocument;
import org.apache.chemistry.opencmis.client.api.CmisObject;
@@ -31,114 +32,128 @@
import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.Updatability;

-public class TransientAlfrescoDocumentImpl extends TransientDocumentImpl
implements TransientAlfrescoDocument
-{
- protected TransientAlfrescoAspectsImpl aspects;
-
- @Override
- protected void initialize(Session session, CmisObject object)
- {
- super.initialize(session, object);
- aspects = new TransientAlfrescoAspectsImpl(session, object);
+public class TransientAlfrescoDocumentImpl extends TransientDocumentImpl
+ implements TransientAlfrescoDocument {
+ protected TransientAlfrescoAspectsImpl aspects;
+
+ @Override
+ protected void initialize(Session session, CmisObject object) {
+ super.initialize(session, object);
+ aspects = new TransientAlfrescoAspectsImpl(session, object);
+ }
+
+ public ObjectType getTypeWithAspects()
+ {
+ return aspects.getTypeWithAspects();
}

- @SuppressWarnings("unchecked")
- public <T> void setPropertyValue(String id, Object value)
- {
- ObjectType aspectType = aspects.findAspect(id);
-
- if (aspectType == null)
- {
- super.setPropertyValue(id, value);
- return;
- }
-
- PropertyDefinition<T> propertyDefinition = (PropertyDefinition<T>)
aspectType.getPropertyDefinitions().get(id);
- if (propertyDefinition == null)
- {
- throw new IllegalArgumentException("Unknown property '" + id
+ "'!");
- }
- // check updatability
- if (propertyDefinition.getUpdatability() == Updatability.READONLY)
- {
- throw new IllegalArgumentException("Property is read-only!");
- }
-
- List<T> values =
AlfrescoAspectsUtils.checkProperty(propertyDefinition, value);
-
- // create and set property
- Property<T> newProperty =
getObjectFactory().createProperty(propertyDefinition, values);
- properties.put(id, newProperty);
-
- isPropertyUpdateRequired = true;
- isModified = true;
- }
-
- public boolean hasAspect(String id)
- {
- return aspects.hasAspect(id);
- }
-
- public boolean hasAspect(ObjectType type)
- {
- return aspects.hasAspect(type);
- }
-
- public Collection<ObjectType> getAspects()
- {
- return aspects.getAspects();
- }
-
- public ObjectType findAspect(String propertyId)
- {
- return aspects.findAspect(propertyId);
- }
-
- public void addAspect(String... id)
- {
- aspects.addAspect(id);
- }
-
- public void addAspect(ObjectType... type)
- {
- aspects.addAspect(type);
- }
-
- public void removeAspect(String... id)
- {
- aspects.removeAspect(id);
- }
-
- public void removeAspect(ObjectType... type)
- {
- aspects.removeAspect(type);
- }
-
- @Override
- public ObjectId save()
- {
- ObjectId id = super.save();
- if (!isMarkedForDelete)
- {
- aspects.save();
- }
-
- return id;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected Properties prepareProperties()
- {
- ObjectType type = getType();
- PropertyDefinition<String> propDef = (PropertyDefinition<String>)
type.getPropertyDefinitions().get(
- PropertyIds.OBJECT_TYPE_ID);
- String objectTypeIdValue =
AlfrescoAspectsUtils.createObjectTypeIdValue(type, getAspects());
- Property<String> objectTypeIdProperty =
getObjectFactory().createProperty(propDef,
- Collections.singletonList(objectTypeIdValue));
-
- properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeIdProperty);
-
- return super.prepareProperties();
- }
-}
+ @SuppressWarnings("unchecked")
+ public <T> void setPropertyValue(String id, Object value) {
+ ObjectType aspectType = aspects.findAspect(id);
+
+ if (aspectType == null) {
+ super.setPropertyValue(id, value);
+ return;
+ }
+
+ PropertyDefinition<T> propertyDefinition = (PropertyDefinition<T>)
aspectType
+ .getPropertyDefinitions().get(id);
+ if (propertyDefinition == null) {
+ throw new IllegalArgumentException("Unknown property '" + id + "'!");
+ }
+ // check updatability
+ if (propertyDefinition.getUpdatability() == Updatability.READONLY) {
+ throw new IllegalArgumentException("Property is read-only!");
+ }
+
+ List<T> values = AlfrescoAspectsUtils.checkProperty(propertyDefinition,
+ value);
+
+ // create and set property
+ Property<T> newProperty = getObjectFactory().createProperty(
+ propertyDefinition, values);
+ properties.put(id, newProperty);
+
+ isPropertyUpdateRequired = true;
+ isModified = true;
+ }
+
+ public boolean hasAspect(String id) {
+ return aspects.hasAspect(id);
+ }
+
+ public boolean hasAspect(ObjectType type) {
+ return aspects.hasAspect(type);
+ }
+
+ public Collection<ObjectType> getAspects() {
+ return aspects.getAspects();
+ }
+
+ public ObjectType findAspect(String propertyId) {
+ return aspects.findAspect(propertyId);
+ }
+
+ public void addAspect(String... id) {
+ aspects.addAspect(id);
+ }
+
+ public void addAspect(ObjectType... type) {
+ aspects.addAspect(type);
+ }
+
+ public void addAspect(ObjectType type, Map<String, ?> properties) {
+ aspects.addAspect(type);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties) {
+ aspects.addAspect(type);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(String id, Map<String, ?> properties) {
+ aspects.addAspect(id);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties) {
+ aspects.addAspect(id);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void removeAspect(String... id) {
+ aspects.removeAspect(id);
+ }
+
+ public void removeAspect(ObjectType... type) {
+ aspects.removeAspect(type);
+ }
+
+ @Override
+ public ObjectId save() {
+ ObjectId id = super.save();
+ if (!isMarkedForDelete) {
+ aspects.save();
+ }
+
+ return id;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Properties prepareProperties() {
+ ObjectType type = getType();
+ PropertyDefinition<String> propDef = (PropertyDefinition<String>) type
+ .getPropertyDefinitions().get(PropertyIds.OBJECT_TYPE_ID);
+ String objectTypeIdValue = AlfrescoAspectsUtils
+ .createObjectTypeIdValue(type, getAspects());
+ Property<String> objectTypeIdProperty = getObjectFactory()
+ .createProperty(propDef,
+ Collections.singletonList(objectTypeIdValue));
+
+ properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeIdProperty);
+
+ return super.prepareProperties();
+ }
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoFolderImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoFolderImpl.java
Mon Nov 7 10:53:15 2011
@@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;

import org.alfresco.cmis.client.AlfrescoAspects;
import org.apache.chemistry.opencmis.client.api.CmisObject;
@@ -41,6 +42,11 @@
super.initialize(session, object);
aspects = new TransientAlfrescoAspectsImpl(session, object);
}
+
+ public ObjectType getTypeWithAspects()
+ {
+ return aspects.getTypeWithAspects();
+ }

@SuppressWarnings("unchecked")
public <T> void setPropertyValue(String id, Object value)
@@ -108,6 +114,30 @@
{
aspects.removeAspect(id);
}
+
+ public void addAspect(ObjectType type, Map<String, ?> properties)
+ {
+ aspects.addAspect(type);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(ObjectType[] type, Map<String, ?> properties)
+ {
+ aspects.addAspect(type);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(String id, Map<String, ?> properties)
+ {
+ aspects.addAspect(id);
+ aspects.setPropertyValues(this, properties);
+ }
+
+ public void addAspect(String[] id, Map<String, ?> properties)
+ {
+ aspects.addAspect(id);
+ aspects.setPropertyValues(this, properties);
+ }

public void removeAspect(ObjectType... type)
{
=======================================
--- /trunk/src/test/org/alfresco/cmis/client/test/CMISClientTest.java Fri
Apr 1 03:51:20 2011
+++ /trunk/src/test/org/alfresco/cmis/client/test/CMISClientTest.java Mon
Nov 7 10:53:15 2011
@@ -55,7 +55,7 @@
parameter.put(SessionParameter.PASSWORD, "admin");

// connection settings
-
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/service/cmis");
+
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
parameter.put(SessionParameter.BINDING_TYPE,
BindingType.ATOMPUB.value());

parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

@@ -84,7 +84,7 @@

assertTrue(alfDoc.hasAspect("P:cm:titled"));
assertFalse(alfDoc.hasAspect("P:cm:taggable"));
- assertEquals(1, alfDoc.getAspects().size());
+ assertTrue(alfDoc.getAspects().size() > 0);

ObjectType titledAspectType = alfDoc.findAspect("cm:description");
assertNotNull(titledAspectType);
@@ -103,20 +103,24 @@
assertEquals(descriptionValue2,
descriptionProperty.getFirstValue());

// add aspect
+ int aspectCount = alfDoc.getAspects().size();
alfDoc.addAspect("P:cm:taggable");

assertTrue(alfDoc.hasAspect("P:cm:titled"));

assertTrue(alfDoc.hasAspect(session.getTypeDefinition("P:cm:titled")));
assertTrue(alfDoc.hasAspect("P:cm:taggable"));

assertTrue(alfDoc.hasAspect(session.getTypeDefinition("P:cm:taggable")));
- assertEquals(2, alfDoc.getAspects().size());
+ assertEquals(aspectCount + 1, alfDoc.getAspects().size());
+
+ ObjectType alfType = alfDoc.getTypeWithAspects();
+
assertNotNull(alfType.getPropertyDefinitions().get("cm:description"));

// remove aspect
alfDoc.removeAspect("P:cm:titled");

assertFalse(alfDoc.hasAspect("P:cm:titled"));
assertTrue(alfDoc.hasAspect("P:cm:taggable"));
- assertEquals(1, alfDoc.getAspects().size());
+ assertEquals(aspectCount, alfDoc.getAspects().size());

assertNull(doc.getProperty("cm:description"));

@@ -135,6 +139,37 @@
// delete
alfDoc.delete(true);
}
+
+ public void testAddAspectWithProperties()
+ {
+ String descriptionValue1 = "Beschreibung";
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.NAME, "test1");
+ properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
+
+ Document doc = session.getRootFolder().createDocument(properties,
null, null);
+
+ assertTrue(doc instanceof AlfrescoDocument);
+ AlfrescoDocument alfDoc = (AlfrescoDocument) doc;
+
+ // add aspect
+ Map<String, Object> aspectProperties = new HashMap<String,
Object>();
+ aspectProperties.put("cm:description", descriptionValue1);
+
+ alfDoc.addAspect("P:cm:titled", aspectProperties);
+
+ assertTrue(alfDoc.hasAspect("P:cm:titled"));
+ assertEquals(descriptionValue1,
alfDoc.getPropertyValue("cm:description"));
+
+ // remove aspect
+ alfDoc.removeAspect("P:cm:titled");
+
+ assertFalse(alfDoc.hasAspect("P:cm:titled"));
+
+ // delete
+ alfDoc.delete(true);
+ }

public void testTransientDocument()
{
@@ -249,11 +284,11 @@
List<String> tags = new ArrayList<String>();

tags.add("workspace://SpacesStore/a807b10e-6dea-403f-88f1-33e2383890dd");

tags.add("workspace://SpacesStore/a728d30f-0bbe-48cf-9557-2d6b7cb63b45");
-
+
properties = new HashMap<String, Object>();
properties.put("cm:taggable", tags);
doc.updateProperties(properties);
-
+
// delete
doc.delete(true);
}
=======================================
--- /trunk/src/test/org/alfresco/cmis/client/test/Test.java Fri Apr 1
03:51:20 2011
+++ /trunk/src/test/org/alfresco/cmis/client/test/Test.java Mon Nov 7
10:53:15 2011
@@ -41,8 +41,31 @@
parameter.put(SessionParameter.PASSWORD, "admin");

// connection settings
-
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/service/cmis");
- parameter.put(SessionParameter.BINDING_TYPE,
BindingType.ATOMPUB.value());
+ // parameter.put(SessionParameter.ATOMPUB_URL,
+ // "http://localhost:8080/alfresco/cmisatom");
+ // parameter.put(SessionParameter.BINDING_TYPE,
+ // BindingType.ATOMPUB.value());
+
+ parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/RepositoryService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/NavigationService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/ObjectService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/VersioningService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
+ "http://localhost:8080/alfresco/cmis/DiscoveryService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/MultiFilingService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/RelationshipService?wsdl");
+ parameter
+ .put(SessionParameter.WEBSERVICES_ACL_SERVICE, "http://localhost:8080/alfresco/cmisws/ACLService?wsdl");
+ parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE,
+ "http://localhost:8080/alfresco/cmisws/PolicyService?wsdl");
+
+ parameter.put(SessionParameter.BINDING_TYPE,
BindingType.WEBSERVICES.value());

parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

// create session

Reply all
Reply to author
Forward
0 new messages