From 482584827bca6ec97ea36420bd7ed14c1fc9da5f Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 7 Feb 2024 10:15:25 +0100 Subject: [PATCH] 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();