Search in sources :

Example 1 with ValidationResultsDto

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);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) ValidationResultsDto(org.talend.components.service.rest.dto.ValidationResultsDto) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 2 with ValidationResultsDto

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;
}
Also used : ValidationResultsDto(org.talend.components.service.rest.dto.ValidationResultsDto) ValidationResult(org.talend.daikon.properties.ValidationResult)

Aggregations

ValidationResultsDto (org.talend.components.service.rest.dto.ValidationResultsDto)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1 DatastoreProperties (org.talend.components.common.datastore.DatastoreProperties)1 DatastoreRuntime (org.talend.components.common.datastore.runtime.DatastoreRuntime)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1