Search in sources :

Example 61 with TreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.

the class AutoMapper method map.

/**
     * DOC amaumont Comment method "map".
     */
public void map() {
    EList<InputXmlTree> inputTrees = xmlMapData.getInputTrees();
    EList<OutputXmlTree> outputTrees = xmlMapData.getOutputTrees();
    /*
         * non-document node , if name is the same ,automap document node , check xpath first , if can't find ,check the
         * name
         */
    for (OutputXmlTree outputTree : outputTrees) {
        List<TreeNode> outputEntries = getAllEntities(outputTree);
        for (TreeNode outputEntry : outputEntries) {
            if ((outputEntry.getExpression() == null || "".equals(outputEntry.getExpression())) && XmlMapUtil.isExpressionEditable(outputEntry)) {
                String xpath = outputEntry.getXpath();
                String outputNodePath = xpath.substring(outputTree.getName().length() + 1, xpath.length());
                TreeNode inputSameXpath = null;
                TreeNode inputSameName = null;
                out: for (InputXmlTree inputTable : inputTrees) {
                    List<TreeNode> inputColumnEntries = getAllEntities(inputTable);
                    in: for (TreeNode inputEntry : inputColumnEntries) {
                        // check if input tree node can be mapped
                        if (XmlMapUtil.isExpressionEditable(inputEntry)) {
                            String inputXpath = inputEntry.getXpath();
                            String inputNodePath = inputXpath.substring(inputTable.getName().length() + 1, inputXpath.length());
                            if (outputNodePath.equals(inputNodePath)) {
                                inputSameXpath = inputEntry;
                                break out;
                            }
                            // if the same name , find the first matched node , don't overwrite
                            if (inputSameName == null && outputEntry.getName() != null && outputEntry.getName().equals(inputEntry.getName())) {
                                inputSameName = inputEntry;
                            }
                        }
                    }
                }
                TreeNode inputEntryToMap = null;
                if (inputSameXpath != null) {
                    inputEntryToMap = inputSameXpath;
                } else if (inputSameName != null) {
                    inputEntryToMap = inputSameName;
                }
                if (inputEntryToMap != null) {
                    String expression = outputEntry.getExpression();
                    String convertToExpression = XmlMapUtil.convertToExpression(inputEntryToMap.getXpath());
                    if (expression != null && expression.indexOf(convertToExpression) != -1) {
                        continue;
                    } else {
                        if (expression == null) {
                            expression = "";
                        }
                        expression = expression + convertToExpression;
                    }
                    outputEntry.setExpression(expression);
                    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
                    conn.setSource(inputEntryToMap);
                    conn.setTarget(outputEntry);
                    outputEntry.getIncomingConnections().add(conn);
                    inputEntryToMap.getOutgoingConnections().add(conn);
                    xmlMapData.getConnections().add(conn);
                }
            }
        }
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) List(java.util.List) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 62 with TreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.

the class SearchZoneMapper method search.

public void search(Map<Integer, Map<Integer, Figure>> searchMaps, String searchValue) {
    if (searchValue.equals("") || searchValue == null) {
        return;
    }
    List<InputXmlTree> inputTrees = mapperManager.getExternalData().getInputTrees();
    List<VarTable> varTables = mapperManager.getExternalData().getVarTables();
    List<OutputXmlTree> outputTrees = mapperManager.getExternalData().getOutputTrees();
    matcher.setPattern("*" + searchValue.trim() + "*");
    int index = -1;
    // for the InputTables
    for (InputXmlTree inputXmlTree : inputTrees) {
        // ExpressionFilter
        if (inputXmlTree.getExpressionFilter() != null && matcher.matches(inputXmlTree.getExpressionFilter())) {
            EList<Adapter> adapter = inputXmlTree.eAdapters();
            if (adapter.size() > 0) {
                if (adapter.get(0) instanceof InputXmlTreeEditPart) {
                    InputXmlTreeEditPart inputXmlTreeEditPart = (InputXmlTreeEditPart) adapter.get(0);
                    if (inputXmlTreeEditPart != null && inputXmlTreeEditPart.getFigure() != null && inputXmlTreeEditPart.getFigure() instanceof InputXmlTreeFigure) {
                        InputXmlTreeFigure inputXmlTreeFigure = (InputXmlTreeFigure) inputXmlTreeEditPart.getFigure();
                        Map<Integer, Figure> map = new HashMap<Integer, Figure>();
                        map.put(0, inputXmlTreeFigure.getFilterContainer());
                        index++;
                        searchMaps.put(index, map);
                    }
                }
            }
        }
        // TreeNode
        for (TreeNode node : inputXmlTree.getNodes()) {
            // id_Document type
            if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
                for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
                    if (getMatcherNodeFigure(nodeTemp).size() > 0) {
                        index++;
                        searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
                    }
                }
            }
            if (getMatcherNodeFigure(node).size() > 0) {
                index++;
                searchMaps.put(index, getMatcherNodeFigure(node));
            }
        }
    }
    // for the VarsTables
    for (VarTable varTable : varTables) {
        for (VarNode node : varTable.getNodes()) {
            if (getMatcherNodeFigure(node).size() > 0) {
                index++;
                searchMaps.put(index, getMatcherNodeFigure(node));
            }
        }
    }
    // for the OutputTables
    for (OutputXmlTree outputXmlTree : outputTrees) {
        // ExpressionFilter
        if (outputXmlTree.getExpressionFilter() != null && matcher.matches(outputXmlTree.getExpressionFilter())) {
            EList<Adapter> adapter = outputXmlTree.eAdapters();
            if (adapter.size() > 0) {
                if (adapter.get(0) instanceof OutputXmlTreeEditPart) {
                    OutputXmlTreeEditPart outputXmlTreeEditPart = (OutputXmlTreeEditPart) adapter.get(0);
                    if (outputXmlTreeEditPart != null && outputXmlTreeEditPart.getFigure() != null && outputXmlTreeEditPart.getFigure() instanceof OutputXmlTreeFigure) {
                        OutputXmlTreeFigure outputXmlTreeFigure = (OutputXmlTreeFigure) outputXmlTreeEditPart.getFigure();
                        Map<Integer, Figure> map = new HashMap<Integer, Figure>();
                        map.put(0, outputXmlTreeFigure.getFilterContainer());
                        index++;
                        searchMaps.put(index, map);
                    }
                }
            }
        }
        // OutputTreeNode
        for (OutputTreeNode node : outputXmlTree.getNodes()) {
            // id_Document type
            if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
                for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
                    if (getMatcherNodeFigure(nodeTemp).size() > 0) {
                        index++;
                        searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
                    }
                }
            } else {
                if (getMatcherNodeFigure(node).size() > 0) {
                    index++;
                    searchMaps.put(index, getMatcherNodeFigure(node));
                }
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) HashMap(java.util.HashMap) Adapter(org.eclipse.emf.common.notify.Adapter) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart) IFigure(org.eclipse.draw2d.IFigure) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) XmlmapTreeNodeFigure(org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure) VarNodeFigure(org.talend.designer.xmlmap.figures.varnode.VarNodeFigure) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) VarEntityFigure(org.talend.designer.gefabstractmap.figures.var.VarEntityFigure) Figure(org.eclipse.draw2d.Figure) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure)

