Search in sources :

Example 6 with ColumnNameChanged

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

the class ColumnListController method isUpdateColumnEnable.

private static boolean isUpdateColumnEnable(IElementParameter param, List<ColumnNameChanged> columnsChanged, IElementParameter tmpParam) {
    ColumnNameChanged tmpChanged = columnsChanged.get(0);
    if (tmpChanged instanceof ColumnNameChangedExt && param.getElement() instanceof Node) {
        INode curNode = (Node) param.getElement();
        INode changedNode = ((ColumnNameChangedExt) tmpChanged).getChangedNode();
        if (changedNode == null) {
            return false;
        }
        if (changedNode != curNode) {
            // if not update current node, only update the prev/lookup column list
            if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                return true;
            }
        } else {
            // if update current node, only update the self column list
            if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST) {
                return true;
            }
        }
    } else {
        // only update self column list
        if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST) {
            return true;
        }
    }
    return false;
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) INode(org.talend.core.model.process.INode) ColumnNameChangedExt(org.talend.core.model.metadata.ColumnNameChangedExt) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode)

Example 7 with ColumnNameChanged

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

the class ColumnListController method syncNodePropertiesTableColumns.

/**
     * 
     * DOC ggu Comment method "syncNodePropertiesTableColumns".<BR/>
     * 
     * synchronize COLUMN_LIST, PREV_COLUMN_LIST, LOOKUP_COLUMN_LIST in table. <br/>
     * when modified column name of schema .
     * 
     * @param param
     * @param columnsChanged
     * @param columnNameList
     * @param tmpParam
     */
