RM-3386 Centralise the logic for recalculating "disposition as of" dates.

This commit is contained in:
Tom Page
2016-10-04 12:52:34 +01:00
parent 726c2284b8
commit 70eb0cb399
4 changed files with 57 additions and 34 deletions

View File

@@ -239,15 +239,9 @@ public class BroadcastDispositionActionDefinitionUpdateAction extends RMActionEx
*/
private void persistPeriodChanges(NodeRef dispositionActionDef, DispositionAction nextAction)
{
Date newAsOfDate = null;
Period dispositionPeriod = (Period) getNodeService().getProperty(dispositionActionDef, PROP_DISPOSITION_PERIOD);
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);
}
NodeRef dispositionedNode = getNodeService().getPrimaryParent(nextAction.getNodeRef()).getParentRef();
DispositionActionDefinition definition = nextAction.getDispositionActionDefinition();
Date newAsOfDate = getDispositionService().calculateAsOfDate(dispositionedNode, definition, false);
if (logger.isDebugEnabled())
{

View File

@@ -20,6 +20,7 @@ package org.alfresco.module.org_alfresco_module_rm.disposition;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -232,4 +233,15 @@ public interface DispositionService
* @param nodeRef node reference
*/
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);
}

View File

@@ -625,6 +625,46 @@ public class DispositionServiceImpl extends ServiceBaseImpl
// Create the properties
Map<QName, Serializable> props = new HashMap<QName, Serializable>(10);
Date asOfDate = calculateAsOfDate(nodeRef, dispositionActionDefinition, allowContextFromAsOf);
// Set the property values
props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId());
props.put(PROP_DISPOSITION_ACTION, dispositionActionDefinition.getName());
if (asOfDate != null)
{
props.put(PROP_DISPOSITION_AS_OF, asOfDate);
}
// Create a new disposition action object
NodeRef dispositionActionNodeRef = this.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 = dispositionActionDefinition.getEvents();
for (RecordsManagementEvent event : events)
{
// For every event create an entry on the action
da.addEventCompletionDetails(event);
}
}
/**
* 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();
@@ -654,31 +694,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
asOfDate = period.getNextDate(contextDate);
}
}
// Set the property values
props.put(PROP_DISPOSITION_ACTION_ID, dispositionActionDefinition.getId());
props.put(PROP_DISPOSITION_ACTION, dispositionActionDefinition.getName());
if (asOfDate != null)
{
props.put(PROP_DISPOSITION_AS_OF, asOfDate);
}
// Create a new disposition action object
NodeRef dispositionActionNodeRef = this.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 = dispositionActionDefinition.getEvents();
for (RecordsManagementEvent event : events)
{
// For every event create an entry on the action
da.addEventCompletionDetails(event);
}
return asOfDate;
}
/**