Make Dataset Validation checker to no longer be exception depedant
This commit is contained in:
parent
3eb27c04f6
commit
c41c89774b
|
@ -291,12 +291,12 @@ public class Datasets extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/validate"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Boolean>> validate(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||
try {
|
||||
Dataset dataset = datasetManager.getEntitySingle(id);
|
||||
datasetManager.checkDatasetValidation(dataset);
|
||||
String failedField = datasetManager.checkDatasetValidation(dataset);
|
||||
if (failedField == null) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Valid"));
|
||||
} catch (Exception datasetWizardCannotUnlockException) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Boolean>().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage()));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Boolean>().status(ApiMessageCode.ERROR_MESSAGE).message("Field value of " + failedField + " must be filled."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -587,8 +587,12 @@ public class DatasetManager {
|
|||
if (this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().getClient() != null) {
|
||||
this.getTagsFromProfile(datasetWizardModel, dataset);
|
||||
}
|
||||
if (datasetWizardModel.getStatus() == (int) Dataset.Status.FINALISED.getValue())
|
||||
checkDatasetValidation(dataset);
|
||||
if (datasetWizardModel.getStatus() == (int) Dataset.Status.FINALISED.getValue()) {
|
||||
String failedField = checkDatasetValidation(dataset);
|
||||
if (failedField != null) {
|
||||
throw new Exception("Field value of " + failedField + " must be filled.");
|
||||
}
|
||||
}
|
||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||
dataset.setCreator(userInfo);
|
||||
|
||||
|
@ -683,7 +687,7 @@ public class DatasetManager {
|
|||
|
||||
}
|
||||
|
||||
public void checkDatasetValidation(Dataset dataset) throws Exception {
|
||||
public String checkDatasetValidation(Dataset dataset) throws Exception {
|
||||
List<String> datasetProfileValidators = new LinkedList<>();
|
||||
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId());
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
|
@ -712,11 +716,17 @@ public class DatasetManager {
|
|||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
|
||||
|
||||
String failedField = null;
|
||||
|
||||
for (String validator : datasetProfileValidators) {
|
||||
if (obj.has(validator) && isNullOrEmpty(obj.getString(validator)) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
||||
throw new Exception("Field value of " + validator + " must be filled.");
|
||||
//throw new Exception("Field value of " + validator + " must be filled.");
|
||||
failedField = validator;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return failedField;
|
||||
}
|
||||
|
||||
private boolean isNullOrEmpty(String value) {
|
||||
|
|
Loading…
Reference in New Issue