Search in sources :

Example 51 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class SalesforceMultiSchemaMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof SalesforceSchemaConnectionItem) {
        boolean modify = false;
        SalesforceSchemaConnectionItem salesforceItem = (SalesforceSchemaConnectionItem) item;
        if (salesforceItem.getConnection() instanceof SalesforceSchemaConnection) {
            SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) salesforceItem.getConnection();
            SalesforceModuleUnit module = ConnectionFactory.eINSTANCE.createSalesforceModuleUnit();
            module.setId(ProxyRepositoryFactory.getInstance().getNextId());
            String moduleName = sfConnection.getModuleName();
            if (moduleName == null || "".equals(moduleName)) {
                moduleName = "Default";
            }
            module.setLabel(moduleName);
            module.setModuleName(moduleName);
            EList<orgomg.cwm.objectmodel.core.Package> originalPackages = sfConnection.getDataPackage();
            for (int i = 0; i < originalPackages.size(); i++) {
                MetadataTable table = (MetadataTable) originalPackages.get(i).getOwnedElement().get(0);
                if (originalPackages.get(i) instanceof RecordFile) {
                    table.setLabel(moduleName);
                }
                module.getTables().add(table);
            }
            sfConnection.getModules().add(module);
            modify = true;
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SalesforceModuleUnit(org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit)

Example 52 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class SchemaUtilsTest method createMetadataTable.

private MetadataTable createMetadataTable(String name) {
    MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
    table.setName(name);
    table.setLabel(table.getName());
    return table;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 53 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class SchemaUtilsTest method testGetMetadataTables.

@Test
public void testGetMetadataTables() {
    // Create some MetadataTables for test.
    //$NON-NLS-1$
    MetadataTable table1 = createMetadataTable("table1");
    //$NON-NLS-1$
    MetadataTable table2 = createMetadataTable("table2");
    //$NON-NLS-1$
    MetadataTable table3 = createMetadataTable("table3");
    //$NON-NLS-1$
    MetadataTable table4 = createMetadataTable("table4");
    // ///////////////////////////////////
    // Overall structure:
    //
    // . parentPackage
    // .. table1
    // .. container1
    // ... table2
    // ... container1_1
    // .... table4
    // .. container2
    // ... table3
    //
    // ///////////////////////////////////
    Package parentPackage = CoreFactory.eINSTANCE.createPackage();
    parentPackage.getOwnedElement().add(table1);
    Package container1 = new TestContainer();
    container1.getOwnedElement().add(table2);
    Package container1_1 = new TestContainer();
    container1_1.getOwnedElement().add(table4);
    container1.getOwnedElement().add(container1_1);
    parentPackage.getOwnedElement().add(container1);
    Package container2 = new OtherTestContainer();
    container2.getOwnedElement().add(table3);
    parentPackage.getOwnedElement().add(container2);
    // When there is not any sub-container specified, will return all direct MetadataTables of the parent package.
    List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(parentPackage, null);
    assertNotNull(getTheTable(metadataTables, table1.getName()));
    // When there is one sub-container specified, will return all direct MetadataTables of the parent package and
    // sub-container recursively.
    metadataTables = SchemaUtils.getMetadataTables(parentPackage, TestContainer.class);
    assertNotNull(getTheTable(metadataTables, table1.getName()));
    assertNotNull(getTheTable(metadataTables, table2.getName()));
    assertNotNull(getTheTable(metadataTables, table4.getName()));
    assertNull(getTheTable(metadataTables, table3.getName()));
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Package(orgomg.cwm.objectmodel.core.Package) Test(org.junit.Test)

Example 54 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class AddTablesComposite method createTableList.

/**
     * DOC admin Comment method "createTableList".
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private Composite createTableList() {
    Composite div1 = new Composite(tabFolder, SWT.NONE);
    div1.setLayout(new GridLayout());
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL_BOTH;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(ColorConstants.white);
    listTables = new org.eclipse.swt.widgets.List(div1, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    listTables.setLayoutData(new GridData(GridData.FILL_BOTH));
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(getRootNode());
    tables = ConnectionHelper.getTables((DatabaseConnection) item.getConnection());
    for (MetadataTable table : tables) {
        if (table.getSourceName() != null) {
            listTables.add(table.getSourceName());
        }
    }
    return div1;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 55 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.

the class AddTablesDialog method setRootNode.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
public void setRootNode(RepositoryNode rootNode) {
    this.rootNode = rootNode;
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(getRootNode());
    tables = new HashSet<MetadataTable>();
    tables.addAll(ConnectionHelper.getTables((DatabaseConnection) item.getConnection()));
}
Also used : MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)76 ArrayList (java.util.ArrayList)26 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)24 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)22 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)18 List (java.util.List)14 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)13 PersistenceException (org.talend.commons.exception.PersistenceException)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)10 RepositoryNode (org.talend.repository.model.RepositoryNode)10 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)9 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)9 HashMap (java.util.HashMap)8 Schema (org.apache.avro.Schema)7 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)7 IElementParameter (org.talend.core.model.process.IElementParameter)7 Map (java.util.Map)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6