mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-2368 Initial version record does not inherit document type and
aspects from original document
This commit is contained in:
@@ -77,3 +77,10 @@ rm.patch.v22.convertToStandardFilePlan=false
|
||||
# a document will be auto-versioned when its type is changed.
|
||||
#
|
||||
version.store.enableAutoVersionOnTypeChange=false
|
||||
|
||||
#
|
||||
# Enable auto-version to be created when there is a difference between the document and latest record state
|
||||
# to ensure that the created version record matches the current document state,
|
||||
# otherwise create the version record from the version history
|
||||
#
|
||||
rm.enableAutoVersionOnRecordCreation=false
|
||||
|
@@ -19,3 +19,4 @@ rm.service.close-record-folder-not-folder=The record folder couldn't be closed b
|
||||
rm.service.node-has-aspect=The node {0} has already the aspect {1}.
|
||||
rm.service.final-version=Final
|
||||
rm.service.final-version-description=The final archived record version
|
||||
rm.service.enable-autoversion-on-record-creation=Auto Version on Record Creation
|
@@ -21,6 +21,7 @@
|
||||
<!-- extended version service bean definition -->
|
||||
<bean id="rm.versionService" abstract="true" class="org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl">
|
||||
<property name="filePlanService" ref="FilePlanService" />
|
||||
<property name="enableAutoVersionOnRecordCreation" value="${rm.enableAutoVersionOnRecordCreation}" />
|
||||
<property name="authenticationUtil" ref="rm.authenticationUtil" />
|
||||
<property name="relationshipService" ref="RelationshipService" />
|
||||
<property name="recordService" ref="RecordService" />
|
||||
@@ -28,6 +29,7 @@
|
||||
<property name="cmObjectType" ref="cm.object" />
|
||||
<property name="extendedPermissionService" ref="ExtendedPermissionService" />
|
||||
<property name="extendedSecurityService" ref="ExtendedSecurityService" />
|
||||
|
||||
</bean>
|
||||
<bean class="org.alfresco.util.BeanExtender">
|
||||
<property name="beanName" value="versionService" />
|
||||
@@ -77,6 +79,7 @@
|
||||
<value>
|
||||
<![CDATA[
|
||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.isCurrentVersionRecorded=RM_ALLOW
|
||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.isEnableAutoVersionOnRecordCreation=RM_ALLOW
|
||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.isRecordedVersion=RM_ALLOW
|
||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.getVersionRecord=RM_ALLOW
|
||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.getRecordedVersion=RM_ALLOW
|
||||
|
@@ -1038,6 +1038,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
{
|
||||
NodeRef versionRecord = null;
|
||||
|
||||
|
||||
recordableVersionService.createFreezeVersion(nodeRef);
|
||||
// wire record up to previous record
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
|
||||
if (versionHistory != null)
|
||||
|
@@ -48,8 +48,7 @@ public interface RecordableVersionService
|
||||
boolean isRecordedVersion(Version version);
|
||||
|
||||
/**
|
||||
* If the version is a recorded version, gets the related version
|
||||
* record.
|
||||
* If the version is a recorded version, gets the related version record.
|
||||
*
|
||||
* @param version version
|
||||
* @return NodeRef node reference of version record
|
||||
@@ -67,8 +66,7 @@ public interface RecordableVersionService
|
||||
/**
|
||||
* Creates a record from the latest version, marking it as recorded.
|
||||
* <p>
|
||||
* Does not create a record if the node is not versionable or the latest
|
||||
* version is already recorded.
|
||||
* Does not create a record if the node is not versionable or the latest version is already recorded.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @return NodeRef node reference to the created record.
|
||||
@@ -86,11 +84,24 @@ public interface RecordableVersionService
|
||||
/**
|
||||
* Marks a recorded version as destroyed.
|
||||
* <p>
|
||||
* Note this method does not destroy the associated record, instead it marks the
|
||||
* version as destroyed.
|
||||
* Note this method does not destroy the associated record, instead it marks the version as destroyed.
|
||||
*
|
||||
* @param version version
|
||||
*/
|
||||
void destroyRecordedVersion(Version version);
|
||||
|
||||
/**
|
||||
* Flag that indicate to create new version on record creation if current state of node is modified
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEnableAutoVersionOnRecordCreation();
|
||||
|
||||
/**
|
||||
* Create a snapshot - 'freeze' version of current node
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @return version version or null
|
||||
*/
|
||||
Version createFreezeVersion(NodeRef nodeRef);
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import static org.codehaus.plexus.util.StringUtils.isNotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -57,6 +58,7 @@ import org.alfresco.util.PropertyMap;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Recordable version service implementation
|
||||
@@ -79,6 +81,12 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
protected static final String PROP_VERSION_RECORD = "RecordVersion";
|
||||
protected static final String PROP_RECORDED_VERSION_DESTROYED = "RecordedVersionDestroyed";
|
||||
|
||||
/** I18N */
|
||||
private static final String AUTO_VERSION_ON_RECORD_CREATION = "rm.service.enable-autoversion-on-record-creation";
|
||||
|
||||
/** flag that enable auto-version on record creation */
|
||||
private boolean isEnableAutoVersionOnRecordCreation = false;
|
||||
|
||||
/** version aspect property names */
|
||||
private static final String[] VERSION_PROPERTY_NAMES = new String[]
|
||||
{
|
||||
@@ -185,7 +193,21 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.version.Version2ServiceImpl#createVersion(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, int)
|
||||
* @param isEnableAutoVersionOnRecordCreation
|
||||
*/
|
||||
public void setEnableAutoVersionOnRecordCreation(boolean isEnableAutoVersionOnRecordCreation)
|
||||
{
|
||||
this.isEnableAutoVersionOnRecordCreation = isEnableAutoVersionOnRecordCreation;
|
||||
}
|
||||
|
||||
public boolean isEnableAutoVersionOnRecordCreation()
|
||||
{
|
||||
return isEnableAutoVersionOnRecordCreation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.version.Version2ServiceImpl#createVersion(org.alfresco.service.cmr.repository.NodeRef,
|
||||
* java.util.Map, int)
|
||||
*/
|
||||
@Override
|
||||
protected Version createVersion(NodeRef nodeRef, Map<String, Serializable> origVersionProperties, int versionNumber) throws ReservedVersionNameException
|
||||
@@ -545,6 +567,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
@Override
|
||||
protected Version getVersion(NodeRef versionRef)
|
||||
{
|
||||
|
||||
Version version = super.getVersion(versionRef);
|
||||
|
||||
// place the version record reference in the version properties
|
||||
@@ -665,6 +688,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
// check for versionable aspect
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE))
|
||||
{
|
||||
createFreezeVersion(nodeRef);
|
||||
// get the latest version
|
||||
final Version currentVersion = getCurrentVersion(nodeRef);
|
||||
|
||||
@@ -869,4 +893,55 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
{
|
||||
return convertNodeRef(version.getFrozenStateNodeRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current version of the node is modified compared with versioned version
|
||||
*
|
||||
* @param nodeRef internal node reference
|
||||
* @return boolean true if nodeRef is modified, otherwise false
|
||||
*/
|
||||
public boolean isCurrentVersionDirty(NodeRef nodeRef)
|
||||
{
|
||||
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
{
|
||||
// get the latest version
|
||||
Version currentVersion = getCurrentVersion(nodeRef);
|
||||
Date modificationDate = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||
if (currentVersion != null)
|
||||
{
|
||||
// grab the frozen state
|
||||
NodeRef currentFrozenState = currentVersion.getFrozenStateNodeRef();
|
||||
Date frozenModificationDate = (Date) nodeService.getProperty(currentFrozenState, ContentModel.PROP_MODIFIED);
|
||||
if (frozenModificationDate != null)
|
||||
{
|
||||
if (modificationDate.getTime() > frozenModificationDate.getTime()) { return true; }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RecordableVersionService#createFreezeVersion(NodeRef)
|
||||
*/
|
||||
public Version createFreezeVersion(NodeRef nodeRef)
|
||||
{
|
||||
Version newVersion = null;
|
||||
boolean autoVersion = isEnableAutoVersionOnRecordCreation();
|
||||
// if the flag autoversion on record creation set, create new version on dirty nodes
|
||||
if (autoVersion && isCurrentVersionDirty(nodeRef))
|
||||
{
|
||||
Map<String, Serializable> autoVersionProperties = new HashMap<String, Serializable>(2);
|
||||
autoVersionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
|
||||
autoVersionProperties.put(VersionModel.PROP_DESCRIPTION, I18NUtil.getMessage(AUTO_VERSION_ON_RECORD_CREATION));
|
||||
newVersion = createVersion(nodeRef, autoVersionProperties);
|
||||
}
|
||||
return newVersion;
|
||||
}
|
||||
}
|
||||
|
@@ -19,15 +19,18 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl;
|
||||
import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionType;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
@@ -52,9 +55,8 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Given versionable content with a non-recorded latest version
|
||||
* When I declare a version record
|
||||
* Then the latest version is recorded and a record is created
|
||||
* Given versionable content with a non-recorded latest version When I declare a version record Then the latest
|
||||
* version is recorded and a record is created
|
||||
*/
|
||||
public void testDeclareLatestVersionAsRecord()
|
||||
{
|
||||
@@ -99,10 +101,8 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Given versionable content with a recorded latest version
|
||||
* When I declare a version record
|
||||
* Then nothing happens since the latest version is already recorded
|
||||
* And a warning is logged
|
||||
* Given versionable content with a recorded latest version When I declare a version record Then nothing happens
|
||||
* since the latest version is already recorded And a warning is logged
|
||||
*/
|
||||
public void testDeclareLatestVersionAsRecordButAlreadyRecorded()
|
||||
{
|
||||
@@ -148,9 +148,8 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a document is a specialized type
|
||||
* When version is declared as a record
|
||||
* Then the record is the same type as the source document
|
||||
* Given that a document is a specialized type When version is declared as a record Then the record is the same type
|
||||
* as the source document
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2194
|
||||
*/
|
||||
@@ -205,4 +204,145 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2368
|
||||
*/
|
||||
public void testCreateRecordFromLatestVersion()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
private NodeRef versionedRecord;
|
||||
private Map<String, Serializable> versionProperties;
|
||||
private Date createdDate;
|
||||
private Date frozenModifDate;
|
||||
private Date modificationDate;
|
||||
private String record_name = "initial_name";
|
||||
private String AUTO_VERSION_DESCRIPTION = "Auto Version on Record Creation";
|
||||
private boolean autoVersion = false;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
createdDate = (Date) nodeService.getProperty(myDocument, ContentModel.PROP_CREATED);
|
||||
modificationDate = (Date) nodeService.getProperty(myDocument, ContentModel.PROP_MODIFIED);
|
||||
assertTrue("Modified date must be after or on creation date", createdDate.getTime() == modificationDate.getTime());
|
||||
|
||||
// Set initial set of properties
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(3);
|
||||
// Ensure default behaviour autoversion on change properties is set to false
|
||||
properties.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
|
||||
// Set initial name
|
||||
properties.put(ContentModel.PROP_NAME, "initial_name");
|
||||
nodeService.setProperties(myDocument, properties);
|
||||
nodeService.setProperty(myDocument, ContentModel.PROP_DESCRIPTION, DESCRIPTION);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_OWNABLE, null);
|
||||
// make sure document is versionable
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
// Change Type to a custom document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
|
||||
Date modificationDate1 = (Date) nodeService.getProperty(myDocument, ContentModel.PROP_MODIFIED);
|
||||
assertTrue("Frozen modification date", modificationDate.getTime() == modificationDate1.getTime());
|
||||
// setup version properties
|
||||
versionProperties = new HashMap<String, Serializable>(2);
|
||||
versionProperties.put(Version.PROP_DESCRIPTION, DESCRIPTION);
|
||||
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
|
||||
|
||||
// create initial version
|
||||
versionService.createVersion(myDocument, versionProperties);
|
||||
Version version = versionService.getCurrentVersion(myDocument);
|
||||
frozenModifDate = version.getFrozenModifiedDate();
|
||||
|
||||
// get autoversion flag from cofiguratie
|
||||
autoVersion = recordableVersionService.isEnableAutoVersionOnRecordCreation();
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// check1
|
||||
assertTrue("Frozen modification date is the same with initial document ", modificationDate.getTime() == frozenModifDate.getTime());
|
||||
// current node is not dirty
|
||||
assertFalse(isCurrentVersionDirty(myDocument));
|
||||
|
||||
if (autoVersion)
|
||||
{
|
||||
// Apply a custom aspect
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_TITLED, null);
|
||||
// Update properties
|
||||
nodeService.setProperty(myDocument, ContentModel.PROP_NAME, "updated_name");
|
||||
nodeService.setProperty(myDocument, ContentModel.PROP_DESCRIPTION, DESCRIPTION);
|
||||
// node should be modified
|
||||
assertTrue(isCurrentVersionDirty(myDocument));
|
||||
}
|
||||
else
|
||||
{
|
||||
assertFalse(isCurrentVersionDirty(myDocument));
|
||||
}
|
||||
|
||||
assertFalse(recordableVersionService.isCurrentVersionRecorded(myDocument));
|
||||
// test RM-2368
|
||||
versionedRecord = recordableVersionService.createRecordFromLatestVersion(filePlan, myDocument);
|
||||
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// Properties updated / flag as modified
|
||||
// check the created record
|
||||
assertNotNull(versionedRecord);
|
||||
assertTrue(recordService.isRecord(versionedRecord));
|
||||
|
||||
// check the record type is correct
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(versionedRecord));
|
||||
|
||||
// assert the current version is recorded
|
||||
assertTrue(recordableVersionService.isCurrentVersionRecorded(myDocument));
|
||||
|
||||
// get name of record
|
||||
record_name = (String) nodeService.getProperty(versionedRecord, ContentModel.PROP_NAME);
|
||||
|
||||
if (autoVersion)
|
||||
{
|
||||
// new version is create, current node was modified
|
||||
assertTrue("Name was updated:", record_name.contains("updated_name"));
|
||||
// check record
|
||||
checkRecordedVersion(myDocument, AUTO_VERSION_DESCRIPTION, "1.1");
|
||||
}
|
||||
else
|
||||
{
|
||||
// record is created based on existing frozen, which does not contain any modification of node
|
||||
assertTrue("Name is not modified: ", record_name.contains("initial_name"));
|
||||
checkRecordedVersion(myDocument, DESCRIPTION, "1.0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isCurrentVersionDirty(NodeRef nodeRef)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
{
|
||||
// get the latest version
|
||||
Version currentVersion = versionService.getCurrentVersion(nodeRef);
|
||||
Date modificationDate = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||
if (currentVersion != null)
|
||||
{
|
||||
// grab the frozen state
|
||||
NodeRef currentFrozenState = currentVersion.getFrozenStateNodeRef();
|
||||
Date frozenModificationDate = (Date) nodeService.getProperty(currentFrozenState, ContentModel.PROP_MODIFIED);
|
||||
if (modificationDate.getTime() > frozenModificationDate.getTime()) { return true; }
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user