From c30ffdcab04175525b3d2c7be9be405aa28e4a52 Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 30 Apr 2014 16:07:02 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 68111: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 65926: MNT-10021: Merged DEV to V4.2-BUG-FIX 58137: MNT-10021: CMIS 1.0 aspect properties only provide propertyDefinitionId - Fields displayName, localName, queryName added into response 61316: MNT-10021: CMIS 1.0 aspect properties only provide propertyDefinitionId - Add unit test for case git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@68399 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/opencmis/CMISConnector.java | 20 +++- .../org/alfresco/opencmis/CMISTest.java | 93 +++++++++++++++++++ 2 files changed, 109 insertions(+), 4 deletions(-) diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index 5807b74e08..e13b760156 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -1946,10 +1946,10 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen * Creates a property extension element. */ @SuppressWarnings("rawtypes") - private CmisExtensionElement createAspectPropertyExtension(PropertyDefinition propertyDefintion, Object value) + private CmisExtensionElement createAspectPropertyExtension(PropertyDefinition propertyDefinition, Object value) { String name; - switch (propertyDefintion.getPropertyType()) + switch (propertyDefinition.getPropertyType()) { case BOOLEAN: name = "propertyBoolean"; @@ -1971,7 +1971,19 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen } Map attributes = new HashMap(); - attributes.put("propertyDefinitionId", propertyDefintion.getId()); + attributes.put("propertyDefinitionId", propertyDefinition.getId()); + attributes.put("queryName", propertyDefinition.getQueryName()); + // optional value + if (propertyDefinition.getDisplayName() !=null && propertyDefinition.getDisplayName().trim().length() > 0) + { + attributes.put("displayName", propertyDefinition.getDisplayName()); + } + // optional value + if (propertyDefinition.getLocalName() !=null && propertyDefinition.getLocalName().trim().length() > 0) + { + attributes.put("localName", propertyDefinition.getLocalName()); + } + List propertyValues = new ArrayList(); if (value != null) @@ -1987,7 +1999,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen } else { - logger.warn("Unexpected null entry in list value for property " + propertyDefintion.getDisplayName() + logger.warn("Unexpected null entry in list value for property " + propertyDefinition.getDisplayName() + ", value = " + value); } } diff --git a/source/test-java/org/alfresco/opencmis/CMISTest.java b/source/test-java/org/alfresco/opencmis/CMISTest.java index 8750a3b50b..bea15f95f1 100644 --- a/source/test-java/org/alfresco/opencmis/CMISTest.java +++ b/source/test-java/org/alfresco/opencmis/CMISTest.java @@ -35,6 +35,7 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.alfresco.cmis.CMISDictionaryModel; import org.alfresco.model.ContentModel; @@ -1922,4 +1923,96 @@ public class CMISTest org.alfresco.opencmis.search.CMISResultSet rs = cmisConnector.getOpenCMISQueryService().query(options); assertEquals(rs.getNumberFound(), 0); } + + /** + * CMIS 1.0 aspect properties should provide the following CMIS attributes: + * propertyDefinitionId, displayName, localName, queryName + */ + @Test + public void testMNT10021() throws Exception + { + final String folderName = "testfolder." + GUID.generate(); + final String docName = "testdoc.txt." + GUID.generate(); + + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + try + { + transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome(); + + FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER); + nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName); + assertNotNull(folderInfo); + + FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT); + assertNotNull(document); + nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName); + + // lock adds aspects to the document with properties: lockIsDeep, lockOwner, lockType, expiryDate, lockLifetime + lockService.lock(document.getNodeRef(), LockType.READ_ONLY_LOCK, 0, true); + + 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(); + ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, + IncludeRelationships.NONE, null, false, true, null); + return objectData; + } + }, CmisVersion.CMIS_1_0); + + List propertyExtensionList = objectData.getProperties().getExtensions(); + assertEquals("propertyExtensionList should be singletonList", propertyExtensionList.size(), 1); + List extensions = propertyExtensionList.iterator().next().getChildren(); + for (CmisExtensionElement extension : extensions) + { + if ("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")); + assertTrue("queryName attribute should be present", cmisAspectPropertyNames.contains("queryName")); + // optional values that are present for test document + assertTrue("displayName attribute should be present for property of test node", cmisAspectPropertyNames.contains("displayName")); + assertTrue("localName attribute should be present for property of test node", cmisAspectPropertyNames.contains("localName")); + assertEquals(cmisAspectPropertyNames.size(), 4); + // check values + for (String aspectPropertyName : cmisAspectPropertyNames) + { + String value = cmisAspectProperty.get(aspectPropertyName); + assertTrue("value for " + aspectPropertyName + " should be present", value != null && value.length() > 0); + } + } + } + } + } + catch (CmisConstraintException e) + { + fail(e.toString()); + } + finally + { + AuthenticationUtil.popAuthentication(); + } + } }