Search in sources :

Example 41 with MetadataColumn

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

the class UIManager method convert.

/**
     * qzhang Comment method "convert".
     * 
     * @param outputMetaTable2
     * @return TODO
     */
public void convert(RowGeneratorComponent externalNode, IMetadataTable outputMetaTable2, FunctionManagerExt functionManager) {
    List<IMetadataColumn> exts = new ArrayList<IMetadataColumn>();
    for (int j = 0; j < outputMetaTable2.getListColumns().size(); j++) {
        IMetadataColumn column = outputMetaTable2.getListColumns().get(j);
        if (column instanceof MetadataColumnExt) {
            exts.add(column.clone());
        } else if (column instanceof MetadataColumn) {
            MetadataColumnExt ext = new MetadataColumnExt((MetadataColumn) column);
            List<Function> funs = functionManager.getFunctionsByType(ext.getTalendType());
            ext.setArrayFunctions(functionManager.getFunctionArrays(funs));
            if (!funs.isEmpty()) {
                Function funtion = functionManager.getFunctionFromColumn(ext);
                if (funtion == null) {
                    funtion = functionManager.getFuntionFromArray(ext, externalNode, j);
                }
                ext.setFunction(funtion);
            }
            exts.add(ext);
        }
    }
    outputMetaTable2.setListColumns(exts);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) Function(org.talend.designer.rowgenerator.data.Function) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)

Example 42 with MetadataColumn

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

the class ValidationRulesUtil method updateRejectMetatable.

public static void updateRejectMetatable(INode node, INode refNode) {
    if (!isHasValidationRule(node)) {
        return;
    }
    List<IMetadataTable> metadatas = node.getMetadataList();
    if (metadatas != null && metadatas.size() > 0) {
        IMetadataTable table = null;
        boolean isHasRejectTable = false;
        for (IMetadataTable metadataTable : metadatas) {
            if ("VALIDATION_REJECT".equals(metadataTable.getTableName())) {
                //$NON-NLS-1$
                isHasRejectTable = true;
                table = metadataTable;
                break;
            }
        }
        if (!isHasRejectTable) {
            table = new MetadataTable();
        }
        //$NON-NLS-1$
        table.setAttachedConnector("VALIDATION_REJECT");
        //$NON-NLS-1$
        table.setTableName("VALIDATION_REJECT");
        table.setReadOnly(true);
        List<? extends IConnection> mainConnection = null;
        if (refNode != null) {
            mainConnection = refNode.getIncomingConnections(EConnectionType.FLOW_MAIN);
        } else {
            mainConnection = node.getIncomingConnections(EConnectionType.FLOW_MAIN);
        }
        IConnection connection = null;
        if (mainConnection != null && mainConnection.size() > 0) {
            table.getListColumns().clear();
            connection = mainConnection.get(0);
        } else {
            List<? extends IConnection> outgoingConnections;
            if (refNode != null) {
                //$NON-NLS-1$
                outgoingConnections = refNode.getOutgoingConnections("FLOW");
            } else {
                //$NON-NLS-1$
                outgoingConnections = node.getOutgoingConnections("FLOW");
            }
            if (outgoingConnections != null && outgoingConnections.size() > 0) {
                connection = outgoingConnections.get(0);
            }
        }
        if (connection != null) {
            IMetadataTable inputTable = connection.getMetadataTable();
            if (inputTable != null) {
                MetadataToolHelper.copyTable(null, inputTable, table);
            }
        }
        List<IMetadataColumn> listColumns = table.getListColumns();
        boolean isHasErrorMsgCol = false;
        for (IMetadataColumn metadataColumn : listColumns) {
            if ("errorMessage".equals(metadataColumn.getLabel())) {
                //$NON-NLS-1$
                isHasErrorMsgCol = true;
                break;
            }
        }
        if (!isHasErrorMsgCol) {
            MetadataColumn column = new MetadataColumn();
            //$NON-NLS-1$
            column.setId("30");
            column.setKey(false);
            //$NON-NLS-1$
            column.setLabel("errorMessage");
            column.setLength(255);
            //$NON-NLS-1$
            column.setOriginalDbColumnName("errorMessage");
            column.setPrecision(0);
            column.setCustom(true);
            column.setReadOnly(true);
            column.setNullable(true);
            //$NON-NLS-1$
            column.setTalendType("id_String");
            table.getListColumns().add(column);
            if (!isHasRejectTable) {
                node.getMetadataList().add(table);
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 43 with MetadataColumn

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

the class CompleteDropTargetTableListener method insertNewOutputEntryFromVarEntry.

private void insertNewOutputEntryFromVarEntry(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, ITableEntry tableEntrySource, String columnName) {
    MetadataColumn metadataColumn = new MetadataColumn();
    metadataColumn.setLabel(columnName);
    metadataColumn.setTalendType(((VarTableEntry) tableEntrySource).getType());
    metadataColumn.setNullable(((VarTableEntry) tableEntrySource).isNullable());
    metadataColumnsBeingAdded.add(metadataColumn);
    sources.add(tableEntrySource);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn)

Example 44 with MetadataColumn

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

the class RestResponseSchemaController method createComboCommand.

@Override
public Command createComboCommand(SelectionEvent event) {
    // Change the body type according to selected return body type
    Command changePropertyCommand = super.createComboCommand(event);
    Object newReturnType = null;
    if (changePropertyCommand != null) {
        newReturnType = ((PropertyChangeCommand) changePropertyCommand).getNewValue();
    }
    if (newReturnType == null) {
        return null;
    }
    // get old metadata column
    List<IMetadataTable> metadataList = ((INode) elem).getMetadataList();
    IMetadataTable oldMetadataTable = null;
    if (metadataList != null && metadataList.size() > 0) {
        oldMetadataTable = metadataList.get(0);
    } else {
        metadataList = new ArrayList<IMetadataTable>();
        ((INode) elem).setMetadataList(metadataList);
    }
    // create new metadata column
    IMetadataTable newMetadataTable = oldMetadataTable == null ? new MetadataTable() : oldMetadataTable.clone();
    List<IMetadataColumn> listColumns = newMetadataTable.getListColumns();
    if (listColumns == null) {
        listColumns = new ArrayList<IMetadataColumn>();
        newMetadataTable.setListColumns(listColumns);
    }
    IMetadataColumn bodyColumn = listColumns.size() > 0 ? listColumns.get(0) : new MetadataColumn();
    bodyColumn.setId("body");
    bodyColumn.setTalendType(newReturnType.toString());
    listColumns.clear();
    listColumns.add(bodyColumn);
    metadataList.clear();
    metadataList.add(newMetadataTable);
    // construct change metadata command
    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand((INode) elem, null, oldMetadataTable, newMetadataTable);
    // construct compound command by combining above 2 commands
    CompoundCommand compoundCommand = new CompoundCommand();
    compoundCommand.add(changePropertyCommand);
    compoundCommand.add(changeMetadataCommand);
    return compoundCommand;
}
Also used : INode(org.talend.core.model.process.INode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)

Aggregations

MetadataColumn (org.talend.core.model.metadata.MetadataColumn)44 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)20 ArrayList (java.util.ArrayList)14 MetadataTable (org.talend.core.model.metadata.MetadataTable)13 Test (org.junit.Test)6 MetadataColumnExt (org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)6 IElementParameter (org.talend.core.model.process.IElementParameter)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 IComponent (org.talend.core.model.components.IComponent)3 IConnection (org.talend.core.model.process.IConnection)3 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)3 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 List (java.util.List)2 Schema (org.apache.avro.Schema)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Point (org.eclipse.swt.graphics.Point)2