Search in sources :

Example 96 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ExportEventProcessorIT method testShouldProcessItem.

@Test
public /**
 * Test the ShouldProcessItem method where all conditions are met
 */
void testShouldProcessItem() throws SQLException {
    context.turnOffAuthorisationSystem();
    Community community = CommunityBuilder.createCommunity(context).build();
    Collection collection = CollectionBuilder.createCollection(context, community).withEntityType(publication.getLabel()).build();
    Item item = ItemBuilder.createItem(context, collection).build();
    context.restoreAuthSystemState();
    ExportEventProcessor exportEventProcessor = new ItemEventProcessor(context, request, item);
    boolean result = exportEventProcessor.shouldProcessItem(item);
    assertTrue(result);
}
Also used : Item(org.dspace.content.Item) WorkspaceItem(org.dspace.content.WorkspaceItem) Collection(org.dspace.content.Collection) Community(org.dspace.content.Community) Test(org.junit.Test)

Example 97 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ItemEventProcessorIT method testAddObectSpecificData.

@Test
public /**
 * Test the method that adds data based on the object types
 */
void testAddObectSpecificData() throws UnsupportedEncodingException {
    context.turnOffAuthorisationSystem();
    Community community = CommunityBuilder.createCommunity(context).build();
    Collection collection = CollectionBuilder.createCollection(context, community).build();
    Item item = ItemBuilder.createItem(context, collection).build();
    context.restoreAuthSystemState();
    String encodedHandle = URLEncoder.encode(item.getHandle(), CharEncoding.UTF_8);
    ItemEventProcessor itemEventProcessor = new ItemEventProcessor(context, null, item);
    String result = itemEventProcessor.addObjectSpecificData("existing-string", item);
    assertThat(result, is("existing-string&svc_dat=" + encodedUrl + "%2Fhandle%2F" + encodedHandle + "&rft_dat=Investigation"));
}
Also used : Item(org.dspace.content.Item) Collection(org.dspace.content.Collection) Community(org.dspace.content.Community) Test(org.junit.Test)

Example 98 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class WorkflowCurationIT method curationTest.

/**
 * Basic smoke test of a curation task attached to a workflow step.
 * See {@link MarkerTask}.
 * @throws java.lang.Exception passed through.
 */
@Test
public void curationTest() throws Exception {
    context.turnOffAuthorisationSystem();
    // ** GIVEN **
    // A submitter;
    EPerson submitter = EPersonBuilder.createEPerson(context).withEmail("submitter@example.com").withPassword(password).withLanguage("en").build();
    // A containment hierarchy;
    Community community = CommunityBuilder.createCommunity(context).withName("Community").build();
    final String CURATION_COLLECTION_HANDLE = "123456789/curation-test-1";
    Collection collection = CollectionBuilder.createCollection(context, community, CURATION_COLLECTION_HANDLE).withName("Collection").build();
    // A workflow configuration for the test Collection;
    // See test/dspaceFolder/config/spring/api/workflow.xml
    // A curation task attached to the workflow;
    // See test/dspaceFolder/config/workflow-curation.xml for the attachment.
    // This should include MarkerTask.
    // A workflow item;
    context.setCurrentUser(submitter);
    XmlWorkflowItem wfi = WorkflowItemBuilder.createWorkflowItem(context, collection).withTitle("Test of workflow curation").withIssueDate("2021-05-14").withSubject("Testing").build();
    context.restoreAuthSystemState();
    // ** THEN **
    // Search the Item's provenance for MarkerTask's name.
    List<MetadataValue> provenance = itemService.getMetadata(wfi.getItem(), MarkerTask.SCHEMA, MarkerTask.ELEMENT, MarkerTask.QUALIFIER, MarkerTask.LANGUAGE);
    Pattern markerPattern = Pattern.compile(MarkerTask.class.getCanonicalName());
    boolean found = false;
    for (MetadataValue record : provenance) {
        if (markerPattern.matcher(record.getValue()).find()) {
            found = true;
            break;
        }
    }
    assertThat("Item should have been curated", found);
}
Also used : MetadataValue(org.dspace.content.MetadataValue) Pattern(java.util.regex.Pattern) MarkerTask(org.dspace.ctask.testing.MarkerTask) XmlWorkflowItem(org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem) Collection(org.dspace.content.Collection) EPerson(org.dspace.eperson.EPerson) Community(org.dspace.content.Community) Test(org.junit.Test)

Example 99 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class XmlWorkflowServiceIT method workflowUserRejectsItemTheySubmitted_ItemShouldBeEditable.

/**
 * Test to verify that if a user submits an item into the workflow, then it gets rejected that the submitter gets
 * write access back on the item
 *
 * @throws Exception
 */