private static void syncNodePropertiesTableColumns(IElementParameter param, List<ColumnNameChanged> columnsChanged, String[] columnNameList, IElementParameter tmpParam) {
    if (columnsChanged == null || columnsChanged.isEmpty()) {
        return;
    }
    if (columnNameList == null || columnNameList.length == 0) {
        return;
    }
    if (!isUpdateColumnEnable(param, columnsChanged, tmpParam)) {
        return;
    }
    //$NON-NLS-1$
    String componentUniqueName = "";
    //$NON-NLS-1$
    String preRowLookup = "";
    if (tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST && columnNameList[0].indexOf(".") > 0) {
        //$NON-NLS-1$
        ColumnNameChanged tmpChanged = columnsChanged.get(0);
        if (tmpChanged instanceof ColumnNameChangedExt) {
            //$NON-NLS-1$
            componentUniqueName = ((ColumnNameChangedExt) tmpChanged).getChangedNode().getUniqueName() + ".";
            //$NON-NLS-1$
            preRowLookup = columnNameList[0].substring(0, columnNameList[0].indexOf(".") + 1);
        }
    }
    for (ColumnNameChanged colChanged : columnsChanged) {
        String newName = preRowLookup + colChanged.getNewName();
        ColumnNameChanged theChanged = null;
        for (String element : columnNameList) {
            if (newName.equals(element)) {
                theChanged = colChanged;
                break;
            }
        }
        // found
        if (theChanged != null && param.getValue() != null) {
            for (Map<String, Object> currentLine : (List<Map<String, Object>>) param.getValue()) {
                if (currentLine.get(tmpParam.getName()).equals(componentUniqueName + theChanged.getOldName())) {
                    currentLine.put(tmpParam.getName(), componentUniqueName + theChanged.getNewName());
                }
            }
        }
    }
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ColumnNameChangedExt(org.talend.core.model.metadata.ColumnNameChangedExt) JSONObject(org.talend.utils.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with ColumnNameChanged

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

the class RowGeneratorComponent method metadataOutputChanged.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.core.model.process.AbstractExternalNode#metadataOutputChanged(org.talend.core.model.components.
     * IODataComponent, java.lang.String)
     */
@Override
public void metadataOutputChanged(IODataComponent dataComponent, String connectionToApply) {
    List<Map<String, Object>> oldMap = getMapList();
    List<Map<String, Object>> newMap = new ArrayList<Map<String, Object>>();
    List<Map<String, Object>> notuseMap = new ArrayList<Map<String, Object>>();
    notuseMap.addAll(oldMap);
    List<ColumnNameChanged> newColumns = dataComponent.getNewMetadataColumns();
    for (ColumnNameChanged changed : newColumns) {
        if ("".equals(changed.getOldName())) {
            //$NON-NLS-1$
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put(COLUMN_NAME, changed.getNewName());
            newMap.add(map2);
        }
    }
    List<ColumnNameChanged> removeColumns = dataComponent.getRemoveMetadataColumns();
    for (ColumnNameChanged changed : removeColumns) {
        if ("".equals(changed.getNewName())) {
            //$NON-NLS-1$
            for (Map<String, Object> map : oldMap) {
                if (changed.getOldName().equals(map.get(COLUMN_NAME))) {
                    notuseMap.remove(map);
                    break;
                }
            }
        }
    }
    List<ColumnNameChanged> columnNameChanged = dataComponent.getColumnNameChanged();
    for (ColumnNameChanged changed : columnNameChanged) {
        for (Map<String, Object> map : oldMap) {
            if (changed.getOldName().equals(map.get(COLUMN_NAME))) {
                Map<String, Object> map2 = new HashMap<String, Object>();
                map2.put(COLUMN_NAME, changed.getNewName());
                map2.put(ARRAY, map.get(ARRAY));
                newMap.add(map2);
                notuseMap.remove(map);
                break;
            }
        }
    }
    newMap.addAll(notuseMap);
    // for (IMetadataColumn column : metadataTable.getListColumns()) {
    // for (Map<String, Object> map : oldMap) {
    // if (column.getLabel().equals(map.get(COLUMN_NAME))) {
    // Map<String, Object> map2 = new HashMap<String, Object>();
    // map2.put(COLUMN_NAME, column.getLabel());
    // map2.put(ARRAY, map.get(ARRAY));
    // newMap.add(map2);
    // }
    // }
    // }
    setTableElementParameter(newMap);
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ColumnNameChanged

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

the class ChangeMetadataCommand method propagateDatas.

private void propagateDatas(boolean isExecute) {
    // update currentConnector when flow main type
    if (schemaParam != null && (schemaParam.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || schemaParam.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) && EConnectionType.FLOW_MAIN.getDefaultMenuName().toUpperCase().equals(schemaParam.getContext())) {
        currentConnector = EConnectionType.FLOW_MAIN.getName();
    }
    String baseConnectorForCurrentNode = node.getConnectorFromName(currentConnector).getBaseSchema();
    // Propagate :
    if (outputdataContainer != null && (!outputdataContainer.getInputs().isEmpty() || !outputdataContainer.getOuputs().isEmpty())) {
        for (IODataComponent currentIO : outputdataContainer.getInputs()) {
            INode sourceNode = currentIO.getSource();
            if (currentIO.hasChanged() && (sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName()).getBaseSchema().equals(baseConnectorForCurrentNode))) {
                sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
                if (isExecute) {
                    currentIO.setTable(oldInputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    currentIO.setTable(newInputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
        for (IODataComponent currentIO : outputdataContainer.getOuputs()) {
            INodeConnector nodeConnector = null;
            String baseConnector = null;
            Node sourceNode = (Node) currentIO.getSource();
            nodeConnector = sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName());
            baseConnector = nodeConnector.getBaseSchema();
            INode targetNode = currentIO.getTarget();
            boolean sourceIsBuiltIn = ((Node) currentIO.getSource()).getConnectorFromType(currentIO.getConnection().getLineStyle()).isMultiSchema();
            boolean targetIsBuiltIn = ((Node) targetNode).getConnectorFromType(currentIO.getConnection().getLineStyle()).isMultiSchema();
            boolean isJoblet = ((Node) targetNode).isJoblet();
            if (!isJoblet && baseConnector.equals(baseConnectorForCurrentNode) && (targetIsBuiltIn || (targetNode.getMetadataFromConnector(baseConnector) != null && !targetNode.getMetadataFromConnector(baseConnector).sameMetadataAs(newOutputMetadata)))) {
                targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
                if (isExecute) {
                    if (targetNode instanceof Node) {
                        if (((Node) targetNode).getComponent().isSchemaAutoPropagated() && getPropagate() && targetNode.getMetadataList().size() > 0) {
                            IMetadataTable tmpClone;
                            if (sourceIsBuiltIn) {
                                IMetadataTable tab = node.getMetadataTable(currentIO.getConnection().getMetadataTable().getTableName());
                                if (tab == null && node.getJobletNode() != null) {
                                    tab = node.getJobletNode().getMetadataTable(currentIO.getConnection().getMetadataTable().getTableName());
                                }
                                tmpClone = tab.clone(true);
                            } else {
                                IMetadataTable tab = node.getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                                if (tab == null && node.getJobletNode() != null) {
                                    tab = node.getJobletNode().getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                                }
                                tmpClone = tab.clone(true);
                            }
                            IMetadataTable toCopy = newOutputMetadata.clone();
                            // wzhang modify to add feature 7611
                            String dbmsId = null;
                            IMetadataTable copy;
                            if (((Node) targetNode).getMetadataFromConnector(baseConnector) != null) {
                                dbmsId = targetNode.getMetadataFromConnector(baseConnector).getDbms();
                                MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                                toCopy = tmpClone;
                                // only if the target node have exactly the same connector
                                copy = ((Node) targetNode).getMetadataFromConnector(baseConnector).clone(true);
                            } else {
                                // can only be FLOW right now for this case. //$NON-NLS-1$
                                final String mainConnector = "FLOW";
                                dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
                                MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                                toCopy = tmpClone;
                                // if don't have the same connector, take the main connector of the component.
                                copy = ((Node) targetNode).getMetadataFromConnector(mainConnector).clone(true);
                            }
                            // MetadataTool.copyTable(toCopy, copy);
                            // wzhang modify to add feature 7611
                            MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, inputSchemaParam);
                            if (outputdataContainer.getOuputs().size() > 0) {
                                List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                                for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                                    dataComp.setColumnNameChanged(columnNameChanged);
                                }
                            }
                            cmd.setRepositoryMode(repositoryMode);
                            cmd.execute(true);
                            propagatedChange.add(cmd);
                        }
                    }
                    currentIO.setTable(oldOutputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    if (targetNode instanceof Node) {
                        if (!targetIsBuiltIn && getPropagate()) {
                            if (((Node) targetNode).getComponent().isSchemaAutoPropagated()) {
                                if (outputdataContainer.getOuputs().size() > 0) {
                                    List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                                    for (ChangeMetadataCommand cmd : propagatedChange) {
                                        for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                                            dataComp.setColumnNameChanged(columnNameChanged);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    currentIO.setTable(newOutputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
    } else if (dataComponent != null) {
        for (IConnection outgoingConnection : node.getOutgoingConnections()) {
            if (outgoingConnection.getConnectorName().equals(currentConnector)) {
                outgoingConnection.getTarget().metadataInputChanged(dataComponent, outgoingConnection.getName());
            }
        }
    } else {
        if (!node.getOutgoingConnections().isEmpty()) {
            IMetadataTable relativeOldOutputMetadata = null;
            IMetadataTable relativeNewOutputMetadata = null;
            if (isExecute) {
                relativeOldOutputMetadata = oldOutputMetadata;
                relativeNewOutputMetadata = newOutputMetadata;
            } else {
                relativeOldOutputMetadata = newOutputMetadata;
                relativeNewOutputMetadata = oldOutputMetadata;
            }
            for (IConnection outgoingConnection : node.getOutgoingConnections()) {
                if (!outgoingConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                    continue;
                }
                final Node target = (Node) outgoingConnection.getTarget();
                if (target != null && target.getExternalNode() != null) {
                    List<IMetadataColumn> oldListColumns = relativeOldOutputMetadata.getListColumns();
                    List<IMetadataColumn> newListColumns = relativeNewOutputMetadata.getListColumns();
                    List<ColumnNameChanged> columnNameChanges = new ArrayList<ColumnNameChanged>();
                    int size = oldListColumns.size();
                    int newSize = newListColumns.size();
                    if (newSize < size) {
                        size = newSize;
                    }
                    IODataComponent output = new IODataComponent(outgoingConnection, relativeNewOutputMetadata);
                    if (newListColumns != null) {
                        List<ColumnNameChanged> newColumnsList = output.getNewMetadataColumns();
                        // new added columns list
                        Set<String> newAddedColumns = new HashSet<String>();
                        // newest columns after user changed
                        Set<String> newestColumns = new HashSet<String>();
                        // init
                        if (newColumnsList != null) {
                            for (ColumnNameChanged columnChanged : newColumnsList) {
                                newAddedColumns.add(columnChanged.getNewName());
                            }
                        }
                        for (IMetadataColumn metadataColumn : newListColumns) {
                            newestColumns.add(metadataColumn.getLabel());
                        }
                        // check
                        for (int i = 0; i < size; i++) {
                            IMetadataColumn oldMetadataColumn = oldListColumns.get(i);
                            String columnName = oldMetadataColumn.getLabel();
                            // been removed
                            if (!newestColumns.contains(columnName)) {
                                IMetadataColumn newMetadataColumn = newListColumns.get(i);
                                String newColumnNameAtThisIndex = newMetadataColumn.getLabel();
                                // column, so we suppose the more possible truth is that it is a renamed column
                                if (newAddedColumns.contains(newColumnNameAtThisIndex)) {
                                    columnNameChanges.add(new ColumnNameChanged(columnName, newColumnNameAtThisIndex));
                                }
                            }
                        }
                    }
                    output.setColumnNameChanged(columnNameChanges);
                    target.metadataInputChanged(output, outgoingConnection.getName());
                }
            }
        }
    }
    if (inputdataContainer != null) {
        for (IODataComponent currentIO : inputdataContainer.getOuputs()) {
            if (currentIO.hasChanged() && (currentIO.getSource().getConnectorFromName(currentIO.getConnection().getConnectorName()).getBaseSchema().equals(currentConnector))) {
                INode targetNode = currentIO.getTarget();
                targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
                if (isExecute) {
                    currentIO.setTable(oldInputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    currentIO.setTable(newInputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
    }
// End propagate
}
Also used : INode(org.talend.core.model.process.INode) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) INodeConnector(org.talend.core.model.process.INodeConnector) 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)

Example 10 with ColumnNameChanged

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

the class ChangeMetadataCommand method execute.

@Override
public void execute() {
    propagatedChange.clear();
    propagateDatas(true);
    if (currentInputMetadata != null) {
        if (!currentInputMetadata.sameMetadataAs(newInputMetadata, IMetadataColumn.OPTIONS_NONE)) {
            if (!currentInputMetadata.sameMetadataAs(newInputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) {
                String type = (String) inputNode.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
                if (type != null) {
                    if (type.equals(EmfComponent.REPOSITORY)) {
                        inputWasRepository = true;
                        inputNode.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                    }
                }
            }
            MetadataToolHelper.copyTable(newInputMetadata, currentInputMetadata);
        }
    }
    if (!currentOutputMetadata.sameMetadataAs(newOutputMetadata, IMetadataColumn.OPTIONS_NONE)) {
        if (!currentOutputMetadata.sameMetadataAs(newOutputMetadata, IMetadataColumn.OPTIONS_IGNORE_USED)) {
            String type = (String) node.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
            if (type != null && type.equals(EmfComponent.REPOSITORY) && !repositoryMode) {
                // for one node has several schema_type,set mode for the current one
                if ((node.getElementParameter("SCHEMA_TYPE").getContext().equals(currentOutputMetadata.getAttachedConnector()))) {
                    outputWasRepository = true;
                    node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                }
            }
        }
        MetadataToolHelper.copyTable(newOutputMetadata, currentOutputMetadata);
    }
    if (inputSchemaParam != null && inputSchemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()) != null && EmfComponent.REPOSITORY.equals(inputSchemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).getValue())) {
        // add by wzhang to fix bug 7898.
        IElementParameter elementParameter = node.getElementParameter(EParameterName.MAPPING.getName());
        if (elementParameter != null) {
            if (elementParameter.getValue() instanceof String) {
                String value = (String) elementParameter.getValue();
                if (!isDBComponent(value)) {
                    schemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                    schemaParam.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName()).setValue(inputSchemaParam.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName()).getValue());
                }
            }
        }
    }
    for (INodeConnector connector : node.getListConnector()) {
        if ((!connector.getName().equals(currentConnector)) && connector.getBaseSchema().equals(currentConnector)) {
            // if there is some other schema dependant of this one, modify them
            MetadataToolHelper.copyTable(newOutputMetadata, node.getMetadataFromConnector(connector.getName()));
            updateComponentSchema(node, node.getMetadataFromConnector(connector.getName()));
        }
    }
    updateComponentSchema(node, currentOutputMetadata);
    List<ColumnNameChanged> columnNameChanged = MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata);
    ColumnListController.updateColumnList(node, columnNameChanged, true);
    if (inputNode != null) {
        updateComponentSchema(inputNode, currentInputMetadata);
        List<ColumnNameChanged> inputColumnNameChangedExt = MetadataToolHelper.getColumnNameChangedExt(inputNode, oldInputMetadata, newInputMetadata);
        ColumnListController.updateColumnList(node, inputColumnNameChangedExt);
    }
    //
    List<ColumnNameChanged> outputColumnNameChangedExt = MetadataToolHelper.getColumnNameChangedExt(node, oldOutputMetadata, newOutputMetadata);
    syncOutputNodeColumnsList(outputColumnNameChangedExt);
    setTableMAPPING();
    if (!internal) {
        updateColumnList(oldOutputMetadata, newOutputMetadata);
        ((Process) node.getProcess()).checkProcess();
    }
    refreshMetadataChanged();
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector)

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