From 0e16cb5a3b07109c7d507ab63d76aa243759f92a Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 5 Feb 2024 17:33:31 +0100 Subject: [PATCH 1/3] [DSC-1526] Add test to check the bug --- .../org/dspace/app/rest/CorrectionStepIT.java | 98 ++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) 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); From 20c67d4289faa7f9c87634271918a5358a38376d Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 6 Feb 2024 09:50:39 +0100 Subject: [PATCH 2/3] DSC-1526 We now have a check for which if the workspace item is a correction request we check if it is submission correction or a simple submission --- .../app/util/SubmissionConfigReader.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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..02d7429b4112 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,11 @@ 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.dspace.web.ContextUtil; +import org.springframework.beans.factory.annotation.Autowired; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -58,6 +62,13 @@ */ public class SubmissionConfigReader { + + @Autowired + private ItemCorrectionService itemCorrectionService; + + @Autowired + RequestService requestService; + /** * The ID of the default collection. Will never be the ID of a named * collection @@ -430,6 +441,21 @@ private void doNodes(Node n) throws SAXException, SearchServiceException, Submis } } + + private boolean isCorrectionItem(Item item) { + Context context = ContextUtil.obtainCurrentRequestContext(); + ItemCorrectionService itemCorrectionService = + DSpaceServicesFactory.getInstance().getServiceManager() + .getServicesByType(ItemCorrectionService.class) + .get(0); + 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; + } + } + /** * Process the submission-map section of the XML file. Each element looks * like: Extract @@ -764,6 +790,13 @@ public SubmissionConfig getSubmissionConfigByInProgressSubmission(InProgressSubm return getSubmissionConfigByName(submissionDefinition); } - return getSubmissionConfigByCollection(object.getCollection()); + if (isCorrectionItem(object.getItem())) { + return getCorrectionSubmissionConfigByCollection(object.getCollection()); + } else { + return getSubmissionConfigByCollection(object.getCollection()); + } + } + + } \ No newline at end of file From 482584827bca6ec97ea36420bd7ed14c1fc9da5f Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 7 Feb 2024 10:15:25 +0100 Subject: [PATCH 3/3] DSC-1526 Improved code and fixed checkstyle --- .../app/util/SubmissionConfigReader.java | 42 +++++++++---------- .../service/impl/ValidationServiceImpl.java | 3 +- 2 files changed, 23 insertions(+), 22 deletions(-) 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 02d7429b4112..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 @@ -33,7 +33,6 @@ import org.dspace.services.RequestService; import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.versioning.ItemCorrectionService; -import org.dspace.web.ContextUtil; import org.springframework.beans.factory.annotation.Autowired; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; @@ -63,9 +62,6 @@ public class SubmissionConfigReader { - @Autowired - private ItemCorrectionService itemCorrectionService; - @Autowired RequestService requestService; @@ -129,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 @@ -442,19 +448,7 @@ private void doNodes(Node n) throws SAXException, SearchServiceException, Submis } - private boolean isCorrectionItem(Item item) { - Context context = ContextUtil.obtainCurrentRequestContext(); - ItemCorrectionService itemCorrectionService = - DSpaceServicesFactory.getInstance().getServiceManager() - .getServicesByType(ItemCorrectionService.class) - .get(0); - 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; - } - } + /** * Process the submission-map section of the XML file. Each element looks @@ -784,19 +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); } - if (isCorrectionItem(object.getItem())) { + 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();