Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufal/be-provenance-subbmitter-missing #469

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public XmlWorkflowItem start(Context context, WorkspaceItem wsi)
//Get our next step, if none is found, archive our item
firstStep = wf.getNextStep(context, wfi, firstStep, ActionResult.OUTCOME_COMPLETE);
if (firstStep == null) {
// record the submitted provenance message
recordStart(context, wfi.getItem(),null);
archive(context, wfi);
} else {
activateFirstStep(context, wf, firstStep, wfi);
Expand Down Expand Up @@ -334,7 +336,7 @@ protected void activateFirstStep(Context context, Workflow wf, Step firstStep, X
+ "item_id=" + wfi.getItem().getID()
+ "collection_id=" + wfi.getCollection().getID()));

// record the start of the workflow w/provenance message
// record the start of the workflow w/provenance message
recordStart(context, wfi.getItem(), firstActionConfig.getProcessingAction());

//Fire an event !
Expand Down Expand Up @@ -1187,25 +1189,30 @@ protected void recordStart(Context context, Item myitem, Action action)
DCDate now = DCDate.getCurrent();

// Create provenance description
String provmessage = "";
StringBuffer provmessage = new StringBuffer();

if (myitem.getSubmitter() != null) {
provmessage = "Submitted by " + myitem.getSubmitter().getFullName()
+ " (" + myitem.getSubmitter().getEmail() + ") on "
+ now.toString() + " workflow start=" + action.getProvenanceStartId() + "\n";
provmessage.append("Submitted by ").append(myitem.getSubmitter().getFullName())
.append(" (").append(myitem.getSubmitter().getEmail()).append(") on ")
.append(now.toString());
} else {
// else, null submitter
provmessage = "Submitted by unknown (probably automated) on"
+ now.toString() + " workflow start=" + action.getProvenanceStartId() + "\n";
provmessage.append("Submitted by unknown (probably automated) on")
.append(now.toString());
}
if (action != null) {
provmessage.append(" workflow start=").append(action.getProvenanceStartId()).append("\n");
} else {
provmessage.append("\n");
}

// add sizes and checksums of bitstreams
provmessage += installItemService.getBitstreamProvenanceMessage(context, myitem);
provmessage.append(installItemService.getBitstreamProvenanceMessage(context, myitem));

// Add message to the DC
itemService
.addMetadata(context, myitem, MetadataSchemaEnum.DC.getName(),
"description", "provenance", "en", provmessage);
"description", "provenance", "en", provmessage.toString());
itemService.update(context, myitem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,39 @@
import static com.jayway.jsonpath.JsonPath.read;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EPersonBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.VersionBuilder;
import org.dspace.builder.WorkspaceItemBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.eperson.EPerson;
import org.dspace.license.service.CreativeCommonsService;
import org.dspace.services.ConfigurationService;
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
import org.dspace.xmlworkflow.storedcomponents.service.CollectionRoleService;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -64,6 +72,8 @@ public class ClarinWorkflowItemRestRepositoryIT extends AbstractControllerIntegr

@Autowired
private CreativeCommonsService creativeCommonsService;
@Autowired
private XmlWorkflowItemService xmlWorkflowItemService;

@Autowired
private ItemService itemService;
Expand Down Expand Up @@ -250,4 +260,64 @@ public void shouldAddNewHandleToItemMetadata() throws Exception {
WorkspaceItemBuilder.deleteWorkspaceItem(idWorkspaceItemRef.get());
}
}


@Test
public void shouldCreateProvenanceMessageOnItemSubmit() throws Exception {
context.turnOffAuthorisationSystem();

//** GIVEN **
//1. A community with one collection.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();

//2. create a normal user to use as submitter
EPerson submitter = EPersonBuilder.createEPerson(context)
.withEmail("submitter@example.com")
.withPassword("dspace")
.build();

// Submitter group - allow deposit a new item without workflow
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection 2")
.withSubmitterGroup(submitter)
.build();
context.setCurrentUser(submitter);

//3. a workspace item
WorkspaceItem wsitem = WorkspaceItemBuilder.createWorkspaceItem(context, col1)
.withTitle("Submission Item")
.withIssueDate("2017-10-17")
.grantLicense()
.build();

context.restoreAuthSystemState();

// get the submitter auth token
String authToken = getAuthToken(submitter.getEmail(), "dspace");

// submit the workspaceitem to start the workflow
getClient(authToken)
.perform(post(BASE_REST_SERVER_URL + "/api/workflow/workflowitems")
.content("/api/submission/workspaceitems/" + wsitem.getID())
.contentType(textUriContentType))
.andExpect(status().isCreated());

// Load deposited item and check the provenance metadata
Item depositedItem = itemService.find(context, wsitem.getItem().getID());
List<MetadataValue> mvList = itemService.getMetadata(depositedItem, "dc", "description",
"provenance", Item.ANY);
assertFalse(mvList.isEmpty());

// Check if the provenance contains the submitter info
boolean containsSubmitterProvenance = false;
for (MetadataValue mv: mvList) {
if (mv.getValue().contains("Submitted by " + submitter.getEmail())) {
containsSubmitterProvenance = true;
break;
}
}
assertThat(containsSubmitterProvenance, is(true));
}
}