diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/validation/MetadataValidation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/validation/MetadataValidation.java index 5528b5352f..9ee31656c2 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/validation/MetadataValidation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/validation/MetadataValidation.java @@ -83,6 +83,9 @@ public class MetadataValidation extends AbstractValidation { String fullFieldname = input.getFieldName() + "." + inputPairs.get(i); if (input.isAllowedFor(documentTypeValue)) { isAllowedLookup.put(fullFieldname, true); + // For the purposes of qualdrop, we have to add the field name without the qualifier + // too, or a required qualdrop will get confused and incorrectly reject a value + isAllowedLookup.put(input.getFieldName(), true); } } } else { @@ -103,12 +106,32 @@ public class MetadataValidation extends AbstractValidation { List fieldsName = new ArrayList(); if (input.isQualdropValue()) { + boolean foundResult = false; List inputPairs = input.getPairs(); //starting from the second element of the list and skipping one every time because the display // values are also in the list and before the stored values. for (int i = 1; i < inputPairs.size(); i += 2) { String fullFieldname = input.getFieldName() + "." + (String) inputPairs.get(i); - fieldsName.add(fullFieldname); + List mdv = itemService.getMetadataByMetadataString(obj.getItem(), fullFieldname); + + // Check the lookup list. If no other inputs of the same field name allow this type, + // then remove. This includes field name without qualifier. + if (!input.isAllowedFor(documentTypeValue) && (!isAllowedLookup.containsKey(fullFieldname) + && !isAllowedLookup.containsKey(input.getFieldName()))) { + itemService.removeMetadataValues(ContextUtil.obtainCurrentRequestContext(), + obj.getItem(), mdv); + } else { + validateMetadataValues(mdv, input, config, isAuthorityControlled, fieldKey, errors); + if (mdv.size() > 0 && input.isVisible(DCInput.SUBMISSION_SCOPE)) { + foundResult = true; + } + } + } + if (input.isRequired() && !foundResult) { + // for this required qualdrop no value was found, add to the list of error fields + addError(errors, ERROR_VALIDATION_REQUIRED, + "/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() + "/" + + input.getFieldName()); } } else { fieldsName.add(input.getFieldName());