use of org.dspace.content.Community in project DSpace by DSpace.
the class ITDSpaceAIP method testRestoreRestrictedCollection.
/**
* Test restoration from AIP of an access restricted Collection
*/
@Test
public void testRestoreRestrictedCollection() throws Exception {
log.info("testRestoreRestrictedCollection() - BEGIN");
// Locate the top-level Community (as a parent)
Community parent = (Community) handleService.resolveToObject(context, topCommunityHandle);
// Create a brand new (empty) Collection to test with
Collection collection = collectionService.create(context, parent);
collectionService.addMetadata(context, collection, "dc", "title", null, null, "Restricted Collection");
collectionService.update(context, collection);
String collectionHandle = collection.getHandle();
// Create a new Group to access restrict to
Group group = groupService.create(context);
groupService.setName(group, "Special Users");
groupService.update(context, group);
// Create a custom resource policy for this Collection
List<ResourcePolicy> policies = new ArrayList<>();
ResourcePolicy policy = resourcePolicyService.create(context);
policy.setRpName("Special Read Only");
policy.setGroup(group);
policy.setAction(Constants.READ);
policies.add(policy);
// Replace default Collection policies with this new one
authorizeService.removeAllPolicies(context, collection);
authorizeService.addPolicies(context, policies, collection);
// Export collection AIP
log.info("testRestoreRestrictedCollection() - CREATE Collection AIP");
File aipFile = createAIP(collection, null, false);
// Now, delete that Collection
log.info("testRestoreRestrictedCollection() - DELETE Collection");
communityService.removeCollection(context, parent, collection);
// Assert the deleted collection no longer exists
DSpaceObject obj = handleService.resolveToObject(context, collectionHandle);
assertThat("testRestoreRestrictedCollection() Collection " + collectionHandle + " doesn't exist", obj, nullValue());
// Restore Collection from AIP (non-recursive)
log.info("testRestoreRestrictedCollection() - RESTORE Collection");
restoreFromAIP(parent, aipFile, null, false);
// Assert the deleted Collection is RESTORED
DSpaceObject objRestored = handleService.resolveToObject(context, collectionHandle);
assertThat("testRestoreRestrictedCollection() Collection " + collectionHandle + " exists", objRestored, notNullValue());
// Assert the number of restored policies is equal
List<ResourcePolicy> policiesRestored = authorizeService.getPolicies(context, objRestored);
assertEquals("testRestoreRestrictedCollection() restored policy count equal", policies.size(), policiesRestored.size());
// Assert the restored policy has same name, group and permission settings
ResourcePolicy restoredPolicy = policiesRestored.get(0);
assertEquals("testRestoreRestrictedCollection() restored policy group successfully", policy.getGroup().getName(), restoredPolicy.getGroup().getName());
assertEquals("testRestoreRestrictedCollection() restored policy action successfully", policy.getAction(), restoredPolicy.getAction());
assertEquals("testRestoreRestrictedCollection() restored policy name successfully", policy.getRpName(), restoredPolicy.getRpName());
log.info("testRestoreRestrictedCollection() - END");
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class ITDSpaceAIP method tearDownClass.
/**
* This method will be run once at the very end
*/
@AfterClass
public static void tearDownClass() {
try {
Context context = new Context();
CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
Community topCommunity = (Community) handleService.resolveToObject(context, topCommunityHandle);
// Delete top level test community and test hierarchy under it
if (topCommunity != null) {
log.info("tearDownClass() - DESTROY TEST HIERARCHY");
context.turnOffAuthorisationSystem();
communityService.delete(context, topCommunity);
context.restoreAuthSystemState();
context.commit();
}
// Delete the Eperson created to submit test items
EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
EPerson eperson = ePersonService.findByEmail(context, submitterEmail);
if (eperson != null) {
log.info("tearDownClass() - DESTROY TEST EPERSON");
context.turnOffAuthorisationSystem();
ePersonService.delete(context, eperson);
context.restoreAuthSystemState();
context.commit();
}
if (context.isValid()) {
context.abort();
}
} catch (Exception ex) {
log.error("Error in tearDownClass()", ex);
}
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class PackageUtilsTest method setUpClass.
/**
* This method will be run during class initialization. It will initialize
* shared resources required for all the tests. It is only run once.
*
* Other methods can be annotated with @Before here or in subclasses
* but no execution order is guaranteed
*/
@BeforeClass
public static void setUpClass() {
try {
Context context = new Context();
// Create a dummy Community hierarchy to test with
// Turn off authorization temporarily to create some test objects.
context.turnOffAuthorisationSystem();
CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
log.info("setUpClass() - CREATE TEST HIERARCHY");
// Create a hierachy of sub-Communities and Collections
// which looks like this:
// "Top Community"
// - "Child Community"
// - "Grandchild Collection"
//
Community topCommunity = communityService.create(null, context);
communityService.addMetadata(context, topCommunity, MetadataSchemaEnum.DC.getName(), "title", null, null, "Top Community");
communityService.update(context, topCommunity);
topCommunityHandle = topCommunity.getHandle();
Community child = communityService.createSubcommunity(context, topCommunity);
communityService.addMetadata(context, child, MetadataSchemaEnum.DC.getName(), "title", null, null, "Child Community");
communityService.update(context, child);
// Create our primary Test Collection
Collection grandchildCol = collectionService.create(context, child);
collectionService.addMetadata(context, grandchildCol, "dc", "title", null, null, "Grandchild Collection");
collectionService.update(context, grandchildCol);
testCollectionHandle = grandchildCol.getHandle();
// Commit these changes to our DB
context.restoreAuthSystemState();
context.complete();
} catch (AuthorizeException ex) {
log.error("Authorization Error in setUpClass()", ex);
fail("Authorization Error in setUpClass(): " + ex.getMessage());
} catch (SQLException ex) {
log.error("SQL Error in setUpClass()", ex);
fail("SQL Error in setUpClass(): " + ex.getMessage());
}
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class EPersonInWorkflowIT method testDeleteUserAfterReplacingUser6.
/**
* This test verifies that an EPerson cannot be removed if they are the only member of a Workflow Group that has
* tasks currently assigned to it. This test verifies this with a claimed task by the user to be deleted in the
* final workflow step.
* This test also verifies that after another user has been added to the workflow groups of the to be deleted user,
* the original user can be successfully deleted.
* Afterwards the task can be claimed in the final step by the newly added user and the workflow can be completed.
*
* @throws Exception
*/
@Test
public void testDeleteUserAfterReplacingUser6() throws Exception {
/*
* This test has the following setup:
* - Step 1: user B
* - Step 2: user C
* - Step 3: user B
*
* This test will perform the following checks:
* - create a workspace item, and let it move to step 1
* - Approve it by user B
* - verify that the item moved to step 2
* - Approve it by user C
* - verify that the item moved to step 3
* - claim it by user B, but don’t approve it
* - delete user B
* - verify the delete is refused
* - add user D to workflow step 1
* - add user D to workflow step 3
* - delete user B
* - verify the delete succeeds
* - Verify user D can now claim and approve it
* - verify that the item is archived
*/
context.turnOffAuthorisationSystem();
Community parent = CommunityBuilder.createCommunity(context).build();
Collection collection = CollectionBuilder.createCollection(context, parent).withWorkflowGroup(1, workflowUserB).withWorkflowGroup(2, workflowUserC).withWorkflowGroup(3, workflowUserB).build();
WorkspaceItem wsi = WorkspaceItemBuilder.createWorkspaceItem(context, collection).withSubmitter(workflowUserA).withTitle("Test item full workflow").withIssueDate("2019-03-06").withSubject("ExtraEntry").build();
Workflow workflow = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory().getWorkflow(collection);
XmlWorkflowItem workflowItem = xmlWorkflowService.startWithoutNotify(context, wsi);
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
httpServletRequest.setParameter("submit_approve", "submit_approve");
executeWorkflowAction(httpServletRequest, workflowUserB, workflow, workflowItem, REVIEW_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserB, workflow, workflowItem, REVIEW_STEP, REVIEW_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserC, workflow, workflowItem, EDIT_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserC, workflow, workflowItem, EDIT_STEP, EDIT_ACTION);
assertDeletionOfEperson(workflowUserB, false);
addUserToWorkflowGroup(workflowUserD, collection, REVIEW_ROLE);
addUserToWorkflowGroup(workflowUserD, collection, FINAL_EDIT_ROLE);
assertDeletionOfEperson(workflowUserB, true);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, FINAL_EDIT_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, FINAL_EDIT_STEP, FINAL_EDIT_ACTION);
assertTrue(workflowItem.getItem().isArchived());
}
use of org.dspace.content.Community in project DSpace by DSpace.
the class EPersonInWorkflowIT method testDeleteUserWhenMultipleUser4.
/**
* This test verifies that an EPerson can be removed if there is another user is present in the Workflow Group.
* This test verifies this with a claimed task in the first workflow step.
* This test also verifies that the claimed task will return the first workflow's step task pool and that the other
* user can claim the task and progress it.
* This test then verifies that the workflow can be completed and the item will be archived.
*
* @throws Exception
*/
@Test
public void testDeleteUserWhenMultipleUser4() throws Exception {
/*
* This test has the following setup:
* - Step 1: user B and D
* - Step 2: user C and D
* - Step 3: user B and D
*
* This test will perform the following checks:
* - create a workspace item, and let it move to step 1
* - claim it by user B, but don’t approve it
* - delete user B
* - verify the delete succeeds
* - Verify user D can now claim and approve it
* - verify that the item moved to step 2
* - Approve it by user C
* - verify that the item moved to step 3
* - Approve it by user D
* - verify that the item is archived
*/
context.turnOffAuthorisationSystem();
Community parent = CommunityBuilder.createCommunity(context).build();
Collection collection = CollectionBuilder.createCollection(context, parent).withWorkflowGroup(1, workflowUserB, workflowUserD).withWorkflowGroup(2, workflowUserC, workflowUserD).withWorkflowGroup(3, workflowUserB, workflowUserD).build();
WorkspaceItem wsi = WorkspaceItemBuilder.createWorkspaceItem(context, collection).withSubmitter(workflowUserA).withTitle("Test item full workflow").withIssueDate("2019-03-06").withSubject("ExtraEntry").build();
Workflow workflow = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory().getWorkflow(collection);
XmlWorkflowItem workflowItem = xmlWorkflowService.startWithoutNotify(context, wsi);
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
httpServletRequest.setParameter("submit_approve", "submit_approve");
executeWorkflowAction(httpServletRequest, workflowUserB, workflow, workflowItem, REVIEW_STEP, CLAIM_ACTION);
assertDeletionOfEperson(workflowUserB, true);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, REVIEW_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, REVIEW_STEP, REVIEW_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserC, workflow, workflowItem, EDIT_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserC, workflow, workflowItem, EDIT_STEP, EDIT_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, FINAL_EDIT_STEP, CLAIM_ACTION);
executeWorkflowAction(httpServletRequest, workflowUserD, workflow, workflowItem, FINAL_EDIT_STEP, FINAL_EDIT_ACTION);
assertTrue(workflowItem.getItem().isArchived());
}
Aggregations