mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[task 85840] implementation of different requirement check for qualdrops in input forms
This commit is contained in:
@@ -63,37 +63,38 @@ public class MetadataValidation extends AbstractValidation {
|
||||
|
||||
List<String> fieldsName = new ArrayList<String>();
|
||||
if (input.isQualdropValue()) {
|
||||
for (Object qualifier : input.getPairs()) {
|
||||
fieldsName.add(input.getFieldName() + "." + (String) qualifier);
|
||||
boolean foundResult = false;
|
||||
List<Object> 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);
|
||||
List<MetadataValue> mdv = itemService.getMetadataByMetadataString(obj.getItem(), fullFieldname);
|
||||
validateMetadataValues(mdv, input, config, isAuthorityControlled, fieldKey);
|
||||
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(ERROR_VALIDATION_REQUIRED,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() + "/" +
|
||||
input.getFieldName());
|
||||
}
|
||||
|
||||
} else {
|
||||
fieldsName.add(input.getFieldName());
|
||||
}
|
||||
|
||||
for (String fieldName : fieldsName) {
|
||||
List<MetadataValue> mdv = itemService.getMetadataByMetadataString(obj.getItem(), fieldName);
|
||||
for (MetadataValue md : mdv) {
|
||||
if (!(input.validate(md.getValue()))) {
|
||||
addError(ERROR_VALIDATION_REGEX,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() + "/" +
|
||||
input.getFieldName() + "/" + md.getPlace());
|
||||
}
|
||||
if (isAuthorityControlled) {
|
||||
String authKey = md.getAuthority();
|
||||
if (metadataAuthorityService.isAuthorityRequired(fieldKey) &&
|
||||
StringUtils.isBlank(authKey)) {
|
||||
addError(ERROR_VALIDATION_AUTHORITY_REQUIRED,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() +
|
||||
"/" + input.getFieldName() + "/" + md.getPlace());
|
||||
}
|
||||
}
|
||||
}
|
||||
validateMetadataValues(mdv, input, config, isAuthorityControlled, fieldKey);
|
||||
if ((input.isRequired() && mdv.size() == 0) && input.isVisible(DCInput.SUBMISSION_SCOPE)) {
|
||||
// since this field is missing add to list of error
|
||||
// fields
|
||||
addError(ERROR_VALIDATION_REQUIRED,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() + "/" +
|
||||
input.getFieldName());
|
||||
input.getFieldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,6 +102,26 @@ public class MetadataValidation extends AbstractValidation {
|
||||
return getErrors();
|
||||
}
|
||||
|
||||
private void validateMetadataValues(List<MetadataValue> mdv, DCInput input, SubmissionStepConfig config,
|
||||
boolean isAuthorityControlled, String fieldKey) {
|
||||
for (MetadataValue md : mdv) {
|
||||
if (! (input.validate(md.getValue()))) {
|
||||
addError(ERROR_VALIDATION_REGEX,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() + "/" +
|
||||
input.getFieldName() + "/" + md.getPlace());
|
||||
}
|
||||
if (isAuthorityControlled) {
|
||||
String authKey = md.getAuthority();
|
||||
if (metadataAuthorityService.isAuthorityRequired(fieldKey) &&
|
||||
StringUtils.isBlank(authKey)) {
|
||||
addError(ERROR_VALIDATION_AUTHORITY_REQUIRED,
|
||||
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/" + config.getId() +
|
||||
"/" + input.getFieldName() + "/" + md.getPlace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
@@ -5940,7 +5940,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
|
||||
MetadataFieldName issnFieldName = new MetadataFieldName("dc", "identifier", "issn");
|
||||
MetadataFieldName isbnFieldName = new MetadataFieldName("dc", "identifier", "isbn");
|
||||
MetadataFieldName urlfieldName = new MetadataFieldName("dc", "identifier", "url");
|
||||
MetadataFieldName citationFieldName = new MetadataFieldName("dc", "identifier", "citation");
|
||||
|
||||
WorkspaceItem workspaceItem1 = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
|
||||
.withTitle("test workspace item 1")
|
||||
@@ -5956,7 +5956,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
WorkspaceItem workspaceItem3 = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
|
||||
.withTitle("test workspace item 3")
|
||||
.build();
|
||||
itemService.setMetadataSingleValue(context, workspaceItem3.getItem(), urlfieldName, null, "url");
|
||||
itemService.setMetadataSingleValue(context, workspaceItem3.getItem(),citationFieldName, null, "citation");
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
@@ -5973,7 +5973,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath(errorPath).doesNotExist());
|
||||
|
||||
getClient(authToken).perform(get(workspaceItemsUri + workspaceItem3.getItem()))
|
||||
getClient(authToken).perform(get(workspaceItemsUri + workspaceItem3.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.required')]",
|
||||
Matchers.contains(
|
||||
|
Reference in New Issue
Block a user