Merge remote-tracking branch 'remotes/origin/master' into feature/RM-6811_DeclareAndFileUI_Tests

This commit is contained in:
Rodica Sutu
2019-05-27 10:26:56 +03:00
4 changed files with 46 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
private final static String DESTINATION_PATH_NOT_FOUND_EXC = "Unable to execute create-record action, because the destination path could not be found.";
private final static String INVALID_DESTINATION_PATH_EXC = "Unable to execute create-record action, because the destination path is invalid.";
private final static String DESTINATION_PATH_NOT_RECORD_FOLDER_EXC = "Unable to execute create-record action, because the destination path is not a record folder.";
private final static String CLOSED_RECORD_FOLDER_EXC = "Unable to create record, because container is closed";
private final static String CLOSED_RECORD_FOLDER_EXC = "You can't add new items to a closed record folder.";
private final static String HOLD_NAME = "holdName";
private UserModel userFillingPermission, userReadOnlyPermission;

View File

@@ -21,4 +21,5 @@ rm.service.final-version=Final
rm.service.final-version-description=The final archived record version
rm.service.enable-autoversion-on-record-creation=Auto Version on Record Creation
rm.service.add-children-to-closed-record-folder=You can't add new items to a closed record folder.
rm.service.add-children-to-frozen-record-folder=You can't add new items to a frozen record folder.
rm.service.update-record-content=You can't update a record's content property.

View File

@@ -164,6 +164,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
private static final String FINAL_DESCRIPTION = "rm.service.final-version-description";
private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records";
private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop";
private static final String MSG_CANNOT_CREATE_CHILDREN_IN_CLOSED_RECORD_FOLDER = "rm.service.add-children-to-closed-record-folder";
/** Always edit property array */
private static final QName[] ALWAYS_EDIT_PROPERTIES = new QName[]
@@ -1058,13 +1059,18 @@ public class RecordServiceImpl extends BaseBehaviourBean
Boolean isClosed = (Boolean) nodeService.getProperty(newRecordContainer, PROP_IS_CLOSED);
if (isClosed != null && isClosed)
{
throw new AlfrescoRuntimeException("Unable to create record, because container is closed.");
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_CHILDREN_IN_CLOSED_RECORD_FOLDER), null);
}
if (extendedPermissionService.hasPermission(newRecordContainer, RMPermissionModel.FILING) == AccessStatus.DENIED)
{
throw new AccessDeniedException(I18NUtil.getMessage("permissions.err_access_denied"));
}
if (freezeService.isFrozen(newRecordContainer))
{
throw new IntegrityException(I18NUtil.getMessage("rm.service.add-children-to-frozen-record-folder"),null);
}
}
return newRecordContainer;

View File

@@ -50,6 +50,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -76,6 +77,8 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
private NodeRef nonStandardFilePlan;
private NodeRef dmNodeRef;
private NodeRef unfiledRecordContainer;
private NodeRef frozenRecordFolder;
private NodeRef closedRecordFolder;
private ChildAssociationRef parentAssoc;
private static QName TYPE_MY_FILE_PLAN = generateQName();
@@ -94,6 +97,8 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
nonStandardFilePlan = generateNodeRef(TYPE_MY_FILE_PLAN);
dmNodeRef = generateNodeRef(TYPE_CONTENT);
unfiledRecordContainer = generateNodeRef(TYPE_UNFILED_RECORD_CONTAINER);
frozenRecordFolder = generateNodeRef(TYPE_RECORD_FOLDER);
closedRecordFolder = generateNodeRef(TYPE_RECORD_FOLDER);
parentAssoc = mock(ChildAssociationRef.class);
// set-up node service
@@ -583,6 +588,34 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
recordService.createRecord(filePlan, dmNodeRef, recordFolder);
}
/**
* Given a file that is not yet a record
* When I create the record specifying a folder which is in a hold
* Then an exception is thrown
*/
@Test(expected= IntegrityException.class)
public void createRecordIntoRecordFolderInHold()
{
mocksForRecordCreation();
// create the record
recordService.createRecord(filePlan, dmNodeRef, frozenRecordFolder);
}
/**
* Given a file that is not yet a record
* When I create the record specifying a closed destination record folder
* Then an exception is thrown
*/
@Test(expected= IntegrityException.class)
public void createRecordIntoClosedRecordFolder()
{
mocksForRecordCreation();
// create the record
recordService.createRecord(filePlan, dmNodeRef, closedRecordFolder);
}
/* Helper method to set up the mocks for record creation */
private void mocksForRecordCreation()
{
@@ -590,10 +623,13 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
.thenReturn(parentAssoc);
when(parentAssoc.getQName()).thenReturn(generateQName());
// mocks for sanity checks on node and fileplan
// mocks for sanity checks on node, folder and fileplan
when(mockedExtendedPermissionService.hasPermission(dmNodeRef, PermissionService.WRITE)).thenReturn(AccessStatus.ALLOWED);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(dmNodeRef), ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedFilePlanService.isFilePlan(nonStandardFilePlan)).thenReturn(true);
when(mockedFreezeService.isFrozen(recordFolder)).thenReturn(false);
when(mockedFreezeService.isFrozen(frozenRecordFolder)).thenReturn(true);
when(mockedNodeService.getProperty(closedRecordFolder, PROP_IS_CLOSED)).thenReturn(true);
// mocks for policies
doNothing().when(recordService).invokeBeforeRecordDeclaration(dmNodeRef);