RM-5012 - fix record folder children - 2

This commit is contained in:
Ana Bozianu
2017-05-15 23:31:42 +03:00
parent 1276e5c5c7
commit 5988185459
2 changed files with 65 additions and 39 deletions

View File

@@ -255,14 +255,19 @@ public class RecordFolderType extends AbstractDisposableItem
) )
public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew)
{ {
final NodeRef recordFolder = childAssocRef.getChildRef(); final NodeRef child = childAssocRef.getChildRef();
// only records can be added in a record folder or hidden folders(is the case of e-mail attachments) // only records can be added in a record folder or hidden folders(is the case of e-mail attachments)
if (instanceOf(recordFolder, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(recordFolder, ContentModel.ASPECT_HIDDEN)) if (instanceOf(child, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN))
{ {
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(recordFolder)), null); throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(child)), null);
} }
// file the record
recordService.file(child);
// recalculate disposition schedule
dispositionService.recalculateNextDispositionStep(child);
behaviourFilter.disableBehaviour(); behaviourFilter.disableBehaviour();
try try
{ {
@@ -272,7 +277,7 @@ public class RecordFolderType extends AbstractDisposableItem
public Void doWork() public Void doWork()
{ {
// setup vital record definition // setup vital record definition
vitalRecordService.setupVitalRecordDefinition(recordFolder); vitalRecordService.setupVitalRecordDefinition(child);
return null; return null;
} }

View File

@@ -73,13 +73,14 @@ public class FileToActionTest extends BaseRMTestCase
} }
public void testFileToNodeRef() public void testFileToNodeRef()
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
@Override
public void given() throws Exception
{ {
initRecord(); initRecord();
doTestInTransaction(new Test<Void>()
{
public Void run()
{
NodeRef unfiledContainer = filePlanService.getUnfiledContainer(filePlan); NodeRef unfiledContainer = filePlanService.getUnfiledContainer(filePlan);
assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(unfiledContainer, RMPermissionModel.FILING)); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(unfiledContainer, RMPermissionModel.FILING));
assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rmFolder, RMPermissionModel.FILING)); assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(rmFolder, RMPermissionModel.FILING));
@@ -87,14 +88,22 @@ public class FileToActionTest extends BaseRMTestCase
Capability capability = capabilityService.getCapability("FileUnfiledRecords"); Capability capability = capabilityService.getCapability("FileUnfiledRecords");
assertNotNull(capability); assertNotNull(capability);
assertEquals(AccessStatus.ALLOWED, capability.hasPermission(dmDocument)); assertEquals(AccessStatus.ALLOWED, capability.hasPermission(dmDocument));
}
@Override
public void when() throws Exception
{
// set parameters // set parameters
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(FileToAction.PARAM_DESTINATION_RECORD_FOLDER, rmFolder); params.put(FileToAction.PARAM_DESTINATION_RECORD_FOLDER, rmFolder);
// execute file-to action // execute file-to action
rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params); rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params);
}
@Override
public void then() throws Exception
{
// check things have gone according to plan // check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument)); assertTrue(recordService.isRecord(dmDocument));
assertTrue(recordService.isFiled(dmDocument)); assertTrue(recordService.isFiled(dmDocument));
@@ -102,10 +111,8 @@ public class FileToActionTest extends BaseRMTestCase
// is the record folder the primary parent of the filed record // is the record folder the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef(); NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(rmFolder, parent); assertEquals(rmFolder, parent);
return null;
} }
}, ADMIN_USER); });
} }
private void initRecord() private void initRecord()
@@ -131,13 +138,13 @@ public class FileToActionTest extends BaseRMTestCase
assertTrue(recordService.isRecord(dmDocument)); assertTrue(recordService.isRecord(dmDocument));
assertFalse(recordService.isFiled(dmDocument)); assertFalse(recordService.isFiled(dmDocument));
// is the unfiled container the primary parent of the filed record // is the unfiled container the primary parent of the filed
// record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef(); NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(filePlanService.getUnfiledContainer(filePlan), parent); assertEquals(filePlanService.getUnfiledContainer(filePlan), parent);
return null; return null;
}, }, AuthenticationUtil.getAdminUserName());
AuthenticationUtil.getAdminUserName());
} }
}, dmCollaborator); }, dmCollaborator);
@@ -145,11 +152,16 @@ public class FileToActionTest extends BaseRMTestCase
public void testFileToPath() public void testFileToPath()
{ {
initRecord(); doBehaviourDrivenTest(new BehaviourDrivenTest()
doTestInTransaction(new Test<Void>()
{ {
public Void run() @Override
public void given() throws Exception
{
initRecord();
}
@Override
public void when() throws Exception
{ {
// set parameters // set parameters
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
@@ -157,7 +169,11 @@ public class FileToActionTest extends BaseRMTestCase
// execute file-to action // execute file-to action
rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params); rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params);
}
@Override
public void then() throws Exception
{
// check things have gone according to plan // check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument)); assertTrue(recordService.isRecord(dmDocument));
assertTrue(recordService.isFiled(dmDocument)); assertTrue(recordService.isFiled(dmDocument));
@@ -165,19 +181,22 @@ public class FileToActionTest extends BaseRMTestCase
// is the record folder the primary parent of the filed record // is the record folder the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef(); NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(rmFolder, parent); assertEquals(rmFolder, parent);
return null;
} }
}, ADMIN_USER); });
} }
public void testFileToPath2() public void testFileToPath2()
{ {
initRecord(); doBehaviourDrivenTest(new BehaviourDrivenTest()
doTestInTransaction(new Test<Void>()
{ {
public Void run() @Override
public void given() throws Exception
{
initRecord();
}
@Override
public void when() throws Exception
{ {
// set parameters // set parameters
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
@@ -185,7 +204,11 @@ public class FileToActionTest extends BaseRMTestCase
// execute file-to action // execute file-to action
rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params); rmActionService.executeRecordsManagementAction(dmDocument, FileToAction.NAME, params);
}
@Override
public void then() throws Exception
{
// check things have gone according to plan // check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument)); assertTrue(recordService.isRecord(dmDocument));
assertTrue(recordService.isFiled(dmDocument)); assertTrue(recordService.isFiled(dmDocument));
@@ -193,10 +216,8 @@ public class FileToActionTest extends BaseRMTestCase
// is the record folder the primary parent of the filed record // is the record folder the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef(); NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(rmFolder, parent); assertEquals(rmFolder, parent);
return null;
} }
}, ADMIN_USER); });
} }
public void testCreate() throws Exception public void testCreate() throws Exception