From 67bda4baa6aee3af8b7e8a70cc9db958d2313e88 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Tue, 9 Mar 2010 17:22:22 +0000 Subject: [PATCH] Merging /BRANCHES/DEV/BELARUS/HEAD-2010_03_09/ to HEAD: 19162: Bug related to properties receiving in PropertyUtil was fixed. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19164 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/cmis/ws/DMObjectServicePort.java | 8 +++-- .../repo/cmis/ws/utils/PropertyUtil.java | 36 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java index d19b514c3f..c748b9c38c 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMObjectServicePort.java @@ -37,6 +37,7 @@ import org.alfresco.cmis.CMISInvalidArgumentException; import org.alfresco.cmis.CMISRenditionKind; import org.alfresco.cmis.CMISScope; import org.alfresco.cmis.CMISServiceException; +import org.alfresco.cmis.CMISServices; import org.alfresco.cmis.CMISTypeDefinition; import org.alfresco.cmis.CMISVersioningStateEnum; import org.alfresco.repo.cmis.PropertyFilter; @@ -48,6 +49,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileNotFoundException; +import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.FileTypeImageSize; @@ -320,8 +322,8 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object { throw ExceptionUtil.createCmisException("Target object type isn't allowed as target type", EnumServiceException.CONSTRAINT); } - String createdId = nodeService.createAssociation(sourceNodeRef, targetNodeRef, relationshipTypeQName).toString(); - objectId.value = createdId; + AssociationRef assocRef = nodeService.createAssociation(sourceNodeRef, targetNodeRef, relationshipTypeQName); + objectId.value = CMISServices.ASSOC_ID_PREFIX + assocRef.getId(); } else { @@ -428,7 +430,7 @@ public class DMObjectServicePort extends DMAbstractServicePort implements Object try { - NodeRef object = cmisService.getReadableObject(objectId, NodeRef.class); + Object object = cmisService.getReadableObject(objectId, Object.class); PropertyFilter propertyFilter = createPropertyFilter(filter); CmisObjectType cmisObject = createCmisObject(object, propertyFilter, includeRelationships, includeAllowableActions, renditionFilter); diff --git a/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java b/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java index d3d0bf6141..519e48bd7d 100644 --- a/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java +++ b/source/java/org/alfresco/repo/cmis/ws/utils/PropertyUtil.java @@ -471,14 +471,14 @@ public class PropertyUtil aspectProperties.putAll(cmisService.getProperties((NodeRef)object, typeDef)); } CmisPropertiesType aspectResult = new CmisPropertiesType(); - convertToCmisProperties(aspectProperties, filter, aspectResult); + convertToCmisProperties(object, aspectProperties, filter, aspectResult); extension.setProperties(aspectResult); } else { properties = createBaseRelationshipProperties((AssociationRef) object); } - convertToCmisProperties(properties, filter, result); + convertToCmisProperties(object, properties, filter, result); return result; } catch (CMISInvalidArgumentException e) @@ -491,7 +491,7 @@ public class PropertyUtil { Map result = new HashMap(); result.put(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, cmisDictionaryService.findTypeForClass(association.getTypeQName(), CMISScope.RELATIONSHIP).getTypeId()); - result.put(CMISDictionaryModel.PROP_OBJECT_ID, association.toString()); + result.put(CMISDictionaryModel.PROP_OBJECT_ID, CMISServices.ASSOC_ID_PREFIX + association.getId()); result.put(BASE_TYPE_PROPERTY_NAME, CMISDictionaryModel.RELATIONSHIP_TYPE_ID.getId()); result.put(CMISDictionaryModel.PROP_CREATED_BY, AuthenticationUtil.getFullyAuthenticatedUser()); result.put(CMISDictionaryModel.PROP_CREATION_DATE, new Date()); @@ -500,14 +500,36 @@ public class PropertyUtil return result; } - private void convertToCmisProperties(Map properties, PropertyFilter filter, CmisPropertiesType cmisProperties) throws CmisException + private void convertToCmisProperties(Object object, Map properties, PropertyFilter filter, CmisPropertiesType cmisProperties) throws CmisException { - String typeId = properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID) != null ? properties.get(CMISDictionaryModel.PROP_OBJECT_TYPE_ID).toString() : null; - CMISTypeDefinition type = cmisDictionaryService.findType(typeId); + CMISTypeDefinition type = null; + if (object instanceof NodeRef) + { + try + { + type = cmisService.getTypeDefinition((NodeRef) object); + } + catch (CMISInvalidArgumentException e) + { + throw ExceptionUtil.createCmisException(e.getMessage(), EnumServiceException.INVALID_ARGUMENT); + } + + } + else + { + try + { + type = cmisService.getTypeDefinition((AssociationRef) object); + } + catch (CMISInvalidArgumentException e) + { + throw ExceptionUtil.createCmisException(e.getMessage(), EnumServiceException.INVALID_ARGUMENT); + } + } if (null == type) { - throw ExceptionUtil.createCmisException(("Type with " + typeId + " typeId was not found"), EnumServiceException.RUNTIME); + throw ExceptionUtil.createCmisException(("Type for object " + object + " was not found"), EnumServiceException.RUNTIME); } for (String propertyName : properties.keySet())