Skip to content

Commit

Permalink
Updated bitstream patch validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mspalti committed Mar 26, 2024
1 parent 29ecc5c commit 4dbb130
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +25,9 @@ public class BitstreamMetadataValuePathUtils {

private DCInputsReader inputReader;

@Autowired
UploadConfigurationService uploadConfigurationService;

BitstreamMetadataValuePathUtils() throws DCInputsReaderException {
inputReader = new DCInputsReader();
}
Expand All @@ -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 ");
Expand Down

0 comments on commit 4dbb130

Please sign in to comment.