Revision: 24
Author:
steven...@gmail.com
Date: Mon Jun 10 03:33:56 2013
Log: Enhancements/changes for CMIS 1.1 and OpenCMIS 0.9
http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/source/detail?r=24
Modified:
/trunk/pom.xml
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentTypeImpl.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderTypeImpl.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoObjectFactoryImpl.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoUtils.java
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
=======================================
--- /trunk/pom.xml Tue Oct 30 12:25:57 2012
+++ /trunk/pom.xml Mon Jun 10 03:33:56 2013
@@ -20,7 +20,7 @@
<groupId>org.alfresco.cmis.client</groupId>
<artifactId>alfresco-opencmis-extension</artifactId>
<name>Alfresco OpenCMIS Extension</name>
- <version>0.4</version>
+ <version>0.5</version>
<packaging>jar</packaging>
<organization>
@@ -34,6 +34,16 @@
The Alfresco OpenCMIS Extension is an extension of Apache
Chemistry OpenCMIS.
</description>
+ <repositories>
+ <repository>
+ <id>apache-snapshots</id>
+ <url>
https://repository.apache.org/content/groups/snapshots/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
+
<licenses>
<license>
<name>Apache 2</name>
@@ -78,7 +88,6 @@
<maven.compile.target>1.5</maven.compile.target>
</properties>
-
<build>
<resources>
<resource>
@@ -158,22 +167,27 @@
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl</artifactId>
- <version>0.8.0</version>
+ <version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-api</artifactId>
- <version>0.8.0</version>
+ <version>0.9.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.chemistry.opencmis</groupId>
+ <artifactId>chemistry-opencmis-client-bindings</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-commons-impl</artifactId>
- <version>0.8.0</version>
+ <version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-commons-api</artifactId>
- <version>0.8.0</version>
+ <version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
@@ -185,5 +199,10 @@
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>4.11</version>
+ </dependency>
</dependencies>
</project>
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Fri Feb 17 09:34:36 2012
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Mon Jun 10 03:33:56 2013
@@ -26,7 +26,9 @@
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.Property;
import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel;
@@ -39,18 +41,34 @@
this.session = session;
this.object = object;
- List<CmisExtensionElement> alfrescoExtensions = AlfrescoUtils
- .findAlfrescoExtensions(object
- .getExtensions(ExtensionLevel.PROPERTIES));
-
- if (alfrescoExtensions == null) {
- aspectTypes = Collections.emptyMap();
- } else {
+ Property<?> secondaryTypesProp =
object.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ if(secondaryTypesProp != null)
+ {
+ // cmis 1.1
+ List<String> secondaryTypes = secondaryTypesProp.getValue();
aspectTypes = new HashMap<String, ObjectType>();
- for (ObjectType type : AlfrescoUtils.getAspectTypes(session,
- alfrescoExtensions)) {
- if (type != null) {
- aspectTypes.put(type.getId(), type);
+ for(String secondaryType : secondaryTypes)
+ {
+ ObjectType aspectType =
session.getTypeDefinition(secondaryType);
+ aspectTypes.put(aspectType.getId(), aspectType);
+ }
+ }
+ else
+ {
+ // cmis 1.0
+ List<CmisExtensionElement> alfrescoExtensions = AlfrescoUtils
+ .findAlfrescoExtensions(object
+ .getExtensions(ExtensionLevel.PROPERTIES));
+
+ if (alfrescoExtensions == null) {
+ aspectTypes = Collections.emptyMap();
+ } else {
+ aspectTypes = new HashMap<String, ObjectType>();
+ for (ObjectType type : AlfrescoUtils.getAspectTypes(session,
+ alfrescoExtensions)) {
+ if (type != null) {
+ aspectTypes.put(type.getId(), type);
+ }
}
}
}
@@ -101,7 +119,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoUtils.updateAspects(session, object.getId(), type, null,
+ AlfrescoUtils.updateAspects(session, object, type, null,
null);
}
@@ -114,7 +132,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoUtils.updateAspects(session, object.getId(), type, null,
+ AlfrescoUtils.updateAspects(session, object, type, null,
properties);
}
@@ -153,7 +171,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoUtils.updateAspects(session, object.getId(), null, type,
+ AlfrescoUtils.updateAspects(session, object, null, type,
null);
}
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentTypeImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentTypeImpl.java
Mon Jun 10 03:33:56 2013
@@ -28,8 +28,10 @@
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.definitions.TypeMutability;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
public class AlfrescoDocumentTypeImpl implements AlfrescoDocumentType {
private static final long serialVersionUID = 1L;
@@ -154,4 +156,13 @@
public List<Tree<ObjectType>> getDescendants(int depth) {
return doc.getType().getDescendants(depth);
}
+
+ public TypeMutability getTypeMutability()
+ {
+ TypeMutabilityImpl typeMutability = new TypeMutabilityImpl();
+ typeMutability.setCanCreate(Boolean.FALSE);
+ typeMutability.setCanDelete(Boolean.FALSE);
+ typeMutability.setCanUpdate(Boolean.FALSE);
+ return typeMutability;
+ }
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderTypeImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderTypeImpl.java
Mon Jun 10 03:33:56 2013
@@ -27,7 +27,9 @@
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.definitions.TypeMutability;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
public class AlfrescoFolderTypeImpl implements AlfrescoFolderType
{
@@ -168,4 +170,13 @@
{
return folder.getType().getDescendants(depth);
}
+
+ public TypeMutability getTypeMutability()
+ {
+ TypeMutabilityImpl typeMutability = new TypeMutabilityImpl();
+ typeMutability.setCanCreate(Boolean.FALSE);
+ typeMutability.setCanDelete(Boolean.FALSE);
+ typeMutability.setCanUpdate(Boolean.FALSE);
+ return typeMutability;
+ }
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoObjectFactoryImpl.java
Fri Feb 17 09:34:36 2012
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoObjectFactoryImpl.java
Mon Jun 10 03:33:56 2013
@@ -31,10 +31,12 @@
import org.alfresco.cmis.client.type.AlfrescoFolderType;
import org.alfresco.cmis.client.type.AlfrescoPolicyType;
import org.alfresco.cmis.client.type.AlfrescoRelationshipType;
+import org.alfresco.cmis.client.type.AlfrescoSecondaryType;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.OperationContext;
import org.apache.chemistry.opencmis.client.api.Property;
+import org.apache.chemistry.opencmis.client.api.SecondaryType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.runtime.PolicyImpl;
import org.apache.chemistry.opencmis.client.runtime.RelationshipImpl;
@@ -49,7 +51,9 @@
import
org.apache.chemistry.opencmis.commons.definitions.PolicyTypeDefinition;
import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import
org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
+import
org.apache.chemistry.opencmis.commons.definitions.SecondaryTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
import
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
@@ -79,6 +83,8 @@
ret = new AlfrescoRelationshipType(this.session,
(RelationshipTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof PolicyTypeDefinition) {
ret = new AlfrescoPolicyType(this.session, (PolicyTypeDefinition)
typeDefinition);
+ } else if (typeDefinition instanceof SecondaryTypeDefinition) {
+ ret = new AlfrescoSecondaryType(this.session,
(SecondaryTypeDefinition) typeDefinition);
} else {
throw new CmisRuntimeException("Unknown base type!");
}
@@ -92,7 +98,7 @@
this.session = session;
}
- public Properties convertProperties(Map<String, ?> properties,
ObjectType type, Set<Updatability> updatabilityFilter)
+ public Properties convertProperties(Map<String, ?> properties,
ObjectType type, Collection<SecondaryType> secondaryTypes,
Set<Updatability> updatabilityFilter)
{
// check input
if (properties == null)
@@ -118,8 +124,10 @@
throw new IllegalArgumentException("Type property must be
set!");
}
+ // CMIS 1.0, secondary types/aspects are in the objectTypeId
ObjectType objectType = null;
List<ObjectType> aspectTypes = new ArrayList<ObjectType>();
+ List<String> secondaryTypesPropValue = new ArrayList<String>();
if (typeIdStr.indexOf(',') == -1)
{
objectType = session.getTypeDefinition(typeIdStr);
@@ -130,7 +138,9 @@
for (int i = 1; i < typeIds.length; i++)
{
-
aspectTypes.add(session.getTypeDefinition(typeIds[i].trim()));
+ String secondaryTypeId = typeIds[i].trim();
+ secondaryTypesPropValue.add(secondaryTypeId);
+
aspectTypes.add(session.getTypeDefinition(secondaryTypeId));
}
}
@@ -184,125 +194,137 @@
}
}
- // prepare type properties
- Properties result = super.convertProperties(typeProperties, type,
updatabilityFilter);
-
- // prepare extensions
- List<CmisExtensionElement> alfrescoExtensionList = new
ArrayList<CmisExtensionElement>();
-
- // prepare aspects
- for (ObjectType aspectType : aspectTypes)
+
if(session.getRepositoryInfo().getCmisVersion().equals(CmisVersion.CMIS_1_1))
{
-
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToAddExtension(aspectType));
+ // cmis 1.1 - secondary types
+ typeProperties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS,
secondaryTypesPropValue);
}
- // prepare aspect properties
- if (!aspectProperties.isEmpty())
- {
- List<CmisExtensionElement> propertrtyExtensionList = new
ArrayList<CmisExtensionElement>();
+ // prepare type properties
+ Properties result = super.convertProperties(typeProperties, type,
secondaryTypes, updatabilityFilter);
- for (Map.Entry<String, Object> property :
aspectProperties.entrySet())
- {
- PropertyDefinition<?> propDef =
aspectPropertyDefinition.get(property.getKey());
- if (propDef == null)
- {
- throw new IllegalArgumentException("Unknown aspect
property: " + property.getKey());
- }
-
- CmisExtensionElement element =
AlfrescoUtils.createAspectPropertyExtension(propDef,
- property.getValue());
- if (element != null)
- {
- propertrtyExtensionList.add(element);
- }
- }
-
-
alfrescoExtensionList.add(AlfrescoUtils.createAspectPropertiesExtension(propertrtyExtensionList));
- }
-
- if (!alfrescoExtensionList.isEmpty())
+
if(session.getRepositoryInfo().getCmisVersion().equals(CmisVersion.CMIS_1_0))
{
- result.setExtensions(Collections.singletonList(AlfrescoUtils
- .createSetAspectsExtension(alfrescoExtensionList)));
+ // prepare extensions
+ List<CmisExtensionElement> alfrescoExtensionList = new
ArrayList<CmisExtensionElement>();
+
+ // prepare aspects
+ for (ObjectType aspectType : aspectTypes)
+ {
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToAddExtension(aspectType));
+ }
+
+ // prepare aspect properties
+ if (!aspectProperties.isEmpty())
+ {
+ List<CmisExtensionElement> propertrtyExtensionList = new
ArrayList<CmisExtensionElement>();
+
+ for (Map.Entry<String, Object> property :
aspectProperties.entrySet())
+ {
+ PropertyDefinition<?> propDef =
aspectPropertyDefinition.get(property.getKey());
+ if (propDef == null)
+ {
+ throw new IllegalArgumentException("Unknown aspect
property: " + property.getKey());
+ }
+
+ CmisExtensionElement element =
AlfrescoUtils.createAspectPropertyExtension(propDef,
+ property.getValue());
+ if (element != null)
+ {
+ propertrtyExtensionList.add(element);
+ }
+ }
+
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectPropertiesExtension(propertrtyExtensionList));
+ }
+
+ if (!alfrescoExtensionList.isEmpty())
+ {
+ result.setExtensions(Collections.singletonList(AlfrescoUtils
+ .createSetAspectsExtension(alfrescoExtensionList)));
+ }
}
return result;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- public Map<String, Property<?>> convertProperties(ObjectType
objectType, Properties properties)
+ public Map<String, Property<?>> convertProperties(ObjectType
objectType, Collection<SecondaryType> secondaryTypes, Properties properties)
{
- Map<String, Property<?>> result =
super.convertProperties(objectType, properties);
+ Map<String, Property<?>> result =
super.convertProperties(objectType, secondaryTypes, properties);
- // find the Alfresco extensions
- List<CmisExtensionElement> alfrescoExtensions =
AlfrescoUtils.findAlfrescoExtensions(properties
- .getExtensions());
-
- if (alfrescoExtensions == null)
+
if(session.getRepositoryInfo().getCmisVersion().equals(CmisVersion.CMIS_1_0))
{
- // no Alfresco extensions found
- return result;
- }
-
- // get the aspect types
- Collection<ObjectType> aspectTypes =
AlfrescoUtils.getAspectTypes(session, alfrescoExtensions);
-
- for (CmisExtensionElement extension : alfrescoExtensions)
- {
- if (!extension.getName().equals("properties"))
- {
- continue;
- }
-
- for (CmisExtensionElement property : extension.getChildren())
- {
- String id =
property.getAttributes().get("propertyDefinitionId");
-
- // find the aspect type
- ObjectType aspectType =
AlfrescoUtils.findAspect(aspectTypes, id);
- if (aspectType == null)
- {
- throw new IllegalArgumentException("Unknown aspect
property: " + id);
- }
-
- // convert values
- PropertyDefinition propDef =
aspectType.getPropertyDefinitions().get(id);
- List values = new ArrayList();
- DatatypeFactory df = null;
- try
- {
- for (CmisExtensionElement propertyValues :
property.getChildren())
- {
- switch (propDef.getPropertyType())
- {
- case BOOLEAN:
-
values.add(Boolean.parseBoolean(propertyValues.getValue()));
- break;
- case DATETIME:
- if (df == null)
- {
- df = DatatypeFactory.newInstance();
- }
-
values.add(df.newXMLGregorianCalendar(propertyValues.getValue()).toGregorianCalendar());
- break;
- case DECIMAL:
- values.add(new
BigDecimal(propertyValues.getValue()));
- break;
- case INTEGER:
- values.add(new
BigInteger(propertyValues.getValue()));
- break;
- default:
- values.add(propertyValues.getValue());
- }
- }
- } catch (Exception e)
- {
- throw new IllegalArgumentException("Aspect
conversation exception: " + e.getMessage(), e);
- }
-
- // add property
- result.put(id, createProperty(propDef, values));
- }
+ // find the Alfresco extensions
+ List<CmisExtensionElement> alfrescoExtensions =
AlfrescoUtils.findAlfrescoExtensions(properties
+ .getExtensions());
+
+ if (alfrescoExtensions == null)
+ {
+ // no Alfresco extensions found
+ return result;
+ }
+
+ // get the aspect types
+ Collection<ObjectType> aspectTypes =
AlfrescoUtils.getAspectTypes(session, alfrescoExtensions);
+
+ for (CmisExtensionElement extension : alfrescoExtensions)
+ {
+ if (!extension.getName().equals("properties"))
+ {
+ continue;
+ }
+
+ for (CmisExtensionElement property : extension.getChildren())
+ {
+ String id =
property.getAttributes().get("propertyDefinitionId");
+
+ // find the aspect type
+ ObjectType aspectType =
AlfrescoUtils.findAspect(aspectTypes, id);
+ if (aspectType == null)
+ {
+ throw new IllegalArgumentException("Unknown aspect
property: " + id);
+ }
+
+ // convert values
+ PropertyDefinition propDef =
aspectType.getPropertyDefinitions().get(id);
+ List values = new ArrayList();
+ DatatypeFactory df = null;
+ try
+ {
+ for (CmisExtensionElement propertyValues :
property.getChildren())
+ {
+ switch (propDef.getPropertyType())
+ {
+ case BOOLEAN:
+
values.add(Boolean.parseBoolean(propertyValues.getValue()));
+ break;
+ case DATETIME:
+ if (df == null)
+ {
+ df = DatatypeFactory.newInstance();
+ }
+
values.add(df.newXMLGregorianCalendar(propertyValues.getValue()).toGregorianCalendar());
+ break;
+ case DECIMAL:
+ values.add(new
BigDecimal(propertyValues.getValue()));
+ break;
+ case INTEGER:
+ values.add(new
BigInteger(propertyValues.getValue()));
+ break;
+ default:
+ values.add(propertyValues.getValue());
+ }
+ }
+ } catch (Exception e)
+ {
+ throw new IllegalArgumentException("Aspect
conversation exception: " + e.getMessage(), e);
+ }
+
+ // add property
+ result.put(id, createProperty(propDef, values));
+ }
+ }
}
return result;
=======================================
--- /trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoUtils.java
Wed Apr 3 01:37:51 2013
+++ /trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoUtils.java
Mon Jun 10 03:33:56 2013
@@ -22,13 +22,16 @@
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
+import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Property;
import org.apache.chemistry.opencmis.client.api.Session;
@@ -36,10 +39,13 @@
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
import org.apache.chemistry.opencmis.commons.spi.Holder;
public class AlfrescoUtils
@@ -356,78 +362,134 @@
/**
* Adds and removes aspects.
*/
- public static void updateAspects(Session session, String objectId,
ObjectType[] addAspectIds,
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static void updateAspects(Session session, CmisObject object,
ObjectType[] addAspectIds,
ObjectType[] removeAspectIds, Map<String, ?> properties)
{
+ String objectId = object.getId();
String repId = session.getRepositoryInfo().getId();
Holder<String> objectIdHolder = new Holder<String>(objectId);
Map<String, PropertyDefinition<?>> aspectPropertyDefinition = null;
+ // create properties object
+ Properties cmisProperties = new PropertiesImpl();
+
+ CmisVersion cmisVersion =
session.getRepositoryInfo().getCmisVersion();
- List<CmisExtensionElement> alfrescoExtensionList = new
ArrayList<CmisExtensionElement>();
-
- if (addAspectIds != null)
+ if(cmisVersion.equals(CmisVersion.CMIS_1_1))
+// Property<?> secondaryTypesProp =
object.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+// if(secondaryTypesProp != null)
{
- aspectPropertyDefinition = new HashMap<String,
PropertyDefinition<?>>();
- for (ObjectType type : addAspectIds)
- {
- if (type != null)
- {
-
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToAddExtension(type));
+ // cmis 1.1
+ Property<?> secondaryTypesProp =
object.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ List currentSecondaryTypes = (List)secondaryTypesProp.getValue();
+ Set<String> currentSecondaryTypesSet = new
HashSet<String>(currentSecondaryTypes);
- if (type.getPropertyDefinitions() != null)
- {
-
aspectPropertyDefinition.putAll(type.getPropertyDefinitions());
- }
- }
- }
- }
+ if (addAspectIds != null)
+ {
+ Set<String> addAspects = new HashSet<String>();
+ for(ObjectType type : addAspectIds)
+ {
+ addAspects.add(type.getId());
+ }
+ currentSecondaryTypesSet.addAll(addAspects);
+ }
- if (removeAspectIds != null)
- {
- for (ObjectType type : removeAspectIds)
- {
- if (type != null)
- {
-
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToRemoveExtension(type));
- }
- }
- }
+ if (removeAspectIds != null)
+ {
+ Set<String> removeAspects = new HashSet<String>();
+ for(ObjectType type : removeAspectIds)
+ {
+ removeAspects.add(type.getId());
+ }
+ currentSecondaryTypesSet.removeAll(removeAspects);
+ }
+
+ List<String> secondaryTypesToSet = new ArrayList<String>();
+ for(String secondaryType : currentSecondaryTypesSet)
+ {
+ secondaryTypesToSet.add(secondaryType);
+ }
+
+ if(secondaryTypesToSet.isEmpty())
+ {
+ // nothing to do
+ return;
+ }
- if (alfrescoExtensionList.isEmpty())
- {
- return;
+ Collection<PropertyData<?>> props = new
ArrayList<PropertyData<?>>(1);
+ PropertyData<?> updatedSecondaryTypesProp = new
PropertyIdImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesToSet);
+ props.add(updatedSecondaryTypesProp);
+ cmisProperties = new PropertiesImpl(props);
+ session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, cmisProperties, null);
}
-
- // add property values
- if (addAspectIds != null && properties != null
&& !properties.isEmpty())
+ else if(cmisVersion.equals(CmisVersion.CMIS_1_0))
{
- 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));
- }
+ // cmis 1.0
+ List<CmisExtensionElement> alfrescoExtensionList = new
ArrayList<CmisExtensionElement>();
+
+ if (addAspectIds != null)
+ {
+ aspectPropertyDefinition = new HashMap<String,
PropertyDefinition<?>>();
+ for (ObjectType type : addAspectIds)
+ {
+ if (type != null)
+ {
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToAddExtension(type));
+
+ if (type.getPropertyDefinitions() != null)
+ {
+
aspectPropertyDefinition.putAll(type.getPropertyDefinitions());
+ }
+ }
+ }
+ }
+
+ if (removeAspectIds != null)
+ {
+ for (ObjectType type : removeAspectIds)
+ {
+ if (type != null)
+ {
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToRemoveExtension(type));
+ }
+ }
+ }
+
+ if (alfrescoExtensionList.isEmpty())
+ {
+ return;
+ }
+
+ // 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(AlfrescoUtils.createAspectPropertiesExtension(aspectProperties));
+ }
-
alfrescoExtensionList.add(AlfrescoUtils.createAspectPropertiesExtension(aspectProperties));
+ cmisProperties = new PropertiesImpl();
+
cmisProperties.setExtensions(Collections.singletonList(AlfrescoUtils
+ .createSetAspectsExtension(alfrescoExtensionList)));
}
-
- // create properties object
- Properties cmisProperties = new PropertiesImpl();
-
cmisProperties.setExtensions(Collections.singletonList(AlfrescoUtils
- .createSetAspectsExtension(alfrescoExtensionList)));
session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, cmisProperties, null);
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Fri Feb 17 09:34:36 2012
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Mon Jun 10 03:33:56 2013
@@ -190,7 +190,7 @@
return;
}
- AlfrescoUtils.updateAspects(session, object.getId(),
+ AlfrescoUtils.updateAspects(session, object,
addAspectTypes.values().toArray(new ObjectType[0]),
removeAspectTypes.values().toArray(new ObjectType[0]), null);
}