diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index 8f56c4d8d3..d768af1984 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -1466,11 +1466,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen { if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) { - Map props = new HashMap(); - props.put(ContentModel.PROP_INITIAL_VERSION, false); - props.put(ContentModel.PROP_AUTO_VERSION, false); - props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false); - nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, props); + nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null); } Map versionProperties = new HashMap(5); @@ -1483,11 +1479,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen { if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) { - Map props = new HashMap(); - props.put(ContentModel.PROP_INITIAL_VERSION, false); - props.put(ContentModel.PROP_AUTO_VERSION, false); - props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false); - nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, props); + nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null); } Map versionProperties = new HashMap(5); diff --git a/source/test-java/org/alfresco/opencmis/CMISTest.java b/source/test-java/org/alfresco/opencmis/CMISTest.java index 86cc5f0a6c..cf47069535 100644 --- a/source/test-java/org/alfresco/opencmis/CMISTest.java +++ b/source/test-java/org/alfresco/opencmis/CMISTest.java @@ -66,6 +66,9 @@ import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.action.ActionCondition; import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.dictionary.AspectDefinition; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockType; import org.alfresco.service.cmr.model.FileFolderService; @@ -734,7 +737,8 @@ public class CMISTest @Override public Void execute(CmisService cmisService) { - cmisService.setContentStream(repositoryId, objectIdHolder, true, null, contentStreamHTML, null); + Holder latestObjectIdHolder = getHolderOfObjectOfLatestVersion(cmisService, repositoryId, objectIdHolder); + cmisService.setContentStream(repositoryId, latestObjectIdHolder, true, null, contentStreamHTML, null); return null; } }); @@ -818,6 +822,12 @@ public class CMISTest } } + private Holder getHolderOfObjectOfLatestVersion(CmisService cmisService, String repositoryId, Holder currentHolder) + { + ObjectData oData = cmisService.getObjectOfLatestVersion(repositoryId, currentHolder.getValue(), null, Boolean.FALSE, null, null, null, null, null, null, null); + return new Holder(oData.getId()); + } + /** * ALF-20389 Test Alfresco cmis stream interceptor that checks content stream for mimetype. Only ContentStreamImpl extensions should take palace. */ @@ -1498,7 +1508,8 @@ public class CMISTest @Override public Void execute(CmisService cmisService) { - cmisService.updateProperties(repositoryId, objectIdHolder, null, newProperties, null); + Holder latestObjectIdHolder = getHolderOfObjectOfLatestVersion(cmisService, repositoryId, objectIdHolder); + cmisService.updateProperties(repositoryId, latestObjectIdHolder, null, newProperties, null); return null; } }, CmisVersion.CMIS_1_1); @@ -3301,4 +3312,78 @@ public class CMISTest AuthenticationUtil.popAuthentication(); } } + + /** + * Test to ensure that versioning properties have default values defined in Alfresco content model. + * Testing cm:initialVersion, cm:autoVersion and cm:autoVersionOnUpdateProps properties + * + * @throws Exception + */ + @Test + public void testVersioningPropertiesHaveDefaultValue() throws Exception + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + try + { + // Create document via CMIS + final NodeRef documentNodeRef = withCmisService(new CmisServiceCallback() + { + @Override + public NodeRef execute(CmisService cmisService) + { + String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId(); + + String rootNodeId = cmisService.getObjectByPath(repositoryId, "/", null, true, IncludeRelationships.NONE, null, false, true, null).getId(); + + Collection> propsList = new ArrayList>(); + propsList.add(new PropertyStringImpl(CMISDictionaryModel.PROP_NAME, "Folder-" + GUID.generate())); + propsList.add(new PropertyIdImpl(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, "cmis:folder")); + + String folderId = cmisService.createFolder(repositoryId, new PropertiesImpl(propsList), rootNodeId, null, null, null, null); + + propsList = new ArrayList>(); + propsList.add(new PropertyStringImpl(CMISDictionaryModel.PROP_NAME, "File-" + GUID.generate())); + propsList.add(new PropertyIdImpl(CMISDictionaryModel.PROP_OBJECT_TYPE_ID, "cmis:document")); + + String nodeId = cmisService.createDocument(repositoryId, new PropertiesImpl(propsList), folderId, null, null, null, null, null, null); + + return new NodeRef(nodeId.substring(0, nodeId.indexOf(';'))); + } + }, CmisVersion.CMIS_1_1); + + // check versioning properties + transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback>() + { + @Override + public List execute() throws Throwable + { + assertTrue(nodeService.exists(documentNodeRef)); + assertTrue(nodeService.hasAspect(documentNodeRef, ContentModel.ASPECT_VERSIONABLE)); + + AspectDefinition ad = dictionaryService.getAspect(ContentModel.ASPECT_VERSIONABLE); + Map properties = ad.getProperties(); + + for (QName qName : new QName[] {ContentModel.PROP_INITIAL_VERSION, ContentModel.PROP_AUTO_VERSION, ContentModel.PROP_AUTO_VERSION_PROPS}) + { + Serializable property = nodeService.getProperty(documentNodeRef, qName); + + assertNotNull(property); + + PropertyDefinition pd = properties.get(qName); + assertNotNull(pd.getDefaultValue()); + + assertEquals(property, Boolean.parseBoolean(pd.getDefaultValue())); + } + + return null; + } + }); + } + finally + { + AuthenticationUtil.popAuthentication(); + } + } }