You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/08/04 15:16:21 UTC
svn commit: r1510178 - in
/chemistry/opencmis/trunk/chemistry-opencmis-server:
chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/
chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/serv...
Author: fmui
Date: Sun Aug 4 13:16:20 2013
New Revision: 1510178
URL: http://svn.apache.org/r1510178
Log:
TypeDefinitionFactory enhancements + FileShare repository updates
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareServiceFactory.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/RepositoryMap.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/TypeManager.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java Sun Aug 4 13:16:20 2013
@@ -355,12 +355,12 @@ public class FileShareRepository {
/**
* CMIS getTypesDescendants.
*/
- public List<TypeDefinitionContainer> getTypesDescendants(CallContext context, String typeId, BigInteger depth,
+ public List<TypeDefinitionContainer> getTypeDescendants(CallContext context, String typeId, BigInteger depth,
Boolean includePropertyDefinitions) {
debug("getTypesDescendants");
checkUser(context, false);
- return types.getTypesDescendants(context, typeId, depth, includePropertyDefinitions);
+ return types.getTypeDescendants(context, typeId, depth, includePropertyDefinitions);
}
/**
@@ -2026,12 +2026,12 @@ public class FileShareRepository {
private static String getTypeId(Properties properties) {
PropertyData<?> typeProperty = properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
if (!(typeProperty instanceof PropertyId)) {
- throw new CmisInvalidArgumentException("Type id must be set!");
+ throw new CmisInvalidArgumentException("Type Id must be set!");
}
String typeId = ((PropertyId) typeProperty).getFirstValue();
if (typeId == null) {
- throw new CmisInvalidArgumentException("Type id must be set!");
+ throw new CmisInvalidArgumentException("Type Id must be set!");
}
return typeId;
@@ -2050,7 +2050,7 @@ public class FileShareRepository {
}
/**
- * Returns the first value of an string property.
+ * Returns the first value of a string property.
*/
private static String getStringProperty(Properties properties, String name) {
PropertyData<?> property = properties.getProperties().get(name);
@@ -2062,7 +2062,7 @@ public class FileShareRepository {
}
/**
- * Returns the first value of an datetime property.
+ * Returns the first value of a datetime property.
*/
private static GregorianCalendar getDateTimeProperty(Properties properties, String name) {
PropertyData<?> property = properties.getProperties().get(name);
@@ -2167,7 +2167,9 @@ public class FileShareRepository {
}
private void warn(String msg, Throwable t) {
- LOG.warn("<" + repositoryId + "> " + msg, t);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("<" + repositoryId + "> " + msg, t);
+ }
}
private void debug(String msg) {
@@ -2175,6 +2177,8 @@ public class FileShareRepository {
}
private void debug(String msg, Throwable t) {
- LOG.debug("<" + repositoryId + "> " + msg, t);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<" + repositoryId + "> " + msg, t);
+ }
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareService.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareService.java Sun Aug 4 13:16:20 2013
@@ -119,7 +119,7 @@ public class FileShareService extends Ab
@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth,
Boolean includePropertyDefinitions, ExtensionsData extension) {
- return getRepository().getTypesDescendants(getCallContext(), typeId, depth, includePropertyDefinitions);
+ return getRepository().getTypeDescendants(getCallContext(), typeId, depth, includePropertyDefinitions);
}
// --- navigation service ---
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareServiceFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareServiceFactory.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareServiceFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareServiceFactory.java Sun Aug 4 13:16:20 2013
@@ -32,6 +32,7 @@ import java.util.Map;
import javax.xml.stream.XMLStreamReader;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
@@ -64,7 +65,7 @@ public class FileShareServiceFactory ext
@Override
public void init(Map<String, String> parameters) {
repositoryMap = new RepositoryMap();
- typeManager = new TypeManager();
+ typeManager = new TypeManager(CmisVersion.CMIS_1_1);
readConfiguration(parameters);
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/RepositoryMap.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/RepositoryMap.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/RepositoryMap.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/RepositoryMap.java Sun Aug 4 13:16:20 2013
@@ -31,11 +31,11 @@ import org.apache.chemistry.opencmis.com
*/
public class RepositoryMap {
- private final Map<String, FileShareRepository> map;
+ private final Map<String, FileShareRepository> repositories;
private final Map<String, String> logins;
public RepositoryMap() {
- map = new HashMap<String, FileShareRepository>();
+ repositories = new HashMap<String, FileShareRepository>();
logins = new HashMap<String, String>();
}
@@ -47,7 +47,7 @@ public class RepositoryMap {
return;
}
- map.put(fsr.getRepositoryId(), fsr);
+ repositories.put(fsr.getRepositoryId(), fsr);
}
/**
@@ -55,7 +55,7 @@ public class RepositoryMap {
*/
public FileShareRepository getRepository(String repositoryId) {
// get repository object
- FileShareRepository result = map.get(repositoryId);
+ FileShareRepository result = repositories.get(repositoryId);
if (result == null) {
throw new CmisObjectNotFoundException("Unknown repository '" + repositoryId + "'!");
}
@@ -77,7 +77,7 @@ public class RepositoryMap {
* Returns all repository objects.
*/
public Collection<FileShareRepository> getRepositories() {
- return map.values();
+ return repositories.values();
}
/**
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/TypeManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/TypeManager.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/TypeManager.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/TypeManager.java Sun Aug 4 13:16:20 2013
@@ -37,9 +37,6 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
-import org.apache.chemistry.opencmis.commons.impl.WSConverter;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractTypeDefinition;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
import org.apache.chemistry.opencmis.commons.server.CallContext;
@@ -62,11 +59,14 @@ public class TypeManager {
private static final Logger LOG = LoggerFactory.getLogger(TypeManager.class);
- private TypeDefinitionFactory tdf;
+ private final CmisVersion cmisVersion;
+ private final TypeDefinitionFactory tdf;
private Map<String, TypeDefinitionContainerImpl> types;
private List<TypeDefinitionContainer> typesList;
- public TypeManager() {
+ public TypeManager(CmisVersion cmisVersion) {
+ this.cmisVersion = cmisVersion;
+
tdf = TypeDefinitionFactory.newInstance();
tdf.setDefaultNamespace(NAMESPACE);
tdf.setDefaultControllableAcl(false);
@@ -74,13 +74,13 @@ public class TypeManager {
tdf.setDefaultQueryable(false);
tdf.setDefaultTypeMutability(tdf.createTypeMutability(false, false, false));
- setup(CmisVersion.CMIS_1_1);
+ setup();
}
/**
* Creates the base types.
*/
- private void setup(CmisVersion cmisVersion) {
+ private void setup() {
types = new HashMap<String, TypeDefinitionContainerImpl>();
typesList = new ArrayList<TypeDefinitionContainer>();
@@ -103,13 +103,15 @@ public class TypeManager {
// not supported - don't expose it
// addTypeInteral(tdf.createBasePolicyTypeDefinition(cmisVersion));
- // item type
- // not supported - don't expose it
- // addTypeInteral(tdf.createBaseItemTypeDefinition(cmisVersion));
-
- // secondary type
- // not supported - don't expose it
- // addTypeInteral(tdf.createBaseSecondaryTypeDefinition(cmisVersion));
+ if (cmisVersion != CmisVersion.CMIS_1_0) {
+ // item type
+ // not supported - don't expose it
+ // addTypeInteral(tdf.createBaseItemTypeDefinition(cmisVersion));
+
+ // secondary type
+ // not supported - don't expose it
+ // addTypeInteral(tdf.createBaseSecondaryTypeDefinition(cmisVersion));
+ }
} catch (Exception e) {
throw new CmisRuntimeException("Cannot set up type defintions!", e);
}
@@ -129,7 +131,7 @@ public class TypeManager {
}
/**
- * Adds a type to collection with inheriting base type properties.
+ * Adds a type to the collection with inheriting base type properties.
*/
public boolean addType(TypeDefinition type) {
if (type == null) {
@@ -141,27 +143,19 @@ public class TypeManager {
}
// find base type
- TypeDefinition baseType = null;
- if (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) {
- baseType = copyTypeDefintion(types.get(DOCUMENT_TYPE_ID).getTypeDefinition());
- } else if (type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) {
- baseType = copyTypeDefintion(types.get(FOLDER_TYPE_ID).getTypeDefinition());
- } else if (type.getBaseTypeId() == BaseTypeId.CMIS_ITEM) {
- baseType = copyTypeDefintion(types.get(ITEM_TYPE_ID).getTypeDefinition());
- } else if (type.getBaseTypeId() == BaseTypeId.CMIS_RELATIONSHIP) {
- baseType = copyTypeDefintion(types.get(RELATIONSHIP_TYPE_ID).getTypeDefinition());
- } else if (type.getBaseTypeId() == BaseTypeId.CMIS_POLICY) {
- baseType = copyTypeDefintion(types.get(POLICY_TYPE_ID).getTypeDefinition());
- } else {
+ TypeDefinitionContainer baseTypeContainer = types.get(type.getBaseTypeId().value());
+ if (baseTypeContainer == null) {
return false;
}
+ TypeDefinition baseType = baseTypeContainer.getTypeDefinition();
- AbstractTypeDefinition newType = (AbstractTypeDefinition) copyTypeDefintion(type);
+ MutableTypeDefinition newType = tdf.copy(type, true);
- // copy property definition
+ // copy base type property definitions and mark them as inherited
for (PropertyDefinition<?> propDef : baseType.getPropertyDefinitions().values()) {
- ((AbstractPropertyDefinition<?>) propDef).setIsInherited(true);
- newType.addPropertyDefinition(propDef);
+ MutablePropertyDefinition<?> basePropDef = tdf.copy(propDef);
+ basePropDef.setIsInherited(true);
+ newType.addPropertyDefinition(basePropDef);
}
// add it
@@ -192,9 +186,6 @@ public class TypeManager {
if (type.getParentTypeId() != null) {
TypeDefinitionContainerImpl tdc = types.get(type.getParentTypeId());
if (tdc != null) {
- if (tdc.getChildren() == null) {
- tdc.setChildren(new ArrayList<TypeDefinitionContainer>());
- }
tdc.getChildren().add(tc);
}
}
@@ -222,11 +213,15 @@ public class TypeManager {
if (typeId == null) {
if (skip < 1) {
- result.getList().add(copyTypeDefintion(types.get(FOLDER_TYPE_ID).getTypeDefinition()));
+ result.getList().add(
+ tdf.copy(types.get(FOLDER_TYPE_ID).getTypeDefinition(), includePropertyDefinitions,
+ context.getCmisVersion()));
max--;
}
if ((skip < 2) && (max > 0)) {
- result.getList().add(copyTypeDefintion(types.get(DOCUMENT_TYPE_ID).getTypeDefinition()));
+ result.getList().add(
+ tdf.copy(types.get(DOCUMENT_TYPE_ID).getTypeDefinition(), includePropertyDefinitions,
+ context.getCmisVersion()));
max--;
}
@@ -244,7 +239,7 @@ public class TypeManager {
continue;
}
- result.getList().add(copyTypeDefintion(child.getTypeDefinition()));
+ result.getList().add(tdf.copy(child.getTypeDefinition(), includePropertyDefinitions));
max--;
if (max == 0) {
@@ -256,19 +251,13 @@ public class TypeManager {
result.setNumItems(BigInteger.valueOf(tc.getChildren().size()));
}
- if (!includePropertyDefinitions) {
- for (TypeDefinition type : result.getList()) {
- type.getPropertyDefinitions().clear();
- }
- }
-
return result;
}
/**
* CMIS getTypesDescendants.
*/
- public List<TypeDefinitionContainer> getTypesDescendants(CallContext context, String typeId, BigInteger depth,
+ public List<TypeDefinitionContainer> getTypeDescendants(CallContext context, String typeId, BigInteger depth,
Boolean includePropertyDefinitions) {
List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
@@ -285,16 +274,12 @@ public class TypeManager {
boolean ipd = (includePropertyDefinitions == null ? false : includePropertyDefinitions.booleanValue());
if (typeId == null) {
- result.add(getTypesDescendants(d, types.get(FOLDER_TYPE_ID), ipd));
- result.add(getTypesDescendants(d, types.get(DOCUMENT_TYPE_ID), ipd));
- // result.add(getTypesDescendants(depth,
- // fTypes.get(RELATIONSHIP_TYPE_ID), includePropertyDefinitions));
- // result.add(getTypesDescendants(depth, fTypes.get(POLICY_TYPE_ID),
- // includePropertyDefinitions));
+ result.add(getTypesDescendants(context, d, types.get(FOLDER_TYPE_ID), ipd));
+ result.add(getTypesDescendants(context, d, types.get(DOCUMENT_TYPE_ID), ipd));
} else {
TypeDefinitionContainer tc = types.get(typeId);
if (tc != null) {
- result.add(getTypesDescendants(d, tc, ipd));
+ result.add(getTypesDescendants(context, d, tc, ipd));
}
}
@@ -304,24 +289,18 @@ public class TypeManager {
/**
* Gathers the type descendants tree.
*/
- private TypeDefinitionContainer getTypesDescendants(int depth, TypeDefinitionContainer tc,
+ private TypeDefinitionContainer getTypesDescendants(CallContext context, int depth, TypeDefinitionContainer tc,
boolean includePropertyDefinitions) {
TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl();
- TypeDefinition type = copyTypeDefintion(tc.getTypeDefinition());
- if (!includePropertyDefinitions) {
- type.getPropertyDefinitions().clear();
- }
+ TypeDefinition type = tdf.copy(tc.getTypeDefinition(), includePropertyDefinitions, context.getCmisVersion());
result.setTypeDefinition(type);
if (depth != 0) {
- if (tc.getChildren() != null) {
- result.setChildren(new ArrayList<TypeDefinitionContainer>());
- for (TypeDefinitionContainer tdc : tc.getChildren()) {
- result.getChildren().add(
- getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions));
- }
+ for (TypeDefinitionContainer tdc : tc.getChildren()) {
+ result.getChildren().add(
+ getTypesDescendants(context, depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions));
}
}
@@ -349,10 +328,6 @@ public class TypeManager {
throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
}
- return copyTypeDefintion(tc.getTypeDefinition());
- }
-
- private static TypeDefinition copyTypeDefintion(TypeDefinition type) {
- return WSConverter.convert(WSConverter.convert(type));
+ return tdf.copy(tc.getTypeDefinition(), true, context.getCmisVersion());
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java?rev=1510178&r1=1510177&r2=1510178&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java Sun Aug 4 13:16:20 2013
@@ -22,12 +22,15 @@ package org.apache.chemistry.opencmis.se
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
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.definitions.Choice;
import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition;
@@ -37,11 +40,16 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyHtmlDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyIdDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeMutability;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
@@ -51,6 +59,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChoiceImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.FolderTypeDefinitionImpl;
@@ -73,6 +82,13 @@ import org.apache.chemistry.opencmis.com
*/
public class TypeDefinitionFactory {
+ private static final Set<String> NEW_CMIS11_PROPERTIES = new HashSet<String>();
+ static {
+ NEW_CMIS11_PROPERTIES.add(PropertyIds.DESCRIPTION);
+ NEW_CMIS11_PROPERTIES.add(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ NEW_CMIS11_PROPERTIES.add(PropertyIds.IS_PRIVATE_WORKING_COPY);
+ }
+
private Class<? extends MutableDocumentTypeDefinition> documentTypeDefinitionClass;
private Class<? extends MutableFolderTypeDefinition> folderTypeDefinitionClass;
private Class<? extends MutablePolicyTypeDefinition> policyTypeDefinitionClass;
@@ -343,60 +359,6 @@ public class TypeDefinitionFactory {
}
/**
- * Creates a new mutable document type definition, which is a child of the
- * provided type definition. Property definitions are copied from the parent
- * and marked as inherited.
- *
- * @param parentTypeDefinition
- * the type definition of the parent
- * @param id
- * the id of the child type definition
- *
- * @return a mutable child type definition
- */
- public MutableDocumentTypeDefinition createChildDocumentTypeDefinition(DocumentTypeDefinition parentTypeDefinition,
- String id) {
- return createChildDocumentTypeDefinition(parentTypeDefinition, id, id, id, id, null, true);
- }
-
- /**
- * Creates a new mutable document type definition, which is a child of the
- * provided type definition. If the parameter
- * <code>includePropertyDefinitions</code> is to
- * <code>true</true> property definitions are copied from the parent
- * and marked as inherited.
- */
- public MutableDocumentTypeDefinition createChildDocumentTypeDefinition(DocumentTypeDefinition parentTypeDefinition,
- String id, String localName, String queryName, String displayName, String description,
- boolean includePropertyDefinitions) {
- MutableDocumentTypeDefinition documentType = createDocumentTypeDefinitionObject();
- documentType.setBaseTypeId(parentTypeDefinition.getBaseTypeId());
- documentType.setParentTypeId(parentTypeDefinition.getId());
- documentType.setIsControllableAcl(parentTypeDefinition.isControllableAcl());
- documentType.setIsControllablePolicy(parentTypeDefinition.isControllablePolicy());
- documentType.setIsCreatable(parentTypeDefinition.isCreatable());
- documentType.setDescription(description);
- documentType.setDisplayName(displayName);
- documentType.setIsFileable(parentTypeDefinition.isFileable());
- documentType.setIsFulltextIndexed(parentTypeDefinition.isFulltextIndexed());
- documentType.setIsIncludedInSupertypeQuery(parentTypeDefinition.isIncludedInSupertypeQuery());
- documentType.setLocalName(localName);
- documentType.setLocalNamespace(parentTypeDefinition.getLocalNamespace());
- documentType.setIsQueryable(parentTypeDefinition.isQueryable());
- documentType.setQueryName(queryName);
- documentType.setId(id);
- documentType.setTypeMutability(parentTypeDefinition.getTypeMutability());
- documentType.setIsVersionable(parentTypeDefinition.isVersionable());
- documentType.setContentStreamAllowed(parentTypeDefinition.getContentStreamAllowed());
-
- if (includePropertyDefinitions) {
- copyPropertyDefinitions(parentTypeDefinition, documentType, true);
- }
-
- return documentType;
- }
-
- /**
* Creates a new mutable base folder type definition including all property
* definitions defined in the CMIS specification.
*/
@@ -589,14 +551,76 @@ public class TypeDefinitionFactory {
return secondaryType;
}
+ /**
+ * Creates a new mutable type definition, which is a child of the provided
+ * type definition. Property definitions are copied from the parent and
+ * marked as inherited.
+ *
+ * @param parentTypeDefinition
+ * the type definition of the parent
+ * @param id
+ * the id of the child type definition
+ *
+ * @return a mutable child type definition
+ */
+ public MutableTypeDefinition createChildTypeDefinition(TypeDefinition parentTypeDefinition, String id) {
+ return createChildTypeDefinition(parentTypeDefinition, id, id, id, id, null, true, null);
+ }
+
+ /**
+ * Creates a new mutable type definition, which is a child of the provided
+ * type definition. If the parameter <code>includePropertyDefinitions</code>
+ * is set to
+ * <code>true</true> property definitions are copied from the parent
+ * and marked as inherited.
+ */
+ public MutableTypeDefinition createChildTypeDefinition(TypeDefinition parentTypeDefinition, String id,
+ String localName, String queryName, String displayName, String description,
+ boolean includePropertyDefinitions, CmisVersion cmisVersion) {
+ if (parentTypeDefinition == null) {
+ throw new IllegalArgumentException("Parent type must be set!");
+ }
+
+ if (id == null) {
+ throw new IllegalArgumentException("Child id must be set!");
+ }
+
+ MutableTypeDefinition childType = copy(parentTypeDefinition, false);
+
+ childType.setParentTypeId(parentTypeDefinition.getId());
+ childType.setDescription(description);
+ childType.setDisplayName(displayName);
+ childType.setLocalName(localName);
+ childType.setQueryName(queryName);
+ childType.setId(id);
+
+ if (includePropertyDefinitions) {
+ copyPropertyDefinitions(parentTypeDefinition, childType, cmisVersion, true);
+ }
+
+ return childType;
+ }
+
// --- copy methods ---
/**
* Copies the given type definition and returns a mutable object.
*/
public MutableTypeDefinition copy(TypeDefinition sourceTypeDefintion, boolean includePropertyDefinitions) {
+ return copy(sourceTypeDefintion, includePropertyDefinitions, null);
+ }
+
+ /**
+ * Copies the given type definition and returns a mutable object.
+ */
+ public MutableTypeDefinition copy(TypeDefinition sourceTypeDefintion, boolean includePropertyDefinitions,
+ CmisVersion cmisVersion) {
if (sourceTypeDefintion == null) {
- return null;
+ throw new IllegalArgumentException("Source type must be set!");
+ }
+
+ if (sourceTypeDefintion.getBaseTypeId() == null) {
+ throw new IllegalArgumentException("Source type has no base type!");
}
MutableTypeDefinition result = null;
@@ -604,6 +628,10 @@ public class TypeDefinitionFactory {
switch (sourceTypeDefintion.getBaseTypeId()) {
case CMIS_DOCUMENT:
result = createDocumentTypeDefinitionObject();
+ ((MutableDocumentTypeDefinition) result).setIsVersionable(((DocumentTypeDefinition) sourceTypeDefintion)
+ .isVersionable());
+ ((MutableDocumentTypeDefinition) result)
+ .setContentStreamAllowed(((DocumentTypeDefinition) sourceTypeDefintion).getContentStreamAllowed());
break;
case CMIS_FOLDER:
result = createFolderTypeDefinitionObject();
@@ -613,23 +641,61 @@ public class TypeDefinitionFactory {
break;
case CMIS_RELATIONSHIP:
result = createRelationshipTypeDefinitionObject();
+ List<String> sourceTypeIds = ((RelationshipTypeDefinition) sourceTypeDefintion).getAllowedSourceTypeIds();
+ if (sourceTypeIds != null) {
+ ((MutableRelationshipTypeDefinition) result)
+ .setAllowedSourceTypes(new ArrayList<String>(sourceTypeIds));
+ }
+ List<String> targetTypeIds = ((RelationshipTypeDefinition) sourceTypeDefintion).getAllowedTargetTypeIds();
+ if (targetTypeIds != null) {
+ ((MutableRelationshipTypeDefinition) result)
+ .setAllowedTargetTypes(new ArrayList<String>(targetTypeIds));
+ }
break;
case CMIS_ITEM:
+ if (cmisVersion == CmisVersion.CMIS_1_0) {
+ throw new IllegalArgumentException("CMIS 1.0 doesn't support item types!");
+ }
result = createItemTypeDefinitionObject();
break;
case CMIS_SECONDARY:
+ if (cmisVersion == CmisVersion.CMIS_1_0) {
+ throw new IllegalArgumentException("CMIS 1.0 doesn't support secondary types!");
+ }
result = createSecondaryTypeDefinitionObject();
break;
default:
throw new RuntimeException("Unknown base type!");
}
- // TODO: copy attributes
+ result.setId(sourceTypeDefintion.getId());
+ result.setLocalName(sourceTypeDefintion.getLocalName());
+ result.setLocalNamespace(sourceTypeDefintion.getLocalNamespace());
+ result.setDisplayName(sourceTypeDefintion.getDisplayName());
+ result.setQueryName(sourceTypeDefintion.getQueryName());
+ result.setDescription(sourceTypeDefintion.getDescription());
+ result.setBaseTypeId(sourceTypeDefintion.getBaseTypeId());
+ result.setParentTypeId(sourceTypeDefintion.getParentTypeId());
+ result.setIsCreatable(sourceTypeDefintion.isCreatable());
+ result.setIsFileable(sourceTypeDefintion.isFileable());
+ result.setIsQueryable(sourceTypeDefintion.isQueryable());
+ result.setIsFulltextIndexed(sourceTypeDefintion.isFulltextIndexed());
+ result.setIsIncludedInSupertypeQuery(sourceTypeDefintion.isIncludedInSupertypeQuery());
+ result.setIsControllablePolicy(sourceTypeDefintion.isControllablePolicy());
+ result.setIsControllableAcl(sourceTypeDefintion.isControllableAcl());
+
+ if (cmisVersion != CmisVersion.CMIS_1_0) {
+ if (sourceTypeDefintion.getTypeMutability() != null) {
+ result.setTypeMutability(createTypeMutability(sourceTypeDefintion.getTypeMutability().canCreate(),
+ sourceTypeDefintion.getTypeMutability().canUpdate(), sourceTypeDefintion.getTypeMutability()
+ .canDelete()));
+ }
+ }
copyExtensions(sourceTypeDefintion, result);
if (includePropertyDefinitions) {
- copyPropertyDefinitions(sourceTypeDefintion, result, false);
+ copyPropertyDefinitions(sourceTypeDefintion, result, cmisVersion, false);
}
return result;
@@ -640,7 +706,11 @@ public class TypeDefinitionFactory {
*/
public MutablePropertyDefinition<?> copy(PropertyDefinition<?> sourcePropertyDefinition) {
if (sourcePropertyDefinition == null) {
- return null;
+ throw new IllegalArgumentException("Source definition must be set!");
+ }
+
+ if (sourcePropertyDefinition.getPropertyType() == null) {
+ throw new IllegalArgumentException("Source definition property type must be set!");
}
MutablePropertyDefinition<?> result = null;
@@ -648,12 +718,20 @@ public class TypeDefinitionFactory {
switch (sourcePropertyDefinition.getPropertyType()) {
case BOOLEAN:
result = new PropertyBooleanDefinitionImpl();
+ ((PropertyBooleanDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyBooleanDefinition) sourcePropertyDefinition));
+ ((PropertyBooleanDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyBooleanDefinition) sourcePropertyDefinition));
break;
case DATETIME:
result = new PropertyDateTimeDefinitionImpl();
((PropertyDateTimeDefinitionImpl) result)
.setDateTimeResolution(((PropertyDateTimeDefinition) sourcePropertyDefinition)
.getDateTimeResolution());
+ ((PropertyDateTimeDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyDateTimeDefinition) sourcePropertyDefinition));
+ ((PropertyDateTimeDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyDateTimeDefinition) sourcePropertyDefinition));
break;
case DECIMAL:
result = new PropertyDecimalDefinitionImpl();
@@ -663,12 +741,22 @@ public class TypeDefinitionFactory {
.getMaxValue());
((PropertyDecimalDefinitionImpl) result)
.setPrecision(((PropertyDecimalDefinition) sourcePropertyDefinition).getPrecision());
+ ((PropertyDecimalDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyDecimalDefinition) sourcePropertyDefinition));
+ ((PropertyDecimalDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyDecimalDefinition) sourcePropertyDefinition));
break;
case HTML:
result = new PropertyHtmlDefinitionImpl();
+ ((PropertyHtmlDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyHtmlDefinition) sourcePropertyDefinition));
break;
case ID:
result = new PropertyIdDefinitionImpl();
+ ((PropertyIdDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyIdDefinition) sourcePropertyDefinition));
+ ((PropertyIdDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyIdDefinition) sourcePropertyDefinition));
break;
case INTEGER:
result = new PropertyIntegerDefinitionImpl();
@@ -676,14 +764,26 @@ public class TypeDefinitionFactory {
.getMinValue());
((PropertyIntegerDefinitionImpl) result).setMaxValue(((PropertyIntegerDefinition) sourcePropertyDefinition)
.getMaxValue());
+ ((PropertyIntegerDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyIntegerDefinition) sourcePropertyDefinition));
+ ((PropertyIntegerDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyIntegerDefinition) sourcePropertyDefinition));
break;
case STRING:
result = new PropertyStringDefinitionImpl();
((PropertyStringDefinitionImpl) result).setMaxLength((((PropertyStringDefinition) sourcePropertyDefinition)
.getMaxLength()));
+ ((PropertyStringDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyStringDefinition) sourcePropertyDefinition));
+ ((PropertyStringDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyStringDefinition) sourcePropertyDefinition));
break;
case URI:
result = new PropertyUriDefinitionImpl();
+ ((PropertyUriDefinitionImpl) result)
+ .setDefaultValue(copyDefaultValue((PropertyUriDefinition) sourcePropertyDefinition));
+ ((PropertyUriDefinitionImpl) result)
+ .setChoices(copyChoices((PropertyUriDefinition) sourcePropertyDefinition));
break;
default:
throw new RuntimeException("Unknown datatype!");
@@ -702,8 +802,6 @@ public class TypeDefinitionFactory {
result.setIsOrderable(sourcePropertyDefinition.isOrderable());
result.setQueryName(sourcePropertyDefinition.getQueryName());
- // TODO: handle default values and choices
-
copyExtensions(sourcePropertyDefinition, result);
return result;
@@ -714,9 +812,16 @@ public class TypeDefinitionFactory {
/**
* Copies the property definitions from a source type to a target type.
*/
- protected void copyPropertyDefinitions(TypeDefinition source, MutableTypeDefinition target, boolean markAsInherited) {
+ protected void copyPropertyDefinitions(TypeDefinition source, MutableTypeDefinition target,
+ CmisVersion cmisVersion, boolean markAsInherited) {
if (source != null && source.getPropertyDefinitions() != null) {
for (PropertyDefinition<?> propDef : source.getPropertyDefinitions().values()) {
+ if (cmisVersion == CmisVersion.CMIS_1_0) {
+ if (NEW_CMIS11_PROPERTIES.contains(propDef.getId())) {
+ break;
+ }
+ }
+
MutablePropertyDefinition<?> newPropDef = copy(propDef);
if (markAsInherited) {
newPropDef.setIsInherited(true);
@@ -727,6 +832,56 @@ public class TypeDefinitionFactory {
}
/**
+ * Returns a copy of a default value.
+ */
+ protected <T> List<T> copyDefaultValue(PropertyDefinition<T> source) {
+ if (source == null || source.getDefaultValue() == null) {
+ return null;
+ }
+
+ return new ArrayList<T>(source.getDefaultValue());
+ }
+
+ /**
+ * Returns a copy of a choice tree.
+ */
+ protected <T> List<Choice<T>> copyChoices(PropertyDefinition<T> source) {
+ if (source == null || source.getChoices() == null) {
+ return null;
+ }
+
+ List<Choice<T>> result = new ArrayList<Choice<T>>();
+
+ for (Choice<T> c : source.getChoices()) {
+ result.add(copyChoice(c));
+ }
+
+ return result;
+ }
+
+ private <T> Choice<T> copyChoice(Choice<T> source) {
+ if (source == null) {
+ return null;
+ }
+
+ ChoiceImpl<T> result = new ChoiceImpl<T>();
+
+ result.setDisplayName(source.getDisplayName());
+ if (source.getValue() != null) {
+ result.setValue(new ArrayList<T>(source.getValue()));
+ }
+ if (source.getChoice() != null) {
+ List<Choice<T>> choices = new ArrayList<Choice<T>>();
+ for (Choice<T> c : source.getChoice()) {
+ choices.add(copyChoice(c));
+ }
+ result.setChoice(choices);
+ }
+
+ return result;
+ }
+
+ /**
* Makes a deep copy of extension of a source object and adds them to a
* target object.
*/