mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-557: Unfiled records service API
* fleshed out unit tests for record service * fixed up a couple of issues when creating records * unfiled record API integrated into the Record Service * investigated moving filling API from actions into service (roughed out API) * updated create record action git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44403 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -250,24 +250,6 @@ public abstract class RMActionExecuterAbstractBase extends ActionExecuterAbstra
|
||||
this.recordService = recordService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register with a single capability
|
||||
* @param capability
|
||||
*/
|
||||
// public void setCapability(AbstractCapability capability)
|
||||
// {
|
||||
// capabilities.add(capability);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Register with several capabilities
|
||||
* @param capabilities
|
||||
*/
|
||||
// public void setCapabilities(Collection<AbstractCapability> capabilities)
|
||||
// {
|
||||
// this.capabilities.addAll(capabilities);
|
||||
// }
|
||||
|
||||
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
|
||||
{
|
||||
this.recordsManagementAdminService = recordsManagementAdminService;
|
||||
@@ -296,11 +278,6 @@ public abstract class RMActionExecuterAbstractBase extends ActionExecuterAbstra
|
||||
PropertyCheck.mandatory(this, "recordsManagementService", recordsManagementService);
|
||||
PropertyCheck.mandatory(this, "recordsManagementAdminService", recordsManagementAdminService);
|
||||
PropertyCheck.mandatory(this, "recordsManagementEventService", recordsManagementEventService);
|
||||
|
||||
// for(AbstractCapability capability : capabilities)
|
||||
// {
|
||||
// capability.registerAction(this);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,8 +27,6 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -114,48 +112,38 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
|
||||
}
|
||||
else
|
||||
{
|
||||
// run record creation as system
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
|
||||
if (filePlan == null)
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
|
||||
if (filePlan == null)
|
||||
{
|
||||
List<NodeRef> filePlans = recordsManagementService.getFilePlans();
|
||||
if (filePlans.size() == 1)
|
||||
{
|
||||
filePlan = filePlans.get(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Can not create record, because the default file plan can not be determined.");
|
||||
}
|
||||
throw new AlfrescoRuntimeException("Can not create record, because the default file plan can not be determined.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// verify that the provided file plan is actually a file plan
|
||||
if (recordsManagementService.isFilePlan(filePlan) == false)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Can not create record, because the provided file plan node reference is not a file plan.");
|
||||
}
|
||||
throw new AlfrescoRuntimeException("Can not create record, because the provided file plan node reference is not a file plan.");
|
||||
}
|
||||
}
|
||||
|
||||
// create record from existing document
|
||||
recordService.createRecordFromDocument(filePlan, actionedUponNodeRef);
|
||||
|
||||
return null;
|
||||
List<NodeRef> filePlans = recordsManagementService.getFilePlans();
|
||||
if (filePlans.size() == 1)
|
||||
{
|
||||
filePlan = filePlans.get(0);
|
||||
}
|
||||
});
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Can not create record, because the default file plan can not be determined.");
|
||||
}
|
||||
throw new AlfrescoRuntimeException("Can not create record, because the default file plan can not be determined.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// verify that the provided file plan is actually a file plan
|
||||
if (recordsManagementService.isFilePlan(filePlan) == false)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Can not create record, because the provided file plan node reference is not a file plan.");
|
||||
}
|
||||
throw new AlfrescoRuntimeException("Can not create record, because the provided file plan node reference is not a file plan.");
|
||||
}
|
||||
}
|
||||
|
||||
// create record from existing document
|
||||
recordService.createRecord(filePlan, actionedUponNodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -145,7 +145,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC
|
||||
rmNodeValues.put("filePlan", filePlan.toString());
|
||||
|
||||
// Unfiled container node reference
|
||||
NodeRef unfiledRecordContainer = recordService.getUnfiledRecordContainer(filePlan);
|
||||
NodeRef unfiledRecordContainer = recordService.getUnfiledContainer(filePlan);
|
||||
rmNodeValues.put("unfiledRecordContainer", unfiledRecordContainer.toString());
|
||||
rmNodeValues.put("properties", propertiesToJSON(unfiledRecordContainer, useShortQName));
|
||||
QName type = fileFolderService.getFileInfo(unfiledRecordContainer).getType();
|
||||
|
@@ -231,5 +231,4 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
|
||||
// Extended readers aspect
|
||||
public static final QName ASPECT_EXTENDED_READERS = QName.createQName(RM_URI, "extendedReaders");
|
||||
public static final QName PROP_READERS = QName.createQName(RM_URI, "readers");
|
||||
|
||||
}
|
||||
|
@@ -54,32 +54,36 @@ public interface RecordService
|
||||
* @return boolean true if record is declared, false otherwise
|
||||
*/
|
||||
boolean isDeclared(NodeRef nodeRef);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new record from an existing document.
|
||||
* Indicates whether the record is filed or not
|
||||
*
|
||||
* @param filePlan The filePlan in which the record should be placed
|
||||
* @param document The document from which the record will be created
|
||||
* @param nodeRef record
|
||||
* @return boolean true if filed, false otherwise
|
||||
*/
|
||||
void createRecordFromDocument(NodeRef filePlan, NodeRef document);
|
||||
|
||||
boolean isFiled(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Gets the unfiled record container for the given file plan
|
||||
* Gets the unfiled root container for the given file plan
|
||||
*
|
||||
* @param filePlan The filePlan for which the unfiled record container should be retrieved
|
||||
* @return NodeRef The nodeRef of the container object
|
||||
*/
|
||||
public NodeRef getUnfiledRecordContainer(NodeRef filePlan);
|
||||
public NodeRef getUnfiledContainer(NodeRef filePlan);
|
||||
|
||||
// TODO boolean isRecordFiled(NodeRef record);
|
||||
|
||||
// TODO boolean isRecordClassified(NodeRef record);
|
||||
|
||||
// TODO NodeRef getNewRecordContainer(NodeRef filePlan);
|
||||
|
||||
// TODO NodeRef createRecord(NodeRef filePlan, NodeRef document);
|
||||
|
||||
// TODO NodeRef createAndFileRecord(NodeRef recordFolder, NodeRef document);
|
||||
|
||||
// TODO void fileRecord(NodeRef recordFolder, NodeRef record);
|
||||
/**
|
||||
* Creates a new unfiled record from an existing node.
|
||||
*
|
||||
* @param filePlan The filePlan in which the record should be placed
|
||||
* @param nodeRef The node from which the record will be created
|
||||
*/
|
||||
void createRecord(NodeRef filePlan, NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Files an unfiled record.
|
||||
*
|
||||
* @param record record
|
||||
* @param recordFolder record folder
|
||||
*/
|
||||
void fileRecord(NodeRef record, NodeRef recordFolder);
|
||||
}
|
||||
|
@@ -25,14 +25,19 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
@@ -60,6 +65,9 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
|
||||
|
||||
/** Extended security service */
|
||||
private ExtendedSecurityService extendedSecurityService;
|
||||
|
||||
/** Records management service */
|
||||
private RecordsManagementService recordsManagementService;
|
||||
|
||||
/** List of available record meta-data aspects */
|
||||
private Set<QName> recordMetaDataAspects;
|
||||
@@ -104,9 +112,20 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
|
||||
this.extendedSecurityService = extendedSecurityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordsManagementService records management service
|
||||
*/
|
||||
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
|
||||
{
|
||||
this.recordsManagementService = recordsManagementService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,52 +175,39 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
|
||||
|
||||
return nodeService.hasAspect(record, ASPECT_DECLARED_RECORD);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecordFromDocument(org.alfresco.service.cmr.repository.NodeRef,
|
||||
* org.alfresco.service.cmr.repository.NodeRef)
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#isFiled(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void createRecordFromDocument(NodeRef filePlan, NodeRef document)
|
||||
public boolean isFiled(NodeRef nodeRef)
|
||||
{
|
||||
ParameterCheck.mandatory("filePlan", filePlan);
|
||||
ParameterCheck.mandatory("document", document);
|
||||
|
||||
// skip everything if the document is already a record
|
||||
if (nodeService.hasAspect(document, ASPECT_RECORD) == false)
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
if (isRecord(nodeRef) == true)
|
||||
{
|
||||
// get the new record container for the file plan
|
||||
NodeRef newRecordContainer = getUnfiledRecordContainer(filePlan);
|
||||
if (newRecordContainer == null) { throw new AlfrescoRuntimeException(
|
||||
"Unable to create record, because new record container could not be found."); }
|
||||
|
||||
// get the documents primary parent assoc
|
||||
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(document);
|
||||
|
||||
// move the document into the file plan
|
||||
nodeService.moveNode(document, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
|
||||
|
||||
// maintain the original primary location
|
||||
nodeService.addChild(parentAssoc.getParentRef(), document, parentAssoc.getTypeQName(), parentAssoc
|
||||
.getQName());
|
||||
|
||||
// make the document a record
|
||||
makeRecord(document);
|
||||
|
||||
// get the documents readers
|
||||
Long aclId = nodeService.getNodeAclId(document);
|
||||
Set<String> readers = permissionService.getReaders(aclId);
|
||||
|
||||
// set the readers
|
||||
extendedSecurityService.setExtendedReaders(document, readers);
|
||||
ChildAssociationRef childAssocRef = nodeService.getPrimaryParent(nodeRef);
|
||||
if (childAssocRef != null)
|
||||
{
|
||||
NodeRef parent = childAssocRef.getParentRef();
|
||||
if (parent != null &&
|
||||
recordsManagementService.isRecordFolder(parent) == true)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#getUnfiledRecordContainer(org.alfresco.service.cmr.repository.NodeRef)
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#getUnfiledRootContainer(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public NodeRef getUnfiledRecordContainer(NodeRef filePlan)
|
||||
public NodeRef getUnfiledContainer(NodeRef filePlan)
|
||||
{
|
||||
ParameterCheck.mandatory("filePlan", filePlan);
|
||||
|
||||
@@ -213,6 +219,93 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
|
||||
return assocs.get(0).getChildRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecord(org.alfresco.service.cmr.repository.NodeRef,
|
||||
* org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void createRecord(final NodeRef filePlan, final NodeRef nodeRef)
|
||||
{
|
||||
ParameterCheck.mandatory("filePlan", filePlan);
|
||||
ParameterCheck.mandatory("document", nodeRef);
|
||||
|
||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD) == false)
|
||||
{
|
||||
// first we do a sanity check to ensure that the user has at least write permissions on the document
|
||||
if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) != AccessStatus.ALLOWED)
|
||||
{
|
||||
throw new AccessDeniedException("Can not create record from document, because the user " +
|
||||
AuthenticationUtil.getFullyAuthenticatedUser() +
|
||||
" does not have Write permissions on the doucment " +
|
||||
nodeRef.toString());
|
||||
}
|
||||
|
||||
// do the work of creating the record as the system user
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
// get the new record container for the file plan
|
||||
NodeRef newRecordContainer = getUnfiledContainer(filePlan);
|
||||
if (newRecordContainer == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
|
||||
}
|
||||
|
||||
// get the documents readers
|
||||
Long aclId = nodeService.getNodeAclId(nodeRef);
|
||||
Set<String> readers = permissionService.getReaders(aclId);
|
||||
|
||||
// get the documents primary parent assoc
|
||||
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
|
||||
|
||||
// move the document into the file plan
|
||||
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
|
||||
|
||||
// maintain the original primary location
|
||||
nodeService.addChild(parentAssoc.getParentRef(), nodeRef, parentAssoc.getTypeQName(), parentAssoc.getQName());
|
||||
|
||||
// make the document a record
|
||||
makeRecord(nodeRef);
|
||||
|
||||
// set the readers
|
||||
extendedSecurityService.setExtendedReaders(nodeRef, readers);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#fileRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void fileRecord(NodeRef record, NodeRef recordFolder)
|
||||
{
|
||||
// check if this is a record
|
||||
if (isRecord(record) == false)
|
||||
{
|
||||
// TODO .. should we make this a record?
|
||||
throw new UnsupportedOperationException("Currently unable to file something that isn't already a record");
|
||||
}
|
||||
|
||||
if (isFiled(record) == false)
|
||||
{
|
||||
// TODO .. refactor the existing code to file a record here ... this will include moving the code that
|
||||
// currently manages the properties of the disposition lifecycle aspect into the disposition service
|
||||
throw new UnsupportedOperationException("Currently unsuported.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO .. figure out how we 'refile' a currently filed record
|
||||
throw new UnsupportedOperationException("Currently unable to file an already filed record.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper Methods
|
||||
*/
|
||||
|
Reference in New Issue
Block a user