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)
{
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)
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();
try
{
@@ -272,7 +277,7 @@ public class RecordFolderType extends AbstractDisposableItem
public Void doWork()
{
// setup vital record definition
vitalRecordService.setupVitalRecordDefinition(recordFolder);
vitalRecordService.setupVitalRecordDefinition(child);
return null;
}

View File

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