Search in sources :

Example 51 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class FixedConnectorsComponentProperties method setConnectedSchema.

@SuppressWarnings("unchecked")
@Override
public void setConnectedSchema(Connector connector, Schema schema, boolean isOutputConnection) {
    if (connector instanceof PropertyPathConnector) {
        NamedThing property = getProperty(((PropertyPathConnector) connector).getPropertyPath());
        if (property != null) {
            if (property instanceof SchemaProperties) {
                SchemaProperties schemaProperties = (SchemaProperties) property;
                schemaProperties.schema.setValue(schema);
            } else if (property instanceof Property) {
                ((Property<Schema>) property).setValue(schema);
            }
        } else {
            // else path not found so throw exception
            throw new ComponentException(ComponentsErrorCode.WRONG_CONNECTOR, ExceptionContext.build().put("properties", this.getClass().getCanonicalName()));
        }
    }
// not a connector handled by this class
}
Also used : PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) Schema(org.apache.avro.Schema) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) Property(org.talend.daikon.properties.property.Property)

Example 52 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class FixedConnectorsComponentProperties method getSchema.

/**
 * This default implementation uses {@link PropertyPathConnector} to find the SchemaProperties or Property of type
 * Schema instances avaialble in this Object. It return null if none found
 */
@SuppressWarnings("unchecked")
@Override
public Schema getSchema(Connector connector, boolean isOutputConnection) {
    if (connector instanceof PropertyPathConnector) {
        NamedThing property = getProperty(((PropertyPathConnector) connector).getPropertyPath());
        if (property != null) {
            Property<Schema> schemaProp = null;
            if (property instanceof SchemaProperties) {
                SchemaProperties schemaProperties = (SchemaProperties) property;
                schemaProp = schemaProperties.schema;
            } else if (property instanceof Property) {
                schemaProp = (Property<Schema>) property;
            }
            return schemaProp != null ? schemaProp.getValue() : null;
        } else {
            // else path not found so throw exception
            throw new ComponentException(ComponentsErrorCode.WRONG_CONNECTOR, ExceptionContext.build().put("properties", this.getClass().getCanonicalName()));
        }
    }
    // else not a connector handled by this class so return null
    return null;
}
Also used : PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) Schema(org.apache.avro.Schema) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) Property(org.talend.daikon.properties.property.Property)

Example 53 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class AzureStorageComponentListProperties method afterFormFinishTable.

public ValidationResult afterFormFinishTable(Repository<Properties> repo) throws Exception {
    connection.BlobSchema = selectedContainerNames.getValue();
    connection.QueueSchema = selectedQueueNames.getValue();
    connection.TableSchema = selectedTableNames.getValue();
    String repoLoc = repo.storeProperties(connection, connection.name.getValue(), repositoryLocation, null);
    String storeId;
    if (selectedContainerNames.getValue() != null) {
        for (NamedThing nl : selectedContainerNames.getValue()) {
            String containerId = nl.getName();
            AzureStorageContainerProperties containerProps = new AzureStorageContainerProperties(containerId);
            containerProps.init();
            containerProps.connection = connection;
            containerProps.container.setValue(containerId);
            containerProps.schema.schema.setValue(getContainerSchema());
            repo.storeProperties(containerProps, formatSchemaName(containerId), repoLoc, "schema.schema");
        }
    }
    if (selectedQueueNames.getValue() != null) {
        for (NamedThing nl : selectedQueueNames.getValue()) {
            String queueId = nl.getName();
            AzureStorageQueueProperties queueProps = new AzureStorageQueueProperties(queueId);
            queueProps.init();
            queueProps.connection = connection;
            queueProps.queueName.setValue(queueId);
            queueProps.schema.schema.setValue(getQueueSchema());
            repo.storeProperties(queueProps, formatSchemaName(queueId), repoLoc, "schema.schema");
        }
    }
    if (selectedTableNames.getValue() != null) {
        for (NamedThing nl : selectedTableNames.getValue()) {
            String tableId = nl.getName();
            AzureStorageTableProperties tableProps = new AzureStorageTableProperties(tableId);
            tableProps.init();
            tableProps.connection = connection;
            tableProps.tableName.setValue(tableId);
            try {
                Schema schema = AzureStorageTableSourceOrSink.getSchema(null, connection, tableId);
                tableProps.schema.schema.setValue(schema);
                repo.storeProperties(tableProps, formatSchemaName(tableId), repoLoc, "schema.schema");
            } catch (IOException e) {
                LOGGER.error(e.getLocalizedMessage());
            }
        }
    }
    return ValidationResult.OK;
}
Also used : AzureStorageContainerProperties(org.talend.components.azurestorage.blob.AzureStorageContainerProperties) Schema(org.apache.avro.Schema) IOException(java.io.IOException) NamedThing(org.talend.daikon.NamedThing) AzureStorageQueueProperties(org.talend.components.azurestorage.queue.AzureStorageQueueProperties) AzureStorageTableProperties(org.talend.components.azurestorage.table.AzureStorageTableProperties)

Example 54 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class AzureStorageComponentListPropertiesTest method afterFormFinishTable2.

@Test(expected = NoSuchElementException.class)
public void afterFormFinishTable2() throws Exception {
    TAzureStorageConnectionProperties connection = new TAzureStorageConnectionProperties("test");
    connection.setupProperties();
    connection.setupLayout();
    connection.useSharedAccessSignature.setValue(true);
    connection.sharedAccessSignature.setValue("https://talendrd.blob.core.windows.net/?sv=2016-05-31&ss=f&srt=sco&sp=rwdlacup&se=2017-06-07T23:50:05Z&st=2017-05-24T15:50:05Z&spr=https&sig=fakeSASfakeSASfakeSASfakeSASfakeSASfakeSASfakeSASfakeSAS");
    properties.setConnection(connection);
    List<NamedThing> nameWithNumeric = new ArrayList<NamedThing>();
    nameWithNumeric.add(new SimpleNamedThing("2Name_with_numeric2", "2Name_with_numeric2"));
    properties.selectedTableNames.setStoredValue(nameWithNumeric);
    @SuppressWarnings("unused") ValidationResult result = properties.afterFormFinishTable(repo);
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 55 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class BigQueryDatasetProperties method beforeBqDataset.

public ValidationResult beforeBqDataset() {
    BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> datasets = new ArrayList<>();
        for (String dataset : runtime.listDatasets()) {
            datasets.add(new SimpleNamedThing(dataset, dataset));
        }
        bqDataset.setPossibleValues(datasets);
        return ValidationResult.OK;
    } catch (Exception e) {
        return new ValidationResult(new ComponentException(e));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IBigQueryDatasetRuntime(org.talend.components.bigquery.runtime.IBigQueryDatasetRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Aggregations

NamedThing (org.talend.daikon.NamedThing)71 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)34 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)21 Property (org.talend.daikon.properties.property.Property)17 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 ComponentException (org.talend.components.api.exception.ComponentException)14 Schema (org.apache.avro.Schema)11 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)9 ValidationResult (org.talend.daikon.properties.ValidationResult)8 Form (org.talend.daikon.properties.presentation.Form)8 List (java.util.List)7 IOException (java.io.IOException)6 PresentationItem (org.talend.daikon.properties.PresentationItem)6 Properties (org.talend.daikon.properties.Properties)6 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)5 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)5 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)4 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4