From 4dbb1303bb3fdd5f2c7dc1f6d13062494cb59f19 Mon Sep 17 00:00:00 2001 From: Michael Spalti Date: Thu, 16 Nov 2023 10:14:28 -0800 Subject: [PATCH] Updated bitstream patch validation --- .../org/dspace/app/rest/submit/step/UploadStep.java | 3 ++- .../rest/utils/BitstreamMetadataValuePathUtils.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/UploadStep.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/UploadStep.java index 1dea6bbeeb7..61fd6974074 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/UploadStep.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/UploadStep.java @@ -48,7 +48,7 @@ public class UploadStep extends AbstractProcessingStep private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(UploadStep.class); - public static final String UPLOAD_STEP_METADATA_SECTION = "bitstream-metadata"; + public static String UPLOAD_STEP_ID; @Override public DataUpload getData(SubmissionService submissionService, InProgressSubmission obj, @@ -94,6 +94,7 @@ public void doPatchProcessing(Context context, HttpServletRequest currentRequest if (op.getPath().contains(UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY)) { instance = stepConf.getType() + "." + UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY; } else if (op.getPath().contains(UPLOAD_STEP_METADATA_PATH)) { + UPLOAD_STEP_ID = stepConf.getId(); instance = UPLOAD_STEP_METADATA_OPERATION_ENTRY; } else if (op.getPath().contains(PRIMARY_FLAG_ENTRY)) { instance = PRIMARY_FLAG_ENTRY; diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/BitstreamMetadataValuePathUtils.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/BitstreamMetadataValuePathUtils.java index dda661e4910..a3a8f3325c7 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/BitstreamMetadataValuePathUtils.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/BitstreamMetadataValuePathUtils.java @@ -12,6 +12,9 @@ import org.dspace.app.util.DCInputSet; import org.dspace.app.util.DCInputsReader; import org.dspace.app.util.DCInputsReaderException; +import org.dspace.submit.model.UploadConfiguration; +import org.dspace.submit.model.UploadConfigurationService; +import org.springframework.beans.factory.annotation.Autowired; /** * Utils class offering methods to validate patch operations for bitstream metadata in the submission @@ -22,6 +25,9 @@ public class BitstreamMetadataValuePathUtils { private DCInputsReader inputReader; + @Autowired + UploadConfigurationService uploadConfigurationService; + BitstreamMetadataValuePathUtils() throws DCInputsReaderException { inputReader = new DCInputsReader(); } @@ -36,13 +42,14 @@ public class BitstreamMetadataValuePathUtils { * @throws UnprocessableEntityException if the path is invalid */ public void validate(String absolutePath) throws DCInputsReaderException { + UploadConfiguration uploadService = uploadConfigurationService.getMap().get(UploadStep.UPLOAD_STEP_ID); + DCInputSet inputConfig = inputReader.getInputsByFormName(uploadService.getMetadata()); String[] split = absolutePath.split("/"); - DCInputSet inputConfig = inputReader.getInputsByFormName(UploadStep.UPLOAD_STEP_METADATA_SECTION); // according to the rest contract the absolute path must be something like files/:idx/metadata/dc.title if (split.length >= 4) { if (!inputConfig.isFieldPresent(split[3])) { throw new UnprocessableEntityException("The field " + split[3] + " is not present in section " - + UploadStep.UPLOAD_STEP_METADATA_SECTION); + + UploadStep.UPLOAD_STEP_ID); } } else { throw new UnprocessableEntityException("The path " + absolutePath + " cannot be patched ");