Search in sources :

Example 6 with SalesforceRuntimeSourceOrSink

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

the class SalesforceDatasetProperties method retrieveModuleFields.

private void retrieveModuleFields() throws IOException {
    // refresh the module list
    if (sourceType.getValue() == SourceType.MODULE_SELECTION && StringUtils.isNotEmpty(moduleName.getValue())) {
        Consumer consumer = new Consumer() {

            @Override
            public void accept(SalesforceRuntimeSourceOrSink runtime) throws IOException {
                List<NamedThing> moduleNames = runtime.getSchemaNames(null);
                moduleName.setPossibleNamedThingValues(filter(moduleNames));
                Schema schema = runtime.getEndpointSchema(null, moduleName.getValue());
                List<NamedThing> columns = new ArrayList<>();
                for (Schema.Field field : schema.getFields()) {
                    columns.add(new SimpleNamedThing(field.name(), field.name()));
                }
                selectColumnIds.setPossibleValues(columns);
            }
        };
        runtimeTask(consumer);
    }
}
Also used : Schema(org.apache.avro.Schema) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 7 with SalesforceRuntimeSourceOrSink

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

the class SalesforceDatasetProperties method runtimeTask.

private void runtimeTask(Consumer task) throws IOException {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(DATAPREP_SOURCE_CLASS)) {
        SalesforceRuntimeSourceOrSink runtime = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        SalesforceInputProperties properties = new SalesforceInputProperties("model");
        properties.setDatasetProperties(this);
        throwExceptionIfValidationResultIsError(runtime.initialize(null, properties));
        throwExceptionIfValidationResultIsError(runtime.validate(null));
        task.accept(runtime);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties)

Example 8 with SalesforceRuntimeSourceOrSink

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

the class SalesforceModuleListProperties method beforeFormPresentMain.

public void beforeFormPresentMain() 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) {
            try {
                moduleNames = ss.getSchemaNames(null);
            } catch (Exception ex) {
                throw new ComponentException(ExceptionUtil.exceptionToValidationResult(ex));
            }
            selectedModuleNames.setPossibleValues(moduleNames);
            getForm(Form.MAIN).setAllowBack(true);
            getForm(Form.MAIN).setAllowFinish(true);
        } else {
            throw new ComponentException(vr);
        }
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) 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 9 with SalesforceRuntimeSourceOrSink

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

the class TSalesforceInputProperties method validateGuessSchema.

public ValidationResult validateGuessSchema() {
    ValidationResultMutable validationResult = new ValidationResultMutable();
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS)) {
        SalesforceRuntimeSourceOrSink salesforceSourceOrSink = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        salesforceSourceOrSink.initialize(null, this);
        Schema schema = ((SalesforceSchemaHelper<Schema>) salesforceSourceOrSink).guessSchema(query.getValue());
        module.main.schema.setValue(schema);
        validationResult.setStatus(ValidationResult.Result.OK);
    } catch (TalendRuntimeException tre) {
        String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaSoqlError", tre.getMessage());
        validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
    } catch (RuntimeException e1) {
        String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaRuntimeError", e1.getMessage());
        validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
    } catch (IOException e2) {
        String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaConnectionError", e2.getMessage());
        validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
    }
    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) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) Schema(org.apache.avro.Schema) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) IOException(java.io.IOException)

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