mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
90394: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 90287: Merged DEV to V4.2-BUG-FIX (4.2.4) 89952 : MNT-12242 : Alfresco "autoVersionOnUpdateProps=false" does not work properly when making a CMIS call - Test to ensure auto-versioning on update properties and set/delete content using both Alfresco and CMIS perspectives. Changes according to new auto-versioning behavior git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94672 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -552,6 +552,7 @@
|
|||||||
<value>fm:commentCount</value>
|
<value>fm:commentCount</value>
|
||||||
<!-- MNT-9688 -->
|
<!-- MNT-9688 -->
|
||||||
<value>cm:storeName</value>
|
<value>cm:storeName</value>
|
||||||
|
<value>cm:content</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
<property name="enableAutoVersioning" value="${version.store.enableAutoVersioning}" />
|
<property name="enableAutoVersioning" value="${version.store.enableAutoVersioning}" />
|
||||||
|
@@ -1413,6 +1413,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||||
props.put(ContentModel.PROP_AUTO_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, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1429,6 +1430,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||||
props.put(ContentModel.PROP_AUTO_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, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -432,6 +432,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
// Create the auto-version
|
// Create the auto-version
|
||||||
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
|
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
|
||||||
versionProperties.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_AUTO_VERSION));
|
versionProperties.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_AUTO_VERSION));
|
||||||
|
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
|
||||||
|
|
||||||
createVersionImpl(nodeRef, versionProperties);
|
createVersionImpl(nodeRef, versionProperties);
|
||||||
}
|
}
|
||||||
@@ -463,24 +464,15 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
Map<NodeRef, NodeRef> versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
|
Map<NodeRef, NodeRef> versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
|
||||||
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
|
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
|
||||||
{
|
{
|
||||||
// Determine whether the node is auto versionable (for property only updates) or not
|
|
||||||
boolean autoVersion = false;
|
|
||||||
Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION);
|
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
// If the value is not null then
|
|
||||||
autoVersion = value.booleanValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean autoVersionProps = false;
|
boolean autoVersionProps = false;
|
||||||
value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS);
|
Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS);
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
// If the value is not null then
|
// If the value is not null then
|
||||||
autoVersionProps = value.booleanValue();
|
autoVersionProps = value.booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((autoVersion == true) && (autoVersionProps == true))
|
if (autoVersionProps == true)
|
||||||
{
|
{
|
||||||
// Check for explicitly excluded props - if one or more excluded props changes then do not auto-version on this event (even if other props changed)
|
// Check for explicitly excluded props - if one or more excluded props changes then do not auto-version on this event (even if other props changed)
|
||||||
if (excludedOnUpdatePropQNames.size() > 0)
|
if (excludedOnUpdatePropQNames.size() > 0)
|
||||||
|
@@ -82,7 +82,9 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
|||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||||
|
import org.alfresco.service.cmr.version.Version;
|
||||||
import org.alfresco.service.cmr.version.VersionService;
|
import org.alfresco.service.cmr.version.VersionService;
|
||||||
|
import org.alfresco.service.cmr.version.VersionType;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
@@ -2753,4 +2755,249 @@ public class CMISTest
|
|||||||
|
|
||||||
withCmisService(callback, CmisVersion.CMIS_1_1);
|
withCmisService(callback, CmisVersion.CMIS_1_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to ensure auto version behavior for update properties, set and delete content using both Alfresco and CMIS perspectives.
|
||||||
|
* Testing different combinations of <b>cm:initialVersion</b>, <b>cm:autoVersion</b> and <b>cm:autoVersionOnUpdateProps</b> properties
|
||||||
|
* <br>
|
||||||
|
* OnUpdateProperties MINOR version should be created if <b>cm:initialVersion</b> and <b>cm:autoVersionOnUpdateProps</b> are both TRUE
|
||||||
|
* <br>
|
||||||
|
* OnContentUpdate MINOR version should be created if <b>cm:initialVersion</b> and <b>cm:autoVersion</b> are both TRUE
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUpdatePropertiesSetDeleteContentVersioning() throws Exception
|
||||||
|
{
|
||||||
|
AuthenticationUtil.pushAuthentication();
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
|
||||||
|
final String FOLDER = "testUpdatePropertiesSetDeleteContentVersioning-" + GUID.generate();
|
||||||
|
final String DOC1 = "documentProperties1-" + GUID.generate();
|
||||||
|
final String DOC2 = "documentProperties2-" + GUID.generate();
|
||||||
|
final String DOC3 = "documentProperties3-" + GUID.generate();
|
||||||
|
final String DOC4 = "documentProperties4-" + GUID.generate();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final List<FileInfo> docs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<FileInfo>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public List<FileInfo> 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);
|
||||||
|
|
||||||
|
FileInfo document;
|
||||||
|
List<FileInfo> docs = new ArrayList<FileInfo>();
|
||||||
|
// create documents
|
||||||
|
document = fileFolderService.create(folderInfo.getNodeRef(), DOC1, ContentModel.TYPE_CONTENT);
|
||||||
|
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC1);
|
||||||
|
docs.add(document);
|
||||||
|
document = fileFolderService.create(folderInfo.getNodeRef(), DOC2, ContentModel.TYPE_CONTENT);
|
||||||
|
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC2);
|
||||||
|
docs.add(document);
|
||||||
|
document = fileFolderService.create(folderInfo.getNodeRef(), DOC3, ContentModel.TYPE_CONTENT);
|
||||||
|
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC3);
|
||||||
|
docs.add(document);
|
||||||
|
document = fileFolderService.create(folderInfo.getNodeRef(), DOC4, ContentModel.TYPE_CONTENT);
|
||||||
|
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC4);
|
||||||
|
docs.add(document);
|
||||||
|
|
||||||
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||||
|
props.put(ContentModel.PROP_TITLE, "Initial Title");
|
||||||
|
props.put(ContentModel.PROP_DESCRIPTION, "Initial Description");
|
||||||
|
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
nodeService.addAspect(fileInfo.getNodeRef(), ContentModel.ASPECT_TITLED, props);
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply versionable aspect with properties
|
||||||
|
props = new HashMap<QName, Serializable>();
|
||||||
|
// ContentModel.PROP_INITIAL_VERSION always true
|
||||||
|
props.put(ContentModel.PROP_INITIAL_VERSION, true);
|
||||||
|
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION, false);
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
|
||||||
|
versionService.ensureVersioningEnabled(docs.get(0).getNodeRef(), props);
|
||||||
|
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION, false);
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
|
||||||
|
versionService.ensureVersioningEnabled(docs.get(1).getNodeRef(), props);
|
||||||
|
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION, true);
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
|
||||||
|
versionService.ensureVersioningEnabled(docs.get(2).getNodeRef(), props);
|
||||||
|
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION, true);
|
||||||
|
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
|
||||||
|
versionService.ensureVersioningEnabled(docs.get(3).getNodeRef(), props);
|
||||||
|
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
|
||||||
|
// update node properties using Alfresco
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public List<Void> execute() throws Throwable
|
||||||
|
{
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
Map<QName, Serializable> props = nodeService.getProperties(fileInfo.getNodeRef());
|
||||||
|
|
||||||
|
props.put(ContentModel.PROP_DESCRIPTION, "description-" + GUID.generate());
|
||||||
|
props.put(ContentModel.PROP_TITLE, "title-" + GUID.generate());
|
||||||
|
|
||||||
|
nodeService.setProperties(fileInfo.getNodeRef(), props);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.1", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.1", VersionType.MINOR);
|
||||||
|
|
||||||
|
// update properties using CMIS perspective
|
||||||
|
final String repositoryId = withCmisService(new CmisServiceCallback<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String execute(CmisService cmisService)
|
||||||
|
{
|
||||||
|
String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
|
||||||
|
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
PropertiesImpl properties = new PropertiesImpl();
|
||||||
|
properties.addProperty(new PropertyStringImpl(PropertyIds.DESCRIPTION, "description-" + GUID.generate()));
|
||||||
|
|
||||||
|
cmisService.updateProperties(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), null, properties, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return repositoryId;
|
||||||
|
}
|
||||||
|
}, CmisVersion.CMIS_1_1);
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
|
||||||
|
// CMIS setContentStream
|
||||||
|
withCmisService(new CmisServiceCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute(CmisService cmisService)
|
||||||
|
{
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
ContentStreamImpl contentStream = new ContentStreamImpl(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Content " + GUID.generate());
|
||||||
|
|
||||||
|
cmisService.setContentStream(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), true, null, contentStream, null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, CmisVersion.CMIS_1_1);
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.1", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.3", VersionType.MINOR);
|
||||||
|
|
||||||
|
// update content using Alfresco
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public List<Void> execute() throws Throwable
|
||||||
|
{
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
|
||||||
|
writer.putContent("Content " + GUID.generate());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.4", VersionType.MINOR);
|
||||||
|
|
||||||
|
// CMIS deleteContentStream
|
||||||
|
withCmisService(new CmisServiceCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute(CmisService cmisService)
|
||||||
|
{
|
||||||
|
for (FileInfo fileInfo : docs)
|
||||||
|
{
|
||||||
|
cmisService.deleteContentStream(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), null, null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, CmisVersion.CMIS_1_1);
|
||||||
|
|
||||||
|
assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
|
||||||
|
assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(2).getNodeRef(), "1.3", VersionType.MINOR);
|
||||||
|
assertVersions(docs.get(3).getNodeRef(), "1.5", VersionType.MINOR);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
AuthenticationUtil.popAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertVersions(final NodeRef nodeRef, final String expectedVersionLabel, final VersionType expectedVersionType)
|
||||||
|
{
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public List<Void> execute() throws Throwable
|
||||||
|
{
|
||||||
|
assertTrue("Node should be versionable", nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
Version version = versionService.getCurrentVersion(nodeRef);
|
||||||
|
|
||||||
|
assertNotNull(version);
|
||||||
|
assertEquals(expectedVersionLabel, version.getVersionLabel());
|
||||||
|
assertEquals(expectedVersionType, version.getVersionType());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
withCmisService(new CmisServiceCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute(CmisService cmisService)
|
||||||
|
{
|
||||||
|
String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
|
||||||
|
|
||||||
|
ObjectData data =
|
||||||
|
cmisService.getObjectOfLatestVersion(repositoryId, nodeRef.toString(), null, Boolean.FALSE, null, null, null, null, null, null, null);
|
||||||
|
|
||||||
|
assertNotNull(data);
|
||||||
|
|
||||||
|
PropertyData<?> prop = data.getProperties().getProperties().get(PropertyIds.VERSION_LABEL);
|
||||||
|
Object versionLabelCmisValue = prop.getValues().get(0);
|
||||||
|
|
||||||
|
assertEquals(expectedVersionLabel, versionLabelCmisValue);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, CmisVersion.CMIS_1_1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user