mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'release/V2.5' into merge/MergeV25ToMaster_111016
This commit is contained in:
@@ -86,3 +86,10 @@ rm.patch.v22.convertToStandardFilePlan=false
|
|||||||
# a document will be auto-versioned when its type is changed.
|
# a document will be auto-versioned when its type is changed.
|
||||||
#
|
#
|
||||||
version.store.enableAutoVersionOnTypeChange=false
|
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 record type {1} is already showing for record {0}.
|
rm.service.node-has-aspect=The record type {1} is already showing for record {0}.
|
||||||
rm.service.final-version=Final
|
rm.service.final-version=Final
|
||||||
rm.service.final-version-description=The final archived record version
|
rm.service.final-version-description=The final archived record version
|
||||||
|
rm.service.enable-autoversion-on-record-creation=Auto Version on Record Creation
|
@@ -154,6 +154,7 @@
|
|||||||
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.getLastCompletedDispostionAction=RM.Read.0
|
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.getLastCompletedDispostionAction=RM.Read.0
|
||||||
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.isDisposableItemCutoff=RM.Read.0
|
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.isDisposableItemCutoff=RM.Read.0
|
||||||
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.cutoffDisposableItem=RM.Read.0
|
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.cutoffDisposableItem=RM.Read.0
|
||||||
|
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.calculateAsOfDate=RM_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.*=RM_DENY
|
org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService.*=RM_DENY
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
<!-- extended version service bean definition -->
|
<!-- extended version service bean definition -->
|
||||||
<bean id="rm.versionService" abstract="true" class="org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl">
|
<bean id="rm.versionService" abstract="true" class="org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl">
|
||||||
<property name="filePlanService" ref="FilePlanService" />
|
<property name="filePlanService" ref="FilePlanService" />
|
||||||
|
<property name="enableAutoVersionOnRecordCreation" value="${rm.enableAutoVersionOnRecordCreation}" />
|
||||||
<property name="authenticationUtil" ref="rm.authenticationUtil" />
|
<property name="authenticationUtil" ref="rm.authenticationUtil" />
|
||||||
<property name="relationshipService" ref="RelationshipService" />
|
<property name="relationshipService" ref="RelationshipService" />
|
||||||
<property name="recordService" ref="RecordService" />
|
<property name="recordService" ref="RecordService" />
|
||||||
@@ -77,6 +78,7 @@
|
|||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.isCurrentVersionRecorded=RM_ALLOW
|
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.isRecordedVersion=RM_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.getVersionRecord=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
|
org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService.getRecordedVersion=RM_ALLOW
|
||||||
|
@@ -246,17 +246,11 @@ public class BroadcastDispositionActionDefinitionUpdateAction extends RMActionEx
|
|||||||
* @param dispositionActionDef The disposition action definition node
|
* @param dispositionActionDef The disposition action definition node
|
||||||
* @param nextAction The next disposition action
|
* @param nextAction The next disposition action
|
||||||
*/
|
*/
|
||||||
private void persistPeriodChanges(NodeRef dispositionActionDef, DispositionAction nextAction)
|
protected void persistPeriodChanges(NodeRef dispositionActionDef, DispositionAction nextAction)
|
||||||
{
|
{
|
||||||
Date newAsOfDate = null;
|
NodeRef dispositionedNode = getNodeService().getPrimaryParent(nextAction.getNodeRef()).getParentRef();
|
||||||
Period dispositionPeriod = (Period) getNodeService().getProperty(dispositionActionDef, PROP_DISPOSITION_PERIOD);
|
DispositionActionDefinition definition = nextAction.getDispositionActionDefinition();
|
||||||
|
Date newAsOfDate = getDispositionService().calculateAsOfDate(dispositionedNode, definition, false);
|
||||||
if (dispositionPeriod != null)
|
|
||||||
{
|
|
||||||
// calculate the new as of date as we have been provided a new period
|
|
||||||
Date now = new Date();
|
|
||||||
newAsOfDate = dispositionPeriod.getNextDate(now);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
|
@@ -181,12 +181,12 @@ public class DestroyAction extends RMDispositionActionExecuterAbstractBase
|
|||||||
recordableVersionService.destroyRecordedVersion(version);
|
recordableVersionService.destroyRecordedVersion(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the ghosted aspect
|
|
||||||
getNodeService().addAspect(record, ASPECT_GHOSTED, null);
|
|
||||||
|
|
||||||
// Hide from inplace users to give the impression of destruction
|
// Hide from inplace users to give the impression of destruction
|
||||||
inplaceRecordService.hideRecord(record);
|
inplaceRecordService.hideRecord(record);
|
||||||
|
|
||||||
|
// Add the ghosted aspect
|
||||||
|
getNodeService().addAspect(record, ASPECT_GHOSTED, null);
|
||||||
|
|
||||||
// destroy content
|
// destroy content
|
||||||
contentDestructionComponent.destroyContent(record);
|
contentDestructionComponent.destroyContent(record);
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ package org.alfresco.module.org_alfresco_module_rm.disposition;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -242,4 +243,15 @@ public interface DispositionService
|
|||||||
* @param nodeRef node reference
|
* @param nodeRef node reference
|
||||||
*/
|
*/
|
||||||
void refreshDispositionAction(NodeRef nodeRef);
|
void refreshDispositionAction(NodeRef nodeRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the "disposition as of" date (if necessary) for a disposition action and a node.
|
||||||
|
*
|
||||||
|
* @param nodeRef The node which the schedule applies to.
|
||||||
|
* @param dispositionActionDefinition The definition of the disposition action.
|
||||||
|
* @param allowContextFromAsOf true if the context date is allowed to be obtained from the disposition "as of" property.
|
||||||
|
* @return The new "disposition as of" date.
|
||||||
|
*/
|
||||||
|
Date calculateAsOfDate(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition,
|
||||||
|
boolean allowContextFromAsOf);
|
||||||
}
|
}
|
||||||
|
@@ -62,8 +62,8 @@ import org.alfresco.service.namespace.NamespaceService;
|
|||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.apache.commons.logging.Log;
|
import org.slf4j.Logger;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposition service implementation.
|
* Disposition service implementation.
|
||||||
@@ -77,7 +77,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
RecordsManagementPolicies.OnFileRecord
|
RecordsManagementPolicies.OnFileRecord
|
||||||
{
|
{
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static Log logger = LogFactory.getLog(DispositionServiceImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DispositionServiceImpl.class);
|
||||||
|
|
||||||
/** Behaviour filter */
|
/** Behaviour filter */
|
||||||
private BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
@@ -226,7 +226,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
DispositionActionDefinition nextDispositionActionDefinition = dispositionActionDefinitions.get(0);
|
DispositionActionDefinition nextDispositionActionDefinition = dispositionActionDefinitions.get(0);
|
||||||
|
|
||||||
// initialise the details of the next disposition action
|
// initialise the details of the next disposition action
|
||||||
initialiseDispositionAction(nodeRef, nextDispositionActionDefinition);
|
initialiseDispositionAction(nodeRef, nextDispositionActionDefinition, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,9 +396,9 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
{
|
{
|
||||||
// TODO in the future we should be able to support disposition schedule reuse, but for now just warn that
|
// TODO in the future we should be able to support disposition schedule reuse, but for now just warn that
|
||||||
// only the first disposition schedule will be considered
|
// only the first disposition schedule will be considered
|
||||||
if (logger.isWarnEnabled())
|
if (LOGGER.isWarnEnabled())
|
||||||
{
|
{
|
||||||
logger.warn("Retention schedule has more than one associated records management container. " +
|
LOGGER.warn("Retention schedule has more than one associated records management container. " +
|
||||||
"This is not currently supported so only the first container will be considered. " +
|
"This is not currently supported so only the first container will be considered. " +
|
||||||
"(dispositionScheduleNodeRef=" + dispositionSchedule.getNodeRef().toString() + ")");
|
"(dispositionScheduleNodeRef=" + dispositionSchedule.getNodeRef().toString() + ")");
|
||||||
}
|
}
|
||||||
@@ -629,40 +629,14 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
*
|
*
|
||||||
* @param nodeRef node reference
|
* @param nodeRef node reference
|
||||||
* @param dispositionActionDefinition disposition action definition
|
* @param dispositionActionDefinition disposition action definition
|
||||||
|
* @param allowContextFromAsOf true if the context date is allowed to be obtained from the disposition "as of" property.
|
||||||
*/
|
*/
|
||||||
private void initialiseDispositionAction(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition)
|
private void initialiseDispositionAction(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition, boolean allowContextFromAsOf)
|
||||||
{
|
{
|
||||||
// Create the properties
|
// Create the properties
|
||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(10);
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>(10);
|
||||||
|
|
||||||
// Calculate the asOf date
|
Date asOfDate = calculateAsOfDate(nodeRef, dispositionActionDefinition, allowContextFromAsOf);
|
||||||
Date asOfDate = null;
|
|
||||||
Period period = dispositionActionDefinition.getPeriod();
|
|
||||||
if (period != null)
|
|
||||||
{
|
|
||||||
Date contextDate = null;
|
|
||||||
|
|
||||||
// Get the period properties value
|
|
||||||
QName periodProperty = dispositionActionDefinition.getPeriodProperty();
|
|
||||||
if (periodProperty != null)
|
|
||||||
{
|
|
||||||
// doesn't matter if the period property isn't set ... the asOfDate will get updated later
|
|
||||||
// when the value of the period property is set
|
|
||||||
contextDate = (Date)this.nodeService.getProperty(nodeRef, periodProperty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// for now use 'NOW' as the default context date
|
|
||||||
// TODO set the default period property ... cut off date or last disposition date depending on context
|
|
||||||
contextDate = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the as of date
|
|
||||||
if (contextDate != null)
|
|
||||||
{
|
|
||||||
asOfDate = period.getNextDate(contextDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the property values
|
// Set the property values
|
||||||
props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId());
|
props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId());
|
||||||
@@ -690,6 +664,50 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the "disposition as of" date (if necessary) for a disposition action and a node.
|
||||||
|
*
|
||||||
|
* @param nodeRef The node which the schedule applies to.
|
||||||
|
* @param dispositionActionDefinition The definition of the disposition action.
|
||||||
|
* @param allowContextFromAsOf true if the context date is allowed to be obtained from the disposition "as of" property.
|
||||||
|
* @return The new "disposition as of" date.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Date calculateAsOfDate(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition,
|
||||||
|
boolean allowContextFromAsOf)
|
||||||
|
{
|
||||||
|
// Calculate the asOf date
|
||||||
|
Date asOfDate = null;
|
||||||
|
Period period = dispositionActionDefinition.getPeriod();
|
||||||
|
if (period != null)
|
||||||
|
{
|
||||||
|
Date contextDate = null;
|
||||||
|
|
||||||
|
// Get the period properties value
|
||||||
|
QName periodProperty = dispositionActionDefinition.getPeriodProperty();
|
||||||
|
if (periodProperty != null && (allowContextFromAsOf
|
||||||
|
|| !RecordsManagementModel.PROP_DISPOSITION_AS_OF.equals(periodProperty)))
|
||||||
|
{
|
||||||
|
// doesn't matter if the period property isn't set ... the asOfDate will get updated later
|
||||||
|
// when the value of the period property is set
|
||||||
|
contextDate = (Date)this.nodeService.getProperty(nodeRef, periodProperty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// for now use 'NOW' as the default context date
|
||||||
|
// TODO set the default period property ... cut off date or last disposition date depending on context
|
||||||
|
contextDate = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the as of date
|
||||||
|
if (contextDate != null)
|
||||||
|
{
|
||||||
|
asOfDate = period.getNextDate(contextDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return asOfDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#isNextDispositionActionEligible(org.alfresco.service.cmr.repository.NodeRef)
|
* @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#isNextDispositionActionEligible(org.alfresco.service.cmr.repository.NodeRef)
|
||||||
*/
|
*/
|
||||||
@@ -914,63 +932,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
nodeService.addAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE, null);
|
nodeService.addAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the properties
|
initialiseDispositionAction(nodeRef, nextDispositionActionDefinition, false);
|
||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(10);
|
|
||||||
|
|
||||||
// Calculate the asOf date
|
|
||||||
Date asOfDate = null;
|
|
||||||
Period period = nextDispositionActionDefinition.getPeriod();
|
|
||||||
if (period != null)
|
|
||||||
{
|
|
||||||
Date contextDate = null;
|
|
||||||
|
|
||||||
// Get the period properties value
|
|
||||||
QName periodProperty = nextDispositionActionDefinition.getPeriodProperty();
|
|
||||||
if (periodProperty != null &&
|
|
||||||
!RecordsManagementModel.PROP_DISPOSITION_AS_OF.equals(periodProperty))
|
|
||||||
{
|
|
||||||
// doesn't matter if the period property isn't set ... the asOfDate will get updated later
|
|
||||||
// when the value of the period property is set
|
|
||||||
contextDate = (Date) nodeService.getProperty(nodeRef, periodProperty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// for now use 'NOW' as the default context date
|
|
||||||
// TODO set the default period property ... cut off date or last disposition date depending on context
|
|
||||||
contextDate = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the as of date
|
|
||||||
if (contextDate != null)
|
|
||||||
{
|
|
||||||
asOfDate = period.getNextDate(contextDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the property values
|
|
||||||
props.put(PROP_DISPOSITION_ACTION_ID, nextDispositionActionDefinition.getId());
|
|
||||||
props.put(PROP_DISPOSITION_ACTION, nextDispositionActionDefinition.getName());
|
|
||||||
if (asOfDate != null)
|
|
||||||
{
|
|
||||||
props.put(PROP_DISPOSITION_AS_OF, asOfDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new disposition action object
|
|
||||||
NodeRef dispositionActionNodeRef = nodeService.createNode(
|
|
||||||
nodeRef,
|
|
||||||
ASSOC_NEXT_DISPOSITION_ACTION,
|
|
||||||
ASSOC_NEXT_DISPOSITION_ACTION,
|
|
||||||
TYPE_DISPOSITION_ACTION,
|
|
||||||
props).getChildRef();
|
|
||||||
DispositionAction da = new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef);
|
|
||||||
|
|
||||||
// Create the events
|
|
||||||
List<RecordsManagementEvent> events = nextDispositionActionDefinition.getEvents();
|
|
||||||
for (RecordsManagementEvent event : events)
|
|
||||||
{
|
|
||||||
// For every event create an entry on the action
|
|
||||||
da.addEventCompletionDetails(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1059,6 +1059,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
{
|
{
|
||||||
NodeRef versionRecord = null;
|
NodeRef versionRecord = null;
|
||||||
|
|
||||||
|
|
||||||
|
recordableVersionService.createSnapshotVersion(nodeRef);
|
||||||
// wire record up to previous record
|
// wire record up to previous record
|
||||||
VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
|
VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
|
||||||
if (versionHistory != null)
|
if (versionHistory != null)
|
||||||
|
@@ -59,8 +59,7 @@ public interface RecordableVersionService
|
|||||||
boolean isRecordedVersion(Version version);
|
boolean isRecordedVersion(Version version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the version is a recorded version, gets the related version
|
* If the version is a recorded version, gets the related version record.
|
||||||
* record.
|
|
||||||
*
|
*
|
||||||
* @param version version
|
* @param version version
|
||||||
* @return NodeRef node reference of version record
|
* @return NodeRef node reference of version record
|
||||||
@@ -76,16 +75,27 @@ public interface RecordableVersionService
|
|||||||
Version getRecordedVersion(NodeRef record);
|
Version getRecordedVersion(NodeRef record);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a record from the latest version, marking it as recorded.
|
* Creates a record from the latest frozen version, marking it as recorded.
|
||||||
* <p>
|
* <p>
|
||||||
* Does not create a record if the node is not versionable or the latest
|
* Does not create a record if the node is not versionable or the latest version is already recorded.
|
||||||
* version is already recorded.
|
|
||||||
*
|
*
|
||||||
* @param nodeRef node reference
|
* @param nodeRef node reference
|
||||||
* @return NodeRef node reference to the created record.
|
* @return NodeRef node reference to the created record.
|
||||||
*/
|
*/
|
||||||
NodeRef createRecordFromLatestVersion(NodeRef filePlan, NodeRef nodeRef);
|
NodeRef createRecordFromLatestVersion(NodeRef filePlan, NodeRef nodeRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param nodeRef parent node reference
|
||||||
|
* @param nodeRef node reference
|
||||||
|
* @param autoVersion true, create new record version from latest version, false creates a record from the latest frozen version
|
||||||
|
* @return NodeRef node reference to the created record.
|
||||||
|
*/
|
||||||
|
NodeRef createRecordFromLatestVersion(NodeRef filePlan, NodeRef nodeRef, boolean autoVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether a record version is destroyed or not.
|
* Indicates whether a record version is destroyed or not.
|
||||||
*
|
*
|
||||||
@@ -97,11 +107,23 @@ public interface RecordableVersionService
|
|||||||
/**
|
/**
|
||||||
* Marks a recorded version as destroyed.
|
* Marks a recorded version as destroyed.
|
||||||
* <p>
|
* <p>
|
||||||
* Note this method does not destroy the associated record, instead it marks the
|
* Note this method does not destroy the associated record, instead it marks the version as destroyed.
|
||||||
* version as destroyed.
|
|
||||||
*
|
*
|
||||||
* @param version version
|
* @param version version
|
||||||
*/
|
*/
|
||||||
void destroyRecordedVersion(Version version);
|
void destroyRecordedVersion(Version version);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that indicate to create new version on record creation if current node is modified
|
||||||
|
*
|
||||||
|
* @return boolean true to auto-version on record creation, false to use latest versioned version
|
||||||
|
*/
|
||||||
|
boolean isEnableAutoVersionOnRecordCreation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a snapshot version of current node
|
||||||
|
*
|
||||||
|
* @param nodeRef node reference
|
||||||
|
*/
|
||||||
|
void createSnapshotVersion(NodeRef nodeRef);
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ import static org.codehaus.plexus.util.StringUtils.isNotBlank;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -66,6 +67,7 @@ import org.alfresco.util.PropertyMap;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recordable version service implementation
|
* Recordable version service implementation
|
||||||
@@ -88,6 +90,12 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
|||||||
protected static final String PROP_VERSION_RECORD = "RecordVersion";
|
protected static final String PROP_VERSION_RECORD = "RecordVersion";
|
||||||
protected static final String PROP_RECORDED_VERSION_DESTROYED = "RecordedVersionDestroyed";
|
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 */
|
/** version aspect property names */
|
||||||
private static final String[] VERSION_PROPERTY_NAMES = new String[]
|
private static final String[] VERSION_PROPERTY_NAMES = new String[]
|
||||||
{
|
{
|
||||||
@@ -194,7 +202,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
|
@Override
|
||||||
protected Version createVersion(NodeRef nodeRef, Map<String, Serializable> origVersionProperties, int versionNumber) throws ReservedVersionNameException
|
protected Version createVersion(NodeRef nodeRef, Map<String, Serializable> origVersionProperties, int versionNumber) throws ReservedVersionNameException
|
||||||
@@ -563,6 +585,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
|||||||
@Override
|
@Override
|
||||||
protected Version getVersion(NodeRef versionRef)
|
protected Version getVersion(NodeRef versionRef)
|
||||||
{
|
{
|
||||||
|
|
||||||
Version version = super.getVersion(versionRef);
|
Version version = super.getVersion(versionRef);
|
||||||
|
|
||||||
// place the version record reference in the version properties
|
// place the version record reference in the version properties
|
||||||
@@ -669,6 +692,17 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
|||||||
return new NodeRef(convertStoreRef(nodeRef.getStoreRef()), nodeRef.getId());
|
return new NodeRef(convertStoreRef(nodeRef.getStoreRef()), nodeRef.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#createRecordFromLatestVersion(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, autoVersion)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NodeRef createRecordFromLatestVersion(final NodeRef filePlan, final NodeRef nodeRef, final boolean isEnableAutoVersionOnRecordCreation)
|
||||||
|
{
|
||||||
|
setEnableAutoVersionOnRecordCreation(isEnableAutoVersionOnRecordCreation);
|
||||||
|
|
||||||
|
return createRecordFromLatestVersion(filePlan, nodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#createRecordFromLatestVersion(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
* @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#createRecordFromLatestVersion(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
*/
|
*/
|
||||||
@@ -683,6 +717,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
|||||||
// check for versionable aspect
|
// check for versionable aspect
|
||||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE))
|
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE))
|
||||||
{
|
{
|
||||||
|
createSnapshotVersion(nodeRef);
|
||||||
// get the latest version
|
// get the latest version
|
||||||
final Version currentVersion = getCurrentVersion(nodeRef);
|
final Version currentVersion = getCurrentVersion(nodeRef);
|
||||||
|
|
||||||
@@ -888,4 +923,45 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
|||||||
{
|
{
|
||||||
return convertNodeRef(version.getFrozenStateNodeRef());
|
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)) { return false; }
|
||||||
|
|
||||||
|
// get the latest version
|
||||||
|
Version currentVersion = getCurrentVersion(nodeRef);
|
||||||
|
Date modificationDate = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||||
|
|
||||||
|
if (currentVersion == null) { return true; }
|
||||||
|
|
||||||
|
// grab the frozen state
|
||||||
|
NodeRef currentFrozenState = currentVersion.getFrozenStateNodeRef();
|
||||||
|
Date frozenModificationDate = (Date) nodeService.getProperty(currentFrozenState, ContentModel.PROP_MODIFIED);
|
||||||
|
|
||||||
|
boolean versionStoreOutdated = ((frozenModificationDate != null) && (modificationDate.getTime() > frozenModificationDate.getTime()));
|
||||||
|
return versionStoreOutdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RecordableVersionService#createSnapshotVersion(NodeRef)
|
||||||
|
*/
|
||||||
|
public void createSnapshotVersion(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
createVersion(nodeRef, autoVersionProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.test.integration.disposition;
|
||||||
|
|
||||||
|
import static org.alfresco.module.org_alfresco_module_rm.test.util.bdt.BehaviourTest.test;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.job.publish.DispositionActionDefinitionPublishExecutor;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.bdt.BehaviourTest;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
import org.springframework.extensions.webscripts.GUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests for updating the disposition schedule.
|
||||||
|
*
|
||||||
|
* @author Tom Page
|
||||||
|
* @since 2.3.1
|
||||||
|
*/
|
||||||
|
public class UpdateDispositionScheduleTest extends BaseRMTestCase
|
||||||
|
{
|
||||||
|
/** A unique prefix for the constants in this test. */
|
||||||
|
protected static final String TEST_PREFIX = UpdateDispositionScheduleTest.class.getName() + GUID.generate() + "_";
|
||||||
|
/** The name to use for the category. */
|
||||||
|
protected static final String CATEGORY_NAME = TEST_PREFIX + "Category";
|
||||||
|
/** The name to use for the folder. */
|
||||||
|
protected static final String FOLDER_NAME = TEST_PREFIX + "Folder";
|
||||||
|
/** The name to use for the record. */
|
||||||
|
protected static final String RECORD_NAME = TEST_PREFIX + "Record";
|
||||||
|
|
||||||
|
/** The executor for the disposition update job. */
|
||||||
|
private DispositionActionDefinitionPublishExecutor dispositionActionDefinitionPublishExecutor;
|
||||||
|
/** The internal disposition service is used to avoid permissions issues when updating the record. */
|
||||||
|
private DispositionService internalDispositionService;
|
||||||
|
|
||||||
|
/** The category node. */
|
||||||
|
private NodeRef category;
|
||||||
|
/** The folder node. */
|
||||||
|
private NodeRef folder;
|
||||||
|
/** The record node. */
|
||||||
|
private NodeRef record;
|
||||||
|
/** The 'disposition as of' date from before the 'when' step. */
|
||||||
|
private Date originalAsOfDate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
BehaviourTest.initBehaviourTests(retryingTransactionHelper);
|
||||||
|
|
||||||
|
// Get the application context
|
||||||
|
applicationContext = ApplicationContextHelper.getApplicationContext(getConfigLocations());
|
||||||
|
dispositionActionDefinitionPublishExecutor = applicationContext.getBean(DispositionActionDefinitionPublishExecutor.class);
|
||||||
|
internalDispositionService = (DispositionService) applicationContext.getBean("dispositionService");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <a href="https://issues.alfresco.com/jira/browse/RM-3386">RM-3386</a>
|
||||||
|
* <p><pre>
|
||||||
|
* Given a record subject to a disposition schedule
|
||||||
|
* And the next step is due to run at some period after the date the content was created
|
||||||
|
* When I update the period of the next step (and wait for this to be processed)
|
||||||
|
* Then the "as of" date is updated to be at the new period after the creation date.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void testUpdatePeriod()
|
||||||
|
{
|
||||||
|
test()
|
||||||
|
.given(() -> {
|
||||||
|
// Create a category.
|
||||||
|
category = filePlanService.createRecordCategory(filePlan, CATEGORY_NAME);
|
||||||
|
// Create a disposition schedule for the category (Cut off immediately, then Destroy 1 year after the creation date).
|
||||||
|
DispositionSchedule dispSched = utils.createBasicDispositionSchedule(category, "instructions", "authority", true, false);
|
||||||
|
Map<QName, Serializable> cutOffParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY);
|
||||||
|
dispositionService.addDispositionActionDefinition(dispSched, cutOffParams);
|
||||||
|
Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_ONE_YEAR,
|
||||||
|
PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
|
||||||
|
dispositionService.addDispositionActionDefinition(dispSched, destroyParams);
|
||||||
|
// Create a folder containing a record within the category.
|
||||||
|
folder = recordFolderService.createRecordFolder(category, FOLDER_NAME);
|
||||||
|
record = fileFolderService.create(folder, RECORD_NAME, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||||
|
|
||||||
|
dispositionService.cutoffDisposableItem(record);
|
||||||
|
// Ensure the update has been applied to the record.
|
||||||
|
internalDispositionService.updateNextDispositionAction(record);
|
||||||
|
|
||||||
|
originalAsOfDate = dispositionService.getNextDispositionAction(record).getAsOfDate();
|
||||||
|
})
|
||||||
|
.when(() -> {
|
||||||
|
// Update the Destroy step to be 3 years after the creation date.
|
||||||
|
DispositionSchedule dispSched = dispositionService.getDispositionSchedule(category);
|
||||||
|
DispositionActionDefinition destroy = dispSched.getDispositionActionDefinitionByName(DestroyAction.NAME);
|
||||||
|
Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_THREE_YEARS,
|
||||||
|
PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
|
||||||
|
dispositionService.updateDispositionActionDefinition(destroy, destroyParams);
|
||||||
|
|
||||||
|
// Make the disposition action definition update job run.
|
||||||
|
dispositionActionDefinitionPublishExecutor.publish(destroy.getNodeRef());
|
||||||
|
})
|
||||||
|
.then()
|
||||||
|
.expect(true)
|
||||||
|
.from(() -> aboutTwoYearsApart(originalAsOfDate, dispositionService.getNextDispositionAction(record).getAsOfDate()))
|
||||||
|
.because("Increasing the destroy period by two years should increase the 'as of' date by two years.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the two given dates are approximately two years apart.
|
||||||
|
* <p>
|
||||||
|
* This actually just checks that they're more than one and less than three years apart, because leap years make
|
||||||
|
* things hard to calculate.
|
||||||
|
*
|
||||||
|
* @return true if the two dates are about two years apart.
|
||||||
|
*/
|
||||||
|
private boolean aboutTwoYearsApart(Date start, Date end)
|
||||||
|
{
|
||||||
|
long days = daysBetween(start, end);
|
||||||
|
long yearInDays = 365;
|
||||||
|
return (yearInDays < days) && (days < 3 * yearInDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Find the number of days between the two dates. */
|
||||||
|
private long daysBetween(Date start, Date end)
|
||||||
|
{
|
||||||
|
return TimeUnit.MILLISECONDS.toDays(end.getTime() - start.getTime());
|
||||||
|
}
|
||||||
|
}
|
@@ -28,15 +28,18 @@
|
|||||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.RecordableVersionService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl;
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl;
|
||||||
import org.alfresco.repo.version.VersionModel;
|
import org.alfresco.repo.version.VersionModel;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.version.Version;
|
import org.alfresco.service.cmr.version.Version;
|
||||||
import org.alfresco.service.cmr.version.VersionType;
|
import org.alfresco.service.cmr.version.VersionType;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,4 +217,184 @@ public class DeclareAsRecordVersionTest extends RecordableVersionsBaseTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given versionable content with a recorded latest version and autoversion is true
|
||||||
|
* When I declare this version record and contains local modifications
|
||||||
|
* Then a new minor version is created for document
|
||||||
|
*
|
||||||
|
* @see https://issues.alfresco.com/jira/browse/RM-2368
|
||||||
|
*/
|
||||||
|
public void testCreateRecordFromLatestVersionAutoTrue()
|
||||||
|
{
|
||||||
|
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||||
|
{
|
||||||
|
private NodeRef myDocument;
|
||||||
|
private NodeRef versionedRecord;
|
||||||
|
private Map<String, Serializable> versionProperties;
|
||||||
|
private Date createdDate;
|
||||||
|
private Date modificationDate;
|
||||||
|
private String record_name = "initial_name";
|
||||||
|
private String AUTO_VERSION_DESCRIPTION = "Auto Version on Record Creation";
|
||||||
|
private boolean autoVersion = true;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void when()
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
// test RM-2368
|
||||||
|
versionedRecord = recordableVersionService.createRecordFromLatestVersion(filePlan, myDocument, autoVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Given versionable content with a recorded latest version and autoversion is false
|
||||||
|
* When I declare this version record and contains local modifications
|
||||||
|
* Then a record is created from latest version
|
||||||
|
*
|
||||||
|
* @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 modificationDate;
|
||||||
|
private String record_name = "initial_name";
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void when()
|
||||||
|
{
|
||||||
|
// Apply a custom aspect
|
||||||
|
nodeService.addAspect(myDocument, ContentModel.ASPECT_TITLED, null);
|
||||||
|
// Update properties
|
||||||
|
nodeService.setProperty(myDocument, ContentModel.PROP_NAME, "initial_name");
|
||||||
|
nodeService.setProperty(myDocument, ContentModel.PROP_DESCRIPTION, DESCRIPTION);
|
||||||
|
// test RM-2368
|
||||||
|
versionedRecord = recordableVersionService.createRecordFromLatestVersion(filePlan, myDocument, autoVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -87,6 +87,8 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
public static final String PERIOD_NONE = "none|0";
|
public static final String PERIOD_NONE = "none|0";
|
||||||
public static final String PERIOD_IMMEDIATELY = "immediately|0";
|
public static final String PERIOD_IMMEDIATELY = "immediately|0";
|
||||||
public static final String PERIOD_ONE_WEEK = "week|1";
|
public static final String PERIOD_ONE_WEEK = "week|1";
|
||||||
|
public static final String PERIOD_ONE_YEAR = "year|1";
|
||||||
|
public static final String PERIOD_THREE_YEARS = "year|3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.action.impl;
|
||||||
|
|
||||||
|
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_DISPOSITION_AS_OF;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for {@link BroadcastDispositionActionDefinitionUpdateAction}.
|
||||||
|
*
|
||||||
|
* @author Tom Page
|
||||||
|
* @since 2.3.1
|
||||||
|
*/
|
||||||
|
public class BroadcastDispositionActionDefinitionUpdateActionUnitTest
|
||||||
|
{
|
||||||
|
/** The node under the category containing information about the definition of the action. */
|
||||||
|
private static final NodeRef DISPOSITION_ACTION_DEF_NODE = new NodeRef("disposition://Action/Def");
|
||||||
|
/** The node containing the details of the next disposition step for the content. */
|
||||||
|
private static final NodeRef NEXT_ACTION_NODE_REF = new NodeRef("next://Step/");
|
||||||
|
/** The node being subject to the disposition step. */
|
||||||
|
private static final NodeRef CONTENT_NODE_REF = new NodeRef("content://Node/Ref");
|
||||||
|
|
||||||
|
/** The class under test. */
|
||||||
|
private BroadcastDispositionActionDefinitionUpdateAction action = new BroadcastDispositionActionDefinitionUpdateAction();
|
||||||
|
|
||||||
|
private NodeService mockNodeService = mock(NodeService.class);
|
||||||
|
private DispositionService mockDispositionService = mock(DispositionService.class);
|
||||||
|
|
||||||
|
/** Inject the mock services into the class under test and link the content and next action nodes. */
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
action.setNodeService(mockNodeService);
|
||||||
|
action.setDispositionService(mockDispositionService);
|
||||||
|
|
||||||
|
ChildAssociationRef mockAssocRef = mock(ChildAssociationRef.class);
|
||||||
|
when(mockNodeService.getPrimaryParent(NEXT_ACTION_NODE_REF)).thenReturn(mockAssocRef);
|
||||||
|
when(mockAssocRef.getParentRef()).thenReturn(CONTENT_NODE_REF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the disposition service is used to determine the "disposition as of" date when changes are made to the
|
||||||
|
* disposition period.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPersistPeriodChanges()
|
||||||
|
{
|
||||||
|
// Set up the data associated with the next disposition action.
|
||||||
|
DispositionAction mockAction = mock(DispositionAction.class);
|
||||||
|
when(mockAction.getNodeRef()).thenReturn(NEXT_ACTION_NODE_REF);
|
||||||
|
DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class);
|
||||||
|
when(mockAction.getDispositionActionDefinition()).thenReturn(mockDispositionActionDefinition);
|
||||||
|
when(mockAction.getName()).thenReturn("mockAction");
|
||||||
|
// Set up the disposition service to return a known "disposition as of" date.
|
||||||
|
Date asOfDate = new Date();
|
||||||
|
when(mockDispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, false))
|
||||||
|
.thenReturn(asOfDate);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
action.persistPeriodChanges(DISPOSITION_ACTION_DEF_NODE, mockAction);
|
||||||
|
|
||||||
|
// Check that the "disposition as of" date has been set on the next action.
|
||||||
|
verify(mockNodeService).setProperty(NEXT_ACTION_NODE_REF, PROP_DISPOSITION_AS_OF, asOfDate);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.disposition;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.Period;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for {@link DispositionServiceImpl}.
|
||||||
|
*
|
||||||
|
* @author Tom Page
|
||||||
|
* @since 2.3.1
|
||||||
|
*/
|
||||||
|
public class DispositionServiceImplUnitTest
|
||||||
|
{
|
||||||
|
/** The node being subject to the disposition step. */
|
||||||
|
NodeRef CONTENT_NODE_REF = new NodeRef("content://node/");
|
||||||
|
|
||||||
|
/** The class under test. */
|
||||||
|
private DispositionServiceImpl dispositionService = new DispositionServiceImpl();
|
||||||
|
|
||||||
|
private NodeService mockNodeService = mock(NodeService.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
dispositionService.setNodeService(mockNodeService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the relevant information is retrieved from the DispositionActionDefinition in order to determine the
|
||||||
|
* "disposition as of" date.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCalculateAsOfDate()
|
||||||
|
{
|
||||||
|
// Set up a mock for the disposition action definition.
|
||||||
|
DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class);
|
||||||
|
Period mockPeriod = mock(Period.class);
|
||||||
|
when(mockDispositionActionDefinition.getPeriod()).thenReturn(mockPeriod);
|
||||||
|
when(mockDispositionActionDefinition.getPeriodProperty()).thenReturn(ContentModel.PROP_CREATED);
|
||||||
|
// Set up a created date and another date that is some Period later.
|
||||||
|
Date createdDate = new Date(1234567890);
|
||||||
|
when(mockNodeService.getProperty(CONTENT_NODE_REF, ContentModel.PROP_CREATED)).thenReturn(createdDate);
|
||||||
|
Date nextDate = new Date(1240000000);
|
||||||
|
when(mockPeriod.getNextDate(createdDate)).thenReturn(nextDate);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
Date asOfDate = dispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, true);
|
||||||
|
|
||||||
|
assertEquals("Unexpected calculation for 'as of' date", nextDate, asOfDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check that the calculated "disposition as of" date is null if a null period is given. */
|
||||||
|
@Test
|
||||||
|
public void testCalculateAsOfDate_nullPeriod()
|
||||||
|
{
|
||||||
|
DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class);
|
||||||
|
when(mockDispositionActionDefinition.getPeriod()).thenReturn(null);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
Date asOfDate = dispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, true);
|
||||||
|
|
||||||
|
assertNull("It should not be possible to determine the 'as of' date.", asOfDate);
|
||||||
|
}
|
||||||
|
}
|
@@ -24,24 +24,6 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
|
||||||
*
|
|
||||||
* This file is part of Alfresco
|
|
||||||
*
|
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.alfresco.repo.web.scripts.roles;
|
package org.alfresco.repo.web.scripts.roles;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user