diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index 4e39d6c914..39134a404e 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -1568,18 +1568,14 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen }); } - CmisVersion cmisVersion = getRequestCmisVersion(); - if(cmisVersion.equals(CmisVersion.CMIS_1_0)) + // add aspects + List extensions = getAspectExtensions(info, filter, result.getProperties() + .getProperties().keySet()); + if (!extensions.isEmpty()) { - // add aspects (cmis 1.0) - List extensions = getAspectExtensions(info, filter, result.getProperties() - .getProperties().keySet()); - if (!extensions.isEmpty()) - { - result.getProperties().setExtensions( - Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl( - ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions))); - } + result.getProperties().setExtensions( + Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl( + ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions))); } } return result; @@ -1983,13 +1979,18 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen { continue; } + + AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect); + Map aspectProperties = aspectDefinition.getProperties(); extensions.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, APPLIED_ASPECTS, null, aspectType .getTypeId())); for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) { - if (propertyIds.contains(propDef.getPropertyId())) + boolean addPropertyToExtensionList = getRequestCmisVersion().equals(CmisVersion.CMIS_1_1) && aspectProperties.keySet().contains(propDef.getAlfrescoName()); + // MNT-11876 : add property to extension even if it has been returned (CMIS 1.1) + if (propertyIds.contains(propDef.getPropertyId()) && !addPropertyToExtensionList) { // skip properties that have already been added continue; diff --git a/source/test-java/org/alfresco/opencmis/CMISTest.java b/source/test-java/org/alfresco/opencmis/CMISTest.java index 7d9b0c8e58..a1c1d97e18 100644 --- a/source/test-java/org/alfresco/opencmis/CMISTest.java +++ b/source/test-java/org/alfresco/opencmis/CMISTest.java @@ -36,6 +36,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.GregorianCalendar; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -2439,4 +2440,98 @@ public class CMISTest AuthenticationUtil.popAuthentication(); } } -} \ No newline at end of file + + /** + * MNT-11876 : Test that Alfresco CMIS 1.1 Implementation is returning aspect and aspect properties as extension data + * @throws Exception + */ + @Test + public void testExtensionDataIsReturnedViaCmis1_1() throws Exception + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + final String FOLDER = "testExtensionDataIsReturnedViaCmis1_1-" + GUID.generate(); + final String CONTENT = FOLDER + "-file"; + + try + { + transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + // create folder + FileInfo folderInfo = fileFolderService.create(repositoryHelper.getCompanyHome(), FOLDER, ContentModel.TYPE_FOLDER); + nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER); + assertNotNull(folderInfo); + + // create document + FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), CONTENT, ContentModel.TYPE_CONTENT); + assertNotNull(document); + nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, CONTENT); + + // apply aspect with properties + Map props = new HashMap(); + props.put(ContentModel.PROP_LATITUDE, Double.valueOf(1.0d)); + props.put(ContentModel.PROP_LONGITUDE, Double.valueOf(1.0d)); + nodeService.addAspect(document.getNodeRef(), ContentModel.ASPECT_GEOGRAPHIC, props); + + return null; + } + }); + + final ObjectData objectData = withCmisService(new CmisServiceCallback() + { + @Override + public ObjectData execute(CmisService cmisService) + { + List repositories = cmisService.getRepositoryInfos(null); + assertTrue(repositories.size() > 0); + RepositoryInfo repo = repositories.get(0); + String repositoryId = repo.getId(); + // get object data + ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + CONTENT, null, true, + IncludeRelationships.NONE, null, false, true, null); + return objectData; + } + }, CmisVersion.CMIS_1_1); + + // get extension data from object properties + List extensions = objectData.getProperties().getExtensions().iterator().next().getChildren(); + + Set appliedAspects = new HashSet(); + Set aspectProperties = new HashSet(); + + for (CmisExtensionElement extension : extensions) + { + if (CMISConnector.PROPERTIES.equals(extension.getName())) + { + // check properties extension + List propExtensions = extension.getChildren(); + assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0); + for (CmisExtensionElement prop : propExtensions) + { + Map cmisAspectProperty = prop.getAttributes(); + Set cmisAspectPropertyNames = cmisAspectProperty.keySet(); + assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId")); + aspectProperties.add(cmisAspectProperty.get("propertyDefinitionId")); + } + } + else if (CMISConnector.APPLIED_ASPECTS.equals(extension.getName())) + { + appliedAspects.add(extension.getValue()); + } + } + + // extension data should contain applied aspects and aspect properties + assertTrue("Extensions should contain " + ContentModel.ASPECT_GEOGRAPHIC, appliedAspects.contains("P:cm:geographic")); + assertTrue("Extensions should contain " + ContentModel.PROP_LATITUDE, aspectProperties.contains("cm:latitude")); + assertTrue("Extensions should contain " + ContentModel.PROP_LONGITUDE, aspectProperties.contains("cm:longitude")); + } + finally + { + AuthenticationUtil.popAuthentication(); + } + } +}