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