mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge remote-tracking branch 'remotes/origin/feature/RM-6792_AddLocnParamToDeclareAsRec' into feature/RM-6796_DeclareAndFileTests
This commit is contained in:
@@ -48,7 +48,7 @@ isRecordType.description=Records have a specified record type
|
|||||||
#
|
#
|
||||||
# Declare As Record
|
# Declare As Record
|
||||||
create-record.title=Declare as Record
|
create-record.title=Declare as Record
|
||||||
create-record.description=Declares file as a record
|
create-record.description=Declares file as a record and optionally files it
|
||||||
create-record.file-plan.display-label=File Plan
|
create-record.file-plan.display-label=File Plan
|
||||||
create-record.hide-record.display-label=Hide Record
|
create-record.hide-record.display-label=Hide Record
|
||||||
create-record.path.display-label=Destination Record Folder Path
|
create-record.path.display-label=Destination Record Folder Path
|
||||||
|
@@ -60,7 +60,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
implements RecordsManagementModel
|
implements RecordsManagementModel
|
||||||
{
|
{
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static Log logger = LogFactory.getLog(CreateRecordAction.class);
|
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";
|
||||||
@@ -125,9 +125,9 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
// resolve destination record folder if path supplied
|
// resolve destination record folder if path supplied
|
||||||
NodeRef destinationRecordFolder = null;
|
NodeRef destinationRecordFolder = null;
|
||||||
String pathParameter = (String) action.getParameterValue(PARAM_PATH);
|
String pathParameter = (String) action.getParameterValue(PARAM_PATH);
|
||||||
if (pathParameter != null)
|
if (pathParameter != null && !pathParameter.isEmpty())
|
||||||
{
|
{
|
||||||
destinationRecordFolder = resolvePath(action, filePlan, pathParameter);
|
destinationRecordFolder = resolvePath(filePlan, pathParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// indicate whether the record should be hidden or not (default not)
|
// indicate whether the record should be hidden or not (default not)
|
||||||
@@ -162,37 +162,49 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
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 */
|
/**
|
||||||
private NodeRef resolvePath(final Action action, NodeRef filePlan, final String pathParameter)
|
* 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;
|
NodeRef destinationFolder;
|
||||||
|
|
||||||
if (filePlan == null)
|
if (filePlan == null)
|
||||||
{
|
{
|
||||||
filePlan = getDefaultFilePlan(action);
|
filePlan = getDefaultFilePlan();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
|
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
|
||||||
if ((pathElementsArray != null) && (pathElementsArray.length > 0))
|
if ((pathElementsArray != null) && (pathElementsArray.length > 0))
|
||||||
{
|
{
|
||||||
destinationFolder = resolvePath(action, filePlan, Arrays.asList(pathElementsArray));
|
destinationFolder = resolvePath(filePlan, Arrays.asList(pathElementsArray));
|
||||||
|
|
||||||
// destination must be a record folder
|
// destination must be a record folder
|
||||||
QName nodeType = nodeService.getType(destinationFolder);
|
QName nodeType = nodeService.getType(destinationFolder);
|
||||||
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
|
if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path is not a record folder.");
|
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is not a record folder.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path could not be resolved.");
|
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found.");
|
||||||
}
|
}
|
||||||
return destinationFolder;
|
return destinationFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper method to recursively get the next path element node reference from the action path parameter */
|
/**
|
||||||
private NodeRef resolvePath(Action action, NodeRef parent, List<String> pathElements)
|
* 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;
|
NodeRef nodeRef;
|
||||||
String childName = pathElements.get(0);
|
String childName = pathElements.get(0);
|
||||||
@@ -201,7 +213,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
|
|
||||||
if (nodeRef == null)
|
if (nodeRef == null)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path could not be resolved.");
|
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be resolved.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -210,33 +222,37 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase
|
|||||||
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
|
nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) ||
|
||||||
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
|
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER))
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path is invalid.");
|
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is invalid.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pathElements.size() > 1)
|
if (pathElements.size() > 1)
|
||||||
{
|
{
|
||||||
nodeRef = resolvePath(action, nodeRef, pathElements.subList(1, pathElements.size()));
|
nodeRef = resolvePath(nodeRef, pathElements.subList(1, pathElements.size()));
|
||||||
}
|
}
|
||||||
return nodeRef;
|
return nodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper method to get the default RM filePlan */
|
/**
|
||||||
private NodeRef getDefaultFilePlan(final Action action)
|
* Helper method to get the default RM filePlan
|
||||||
|
*
|
||||||
|
* @return The NodeRef of the default RM filePlan
|
||||||
|
*/
|
||||||
|
private NodeRef getDefaultFilePlan()
|
||||||
{
|
{
|
||||||
NodeRef filePlan = authenticationUtil.runAs(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>()
|
NodeRef filePlan = authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<NodeRef>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public NodeRef doWork()
|
public NodeRef doWork()
|
||||||
{
|
{
|
||||||
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
|
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
|
||||||
}
|
}
|
||||||
}, authenticationUtil.getAdminUserName());
|
});
|
||||||
|
|
||||||
// if the file plan is still null, raise an exception
|
// if the file plan is still null, raise an exception
|
||||||
if (filePlan == null)
|
if (filePlan == null)
|
||||||
{
|
{
|
||||||
logger.debug("Unable to execute " + action.getActionDefinitionName() + " action, because the path fileplan could not be determined. Make sure at least one file plan has been created.");
|
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 " + action.getActionDefinitionName() + " action, because the path fileplan could not be determined.");
|
throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the fileplan path could not be determined.");
|
||||||
}
|
}
|
||||||
return filePlan;
|
return filePlan;
|
||||||
}
|
}
|
||||||
|
@@ -911,18 +911,22 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
|
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// if optional location supplied, check that it is a folder
|
// if optional location supplied, check that it is a valid record folder
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// first look to see if the destination record folder has been specified
|
|
||||||
QName nodeType = nodeService.getType(newRecordContainer);
|
QName nodeType = nodeService.getType(newRecordContainer);
|
||||||
if(!(nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER) ||
|
if(!(nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER) ||
|
||||||
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)))
|
nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)))
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to create record, because container is not a valid type for new record.");
|
throw new AlfrescoRuntimeException("Unable to create record, because container is not a valid type for new record.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boolean isClosed = (Boolean) nodeService.getProperty(newRecordContainer, PROP_IS_CLOSED);
|
||||||
|
if (isClosed != null && isClosed)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to create record, because container is closed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the documents readers and writers
|
// get the documents readers and writers
|
||||||
|
@@ -53,6 +53,13 @@ public class CreateRecordActionTest extends BaseRMTestCase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test create record action
|
||||||
|
*
|
||||||
|
* Given a collaboration site document
|
||||||
|
* When the create record action is executed for that document
|
||||||
|
* Then a record is created for it
|
||||||
|
*/
|
||||||
public void testCreateRecordAction()
|
public void testCreateRecordAction()
|
||||||
{
|
{
|
||||||
doTestInTransaction(new Test<Void>()
|
doTestInTransaction(new Test<Void>()
|
||||||
|
@@ -274,6 +274,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
|||||||
protected SiteInfo collaborationSite;
|
protected SiteInfo collaborationSite;
|
||||||
protected NodeRef documentLibrary;
|
protected NodeRef documentLibrary;
|
||||||
protected NodeRef dmFolder;
|
protected NodeRef dmFolder;
|
||||||
|
protected NodeRef dmFolder1;
|
||||||
protected NodeRef dmDocument;
|
protected NodeRef dmDocument;
|
||||||
protected NodeRef dmDocument1;
|
protected NodeRef dmDocument1;
|
||||||
|
|
||||||
@@ -781,7 +782,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
|||||||
// create a folder and documents
|
// create a folder and documents
|
||||||
dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef();
|
dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef();
|
||||||
dmDocument = fileFolderService.create(dmFolder, NAME_DM_DOCUMENT, ContentModel.TYPE_CONTENT).getNodeRef();
|
dmDocument = fileFolderService.create(dmFolder, NAME_DM_DOCUMENT, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||||
dmDocument1 = fileFolderService.create(dmFolder, NAME_DM_DOCUMENT1, ContentModel.TYPE_CONTENT).getNodeRef();
|
dmFolder1 = fileFolderService.create(documentLibrary, "collabFolder1", ContentModel.TYPE_FOLDER).getNodeRef();
|
||||||
|
dmDocument1 = fileFolderService.create(dmFolder1, NAME_DM_DOCUMENT1, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||||
|
|
||||||
dmConsumer = GUID.generate();
|
dmConsumer = GUID.generate();
|
||||||
dmConsumerNodeRef = createPerson(dmConsumer);
|
dmConsumerNodeRef = createPerson(dmConsumer);
|
||||||
|
Reference in New Issue
Block a user