Added:
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoUtils.java
Deleted:
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsUtils.java
Modified:
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.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/AlfrescoObjectFactoryImpl.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
=======================================
--- /dev/null
+++ /trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoUtils.java
Fri Feb 17 09:34:36 2012
@@ -0,0 +1,472 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+
+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.data.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
+
+public class AlfrescoUtils
+{
+ private AlfrescoUtils()
+ {
+ }
+
+ public static final String ALFRESCO_NAMESPACE
= "http://www.alfresco.org";
+ public static final String CMIS_NAMESPACE
= "http://docs.oasis-open.org/ns/cmis/core/200908/";
+ public static final String APPLIED_ASPECTS = "appliedAspects";
+ public static final String SET_ASPECTS = "setAspects";
+ public static final String ASPECTS_TO_ADD = "aspectsToAdd";
+ public static final String ASPECTS_TO_REMOVE = "aspectsToRemove";
+ public static final String PROPERTIES = "properties";
+ public static final String MANDATORY_ASPECTS = "mandatoryAspects";
+ public static final String MANDATORY_ASPECT = "mandatoryAspect";
+
+ /**
+ * Finds the Alfresco extensions within the given extensions.
+ */
+ public static List<CmisExtensionElement>
findAlfrescoExtensions(List<CmisExtensionElement> extensions)
+ {
+ if (extensions == null || extensions.isEmpty())
+ {
+ return null;
+ }
+
+ for (CmisExtensionElement ext : extensions)
+ {
+ if (ALFRESCO_NAMESPACE.equals(ext.getNamespace()))
+ {
+ return ext.getChildren();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the aspect types from the Alfresco extensions.
+ */
+ public static Collection<ObjectType> getAspectTypes(Session session,
List<CmisExtensionElement> alfrescoExtensions)
+ {
+ Collection<ObjectType> aspectTypes = new ArrayList<ObjectType>();
+
+ for (CmisExtensionElement extension : alfrescoExtensions)
+ {
+ if (extension.getName().equals(APPLIED_ASPECTS))
+ {
+ ObjectType aspectType =
session.getTypeDefinition(extension.getValue());
+ aspectTypes.add(aspectType);
+ }
+ }
+
+ return aspectTypes;
+ }
+
+ /**
+ * Finds the aspect type that contains the given property id.
+ */
+ public static ObjectType findAspect(Collection<ObjectType>
aspectTypes, String propertyId)
+ {
+ if (aspectTypes == null || propertyId == null)
+ {
+ return null;
+ }
+
+ for (ObjectType type : aspectTypes)
+ {
+ if (type != null && type.getPropertyDefinitions() != null
+ &&
type.getPropertyDefinitions().containsKey(propertyId))
+ {
+ return type;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates a setAspects extension element.
+ */
+ public static CmisExtensionElement
createSetAspectsExtension(List<CmisExtensionElement> setAspectsChildren)
+ {
+ return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
SET_ASPECTS, null, setAspectsChildren);
+ }
+
+ /**
+ * Creates an aspectsToAdd extension element.
+ */
+ public static CmisExtensionElement
createAspectsToAddExtension(ObjectType aspectType)
+ {
+ return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
ASPECTS_TO_ADD, null, aspectType.getId());
+ }
+
+ /**
+ * Creates an aspectsToRemove extension element.
+ */
+ public static CmisExtensionElement
createAspectsToRemoveExtension(ObjectType aspectType)
+ {
+ return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
ASPECTS_TO_REMOVE, null, aspectType.getId());
+ }
+
+ /**
+ * Creates an aspectsToAdd extension element.
+ */
+ public static CmisExtensionElement
createAspectPropertiesExtension(List<CmisExtensionElement>
propertiesChildren)
+ {
+ return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
PROPERTIES, null, propertiesChildren);
+ }
+
+ /**
+ * Creates a property extension element.
+ */
+ @SuppressWarnings("rawtypes")
+ public static CmisExtensionElement
createAspectPropertyExtension(PropertyDefinition<?> propertyDefintion,
+ Object value)
+ {
+ String name;
+ switch (propertyDefintion.getPropertyType())
+ {
+ case BOOLEAN:
+ name = "propertyBoolean";
+ break;
+ case DATETIME:
+ name = "propertyDateTime";
+ break;
+ case DECIMAL:
+ name = "propertyDecimal";
+ break;
+ case INTEGER:
+ name = "propertyInteger";
+ break;
+ case ID:
+ name = "propertyId";
+ break;
+ case HTML:
+ name = "propertyHtml";
+ break;
+ case URI:
+ name = "propertyUri";
+ break;
+ default:
+ name = "propertyString";
+ }
+
+ Map<String, String> attributes = new HashMap<String, String>();
+ attributes.put("propertyDefinitionId", propertyDefintion.getId());
+
+ List<CmisExtensionElement> propertyValues = new
ArrayList<CmisExtensionElement>();
+ if (value != null)
+ {
+ if (value instanceof Property<?>)
+ {
+ value = ((Property<?>) value).getValues();
+ }
+
+ if (value instanceof List)
+ {
+ for (Object o : ((List) value))
+ {
+ propertyValues.add(new
CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null,
+ convertAspectPropertyValue(o)));
+ }
+ } else
+ {
+ propertyValues.add(new
CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null,
+ convertAspectPropertyValue(value)));
+ }
+ }
+
+ return new CmisExtensionElementImpl(CMIS_NAMESPACE, name,
attributes, propertyValues);
+ }
+
+ private static String convertAspectPropertyValue(Object value)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException("Aspect property value must
not be null!");
+ }
+
+ if (value instanceof GregorianCalendar)
+ {
+ DatatypeFactory df;
+ try
+ {
+ df = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e)
+ {
+ throw new IllegalArgumentException("Aspect conversation
exception: " + e.getMessage(), e);
+ }
+ return df.newXMLGregorianCalendar((GregorianCalendar)
value).toXMLFormat();
+ } else if (!(value instanceof String) && !(value instanceof
Number) && !(value instanceof Boolean))
+ {
+ throw new IllegalArgumentException("Invalid aspect value!");
+ }
+
+ return value.toString();
+ }
+
+ /**
+ * Checks a property value.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> checkProperty(PropertyDefinition<T>
propertyDefinition, Object value)
+ {
+ // null values are ok for updates
+ if (value == null)
+ {
+ return null;
+ }
+
+ // single and multi value check
+ List<T> values = null;
+ if (value instanceof List<?>)
+ {
+ if (propertyDefinition.getCardinality() != Cardinality.MULTI)
+ {
+ throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
+ + "' is not a multi value property!");
+ }
+
+ values = (List<T>) value;
+ if (values.isEmpty())
+ {
+ return values;
+ }
+ } else
+ {
+ if (propertyDefinition.getCardinality() != Cardinality.SINGLE)
+ {
+ throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
+ + "' is not a single value property!");
+ }
+
+ values = Collections.singletonList((T) value);
+ }
+
+ // check if list contains null values
+ for (Object o : values)
+ {
+ if (o == null)
+ {
+ throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
+ + "' contains null values!");
+ }
+ }
+
+ // take a sample and test the data type
+ boolean typeMatch = false;
+ Object firstValue = values.get(0);
+
+ switch (propertyDefinition.getPropertyType())
+ {
+ case STRING:
+ case ID:
+ case URI:
+ case HTML:
+ typeMatch = (firstValue instanceof String);
+ break;
+ case INTEGER:
+ typeMatch = (firstValue instanceof BigInteger) || (firstValue
instanceof Byte)
+ || (firstValue instanceof Short) || (firstValue
instanceof Integer) || (firstValue instanceof Long);
+ break;
+ case DECIMAL:
+ typeMatch = (firstValue instanceof BigDecimal);
+ break;
+ case BOOLEAN:
+ typeMatch = (firstValue instanceof Boolean);
+ break;
+ case DATETIME:
+ typeMatch = (firstValue instanceof GregorianCalendar);
+ break;
+ }
+
+ if (!typeMatch)
+ {
+ throw new IllegalArgumentException("Value of property '" +
propertyDefinition.getId()
+ + "' does not match property type!");
+ }
+
+ return values;
+ }
+
+ /**
+ * Adds object type and aspect types to properties.
+ */
+ public static Map<String, ?> preparePropertiesForUpdate(Map<String, ?>
properties, ObjectType type,
+ Collection<ObjectType> aspectTypes)
+ {
+ Map<String, Object> newProperties = (properties == null ? null :
new LinkedHashMap<String, Object>(properties));
+ if (newProperties != null)
+ {
+ newProperties.put(PropertyIds.OBJECT_TYPE_ID,
createObjectTypeIdValue(type, aspectTypes));
+ }
+
+ return newProperties;
+ }
+
+ public static String createObjectTypeIdValue(ObjectType type,
Collection<ObjectType> aspectTypes)
+ {
+ StringBuilder sb = new StringBuilder(type.getId());
+
+ for (ObjectType aspect : aspectTypes)
+ {
+ sb.append(',');
+ sb.append(aspect.getId());
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Adds and removes aspects.
+ */
+ public static void updateAspects(Session session, String objectId,
ObjectType[] addAspectIds,
+ 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(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));
+ }
+
+ // create properties object
+ Properties cmisProperties = new PropertiesImpl();
+
cmisProperties.setExtensions(Collections.singletonList(AlfrescoUtils
+ .createSetAspectsExtension(alfrescoExtensionList)));
+
+ session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, cmisProperties, null);
+ }
+
+ private static CmisExtensionElement
getExtension(List<CmisExtensionElement> extensions, String namespace,
String name)
+ {
+ CmisExtensionElement ret = null;
+
+ for(CmisExtensionElement elem : extensions)
+ {
+ if(elem.getNamespace().equals(namespace) &&
elem.getName().equals(name))
+ {
+ ret = elem;
+ }
+ }
+
+ return ret;
+ }
+
+ public static List<String> getMandatoryAspects(ExtensionsData object)
+ {
+ List<String> mandatoryAspects = null;
+
+ List<CmisExtensionElement> extensions = object.getExtensions();
+ CmisExtensionElement mandatoryAspectsExtension =
getExtension(extensions, ALFRESCO_NAMESPACE, MANDATORY_ASPECTS);
+ if(mandatoryAspectsExtension != null)
+ {
+ List<CmisExtensionElement> mandatoryAspectsExtensions =
mandatoryAspectsExtension.getChildren();
+ mandatoryAspects = new
ArrayList<String>(mandatoryAspectsExtensions.size());
+ for(CmisExtensionElement elem : mandatoryAspectsExtensions)
+ {
+ mandatoryAspects.add(elem.getValue());
+ }
+ }
+ else
+ {
+ mandatoryAspects = Collections.emptyList();
+ }
+
+ return mandatoryAspects;
+ }
+}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsUtils.java
Mon Nov 7 10:53:15 2011
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * 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.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-
-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.data.Properties;
-import
org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
-import org.apache.chemistry.opencmis.commons.enums.Cardinality;
-import
org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
-import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
-import org.apache.chemistry.opencmis.commons.spi.Holder;
-
-public class AlfrescoAspectsUtils
-{
- private AlfrescoAspectsUtils()
- {
- }
-
- public static final String ALFRESCO_NAMESPACE
= "http://www.alfresco.org";
- public static final String CMIS_NAMESPACE
= "http://docs.oasis-open.org/ns/cmis/core/200908/";
- public static final String APPLIED_ASPECTS = "appliedAspects";
- public static final String SET_ASPECTS = "setAspects";
- public static final String ASPECTS_TO_ADD = "aspectsToAdd";
- public static final String ASPECTS_TO_REMOVE = "aspectsToRemove";
- public static final String PROPERTIES = "properties";
-
- /**
- * Finds the Alfresco extensions within the given extensions.
- */
- public static List<CmisExtensionElement>
findAlfrescoExtensions(List<CmisExtensionElement> extensions)
- {
- if (extensions == null || extensions.isEmpty())
- {
- return null;
- }
-
- for (CmisExtensionElement ext : extensions)
- {
- if (ALFRESCO_NAMESPACE.equals(ext.getNamespace()))
- {
- return ext.getChildren();
- }
- }
-
- return null;
- }
-
- /**
- * Returns the aspect types from the Alfresco extensions.
- */
- public static Collection<ObjectType> getAspectTypes(Session session,
List<CmisExtensionElement> alfrescoExtensions)
- {
- Collection<ObjectType> aspectTypes = new ArrayList<ObjectType>();
-
- for (CmisExtensionElement extension : alfrescoExtensions)
- {
- if (extension.getName().equals(APPLIED_ASPECTS))
- {
- ObjectType aspectType =
session.getTypeDefinition(extension.getValue());
- aspectTypes.add(aspectType);
- }
- }
-
- return aspectTypes;
- }
-
- /**
- * Finds the aspect type that contains the given property id.
- */
- public static ObjectType findAspect(Collection<ObjectType>
aspectTypes, String propertyId)
- {
- if (aspectTypes == null || propertyId == null)
- {
- return null;
- }
-
- for (ObjectType type : aspectTypes)
- {
- if (type != null && type.getPropertyDefinitions() != null
- &&
type.getPropertyDefinitions().containsKey(propertyId))
- {
- return type;
- }
- }
-
- return null;
- }
-
- /**
- * Creates a setAspects extension element.
- */
- public static CmisExtensionElement
createSetAspectsExtension(List<CmisExtensionElement> setAspectsChildren)
- {
- return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
SET_ASPECTS, null, setAspectsChildren);
- }
-
- /**
- * Creates an aspectsToAdd extension element.
- */
- public static CmisExtensionElement
createAspectsToAddExtension(ObjectType aspectType)
- {
- return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
ASPECTS_TO_ADD, null, aspectType.getId());
- }
-
- /**
- * Creates an aspectsToRemove extension element.
- */
- public static CmisExtensionElement
createAspectsToRemoveExtension(ObjectType aspectType)
- {
- return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
ASPECTS_TO_REMOVE, null, aspectType.getId());
- }
-
- /**
- * Creates an aspectsToAdd extension element.
- */
- public static CmisExtensionElement
createAspectPropertiesExtension(List<CmisExtensionElement>
propertiesChildren)
- {
- return new CmisExtensionElementImpl(ALFRESCO_NAMESPACE,
PROPERTIES, null, propertiesChildren);
- }
-
- /**
- * Creates a property extension element.
- */
- @SuppressWarnings("rawtypes")
- public static CmisExtensionElement
createAspectPropertyExtension(PropertyDefinition<?> propertyDefintion,
- Object value)
- {
- String name;
- switch (propertyDefintion.getPropertyType())
- {
- case BOOLEAN:
- name = "propertyBoolean";
- break;
- case DATETIME:
- name = "propertyDateTime";
- break;
- case DECIMAL:
- name = "propertyDecimal";
- break;
- case INTEGER:
- name = "propertyInteger";
- break;
- case ID:
- name = "propertyId";
- break;
- case HTML:
- name = "propertyHtml";
- break;
- case URI:
- name = "propertyUri";
- break;
- default:
- name = "propertyString";
- }
-
- Map<String, String> attributes = new HashMap<String, String>();
- attributes.put("propertyDefinitionId", propertyDefintion.getId());
-
- List<CmisExtensionElement> propertyValues = new
ArrayList<CmisExtensionElement>();
- if (value != null)
- {
- if (value instanceof Property<?>)
- {
- value = ((Property<?>) value).getValues();
- }
-
- if (value instanceof List)
- {
- for (Object o : ((List) value))
- {
- propertyValues.add(new
CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null,
- convertAspectPropertyValue(o)));
- }
- } else
- {
- propertyValues.add(new
CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null,
- convertAspectPropertyValue(value)));
- }
- }
-
- return new CmisExtensionElementImpl(CMIS_NAMESPACE, name,
attributes, propertyValues);
- }
-
- private static String convertAspectPropertyValue(Object value)
- {
- if (value == null)
- {
- throw new IllegalArgumentException("Aspect property value must
not be null!");
- }
-
- if (value instanceof GregorianCalendar)
- {
- DatatypeFactory df;
- try
- {
- df = DatatypeFactory.newInstance();
- } catch (DatatypeConfigurationException e)
- {
- throw new IllegalArgumentException("Aspect conversation
exception: " + e.getMessage(), e);
- }
- return df.newXMLGregorianCalendar((GregorianCalendar)
value).toXMLFormat();
- } else if (!(value instanceof String) && !(value instanceof
Number) && !(value instanceof Boolean))
- {
- throw new IllegalArgumentException("Invalid aspect value!");
- }
-
- return value.toString();
- }
-
- /**
- * Checks a property value.
- */
- @SuppressWarnings("unchecked")
- public static <T> List<T> checkProperty(PropertyDefinition<T>
propertyDefinition, Object value)
- {
- // null values are ok for updates
- if (value == null)
- {
- return null;
- }
-
- // single and multi value check
- List<T> values = null;
- if (value instanceof List<?>)
- {
- if (propertyDefinition.getCardinality() != Cardinality.MULTI)
- {
- throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
- + "' is not a multi value property!");
- }
-
- values = (List<T>) value;
- if (values.isEmpty())
- {
- return values;
- }
- } else
- {
- if (propertyDefinition.getCardinality() != Cardinality.SINGLE)
- {
- throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
- + "' is not a single value property!");
- }
-
- values = Collections.singletonList((T) value);
- }
-
- // check if list contains null values
- for (Object o : values)
- {
- if (o == null)
- {
- throw new IllegalArgumentException("Property '" +
propertyDefinition.getId()
- + "' contains null values!");
- }
- }
-
- // take a sample and test the data type
- boolean typeMatch = false;
- Object firstValue = values.get(0);
-
- switch (propertyDefinition.getPropertyType())
- {
- case STRING:
- case ID:
- case URI:
- case HTML:
- typeMatch = (firstValue instanceof String);
- break;
- case INTEGER:
- typeMatch = (firstValue instanceof BigInteger) || (firstValue
instanceof Byte)
- || (firstValue instanceof Short) || (firstValue
instanceof Integer) || (firstValue instanceof Long);
- break;
- case DECIMAL:
- typeMatch = (firstValue instanceof BigDecimal);
- break;
- case BOOLEAN:
- typeMatch = (firstValue instanceof Boolean);
- break;
- case DATETIME:
- typeMatch = (firstValue instanceof GregorianCalendar);
- break;
- }
-
- if (!typeMatch)
- {
- throw new IllegalArgumentException("Value of property '" +
propertyDefinition.getId()
- + "' does not match property type!");
- }
-
- return values;
- }
-
- /**
- * Adds object type and aspect types to properties.
- */
- public static Map<String, ?> preparePropertiesForUpdate(Map<String, ?>
properties, ObjectType type,
- Collection<ObjectType> aspectTypes)
- {
- Map<String, Object> newProperties = (properties == null ? null :
new LinkedHashMap<String, Object>(properties));
- if (newProperties != null)
- {
- newProperties.put(PropertyIds.OBJECT_TYPE_ID,
createObjectTypeIdValue(type, aspectTypes));
- }
-
- return newProperties;
- }
-
- public static String createObjectTypeIdValue(ObjectType type,
Collection<ObjectType> aspectTypes)
- {
- StringBuilder sb = new StringBuilder(type.getId());
-
- for (ObjectType aspect : aspectTypes)
- {
- sb.append(',');
- sb.append(aspect.getId());
- }
-
- return sb.toString();
- }
-
- /**
- * Adds and removes aspects.
- */
- public static void updateAspects(Session session, String objectId,
ObjectType[] addAspectIds,
- 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());
- }
- }
- }
- }
-
- if (removeAspectIds != null)
- {
- for (ObjectType type : removeAspectIds)
- {
- if (type != null)
- {
-
alfrescoExtensionList.add(AlfrescoAspectsUtils.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(AlfrescoAspectsUtils.createAspectPropertiesExtension(aspectProperties));
- }
-
- // create properties object
- Properties cmisProperties = new PropertiesImpl();
-
cmisProperties.setExtensions(Collections.singletonList(AlfrescoAspectsUtils
- .createSetAspectsExtension(alfrescoExtensionList)));
-
- session.getBinding().getObjectService().updateProperties(repId,
objectIdHolder, null, cmisProperties, null);
- }
-}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoAspectsImpl.java
Fri Feb 17 09:34:36 2012
@@ -39,7 +39,7 @@
this.session = session;
this.object = object;
- List<CmisExtensionElement> alfrescoExtensions = AlfrescoAspectsUtils
+ List<CmisExtensionElement> alfrescoExtensions = AlfrescoUtils
.findAlfrescoExtensions(object
.getExtensions(ExtensionLevel.PROPERTIES));
@@ -47,7 +47,7 @@
aspectTypes = Collections.emptyMap();
} else {
aspectTypes = new HashMap<String, ObjectType>();
- for (ObjectType type : AlfrescoAspectsUtils.getAspectTypes(session,
+ for (ObjectType type : AlfrescoUtils.getAspectTypes(session,
alfrescoExtensions)) {
if (type != null) {
aspectTypes.put(type.getId(), type);
@@ -79,7 +79,7 @@
}
public ObjectType findAspect(String propertyId) {
- return AlfrescoAspectsUtils
+ return AlfrescoUtils
.findAspect(aspectTypes.values(), propertyId);
}
@@ -101,7 +101,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null,
+ AlfrescoUtils.updateAspects(session, object.getId(), type, null,
null);
}
@@ -114,7 +114,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoAspectsUtils.updateAspects(session, object.getId(), type, null,
+ AlfrescoUtils.updateAspects(session, object.getId(), type, null,
properties);
}
@@ -153,7 +153,7 @@
throw new IllegalArgumentException("Type must be set!");
}
- AlfrescoAspectsUtils.updateAspects(session, object.getId(), null, type,
+ AlfrescoUtils.updateAspects(session, object.getId(), null, type,
null);
}
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoDocumentImpl.java
Fri Feb 17 09:34:36 2012
@@ -70,7 +70,7 @@
@Override
public ObjectId updateProperties(Map<String, ?> properties, boolean
refresh) {
return super.updateProperties(
- AlfrescoAspectsUtils.preparePropertiesForUpdate(properties,
+ AlfrescoUtils.preparePropertiesForUpdate(properties,
getType(), getAspects()), refresh);
}
@@ -79,7 +79,7 @@
ContentStream contentStream, String checkinComment,
List<Policy> policies, List<Ace> addAces, List<Ace> removeAces) {
return super.checkIn(major,
- AlfrescoAspectsUtils.preparePropertiesForUpdate(properties,
+ AlfrescoUtils.preparePropertiesForUpdate(properties,
getType(), getAspects()), contentStream,
checkinComment, policies, addAces, addAces);
}
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoFolderImpl.java
Fri Feb 17 09:34:36 2012
@@ -72,7 +72,7 @@
public ObjectId updateProperties(Map<String, ?> properties, boolean
refresh)
{
return super.updateProperties(
-
AlfrescoAspectsUtils.preparePropertiesForUpdate(properties, getType(),
getAspects()), refresh);
+ AlfrescoUtils.preparePropertiesForUpdate(properties,
getType(), getAspects()), refresh);
}
public boolean hasAspect(String id)
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoObjectFactoryImpl.java
Mon Apr 4 04:55:46 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/AlfrescoObjectFactoryImpl.java
Fri Feb 17 09:34:36 2012
@@ -27,6 +27,10 @@
import javax.xml.datatype.DatatypeFactory;
+import org.alfresco.cmis.client.type.AlfrescoDocumentType;
+import org.alfresco.cmis.client.type.AlfrescoFolderType;
+import org.alfresco.cmis.client.type.AlfrescoPolicyType;
+import org.alfresco.cmis.client.type.AlfrescoRelationshipType;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.OperationContext;
@@ -40,7 +44,12 @@
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.data.ObjectData;
import org.apache.chemistry.opencmis.commons.data.Properties;
+import
org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
+import
org.apache.chemistry.opencmis.commons.definitions.FolderTypeDefinition;
+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.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
import
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
@@ -57,6 +66,26 @@
{
}
+ @Override
+ public ObjectType convertTypeDefinition(TypeDefinition typeDefinition)
+ {
+ ObjectType ret = null;
+
+ if (typeDefinition instanceof DocumentTypeDefinition) {
+ ret = new AlfrescoDocumentType(this.session,
(DocumentTypeDefinition) typeDefinition);
+ } else if (typeDefinition instanceof FolderTypeDefinition) {
+ ret = new AlfrescoFolderType(this.session, (FolderTypeDefinition)
typeDefinition);
+ } else if (typeDefinition instanceof RelationshipTypeDefinition) {
+ ret = new AlfrescoRelationshipType(this.session,
(RelationshipTypeDefinition) typeDefinition);
+ } else if (typeDefinition instanceof PolicyTypeDefinition) {
+ ret = new AlfrescoPolicyType(this.session, (PolicyTypeDefinition)
typeDefinition);
+ } else {
+ throw new CmisRuntimeException("Unknown base type!");
+ }
+
+ return ret;
+ }
+
public void initialize(Session session, Map<String, String> parameters)
{
super.initialize(session, parameters);
@@ -164,7 +193,7 @@
// prepare aspects
for (ObjectType aspectType : aspectTypes)
{
-
alfrescoExtensionList.add(AlfrescoAspectsUtils.createAspectsToAddExtension(aspectType));
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectsToAddExtension(aspectType));
}
// prepare aspect properties
@@ -180,7 +209,7 @@
throw new IllegalArgumentException("Unknown aspect
property: " + property.getKey());
}
- CmisExtensionElement element =
AlfrescoAspectsUtils.createAspectPropertyExtension(propDef,
+ CmisExtensionElement element =
AlfrescoUtils.createAspectPropertyExtension(propDef,
property.getValue());
if (element != null)
{
@@ -188,12 +217,12 @@
}
}
-
alfrescoExtensionList.add(AlfrescoAspectsUtils.createAspectPropertiesExtension(propertrtyExtensionList));
+
alfrescoExtensionList.add(AlfrescoUtils.createAspectPropertiesExtension(propertrtyExtensionList));
}
if (!alfrescoExtensionList.isEmpty())
{
-
result.setExtensions(Collections.singletonList(AlfrescoAspectsUtils
+ result.setExtensions(Collections.singletonList(AlfrescoUtils
.createSetAspectsExtension(alfrescoExtensionList)));
}
@@ -206,7 +235,7 @@
Map<String, Property<?>> result =
super.convertProperties(objectType, properties);
// find the Alfresco extensions
- List<CmisExtensionElement> alfrescoExtensions =
AlfrescoAspectsUtils.findAlfrescoExtensions(properties
+ List<CmisExtensionElement> alfrescoExtensions =
AlfrescoUtils.findAlfrescoExtensions(properties
.getExtensions());
if (alfrescoExtensions == null)
@@ -216,7 +245,7 @@
}
// get the aspect types
- Collection<ObjectType> aspectTypes =
AlfrescoAspectsUtils.getAspectTypes(session, alfrescoExtensions);
+ Collection<ObjectType> aspectTypes =
AlfrescoUtils.getAspectTypes(session, alfrescoExtensions);
for (CmisExtensionElement extension : alfrescoExtensions)
{
@@ -230,7 +259,7 @@
String id =
property.getAttributes().get("propertyDefinitionId");
// find the aspect type
- ObjectType aspectType =
AlfrescoAspectsUtils.findAspect(aspectTypes, id);
+ ObjectType aspectType =
AlfrescoUtils.findAspect(aspectTypes, id);
if (aspectType == null)
{
throw new IllegalArgumentException("Unknown aspect
property: " + id);
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoAspectsImpl.java
Fri Feb 17 09:34:36 2012
@@ -45,7 +45,7 @@
this.session = session;
this.object = object;
- List<CmisExtensionElement> alfrescoExtensions = AlfrescoAspectsUtils
+ List<CmisExtensionElement> alfrescoExtensions = AlfrescoUtils
.findAlfrescoExtensions(object
.getExtensions(ExtensionLevel.PROPERTIES));
@@ -53,7 +53,7 @@
aspectTypes = Collections.emptyMap();
} else {
aspectTypes = new HashMap<String, ObjectType>();
- for (ObjectType type : AlfrescoAspectsUtils.getAspectTypes(session,
+ for (ObjectType type : AlfrescoUtils.getAspectTypes(session,
alfrescoExtensions)) {
if (type != null) {
aspectTypes.put(type.getId(), type);
@@ -103,7 +103,7 @@
}
public ObjectType findAspect(String propertyId) {
- return AlfrescoAspectsUtils.findAspect(getAspects(), propertyId);
+ return AlfrescoUtils.findAspect(getAspects(), propertyId);
}
public void addAspect(String... id) {
@@ -190,7 +190,7 @@
return;
}
- AlfrescoAspectsUtils.updateAspects(session, object.getId(),
+ AlfrescoUtils.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 Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoDocumentImpl.java
Fri Feb 17 09:34:36 2012
@@ -66,7 +66,7 @@
throw new IllegalArgumentException("Property is read-only!");
}
- List<T> values = AlfrescoAspectsUtils.checkProperty(propertyDefinition,
+ List<T> values = AlfrescoUtils.checkProperty(propertyDefinition,
value);
// create and set property
@@ -146,7 +146,7 @@
ObjectType type = getType();
PropertyDefinition<String> propDef = (PropertyDefinition<String>) type
.getPropertyDefinitions().get(PropertyIds.OBJECT_TYPE_ID);
- String objectTypeIdValue = AlfrescoAspectsUtils
+ String objectTypeIdValue = AlfrescoUtils
.createObjectTypeIdValue(type, getAspects());
Property<String> objectTypeIdProperty = getObjectFactory()
.createProperty(propDef,
=======================================
---
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoFolderImpl.java
Mon Nov 7 10:53:15 2011
+++
/trunk/src/main/java/org/alfresco/cmis/client/impl/TransientAlfrescoFolderImpl.java
Fri Feb 17 09:34:36 2012
@@ -70,7 +70,7 @@
throw new IllegalArgumentException("Property is read-only!");
}
- List<T> values =
AlfrescoAspectsUtils.checkProperty(propertyDefinition, value);
+ List<T> values = AlfrescoUtils.checkProperty(propertyDefinition,
value);
// create and set property
Property<T> newProperty =
getObjectFactory().createProperty(propertyDefinition, values);
@@ -163,7 +163,7 @@
ObjectType type = getType();
PropertyDefinition<String> propDef = (PropertyDefinition<String>)
type.getPropertyDefinitions().get(
PropertyIds.OBJECT_TYPE_ID);
- String objectTypeIdValue =
AlfrescoAspectsUtils.createObjectTypeIdValue(type, getAspects());
+ String objectTypeIdValue =
AlfrescoUtils.createObjectTypeIdValue(type, getAspects());
Property<String> objectTypeIdProperty =
getObjectFactory().createProperty(propDef,
Collections.singletonList(objectTypeIdValue));