Search in sources :

Example 21 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project components by Talend.

the class SalesforceComponentTestIT method testAfterLoginType.

@Test
public void testAfterLoginType() throws Throwable {
    ComponentProperties props;
    props = new TSalesforceConnectionDefinition().createProperties();
    ComponentTestUtils.checkSerialize(props, errorCollector);
    Property<LoginType> loginType = (Property<LoginType>) props.getProperty("loginType");
    LOGGER.debug(loginType.getPossibleValues().toString());
    assertEquals(SalesforceConnectionProperties.LoginType.Basic, loginType.getPossibleValues().get(0));
    assertEquals(SalesforceConnectionProperties.LoginType.OAuth, loginType.getPossibleValues().get(1));
    assertEquals(SalesforceConnectionProperties.LoginType.Basic, loginType.getValue());
    Form mainForm = props.getForm(Form.MAIN);
    assertEquals("Salesforce Connection Settings", mainForm.getTitle());
    assertFalse(mainForm.getWidget(SalesforceUserPasswordProperties.class).isHidden());
    loginType.setValue(SalesforceConnectionProperties.LoginType.OAuth);
    props = checkAndAfter(mainForm, "loginType", props);
    mainForm = props.getForm(Form.MAIN);
    assertTrue(mainForm.isRefreshUI());
    assertTrue(mainForm.getWidget(SalesforceUserPasswordProperties.class).isHidden());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) TSalesforceConnectionDefinition(org.talend.components.salesforce.tsalesforceconnection.TSalesforceConnectionDefinition) LoginType(org.talend.components.salesforce.SalesforceConnectionProperties.LoginType) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Example 22 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project components by Talend.

the class SalesforceDataprepSource method initialize.

@Override
public ValidationResult initialize(RuntimeContainer container, ComponentProperties properties) {
    this.properties = (SalesforceInputProperties) properties;
    dataset = this.properties.getDatasetProperties();
    datastore = dataset.getDatastoreProperties();
    String config_file = System.getProperty(CONFIG_FILE_lOCATION_KEY);
    try (InputStream is = config_file != null ? (new FileInputStream(config_file)) : null) {
        if (is == null) {
            LOG.warn("not found the property file, will use the default value for endpoint and timeout");
            return ValidationResult.OK;
        }
        Properties props = new Properties();
        props.load(is);
        String endpoint = props.getProperty("endpoint");
        if (endpoint != null && !endpoint.isEmpty()) {
            this.endpoint = endpoint;
        }
        String timeout = props.getProperty("timeout");
        if (timeout != null && !timeout.isEmpty()) {
            this.timeout = Integer.parseInt(timeout);
        }
    } catch (IOException e) {
        LOG.warn("not found the property file, will use the default value for endpoint and timeout", e);
    }
    return ValidationResult.OK;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) SalesforceDatastoreProperties(org.talend.components.salesforce.datastore.SalesforceDatastoreProperties) Properties(java.util.Properties) SalesforceDatasetProperties(org.talend.components.salesforce.dataset.SalesforceDatasetProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) FileInputStream(java.io.FileInputStream)

Example 23 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project components by Talend.

the class RuntimeControllerImpl method writeData.

@Override
public void writeData(InputStream rawPayload) throws IOException {
    // 1) Read payload (with data as a stream of course)
    DatasetWritePayload payload = DatasetWritePayload.readData(rawPayload, mapper);
    String definitionName = payload.getConfiguration().getDefinitionName();
    // 2) Create properties
    Properties properties = propertiesHelpers.propertiesFromDto(payload.getConfiguration());
    if (properties instanceof ComponentProperties) {
        ComponentProperties componentProperties = (ComponentProperties) properties;
        // 3) Retrieve component definition to be able to create the runtime
        final ComponentDefinition definition = propertiesHelpers.getDefinition(ComponentDefinition.class, definitionName);
        // 4) Get the execution engine
        ExecutionEngine executionEngine;
        if (definition.isSupportingExecutionEngines(DI)) {
            executionEngine = DI;
            // 5) Create the sandbox
            try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(executionEngine, componentProperties, INCOMING), definition.getClass().getClassLoader())) {
                Sink datasetRuntimeInstance = (Sink) instance.getInstance();
                datasetRuntimeInstance.initialize(null, componentProperties);
                Iterator<IndexedRecord> data = payload.getData();
                WriteOperation writeOperation = datasetRuntimeInstance.createWriteOperation();
                // Supplier return null to signify end of data stream => see WriterDataSupplier.writeData
                WriterDataSupplier<?, IndexedRecord> stringWriterDataSupplier = new WriterDataSupplier<Object, IndexedRecord>(writeOperation, () -> data.hasNext() ? data.next() : null, null);
                stringWriterDataSupplier.writeData();
            }
        } else if (definition.isSupportingExecutionEngines(BEAM)) {
            throw new UnsupportedOperationException("Beam runtime is not available for dataset write through HTTP API.");
        } else {
            throw new TalendRuntimeException(CommonErrorCodes.UNREGISTERED_DEFINITION);
        }
    } else if (properties instanceof DatasetProperties) {
        throw new UnsupportedOperationException("HTTP API is only able to write using component implementations. Not " + properties.getClass());
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) Sink(org.talend.components.api.component.runtime.Sink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) WriterDataSupplier(org.talend.components.api.component.runtime.WriterDataSupplier) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 24 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project components by Talend.

the class JDBCOutputWriter method open.

@Override
public void open(String uId) throws IOException {
    componentSchema = CommonUtils.getMainSchemaFromInputConnector((ComponentProperties) properties);
    rejectSchema = CommonUtils.getRejectSchema((ComponentProperties) properties);
    columnList = JDBCSQLBuilder.getInstance().createColumnList(setting, componentSchema);
    if (!setting.getClearDataInTable()) {
        return;
    }
    String sql = JDBCSQLBuilder.getInstance().generateSQL4DeleteTable(setting.getTablename());
    try {
        conn = sink.getConnection(runtime);
        try (Statement statement = conn.createStatement()) {
            deleteCount += statement.executeUpdate(sql);
        }
    } catch (ClassNotFoundException | SQLException e) {
        throw CommonUtils.newComponentException(e);
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement)

Example 25 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project components by Talend.

the class SnowflakeTestIT method generateJavaNestedCompPropClassNames.

@Test
public void generateJavaNestedCompPropClassNames() {
    Set<ComponentDefinition> allComponents = getComponentService().getAllComponents();
    for (ComponentDefinition cd : allComponents) {
        ComponentProperties props = cd.createProperties();
        String javaCode = PropertiesTestUtils.generatedNestedComponentCompatibilitiesJavaCode(props);
        LOGGER.debug("Nested Props for (" + cd.getClass().getSimpleName() + ".java:1)" + javaCode);
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test) AbstractComponentTest(org.talend.components.api.test.AbstractComponentTest)

Aggregations

ComponentProperties (org.talend.components.api.properties.ComponentProperties)76 Test (org.junit.Test)22 Form (org.talend.daikon.properties.presentation.Form)17 Property (org.talend.daikon.properties.property.Property)17 ArrayList (java.util.ArrayList)16 NamedThing (org.talend.daikon.NamedThing)13 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)13 Properties (org.talend.daikon.properties.Properties)10 List (java.util.List)9 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Schema (org.apache.avro.Schema)7 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)7 ComponentService (org.talend.components.api.service.ComponentService)7 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)7 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)7 ElementParameter (org.talend.designer.core.model.components.ElementParameter)7