Search in sources :

Example 1 with SalesforceRuntimeSourceOrSink

use of org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink in project components by Talend.

the class SalesforceModuleProperties method beforeModuleName.

// consider beforeActivate and beforeRender (change after to afterActivate)
public ValidationResult beforeModuleName() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, getEffectiveConnection());
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() == ValidationResult.Result.OK) {
            try {
                List<NamedThing> moduleNames = ss.getSchemaNames(null);
                moduleName.setPossibleNamedThingValues(moduleNames);
            } catch (Exception ex) {
                return ExceptionUtil.exceptionToValidationResult(ex);
            }
        } else {
            return vr;
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) NamedThing(org.talend.daikon.NamedThing) ComponentException(org.talend.components.api.exception.ComponentException)

Example 2 with SalesforceRuntimeSourceOrSink

use of org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink in project components by Talend.

the class SalesforceModuleProperties method afterModuleName.

public ValidationResult afterModuleName() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, getEffectiveConnection());
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() == ValidationResult.Result.OK) {
            try {
                Schema schema = ss.getEndpointSchema(null, moduleName.getStringValue());
                main.schema.setValue(schema);
                moduleName.setPossibleValues(Collections.emptyList());
            } catch (Exception ex) {
                throw new ComponentException(ExceptionUtil.exceptionToValidationResult(ex));
            }
        } else {
            throw new ComponentException(vr);
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) Schema(org.apache.avro.Schema) ComponentException(org.talend.components.api.exception.ComponentException) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException)

Example 3 with SalesforceRuntimeSourceOrSink

use of org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink in project components by Talend.

the class SalesforceConnectionProperties method validateTestConnection.

public ValidationResult validateTestConnection() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, SalesforceConnectionProperties.this);
        ValidationResultMutable vr = new ValidationResultMutable(ss.validate(null));
        if (vr.getStatus() == ValidationResult.Result.OK) {
            vr.setMessage(MESSAGES.getMessage("connection.success"));
            getForm(FORM_WIZARD).setAllowForward(true);
        } else {
            getForm(FORM_WIZARD).setAllowForward(false);
        }
        return vr;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)

Example 4 with SalesforceRuntimeSourceOrSink

use of org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink in project components by Talend.

the class SalesforceModuleListProperties method afterFormFinishMain.

public ValidationResult afterFormFinishMain(Repository<Properties> repo) throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, this);
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() != ValidationResult.Result.OK) {
            return vr;
        }
        String connRepLocation = repo.storeProperties(connection, connection.name.getValue(), repositoryLocation, null);
        for (NamedThing nl : selectedModuleNames.getValue()) {
            String moduleId = nl.getName();
            SalesforceModuleProperties modProps = new SalesforceModuleProperties(moduleId);
            modProps.connection = connection;
            modProps.init();
            Schema schema = ss.getEndpointSchema(null, moduleId);
            modProps.moduleName.setValue(moduleId);
            modProps.main.schema.setValue(schema);
            repo.storeProperties(modProps, nl.getName(), connRepLocation, "main.schema");
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) Schema(org.apache.avro.Schema) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) NamedThing(org.talend.daikon.NamedThing)

Example 5 with SalesforceRuntimeSourceOrSink

use of org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink in project components by Talend.

the class TSalesforceInputProperties method validateGuessQuery.

public ValidationResult validateGuessQuery() {
    ValidationResultMutable validationResult = new ValidationResultMutable();
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS)) {
        SalesforceRuntimeSourceOrSink salesforceSourceOrSink = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        salesforceSourceOrSink.initialize(null, this);
        Schema schema = module.main.schema.getValue();
        String moduleName = module.moduleName.getValue();
        if (!schema.getFields().isEmpty()) {
            String soqlQuery = ((SalesforceSchemaHelper<Schema>) salesforceSourceOrSink).guessQuery(schema, moduleName);
            query.setValue(soqlQuery);
            validationResult.setStatus(ValidationResult.Result.OK);
        } else {
            String errorMessage = getI18nMessage("errorMessage.validateGuessQueryError");
            validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
            query.setValue("");
        }
    } catch (TalendRuntimeException tre) {
        validationResult.setStatus(ValidationResult.Result.ERROR);
        validationResult.setMessage(getI18nMessage("errorMessage.validateGuessQuerySoqlError", tre.getMessage()));
    }
    return validationResult;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) SalesforceSchemaHelper(org.talend.components.salesforce.schema.SalesforceSchemaHelper) Schema(org.apache.avro.Schema) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)

Aggregations

SalesforceRuntimeSourceOrSink (org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)9 SalesforceDefinition.getSandboxedInstance (org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance)8 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)8 Schema (org.apache.avro.Schema)5 ValidationResult (org.talend.daikon.properties.ValidationResult)4 ComponentException (org.talend.components.api.exception.ComponentException)3 NamedThing (org.talend.daikon.NamedThing)3 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)3 SalesforceSchemaHelper (org.talend.components.salesforce.schema.SalesforceSchemaHelper)2 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SalesforceInputProperties (org.talend.components.salesforce.dataprep.SalesforceInputProperties)1 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)1