Search in sources :

Example 11 with ColumnNameChanged

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

the class ChangeMetadataCommand method undo.

@Override
public void undo() {
    propagateDatas(false);
    if (currentInputMetadata != null) {
        if (!currentInputMetadata.sameMetadataAs(oldInputMetadata, IMetadataColumn.OPTIONS_NONE)) {
            currentInputMetadata.setListColumns(oldInputMetadata.getListColumns());
            if (inputWasRepository) {
                inputNode.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY);
            }
        }
    }
    if (!currentOutputMetadata.sameMetadataAs(oldOutputMetadata, IMetadataColumn.OPTIONS_NONE)) {
        List<IMetadataColumn> currentColumns = new ArrayList<IMetadataColumn>(oldOutputMetadata.getListColumns());
        currentOutputMetadata.setListColumns(currentColumns);
        MetadataToolHelper.copyTable(oldOutputMetadata, currentOutputMetadata);
    }
    for (INodeConnector connector : node.getListConnector()) {
        if ((!connector.getName().equals(currentConnector)) && connector.getBaseSchema().equals(currentConnector)) {
            MetadataToolHelper.copyTable(oldOutputMetadata, node.getMetadataFromConnector(connector.getName()));
        }
    }
    if (outputWasRepository) {
        node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.REPOSITORY);
    }
    for (ChangeMetadataCommand cmd : propagatedChange) {
        cmd.undo();
    }
    List<ColumnNameChanged> columnNameChanged = MetadataToolHelper.getColumnNameChanged(oldOutputMetadata, newOutputMetadata);
    ColumnListController.updateColumnList(node, columnNameChanged, true);
    if (!internal) {
        updateColumnList(newOutputMetadata, oldOutputMetadata);
        ((Process) node.getProcess()).checkProcess();
    }
    refreshMetadataChanged();
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 12 with ColumnNameChanged

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

the class ColumnListController method updateColumnsOnElement.

