diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java index f95dbfa4e9..11189a4135 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/TransferReportPost.java @@ -59,14 +59,14 @@ import org.springframework.extensions.webscripts.WebScriptResponse; /** * Files a transfer report as a record. - * + * * @author Gavin Cornwell */ public class TransferReportPost extends BaseTransferWebScript { /** Logger */ private static Log logger = LogFactory.getLog(TransferReportPost.class); - + protected static final String REPORT_FILE_PREFIX = "report_"; protected static final String REPORT_FILE_SUFFIX = ".html"; protected static final String PARAM_DESTINATION = "destination"; @@ -74,65 +74,65 @@ public class TransferReportPost extends BaseTransferWebScript protected static final String RESPONSE_RECORD = "record"; protected static final String RESPONSE_RECORD_NAME = "recordName"; protected static final String FILE_ACTION = "file"; - + protected DictionaryService ddService; protected RecordsManagementActionService rmActionService; protected RecordsManagementService rmService; protected DispositionService dispositionService; - + /** * Sets the DictionaryService instance - * + * * @param ddService The DictionaryService instance */ public void setDictionaryService(DictionaryService ddService) { this.ddService = ddService; } - + /** * Sets the RecordsManagementService instance - * + * * @param rmService RecordsManagementService instance */ public void setRecordsManagementService(RecordsManagementService rmService) { this.rmService = rmService; } - + /** * Sets the disposition service - * + * * @param dispositionService disposition service */ public void setDispositionService(DispositionService dispositionService) { this.dispositionService = dispositionService; } - + /** * Sets the RecordsManagementActionService instance - * + * * @param rmActionService RecordsManagementActionService instance */ public void setRecordsManagementActionService(RecordsManagementActionService rmActionService) { this.rmActionService = rmActionService; } - + @Override protected File executeTransfer(NodeRef transferNode, - WebScriptRequest req, WebScriptResponse res, + WebScriptRequest req, WebScriptResponse res, Status status, Cache cache) throws IOException { File report = null; - + // retrieve requested format String format = req.getFormat(); Map model = new HashMap(); model.put("status", status); model.put("cache", cache); - + try { // extract the destination parameter, ensure it's present and it is @@ -140,63 +140,63 @@ public class TransferReportPost extends BaseTransferWebScript JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent())); if (!json.has(PARAM_DESTINATION)) { - status.setCode(HttpServletResponse.SC_BAD_REQUEST, + status.setCode(HttpServletResponse.SC_BAD_REQUEST, "Mandatory '" + PARAM_DESTINATION + "' parameter has not been supplied"); Map templateModel = createTemplateParameters(req, res, model); sendStatus(req, res, status, cache, format, templateModel); return null; } - + String destinationParam = json.getString(PARAM_DESTINATION); NodeRef destination = new NodeRef(destinationParam); - + if (!this.nodeService.exists(destination)) { - status.setCode(HttpServletResponse.SC_NOT_FOUND, + status.setCode(HttpServletResponse.SC_NOT_FOUND, "Node " + destination.toString() + " does not exist"); Map templateModel = createTemplateParameters(req, res, model); sendStatus(req, res, status, cache, format, templateModel); return null; } - + // ensure the node is a filePlan object if (!RecordsManagementModel.TYPE_RECORD_FOLDER.equals(this.nodeService.getType(destination))) { - status.setCode(HttpServletResponse.SC_BAD_REQUEST, + status.setCode(HttpServletResponse.SC_BAD_REQUEST, "Node " + destination.toString() + " is not a record folder"); Map templateModel = createTemplateParameters(req, res, model); sendStatus(req, res, status, cache, format, templateModel); return null; } - + if (logger.isDebugEnabled()) logger.debug("Filing transfer report as record in record folder: " + destination); - + // generate the report (will be in JSON format) report = generateHTMLTransferReport(transferNode); - + // file the report as a record NodeRef record = fileTransferReport(report, destination); - + if (logger.isDebugEnabled()) logger.debug("Filed transfer report as new record: " + record); - + // return success flag and record noderef as JSON JSONObject responseJSON = new JSONObject(); responseJSON.put(RESPONSE_SUCCESS, (record != null)); if (record != null) { responseJSON.put(RESPONSE_RECORD, record.toString()); - responseJSON.put(RESPONSE_RECORD_NAME, + responseJSON.put(RESPONSE_RECORD_NAME, (String)nodeService.getProperty(record, ContentModel.PROP_NAME)); } - + // setup response String jsonString = responseJSON.toString(); res.setContentType(MimetypeMap.MIMETYPE_JSON); res.setContentEncoding("UTF-8"); res.setHeader("Content-Length", Long.toString(jsonString.length())); - + // write the JSON response res.getWriter().write(jsonString); } @@ -204,14 +204,14 @@ public class TransferReportPost extends BaseTransferWebScript { throw createStatusException(je, req, res); } - + // return the file for deletion return report; } - + /** * Generates a File containing the JSON representation of a transfer report. - * + * * @param transferNode The transfer node * @return File containing JSON representation of a transfer report * @throws IOException @@ -224,16 +224,16 @@ public class TransferReportPost extends BaseTransferWebScript { // get all 'transferred' nodes NodeRef[] itemsToTransfer = getTransferNodes(transferNode); - + if (logger.isDebugEnabled()) { - logger.debug("Generating HTML transfer report for " + itemsToTransfer.length + + logger.debug("Generating HTML transfer report for " + itemsToTransfer.length + " items into file: " + report.getAbsolutePath()); } - + // create the writer writer = new FileWriter(report); - + // use RMService to get disposition authority String dispositionAuthority = null; if (itemsToTransfer.length > 0) @@ -245,11 +245,19 @@ public class TransferReportPost extends BaseTransferWebScript dispositionAuthority = ds.getDispositionAuthority(); } } - + // write the HTML header writer.write("\n"); writer.write("\n\n"); - writer.write("Transfer Report\n"); + Boolean isAccession = (Boolean)this.nodeService.getProperty(transferNode, PROP_TRANSFER_ACCESSION_INDICATOR); + if (isAccession == true) + { + writer.write("Accession Report\n"); + } + else + { + writer.write("Transfer Report\n"); + } writer.write("\n"); - writer.write("\n

Transfer Report

\n"); - + if (isAccession == true) + { + writer.write("\n

Accession Report

\n"); + } + else + { + writer.write("\n

Transfer Report

\n"); + } + writer.write(""); writer.write(""); writer.write(""); writer.write(""); writer.write("
Transfer Date:"); Date transferDate = (Date)this.nodeService.getProperty(transferNode, ContentModel.PROP_CREATED); writer.write(StringEscapeUtils.escapeHtml(transferDate.toString())); writer.write("
Transfer Location:"); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(transferNode, + if (isAccession == true) + { + writer.write("NARA"); + } + else + { + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(transferNode, RecordsManagementModel.PROP_TRANSFER_LOCATION))); + } writer.write("
Performed By:"); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(transferNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(transferNode, ContentModel.PROP_CREATOR))); writer.write("
Disposition Authority:"); writer.write(dispositionAuthority != null ? StringEscapeUtils.escapeHtml(dispositionAuthority) : ""); writer.write("
\n"); - + writer.write("

Transferred Items

\n"); - + // write out HTML representation of items to transfer generateTransferItemsHTML(writer, itemsToTransfer); - + // write the HTML footer writer.write(""); } @@ -292,13 +314,13 @@ public class TransferReportPost extends BaseTransferWebScript try { writer.close(); } catch (IOException ioe) {} } } - + return report; } - + /** * Generates the JSON to represent the given NodeRefs - * + * * @param writer Writer to write to * @param itemsToTransfer NodeRefs being transferred * @throws IOException @@ -320,10 +342,10 @@ public class TransferReportPost extends BaseTransferWebScript writer.write("\n"); } } - + /** * Generates the JSON to represent the given folder. - * + * * @param writer Writer to write to * @param folderNode Folder being transferred * @throws IOException @@ -332,19 +354,19 @@ public class TransferReportPost extends BaseTransferWebScript throws IOException { writer.write(""); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(folderNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(folderNode, ContentModel.PROP_NAME))); writer.write(" (Unique Folder Identifier: "); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(folderNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(folderNode, RecordsManagementModel.PROP_IDENTIFIER))); writer.write(")\n"); - + writer.write("
\n"); - + // NOTE: we don't expect any nested folder structures so just render // the records contained in the folder. - - List assocs = this.nodeService.getChildAssocs(folderNode, + + List assocs = this.nodeService.getChildAssocs(folderNode, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef child : assocs) { @@ -354,13 +376,13 @@ public class TransferReportPost extends BaseTransferWebScript generateTransferRecordHTML(writer, childRef); } } - + writer.write("\n
\n"); } - + /** * Generates the JSON to represent the given record. - * + * * @param writer Writer to write to * @param recordNode Record being transferred * @throws IOException @@ -370,29 +392,29 @@ public class TransferReportPost extends BaseTransferWebScript { writer.write("
\n"); writer.write(" "); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, ContentModel.PROP_NAME))); writer.write(" (Unique Record Identifier: "); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, RecordsManagementModel.PROP_IDENTIFIER))); writer.write(")"); - + if (this.nodeService.hasAspect(recordNode, RecordsManagementModel.ASPECT_DECLARED_RECORD)) { Date declaredOn = (Date)this.nodeService.getProperty(recordNode, RecordsManagementModel.PROP_DECLARED_AT); writer.write(" declared by "); - writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, + writer.write(StringEscapeUtils.escapeHtml((String)this.nodeService.getProperty(recordNode, RecordsManagementModel.PROP_DECLARED_BY))); writer.write(" on "); writer.write(StringEscapeUtils.escapeHtml(declaredOn.toString())); } - + writer.write("\n
\n"); } - + /** * Files the given transfer report as a record in the given record folder. - * + * * @param report Report to file * @param destination The destination record folder * @return NodeRef of the created record @@ -401,17 +423,17 @@ public class TransferReportPost extends BaseTransferWebScript { ParameterCheck.mandatory("report", report); ParameterCheck.mandatory("destination", destination); - + NodeRef record = null; - + Map properties = new HashMap(1); properties.put(ContentModel.PROP_NAME, report.getName()); - + // file the transfer report as an undeclared record - record = this.nodeService.createNode(destination, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, - QName.createValidLocalName(report.getName())), + record = this.nodeService.createNode(destination, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, + QName.createValidLocalName(report.getName())), ContentModel.TYPE_CONTENT, properties).getChildRef(); // Set the content @@ -419,10 +441,10 @@ public class TransferReportPost extends BaseTransferWebScript writer.setMimetype(MimetypeMap.MIMETYPE_HTML); writer.setEncoding("UTF-8"); writer.putContent(report); - + // file the node as a record - this.rmActionService.executeRecordsManagementAction(record, FILE_ACTION); - + this.rmActionService.executeRecordsManagementAction(record, FILE_ACTION); + return record; } } \ No newline at end of file