mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Changed a bit the methods to be more readable.
This commit is contained in:
@@ -21,19 +21,15 @@ package org.alfresco.module.org_alfresco_module_rm.disposition;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
|
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry;
|
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSelectionStrategy.DispositionableNodeRefComparator;
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.disposition.property.DispositionProperty;
|
import org.alfresco.module.org_alfresco_module_rm.disposition.property.DispositionProperty;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent;
|
import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
||||||
@@ -75,6 +71,8 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
/** Logger */
|
/** Logger */
|
||||||
private static Log logger = LogFactory.getLog(DispositionServiceImpl.class);
|
private static Log logger = LogFactory.getLog(DispositionServiceImpl.class);
|
||||||
|
|
||||||
|
public enum WriteMode {ReadOnly, DateOnly, DateAndName};
|
||||||
|
|
||||||
/** Behaviour filter */
|
/** Behaviour filter */
|
||||||
private BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
|
|
||||||
@@ -275,44 +273,42 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
public DispositionSchedule getDispositionSchedule(final NodeRef nodeRef)
|
public DispositionSchedule getDispositionSchedule(final NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
DispositionSchedule ds = null;
|
DispositionSchedule ds = null;
|
||||||
NodeRef diNodeRef = null;
|
NodeRef dsNodeRef = null;
|
||||||
if (isRecord(nodeRef))
|
if (isRecord(nodeRef))
|
||||||
{
|
{
|
||||||
// Get the record folders for the record
|
final NextActionFromDisposition dsNextAction = getDispositionActionByNameForRecord(nodeRef);
|
||||||
List<NodeRef> recordFolders = recordFolderService.getRecordFolders(nodeRef);
|
|
||||||
|
|
||||||
DispositionAction nextDispositionAction = getNextDispositionAction(nodeRef);
|
if (!dsNextAction.getWriteMode().equals(WriteMode.ReadOnly))
|
||||||
|
|
||||||
// the record is not created yet or it doesn't have DS
|
|
||||||
if (nextDispositionAction == null)
|
|
||||||
{
|
{
|
||||||
// calculate nextAction to be the longest first action step
|
final NodeRef action = dsNextAction.getNextActionNodeRef();
|
||||||
DispositionScheduleAndNextAction dsNodeRef = getNextDispositionActionFromParents(recordFolders);
|
final String dispositionActionName = dsNextAction.getNextActionName();
|
||||||
if (dsNodeRef != null)
|
final Date dispositionActionDate = dsNextAction.getNextActionDateAsOf();
|
||||||
{
|
|
||||||
nextDispositionAction = dsNodeRef.getNextAction();
|
|
||||||
diNodeRef = dsNodeRef.getDispositionNodeRef();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
diNodeRef = setRecordNextDispositionActionLatestDate(nodeRef, recordFolders, nextDispositionAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextDispositionAction == null)
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||||
{
|
{
|
||||||
return null;
|
@Override
|
||||||
}
|
public Void doWork()
|
||||||
|
{
|
||||||
|
nodeService.setProperty(action, PROP_DISPOSITION_AS_OF, dispositionActionDate);
|
||||||
|
if (dsNextAction.getWriteMode().equals(WriteMode.DateAndName))
|
||||||
|
{
|
||||||
|
nodeService.setProperty(action, PROP_DISPOSITION_ACTION_NAME, dispositionActionName);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dsNodeRef = dsNextAction.getDispositionNodeRef();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Get the disposition instructions for the node reference provided
|
// Get the disposition instructions for the node reference provided
|
||||||
diNodeRef = getDispositionScheduleImpl(nodeRef);
|
dsNodeRef = getDispositionScheduleImpl(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diNodeRef != null)
|
if (dsNodeRef != null)
|
||||||
{
|
{
|
||||||
ds = new DispositionScheduleImpl(serviceRegistry, nodeService, diNodeRef);
|
ds = new DispositionScheduleImpl(serviceRegistry, nodeService, dsNodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
@@ -1082,7 +1078,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;// throw exception? poate nu are actiuni cu numele dat ca param
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1133,16 +1129,47 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class DispositionScheduleAndNextAction
|
class NextActionFromDisposition
|
||||||
{
|
{
|
||||||
|
public NextActionFromDisposition(NodeRef dispositionNodeRef, NodeRef nextActionNodeRef,
|
||||||
|
String nextActionName, Date nextActionDateAsOf, WriteMode writeMode)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.dispositionNodeRef = dispositionNodeRef;
|
||||||
|
this.nextActionNodeRef = nextActionNodeRef;
|
||||||
|
this.nextActionName = nextActionName;
|
||||||
|
this.nextActionDateAsOf = nextActionDateAsOf;
|
||||||
|
this.writeMode = writeMode;
|
||||||
|
}
|
||||||
|
|
||||||
private NodeRef dispositionNodeRef;
|
private NodeRef dispositionNodeRef;
|
||||||
|
|
||||||
private DispositionAction nextAction;
|
private NodeRef nextActionNodeRef;
|
||||||
|
|
||||||
public DispositionScheduleAndNextAction(NodeRef dispositionNodeRef, DispositionAction nextAction)
|
private String nextActionName;
|
||||||
|
|
||||||
|
private Date nextActionDateAsOf;
|
||||||
|
|
||||||
|
private WriteMode writeMode;
|
||||||
|
|
||||||
|
public WriteMode getWriteMode()
|
||||||
{
|
{
|
||||||
this.dispositionNodeRef = dispositionNodeRef;
|
return writeMode;
|
||||||
this.nextAction = nextAction;
|
}
|
||||||
|
|
||||||
|
public void setWriteMode(WriteMode writeMode)
|
||||||
|
{
|
||||||
|
this.writeMode = writeMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeRef getNextActionNodeRef()
|
||||||
|
{
|
||||||
|
return nextActionNodeRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextActionNodeRef(NodeRef nextActionNodeRef)
|
||||||
|
{
|
||||||
|
this.nextActionNodeRef = nextActionNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeRef getDispositionNodeRef()
|
public NodeRef getDispositionNodeRef()
|
||||||
@@ -1155,120 +1182,122 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
this.dispositionNodeRef = dispositionNodeRef;
|
this.dispositionNodeRef = dispositionNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DispositionAction getNextAction()
|
public String getNextActionName()
|
||||||
{
|
{
|
||||||
return nextAction;
|
return nextActionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextAction(DispositionAction nextAction)
|
public void setNextActionName(String nextActionName)
|
||||||
{
|
{
|
||||||
this.nextAction = nextAction;
|
this.nextActionName = nextActionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getNextActionDateAsOf()
|
||||||
|
{
|
||||||
|
return nextActionDateAsOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextActionDateAsOf(Date nextActionDateAsOf)
|
||||||
|
{
|
||||||
|
this.nextActionDateAsOf = nextActionDateAsOf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the longest period for the given action
|
* Calculate next disposition action for a record
|
||||||
*
|
*
|
||||||
* @param recordNodeRef
|
* @param record
|
||||||
* @param recordFolders
|
* @return next disposition action (name, date) and the disposition associated
|
||||||
* @param nextDispositionAction
|
*/
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private NodeRef setRecordNextDispositionActionLatestDate(final NodeRef recordNodeRef, List<NodeRef> recordFolders, DispositionAction nextDispositionAction)
|
|
||||||
{
|
|
||||||
String recordnextDispositionActionName = nextDispositionAction.getName();
|
|
||||||
Date recordNextDispositionActionDate = nextDispositionAction.getAsOfDate();
|
|
||||||
Date nextDispositionActionDate = null;
|
|
||||||
NodeRef dispositionNodeRef = null;
|
|
||||||
|
|
||||||
for (NodeRef folder : recordFolders)
|
protected NextActionFromDisposition getDispositionActionByNameForRecord(NodeRef record)
|
||||||
|
{
|
||||||
|
List<NodeRef> recordFolders = recordFolderService.getRecordFolders(record);
|
||||||
|
DispositionAction nextDispositionAction = getNextDispositionAction(record);
|
||||||
|
|
||||||
|
if (nextDispositionAction == null)
|
||||||
{
|
{
|
||||||
NodeRef dsNodeRef = getDispositionScheduleImpl(folder);
|
NodeRef newAction = null;
|
||||||
if (dsNodeRef != null)
|
String newDispositionActionName = null;
|
||||||
|
Date newDispositionActionDateAsOf = null;
|
||||||
|
NodeRef dispositionNodeRef = null;
|
||||||
|
for (NodeRef folder : recordFolders)
|
||||||
{
|
{
|
||||||
Date dispActionDate = getDispositionActionDate(dsNodeRef, recordnextDispositionActionName);
|
NodeRef folderDS = getDispositionScheduleImpl(folder);
|
||||||
if (nextDispositionActionDate == null || nextDispositionActionDate.before(dispActionDate))
|
if (folderDS != null)
|
||||||
{
|
{
|
||||||
nextDispositionActionDate = dispActionDate;
|
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(folderDS);
|
||||||
dispositionNodeRef = dsNodeRef;
|
if (assocs != null && assocs.size() > 0)
|
||||||
}
|
{
|
||||||
|
NodeRef firstAction = assocs.get(0).getChildRef();
|
||||||
|
DispositionAction firstDispositionAction = new DispositionActionImpl(serviceRegistry, firstAction);
|
||||||
|
|
||||||
|
if (newAction == null)
|
||||||
|
{
|
||||||
|
newAction = firstAction;
|
||||||
|
newDispositionActionName = (String)nodeService.getProperty(newAction, PROP_DISPOSITION_ACTION_NAME);
|
||||||
|
newDispositionActionDateAsOf = getDispositionActionDate(folderDS, newDispositionActionName);
|
||||||
|
}
|
||||||
|
else if (firstDispositionAction.getAsOfDate() != null && newDispositionActionDateAsOf.before(firstDispositionAction.getAsOfDate()))
|
||||||
|
{
|
||||||
|
newDispositionActionName = (String)nodeService.getProperty(firstAction, PROP_DISPOSITION_ACTION_NAME);
|
||||||
|
newDispositionActionDateAsOf = firstDispositionAction.getAsOfDate();
|
||||||
|
}
|
||||||
|
dispositionNodeRef = folderDS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newDispositionActionName != null && newDispositionActionDateAsOf != null
|
||||||
|
&& dispositionNodeRef != null && newAction != null)
|
||||||
|
{
|
||||||
|
return new NextActionFromDisposition(dispositionNodeRef, newAction,
|
||||||
|
newDispositionActionName, newDispositionActionDateAsOf, WriteMode.DateAndName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set only on record creation or when linking
|
else
|
||||||
if (!nextDispositionActionDate.equals(recordNextDispositionActionDate) && recordNextDispositionActionDate.before(nextDispositionActionDate))
|
|
||||||
{
|
{
|
||||||
final Date nextDADate = nextDispositionActionDate;
|
// get the longest period for the given action name
|
||||||
|
String recordNextDispositionActionName = nextDispositionAction.getName();
|
||||||
|
Date recordNextDispositionActionDate = nextDispositionAction.getAsOfDate();
|
||||||
|
Date nextDispositionActionDate = null;
|
||||||
|
NodeRef dispositionNodeRef = null;
|
||||||
|
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
for (NodeRef folder : recordFolders)
|
||||||
{
|
{
|
||||||
@Override
|
NodeRef dsNodeRef = getDispositionScheduleImpl(folder);
|
||||||
public Void doWork()
|
if (dsNodeRef != null)
|
||||||
{
|
{
|
||||||
nodeService.setProperty(recordNodeRef, PROP_DISPOSITION_AS_OF, nextDADate);
|
Date dispActionDate = getDispositionActionDate(dsNodeRef, recordNextDispositionActionName);
|
||||||
return null;
|
if (nextDispositionActionDate == null || nextDispositionActionDate.before(dispActionDate))
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return dispositionNodeRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate next disposition action for a record with the given parents
|
|
||||||
*
|
|
||||||
* @param recordFolders parent folders
|
|
||||||
* @return next disposition action and the disposition associated
|
|
||||||
*/
|
|
||||||
private DispositionScheduleAndNextAction getNextDispositionActionFromParents(List<NodeRef> recordFolders)
|
|
||||||
{
|
|
||||||
NodeRef newAction = null;
|
|
||||||
String newDispositionActionName = null;
|
|
||||||
Date newDispositionActionDate = null;
|
|
||||||
NodeRef dispositionNodeRef = null;
|
|
||||||
for (NodeRef folder : recordFolders)
|
|
||||||
{
|
|
||||||
NodeRef folderDS = getDispositionScheduleImpl(folder);
|
|
||||||
if (folderDS != null)
|
|
||||||
{
|
|
||||||
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(folderDS);
|
|
||||||
if (assocs != null && assocs.size() > 0)
|
|
||||||
{
|
|
||||||
NodeRef firstAction = assocs.get(0).getChildRef();
|
|
||||||
DispositionAction firstDispositionAction = new DispositionActionImpl(serviceRegistry, firstAction);
|
|
||||||
|
|
||||||
if (newAction == null)
|
|
||||||
{
|
{
|
||||||
newAction = firstAction;
|
nextDispositionActionDate = dispActionDate;
|
||||||
newDispositionActionName = (String)nodeService.getProperty(newAction, PROP_DISPOSITION_ACTION_NAME);
|
dispositionNodeRef = dsNodeRef;
|
||||||
newDispositionActionDate = getDispositionActionDate(folderDS, newDispositionActionName);
|
|
||||||
dispositionNodeRef = folderDS;
|
|
||||||
}
|
|
||||||
else if (firstDispositionAction.getAsOfDate() != null && newDispositionActionDate.before(firstDispositionAction.getAsOfDate()))
|
|
||||||
{
|
|
||||||
newDispositionActionName = (String)nodeService.getProperty(firstAction, PROP_DISPOSITION_ACTION_NAME);
|
|
||||||
newDispositionActionDate = firstDispositionAction.getAsOfDate();
|
|
||||||
dispositionNodeRef = folderDS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (nextDispositionActionDate != null && dispositionNodeRef != null)
|
||||||
if (newAction != null) {
|
|
||||||
final NodeRef action = newAction;
|
|
||||||
final String dispositionActionName = newDispositionActionName;
|
|
||||||
final Date dispositionActionDate = newDispositionActionDate;
|
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
|
||||||
{
|
{
|
||||||
@Override
|
WriteMode mode = null;
|
||||||
public Void doWork()
|
if (!nextDispositionActionDate.equals(recordNextDispositionActionDate)
|
||||||
|
&& recordNextDispositionActionDate.before(nextDispositionActionDate))
|
||||||
{
|
{
|
||||||
nodeService.setProperty(action, PROP_DISPOSITION_ACTION_NAME, dispositionActionName);
|
mode = WriteMode.DateOnly;
|
||||||
nodeService.setProperty(action, PROP_DISPOSITION_AS_OF, dispositionActionDate);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
});
|
else
|
||||||
DispositionAction dsAction = new DispositionActionImpl(serviceRegistry, action);
|
{
|
||||||
return new DispositionScheduleAndNextAction(dispositionNodeRef, dsAction);
|
mode = WriteMode.ReadOnly;
|
||||||
|
}
|
||||||
|
return new NextActionFromDisposition(dispositionNodeRef, nextDispositionAction.getNodeRef(),
|
||||||
|
recordNextDispositionActionName, nextDispositionActionDate, mode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user