Search in sources :

Example 11 with ValidationResultMutable

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

Example 12 with ValidationResultMutable

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

Example 13 with ValidationResultMutable

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

Example 14 with ValidationResultMutable

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;
}
Also used : Schema(org.apache.avro.Schema) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 15 with ValidationResultMutable

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;
}
Also used : FileDelimitedProperties(org.talend.components.filedelimited.FileDelimitedProperties) InputStream(java.io.InputStream) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) ValidationResult(org.talend.daikon.properties.ValidationResult) File(java.io.File)

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