Example 63 with TreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.

the class TXMLMapChangeAllInOneValueMigrationTask method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.talend.core.model.migration.TXMLMapChangeAllInOneValueMigrationTask
	 * (org .talend.core.model.properties.Item)
	 */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            if (nodeType.getComponentName().startsWith("tXMLMap")) {
                XmlMapData xmlMapdata = (XmlMapData) nodeType.getNodeData();
                EList<OutputXmlTree> outputTables = xmlMapdata.getOutputTrees();
                EList<InputXmlTree> inputTables = xmlMapdata.getInputTrees();
                boolean hasDocumentInTheMainInputTable = false;
                for (InputXmlTree inputTable : inputTables) {
                    if (!(inputTable.isLookup())) {
                        for (TreeNode inputEntry : inputTable.getNodes()) {
                            if ("id_Document".equals(inputEntry.getType())) {
                                hasDocumentInTheMainInputTable = true;
                            }
                        }
                    }
                }
                if (hasDocumentInTheMainInputTable) {
                    for (OutputXmlTree outputTable : outputTables) {
                        for (TreeNode outputEntry : outputTable.getNodes()) {
                            if ("id_Document".equals(outputEntry.getType())) {
                                if (!outputTable.isAllInOne()) {
                                    outputTable.setAllInOne(true);
                                    modified = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 64 with TreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.

the class SetLoopAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    // nodesNeedToChangeMainStatus.clear();
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    Object s = getSelectedObjects().get(0);
    if (s instanceof List && !((List) s).isEmpty()) {
        List selectedarts = (List) s;
        Object obj = selectedarts.get(selectedarts.size() - 1);
        if (obj instanceof TreeNodeEditPart) {
            nodePart = (TreeNodeEditPart) obj;
            TreeNode model = (TreeNode) nodePart.getModel();
            if (NodeType.ATTRIBUT.equals(model.getNodeType()) || NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof TreeNode)) {
                return false;
            }
            if (model.isLoop()) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 65 with TreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.

the class SetLoopAction method run.

@Override
public void run() {
    TreeNode model = (TreeNode) nodePart.getModel();
    TreeNode docRoot = XmlMapUtil.getTreeNodeRoot(model);
    AbstractInOutTree abstractTree = (AbstractInOutTree) docRoot.eContainer();
    boolean isLookup = abstractTree != mapperManager.getMainInputTree() && !(abstractTree instanceof OutputXmlTree);
    // remove old group
    if (model instanceof OutputTreeNode) {
        OutputTreeNode outputNode = (OutputTreeNode) model;
        if (docRoot != null) {
            XmlMapUtil.cleanSubGroup(outputNode);
            List<TreeNode> newLoopUpGroups = new ArrayList<TreeNode>();
            findUpGroupNode(newLoopUpGroups, outputNode);
            // clean all groups except the ancestor of new loop
            XmlMapUtil.cleanSubGroup(docRoot, newLoopUpGroups);
            // reset the group in case some element ancestor of loop element are not group but under the group
            if (!newLoopUpGroups.isEmpty()) {
                TreeNode rootGroup = newLoopUpGroups.get(newLoopUpGroups.size() - 1);
                upsetGroup(outputNode, rootGroup);
            }
        }
    }
    if (!isLookup) {
        // TDI-20147
        List<TreeNode> loopNodes = new ArrayList<TreeNode>();
        checkSubElementIsLoop(model, loopNodes);
        checkParentElementIsLoop(model, loopNodes);
        if (!loopNodes.isEmpty()) {
            if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("SetLoopAction.cleanSubLoopTitle"), Messages.getString("SetLoopAction.cleanSubLoopMessages"))) {
            } else {
                return;
            }
        }
        for (TreeNode treeNode : loopNodes) {
            treeNode.setLoop(false);
        }
        model.setLoop(true);
        XmlMapUtil.clearMainNode(model);
        XmlMapUtil.upsetMainNode(model);
        abstractTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(abstractTree));
        if (input) {
            // check if child is mapped to output remove the old loop in output node
            XmlMapUtil.removeloopInOutputTree(mapperManager, loopNodes);
        // disable the function to add sourceloop into InputLoopNodesTable automatically
        // add input loopNodes to InputLoopNodesTable
        // addInputLoopNodesToOutput(model, model);
        } else {
            // clean the InputLoopNodesTable for the old loops
            InputXmlTree mainInput = mapperManager.getMainInputTree();
            XmlMapUtil.removeLoopTableForOutput((OutputXmlTree) abstractTree, loopNodes, mainInput == null ? false : mainInput.isMultiLoops());
        }
    } else {
        if (docRoot != null) {
            cleanSubLoop(docRoot);
        }
        model.setLoop(true);
        XmlMapUtil.clearMainNode(docRoot);
        XmlMapUtil.upsetMainNode(model);
    }
    if (abstractTree != null) {
        mapperManager.getProblemsAnalyser().checkProblems(abstractTree);
        mapperManager.getMapperUI().updateStatusBar();
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Aggregations

TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)119 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)88 ArrayList (java.util.ArrayList)39 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)34 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)26 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)25 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)22 List (java.util.List)21 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)19 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)17 EList (org.eclipse.emf.common.util.EList)15 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)14 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)13 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)12 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)12 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)11 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)10 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)9 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)9 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)8