use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class GoogleDriveDataSource method validate.
@Override
public ValidationResult validate(RuntimeContainer container) {
ValidationResult vr = new ValidationResultMutable(Result.OK);
// check for Connection attributes
if (StringUtils.isEmpty(serviceAccountFile)) {
vr = new ValidationResultMutable(Result.ERROR).setMessage("Service Account JSON File cannot be empty.");
return vr;
}
try {
// make a dummy call to check drive's connection..
User u = getDriveService().about().get().setFields("user").execute().getUser();
LOG.debug("[validate] Testing User Properties: {}.", u);
} catch (Exception ex) {
LOG.error("[validate] {}.", ex.getMessage());
vr = new ValidationResultMutable(Result.ERROR).setMessage(ex.getMessage());
return vr;
}
return ValidationResult.OK;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class GoogleDriveRuntime method validateConnection.
public ValidationResult validateConnection(GoogleDriveConnectionProperties connectionProperties) {
if ((OAuthMethod.InstalledApplicationWithIdAndSecret.equals(connectionProperties.oAuthMethod.getValue()) || OAuthMethod.InstalledApplicationWithJSON.equals(connectionProperties.oAuthMethod.getValue())) && container == null) {
cleanupCredentialsStore(getDatastoreFile(connectionProperties).toPath().resolve("StoredCredential"));
}
ValidationResultMutable vr = new ValidationResultMutable(validateConnectionProperties(connectionProperties));
if (Result.ERROR.equals(vr.getStatus())) {
return vr;
}
try {
// make a dummy call to check drive's connection..
User u = getDriveService().about().get().setFields("user").execute().getUser();
LOG.debug("[validateConnection] Testing User Properties: {}.", u);
} catch (Exception ex) {
LOG.error("[validateConnection] {}.", ex.getMessage());
vr.setStatus(Result.ERROR);
vr.setMessage(ex.getMessage());
return vr;
}
vr.setStatus(Result.OK);
vr.setMessage(messages.getMessage("message.connectionSuccessful"));
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class GoogleDriveValidator method validatePutProperties.
public ValidationResult validatePutProperties(GoogleDrivePutProperties properties) {
ValidationResultMutable vr = new ValidationResultMutable(Result.OK);
if (StringUtils.isEmpty(properties.fileName.getValue())) {
vr.setStatus(Result.ERROR);
vr.setMessage(messages.getMessage("error.validation.filename.empty"));
return vr;
}
if (!UPLOAD_LOCAL_FILE.equals(properties.uploadMode.getValue())) {
vr.setStatus(Result.ERROR);
vr.setMessage(messages.getMessage("error.validation.put.invalid.flow"));
return vr;
}
if (StringUtils.isEmpty(properties.destinationFolder.getValue())) {
vr.setStatus(Result.ERROR);
vr.setMessage(messages.getMessage("error.validation.parentfolder.empty"));
return vr;
}
if (StringUtils.isEmpty(properties.localFilePath.getValue())) {
vr.setStatus(Result.ERROR);
vr.setMessage(messages.getMessage("error.validation.local.filename.empty"));
return vr;
}
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class JDBCRowSourceOrSink method validate.
@Override
public ValidationResult validate(RuntimeContainer runtime) {
if (runtime != null) {
runtime.setComponentData(runtime.getCurrentComponentId(), CommonUtils.getStudioNameFromProperty(ComponentConstants.RETURN_QUERY), setting.getSql());
}
ValidationResultMutable vr = new ValidationResultMutable();
AllSetting setting = properties.getRuntimeSetting();
String sql = setting.getSql();
boolean usePreparedStatement = setting.getUsePreparedStatement();
boolean dieOnError = setting.getDieOnError();
Connection conn = null;
try {
conn = connect(runtime);
} catch (ClassNotFoundException | SQLException e) {
throw CommonUtils.newComponentException(e);
}
try {
if (usePreparedStatement) {
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
JdbcRuntimeUtils.setPreparedStatement(pstmt, setting.getIndexs(), setting.getTypes(), setting.getValues());
pstmt.execute();
}
} else {
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
}
}
if (useCommit) {
conn.commit();
}
} catch (Exception ex) {
if (dieOnError) {
vr.setStatus(Result.ERROR);
vr.setMessage(CommonUtils.correctExceptionInfo(ex));
} else {
System.err.println(CommonUtils.correctExceptionInfo(ex));
}
} finally {
if (!useExistedConnection) {
try {
conn.close();
} catch (SQLException e) {
throw CommonUtils.newComponentException(e);
}
}
}
return vr;
}
use of org.talend.daikon.properties.ValidationResultMutable in project components by Talend.
the class JDBCSPSourceOrSink method validate.
@Override
public ValidationResult validate(RuntimeContainer runtime) {
ValidationResultMutable vr = new ValidationResultMutable();
Connection conn = null;
try {
conn = connect(runtime);
} catch (ClassNotFoundException | SQLException e) {
throw CommonUtils.newComponentException(e);
}
Schema componentSchema = CommonUtils.getMainSchemaFromInputConnector((ComponentProperties) properties);
try {
try (CallableStatement cs = conn.prepareCall(getSPStatement(setting))) {
fillParameters(cs, componentSchema, null, null, setting);
cs.execute();
}
} catch (Exception ex) {
vr.setStatus(Result.ERROR);
vr.setMessage(CommonUtils.correctExceptionInfo(ex));
} finally {
if (!useExistedConnection) {
try {
conn.close();
} catch (SQLException e) {
// close quietly
}
}
}
return vr;
}
Aggregations