Search in sources :

Example 11 with Community

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");
}
Also used : Group(org.dspace.eperson.Group) DSpaceObject(org.dspace.content.DSpaceObject) ArrayList(java.util.ArrayList) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) File(java.io.File) Community(org.dspace.content.Community) AbstractIntegrationTest(org.dspace.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with Community

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);
    }
}
Also used : Context(org.dspace.core.Context) EPersonService(org.dspace.eperson.service.EPersonService) CommunityService(org.dspace.content.service.CommunityService) EPerson(org.dspace.eperson.EPerson) HandleService(org.dspace.handle.service.HandleService) Community(org.dspace.content.Community) SQLException(java.sql.SQLException) WorkflowException(org.dspace.workflow.WorkflowException) AuthorizeException(org.dspace.authorize.AuthorizeException) CrosswalkException(org.dspace.content.crosswalk.CrosswalkException) IOException(java.io.IOException) AfterClass(org.junit.AfterClass)

Example 13 with Community

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());
    }
}
Also used : Context(org.dspace.core.Context) CollectionService(org.dspace.content.service.CollectionService) SQLException(java.sql.SQLException) CommunityService(org.dspace.content.service.CommunityService) AuthorizeException(org.dspace.authorize.AuthorizeException) Collection(org.dspace.content.Collection) Community(org.dspace.content.Community) BeforeClass(org.junit.BeforeClass)

Example 14 with Community

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());
}
Also used : XmlWorkflowItem(org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Collection(org.dspace.content.Collection) Workflow(org.dspace.xmlworkflow.state.Workflow) Community(org.dspace.content.Community) WorkspaceItem(org.dspace.content.WorkspaceItem) Test(org.junit.Test)

Example 15 with Community

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());
}
Also used : XmlWorkflowItem(org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Collection(org.dspace.content.Collection) Workflow(org.dspace.xmlworkflow.state.Workflow) Community(org.dspace.content.Community) WorkspaceItem(org.dspace.content.WorkspaceItem) Test(org.junit.Test)

Aggregations

Community (org.dspace.content.Community)776 Test (org.junit.Test)653 Collection (org.dspace.content.Collection)651 AbstractControllerIntegrationTest (org.dspace.app.rest.test.AbstractControllerIntegrationTest)577 Item (org.dspace.content.Item)348 WorkspaceItem (org.dspace.content.WorkspaceItem)228 EPerson (org.dspace.eperson.EPerson)183 ArrayList (java.util.ArrayList)167 XmlWorkflowItem (org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem)131 Operation (org.dspace.app.rest.model.patch.Operation)127 ReplaceOperation (org.dspace.app.rest.model.patch.ReplaceOperation)123 InputStream (java.io.InputStream)115 AddOperation (org.dspace.app.rest.model.patch.AddOperation)114 RemoveOperation (org.dspace.app.rest.model.patch.RemoveOperation)96 ResourcePolicy (org.dspace.authorize.ResourcePolicy)78 Bitstream (org.dspace.content.Bitstream)76 Group (org.dspace.eperson.Group)71 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)71 HashMap (java.util.HashMap)59 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)53