diff --git a/dspace-api/src/main/java/org/dspace/app/util/SubmissionConfigReader.java b/dspace-api/src/main/java/org/dspace/app/util/SubmissionConfigReader.java
index 2f591b6e7a8c..57e6a3fafcea 100644
--- a/dspace-api/src/main/java/org/dspace/app/util/SubmissionConfigReader.java
+++ b/dspace-api/src/main/java/org/dspace/app/util/SubmissionConfigReader.java
@@ -30,7 +30,10 @@
import org.dspace.core.Context;
import org.dspace.discovery.SearchServiceException;
import org.dspace.handle.factory.HandleServiceFactory;
+import org.dspace.services.RequestService;
import org.dspace.services.factory.DSpaceServicesFactory;
+import org.dspace.versioning.ItemCorrectionService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -58,6 +61,10 @@
*/
public class SubmissionConfigReader {
+
+ @Autowired
+ RequestService requestService;
+
/**
* The ID of the default collection. Will never be the ID of a named
* collection
@@ -118,6 +125,16 @@ public class SubmissionConfigReader {
protected static final CollectionService collectionService
= ContentServiceFactory.getInstance().getCollectionService();
+ /**
+ * itemCorrectionService instance, needed to retrieve the handle correctly
+ * item correction actions
+ *
+ */
+ protected static final ItemCorrectionService itemCorrectionService =
+ DSpaceServicesFactory.getInstance().getServiceManager()
+ .getServicesByType(ItemCorrectionService.class)
+ .get(0);
+
/**
* Load Submission Configuration from the
* item-submission.xml configuration file
@@ -430,6 +447,9 @@ private void doNodes(Node n) throws SAXException, SearchServiceException, Submis
}
}
+
+
+
/**
* Process the submission-map section of the XML file. Each element looks
* like: Extract
@@ -758,12 +778,25 @@ public List getCollectionsBySubmissionConfig(Context context, String
return results;
}
- public SubmissionConfig getSubmissionConfigByInProgressSubmission(InProgressSubmission> object) {
+ public SubmissionConfig getSubmissionConfigByInProgressSubmission(InProgressSubmission> object, Context context) {
if (object instanceof EditItem) {
String submissionDefinition = ((EditItem) object).getMode().getSubmissionDefinition();
return getSubmissionConfigByName(submissionDefinition);
}
- return getSubmissionConfigByCollection(object.getCollection());
+ if (isCorrectionItem(object.getItem(), context)) {
+ return getCorrectionSubmissionConfigByCollection(object.getCollection());
+ } else {
+ return getSubmissionConfigByCollection(object.getCollection());
+ }
+ }
+
+ private boolean isCorrectionItem(Item item, Context context) {
+ try {
+ return itemCorrectionService.checkIfIsCorrectionItem(context, item);
+ } catch (Exception ex) {
+ log.error("An error occurs checking if the given item is a correction item.", ex);
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/validation/service/impl/ValidationServiceImpl.java b/dspace-api/src/main/java/org/dspace/validation/service/impl/ValidationServiceImpl.java
index b4c9b4bc4c1a..65bd0bf19452 100644
--- a/dspace-api/src/main/java/org/dspace/validation/service/impl/ValidationServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/validation/service/impl/ValidationServiceImpl.java
@@ -55,7 +55,8 @@ private void setup() throws SubmissionConfigReaderException {
@Override
public List validate(Context context, InProgressSubmission> obj) {
- SubmissionConfig submissionConfig = submissionConfigReader.getSubmissionConfigByInProgressSubmission(obj);
+ SubmissionConfig submissionConfig = submissionConfigReader
+ .getSubmissionConfigByInProgressSubmission(obj, context);
List errors = new ArrayList();
diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/CorrectionStepIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/CorrectionStepIT.java
index 34665592823e..685036833f06 100644
--- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/CorrectionStepIT.java
+++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/CorrectionStepIT.java
@@ -126,7 +126,8 @@ public void setup() throws Exception {
.withEntityType("Publication")
.withWorkflowGroup("editor", admin)
.withSubmitterGroup(eperson)
- .withSubmissionDefinition("traditional-with-correction")
+ .withSubmissionDefinition("traditional")
+ .withCorrectionSubmissionDefinition("traditional-with-correction")
.build();
date = "2020-02-20";
@@ -274,6 +275,101 @@ public void checkCorrection() throws Exception {
}
+ @Test
+ public void checkCorrectionWithDuplicates() throws Exception {
+
+ String tokenSubmitter = getAuthToken(eperson.getEmail(), password);
+
+ //create a correction item
+ getClient(tokenSubmitter).perform(post("/api/submission/workspaceitems")
+ .param("owningCollection", collection.getID().toString())
+ .param("relationship", "isCorrectionOfItem")
+ .param("item", itemToBeCorrected.getID().toString())
+ .contentType(org.springframework.http.MediaType.APPLICATION_JSON))
+ .andExpect(status().isCreated())
+ .andDo(result -> workspaceItemIdRef.set(read(result.getResponse().getContentAsString(), "$.id")));
+
+ List relationshipList = relationshipService.findByItem(context, itemToBeCorrected);
+ assert relationshipList.size() > 0;
+ Item correctedItem = relationshipList.get(0).getLeftItem();
+ WorkspaceItem newWorkspaceItem = workspaceItemService.findByItem(context,correctedItem);
+
+ //make a change on the title
+ Map value = new HashMap();
+ final String newDate = "2020-02-21";
+ value.put("value", newDate);
+ List operations = new ArrayList();
+ operations.add(new ReplaceOperation("/sections/traditionalpageone/dc.date.issued/0", value));
+ String patchBody = getPatchContent(operations);
+ getClient(tokenSubmitter).perform(patch("/api/submission/workspaceitems/" + newWorkspaceItem.getID())
+ .content(patchBody)
+ .contentType("application/json-patch+json"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.errors").doesNotExist());
+
+ final String newTitle = "New Title";
+ value.put("value", newTitle);
+ operations = new ArrayList();
+ operations.add(new ReplaceOperation("/sections/traditionalpageone/dc.title/0", value));
+ patchBody = getPatchContent(operations);
+ getClient(tokenSubmitter).perform(patch("/api/submission/workspaceitems/" + newWorkspaceItem.getID())
+ .content(patchBody)
+ .contentType("application/json-patch+json"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.errors").doesNotExist());
+
+ //remove subject
+ operations = new ArrayList();
+ operations.add(new RemoveOperation("/sections/traditionalpagetwo/dc.subject/0"));
+ patchBody = getPatchContent(operations);
+ getClient(tokenSubmitter).perform(patch("/api/submission/workspaceitems/" + newWorkspaceItem.getID())
+ .content(patchBody)
+ .contentType("application/json-patch+json"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.errors").doesNotExist());
+
+ //add an asbtract description
+ Map addValue = new HashMap();
+ final String newDescription = "New Description";
+ addValue.put("value", newDescription);
+ operations = new ArrayList();
+ operations.add(new AddOperation("/sections/traditionalpagetwo/dc.description.abstract", List.of(addValue)));
+ patchBody = getPatchContent(operations);
+ getClient(tokenSubmitter).perform(patch("/api/submission/workspaceitems/" + newWorkspaceItem.getID())
+ .content(patchBody)
+ .contentType("application/json-patch+json"))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.errors").doesNotExist());
+
+ getClient(tokenSubmitter).perform(get("/api/submission/workspaceitems/" + newWorkspaceItem.getID()))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.sections.correction.metadata").doesNotExist());
+
+ AtomicReference workflowItemIdRef = new AtomicReference();
+
+ getClient(tokenSubmitter).perform(post("/api/workflow/workflowitems")
+ .content("/api/submission/workspaceitems/" + newWorkspaceItem.getID())
+ .contentType(textUriContentType))
+ .andExpect(status().isCreated())
+ .andDo(result -> workflowItemIdRef.set(read(result.getResponse().getContentAsString(), "$.id")));
+
+ String tokenAdmin = getAuthToken(admin.getEmail(), password);
+
+ //check if the correction is present
+ final String extraEntry = "ExtraEntry";
+ getClient(tokenAdmin).perform(get("/api/workflow/workflowitems/" + workflowItemIdRef.get()))
+ //The status has to be 200 OK
+ .andExpect(status().isOk())
+ //The array of browse index should have a size equals to 4
+ .andExpect(jsonPath("$.sections.correction.metadata", hasSize(equalTo(4))))
+ .andExpect(jsonPath("$.sections.correction.empty", is(false)))
+ .andExpect(jsonPath("$.sections.correction.metadata",hasItem(matchMetadataCorrection(newTitle))))
+ .andExpect(jsonPath("$.sections.correction.metadata",hasItem(matchMetadataCorrection(newDate))))
+ .andExpect(jsonPath("$.sections.correction.metadata",hasItem(matchMetadataCorrection(newDescription))))
+ .andExpect(jsonPath("$.sections.correction.metadata",hasItem(matchMetadataCorrection(extraEntry))));
+
+ }
+
@Test
public void checkEmptyCorrection() throws Exception {
String tokenSubmitter = getAuthToken(eperson.getEmail(), password);