RM-1099 (Refactor Transfer and Accession reports)

* The record type and the destination is now passed from the UI

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@58392 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-11-28 15:14:22 +00:00
parent cfa932d0a0
commit 120d3340ea
7 changed files with 116 additions and 103 deletions

View File

@@ -34,4 +34,5 @@ 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.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.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.event-not-undone=The event {0} can't be undone, because it's not defined on the disposition lifecycle.
rm.action.node-not-record-category=The disposition schedule could not be created, because the actioned upon node ({0}) was not a record category. rm.action.node-not-record-category=The disposition schedule could not be created, because the actioned upon node ({0}) was not a record category.
rm.action.parameter-not-supplied=The parameter ''{0}'' has not been supplied.

View File

@@ -149,8 +149,6 @@
class="org.alfresco.module.org_alfresco_module_rm.report.action.FileTransferAction" class="org.alfresco.module.org_alfresco_module_rm.report.action.FileTransferAction"
parent="rmAction"> parent="rmAction">
<property name="reportService" ref="ReportService" /> <property name="reportService" ref="ReportService" />
<property name="filePlanService" ref="FilePlanService" />
<property name="reportType" value="rmr:transferReport" />
</bean> </bean>
</beans> </beans>

View File

@@ -89,14 +89,15 @@ public interface RecordService
void createRecord(NodeRef filePlan, NodeRef nodeRef); void createRecord(NodeRef filePlan, NodeRef nodeRef);
/** /**
* Creates a new document as a unfiled record. * Creates a new document in the unfiled records container if the given node reference is a file plan
* node reference otherwise the node reference will be used as the destination for the new record.
* *
* @param filePlan * @param nodeRef
* @param name * @param name
* @param type * @param type
* @param properties * @param properties
*/ */
NodeRef createRecord(NodeRef filePlan, String name, QName type, Map<QName, Serializable> properties, ContentReader reader); NodeRef createRecord(NodeRef nodeRef, String name, QName type, Map<QName, Serializable> properties, ContentReader reader);
/** /**
* Indicates whether the record is filed or not * Indicates whether the record is filed or not

View File

@@ -772,11 +772,22 @@ public class RecordServiceImpl implements RecordService,
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map, org.alfresco.service.cmr.repository.ContentReader) * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, org.alfresco.service.namespace.QName, java.util.Map, org.alfresco.service.cmr.repository.ContentReader)
*/ */
@Override @Override
public NodeRef createRecord(NodeRef filePlan, String name, QName type, Map<QName, Serializable> properties, ContentReader reader) public NodeRef createRecord(NodeRef nodeRef, String name, QName type, Map<QName, Serializable> properties, ContentReader reader)
{ {
ParameterCheck.mandatory("filePlan", filePlan); ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("name", name); ParameterCheck.mandatory("name", name);
NodeRef destination = nodeRef;
if (filePlanService.isFilePlan(nodeRef) == true)
{
// get the unfiled record container for the file plan
destination = filePlanService.getUnfiledContainer(nodeRef);
if (destination == null)
{
throw new AlfrescoRuntimeException("Unable to create record, because unfiled container could not be found.");
}
}
// if none set the default record type is cm:content // if none set the default record type is cm:content
if (type == null) if (type == null)
{ {
@@ -784,15 +795,8 @@ public class RecordServiceImpl implements RecordService,
} }
// TODO ensure that the type is a sub-type of cm:content // TODO ensure that the type is a sub-type of cm:content
// get the unfiled record container for the file plan
NodeRef unfiledContainer = filePlanService.getUnfiledContainer(filePlan);
if (unfiledContainer == null)
{
throw new AlfrescoRuntimeException("Unable to create record, because unfiled container could not be found.");
}
// create the new record // create the new record
NodeRef record = fileFolderService.create(unfiledContainer, name, type).getNodeRef(); NodeRef record = fileFolderService.create(destination, name, type).getNodeRef();
// set the properties // set the properties
if (properties != null) if (properties != null)

View File

@@ -25,37 +25,37 @@ import org.alfresco.service.namespace.QName;
/** /**
* Report service. * Report service.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
public interface ReportService public interface ReportService
{ {
/** /**
* Register a report generator with the report service. * Register a report generator with the report service.
* *
* @param reportGenerator report generator * @param reportGenerator report generator
*/ */
void registerReportGenerator(ReportGenerator reportGenerator); void registerReportGenerator(ReportGenerator reportGenerator);
/** /**
* Get a list of the available report types. * Get a list of the available report types.
* *
* @return * @return
*/ */
Set<QName> getReportTypes(); Set<QName> getReportTypes();
/** /**
* *
* *
* @param reportType * @param reportType
* @param reportedUponNodeRef * @param reportedUponNodeRef
* @return * @return
*/ */
Report generateReport(QName reportType, NodeRef reportedUponNodeRef); Report generateReport(QName reportType, NodeRef reportedUponNodeRef);
/** /**
* *
* @param reportType * @param reportType
* @param reportedUponNodeRef * @param reportedUponNodeRef
* @return * @return
@@ -63,11 +63,12 @@ public interface ReportService
Report generateReport(QName reportType, NodeRef reportedUponNodeRef, String mimetype); Report generateReport(QName reportType, NodeRef reportedUponNodeRef, String mimetype);
/** /**
* File report as unfiled record in a file plan. * File report in the given destination. If the given node reference is a file plan node
* * reference the report will be filed in the unfiled records container.
* @param filePlan file plan *
* @param nodeRef node reference
* @param report report * @param report report
* @return NodeRef node reference of unfiled record * @return NodeRef node reference of the filed report
*/ */
NodeRef fileReport(NodeRef filePlan, Report report); NodeRef fileReport(NodeRef nodeRef, Report report);
} }

