From dbec12a9c716192d79324ce2c8ddfd673a933dcb Mon Sep 17 00:00:00 2001 From: David Caruana Date: Tue, 31 Mar 2009 17:48:28 +0000 Subject: [PATCH] Refactor CMIS Dictionary part 2 - further simplification of CMISDictionaryService and fixup fallout - added logging - consolidate & fix property definition handling (only one definition per property) - include support for aspect properties - fix property.isInherited - open up the door for types outside of CMIS doc, folder, rel & policy Dictionary Service - add isOverride() to PropertyDefinition Invite Workflows - ensure they create their own namespace for new types/props - NOTE: the previous way uses a hole in the DictinaryService which has been there unnoticed for over 4 years, till now. At some point, the hole will be filled in. Tests pass for CMIS REST / Web Services and Query. Tests pass for Invitation Service. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13786 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/cmis/atomentry.lib.atom.ftl | 3 ++- .../alfresco/repo/cmis/rest/CMISScript.java | 6 ++--- .../cmis/rest/CMISTypeDefinitionMethod.java | 7 +----- .../repo/cmis/ws/DMAbstractServicePort.java | 25 +++++-------------- .../repo/cmis/ws/DMObjectServicePort.java | 14 +++++------ .../cmis/ws/DMRelationshipServicePort.java | 9 ++++--- .../repo/cmis/ws/DMRepositoryServicePort.java | 6 ++--- .../repo/cmis/ws/utils/CmisObjectsUtils.java | 15 +++++------ 8 files changed, 34 insertions(+), 51 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl b/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl index c8c10a119a..c7c97c2788 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/cmis/atomentry.lib.atom.ftl @@ -388,8 +388,9 @@ ${typedef.controllable?string} ${typedef.includeInSuperTypeQuery?string} [#if includeProperties] + [#assign ownedprops = typedef.ownedPropertyDefinitions?keys] [#list typedef.propertyDefinitions?values as propdef] - [#assign inherited = (propdef.owningType != typedef)] + [#assign inherited = !ownedprops?seq_contains(propdef.propertyId)] [#if includeInheritedProperties || !inherited] [@propdefCMISProps propdef inherited/] [/#if] diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java index 382ab6fa98..158ed25ba5 100644 --- a/source/java/org/alfresco/repo/cmis/rest/CMISScript.java +++ b/source/java/org/alfresco/repo/cmis/rest/CMISScript.java @@ -389,8 +389,7 @@ public class CMISScript extends BaseScopableProcessorExtension { try { - CMISTypeId cmisTypeId = cmisDictionaryService.getTypeId(typeId); - return cmisDictionaryService.getType(cmisTypeId); + return cmisDictionaryService.findType(typeId); } catch(AlfrescoRuntimeException e) { @@ -409,8 +408,7 @@ public class CMISScript extends BaseScopableProcessorExtension try { QName typeQName = node.getQNameType(); - CMISTypeId cmisTypeId = cmisDictionaryService.getTypeId(typeQName, null); - return cmisDictionaryService.getType(cmisTypeId); + return cmisDictionaryService.findTypeForClass(typeQName); } catch(AlfrescoRuntimeException e) { diff --git a/source/java/org/alfresco/repo/cmis/rest/CMISTypeDefinitionMethod.java b/source/java/org/alfresco/repo/cmis/rest/CMISTypeDefinitionMethod.java index 0b8952fdba..4b505c6b9b 100644 --- a/source/java/org/alfresco/repo/cmis/rest/CMISTypeDefinitionMethod.java +++ b/source/java/org/alfresco/repo/cmis/rest/CMISTypeDefinitionMethod.java @@ -28,7 +28,6 @@ import java.util.List; import org.alfresco.cmis.dictionary.CMISDictionaryService; import org.alfresco.cmis.dictionary.CMISTypeDefinition; -import org.alfresco.cmis.dictionary.CMISTypeId; import org.alfresco.repo.template.TemplateNode; import org.alfresco.service.namespace.QName; @@ -89,11 +88,7 @@ public class CMISTypeDefinitionMethod implements TemplateMethodModelEx // convert to CMIS type if (nodeType != null) { - CMISTypeId typeId = dictionaryService.getTypeId(nodeType, null); - if (typeId != null) - { - result = dictionaryService.getType(typeId); - } + result = dictionaryService.findTypeForClass(nodeType); } } } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java index 26dfceb7cc..dcc58270ff 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMAbstractServicePort.java @@ -285,11 +285,11 @@ public class DMAbstractServicePort protected CmisPropertiesType getPropertiesType(Map alfrescoProperties, PropertyFilter filter) { String objectTypeId = (String) alfrescoProperties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID); - CMISTypeId cmisTypeId = cmisDictionaryService.getTypeId(objectTypeId); + CMISTypeDefinition cmisTypeDef = cmisDictionaryService.findType(objectTypeId); CmisPropertiesType properties = new CmisPropertiesType(); - if (cmisTypeId.getScope() == CMISScope.DOCUMENT) + if (cmisTypeDef.getTypeId().getScope() == CMISScope.DOCUMENT) { addBooleanProperty(properties, filter, CMISDictionaryModel.PROP_IS_IMMUTABLE, alfrescoProperties); addBooleanProperty(properties, filter, CMISDictionaryModel.PROP_IS_LATEST_VERSION, alfrescoProperties); @@ -314,7 +314,7 @@ public class DMAbstractServicePort addStringProperty(properties, filter, CMISDictionaryModel.PROP_CHECKIN_COMMENT, alfrescoProperties); addURIProperty(properties, filter, CMISDictionaryModel.PROP_CONTENT_STREAM_URI, alfrescoProperties); } - else if (cmisTypeId.getScope() == CMISScope.FOLDER) + else if (cmisTypeDef.getTypeId().getScope() == CMISScope.FOLDER) { addDateTimeProperty(properties, filter, CMISDictionaryModel.PROP_CREATION_DATE, alfrescoProperties); addDateTimeProperty(properties, filter, CMISDictionaryModel.PROP_LAST_MODIFICATION_DATE, alfrescoProperties); @@ -326,7 +326,7 @@ public class DMAbstractServicePort addStringProperty(properties, filter, CMISDictionaryModel.PROP_CREATED_BY, alfrescoProperties); addStringProperty(properties, filter, CMISDictionaryModel.PROP_LAST_MODIFIED_BY, alfrescoProperties); } - else if (cmisTypeId.getScope() == CMISScope.RELATIONSHIP) + else if (cmisTypeDef.getTypeId().getScope() == CMISScope.RELATIONSHIP) { addStringProperty(properties, filter, CMISDictionaryModel.PROP_OBJECT_TYPE_ID, alfrescoProperties); addIDProperty(properties, filter, CMISDictionaryModel.PROP_OBJECT_ID, alfrescoProperties); @@ -343,7 +343,7 @@ public class DMAbstractServicePort private Map createBaseRelationshipProperties(AssociationRef association) { Map result = new HashMap(); - result.put(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, cmisDictionaryService.getTypeId(association.getTypeQName(), CMISScope.RELATIONSHIP)); + result.put(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, cmisDictionaryService.findTypeForClass(association.getTypeQName(), CMISScope.RELATIONSHIP).getTypeId()); result.put(CMISDictionaryModel.PROP_OBJECT_ID, association.toString()); result.put(BASE_TYPE_PROPERTY_NAME, CMISDictionaryModel.RELATIONSHIP_TYPE_ID.getId()); result.put(CMISDictionaryModel.PROP_CREATED_BY, AuthenticationUtil.getFullyAuthenticatedUser()); @@ -624,24 +624,11 @@ public class DMAbstractServicePort return checkOutCheckInService.checkout(documentNodeReference); } - protected CMISTypeId getCmisTypeId(String typeId) throws InvalidArgumentException - { - try - { - return cmisDictionaryService.getTypeId(typeId); - } - catch (Exception e) - { - throw new InvalidArgumentException("Invalid typeId " + typeId); - } - } - protected CMISTypeDefinition getCmisTypeDefinition(String typeId) throws InvalidArgumentException { try { - CMISTypeId cmisTypeId = cmisDictionaryService.getTypeId(typeId); - return cmisDictionaryService.getType(cmisTypeId); + return cmisDictionaryService.findType(typeId); } catch (Exception e) { diff --git a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java index 330dfb4a66..17d9b8881c 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java @@ -112,8 +112,8 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object checkRepositoryId(repositoryId); Map propertiesMap = getPropertiesMap(properties); - CMISTypeId cmisTypeId = getCmisTypeId(typeId); - if (cmisTypeId.getScope() != CMISScope.DOCUMENT) + CMISTypeDefinition typeDef = cmisDictionaryService.findType(typeId); + if (typeDef.getTypeId().getScope() != CMISScope.DOCUMENT) { throw new ConstraintViolationException("Invalid document type " + typeId); } @@ -126,7 +126,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object throw new InvalidArgumentException("Name property not found"); } - NodeRef newDocumentNodeRef = fileFolderService.create(parentNodeRef, documentName, cmisTypeId.getQName()).getNodeRef(); + NodeRef newDocumentNodeRef = fileFolderService.create(parentNodeRef, documentName, typeDef.getTypeId().getQName()).getNodeRef(); ContentWriter writer = fileFolderService.getWriter(newDocumentNodeRef); String mimeType = (String) propertiesMap.get(CMISDictionaryModel.PROP_CONTENT_STREAM_MIME_TYPE); if (mimeType != null) @@ -286,13 +286,13 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object throw e; } - CMISTypeId relationshipTypeId = getCmisTypeId(typeId); - if (relationshipTypeId.getScope() != CMISScope.RELATIONSHIP) + CMISTypeDefinition relationshipType = cmisDictionaryService.findType(typeId); + if (relationshipType == null || relationshipType.getTypeId().getScope() != CMISScope.RELATIONSHIP) { throw new TypeNotFoundException(typeId); } - QName relationshipTypeQName = relationshipTypeId.getQName(); + QName relationshipTypeQName = relationshipType.getTypeId().getQName(); AssociationDefinition associationDef = dictionaryService.getAssociation(relationshipTypeQName); if (associationDef != null) { @@ -310,7 +310,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object } else { - throw new TypeNotFoundException(relationshipTypeId.getQName() + " Relationship type not found"); + throw new TypeNotFoundException(relationshipType.getTypeId().getQName() + " Relationship type not found"); } } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java index b25a8cd8a2..b5a2e8fec4 100755 --- a/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMRelationshipServicePort.java @@ -29,6 +29,7 @@ import java.util.LinkedList; import java.util.List; import org.alfresco.cmis.dictionary.CMISScope; +import org.alfresco.cmis.dictionary.CMISTypeDefinition; import org.alfresco.cmis.dictionary.CMISTypeId; import org.alfresco.repo.cmis.PropertyFilter; import org.alfresco.repo.cmis.ws.utils.AlfrescoObjectType; @@ -83,8 +84,8 @@ public class DMRelationshipServicePort extends DMAbstractServicePort implements BigInteger skipCount = ((parameters.getSkipCount() != null) && (parameters.getSkipCount().getValue() != null)) ? parameters.getSkipCount().getValue() : BigInteger.ZERO; BigInteger maxItems = ((parameters.getMaxItems() != null) && (parameters.getMaxItems().getValue() != null)) ? parameters.getMaxItems().getValue() : BigInteger.ZERO; - CMISTypeId cmisTypeId = getCmisTypeId(typeId); - QName associationType = cmisTypeId.getQName(); + CMISTypeDefinition cmisTypeDef = cmisDictionaryService.findType(typeId); + QName associationType = cmisTypeDef.getTypeId().getQName(); PropertyFilter propertyFilter = createPropertyFilter(parameters.getFilter()); NodeRef objectNodeRef = (NodeRef) cmisObjectsUtils.getIdentifierInstance(parameters.getObjectId(), AlfrescoObjectType.DOCUMENT_OR_FOLDER_OBJECT).getConvertedIdentifier(); @@ -146,8 +147,8 @@ public class DMRelationshipServicePort extends DMAbstractServicePort implements } else { - CMISTypeId typeId = cmisDictionaryService.getTypeId(qname, CMISScope.RELATIONSHIP); - return typeId != null && relationshipType.equals(qname); + CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(qname, CMISScope.RELATIONSHIP); + return typeDef != null && relationshipType.equals(qname); } } } diff --git a/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java index 75207e0f06..1918f7dc19 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMRepositoryServicePort.java @@ -289,7 +289,7 @@ public class DMRepositoryServicePort extends DMAbstractServicePort implements Re wsPropertyDef.setPropertyType(propertyTypeEnumMapping.get(propertyDefinition.getDataType())); wsPropertyDef.setCardinality(cardinalityEnumMapping.get(propertyDefinition.getCardinality())); wsPropertyDef.setUpdateability(updatabilityEnumMapping.get(propertyDefinition.getUpdatability())); - wsPropertyDef.setInherited(propertyDefinition.getOwningType().equals(typeDefinition)); + wsPropertyDef.setInherited(!typeDefinition.getOwnedPropertyDefinitions().containsKey(propertyDefinition.getPropertyId())); wsPropertyDef.setRequired(propertyDefinition.isRequired()); wsPropertyDef.setQueryable(propertyDefinition.isQueryable()); wsPropertyDef.setOrderable(propertyDefinition.isOrderable()); @@ -410,7 +410,7 @@ public class DMRepositoryServicePort extends DMAbstractServicePort implements Re } else { - CMISTypeDefinition typeDef = cmisDictionaryService.getType(cmisDictionaryService.getTypeId(parameters.getTypeId().getValue())); + CMISTypeDefinition typeDef = cmisDictionaryService.findType(parameters.getTypeId().getValue()); typeDefs = typeDef.getSubTypes(true); } @@ -463,7 +463,7 @@ public class DMRepositoryServicePort extends DMAbstractServicePort implements Re checkRepositoryId(parameters.getRepositoryId()); GetTypeDefinitionResponse response = new GetTypeDefinitionResponse(); - CMISTypeDefinition typeDef = cmisDictionaryService.getType(cmisDictionaryService.getTypeId(parameters.getTypeId())); + CMISTypeDefinition typeDef = cmisDictionaryService.findType(parameters.getTypeId()); response.setType(getCmisTypeDefinition(typeDef, true)); return response; } diff --git a/source/java/org/alfresco/repo/cmis/ws/utils/CmisObjectsUtils.java b/source/java/org/alfresco/repo/cmis/ws/utils/CmisObjectsUtils.java index ec6821a7b7..589ff03b9c 100755 --- a/source/java/org/alfresco/repo/cmis/ws/utils/CmisObjectsUtils.java +++ b/source/java/org/alfresco/repo/cmis/ws/utils/CmisObjectsUtils.java @@ -29,6 +29,7 @@ import java.util.List; import org.alfresco.cmis.dictionary.CMISDictionaryService; import org.alfresco.cmis.dictionary.CMISScope; +import org.alfresco.cmis.dictionary.CMISTypeDefinition; import org.alfresco.cmis.dictionary.CMISTypeId; import org.alfresco.model.ContentModel; import org.alfresco.repo.cmis.ws.EnumObjectType; @@ -219,8 +220,8 @@ public class CmisObjectsUtils return false; } QName typeQName = nodeService.getType(folderNodeRef); - CMISTypeId typeId = cmisDictionaryService.getTypeId(typeQName, CMISScope.FOLDER); - return typeId != null; + CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(typeQName, CMISScope.FOLDER); + return typeDef != null; } public boolean isDocument(NodeRef documentNodeRef) @@ -230,8 +231,8 @@ public class CmisObjectsUtils return false; } QName typeQName = nodeService.getType(documentNodeRef); - CMISTypeId typeId = cmisDictionaryService.getTypeId(typeQName, CMISScope.DOCUMENT); - return typeId != null; + CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(typeQName, CMISScope.DOCUMENT); + return typeDef != null; } public boolean isRelationship(String identifier) @@ -363,14 +364,14 @@ public class CmisObjectsUtils private AlfrescoObjectType determineActualObjectType(AlfrescoObjectType expectedType, QName objectType) { - CMISTypeId typeId = cmisDictionaryService.getTypeId(objectType, null); + CMISTypeDefinition typeDef = cmisDictionaryService.findTypeForClass(objectType); if ((expectedType == AlfrescoObjectType.DOCUMENT_OBJECT || expectedType == AlfrescoObjectType.DOCUMENT_OR_FOLDER_OBJECT) - && typeId.getScope() == CMISScope.DOCUMENT) + && typeDef.getTypeId().getScope() == CMISScope.DOCUMENT) { return expectedType; } if ((expectedType == AlfrescoObjectType.FOLDER_OBJECT || expectedType == AlfrescoObjectType.DOCUMENT_OR_FOLDER_OBJECT) - && typeId.getScope() == CMISScope.FOLDER) + && typeDef.getTypeId().getScope() == CMISScope.FOLDER) { return expectedType; }