Search in sources :

Example 1 with IMetadataTable

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

the class ChangeMultiSchemasCommand method initNew.

private void initNew(Object object) {
    if (fakeConnection != null) {
        this.newFieldSeperator = fakeConnection.getFieldSeparatorValue();
        this.newRowSeperator = fakeConnection.getRowSeparatorValue();
        this.newEncoding = TalendTextUtils.addQuotes(fakeConnection.getEncoding());
        IElementParameter encodingType = node.getElementParameter(EParameterName.ENCODING_TYPE.getName());
        if (encodingType != null) {
            String[] codes = encodingType.getListItemsDisplayCodeName();
            if (codes != null) {
                List<String> list = Arrays.asList(codes);
                if (list.indexOf(fakeConnection.getEncoding()) > -1) {
                    this.newEncodingType = fakeConnection.getEncoding();
                } else {
                    // custom
                    this.newEncodingType = list.get(list.size() - 1);
                }
            }
        }
        this.newFilePath = fakeConnection.getFilePath();
        this.newTextEnclosure = fakeConnection.getTextEnclosure();
        this.newEscapeChar = fakeConnection.getEscapeChar();
        this.newCsvOption = fakeConnection.isCsvOption();
        this.newSelectedColumnIndex = TalendTextUtils.QUOTATION_MARK + String.valueOf(object) + TalendTextUtils.QUOTATION_MARK;
    } else if (params != null) {
        this.newFieldSeperator = params.get(EParameterName.FIELDSEPARATOR);
        this.newRowSeperator = params.get(EParameterName.ROWSEPARATOR);
        this.newEncoding = params.get(EParameterName.ENCODING);
        this.newEncodingType = params.get(EParameterName.ENCODING_TYPE);
        this.newFilePath = params.get(EParameterName.FILENAME);
        this.newTextEnclosure = params.get(EParameterName.TEXT_ENCLOSURE);
        this.newEscapeChar = params.get(EParameterName.ESCAPE_CHAR);
        this.newCsvOption = Boolean.valueOf(params.get(EParameterName.CSV_OPTION));
        this.newUseMultiSaparator = Boolean.valueOf(params.get(EParameterName.USE_MULTISEPARATORS));
        this.newSaparators = params.get(EParameterName.MULTI_SEPARATORS);
        this.newSelectedColumnIndex = params.get(EParameterName.COLUMNINDEX);
        this.newKeyValues = params.get(EParameterName.MULTI_KEYVALUES);
    }
    // map
    this.newSchemasListMap = new ArrayList<Map<String, String>>();
    // metadata table
    this.newMetadataTable = new ArrayList<IMetadataTable>();
    // hywang add for feature7373
    addSchemasMap(newSchemasListMap, newMetadataTable, this.rootSchemaData);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IMetadataTable

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

the class ChangeMultiSchemasCommand method addMetadataTable.

private void addMetadataTable(List<IMetadataTable> newTables) {
    // remove
    IProcess process = this.node.getProcess();
    List<IMetadataTable> needAddedTables = new ArrayList<IMetadataTable>();
    List<String> schemaNames = new ArrayList<String>();
    // record added table, and update the existed table.
    for (IMetadataTable table : newTables) {
        final String tableLabel = table.getLabel();
        schemaNames.add(tableLabel);
        IMetadataTable mappingTable = MetadataToolHelper.getMetadataTableFromNode(node, tableLabel);
        if (mappingTable == null) {
            // added
            needAddedTables.add(table);
            process.addUniqueConnectionName(table.getTableName());
        } else {
            MetadataToolHelper.copyTable(table, mappingTable);
        }
    }
    // record removed table
    List<IMetadataTable> needRemovedTables = new ArrayList<IMetadataTable>();
    for (IMetadataTable table : node.getMetadataList()) {
        if (!schemaNames.contains(table.getLabel())) {
            needRemovedTables.add(table);
            process.removeUniqueConnectionName(table.getTableName());
        }
    }
    node.getMetadataList().removeAll(needRemovedTables);
    node.getMetadataList().addAll(needAddedTables);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess)

Example 3 with IMetadataTable

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

the class ChangeMultiSchemasCommand method addSchemasMap.

private void addSchemasMap(List<Map<String, String>> newValueList, List<IMetadataTable> newTables, SchemasKeyData keyData) {
    if (keyData == null) {
        return;
    }
    if (keyData.getParent() != null) {
        // not root
        //
        Map<String, String> map = new HashMap<String, String>();
        final String uniqueRecord = keyData.getUniqueRecord();
        final String recordType = keyData.getRecordType();
        map.put(IMultiSchemaConstant.SCHEMA, uniqueRecord);
        map.put(IMultiSchemaConstant.RECORD, TalendTextUtils.addQuotes(recordType));
        map.put(IMultiSchemaConstant.PARENT_RECORD, TalendTextUtils.addQuotes(keyData.getParent().getRecordType()));
        map.put(IMultiSchemaConstant.CARDINALITY, keyData.getCard());
        map.put(IMultiSchemaConstant.FIELDDELIMITED, TalendTextUtils.addQuotes(keyData.getSeparator()));
        newValueList.add(map);
        //
        String connectionBaseName = MetadataToolHelper.validateColumnName(MultiSchemasUtil.getConnectionBaseName(uniqueRecord), 0);
        String uniqueConnName = node.getProcess().generateUniqueConnectionName(connectionBaseName);
        MetadataTable table = new MetadataTable();
        table.setLabel(uniqueRecord);
        table.setTableName(uniqueConnName);
        //$NON-NLS-1$
        String keyIndex = "";
        boolean first = true;
        List<MultiMetadataColumn> metadataColumnsInModel = keyData.getMetadataColumnsInModel();
        for (int i = 0; i < metadataColumnsInModel.size(); i++) {
            MultiMetadataColumn column = metadataColumnsInModel.get(i);
            table.getListColumns().add(column.clone(true));
            if (column.isKey()) {
                if (first) {
                    keyIndex += i;
                } else {
                    //$NON-NLS-1$
                    keyIndex += "," + i;
                }
                first = false;
            }
        }
        map.put(IMultiSchemaConstant.KEY_COLUMN_INDEX, TalendTextUtils.addQuotes(keyIndex));
        newTables.add(table);
    }
    for (SchemasKeyData child : keyData.getChildren()) {
        addSchemasMap(newValueList, newTables, child);
    }
}
Also used : HashMap(java.util.HashMap) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Example 4 with IMetadataTable

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

the class ChangeMultiSchemasCommand method initOld.

private void initOld() {
    if (node == null) {
        return;
    }
    IElementParameter elementParameter = this.node.getElementParameter(EParameterName.FILENAME.getName());
    if (elementParameter != null) {
        this.oldFilePath = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.ENCODING_TYPE.getName());
    if (elementParameter != null) {
        this.oldEncodingType = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.ENCODING.getName());
    if (elementParameter != null) {
        this.oldEncoding = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.ROWSEPARATOR.getName());
    if (elementParameter != null) {
        this.oldRowSeperator = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.FIELDSEPARATOR.getName());
    if (elementParameter != null) {
        this.oldFieldSeperator = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.TEXT_ENCLOSURE.getName());
    if (elementParameter != null) {
        this.oldTextEnclosure = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.ESCAPE_CHAR.getName());
    if (elementParameter != null) {
        this.oldEscapeChar = elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.CSV_OPTION.getName());
    if (elementParameter != null) {
        this.oldCsvOption = (Boolean) elementParameter.getValue();
    }
    // hywang add for feature7373
    elementParameter = this.node.getElementParameter(EParameterName.COLUMNINDEX.getName());
    if (elementParameter != null) {
        this.oldSelectedColumnIndex = String.valueOf(elementParameter.getValue());
    }
    elementParameter = this.node.getElementParameter(EParameterName.MULTI_SEPARATORS.getName());
    if (elementParameter != null) {
        this.oldSaparators = String.valueOf(elementParameter.getValue());
    }
    elementParameter = this.node.getElementParameter(EParameterName.USE_MULTISEPARATORS.getName());
    if (elementParameter != null) {
        this.oldUseMultiSaparator = (Boolean) elementParameter.getValue();
    }
    elementParameter = this.node.getElementParameter(EParameterName.MULTI_KEYVALUES.getName());
    if (elementParameter != null) {
        this.oldKeyValues = String.valueOf(elementParameter.getValue());
    }
    // schema table
    elementParameter = this.node.getElementParameter(EParameterName.SCHEMAS.getName());
    if (elementParameter != null) {
        Object value = elementParameter.getValue();
        List<Map<String, String>> oldvalueList = new ArrayList<Map<String, String>>();
        if (value != null) {
            List<Map<String, String>> valueList = (List<Map<String, String>>) value;
            for (Map<String, String> map : valueList) {
                Map<String, String> valueMap = new HashMap<String, String>();
                for (String key : map.keySet()) {
                    valueMap.put(key, map.get(key));
                }
                oldvalueList.add(valueMap);
            }
        }
        this.oldSchemasListMap = oldvalueList;
    }
    // metadata
    List<IMetadataTable> oldMetadataTable = new ArrayList<IMetadataTable>();
    for (IMetadataTable table : this.node.getMetadataList()) {
        oldMetadataTable.add(table.clone(true));
    }
    this.oldMetadataTable = oldMetadataTable;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with IMetadataTable

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

the class HL7UI method initTableViewer.

private void initTableViewer() {
    List<IMetadataTable> tables = externalNode.getMetadataList();
    for (IMetadataTable table : tables) {
        MetadataTable loaded = ConvertionHelper.convert(table);
        List<MetadataColumn> columns = loaded.getColumns();
        String trueTableName = table.getLabel();
        if (trueTableName.split("_").length > 2) {
            // get true table name from node draged from repository
            //$NON-NLS-N$  
            trueTableName = trueTableName.split("_")[1];
        }
        if (hl7Manager.getSchemaRelationMap().get(trueTableName) != null) {
            hl7Manager.getSchemaRelationMap().remove(trueTableName);
            hl7Manager.getSchemaRelationMap().put(trueTableName, columns);
        } else {
            hl7Manager.getSchemaRelationMap().put(trueTableName, columns);
        }
        MetadataColumn[] array = new MetadataColumn[columns.size()];
        int i = 0;
        for (MetadataColumn column : columns) {
            MetadataColumn newColumn = copyColumn(column);
            array[i] = newColumn;
            i++;
        }
        if (this.getMetaTableViewer().getSelection() instanceof IStructuredSelection) {
            IStructuredSelection selection = (IStructuredSelection) this.getMetaTableViewer().getSelection();
            if (selection.getFirstElement() != null) {
                String name = ((IModel) selection.getFirstElement()).getDisplayName();
                if (name.equals(trueTableName)) {
                    for (int j = 0; j < array.length; j++) {
                        hl7SchemaEditorView.getMetadataEditor().add(array[j]);
                    }
                // hl7SchemaEditorView.getMetadataEditor().addAll(columns);
                }
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IModel(org.talend.designer.hl7.model.IModel) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IMetadataTable (org.talend.core.model.metadata.IMetadataTable)216 ArrayList (java.util.ArrayList)103 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)84 IConnection (org.talend.core.model.process.IConnection)67 IElementParameter (org.talend.core.model.process.IElementParameter)67 List (java.util.List)57 INode (org.talend.core.model.process.INode)54 Node (org.talend.designer.core.ui.editor.nodes.Node)51 HashMap (java.util.HashMap)48 Map (java.util.Map)40 MetadataTable (org.talend.core.model.metadata.MetadataTable)35 INodeConnector (org.talend.core.model.process.INodeConnector)32 Connection (org.talend.designer.core.ui.editor.connections.Connection)28 Process (org.talend.designer.core.ui.editor.process.Process)25 IComponent (org.talend.core.model.components.IComponent)24 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)17 Point (org.eclipse.swt.graphics.Point)15