View File

@@ -35,7 +35,7 @@ import org.springframework.extensions.surf.util.ParameterCheck;
/** /**
* Report service implementation. * Report service implementation.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
@@ -44,16 +44,16 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
/** file folder service */ /** file folder service */
protected FileFolderService fileFolderService; protected FileFolderService fileFolderService;
/** file plan service */ /** file plan service */
protected FilePlanService filePlanService; protected FilePlanService filePlanService;
/** content service */ /** content service */
protected ContentService contentService; protected ContentService contentService;
/** record service */ /** record service */
protected RecordService recordService; protected RecordService recordService;
/** report generator registry */ /** report generator registry */
private Map<QName, ReportGenerator> registry = new HashMap<QName, ReportGenerator>(); private Map<QName, ReportGenerator> registry = new HashMap<QName, ReportGenerator>();
@@ -64,7 +64,7 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
this.fileFolderService = fileFolderService; this.fileFolderService = fileFolderService;
} }
/** /**
* @param filePlanService file plan service * @param filePlanService file plan service
*/ */
@@ -72,7 +72,7 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
this.filePlanService = filePlanService; this.filePlanService = filePlanService;
} }
/** /**
* @param contentService content service * @param contentService content service
*/ */
@@ -80,7 +80,7 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
this.contentService = contentService; this.contentService = contentService;
} }
/** /**
* @param recordService record service * @param recordService record service
*/ */
@@ -88,17 +88,17 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
this.recordService = recordService; this.recordService = recordService;
} }
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#registerReportGenerator(org.alfresco.module.org_alfresco_module_rm.report.ReportGenerator) * @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#registerReportGenerator(org.alfresco.module.org_alfresco_module_rm.report.ReportGenerator)
*/ */
@Override @Override
public void registerReportGenerator(ReportGenerator reportGenerator) public void registerReportGenerator(ReportGenerator reportGenerator)
{ {
ParameterCheck.mandatory("reportGenerator", reportGenerator); ParameterCheck.mandatory("reportGenerator", reportGenerator);
registry.put(reportGenerator.getReportType(), reportGenerator); registry.put(reportGenerator.getReportType(), reportGenerator);
} }
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#getReportTypes() * @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#getReportTypes()
*/ */
@@ -116,7 +116,7 @@ public class ReportServiceImpl extends ServiceBaseImpl
{ {
return generateReport(reportType, reportedUponNodeRef, MimetypeMap.MIMETYPE_HTML); return generateReport(reportType, reportedUponNodeRef, MimetypeMap.MIMETYPE_HTML);
} }
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#generateReport(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef) * @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#generateReport(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef)
*/ */
@@ -126,39 +126,33 @@ public class ReportServiceImpl extends ServiceBaseImpl
ParameterCheck.mandatory("reportType", reportType); ParameterCheck.mandatory("reportType", reportType);
ParameterCheck.mandatory("reportedUponNodeRef", reportedUponNodeRef); ParameterCheck.mandatory("reportedUponNodeRef", reportedUponNodeRef);
ParameterCheck.mandatory("mimetype", mimetype); ParameterCheck.mandatory("mimetype", mimetype);
// get the generator // get the generator
ReportGenerator generator = registry.get(reportType); ReportGenerator generator = registry.get(reportType);
// error is generator not found in registry // error is generator not found in registry
if (generator == null) if (generator == null)
{ {
throw new AlfrescoRuntimeException("Unable to generate report, because report type " + reportType.toString() + " does not correspond to a registered report type."); throw new AlfrescoRuntimeException("Unable to generate report, because report type " + reportType.toString() + " does not correspond to a registered report type.");
} }
// generate the report // generate the report
return generator.generateReport(reportedUponNodeRef, mimetype); return generator.generateReport(reportedUponNodeRef, mimetype);
} }
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#fileReport(org.alfresco.module.org_alfresco_module_rm.report.Report) * @see org.alfresco.module.org_alfresco_module_rm.report.ReportService#fileReport(org.alfresco.module.org_alfresco_module_rm.report.Report)
*/ */
@Override @Override
public NodeRef fileReport(NodeRef filePlan, Report report) public NodeRef fileReport(NodeRef nodeRef, Report report)
{ {
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("report", report); ParameterCheck.mandatory("report", report);
ParameterCheck.mandatory("filePlan", filePlan);
return recordService.createRecord(nodeRef,
// check that the passed node reference is a file plan report.getReportName(),
if (filePlanService.isFilePlan(filePlan) == false) report.getReportType(),
{ report.getReportProperties(),
throw new AlfrescoRuntimeException("Unable to file report, because " + filePlan.toString() + " is not a file plan.");
}
return recordService.createRecord(filePlan,
report.getReportName(),
report.getReportType(),
report.getReportProperties(),
report.getReportContent()); report.getReportContent());
} }
} }

