Skip to content

Commit

Permalink
Merged in dspace-cris-2023_02_x-DSC-1526 (pull request DSpace#1661)
Browse files Browse the repository at this point in the history
Dspace cris 2023 02 x DSC-1526

Approved-by: Giuseppe Digilio
  • Loading branch information
Mattia Vianelli authored and atarix83 committed Feb 7, 2024
2 parents 302ab35 + 4825848 commit 217a588
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: <name-map collection-handle="hdl" submission-name="name" /> Extract
Expand Down Expand Up @@ -758,12 +778,25 @@ public List<Collection> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ private void setup() throws SubmissionConfigReaderException {
@Override
public List<ValidationError> validate(Context context, InProgressSubmission<?> obj) {

SubmissionConfig submissionConfig = submissionConfigReader.getSubmissionConfigByInProgressSubmission(obj);
SubmissionConfig submissionConfig = submissionConfigReader
.getSubmissionConfigByInProgressSubmission(obj, context);

List<ValidationError> errors = new ArrayList<ValidationError>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<Relationship> 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<String, String> value = new HashMap<String, String>();
final String newDate = "2020-02-21";
value.put("value", newDate);
List<Operation> operations = new ArrayList<Operation>();
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<Operation>();
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<Operation>();
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<String, String> addValue = new HashMap<String, String>();
final String newDescription = "New Description";
addValue.put("value", newDescription);
operations = new ArrayList<Operation>();
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<Integer> workflowItemIdRef = new AtomicReference<Integer>();

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);
Expand Down

0 comments on commit 217a588

Please sign in to comment.