From 4ad05c6bdc2c491220415b1c87f2a41b9308ee78 Mon Sep 17 00:00:00 2001 From: philippcle Date: Fri, 7 Jul 2023 11:24:08 +0200 Subject: [PATCH 1/2] use authority instead of value for type-bind --- .../dspace/validation/MetadataValidator.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java index 3d50ddf66cd8..ac53c0e2ca5f 100644 --- a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java +++ b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java @@ -69,10 +69,10 @@ public List validate(Context context, InProgressSubmission o List errors = new ArrayList<>(); DCInputSet inputConfig = getDCInputSet(config); - String documentTypeValue = getDocumentTypeValue(obj); + String documentTypeAuthority = getDocumentTypeAuthority(obj); // Get list of all field names (including qualdrop names) allowed for this dc.type - List allowedFieldNames = inputConfig.populateAllowedFieldNames(documentTypeValue); + List allowedFieldNames = inputConfig.populateAllowedFieldNames(documentTypeAuthority); for (DCInput[] row : inputConfig.getFields()) { for (DCInput input : row) { @@ -93,7 +93,7 @@ public List validate(Context context, InProgressSubmission o // 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) && (!allowedFieldNames.contains(fullFieldname) + if (!input.isAllowedFor(documentTypeAuthority) && (!allowedFieldNames.contains(fullFieldname) && !allowedFieldNames.contains(input.getFieldName()))) { removeMetadataValues(context, obj.getItem(), mdv); } else { @@ -118,18 +118,18 @@ public List validate(Context context, InProgressSubmission o for (String fieldName : fieldsName) { boolean valuesRemoved = false; List mdv = itemService.getMetadataByMetadataString(obj.getItem(), fieldName); - if (!input.isAllowedFor(documentTypeValue)) { + if (!input.isAllowedFor(documentTypeAuthority)) { // Check the lookup list. If no other inputs of the same field name allow this type, // then remove. Otherwise, do not if (!(allowedFieldNames.contains(fieldName))) { removeMetadataValues(context, obj.getItem(), mdv); valuesRemoved = true; log.debug("Stripping metadata values for " + input.getFieldName() + " on type " - + documentTypeValue + " as it is allowed by another input of the same field " + + + documentTypeAuthority + " as it is allowed by another input of the same field " + "name"); } else { log.debug("Not removing unallowed metadata values for " + input.getFieldName() + " on type " - + documentTypeValue + " as it is allowed by another input of the same field " + + + documentTypeAuthority + " as it is allowed by another input of the same field " + "name"); } } @@ -139,7 +139,7 @@ public List validate(Context context, InProgressSubmission o && !valuesRemoved) { // Is the input required for *this* type? In other words, are we looking at a required // input that is also allowed for this document type - if (input.isAllowedFor(documentTypeValue)) { + if (input.isAllowedFor(documentTypeAuthority)) { // since this field is missing add to list of error // fields addError(errors, ERROR_VALIDATION_REQUIRED, @@ -153,10 +153,10 @@ public List validate(Context context, InProgressSubmission o return errors; } - private String getDocumentTypeValue(InProgressSubmission obj) { + private String getDocumentTypeAuthority(InProgressSubmission obj) { String documentTypeField = configurationService.getProperty("submit.type-bind.field", "dc.type"); List documentType = itemService.getMetadataByMetadataString(obj.getItem(), documentTypeField); - return documentType.size() > 0 ? documentType.get(0).getValue() : ""; + return documentType.size() > 0 ? documentType.get(0).getAuthority() : ""; } private DCInputSet getDCInputSet(SubmissionStepConfig config) { From f80d2fe62cd90c41190f4cc6d597282f17a0ce0f Mon Sep 17 00:00:00 2001 From: philippcle Date: Fri, 7 Jul 2023 11:51:21 +0200 Subject: [PATCH 2/2] use embedded functionality --- .../src/main/java/org/dspace/validation/MetadataValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java index ac53c0e2ca5f..fe21cf5c71c2 100644 --- a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java +++ b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java @@ -156,7 +156,7 @@ public List validate(Context context, InProgressSubmission o private String getDocumentTypeAuthority(InProgressSubmission obj) { String documentTypeField = configurationService.getProperty("submit.type-bind.field", "dc.type"); List documentType = itemService.getMetadataByMetadataString(obj.getItem(), documentTypeField); - return documentType.size() > 0 ? documentType.get(0).getAuthority() : ""; + return !documentType.isEmpty() ? documentType.get(0).getAuthority() : ""; } private DCInputSet getDCInputSet(SubmissionStepConfig config) {