View File

@@ -20,32 +20,33 @@ package org.alfresco.module.org_alfresco_module_rm.report.action;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase; import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.report.Report; import org.alfresco.module.org_alfresco_module_rm.report.Report;
import org.alfresco.module.org_alfresco_module_rm.report.ReportModel; import org.alfresco.module.org_alfresco_module_rm.report.ReportModel;
import org.alfresco.module.org_alfresco_module_rm.report.ReportService; import org.alfresco.module.org_alfresco_module_rm.report.ReportService;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck; import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* FIXME!!! * File transfer action
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 2.2 * @since 2.2
*/ */
public class FileTransferAction extends RMActionExecuterAbstractBase implements ReportModel public class FileTransferAction extends RMActionExecuterAbstractBase implements ReportModel
{ {
/** Constants for the parameters passed from UI */
private static final String REPORT_TYPE = "reportType";
private static final String DESTINATION = "destination";
/** I18N */
private static final String MSG_PARAM_NOT_SUPPLIED = "rm.action.parameter-not-supplied";
/** report service */ /** report service */
protected ReportService reportService; protected ReportService reportService;
/** file plan service */
protected FilePlanService filePlanService;
/** report type string value */
private String reportType;
/** /**
* @param reportService report service * @param reportService report service
*/ */
@@ -54,31 +55,6 @@ public class FileTransferAction extends RMActionExecuterAbstractBase implements
this.reportService = reportService; this.reportService = reportService;
} }
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @param reportType report type string value
*/
public void setReportType(String reportType)
{
this.reportType = reportType;
}
/**
* @return QName report type
*/
protected QName getReportType()
{
ParameterCheck.mandatory("this.reportType", reportType);
return QName.createQName(reportType, namespaceService);
}
/** /**
* @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)
*/ */
@@ -90,13 +66,51 @@ public class FileTransferAction extends RMActionExecuterAbstractBase implements
// TODO allow the mimetype of the report to be specified as a parameter // TODO allow the mimetype of the report to be specified as a parameter
NodeRef filePlan = filePlanService.getFilePlan(actionedUponNodeRef); QName reportType = getReportType(action);
if (filePlan == null) Report report = reportService.generateReport(reportType, actionedUponNodeRef);
{
throw new AlfrescoRuntimeException("Unable to file destruction report, because file plan could not be resolved.");
}
Report report = reportService.generateReport(getReportType(), actionedUponNodeRef); NodeRef destination = getDestination(action);
reportService.fileReport(filePlan, report); reportService.fileReport(destination, report);
}
/**
* Retrieves the value of the given parameter. If the parameter has not been passed from the UI an error will be thrown
*
* @param action The action
* @param parameter The parameter for which the value should be retrieved
* @return The value of the given parameter
*/
private String getParameterValue(Action action, String parameter)
{
String paramValue = (String) action.getParameterValue(parameter);
if (StringUtils.isBlank(paramValue) == true)
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PARAM_NOT_SUPPLIED, parameter));
}
return paramValue;
}
/**
* Helper method for getting the destination.
*
* @param action The action
* @return The file plan node reference
*/
private NodeRef getDestination(Action action)
{
String destination = getParameterValue(action, DESTINATION);
return new NodeRef(destination);
}
/**
* Helper method for getting the report type.
*
* @param action The action
* @return The report type
*/
private QName getReportType(Action action)
{
String reportType = getParameterValue(action, REPORT_TYPE);
return QName.createQName(reportType, namespaceService);
} }
} }