Skip to content

Commit

Permalink
Initial revisions of patch validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mspalti committed Mar 26, 2024
1 parent 4dbb130 commit 0729265
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ void add(Context context, HttpServletRequest currentRequest, InProgressSubmissio
throws Exception {
//"path": "/sections/upload/files/0/metadata/dc.title/2"
//"abspath": "/files/0/metadata/dc.title/2"
String stepId = getStepId(path);
String absolutePath = getAbsolutePath(path);
String[] split = absolutePath.split("/");
bitstreamMetadataValuePathUtils.validate(absolutePath);
bitstreamMetadataValuePathUtils.validate(stepId, absolutePath);
Item item = source.getItem();
List<Bundle> bundle = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ void move(Context context, HttpServletRequest currentRequest, InProgressSubmissi
throws Exception {
//"path": "/sections/upload/files/0/metadata/dc.title/2"
//"abspath": "/files/0/metadata/dc.title/2"
String stepId = getStepId(path);
String absolutePath = getAbsolutePath(path);
String[] splitTo = absolutePath.split("/");
bitstreamMetadataValuePathUtils.validate(absolutePath);
bitstreamMetadataValuePathUtils.validate(stepId, absolutePath);
Item item = source.getItem();
List<Bundle> bundle = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
for (Bundle bb : bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ void remove(Context context, HttpServletRequest currentRequest, InProgressSubmis
Object value) throws Exception {
//"path": "/sections/upload/files/0/metadata/dc.title/2"
//"abspath": "/files/0/metadata/dc.title/2"
String stepId = getStepId(path);
String absolutePath = getAbsolutePath(path);
String[] split = absolutePath.split("/");
bitstreamMetadataValuePathUtils.validate(absolutePath);
bitstreamMetadataValuePathUtils.validate(stepId, absolutePath);
Item item = source.getItem();
List<Bundle> bundle = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ void replace(Context context, HttpServletRequest currentRequest, InProgressSubmi
Object value) throws Exception {
//"path": "/sections/upload/files/0/metadata/dc.title/2"
//"abspath": "/files/0/metadata/dc.title/2"
String stepId = getStepId(path);
String absolutePath = getAbsolutePath(path);
String[] split = absolutePath.split("/");
bitstreamMetadataValuePathUtils.validate(absolutePath);
bitstreamMetadataValuePathUtils.validate(stepId, absolutePath);
Item item = source.getItem();
List<Bundle> bundle = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
for (Bundle bb : bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void add(Context context, HttpServletRequest currentRequest, InProgressSubmissio
Item item = source.getItem();

List<Bundle> bundle = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
;

UploadConfiguration uploadConfig = uploadConfigurationService.getMap().get(splitPath[2]);
for (Bundle bb : bundle) {
int idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public String getAbsolutePath(String fullpath) {
return absolutePath;
}

public String getStepId(String fullpath) {
String[] path = fullpath.substring(1).split("/", 3);
String stepId = "";
if (path.length > 1) {
stepId = path[1];
}
return stepId;
}

protected abstract Class<T[]> getArrayClassForEvaluation();

protected abstract Class<T> getClassForEvaluation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class UploadStep extends AbstractProcessingStep

private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(UploadStep.class);

public static String UPLOAD_STEP_ID;

@Override
public DataUpload getData(SubmissionService submissionService, InProgressSubmission obj,
SubmissionStepConfig config) throws Exception {
Expand Down Expand Up @@ -94,7 +92,6 @@ 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 @@ -41,15 +41,15 @@ public class BitstreamMetadataValuePathUtils {
* submission configuration
* @throws UnprocessableEntityException if the path is invalid
*/
public void validate(String absolutePath) throws DCInputsReaderException {
UploadConfiguration uploadService = uploadConfigurationService.getMap().get(UploadStep.UPLOAD_STEP_ID);
public void validate(String stepId, String absolutePath) throws DCInputsReaderException {
UploadConfiguration uploadService = uploadConfigurationService.getMap().get(stepId);
DCInputSet inputConfig = inputReader.getInputsByFormName(uploadService.getMetadata());
String[] split = absolutePath.split("/");
// 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_ID);
+ stepId);
}
} else {
throw new UnprocessableEntityException("The path " + absolutePath + " cannot be patched ");
Expand Down

0 comments on commit 0729265

Please sign in to comment.