Skip to content

Commit

Permalink
DSC-1526 Improved code and fixed checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattia Vianelli committed Feb 7, 2024
1 parent 20c67d4 commit 4825848
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,9 +62,6 @@

public class SubmissionConfigReader {

@Autowired
private ItemCorrectionService itemCorrectionService;

@Autowired
RequestService requestService;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -784,19 +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);
}

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;
}
}
}
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

0 comments on commit 4825848

Please sign in to comment.