RM-1099 (Refactor Transfer and Accession reports)

* Bug fixing

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@58637 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-12-05 17:51:22 +00:00
parent c9735c347d
commit 077f5839f4
5 changed files with 202 additions and 63 deletions

View File

@@ -31,6 +31,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/
public class TransferAction extends RMDispositionActionExecuterAbstractBase
{
/** Action name */
public static final String NAME = "transfer";
/** Indicates whether the transfer is an accession or not */
private boolean isAccession = false;

View File

@@ -32,6 +32,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/
public class DestructionReportAction extends BaseReportAction
{
/** Action name */
public static final String NAME = "destructionReport";
@Override
protected Map<String, Serializable> addProperties(NodeRef nodeRef)
{

View File

@@ -42,6 +42,9 @@ import org.apache.commons.lang.StringUtils;
*/
public class TransferReportAction extends BaseReportAction
{
/** Action name */
public static final String NAME = "transferReport";
@Override
protected Map<String, Serializable> addProperties(NodeRef nodeRef)
{

View File

@@ -19,6 +19,7 @@
package org.alfresco.module.org_alfresco_module_rm.test.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -26,13 +27,19 @@ import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.TransferAction;
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.action.DestructionReportAction;
import org.alfresco.module.org_alfresco_module_rm.report.action.TransferNode;
import org.alfresco.module.org_alfresco_module_rm.report.action.TransferReportAction;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.apache.commons.lang.StringUtils;
/**
* Report service implementation unit test.
@@ -41,12 +48,6 @@ import org.alfresco.service.namespace.QName;
*/
public class ReportServiceImplTest extends BaseRMTestCase implements ReportModel
{
@Override
protected boolean isRecordTest()
{
return false;
}
public void testGetReportTypes() throws Exception
{
doTestInTransaction(new Test<Void>()
@@ -76,10 +77,15 @@ public class ReportServiceImplTest extends BaseRMTestCase implements ReportModel
@Override
public Void run() throws Exception
{
Report report = reportService.generateReport(TYPE_DESTRUCTION_REPORT, rmFolder);
// Destruction Report
Report destructionReport = generateDestructionReport();
System.out.println(destructionReport.getReportName());
System.out.println(destructionReport.getReportContent().getContentString());
System.out.println(report.getReportName());
System.out.println(report.getReportContent().getContentString());
// Transfer Report
Report transferReport = generateTransfertReport();
System.out.println(transferReport.getReportName());
System.out.println(transferReport.getReportContent().getContentString());
return null;
}
@@ -93,20 +99,74 @@ public class ReportServiceImplTest extends BaseRMTestCase implements ReportModel
@Override
public Void run() throws Exception
{
Report report = reportService.generateReport(TYPE_DESTRUCTION_REPORT, rmFolder);
NodeRef reportNodeRef = reportService.fileReport(filePlan, report);
// Destruction Report
NodeRef destructionReportNodeRef = fileDestructionReport();
assertNotNull(destructionReportNodeRef);
assertTrue(recordService.isRecord(destructionReportNodeRef));
assertFalse(recordService.isFiled(destructionReportNodeRef));
assertEquals(TYPE_DESTRUCTION_REPORT, nodeService.getType(destructionReportNodeRef));
assertNotNull(reportNodeRef);
assertTrue(recordService.isRecord(reportNodeRef));
assertFalse(recordService.isFiled(reportNodeRef));
assertEquals(TYPE_DESTRUCTION_REPORT, nodeService.getType(reportNodeRef));
// Transfer Report
NodeRef transferReportNodeRef = fileTransferReport();
assertNotNull(transferReportNodeRef);
assertTrue(recordService.isRecord(transferReportNodeRef));
assertFalse(recordService.isFiled(transferReportNodeRef));
assertEquals(TYPE_TRANSFER_REPORT, nodeService.getType(transferReportNodeRef));
return null;
}
});
}
// FIXME!!! FileDestructionReport vs FileReport
/**
* Helper method to generate a destruction report
*
* @return Destruction report
*/
private Report generateDestructionReport()
{
return reportService.generateReport(TYPE_DESTRUCTION_REPORT, rmFolder);
}
/**
* Helper method to generate a transfer report
*
* @return Transfer report
*/
private Report generateTransfertReport()
{
nodeService.setProperty(rmFolder, PROP_TRANSFER_ACCESSION_INDICATOR, false);
nodeService.setProperty(rmFolder, PROP_TRANSFER_LOCATION, filePlan.toString());
Map<String, Serializable> properties = new HashMap<String, Serializable>(2);
ArrayList<TransferNode> transferNodes = new ArrayList<TransferNode>(1);
String dispositionAuthority = StringUtils.EMPTY;
properties.put("transferNodes", transferNodes);
properties.put("dispositionAuthority", dispositionAuthority);
return reportService.generateReport(TYPE_TRANSFER_REPORT, rmFolder, MimetypeMap.MIMETYPE_HTML, properties);
}
/**
* Helper method to file a destruction report
*
* @return Node reference of the destruction report
*/
private NodeRef fileDestructionReport()
{
Report destructionReport = generateDestructionReport();
return reportService.fileReport(filePlan, destructionReport);
}
/**
* Helper method to file a transfer report
*
* @return Node reference of the transfer report
*/
private NodeRef fileTransferReport()
{
Report transferReport = generateTransfertReport();
return reportService.fileReport(filePlan, transferReport);
}
public void testFileDestructionReportAction() throws Exception
{
doTestInTransaction(new Test<Void>()
@@ -122,7 +182,41 @@ public class ReportServiceImplTest extends BaseRMTestCase implements ReportModel
Map<String, Serializable> fileReportParams = new HashMap<String, Serializable>(2);
fileReportParams.put(DestructionReportAction.REPORT_TYPE, "rmr:destructionReport");
fileReportParams.put(DestructionReportAction.DESTINATION, filePlan.toString());
rmActionService.executeRecordsManagementAction(rmFolder, "destructionReport", fileReportParams);
rmActionService.executeRecordsManagementAction(rmFolder, DestructionReportAction.NAME, fileReportParams);
return null;
}
});
}
public void testFileTransferReportAction() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
NodeRef recordCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
utils.createDispositionSchedule(
recordCategory,
CommonRMTestUtils.DEFAULT_DISPOSITION_INSTRUCTIONS,
CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY,
false, // record level
true, // set the default actions
true); // extended disposition schedule
NodeRef recordFolder = recordFolderService.createRecordFolder(recordCategory, GUID.generate());
nodeService.setProperty(recordFolder, PROP_TRANSFER_ACCESSION_INDICATOR, false);
nodeService.setProperty(recordFolder, PROP_TRANSFER_LOCATION, filePlan.toString());
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
rmActionService.executeRecordsManagementAction(recordFolder, CompleteEventAction.NAME, params);
rmActionService.executeRecordsManagementAction(recordFolder, CutOffAction.NAME);
rmActionService.executeRecordsManagementAction(recordFolder, TransferAction.NAME);
Map<String, Serializable> fileReportParams = new HashMap<String, Serializable>(2);
fileReportParams.put(TransferReportAction.REPORT_TYPE, "rmr:transferReport");
fileReportParams.put(TransferReportAction.DESTINATION, filePlan.toString());
rmActionService.executeRecordsManagementAction(recordFolder, TransferReportAction.NAME, fileReportParams);
return null;
}
});

