Search in sources :

Example 51 with MetadataColumn

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

the class WSDLSchemaDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new FillLayout());
    tableEditor = new MetadataEmfTableEditor("");
    tableEditor.setMetadataTable(metadataTable);
    // (List<MetadataColumn>)
    List<MetadataColumn> list = metadataTable.getColumns();
    // form.getSchemaViewer().getInput();
    tableEditor.addAll(list);
    tableEditorView = new MetadataEmfTableEditorView(composite, SWT.NONE);
    tableEditorView.setMetadataEditor(tableEditor);
    return composite;
}
Also used : MetadataEmfTableEditorView(org.talend.core.ui.metadata.editor.MetadataEmfTableEditorView) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Composite(org.eclipse.swt.widgets.Composite) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 52 with MetadataColumn

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

the class SchemaUtils method convertComponentSchemaIntoTalendSchema.

private static void convertComponentSchemaIntoTalendSchema(Schema schema, MetadataTable metadataTable) {
    if (schema == null || metadataTable == null) {
        return;
    }
    for (Schema.Field field : schema.getFields()) {
        MetadataColumn metadataColumn = MetadataToolAvroHelper.convertFromAvro(field);
        metadataTable.getColumns().add(metadataColumn);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Schema(org.apache.avro.Schema)

Example 53 with MetadataColumn

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

the class ImportHL7StructureAction method initXmlTreeData.

private void initXmlTreeData(List<String> schemaList, List<HL7FileNode> root, List<HL7TreeNode> treeData) {
    Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
    List<? extends IConnection> incomingConnections = new ArrayList<IConnection>();
    if (hl7ui != null) {
        if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            ((HL7OutputManager) hl7ui.gethl7Manager()).getContents().clear();
            incomingConnections = NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(), IConnectionCategory.FLOW);
        }
    }
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    List<MetadataTable> iMetadataTables = new ArrayList<MetadataTable>();
    HL7TreeNode rootNode = null;
    Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
    Map<String, MetadataTable> schemaNameToOutputTable = new HashMap<String, MetadataTable>();
    for (String schemaName : schemaList) {
        IMetadataTable metadataTable = null;
        for (IConnection connection : incomingConnections) {
            if (connection.getUniqueName().equals(schemaName)) {
                metadataTable = connection.getMetadataTable();
                metadataTable.setLabel(connection.getUniqueName());
                schemaNameToInputTable.put(schemaName, metadataTable);
                break;
            }
        }
        MetadataTable targetMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
        targetMetadataTable.setId(factory.getNextId());
        schemaNameToOutputTable.put(schemaName, targetMetadataTable);
        targetMetadataTable.setLabel(schemaName);
        iMetadataTables.add(targetMetadataTable);
    }
    HL7TreeNode current = null;
    HL7TreeNode temp = null;
    String currentPath = null;
    String defaultValue = null;
    int nodeOrder = 0;
    boolean haveOrder = true;
    // build root tree
    for (int i = 0; i < root.size(); i++) {
        HL7FileNode node = root.get(i);
        String newPath = node.getFilePath();
        defaultValue = node.getDefaultValue();
        String columnName = node.getRelatedColumn();
        // String type = node.getType();
        String orderValue = String.valueOf(node.getOrder());
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        if (haveOrder) {
            nodeOrder = node.getOrder();
        }
        String rowName = columnName;
        if (columnName != null && columnName.contains(":")) {
            String[] names = columnName.split(":");
            rowName = names[0];
            columnName = names[1];
        } else {
            columnName = null;
        }
        temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
        if (temp == null) {
            // should not happen
            continue;
        }
        // temp.setDataType(type);
        if (rootNode == null) {
            rootNode = temp;
        }
        if (node.getAttribute().equals("main")) {
            temp.setMain(true);
        }
        current = temp;
        currentPath = newPath;
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        if (rowName != null && rowName.length() > 0) {
            temp.setRow(rowName);
        }
        if (columnName != null) {
            IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
            // group node can not get the metadata table
            if (metadataTable == null) {
                IMetadataTable metadataTableTemp = null;
                for (IConnection connection : incomingConnections) {
                    metadataTableTemp = connection.getMetadataTable();
                    String connectionName = metadataTableTemp.getLabel();
                    if (connectionName == null) {
                        connectionName = connection.getUniqueName();
                    }
                    if (columnName.startsWith(connectionName)) {
                        break;
                    }
                }
                temp.setColumnName(columnName);
                if (metadataTableTemp != null) {
                    temp.setColumn(metadataTableTemp.getColumn(columnName));
                    temp.setTable(metadataTableTemp);
                }
            } else {
                temp.setColumnName(columnName);
                temp.setColumn(metadataTable.getColumn(columnName));
                temp.setTable(metadataTable);
            }
            //
            if (!temp.isMain()) {
                MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                newColumn.setLabel(columnName);
                newColumn.setName(temp.getLabel());
                newColumn.setLength(226);
                newColumn.setTalendType("id_String");
                schemaNameToOutputTable.get(rowName).getColumns().add(newColumn);
            }
        }
    }
    if (rootNode == null) {
        rootNode = new Element("rootTag");
    }
    if (haveOrder) {
        orderNode(rootNode);
    }
    if (rootNode != null) {
        treeData.add(rootNode);
    }
    if (hl7ui != null) {
        if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            ((HL7OutputManager) hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(), treeData);
        }
    } else if (form != null) {
        for (HL7TreeNode hl7Node : treeData) {
            form.getContents().put(rootNode.getColumnLabel(), hl7Node);
        }
    }
    if (hl7ui != null) {
        // execute the commands,initialize the propertiesView .
        List<Command> commands = new ArrayList<Command>();
        for (MetadataTable tableTemp : iMetadataTables) {
            Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(hl7ui.gethl7Manager().getHl7Component(), IHL7Constant.TABLE_SCHEMAS, tableTemp.getLabel(), ConvertionHelper.convert(tableTemp));
            commands.add(hl7Cmd);
        }
        for (Command command : commands) {
            command.execute();
        }
    }
}
Also used : HashMap(java.util.HashMap) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) Command(org.eclipse.gef.commands.Command) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 54 with MetadataColumn

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

