mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1096: Refactored AddRecordTypeAction and CloseFolderAction
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@57972 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -11,7 +11,6 @@ rm.action.not-next-disp=The disposition action {0} couldn't be performed, becaus
|
||||
rm.action.not-record-folder=The disposition action {0} couldn't be performed, because this isn't a record folder. (nodeRef={1})
|
||||
rm.action.actioned-upon-not-record=The action {0} can't be performed because this isn't a record. (filePlanComponet={1})
|
||||
rm.action.custom-aspect-not-recognised=The custom type can't be applied because it's not recognised. (customAspect={0})
|
||||
rm.action.close-record-folder-not-folder=The record folder couldn't be closed because it's not defined as a record folder.(nodeRef={0})
|
||||
rm.action.event-no-disp-lc=The event {0} can't be completed, because it's not defined on the disposition lifecycle.
|
||||
rm.action.undeclared-only-records=Only records can be completed. (nodeRef={0})
|
||||
rm.action.no-declare-mand-prop=The record can't be completed, because not all the records mandatory properties have been set.
|
||||
@@ -35,4 +34,3 @@ rm.action.node-not-transfer=The node is not a transfer object.
|
||||
rm.action.undo-not-last=The cut off can't be undone, because the last disposition action was not cut off.
|
||||
rm.action.records_only_undeclared=Only records can be completed.
|
||||
rm.action.event-not-undone=The event {0} can't be undone, because it's not defined on the disposition lifecycle.
|
||||
rm.action.actioned-upon-has-aspect=The node {0} has already the aspect {1}.
|
@@ -15,3 +15,5 @@ rm.service.parent-record-folder-type=Can't create record folder, because the par
|
||||
rm.service.record-folder-type=Can't create record folder, because the provided type is not a sub-type of rm:recordFolder. (type={0})
|
||||
rm.service.not-record=The node {0} is not a record.
|
||||
rm.service.vital-def-missing=Vital record definition aspect is not present on node. (nodeRef={0})
|
||||
rm.service.close-record-folder-not-folder=The record folder couldn't be closed because it's not defined as a record folder.(nodeRef={0})
|
||||
rm.service.node-has-aspect=The node {0} has already the aspect {1}.
|
@@ -44,7 +44,9 @@ public class AddRecordTypeAction extends RMActionExecuterAbstractBase
|
||||
|
||||
/** I18N */
|
||||
private static final String MSG_ACTIONED_UPON_NOT_RECORD = "rm.action.actioned-upon-not-record";
|
||||
private static final String MSG_ACTIONED_UPON_HAS_ASPECT = "rm.action.actioned-upon-has-aspect";
|
||||
|
||||
/** Constant */
|
||||
private static final String DELIMITER = ",";
|
||||
|
||||
/** Parameter names */
|
||||
public static final String PARAM_ADD_RECORD_TYPES = "recordTypes";
|
||||
@@ -59,24 +61,11 @@ public class AddRecordTypeAction extends RMActionExecuterAbstractBase
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
if (nodeService.exists(actionedUponNodeRef) == true &&
|
||||
freezeService.isFrozen(actionedUponNodeRef) == false &&
|
||||
recordService.isRecord(actionedUponNodeRef) == true &&
|
||||
recordService.isDeclared(actionedUponNodeRef) == false)
|
||||
if (eligibleForAction(actionedUponNodeRef) == true)
|
||||
{
|
||||
String recordTypes = (String) action.getParameterValue(PARAM_ADD_RECORD_TYPES);
|
||||
String[] types = recordTypes.split(",");
|
||||
for (String type : types)
|
||||
for (String type : getRecordTypes(action))
|
||||
{
|
||||
QName aspectTypeQName = QName.createQName(type, namespaceService);
|
||||
if (nodeService.hasAspect(actionedUponNodeRef, aspectTypeQName) == false)
|
||||
{
|
||||
nodeService.addAspect(actionedUponNodeRef, aspectTypeQName, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info(I18NUtil.getMessage(MSG_ACTIONED_UPON_HAS_ASPECT, actionedUponNodeRef.toString(), aspectTypeQName.toString()));
|
||||
}
|
||||
recordService.addRecordType(actionedUponNodeRef, QName.createQName(type, namespaceService));
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled() == true)
|
||||
@@ -85,6 +74,42 @@ public class AddRecordTypeAction extends RMActionExecuterAbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to check the actioned upon node reference to decide to execute the action
|
||||
* The preconditions are:
|
||||
* - The node must exist
|
||||
* - The node must not be frozen
|
||||
* - The node must be record
|
||||
* - The node must not be declared
|
||||
*
|
||||
* @param actionedUponNodeRef node reference
|
||||
* @return Return true if the node reference passes all the preconditions for executing the action, false otherwise
|
||||
*/
|
||||
private boolean eligibleForAction(NodeRef actionedUponNodeRef)
|
||||
{
|
||||
boolean result = false;
|
||||
if (nodeService.exists(actionedUponNodeRef) == true &&
|
||||
freezeService.isFrozen(actionedUponNodeRef) == false &&
|
||||
recordService.isRecord(actionedUponNodeRef) == true &&
|
||||
recordService.isDeclared(actionedUponNodeRef) == false)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the record types from the action
|
||||
*
|
||||
* @param action The action
|
||||
* @return An array of record types
|
||||
*/
|
||||
private String[] getRecordTypes(Action action)
|
||||
{
|
||||
String recordTypes = (String) action.getParameterValue(PARAM_ADD_RECORD_TYPES);
|
||||
return recordTypes.split(DELIMITER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase#addParameterDefinitions(java.util.List)
|
||||
*/
|
||||
|
@@ -20,11 +20,7 @@ package org.alfresco.module.org_alfresco_module_rm.action.impl;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Action to close the records folder
|
||||
@@ -33,12 +29,6 @@ import org.springframework.extensions.surf.util.I18NUtil;
|
||||
*/
|
||||
public class CloseRecordFolderAction extends RMActionExecuterAbstractBase
|
||||
{
|
||||
/** Logger */
|
||||
private static Log logger = LogFactory.getLog(CloseRecordFolderAction.class);
|
||||
|
||||
/** I18N */
|
||||
private static final String MSG_CLOSE_RECORD_FOLDER_NOT_FOLDER = "rm.action.close-record-folder-not-folder";
|
||||
|
||||
/** Parameter names */
|
||||
public static final String PARAM_CLOSE_PARENT = "closeParent";
|
||||
|
||||
@@ -49,31 +39,29 @@ public class CloseRecordFolderAction extends RMActionExecuterAbstractBase
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
if (nodeService.exists(actionedUponNodeRef) == true &&
|
||||
freezeService.isFrozen(actionedUponNodeRef) == false)
|
||||
if (eligibleForAction(actionedUponNodeRef) == true)
|
||||
{
|
||||
if (recordService.isRecord(actionedUponNodeRef))
|
||||
{
|
||||
ChildAssociationRef assocRef = nodeService.getPrimaryParent(actionedUponNodeRef);
|
||||
if (assocRef != null)
|
||||
{
|
||||
actionedUponNodeRef = assocRef.getParentRef();
|
||||
recordFolderService.closeFolder(actionedUponNodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (recordFolderService.isRecordFolder(actionedUponNodeRef) == true)
|
||||
/**
|
||||
* Helper method to check the actioned upon node reference to decide to execute the action
|
||||
* The preconditions are:
|
||||
* - The node must exist
|
||||
* - The node must not be frozen
|
||||
*
|
||||
* @param actionedUponNodeRef node reference
|
||||
* @return Return true if the node reference passes all the preconditions for executing the action, false otherwise
|
||||
*/
|
||||
private boolean eligibleForAction(NodeRef actionedUponNodeRef)
|
||||
{
|
||||
Boolean isClosed = (Boolean) nodeService.getProperty(actionedUponNodeRef, PROP_IS_CLOSED);
|
||||
if (Boolean.FALSE.equals(isClosed) == true)
|
||||
boolean result = false;
|
||||
if (nodeService.exists(actionedUponNodeRef) == true &&
|
||||
freezeService.isFrozen(actionedUponNodeRef) == false)
|
||||
{
|
||||
nodeService.setProperty(actionedUponNodeRef, PROP_IS_CLOSED, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
logger.warn(I18NUtil.getMessage(MSG_CLOSE_RECORD_FOLDER_NOT_FOLDER, actionedUponNodeRef.toString()));
|
||||
}
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -152,4 +152,12 @@ public interface RecordService
|
||||
* @return List<NodeRef> list of records in the record folder
|
||||
*/
|
||||
List<NodeRef> getRecords(NodeRef recordFolder);
|
||||
|
||||
/**
|
||||
* Adds the specified type to the record
|
||||
*
|
||||
* @param nodeRef Record node reference
|
||||
* @param typeQName Type to add
|
||||
*/
|
||||
void addRecordType(NodeRef nodeRef, QName typeQName);
|
||||
}
|
||||
|
@@ -88,6 +88,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Record service implementation.
|
||||
@@ -107,6 +108,9 @@ public class RecordServiceImpl implements RecordService,
|
||||
/** Logger */
|
||||
private static Log logger = LogFactory.getLog(RecordServiceImpl.class);
|
||||
|
||||
/** I18N */
|
||||
private static final String MSG_NODE_HAS_ASPECT = "rm.service.node-has-aspect";
|
||||
|
||||
/** Always edit property array */
|
||||
private static final QName[] ALWAYS_EDIT_PROPERTIES = new QName[]
|
||||
{
|
||||
@@ -1291,7 +1295,7 @@ public class RecordServiceImpl implements RecordService,
|
||||
List<NodeRef> result = new ArrayList<NodeRef>(1);
|
||||
if (recordFolderService.isRecordFolder(recordFolder) == true)
|
||||
{
|
||||
List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(recordFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
||||
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(recordFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
||||
for (ChildAssociationRef assoc : assocs)
|
||||
{
|
||||
NodeRef child = assoc.getChildRef();
|
||||
@@ -1303,4 +1307,23 @@ public class RecordServiceImpl implements RecordService,
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#addRecordType(NodeRef, QName)
|
||||
*/
|
||||
@Override
|
||||
public void addRecordType(NodeRef nodeRef, QName typeQName)
|
||||
{
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
ParameterCheck.mandatory("typeQName", typeQName);
|
||||
|
||||
if (nodeService.hasAspect(nodeRef, typeQName) == false)
|
||||
{
|
||||
nodeService.addAspect(nodeRef, typeQName, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info(I18NUtil.getMessage(MSG_NODE_HAS_ASPECT, nodeRef.toString(), typeQName.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -146,4 +146,13 @@ public interface RecordFolderService
|
||||
// TODO List<NodeRef> getParentRecordsManagementContainers(NodeRef container); // also applicable to record folders
|
||||
|
||||
// TODO rename to getContainedRecords(NodeRef recordFolder);
|
||||
|
||||
/**
|
||||
* Closes the folder. If the given node reference is a record the parent will be retrieved and processed.
|
||||
*
|
||||
* @param nodeRef the record folder node reference
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
void closeFolder(NodeRef nodeRef);
|
||||
}
|
||||
|
@@ -42,6 +42,8 @@ import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
@@ -55,11 +57,15 @@ public class RecordFolderServiceImpl extends ServiceBaseImpl
|
||||
RecordsManagementModel,
|
||||
NodeServicePolicies.OnCreateChildAssociationPolicy
|
||||
{
|
||||
/** Logger */
|
||||
private static Log logger = LogFactory.getLog(RecordFolderServiceImpl.class);
|
||||
|
||||
/** I18N */
|
||||
private final static String MSG_RECORD_FOLDER_EXPECTED = "rm.service.record-folder-expected";
|
||||
private final static String MSG_PARENT_RECORD_FOLDER_ROOT = "rm.service.parent-record-folder-root";
|
||||
private final static String MSG_PARENT_RECORD_FOLDER_TYPE = "rm.service.parent-record-folder-type";
|
||||
private final static String MSG_RECORD_FOLDER_TYPE = "rm.service.record-folder-type";
|
||||
private final static String MSG_CLOSE_RECORD_FOLDER_NOT_FOLDER = "rm.service.close-record-folder-not-folder";
|
||||
|
||||
/** Policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
@@ -353,4 +359,36 @@ public class RecordFolderServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService#closeFolder(NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void closeFolder(NodeRef nodeRef)
|
||||
{
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
|
||||
if (recordService.isRecord(nodeRef))
|
||||
{
|
||||
ChildAssociationRef assocRef = nodeService.getPrimaryParent(nodeRef);
|
||||
if (assocRef != null)
|
||||
{
|
||||
nodeRef = assocRef.getParentRef();
|
||||
}
|
||||
}
|
||||
|
||||
if (isRecordFolder(nodeRef) == true)
|
||||
{
|
||||
Boolean isClosed = (Boolean) nodeService.getProperty(nodeRef, PROP_IS_CLOSED);
|
||||
if (Boolean.FALSE.equals(isClosed) == true)
|
||||
{
|
||||
nodeService.setProperty(nodeRef, PROP_IS_CLOSED, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
logger.warn(I18NUtil.getMessage(MSG_CLOSE_RECORD_FOLDER_NOT_FOLDER, nodeRef.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user