View File

@@ -1,5 +1,5 @@
/**
*
*
*/
package org.alfresco.module.org_alfresco_module_rm.test.util;
@@ -15,7 +15,10 @@ import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.FreezeAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.TransferAction;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
@@ -47,7 +50,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
private ModelSecurityService modelSecurityService;
private FilePlanRoleService filePlanRoleService;
private CapabilityService capabilityService;
/** test values */
public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority";
public static final String DEFAULT_DISPOSITION_INSTRUCTIONS = "disposition instructions";
@@ -55,7 +58,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
public static final String DEFAULT_EVENT_NAME = "case_closed";
public static final String PERIOD_NONE = "none|0";
public static final String PERIOD_IMMEDIATELY = "immediately|0";
public CommonRMTestUtils(ApplicationContext applicationContext)
{
dispositionService = (DispositionService)applicationContext.getBean("DispositionService");
@@ -66,9 +69,9 @@ public class CommonRMTestUtils implements RecordsManagementModel
filePlanRoleService = (FilePlanRoleService)applicationContext.getBean("FilePlanRoleService");
capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService");
}
/**
*
*
* @param container
* @return
*/
@@ -76,62 +79,95 @@ public class CommonRMTestUtils implements RecordsManagementModel
{
return createBasicDispositionSchedule(container, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_AUTHORITY, false, true);
}
/**
*
*
* @param container
* @param dispositionInstructions
* @param dispositionAuthority
* @param isRecordLevel
* @param defaultDispositionActions
* @return
*/
public DispositionSchedule createBasicDispositionSchedule(
NodeRef container,
String dispositionInstructions,
String dispositionAuthority,
boolean isRecordLevel,
boolean defaultDispositionActions)
{
return createDispositionSchedule(container, dispositionInstructions, dispositionAuthority, isRecordLevel, defaultDispositionActions, false);
}
/**
*
* @param container
* @param dispositionInstructions
* @param dispositionAuthority
* @param isRecordLevel
* @param defaultDispositionActions
* @param extendedDispositionSchedule
* @return
*/
public DispositionSchedule createBasicDispositionSchedule(
NodeRef container,
public DispositionSchedule createDispositionSchedule(
NodeRef container,
String dispositionInstructions,
String dispositionAuthority,
boolean isRecordLevel,
boolean defaultDispositionActions)
boolean isRecordLevel,
boolean defaultDispositionActions,
boolean extendedDispositionSchedule)
{
Map<QName, Serializable> dsProps = new HashMap<QName, Serializable>(3);
dsProps.put(PROP_DISPOSITION_AUTHORITY, dispositionAuthority);
dsProps.put(PROP_DISPOSITION_INSTRUCTIONS, dispositionInstructions);
dsProps.put(PROP_RECORD_LEVEL_DISPOSITION, isRecordLevel);
DispositionSchedule dispositionSchedule = dispositionService.createDispositionSchedule(container, dsProps);
DispositionSchedule dispositionSchedule = dispositionService.createDispositionSchedule(container, dsProps);
if (defaultDispositionActions == true)
{
Map<QName, Serializable> adParams = new HashMap<QName, Serializable>(3);
adParams.put(PROP_DISPOSITION_ACTION_NAME, "cutoff");
adParams.put(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME);
adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION);
List<String> events = new ArrayList<String>(1);
events.add(DEFAULT_EVENT_NAME);
adParams.put(PROP_DISPOSITION_EVENT, (Serializable)events);
dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams);
if (extendedDispositionSchedule == true)
{
adParams = new HashMap<QName, Serializable>(3);
adParams.put(PROP_DISPOSITION_ACTION_NAME, TransferAction.NAME);
adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION);
adParams.put(PROP_DISPOSITION_PERIOD, PERIOD_IMMEDIATELY);
dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams);
}
adParams = new HashMap<QName, Serializable>(3);
adParams.put(PROP_DISPOSITION_ACTION_NAME, "destroy");
adParams.put(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME);
adParams.put(PROP_DISPOSITION_DESCRIPTION, DEFAULT_DISPOSITION_DESCRIPTION);
adParams.put(PROP_DISPOSITION_PERIOD, "immediately|0");
adParams.put(PROP_DISPOSITION_PERIOD, PERIOD_IMMEDIATELY);
dispositionService.addDispositionActionDefinition(dispositionSchedule, adParams);
}
return dispositionSchedule;
}
public NodeRef createRecord(NodeRef recordFolder, String name)
{
return createRecord(recordFolder, name, null, "Some test content");
}
public NodeRef createRecord(NodeRef recordFolder, String name, String title)
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_TITLE, title);
return createRecord(recordFolder, name, props, "Some test content");
}
public NodeRef createRecord(NodeRef recordFolder, String name, Map<QName, Serializable> properties, String content)
{
// Create the document
@@ -143,21 +179,21 @@ public class CommonRMTestUtils implements RecordsManagementModel
{
properties.put(ContentModel.PROP_NAME, name);
}
NodeRef recordOne = nodeService.createNode(recordFolder,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
NodeRef recordOne = nodeService.createNode(recordFolder,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
ContentModel.TYPE_CONTENT,
properties).getChildRef();
properties).getChildRef();
// Set the content
ContentWriter writer = contentService.getWriter(recordOne, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(content);
return recordOne;
}
}
public void declareRecord(final NodeRef record)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
@@ -170,8 +206,8 @@ public class CommonRMTestUtils implements RecordsManagementModel
{
// Declare record
nodeService.setProperty(record, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date());
nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue");
nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue");
nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue");
nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue");
nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_RECEIVED, new Date());
nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date());
nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATOR, "origValue");
@@ -183,14 +219,14 @@ public class CommonRMTestUtils implements RecordsManagementModel
{
modelSecurityService.setEnabled(true);
}
return null;
}
}, AuthenticationUtil.getAdminUserName());
}
public void closeFolder(final NodeRef recordFolder)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
@@ -211,7 +247,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
}
}, AuthenticationUtil.getAdminUserName());
}
public void freeze(final NodeRef nodeRef)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
@@ -222,13 +258,13 @@ public class CommonRMTestUtils implements RecordsManagementModel
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(FreezeAction.PARAM_REASON, "Freeze reason.");
actionService.executeRecordsManagementAction(nodeRef, "freeze", params);
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
public void unfreeze(final NodeRef nodeRef)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
@@ -236,13 +272,13 @@ public class CommonRMTestUtils implements RecordsManagementModel
@Override
public Void doWork() throws Exception
{
actionService.executeRecordsManagementAction(nodeRef, "unfreeze");
actionService.executeRecordsManagementAction(nodeRef, "unfreeze");
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
public Role createRole(NodeRef filePlan, String roleName, String ... capabilityNames)
{
Set<Capability> capabilities = new HashSet<Capability>(capabilityNames.length);
@@ -255,7 +291,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
}
capabilities.add(capability);
}
return filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
}
}