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);
}
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"));
}
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);
}
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));
}
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;
}
Aggregations