Search in sources :

Example 56 with NamedThing

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

the class BigQueryDatasetProperties method beforeTableName.

public void beforeTableName() {
    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> tables = new ArrayList<>();
        for (String table : runtime.listTables()) {
            tables.add(new SimpleNamedThing(table, table));
        }
        this.tableName.setPossibleValues(tables);
    } catch (Exception e) {
        TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_EXCEPTION).setAndThrow(e.getMessage());
    }
}
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) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ComponentException(org.talend.components.api.exception.ComponentException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Example 57 with NamedThing

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

the class AzureStorageConnectionWizardTest method testWizard.

@Test
public void testWizard() throws Throwable {
    final List<RepoProps> repoProps = new ArrayList<>();
    Repository repo = new TestRepository(repoProps);
    getComponentService().setRepository(repo);
    Set<ComponentWizardDefinition> wizards = getComponentService().getTopLevelComponentWizards();
    int count = 0;
    ComponentWizardDefinition wizardDef = null;
    for (ComponentWizardDefinition wizardDefinition : wizards) {
        if (wizardDefinition instanceof AzureStorageConnectionWizardDefinition) {
            wizardDef = wizardDefinition;
            count++;
        }
    }
    assertEquals(1, count);
    assertEquals("Create an Azure Storage Connection", wizardDef.getMenuItemName());
    ComponentWizard wiz = getComponentService().getComponentWizard(AzureStorageConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeAzureStorage");
    assertNotNull(wiz);
    assertEquals("nodeAzureStorage", wiz.getRepositoryLocation());
    List<Form> forms = wiz.getForms();
    Form connFormWizard = forms.get(0);
    assertEquals("Wizard", connFormWizard.getName());
    assertFalse(connFormWizard.isAllowBack());
    assertFalse(connFormWizard.isAllowForward());
    assertFalse(connFormWizard.isAllowFinish());
    // Main from SalesforceModuleListProperties
    assertEquals("Container", forms.get(1).getName());
    assertEquals("Queue", forms.get(2).getName());
    assertEquals("Table", forms.get(3).getName());
    assertEquals("Azure Storage Connection Settings", connFormWizard.getTitle());
    assertEquals("Fill in fields to configure connection.", connFormWizard.getSubtitle());
    TAzureStorageConnectionProperties connProps = (TAzureStorageConnectionProperties) connFormWizard.getProperties();
    connProps.setupProperties();
    Object image = getComponentService().getWizardPngImage(AzureStorageConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.TREE_ICON_16X16);
    assertNotNull(image);
    image = getComponentService().getWizardPngImage(AzureStorageConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.WIZARD_BANNER_75X66);
    assertNotNull(image);
    // Check the non-top-level wizard
    // check password i18n
    assertEquals("Name", connProps.getProperty("name").getDisplayName());
    connProps.name.setValue("connName");
    connProps.accountName.setValue("demo");
    connProps.accountKey.setValue("demo");
    // check name i18n
    // $NON-NLS-1$
    NamedThing nameProp = connFormWizard.getWidget("name").getContent();
    assertEquals("Name", nameProp.getDisplayName());
    connProps = (TAzureStorageConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), connFormWizard, "testConnection", connProps);
    assertFalse(connFormWizard.isAllowForward());
    Form modForm = forms.get(1);
}
Also used : Form(org.talend.daikon.properties.presentation.Form) ArrayList(java.util.ArrayList) TAzureStorageConnectionProperties(org.talend.components.azurestorage.tazurestorageconnection.TAzureStorageConnectionProperties) NamedThing(org.talend.daikon.NamedThing) Repository(org.talend.daikon.properties.service.Repository) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) Test(org.junit.Test)

Example 58 with NamedThing

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

the class GoogleDriveDataSource method getSchemaNames.

@Override
public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException {
    List<NamedThing> schemas = new ArrayList<>();
    schemas.add(new SimpleNamedThing(SCHEMA_NAME, SCHEMA_NAME));
    return schemas;
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 59 with NamedThing

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

the class JDBCSourceOrSink method getSchemaNames.

@Override
public List<NamedThing> getSchemaNames(RuntimeContainer runtime) throws IOException {
    List<NamedThing> result = new ArrayList<>();
    try (Connection conn = connect(runtime)) {
        DatabaseMetaData dbMetaData = conn.getMetaData();
        Set<String> tableTypes = getAvailableTableTypes(dbMetaData);
        String database_schema = getDatabaseSchema();
        try (ResultSet resultset = dbMetaData.getTables(null, database_schema, null, tableTypes.toArray(new String[0]))) {
            while (resultset.next()) {
                String tablename = resultset.getString("TABLE_NAME");
                if (tablename == null) {
                    tablename = resultset.getString("SYNONYM_NAME");
                }
                result.add(new SimpleNamedThing(tablename, tablename));
            }
        }
    } catch (Exception e) {
        throw CommonUtils.newComponentException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e, ExceptionContext.withBuilder().put("message", e.getMessage()).build());
    }
    return result;
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCAvroRegistryString(org.talend.components.jdbc.avro.JDBCAvroRegistryString) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) DatabaseMetaData(java.sql.DatabaseMetaData) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) SQLException(java.sql.SQLException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Example 60 with NamedThing

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

the class JDBCInputTestIT method testGetSchemaNames.

@Test
public void testGetSchemaNames() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema(tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    List<NamedThing> schemaNames = source.getSchemaNames(null);
    assertTrue(schemaNames != null);
    assertTrue(!schemaNames.isEmpty());
    boolean exists = false;
    for (NamedThing name : schemaNames) {
        if (tablename.equals(name.getName().toUpperCase())) {
            exists = true;
            break;
        }
    }
    assertTrue(exists);
}
Also used : TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) NamedThing(org.talend.daikon.NamedThing) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

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