@Test
public void workflowUserRejectsItemTheySubmitted_ItemShouldBeEditable() throws Exception {
    context.turnOffAuthorisationSystem();
    EPerson submitter = EPersonBuilder.createEPerson(context).withEmail("submitter@example.org").build();
    context.setCurrentUser(submitter);
    Community community = CommunityBuilder.createCommunity(context).withName("Parent Community").build();
    Collection colWithWorkflow = CollectionBuilder.createCollection(context, community).withName("Collection WITH workflow").withWorkflowGroup(1, submitter).build();
    Workflow workflow = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory().getWorkflow(colWithWorkflow);
    ClaimedTask taskToReject = ClaimedTaskBuilder.createClaimedTask(context, colWithWorkflow, submitter).withTitle("Test workflow item to reject").build();
    context.restoreAuthSystemState();
    // Submitter person is both original submitter as well as reviewer, should have edit access of claimed task
    assertTrue(this.containsRPForUser(taskToReject.getWorkflowItem().getItem(), submitter, Constants.WRITE));
    // reject
    MockHttpServletRequest httpRejectRequest = new MockHttpServletRequest();
    httpRejectRequest.setParameter("submit_reject", "submit_reject");
    httpRejectRequest.setParameter("reason", "test");
    executeWorkflowAction(httpRejectRequest, workflow, taskToReject);
    // Submitter person is both original submitter as well as reviewer, should have edit access of reject, i.e.
    // sent back/to submission task
    assertTrue(this.containsRPForUser(taskToReject.getWorkflowItem().getItem(), submitter, Constants.WRITE));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Collection(org.dspace.content.Collection) Workflow(org.dspace.xmlworkflow.state.Workflow) ClaimedTask(org.dspace.xmlworkflow.storedcomponents.ClaimedTask) EPerson(org.dspace.eperson.EPerson) Community(org.dspace.content.Community) Test(org.junit.Test)

Example 100 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ServiceDocumentManagerDSpace method getServiceDocument.

public ServiceDocument getServiceDocument(SwordContext context, String url, SwordConfigurationDSpace swordConfig) throws SwordError, SwordServerException, DSpaceSwordException {
    // been set
    if (context == null) {
        throw new DSpaceSwordException("The Sword Context is null; please set it before calling getServiceDocument");
    }
    // ensure that this method is allowed
    WorkflowManagerFactory.getInstance().retrieveServiceDoc(context.getContext());
    // get the URL manager
    SwordUrlManager urlManager = swordConfig.getUrlManager(context.getContext(), swordConfig);
    // we'll need the authenticator
    SwordAuthenticator swordAuth = new SwordAuthenticator();
    // construct the ATOM collection generators that we might use
    AtomCollectionGenerator comGen = new CommunityCollectionGenerator();
    AtomCollectionGenerator colGen = new CollectionCollectionGenerator();
    // construct a new service document
    ServiceDocument service = new ServiceDocument();
    // set the max upload size
    service.setMaxUploadSize(swordConfig.getMaxUploadSize());
    if (url == null || urlManager.isBaseServiceDocumentUrl(url)) {
        // we are dealing with the default service document
        // set the title of the workspace as per the name of the DSpace installation
        String ws = configurationService.getProperty("dspace.name");
        SwordWorkspace workspace = new SwordWorkspace();
        workspace.setTitle(ws);
        // next thing to do is determine whether the default is communities or collections
        boolean swordCommunities = configurationService.getBooleanProperty("swordv2-server.expose-communities");
        if (swordCommunities) {
            List<Community> comms = swordAuth.getAllowedCommunities(context);
            for (Community comm : comms) {
                SwordCollection scol = comGen.buildCollection(context.getContext(), comm, swordConfig);
                workspace.addCollection(scol);
            }
        } else {
            List<Collection> cols = swordAuth.getAllowedCollections(context);
            for (Collection col : cols) {
                SwordCollection scol = colGen.buildCollection(context.getContext(), col, swordConfig);
                workspace.addCollection(scol);
            }
        }
        service.addWorkspace(workspace);
    } else {
        // we are dealing with a partial or sub-service document
        DSpaceObject dso = urlManager.extractDSpaceObject(url);
        if (dso == null) {
            throw new SwordError(404);
        }
        if (dso instanceof Community) {
            Community community = (Community) dso;
            SwordWorkspace workspace = new SwordWorkspace();
            workspace.setTitle(communityService.getName(community));
            List<Collection> collections = swordAuth.getAllowedCollections(context, community);
            for (Collection collection : collections) {
                SwordCollection scol = colGen.buildCollection(context.getContext(), collection, swordConfig);
                workspace.addCollection(scol);
            }
            List<Community> communities = swordAuth.getCommunities(context, community);
            for (Community comm : communities) {
                SwordCollection scol = comGen.buildCollection(context.getContext(), comm, swordConfig);
                workspace.addCollection(scol);
            }
            service.addWorkspace(workspace);
        }
    }
    return service;
}
Also used : SwordError(org.swordapp.server.SwordError) SwordWorkspace(org.swordapp.server.SwordWorkspace) DSpaceObject(org.dspace.content.DSpaceObject) SwordCollection(org.swordapp.server.SwordCollection) Collection(org.dspace.content.Collection) ServiceDocument(org.swordapp.server.ServiceDocument) Community(org.dspace.content.Community) SwordCollection(org.swordapp.server.SwordCollection)

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