Search in sources :

Example 11 with ExternalMapperTable

use of org.talend.designer.mapper.external.data.ExternalMapperTable in project tdi-studio-se by Talend.

the class ExternalDataConverter method prepareOutputTables.

private ArrayList<OutputTable> prepareOutputTables(List<IOConnection> outputConnections, List<IMetadataTable> outputMetadataTables, ExternalMapperData externalData) {
    Map<String, List<ExternalMapperTable>> nameToOutpuPersistentTable = new HashMap<String, List<ExternalMapperTable>>();
    if (externalData != null) {
        for (ExternalMapperTable persistentTable : externalData.getOutputTables()) {
            String key = persistentTable.getName();
            if (persistentTable.getIsJoinTableOf() != null) {
                key = persistentTable.getIsJoinTableOf();
            }
            List<ExternalMapperTable> list = nameToOutpuPersistentTable.get(key);
            if (list != null) {
                list.add(persistentTable);
            } else {
                list = new ArrayList<ExternalMapperTable>();
                list.add(persistentTable);
                nameToOutpuPersistentTable.put(key, list);
            }
        }
    }
    Map<String, IOConnection> nameMetadataToOutpuConn = new HashMap<String, IOConnection>();
    if (outputConnections != null) {
        for (IOConnection connection : outputConnections) {
            if (connection.getConnectionType().equals(EConnectionType.FLOW_MAIN) || connection.getConnectionType().equals(EConnectionType.FLOW_REF) || connection.getConnectionType().equals(EConnectionType.FLOW_MERGE)) {
                nameMetadataToOutpuConn.put(connection.getTable().getTableName(), connection);
            }
        }
    }
    ArrayList<OutputTable> outputDataMapTables = new ArrayList<OutputTable>();
    for (IMetadataTable table : outputMetadataTables) {
        IOConnection connection = nameMetadataToOutpuConn.get(table.getTableName());
        if (connection != null) {
            List<ExternalMapperTable> persistentTables = nameToOutpuPersistentTable.get(connection.getName());
            creatOutputTables(outputDataMapTables, persistentTables, connection.getTable(), connection, connection.getName());
        } else {
            List<ExternalMapperTable> persistentTables = nameToOutpuPersistentTable.get(table.getTableName());
            creatOutputTables(outputDataMapTables, persistentTables, table, null, table.getTableName());
        }
    }
    return outputDataMapTables;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with ExternalMapperTable

use of org.talend.designer.mapper.external.data.ExternalMapperTable in project tdi-studio-se by Talend.

the class MapperComponent method renameMetadataColumnName.

@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
    if (conectionName == null || oldColumnName == null || newColumnName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        // rename metadata column name
        List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        ExternalMapperTable tableFound = null;
        for (ExternalMapperTable table : tables) {
            if (table.getName().equals(conectionName)) {
                List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
                for (ExternalMapperTableEntry entry : metadataTableEntries) {
                    if (entry.getName().equals(oldColumnName)) {
                        entry.setName(newColumnName);
                        tableFound = table;
                        break;
                    }
                }
                break;
            }
        }
        // it is necessary to update expressions only if renamed column come from input table
        if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
            TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
            TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
            replaceLocationsInAllExpressions(oldLocation, newLocation, false);
        }
    }
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 13 with ExternalMapperTable

use of org.talend.designer.mapper.external.data.ExternalMapperTable in project tdi-studio-se by Talend.

the class MapperComponent method renameInputConnection.

public void renameInputConnection(String oldConnectionName, String newConnectionName) {
    if (oldConnectionName == null || newConnectionName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        List<ExternalMapperTable> inputTables = externalData.getInputTables();
        for (ExternalMapperTable table : inputTables) {
            if (table.getName().equals(oldConnectionName)) {
                table.setName(newConnectionName);
                TableEntryLocation oldLocation = new TableEntryLocation(oldConnectionName, null);
                TableEntryLocation newLocation = new TableEntryLocation(newConnectionName, null);
                replaceLocationsInAllExpressions(oldLocation, newLocation, true);
                break;
            }
        }
    }
}
Also used : TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 14 with ExternalMapperTable

use of org.talend.designer.mapper.external.data.ExternalMapperTable in project tdi-studio-se by Talend.

the class DesignerMapperService method renameJoinTable.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.mapper.IDesignerMapperService#renameJoinTable(java.lang.Process,
     * org.talend.core.model.process.IExternalData, java.util.List)
     */
public void renameJoinTable(IProcess process, IExternalData data, List<String> createdNames) {
    if (data instanceof ExternalMapperData) {
        ExternalMapperData extenalData = (ExternalMapperData) data;
        final List<ExternalMapperTable> outputTables = extenalData.getOutputTables();
        if (outputTables != null) {
            for (ExternalMapperTable table : outputTables) {
                if (table.getIsJoinTableOf() != null && !"".equals(table.getIsJoinTableOf())) {
                    final String newName = createNewConnectionName(process, table.getName(), createdNames);
                    table.setName(newName);
                }
            }
        }
    }
}
Also used : ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData)

Example 15 with ExternalMapperTable

use of org.talend.designer.mapper.external.data.ExternalMapperTable in project tdi-studio-se by Talend.

the class DesignerMapperService method isSameMetadata.

public boolean isSameMetadata(IExternalNode externalNode, String schemaId, IMetadataTable metadataTable) {
    boolean isSame = true;
    if (externalNode == null || schemaId == null || metadataTable == null) {
        return false;
    }
    if (externalNode instanceof MapperComponent) {
        MapperComponent component = (MapperComponent) externalNode;
        IExternalData nodeData = externalNode.getExternalData();
        if (nodeData != null && nodeData instanceof ExternalMapperData) {
            ExternalMapperData mapperData = (ExternalMapperData) nodeData;
            List<ExternalMapperTable> outputTables = mapperData.getOutputTables();
            if (outputTables != null && outputTables.size() > 0) {
                for (ExternalMapperTable outputTable : outputTables) {
                    if (schemaId.equals(outputTable.getId())) {
                        final IMetadataTable mapperTable = getMetadataTable(component, outputTable.getName());
                        if (mapperTable == null || !mapperTable.sameMetadataAs(metadataTable, IMetadataColumn.OPTIONS_NONE)) {
                            return false;
                        }
                    }
                }
            }
        // for (ExternalMapperTable extTable : extTables) {
        // isSame = isMetadataSame(extTable, metadataTable);
        // if (!isSame)
        // return isSame;
        // }
        }
    }
    return isSame;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IExternalData(org.talend.core.model.process.IExternalData) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData)

Aggregations

ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)34 ArrayList (java.util.ArrayList)20 ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)13 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)11 List (java.util.List)5 HashMap (java.util.HashMap)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)4 IExternalData (org.talend.core.model.process.IExternalData)4 IOConnection (org.talend.designer.mapper.external.connection.IOConnection)4 IConnection (org.talend.core.model.process.IConnection)3 Problem (org.talend.core.model.process.Problem)3 MapperComponent (org.talend.designer.mapper.MapperComponent)3 OutputTable (org.talend.designer.mapper.model.table.OutputTable)3 Element (org.dom4j.Element)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)2 InputTable (org.talend.designer.mapper.model.emf.mapper.InputTable)2 OutputTable (org.talend.designer.mapper.model.emf.mapper.OutputTable)2 UiProperties (org.talend.designer.mapper.model.emf.mapper.UiProperties)2