Search in sources :

Example 1 with ColumnNameChanged

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

the class DbMapComponent method inputMetadataColumnAmountChanged.

private void inputMetadataColumnAmountChanged(IODataComponent dataComponent, IExternalNode externalNode) {
    List<ColumnNameChanged> removedMetadataColumns = dataComponent.getRemoveMetadataColumns();
    IExternalData iExternalData = externalNode.getExternalData();
    if (iExternalData == null || removedMetadataColumns == null || removedMetadataColumns.size() == 0) {
        return;
    }
    List<ExternalDbMapTable> metaTableList = (List<ExternalDbMapTable>) iExternalData.getInputTables();
    if (metaTableList == null || metaTableList.size() == 0) {
        return;
    }
    // in the eltmap, the input table name is same with it's input connection name
    String tableName = dataComponent.getName();
    if (StringUtils.isEmpty(tableName)) {
        return;
    }
    for (ExternalDbMapTable metaTable : metaTableList) {
        if (tableName.equals(metaTable.getTableName())) {
            List<IExternalMapEntry> externalMapEntryList = (List<IExternalMapEntry>) metaTable.returnTableEntries();
            if (externalMapEntryList == null || externalMapEntryList.size() == 0) {
                continue;
            }
            if (removedMetadataColumns != null && 0 < removedMetadataColumns.size()) {
                for (ColumnNameChanged removedMetadataColumn : removedMetadataColumns) {
                    if ("".equals(removedMetadataColumn.getNewName())) {
                        //$NON-NLS-1$
                        String columnName = removedMetadataColumn.getOldName();
                        for (int i = externalMapEntryList.size() - 1; 0 <= i; i--) {
                            IExternalMapEntry mapEntry = externalMapEntryList.get(i);
                            if (columnName.equals(mapEntry.getName())) {
                                externalMapEntryList.remove(i);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IExternalData(org.talend.core.model.process.IExternalData) IExternalMapEntry(org.talend.core.model.process.node.IExternalMapEntry)

Example 2 with ColumnNameChanged

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

the class ChangeMetadataCommand method updateColumnList.

@SuppressWarnings("unchecked")
protected void updateColumnList(IMetadataTable oldTable, IMetadataTable newTable) {
    final List<ColumnNameChanged> columnNameChanged = MetadataToolHelper.getColumnNameChanged(oldTable, newTable);
    if (inputNode != null) {
        List<IElementParameter> eps = (List<IElementParameter>) inputNode.getElementParameters();
        if (eps != null) {
            boolean end = false;
            for (int i = 0; i < eps.size() && !end; i++) {
                IElementParameter parameter = eps.get(i);
                if (parameter.getFieldType() == EParameterFieldType.TABLE) {
                    end = true;
                    if (parameter != null) {
                        List<Map<String, Object>> map2 = (List<Map<String, Object>>) parameter.getValue();
                        if (map2 != null && inputNode.getMetadataList().get(0).getListColumns().size() != map2.size()) {
                            ColumnListController.updateColumnList(inputNode, columnNameChanged);
                        }
                    }
                }
            }
        }
        inputNode.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
    }
    node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with ColumnNameChanged

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

the class FileOutputXMLComponent method metadataInputChanged.

@Override
public void metadataInputChanged(IODataComponent dataComponent, String connectionToApply) {
    List<Map<String, String>> listRoot = new ArrayList<Map<String, String>>();
    if (this.getElementParameter(ROOT) != null && this.getElementParameter(ROOT).getValue() != null) {
        listRoot.addAll((List<Map<String, String>>) this.getElementParameter(ROOT).getValue());
    }
    boolean flagRoot = false;
    List<Map<String, String>> listGroup = new ArrayList<Map<String, String>>();
    if (this.getElementParameter(GROUP) != null && this.getElementParameter(GROUP).getValue() != null) {
        listGroup.addAll((List<Map<String, String>>) this.getElementParameter(GROUP).getValue());
    }
    boolean flagGroup = false;
    List<Map<String, String>> listLoop = new ArrayList<Map<String, String>>();
    if (this.getElementParameter(LOOP) != null && this.getElementParameter(LOOP).getValue() != null) {
        listLoop.addAll((List<Map<String, String>>) this.getElementParameter(LOOP).getValue());
    }
    boolean flagLoop = false;
    // add by wzhang. column show with schema name added for mutiSchema
    //$NON-NLS-1$
    String schemaId = "";
    if (istFileOutputMSXML()) {
        //$NON-NLS-1$
        schemaId = dataComponent.getConnection().getMetadataTable().getLabel() + ":";
    }
    for (ColumnNameChanged col : dataComponent.getColumnNameChanged()) {
        for (Map<String, String> map : listRoot) {
            if (map.get(COLUMN).equals(schemaId + col.getOldName())) {
                map.put(COLUMN, schemaId + col.getNewName());
                flagRoot = true;
            }
        }
        for (Map<String, String> map : listGroup) {
            if (map.get(COLUMN).equals(schemaId + col.getOldName())) {
                map.put(COLUMN, schemaId + col.getNewName());
                flagGroup = true;
            }
        }
        for (Map<String, String> map : listLoop) {
            if (map.get(COLUMN).equals(schemaId + col.getOldName())) {
                map.put(COLUMN, schemaId + col.getNewName());
                flagLoop = true;
            }
        }
    }
    if (flagRoot) {
        this.getElementParameter(ROOT).setValue(listRoot);
    }
    if (flagGroup) {
        this.getElementParameter(GROUP).setValue(listGroup);
    }
    if (flagLoop) {
        this.getElementParameter(LOOP).setValue(listLoop);
    }
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ColumnNameChanged

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

the class HL7InputComponent method metadataInputChanged.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.core.model.process.AbstractExternalNode#metadataInputChanged(org.talend.core.model.components.
     * IODataComponent, java.lang.String)
     */
@Override
public void metadataInputChanged(IODataComponent dataComponent, String connectionToApply) {
    super.metadataInputChanged(dataComponent, connectionToApply);
    List<Map<String, String>> listRoot = (List<Map<String, String>>) this.getElementParameter(ROOT).getValue();
    boolean flagRoot = false;
    //$NON-NLS-1$
    String schemaId = "";
    if (isHL7Output()) {
        //$NON-NLS-1$
        schemaId = dataComponent.getConnection().getMetadataTable().getLabel() + ":";
    }
    for (ColumnNameChanged col : dataComponent.getColumnNameChanged()) {
        for (Map<String, String> map : listRoot) {
            if (map.get(COLUMN).equals(schemaId + col.getOldName())) {
                map.put(COLUMN, schemaId + col.getNewName());
                flagRoot = true;
            }
        }
    }
    if (flagRoot) {
        this.getElementParameter(ROOT).setValue(listRoot);
    }
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ColumnNameChanged

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

the class ExternalNodeChangeCommand method propagateInput.

private void propagateInput() {
    for (Connection connection : (List<Connection>) node.getIncomingConnections()) {
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent currentIO = inAndOut.getDataComponent(connection);
            currentIO.setColumnOption(IMetadataColumn.OPTIONS_NONE);
            if (currentIO.hasChanged()) {
                IMetadataTable metadata = inAndOut.getTable(connection);
                INode sourceNode = currentIO.getSource();
                sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
                // It's better to clone, because will change that, if apply, bug 13325
                // IMetadataTable oldMetadata = connection.getMetadataTable().clone();
                IMetadataTable newMetadata = metadata.clone();
                currentIO.setTable(newMetadata);
                String schemaType = (String) connection.getSource().getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
                if (schemaType != null) {
                    // if there is a SCHEMA_TYPE, then switch it to BUILT_IN if REPOSITORY is set.
                    if (schemaType.equals(EmfComponent.REPOSITORY)) {
                        connection.getSource().setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                        metadataInputWasRepository.put(connection, Boolean.TRUE);
                    }
                }
                // for bug 9849
                List<IMetadataColumn> listColumns = connection.getMetadataTable().getListColumns();
                // before is empty
                boolean empty = listColumns.isEmpty();
                List<IMetadataColumn> newListColumns = newMetadata.getListColumns();
                List<ColumnNameChanged> columnNameChangeds = new ArrayList<ColumnNameChanged>();
                int size = listColumns.size();
                int newSize = newListColumns.size();
                if (newSize < size) {
                    size = newSize;
                }
                for (int i = 0; i < size; i++) {
                    IMetadataColumn metadataColumn = listColumns.get(i);
                    IMetadataColumn newMetadataColumn = newListColumns.get(i);
                    if (metadataColumn != null && newMetadataColumn != null) {
                        String oldId = metadataColumn.getId();
                        String oldLabel = metadataColumn.getLabel();
                        String newLabel = newMetadataColumn.getLabel();
                        String newId = newMetadataColumn.getId();
                        if (oldId != null && oldLabel != null && newId != null && oldId.equals(newId) && !oldLabel.equals(newLabel)) {
                            columnNameChangeds.add(new ColumnNameChanged(oldLabel, newLabel));
                        }
                    }
                }
                connection.getMetadataTable().setListColumns(newListColumns);
                // some pig component have FLOW_MAIN && PIGCOMBINE two connector type
                if (connection.getConnectorName() != null && connection.getConnectorName().equals("PIGCOMBINE")) {
                    IMetadataTable table = sourceNode.getMetadataFromConnector(EConnectionType.FLOW_MAIN.getName());
                    if (table != null) {
                        table.setListColumns(newListColumns);
                    }
                }
                ColumnListController.updateColumnList(sourceNode, columnNameChangeds, false);
                if (empty) {
                    // trace init
                    connection.initTraceParamters();
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) List(java.util.List) IODataComponent(org.talend.core.model.components.IODataComponent)

Aggregations

ColumnNameChanged (org.talend.core.model.metadata.ColumnNameChanged)16 ArrayList (java.util.ArrayList)13 List (java.util.List)8 Map (java.util.Map)7 HashMap (java.util.HashMap)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 INode (org.talend.core.model.process.INode)4 ColumnNameChangedExt (org.talend.core.model.metadata.ColumnNameChangedExt)3 IConnection (org.talend.core.model.process.IConnection)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 Node (org.talend.designer.core.ui.editor.nodes.Node)3 IODataComponent (org.talend.core.model.components.IODataComponent)2 Process (org.talend.designer.core.ui.editor.process.Process)2 JSONObject (org.talend.utils.json.JSONObject)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 EList (org.eclipse.emf.common.util.EList)1 Point (org.eclipse.swt.graphics.Point)1