use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class SnowflakeSourceOrSink method validateConnection.
public static ValidationResult validateConnection(SnowflakeProvideConnectionProperties properties) {
// check if every required properties was specified
ValidationResultMutable vr = validateConnectionProperties(properties);
if (vr.getStatus() == Result.OK) {
SnowflakeSourceOrSink sss = new SnowflakeSourceOrSink();
sss.initialize(null, (ComponentProperties) properties);
try {
sss.createConnection(null);
// Make sure we can get the schema names, as that tests that all of the connection parameters are really OK
sss.getSchemaNames((RuntimeContainer) null);
} catch (Exception ex) {
return exceptionToValidationResult(ex);
}
vr.setStatus(Result.OK);
vr.setMessage(SnowflakeConstants.CONNECTION_SUCCESSFUL_MESSAGE);
}
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class SnowflakeTableProperties method beforeTableName.
public ValidationResult beforeTableName() throws Exception {
ValidationResultMutable vr = new ValidationResultMutable();
try {
List<NamedThing> tableNames = SnowflakeSourceOrSink.getSchemaNames(null, connection);
tableName.setPossibleNamedThingValues(tableNames);
} catch (Exception ex) {
vr.setMessage(ex.getMessage());
vr.setStatus(ValidationResult.Result.ERROR);
}
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class SnowflakeCloseSourceOrSink method validate.
@Override
public ValidationResult validate(RuntimeContainer container) {
ValidationResultMutable result = new ValidationResultMutable();
try {
closeConnection(container);
result.setStatus(Result.OK);
} catch (Exception e) {
result.setMessage(e.getMessage());
result.setStatus(Result.ERROR);
}
return result;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class FileDelimitedProperties method validatePreview.
public ValidationResult validatePreview() {
ValidationResultMutable vr = new ValidationResultMutable();
try {
if (!StringUtils.isEmpty(fileName.getStringValue())) {
File file = new File(fileName.getStringValue());
if (!file.exists() || !file.isFile()) {
throw new IOException("File \"" + fileName.getStringValue() + "\" is not found.");
}
Map<String, Schema> dataAndSchema = FileDelimitedSource.previewData(null, this, 200);
for (String jsonData : dataAndSchema.keySet()) {
Schema guessedSchema = dataAndSchema.get(jsonData);
previewTable.setValue(jsonData);
if (guessedSchema.getFields().size() > 0) {
main.schema.setValue(guessedSchema);
} else {
main.schema.setValue(SchemaProperties.EMPTY_SCHEMA);
}
}
if (main.schema.getValue() != null && main.schema.getValue().getFields().size() > 0) {
getForm(FORM_WIZARD).setAllowFinish(true);
} else {
getForm(FORM_WIZARD).setAllowFinish(false);
}
}
} catch (Exception e) {
// Reset preview table when get exception
previewTable.setValue("{\"data\":[]}");
String errorMessage = e.getMessage();
if (e instanceof UnsupportedEncodingException) {
errorMessage = "java.io.UnsupportedEncodingException: " + errorMessage;
}
vr.setMessage(errorMessage);
vr.setStatus(ValidationResult.Result.ERROR);
getForm(FORM_WIZARD).setAllowFinish(false);
}
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class FileDelimitedSource method validate.
@Override
public ValidationResult validate(RuntimeContainer container) {
ValidationResultMutable vr = new ValidationResultMutable(super.validate(container));
// also check that the properties is the right type
if (vr.getStatus() != ValidationResult.Result.ERROR) {
if (!(properties instanceof FileDelimitedProperties)) {
return new ValidationResult(ValidationResult.Result.ERROR, "properties should be of type :" + FileDelimitedProperties.class.getCanonicalName());
}
}
Object fileOrStream = ((FileDelimitedProperties) properties).fileName.getValue();
if (fileOrStream == null) {
vr.setMessage(messages.getMessage("error.fileNameIsNull"));
vr.setStatus(ValidationResult.Result.ERROR);
} else {
if (fileOrStream instanceof InputStream) {
LOGGER.debug("Source is a stream");
} else {
File file = new File(String.valueOf(fileOrStream));
if (!file.exists()) {
vr.setMessage(messages.getMessage("error.fileNotFound", file.getPath()));
vr.setStatus(ValidationResult.Result.ERROR);
}
}
}
return vr;
}
Aggregations