Search in sources :

Example 1 with SourceOrSink

use of org.talend.components.api.component.runtime.SourceOrSink in project components by Talend.

the class SalesforceRuntimeTestUtil method initWriter.

private Writer<?> initWriter(TSalesforceOutputBulkDefinition definition, TSalesforceOutputBulkProperties modelProperties) throws IOException {
    // simulate to generate the runtime code
    TSalesforceOutputBulkProperties runtimeProperties = (TSalesforceOutputBulkProperties) definition.createRuntimeProperties();
    // pass all the value from the ui model
    runtimeProperties.schema.schema.setValue(modelProperties.schema.schema.getValue());
    runtimeProperties.bulkFilePath.setValue(modelProperties.bulkFilePath.getStringValue());
    runtimeProperties.append.setValue(modelProperties.append.getValue());
    runtimeProperties.ignoreNull.setValue(modelProperties.ignoreNull.getValue());
    Object obj = modelProperties.upsertRelationTable.columnName.getValue();
    if (obj != null && obj instanceof List && !((List<?>) obj).isEmpty()) {
        runtimeProperties.upsertRelationTable.columnName.setValue(modelProperties.upsertRelationTable.columnName.getValue());
        runtimeProperties.upsertRelationTable.lookupFieldExternalIdName.setValue(modelProperties.upsertRelationTable.lookupFieldExternalIdName.getValue());
        runtimeProperties.upsertRelationTable.lookupFieldModuleName.setValue(modelProperties.upsertRelationTable.lookupFieldModuleName.getValue());
        runtimeProperties.upsertRelationTable.lookupRelationshipFieldName.setValue(modelProperties.upsertRelationTable.lookupRelationshipFieldName.getValue());
        runtimeProperties.upsertRelationTable.polymorphic.setValue(modelProperties.upsertRelationTable.polymorphic.getValue());
    }
    SourceOrSink source_sink = new SalesforceBulkFileSink();
    source_sink.initialize(null, runtimeProperties);
    ValidationResult result = source_sink.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    Sink sink = (Sink) source_sink;
    WriteOperation<?> writeOperation = sink.createWriteOperation();
    writeOperation.initialize(null);
    Writer<?> writer = writeOperation.createWriter(null);
    writer.open("component_instance_id");
    return writer;
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) Sink(org.talend.components.api.component.runtime.Sink) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 2 with SourceOrSink

use of org.talend.components.api.component.runtime.SourceOrSink in project components by Talend.

the class SalesforceProxyTestIT method testProxy.

@Test
public void testProxy() {
    TSalesforceConnectionDefinition definition = (TSalesforceConnectionDefinition) getComponentService().getComponentDefinition(TSalesforceConnectionDefinition.COMPONENT_NAME);
    SalesforceConnectionProperties properties = (SalesforceConnectionProperties) definition.createRuntimeProperties();
    properties.bulkConnection.setValue(true);
    properties.userPassword.userId.setValue(userId);
    properties.userPassword.password.setValue(password);
    properties.userPassword.securityKey.setValue(securityKey);
    SourceOrSink sourceOrSink = new SalesforceSourceOrSink();
    sourceOrSink.initialize(null, properties);
    org.talend.daikon.properties.ValidationResult vr = sourceOrSink.validate(null);
    Assert.assertEquals(ValidationResult.Result.OK, vr.getStatus());
}
Also used : ValidationResult(org.talend.daikon.properties.ValidationResult) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) TSalesforceConnectionDefinition(org.talend.components.salesforce.tsalesforceconnection.TSalesforceConnectionDefinition) Test(org.junit.Test)

Example 3 with SourceOrSink

use of org.talend.components.api.component.runtime.SourceOrSink in project components by Talend.

the class TSnowflakeCloseDefinitionTest method testGetRuntime.

/**
 * Check {@link TSnowflakeCloseDefinition#getRuntimeInfo(ExecutionEngine, ComponentProperties, ConnectorTopology)} returns instance of {@link SnowflakeCloseSourceOrSink}
 */
@Test
public void testGetRuntime() {
    RuntimeInfo runtimeInfo = snowflakeCloseDefinition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.NONE);
    SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, snowflakeCloseDefinition.getClass().getClassLoader());
    SourceOrSink source = (SourceOrSink) sandboxedInstance.getInstance();
    assertThat(source, is(instanceOf(SnowflakeCloseSourceOrSink.class)));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SnowflakeCloseSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 4 with SourceOrSink