private static void updateColumnsOnElement(IElement element, List<ColumnNameChanged> columnsChanged, boolean synWidthWithMetadataColumn, String[] prevColumnNameList, String[] curColumnNameList, String[] curColumnValueList, List<String> refColumnListNamesTmpWithSourceName, List<String> refColumnListValuesTmp, String[] refColumnListNames, String[] refColumnListValues, boolean isSCDComponent, boolean isEdifactComponent, Map<String, Boolean> customColMap) {
    List<String> columnList;
    String[] columnNameList;
    String edifactId = null;
    if (isEdifactComponent) {
        for (IElementParameter par : element.getElementParametersWithChildrens()) {
            if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
                edifactId = par.getValue().toString();
                break;
            }
        }
    }
    for (int i = 0; i < element.getElementParameters().size(); i++) {
        IElementParameter param = element.getElementParameters().get(i);
        columnList = getColumnList(element, param.getContext(), null);
        columnNameList = columnList.toArray(new String[0]);
        if (param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) {
            curColumnNameList = columnNameList;
            curColumnValueList = columnNameList;
        }
        if (param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST) {
            curColumnNameList = prevColumnNameList;
            curColumnValueList = prevColumnNameList;
        }
        if (param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
            curColumnNameList = refColumnListNames;
            curColumnValueList = refColumnListValues;
        }
        if ((param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) || param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
            param.setListItemsDisplayName(curColumnNameList);
            param.setListItemsValue(curColumnValueList);
            // for bug 10945
            // 10155
            boolean currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
            if (!currentColumnStillExist) {
                for (int j = 0; j < refColumnListNamesTmpWithSourceName.size(); j++) {
                    if (param.getValue().equals(refColumnListNamesTmpWithSourceName.get(j))) {
                        param.setValue(refColumnListValuesTmp.get(j));
                        break;
                    }
                }
                currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
            }
            if (curColumnNameList.length > 0 && !currentColumnStillExist) {
                param.setValue(curColumnValueList[0]);
            } else if (!currentColumnStillExist) {
                //$NON-NLS-1$
                param.setValue("");
            }
            syncNodePropertiesColumns(param, columnsChanged, curColumnNameList);
        }
        if (param.getFieldType() == EParameterFieldType.TABLE) {
            Object[] itemsValue = param.getListItemsValue();
            for (Object element2 : itemsValue) {
                if (element2 instanceof IElementParameter) {
                    IElementParameter tmpParam = (IElementParameter) element2;
                    columnList = getColumnList(element, tmpParam.getContext(), customColMap);
                    String[] tableColumnNameList = columnList.toArray(new String[0]);
                    if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST) {
                        curColumnNameList = tableColumnNameList;
                        curColumnValueList = tableColumnNameList;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof INode) {
                        curColumnNameList = prevColumnNameList;
                        curColumnValueList = prevColumnNameList;
                    }
                    // needed for traces with breakpoint, feature:
                    if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof IConnection) {
                        curColumnNameList = tableColumnNameList;
                        curColumnValueList = tableColumnNameList;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                        curColumnNameList = refColumnListNames;
                        curColumnValueList = refColumnListValues;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                        List<String[]> filterColumns = filterColumns(tmpParam, curColumnNameList, curColumnValueList, customColMap);
                        curColumnNameList = filterColumns.get(0);
                        curColumnValueList = filterColumns.get(1);
                        tmpParam.setListItemsDisplayCodeName(curColumnNameList);
                        tmpParam.setListItemsDisplayName(curColumnNameList);
                        tmpParam.setListItemsValue(curColumnValueList);
                        if (curColumnValueList.length > 0) {
                            tmpParam.setDefaultClosedListValue(curColumnValueList[0]);
                        } else {
                            //$NON-NLS-1$
                            tmpParam.setDefaultClosedListValue("");
                        }
                        syncNodePropertiesTableColumns(param, columnsChanged, curColumnNameList, tmpParam);
                    }
                }
            }
        }
        if (param.isBasedOnSchema()) {
            List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
            List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
            for (int j = 0; j < columnNameList.length; j++) {
                String columnName = columnNameList[j];
                String[] codes = param.getListItemsDisplayCodeName();
                Map<String, Object> newLine = null;
                boolean found = false;
                ColumnNameChanged colChanged = null;
                if (columnsChanged != null) {
                    for (int k = 0; k < columnsChanged.size() && !found; k++) {
                        colChanged = columnsChanged.get(k);
                        if (colChanged.getNewName().equals(columnName)) {
                            found = true;
                        }
                    }
                }
                if (found) {
                    found = false;
                    for (int k = 0; k < paramValues.size() && !found; k++) {
                        Map<String, Object> currentLine = paramValues.get(k);
                        if (currentLine.get(codes[0]).equals(colChanged.getOldName())) {
                            currentLine.put(codes[0], colChanged.getNewName());
                            found = true;
                        }
                    }
                }
                found = false;
                for (int k = 0; k < paramValues.size() && !found; k++) {
                    Map<String, Object> currentLine = paramValues.get(k);
                    if (currentLine.get(codes[0]) == null) {
                        currentLine.put(codes[0], columnName);
                    }
                    if (currentLine.get(codes[0]).equals(columnName)) {
                        found = true;
                        newLine = currentLine;
                    }
                }
                if (!found) {
                    newLine = TableController.createNewLine(param);
                    newLine.put(codes[0], columnName);
                    reUsedColumnFunctionArrayCheck(newLine, element, codes);
                    if (!StringUtils.isEmpty(edifactId)) {
                        org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(edifactId);
                        if (connection != null && connection instanceof EDIFACTConnection) {
                            List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
                            for (MetadataColumn col : tables.get(0).getColumns()) {
                                if (col.getLabel().equals(columnName)) {
                                    if (col instanceof EDIFACTColumn) {
                                        EDIFACTColumn edicolumn = (EDIFACTColumn) col;
                                        String ediXpath = edicolumn.getEDIXpath();
                                        newLine.put(codes[0], columnName);
                                        newLine.put(codes[1], ediXpath);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (element instanceof Node) {
                        Node node = (Node) element;
                        String familyName = node.getComponent().getOriginalFamilyName();
                        /** need add second parameter for hbase input/output component **/
                        if (familyName != null && familyName.equals("Databases/HBase")) {
                            for (IElementParameter par : node.getElementParametersWithChildrens()) {
                                if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
                                    String hbaseConnectionId = par.getValue().toString();
                                    String columnFamily = null;
                                    org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(hbaseConnectionId);
                                    if (connection != null && connection instanceof DatabaseConnection) {
                                        /* use imetadataconnection because maybe it's in context model */
                                        IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
                                        List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
                                        boolean find = false;
                                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                                            for (MetadataColumn column : table.getColumns()) {
                                                if (column.getLabel() != null && column.getLabel().equals(columnName)) {
                                                    for (TaggedValue tv : column.getTaggedValue()) {
                                                        String tag = tv.getTag();
                                                        if (tag != null && tag.equals("COLUMN FAMILY")) {
                                                            String value = tv.getValue();
                                                            if (value != null) {
                                                                columnFamily = value;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                if (find) {
                                                    break;
                                                }
                                            }
                                            if (find) {
                                                break;
                                            }
                                        }
                                    }
                                    if (columnFamily != null) {
                                        newLine.put(codes[1], TalendTextUtils.addQuotes(columnFamily));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                /* should put other attribute for edi mapping */
                }
                if (synWidthWithMetadataColumn) {
                    setColumnSize(newLine, element, codes, param);
                }
                newParamValues.add(j, newLine);
            }
            paramValues.clear();
            paramValues.addAll(newParamValues);
        } else if (param.isColumnsBasedOnSchema()) {
            List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
            List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
            String[] listRepositoryItem = new String[columnNameList.length];
            String[] listItemsDisplayValue = new String[columnNameList.length];
            String[] listItemsDisplayCodeValue = new String[columnNameList.length];
            Object[] listItemsValue = new Object[columnNameList.length];
            String[] listItemsShowIf = new String[columnNameList.length];
            String[] listItemsNotShowIf = new String[columnNameList.length];
            ElementParameter newParam;
            for (int j = 0; j < columnNameList.length; j++) {
                String columnName = columnNameList[j];
                listItemsDisplayCodeValue[j] = columnName;
                listItemsDisplayValue[j] = columnName;
                //$NON-NLS-1$
                listRepositoryItem[j] = "";
                listItemsShowIf[j] = null;
                listItemsNotShowIf[j] = null;
                newParam = new ElementParameter(element);
                newParam.setName(columnName);
                //$NON-NLS-1$
                newParam.setDisplayName("");
                newParam.setFieldType(EParameterFieldType.TEXT);
                //$NON-NLS-1$
                newParam.setValue("");
                listItemsValue[j] = newParam;
                boolean found = false;
                ColumnNameChanged colChanged = null;
                if (columnsChanged != null) {
                    for (int k = 0; k < columnsChanged.size() && !found; k++) {
                        colChanged = columnsChanged.get(k);
                        if (colChanged.getNewName().equals(columnName)) {
                            found = true;
                        }
                    }
                }
                for (int k = 0; k < paramValues.size(); k++) {
                    Map<String, Object> line = paramValues.get(k);
                    Map<String, Object> newline = new HashMap<String, Object>();
                    if (found) {
                        Object object = line.get(colChanged.getOldName());
                        if (object != null) {
                            newline.put(colChanged.getNewName(), object);
                            line.remove(colChanged.getOldName());
                            line.putAll(newline);
                        }
                    }
                }
            }
            param.setListItemsDisplayName(listItemsDisplayValue);
            param.setListItemsDisplayCodeName(listItemsDisplayCodeValue);
            param.setListItemsValue(listItemsValue);
            param.setListRepositoryItems(listRepositoryItem);
            param.setListItemsShowIf(listItemsShowIf);
            param.setListItemsNotShowIf(listItemsNotShowIf);
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) EDIFACTConnection(org.talend.core.model.metadata.builder.connection.EDIFACTConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) Connection(org.talend.core.model.metadata.builder.connection.Connection) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDIFACTColumn(org.talend.core.model.metadata.builder.connection.EDIFACTColumn) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Point(org.eclipse.swt.graphics.Point) JSONObject(org.talend.utils.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with ColumnNameChanged

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

the class ColumnListController method syncNodePropertiesColumns.

/**
     * 
     * DOC ggu Comment method "syncNodePropertiesColumns".<BR/>
     * 
     * synchronize COLUMN_LIST, PREV_COLUMN_LIST, LOOKUP_COLUMN_LIST
     * 
     * @param param
     * @param columnsChanged
     * @param columnNameList
     */
private static void syncNodePropertiesColumns(IElementParameter param, List<ColumnNameChanged> columnsChanged, String[] columnNameList) {
    if (columnsChanged == null || columnsChanged.isEmpty()) {
        return;
    }
    if (columnNameList == null || columnNameList.length == 0) {
        return;
    }
    if (!isUpdateColumnEnable(param, columnsChanged, param)) {
        return;
    }
    //$NON-NLS-1$
    String componentUniqueName = "";
    //$NON-NLS-1$
    String preRowLookup = "";
    if (param.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) {
        boolean found = false;
        String newName = preRowLookup + colChanged.getNewName();
        for (String element : columnNameList) {
            if (newName.equals(element)) {
                found = true;
                break;
            }
        }
        if (found) {
            if (param.getValue().equals(componentUniqueName + colChanged.getOldName())) {
                param.setValue(componentUniqueName + colChanged.getNewName());
            }
        }
    }
}
Also used : ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ColumnNameChangedExt(org.talend.core.model.metadata.ColumnNameChangedExt)

Example 14 with ColumnNameChanged

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

the class RepositoryChangeMetadataCommand method updateColumnList.

@Override
protected void updateColumnList(IMetadataTable oldTable, IMetadataTable newTable) {
    IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (ww == null) {
        return;
    }
    IWorkbenchPage page = ww.getActivePage();
    ComponentSettingsView viewer = (ComponentSettingsView) page.findView(ComponentSettingsView.ID);
    if (viewer == null) {
        return;
    }
    if (viewer.getElement() != null && viewer.getElement().equals(node)) {
        List<ColumnNameChanged> columnNameChanged = new ArrayList<ColumnNameChanged>();
        for (int j = 0; j < oldTable.getListColumns().size(); j++) {
            if (newTable.getListColumns().size() > j) {
                String oldName = oldTable.getListColumns().get(j).getLabel();
                String newName = newTable.getListColumns().get(j).getLabel();
                if (!oldName.equals(newName)) {
                    columnNameChanged.add(new ColumnNameChanged(oldName, newName));
                }
            }
        }
        ColumnListController.updateColumnList(node, null);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ComponentSettingsView(org.talend.designer.core.ui.views.properties.ComponentSettingsView)

Example 15 with ColumnNameChanged

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

the class FileOutputXMLComponent method metadataOutputChanged.

@Override
public void metadataOutputChanged(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()) {
        return;
    }
    for (ColumnNameChanged col : dataComponent.getColumnNameChanged()) {
        for (Map<String, String> map : listRoot) {
            if (map.get(COLUMN).equals(col.getOldName())) {
                map.put(COLUMN, col.getNewName());
                flagRoot = true;
            }
        }
        for (Map<String, String> map : listGroup) {
            if (map.get(COLUMN).equals(col.getOldName())) {
                map.put(COLUMN, col.getNewName());
                flagGroup = true;
            }
        }
        for (Map<String, String> map : listLoop) {
            if (map.get(COLUMN).equals(col.getOldName())) {
                map.put(COLUMN, 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)

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