use of org.talend.components.service.rest.dto.ValidationResultsDto in project components by Talend.
the class RuntimeControllerImpl method doValidateDatastoreConnection.
private ResponseEntity<ValidationResultsDto> doValidateDatastoreConnection(DatastoreProperties properties) {
DatastoreDefinition<DatastoreProperties> definition = propertiesHelpers.getFirstDefinitionFromProperties(properties);
try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(properties), properties.getClass().getClassLoader())) {
DatastoreRuntime<DatastoreProperties> datastoreRuntime = (DatastoreRuntime) instance.getInstance();
datastoreRuntime.initialize(null, properties);
Iterable<ValidationResult> healthChecks = datastoreRuntime.doHealthChecks(null);
ValidationResultsDto response = new ValidationResultsDto(healthChecks == null ? emptyList() : newArrayList(healthChecks));
HttpStatus httpStatus = response.getStatus() == ValidationResult.Result.OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST;
return new ResponseEntity<>(response, httpStatus);
}
}
use of org.talend.components.service.rest.dto.ValidationResultsDto in project components by Talend.
the class PropertiesControllerImpl method doValidateProperties.
private ResponseEntity<ValidationResultsDto> doValidateProperties(Properties properties) {
ValidationResult validationResult = properties.getValidationResult();
// TODO: I really would prefer return 200 status code any time it process correctly and that the payload
// determine the
// result of the analysis.
// Here we use 400 return code for perfectly acceptable validation request but results with unaccepted
// properties.
ResponseEntity<ValidationResultsDto> response;
if (validationResult == null) {
response = new ResponseEntity<>(new ValidationResultsDto(emptyList()), OK);
} else {
switch(validationResult.getStatus()) {
case ERROR:
case WARNING:
response = new ResponseEntity<>(new ValidationResultsDto(validationResult), BAD_REQUEST);
break;
case OK:
default:
response = new ResponseEntity<>(new ValidationResultsDto(validationResult), OK);
}
}
return response;
}
Aggregations