the class HL7Manager method convertMetadataColumns2Propertis.

public List<Map<String, String>> convertMetadataColumns2Propertis() {
    List<Map<String, String>> schemas = new ArrayList<Map<String, String>>();
    Iterator<String> it = schemaRelationMap.keySet().iterator();
    while (it.hasNext()) {
        MetadataTable metatable = ConnectionFactory.eINSTANCE.createMetadataTable();
        String schemaKey = it.next().toString();
        List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
        columns.addAll(schemaRelationMap.get(schemaKey));
        Map<String, String> oneSchema = new HashMap<String, String>();
        //$NON-NLS-N$
        String displayName = "";
        for (int i = 0; i < columns.size(); i++) {
            MetadataColumn column = columns.get(i);
            String original = columns.get(i).getOriginalField();
            if (original != null && !"".equals(original)) {
                if (original.indexOf(TalendTextUtils.LBRACKET) > 0) {
                    original = original.substring(0, original.indexOf(TalendTextUtils.LBRACKET));
                }
            }
            if (i != columns.size() - 1) {
                displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK + ",";
            } else {
                displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK;
            }
            if (column.getSourceType() == null) {
                column.setSourceType("id_String");
            }
            if (column.getTalendType() == null) {
                column.setTalendType("id_String");
            }
            // column.setLabel(column.getOriginalField()); // display user defined column name
            metatable.getColumns().add(column);
        }
        metatable.setLabel(schemaKey);
        schemaKey = mapSchemaKeyFromNode(schemaKey);
        IMetadataTable table = ConvertionHelper.convert(metatable);
        table.setTableName(schemaKey);
        if (displayName != null && !"".equals(displayName)) {
            //$NON-NLS-N$
            oneSchema.put("SCHEMA", schemaKey);
            //$NON-NLS-N$
            oneSchema.put("MAPPING", displayName);
            schemas.add(oneSchema);
        }
        if (table != null && !table.getListColumns().isEmpty()) {
            // 
            boolean find = false;
            int index = 0;
            for (int i = 0; i < hl7Component.getMetadataList().size(); i++) {
                if (table.getLabel().equals(hl7Component.getMetadataList().get(i).getLabel())) {
                    find = true;
                    index = i;
                    break;
                }
            }
            if (find) {
                hl7Component.getMetadataList().remove(index);
            } else {
                schemaKey = hl7Component.getProcess().generateUniqueConnectionName(MultiSchemasUtil.getConnectionBaseName(schemaKey));
                table.setTableName(schemaKey);
            }
            hl7Component.getMetadataList().add(table);
        } else if (table != null && table.getListColumns().isEmpty()) {
            boolean find = false;
            int index = 0;
            for (int i = 0; i < hl7Component.getMetadataList().size(); i++) {
                if (table.getLabel().equals(hl7Component.getMetadataList().get(i).getLabel())) {
                    find = true;
                    index = i;
                    break;
                }
            }
            if (find) {
                hl7Component.getMetadataList().remove(index);
                hl7Component.getMetadataList().add(table);
            }
        }
    }
    return schemas;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 55 with MetadataColumn

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

the class HL7MultiSchemaUI method buildCurrentTable.

private MetadataTable buildCurrentTable(MetadataColumn[] beans, String schemaKey) {
    MetadataTable metatable = ConnectionFactory.eINSTANCE.createMetadataTable();
    //$NON-NLS-N$
    String displayName = "";
    for (int i = 0; i < beans.length; i++) {
        MetadataColumn column = beans[i];
        String original = beans[i].getOriginalField();
        if (original != null && !"".equals(original)) {
            if (original.indexOf(TalendTextUtils.LBRACKET) > 0) {
                original = original.substring(0, original.indexOf(TalendTextUtils.LBRACKET));
            }
        }
        if (i != beans.length - 1) {
            displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK + ",";
        } else {
            displayName = displayName + TalendTextUtils.QUOTATION_MARK + original + TalendTextUtils.QUOTATION_MARK;
        }
        if (column.getSourceType() == null) {
            column.setSourceType("id_String");
        }
        if (column.getTalendType() == null) {
            column.setTalendType("id_String");
        }
        // column.setLabel(column.getOriginalField()); // display user defined column name
        metatable.getColumns().add(column);
    }
    metatable.setLabel(schemaKey);
    return metatable;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)59 ArrayList (java.util.ArrayList)27 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)22 List (java.util.List)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)10 IModel (org.talend.designer.hl7.model.IModel)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Command (org.eclipse.gef.commands.Command)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 ExtendedTableResetDBTypesCommand (org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand)5 MetadataEmfExportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand)5 MetadataEmfImportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand)5 MetadataEmfPasteCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand)5 HL7MultiSchemaUI (org.talend.designer.hl7.ui.HL7MultiSchemaUI)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4