mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
APPS-139 added backend functionality for Declare and file version as record
This commit is contained in:
@@ -54,8 +54,10 @@ create-record.hide-record.display-label=Hide Record
|
|||||||
create-record.path.display-label=Record Folder Location
|
create-record.path.display-label=Record Folder Location
|
||||||
# Declare As Version Record
|
# Declare As Version Record
|
||||||
declare-as-version-record.title=Declare Version as Record
|
declare-as-version-record.title=Declare Version as Record
|
||||||
declare-as-version-record.description=Declares this version of the file as a record
|
declare-as-version-record.description=Declares this version of the file as a record and optionally files it
|
||||||
declare-as-version-record.file-plan.display-label=File Plan
|
declare-as-version-record.file-plan.display-label=File Plan
|
||||||
|
declare-as-version-record.path.display-label=Record Folder Location
|
||||||
|
|
||||||
# Complete record
|
# Complete record
|
||||||
declareRecord.title=Complete Record
|
declareRecord.title=Complete Record
|
||||||
declareRecord.description=Completes a record
|
declareRecord.description=Completes a record
|
||||||
|
@@ -27,12 +27,10 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.action.dm;
|
package org.alfresco.module.org_alfresco_module_rm.action.dm;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.model.ContentModel;
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
|
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.action.dm.RecordActionUtils.Services;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||||
@@ -43,11 +41,6 @@ import org.alfresco.service.cmr.action.ParameterDefinition;
|
|||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.QName;
|
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new record from an existing content object.
|
* Creates a new record from an existing content object.
|
||||||
@@ -59,9 +52,6 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
||||||
implements RecordsManagementModel
|
implements RecordsManagementModel
|
||||||
{
|
{
|
||||||
/** Logger */
|
|
||||||
private static final Log LOGGER = LogFactory.getLog(CreateRecordAction.class);
|
|
||||||
|
|
||||||
/** Action name */
|
/** Action name */
|
||||||
public static final String NAME = "create-record";
|
public static final String NAME = "create-record";
|
||||||
|
|
||||||
@@ -70,20 +60,26 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
public static final String PARAM_HIDE_RECORD = "hide-record";
|
public static final String PARAM_HIDE_RECORD = "hide-record";
|
||||||
public static final String PARAM_PATH = "path";
|
public static final String PARAM_PATH = "path";
|
||||||
|
|
||||||
/** Node service */
|
/**
|
||||||
|
* Node service
|
||||||
|
*/
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
|
||||||
/** File plan service */
|
/**
|
||||||
|
* File plan service
|
||||||
|
*/
|
||||||
private FilePlanService filePlanService;
|
private FilePlanService filePlanService;
|
||||||
|
|
||||||
/** Authentication util */
|
/**
|
||||||
|
* Authentication util
|
||||||
|
*/
|
||||||
private AuthenticationUtil authenticationUtil;
|
private AuthenticationUtil authenticationUtil;
|
||||||
|
|
||||||
/** Record service */
|
/** Record service */
|
||||||
private RecordService recordService;
|
private RecordService recordService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nodeService node service
|
* @param nodeService node service
|
||||||
*/
|
*/
|
||||||
public void setNodeService(NodeService nodeService)
|
public void setNodeService(NodeService nodeService)
|
||||||
{
|
{
|
||||||
@@ -91,7 +87,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param filePlanService file plan service
|
* @param filePlanService file plan service
|
||||||
*/
|
*/
|
||||||
public void setFilePlanService(FilePlanService filePlanService)
|
public void setFilePlanService(FilePlanService filePlanService)
|
||||||
{
|
{
|
||||||
@@ -99,13 +95,14 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param authenticationUtil authentication util
|
* @param authenticationUtil authentication util
|
||||||
*/
|
*/
|
||||||
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
|
public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
|
||||||
{
|
{
|
||||||
this.authenticationUtil = authenticationUtil;
|
this.authenticationUtil = authenticationUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param recordService record service
|
* @param recordService record service
|
||||||
*/
|
*/
|
||||||
@@ -136,7 +133,8 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
|
|
||||||
if (pathParameter != null && !pathParameter.isEmpty())
|
if (pathParameter != null && !pathParameter.isEmpty())
|
||||||
{
|
{
|
||||||
destinationRecordFolder = resolvePath(filePlan, pathParameter);
|
RecordActionUtils.Services services = new Services(nodeService, filePlanService, authenticationUtil);
|
||||||
|
destinationRecordFolder = RecordActionUtils.resolvePath(services, filePlan, pathParameter, NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
@@ -162,102 +160,4 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
|
params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
|
||||||
params.add(new ParameterDefinitionImpl(PARAM_HIDE_RECORD, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_HIDE_RECORD)));
|
params.add(new ParameterDefinitionImpl(PARAM_HIDE_RECORD, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_HIDE_RECORD)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get the target record folder node reference from the action path parameter
|
|
||||||
*
|
|
||||||
* @param filePlan The filePlan containing the path
|
|
||||||
* @param pathParameter The path
|
|
||||||
* @return The NodeRef of the resolved path
|
|
||||||
*/
|
|
||||||
private NodeRef resolvePath(NodeRef filePlan, final String pathParameter)
|
|
||||||
{
|
|
||||||
NodeRef destinationFolder;
|
|
||||||
|
|
||||||
if (filePlan == null)
|
|
||||||
{
|
|
||||||
filePlan = getDefaultFilePlan();
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
|
|
||||||
if ((pathElementsArray != null) && (pathElementsArray.length > 0))
|
|
||||||
{
|
|
||||||
destinationFolder = resolvePath(filePlan, Arrays.asList(pathElementsArray));
|
|
||||||
|
|
||||||
// destination must be a record folder
|
|
||||||
QName nodeType = nodeService.getType(destinationFolder);
|
|
||||||
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is not a record folder.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found.");
|
|
||||||
}
|
|
||||||
return destinationFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to recursively get the next path element node reference from the action path parameter
|
|
||||||
*
|
|
||||||
* @param parent The parent of the path elements
|
|
||||||
* @param pathElements The path elements still to be resolved
|
|
||||||
* @return The NodeRef of the resolved path element
|
|
||||||
*/
|
|
||||||
private NodeRef resolvePath(NodeRef parent, List<String> pathElements)
|
|
||||||
{
|
|
||||||
NodeRef nodeRef;
|
|
||||||
String childName = pathElements.get(0);
|
|
||||||
|
|
||||||
nodeRef = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, childName);
|
|
||||||
|
|
||||||
if (nodeRef == null)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QName nodeType = nodeService.getType(nodeRef);
|
|
||||||
if (nodeType.equals(RecordsManagementModel.TYPE_HOLD_CONTAINER) ||
|
|
||||||
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
|
|
||||||
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is invalid.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pathElements.size() > 1)
|
|
||||||
{
|
|
||||||
nodeRef = resolvePath(nodeRef, pathElements.subList(1, pathElements.size()));
|
|
||||||
}
|
|
||||||
return nodeRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get the default RM filePlan
|
|
||||||
*
|
|
||||||
* @return The NodeRef of the default RM filePlan
|
|
||||||
*/
|
|
||||||
private NodeRef getDefaultFilePlan()
|
|
||||||
{
|
|
||||||
NodeRef filePlan = authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public NodeRef doWork()
|
|
||||||
{
|
|
||||||
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// if the file plan is still null, raise an exception
|
|
||||||
if (filePlan == null)
|
|
||||||
{
|
|
||||||
if (LOGGER.isDebugEnabled())
|
|
||||||
{
|
|
||||||
LOGGER.debug("Unable to execute " + NAME + " action, because the fileplan path could not be determined. Make sure at least one file plan has been created.");
|
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the fileplan path could not be determined.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filePlan;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -27,21 +27,29 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.action.dm;
|
package org.alfresco.module.org_alfresco_module_rm.action.dm;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
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.action.AuditableActionExecuterAbstractBase;
|
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.action.dm.RecordActionUtils.Services;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
||||||
|
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.collections.map.HashedMap;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -63,6 +71,7 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
|
|
||||||
/** Parameter names */
|
/** Parameter names */
|
||||||
public static final String PARAM_FILE_PLAN = "file-plan";
|
public static final String PARAM_FILE_PLAN = "file-plan";
|
||||||
|
public static final String PARAM_PATH = "path";
|
||||||
|
|
||||||
/** Sync Model URI */
|
/** Sync Model URI */
|
||||||
private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0";
|
private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0";
|
||||||
@@ -85,6 +94,10 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
/** authentication util */
|
/** authentication util */
|
||||||
private AuthenticationUtil authenticationUtil;
|
private AuthenticationUtil authenticationUtil;
|
||||||
|
|
||||||
|
/** Record service */
|
||||||
|
private RecordService recordService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nodeService node service
|
* @param nodeService node service
|
||||||
*/
|
*/
|
||||||
@@ -125,6 +138,14 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
this.authenticationUtil = authenticationUtil;
|
this.authenticationUtil = authenticationUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param recordService record service
|
||||||
|
*/
|
||||||
|
public void setRecordService(RecordService recordService)
|
||||||
|
{
|
||||||
|
this.recordService = recordService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
*/
|
*/
|
||||||
@@ -147,47 +168,7 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
logger.debug("Can not declare version as record, because " + actionedUponNodeRef.toString() + " is not a supported type.");
|
logger.debug("Can not declare version as record, because " + actionedUponNodeRef.toString() + " is not a supported type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE))
|
else if (!checkAspects(actionedUponNodeRef))
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " does not have the versionable aspect applied.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD))
|
|
||||||
{
|
|
||||||
// Do not declare version record if the actioned upon node is already a record!
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " is already a record.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY))
|
|
||||||
{
|
|
||||||
// We can not create records from working copies
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " is a working copy.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD_REJECTION_DETAILS))
|
|
||||||
{
|
|
||||||
// can not create a record from a previously rejected one
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + " has previously been rejected.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_SYNCED))
|
|
||||||
{
|
|
||||||
// can't declare the record if the node is sync'ed
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Can't declare version record, because " + actionedUponNodeRef.toString() + " is synched content.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
|
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
|
||||||
if (filePlan == null)
|
if (filePlan == null)
|
||||||
@@ -226,7 +207,22 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolve destination record folder if path supplied
|
||||||
|
NodeRef destinationRecordFolder = null;
|
||||||
|
String pathParameter = (String) action.getParameterValue(PARAM_PATH);
|
||||||
|
if (pathParameter != null && !pathParameter.isEmpty())
|
||||||
|
{
|
||||||
|
RecordActionUtils.Services services = new Services(nodeService, filePlanService, authenticationUtil);
|
||||||
|
destinationRecordFolder = RecordActionUtils.resolvePath(services, filePlan, pathParameter, NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// create record from latest version
|
// create record from latest version
|
||||||
|
if (destinationRecordFolder != null)
|
||||||
|
{
|
||||||
|
recordableVersionService.createRecordFromLatestVersion(destinationRecordFolder, actionedUponNodeRef);
|
||||||
|
recordService.file(actionedUponNodeRef);
|
||||||
|
}
|
||||||
recordableVersionService.createRecordFromLatestVersion(filePlan, actionedUponNodeRef);
|
recordableVersionService.createRecordFromLatestVersion(filePlan, actionedUponNodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,6 +235,32 @@ public class DeclareAsVersionRecordAction extends AuditableActionExecuterAbstrac
|
|||||||
{
|
{
|
||||||
// NOTE: commented out for now so that it doesn't appear in the UI ... enable later when multi-file plan support is added
|
// NOTE: commented out for now so that it doesn't appear in the UI ... enable later when multi-file plan support is added
|
||||||
//params.add(new ParameterDefinitionImpl(PARAM_FILE_PLAN, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_FILE_PLAN)));
|
//params.add(new ParameterDefinitionImpl(PARAM_FILE_PLAN, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_FILE_PLAN)));
|
||||||
|
params.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check aspects that stop declaring the version as record.*/
|
||||||
|
private boolean checkAspects(NodeRef actionedUponNodeRef)
|
||||||
|
{
|
||||||
|
Map<QName, String> mapedAspects = new HashMap<>();
|
||||||
|
|
||||||
|
mapedAspects.put(ContentModel.ASPECT_VERSIONABLE, " does not have the versionable aspect applied.");
|
||||||
|
mapedAspects.put(ASPECT_RECORD, " is already a record.");
|
||||||
|
mapedAspects.put(ContentModel.ASPECT_WORKING_COPY, " is a working copy.");
|
||||||
|
mapedAspects.put(ASPECT_RECORD_REJECTION_DETAILS, " has previously been rejected.");
|
||||||
|
mapedAspects.put(ASPECT_SYNCED, " is synched content.");
|
||||||
|
|
||||||
|
for (Map.Entry<QName, String> aspect : mapedAspects.entrySet())
|
||||||
|
{
|
||||||
|
if (!nodeService.hasAspect(actionedUponNodeRef, aspect.getKey()))
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Can not declare version record, because " + actionedUponNodeRef.toString() + aspect.getValue());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 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.dm;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
public class RecordActionUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private static final Log LOGGER = LogFactory.getLog(CreateRecordAction.class);
|
||||||
|
|
||||||
|
static class Services
|
||||||
|
{
|
||||||
|
private NodeService nodeService;
|
||||||
|
private FilePlanService filePlanService;
|
||||||
|
private AuthenticationUtil authenticationUtil;
|
||||||
|
|
||||||
|
Services(NodeService nodeService, FilePlanService filePlanService, AuthenticationUtil authenticationUtil)
|
||||||
|
{
|
||||||
|
this.nodeService = nodeService;
|
||||||
|
this.filePlanService = filePlanService;
|
||||||
|
this.authenticationUtil = authenticationUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeService getNodeService()
|
||||||
|
{
|
||||||
|
return nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilePlanService getFilePlanService()
|
||||||
|
{
|
||||||
|
return filePlanService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationUtil getAuthenticationUtil()
|
||||||
|
{
|
||||||
|
return authenticationUtil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the target record folder node reference from the action path parameter
|
||||||
|
*
|
||||||
|
* @param filePlan The filePlan containing the path
|
||||||
|
* @param pathParameter The path
|
||||||
|
* @return The NodeRef of the resolved path
|
||||||
|
*/
|
||||||
|
static NodeRef resolvePath(Services services, NodeRef filePlan, final String pathParameter, String actionName)
|
||||||
|
{
|
||||||
|
NodeRef destinationFolder;
|
||||||
|
|
||||||
|
if (filePlan == null)
|
||||||
|
{
|
||||||
|
filePlan = getDefaultFilePlan(services.getAuthenticationUtil(), services.getFilePlanService(), actionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
|
||||||
|
if ((pathElementsArray != null) && (pathElementsArray.length > 0))
|
||||||
|
{
|
||||||
|
destinationFolder = resolvePath(services.getNodeService(), filePlan, Arrays.asList(pathElementsArray), actionName);
|
||||||
|
|
||||||
|
// destination must be a record folder
|
||||||
|
QName nodeType = services.getNodeService().getType(destinationFolder);
|
||||||
|
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path is not a record folder.");
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path could not be found.");
|
||||||
|
}
|
||||||
|
return destinationFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to recursively get the next path element node reference from the action path parameter
|
||||||
|
*
|
||||||
|
* @param parent The parent of the path elements
|
||||||
|
* @param pathElements The path elements still to be resolved
|
||||||
|
* @return The NodeRef of the resolved path element
|
||||||
|
*/
|
||||||
|
static NodeRef resolvePath(NodeService nodeService, NodeRef parent, List<String> pathElements, String actionName)
|
||||||
|
{
|
||||||
|
NodeRef nodeRef;
|
||||||
|
String childName = pathElements.get(0);
|
||||||
|
|
||||||
|
nodeRef = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, childName);
|
||||||
|
|
||||||
|
if (nodeRef == null)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path could not be found.");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
QName nodeType = nodeService.getType(nodeRef);
|
||||||
|
if (nodeType.equals(RecordsManagementModel.TYPE_HOLD_CONTAINER) ||
|
||||||
|
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
|
||||||
|
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the destination path is invalid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pathElements.size() > 1)
|
||||||
|
{
|
||||||
|
nodeRef = resolvePath(nodeService, nodeRef, pathElements.subList(1, pathElements.size()), actionName);
|
||||||
|
}
|
||||||
|
return nodeRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the default RM filePlan
|
||||||
|
*
|
||||||
|
* @return The NodeRef of the default RM filePlan
|
||||||
|
*/
|
||||||
|
static NodeRef getDefaultFilePlan(AuthenticationUtil authenticationUtil, FilePlanService filePlanService, String actionName)
|
||||||
|
{
|
||||||
|
NodeRef filePlan = authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public NodeRef doWork()
|
||||||
|
{
|
||||||
|
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// if the file plan is still null, raise an exception
|
||||||
|
if (filePlan == null)
|
||||||
|
{
|
||||||
|
if (LOGGER.isDebugEnabled())
|
||||||
|
{
|
||||||
|
LOGGER.debug("Unable to execute " + actionName + " action, because the fileplan path could not be determined. Make sure at least one file plan has been created.");
|
||||||
|
throw new AlfrescoRuntimeException("Unable to execute " + actionName + " action, because the fileplan path could not be determined.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filePlan;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user