Search in sources :

Example 26 with ValidationResultMutable

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;
}
Also used : User(com.google.api.services.drive.model.User) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) ValidationResult(org.talend.daikon.properties.ValidationResult) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 27 with ValidationResultMutable

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;
}
Also used : User(com.google.api.services.drive.model.User) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 28 with ValidationResultMutable

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;
}
Also used : ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable)

Example 29 with ValidationResultMutable

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;
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 30 with ValidationResultMutable

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;
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Schema(org.apache.avro.Schema) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) Connection(java.sql.Connection) ComponentException(org.talend.components.api.exception.ComponentException) SQLException(java.sql.SQLException)

Aggregations

ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)41 IOException (java.io.IOException)11 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)8 ValidationResult (org.talend.daikon.properties.ValidationResult)7 SQLException (java.sql.SQLException)5 Schema (org.apache.avro.Schema)5 MarketoComponentDefinition.getSandboxedInstance (org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance)3 MarketoSourceOrSinkRuntime (org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime)3 SalesforceDefinition.getSandboxedInstance (org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance)3 SalesforceRuntimeSourceOrSink (org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)3 User (com.google.api.services.drive.model.User)2 File (java.io.File)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Connection (java.sql.Connection)2 MarketoSourceOrSinkSchemaProvider (org.talend.components.marketo.runtime.MarketoSourceOrSinkSchemaProvider)2 TMarketoInputProperties (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties)2 LeadSelector (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)2 SalesforceSchemaHelper (org.talend.components.salesforce.schema.SalesforceSchemaHelper)2 NamedThing (org.talend.daikon.NamedThing)2 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)2