use of org.talend.components.api.component.runtime.SourceOrSink in project components by Talend.

the class JDBCTableSelectionModule method beforeTablename.

public ValidationResult beforeTablename() throws IOException {
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(connection, "org.talend.components.jdbc.runtime.JDBCSource");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        SourceOrSink ss = (SourceOrSink) sandboxI.getInstance();
        ss.initialize(null, (ComponentProperties) connection);
        List<NamedThing> tablenames = ss.getSchemaNames(null);
        tablename.setPossibleNamedThingValues(tablenames);
    } catch (ComponentException ex) {
        return ex.getValidationResult();
    }
    return ValidationResult.OK;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing)

Example 5 with SourceOrSink

use of org.talend.components.api.component.runtime.SourceOrSink in project components by Talend.

the class SalesforceRuntimeTestUtil method initWriter.

private Writer initWriter(TSalesforceOutputBulkDefinition definition, TSalesforceOutputBulkProperties modelProperties) throws IOException {
    // simulate to generate the runtime code
    TSalesforceOutputBulkProperties runtimeProperties = (TSalesforceOutputBulkProperties) definition.createRuntimeProperties();
    // pass all the value from the ui model
    runtimeProperties.schema.schema.setValue(modelProperties.schema.schema.getValue());
    runtimeProperties.bulkFilePath.setValue(modelProperties.bulkFilePath.getStringValue());
    runtimeProperties.append.setValue(modelProperties.append.getValue());
    runtimeProperties.ignoreNull.setValue(modelProperties.ignoreNull.getValue());
    Object obj = modelProperties.upsertRelationTable.columnName.getValue();
    if (obj != null && obj instanceof List && !((List) obj).isEmpty()) {
        runtimeProperties.upsertRelationTable.columnName.setValue(modelProperties.upsertRelationTable.columnName.getValue());
        runtimeProperties.upsertRelationTable.lookupFieldExternalIdName.setValue(modelProperties.upsertRelationTable.lookupFieldExternalIdName.getValue());
        runtimeProperties.upsertRelationTable.lookupFieldModuleName.setValue(modelProperties.upsertRelationTable.lookupFieldModuleName.getValue());
        runtimeProperties.upsertRelationTable.lookupRelationshipFieldName.setValue(modelProperties.upsertRelationTable.lookupRelationshipFieldName.getValue());
        runtimeProperties.upsertRelationTable.polymorphic.setValue(modelProperties.upsertRelationTable.polymorphic.getValue());
    }
    SourceOrSink source_sink = new SalesforceBulkFileSink();
    source_sink.initialize(null, runtimeProperties);
    ValidationResult result = source_sink.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    Sink sink = (Sink) source_sink;
    WriteOperation writeOperation = sink.createWriteOperation();
    writeOperation.initialize(null);
    Writer writer = writeOperation.createWriter(null);
    writer.open("component_instance_id");
    return writer;
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) Sink(org.talend.components.api.component.runtime.Sink) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) ValidationResult(org.talend.daikon.properties.ValidationResult) Writer(org.talend.components.api.component.runtime.Writer)

Aggregations

SourceOrSink (org.talend.components.api.component.runtime.SourceOrSink)5 ValidationResult (org.talend.daikon.properties.ValidationResult)3 SObject (com.sforce.soap.partner.sobject.SObject)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 Sink (org.talend.components.api.component.runtime.Sink)2 TSalesforceOutputBulkProperties (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties)2 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)2 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)1 Writer (org.talend.components.api.component.runtime.Writer)1 ComponentException (org.talend.components.api.exception.ComponentException)1 JdbcRuntimeInfo (org.talend.components.jdbc.JdbcRuntimeInfo)1 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)1 SalesforceBulkFileSink (org.talend.components.salesforce.runtime.SalesforceBulkFileSink)1 TSalesforceConnectionDefinition (org.talend.components.salesforce.tsalesforceconnection.TSalesforceConnectionDefinition)1 SnowflakeCloseSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink)1 NamedThing (org.talend.daikon.NamedThing)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1