Search in sources :

Example 11 with TreeNode

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

the class XmlMapComponent method connectionStatusChanged.

@Override
public void connectionStatusChanged(EConnectionType newValue, String connectionToApply) {
    XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
    InputXmlTree mainTable = null;
    InputXmlTree oldmainTable = null;
    for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
        if (!inputTree.isLookup()) {
            oldmainTable = inputTree;
            break;
        }
    }
    for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
        if (inputTree.getName() != null && inputTree.getName().equals(connectionToApply)) {
            boolean value = EConnectionType.FLOW_MAIN != newValue;
            inputTree.setLookup(value);
            if (!value) {
                mainTable = inputTree;
            }
        } else if (EConnectionType.FLOW_MAIN == newValue) {
            inputTree.setLookup(true);
        }
    }
    // put the main table to the first place
    if (mainTable != null) {
        externalEmfData.getInputTrees().remove(mainTable);
        externalEmfData.getInputTrees().add(0, mainTable);
    }
    if (oldmainTable != null && oldmainTable != mainTable) {
        boolean checkMultiLoopsStatus = XmlMapUtil.checkMultiLoopsStatus(oldmainTable);
        if (checkMultiLoopsStatus) {
            MessageDialog.openInformation(null, "Information", "Multiple loops in previous main table will be lost in tXmlMap");
            // multipleloops status of the new main table will be false ,clean the InputLoopNodesTables for
            // output will be ok
            XmlMapUtil.removeloopInOutputTree(externalEmfData, mainTable, new ArrayList<TreeNode>());
            // clean multipleloops and only keep the first loop of doc
            for (TreeNode treeNode : oldmainTable.getNodes()) {
                if (XmlMapUtil.DOCUMENT.equals(treeNode.getType())) {
                    List<TreeNode> oldLoops = new ArrayList<TreeNode>();
                    XmlMapUtil.getChildLoops(oldLoops, treeNode.getChildren());
                    if (oldLoops.size() > 1) {
                        for (int i = 1; i < oldLoops.size(); i++) {
                            oldLoops.get(i).setLoop(false);
                        }
                    }
                }
            }
            oldmainTable.setMultiLoops(false);
        }
    }
    initMapperMain();
    mapperMain.getMapperManager().getProblemsAnalyser().checkProblems();
}
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) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 12 with TreeNode

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

the class XmlMapService method cloneTreeNode.

private EObject cloneTreeNode(EObject node) {
    if (node instanceof AbstractInOutTree) {
        AbstractInOutTree source = null;
        AbstractInOutTree oriSource = null;
        if (node instanceof InputXmlTree) {
            oriSource = (InputXmlTree) node;
            source = XmlmapFactory.eINSTANCE.createInputXmlTree();
            ((InputXmlTree) source).setActivateGlobalMap(((InputXmlTree) oriSource).isActivateGlobalMap());
            ((InputXmlTree) source).setInnerJoin(((InputXmlTree) oriSource).isInnerJoin());
            ((InputXmlTree) source).setLookup(((InputXmlTree) oriSource).isLookup());
            ((InputXmlTree) source).setLookupMode(((InputXmlTree) oriSource).getLookupMode());
            ((InputXmlTree) source).setMatchingMode(((InputXmlTree) oriSource).getMatchingMode());
            ((InputXmlTree) source).setPersistent(((InputXmlTree) oriSource).isPersistent());
        } else if (node instanceof OutputXmlTree) {
            oriSource = (OutputXmlTree) node;
            source = XmlmapFactory.eINSTANCE.createOutputXmlTree();
            ((OutputXmlTree) source).setAllInOne(((OutputXmlTree) oriSource).isAllInOne());
            ((OutputXmlTree) source).setEnableEmptyElement(((OutputXmlTree) oriSource).isEnableEmptyElement());
            ((OutputXmlTree) source).setErrorReject(((OutputXmlTree) oriSource).isErrorReject());
            ((OutputXmlTree) source).setReject(((OutputXmlTree) oriSource).isReject());
            ((OutputXmlTree) source).setRejectInnerJoin(((OutputXmlTree) oriSource).isRejectInnerJoin());
        }
        source.setActivateCondensedTool(oriSource.isActivateCondensedTool());
        source.setActivateExpressionFilter(oriSource.isActivateExpressionFilter());
        source.setExpressionFilter(oriSource.getExpressionFilter());
        source.setMinimized(oriSource.isMinimized());
        source.setMultiLoops(oriSource.isMultiLoops());
        source.setName(oriSource.getName());
        return source;
    } else if (node instanceof VarNode) {
        VarNode oriSource = (VarNode) node;
        VarNode source = XmlmapFactory.eINSTANCE.createVarNode();
        source.setExpression(oriSource.getExpression());
        source.setName(oriSource.getName());
        source.setNullable(oriSource.isNullable());
        source.setType(oriSource.getType());
        return source;
    } else if (node instanceof TreeNode) {
        TreeNode source = null;
        TreeNode oriSource = null;
        if (node instanceof OutputTreeNode) {
            oriSource = (OutputTreeNode) node;
            source = XmlmapFactory.eINSTANCE.createOutputTreeNode();
            ((OutputTreeNode) source).setAggregate(((OutputTreeNode) oriSource).isAggregate());
            ((OutputTreeNode) source).setInputLoopNodesTable(((OutputTreeNode) oriSource).getInputLoopNodesTable());
        } else if (node instanceof GlobalMapNode) {
            oriSource = (GlobalMapNode) node;
            source = XmlmapFactory.eINSTANCE.createGlobalMapNode();
            return source;
        } else {
            oriSource = (TreeNode) node;
            source = XmlmapFactory.eINSTANCE.createTreeNode();
        }
        source.setChoice(oriSource.isChoice());
        source.setDefaultValue(oriSource.getDefaultValue());
        source.setExpression(oriSource.getExpression());
        source.setGroup(oriSource.isGroup());
        source.setKey(oriSource.isKey());
        source.setLoop(oriSource.isLoop());
        source.setMain(oriSource.isMain());
        source.setName(oriSource.getName());
        source.setNodeType(oriSource.getNodeType());
        source.setNullable(oriSource.isNullable());
        source.setOptional(oriSource.isOptional());
        source.setPattern(oriSource.getPattern());
        source.setSubstitution(oriSource.isSubstitution());
        source.setType(oriSource.getType());
        source.setXpath(oriSource.getXpath());
        return source;
    }
    return null;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 13 with TreeNode

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

the class XmlMapUtilTest method testUpdateXPathAndExpression.

@Test
public void testUpdateXPathAndExpression() {
    XmlMapData data = XmlmapFactory.eINSTANCE.createXmlMapData();
    InputXmlTree inputTree = XmlmapFactory.eINSTANCE.createInputXmlTree();
    inputTree.setName("row1");
    OutputXmlTree outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
    outputTree.setName("out1");
    data.getInputTrees().add(inputTree);
    data.getOutputTrees().add(outputTree);
    TreeNode doc = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(doc, "doc", "id_Document", NodeType.ELEMENT, "row1/doc", "");
    inputTree.getNodes().add(doc);
    TreeNode school = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(school, "school", "id_String", NodeType.ELEMENT, "row1.doc:/school", "");
    doc.getChildren().add(school);
    TreeNode student = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(student, "student", "id_String", NodeType.ELEMENT, "row1.doc:/school/student", "");
    school.getChildren().add(student);
    TreeNode name = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(name, "name", "id_String", NodeType.ATTRIBUT, "row1.doc:/school/student/@name", "");
    student.getChildren().add(name);
    OutputTreeNode outColumn = XmlmapFactory.eINSTANCE.createOutputTreeNode();
    initTreeNode(outColumn, "outColumn", "id_String", NodeType.ELEMENT, "out1/outColumn", "[row1.doc:/school/student/@name]");
    outputTree.getNodes().add(outColumn);
    createConnection(data, name, outColumn);
    // rename schema column
    doc.setName("document");
    XmlMapUtil.updateXPathAndExpression(data, new XmlMapExpressionManager(), doc, "document", 2, true);
    assertTrue(doc.getXpath().equals("row1/document"));
    assertTrue(school.getXpath().equals("row1.document:/school"));
    assertTrue(student.getXpath().equals("row1.document:/school/student"));
    assertTrue(name.getXpath().equals("row1.document:/school/student/@name"));
    assertTrue(outColumn.getExpression().equals("[row1.document:/school/student/@name]"));
    // rename doc child
    school.setName("kindergarten");
    XmlMapUtil.updateXPathAndExpression(data, new XmlMapExpressionManager(), school, "kindergarten", 3, true);
    assertTrue(doc.getXpath().equals("row1/document"));
    assertTrue(school.getXpath().equals("row1.document:/kindergarten"));
    assertTrue(student.getXpath().equals("row1.document:/kindergarten/student"));
    assertTrue(name.getXpath().equals("row1.document:/kindergarten/student/@name"));
    assertTrue(outColumn.getExpression().equals("[row1.document:/kindergarten/student/@name]"));
}
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) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) Test(org.junit.Test)

Example 14 with TreeNode

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

the class XmlMapDataImplTest method createSparkData.

private XmlMapData createSparkData(String inputDiff, String outputDiff, String varDiff) {
    XmlMapData data = XmlmapFactory.eINSTANCE.createXmlMapData();
    //
    InputXmlTree inputTree = XmlmapFactory.eINSTANCE.createInputXmlTree();
    inputTree.setName("input_1");
    inputTree.setLookup(true);
    inputTree.setInnerJoin(false);
    inputTree.setLookupMode("LOAD_ONCE");
    inputTree.setMatchingMode("ALL_ROWS");
    inputTree.setMinimized(false);
    inputTree.setMultiLoops(false);
    inputTree.setPersistent(false);
    data.getInputTrees().add(inputTree);
    TreeNode treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
    treeNode.setName("inputTreeNode");
    treeNode.setXpath("row1/newColumn");
    treeNode.setExpression(inputDiff);
    treeNode.setType("id_String");
    treeNode.setLoop(false);
    treeNode.setPattern(inputDiff);
    treeNode.setKey(false);
    treeNode.setGroup(false);
    treeNode.setMain(false);
    treeNode.setDefaultValue("value");
    treeNode.setNullable(false);
    treeNode.setChoice(false);
    treeNode.setSubstitution(false);
    treeNode.setOptional(false);
    treeNode.setNodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType.ATTRIBUT);
    inputTree.getNodes().add(treeNode);
    OutputXmlTree outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
    outputTree.setName("output_1");
    outputTree.setReject(false);
    outputTree.setRejectInnerJoin(false);
    outputTree.setErrorReject(false);
    outputTree.setAllInOne(false);
    outputTree.setEnableEmptyElement(false);
    data.getOutputTrees().add(outputTree);
    OutputTreeNode treeNode2 = XmlmapFactory.eINSTANCE.createOutputTreeNode();
    treeNode2.setName("outputTreeNode");
    treeNode2.setXpath("out/newColumn");
    treeNode2.setType("id_String");
    treeNode2.setAggregate(false);
    treeNode2.setLoop(false);
    treeNode2.setPattern(outputDiff);
    treeNode2.setExpression(outputDiff);
    treeNode2.setKey(false);
    treeNode2.setGroup(false);
    treeNode2.setMain(false);
    treeNode2.setDefaultValue("value");
    treeNode2.setNullable(false);
    treeNode2.setChoice(false);
    treeNode2.setSubstitution(false);
    treeNode2.setOptional(false);
    treeNode2.setNodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType.ATTRIBUT);
    outputTree.getNodes().add(treeNode2);
    VarTable vatTable = XmlmapFactory.eINSTANCE.createVarTable();
    vatTable.setName("varTable");
    vatTable.setMinimized(true);
    VarNode varNode = XmlmapFactory.eINSTANCE.createVarNode();
    varNode.setName("varNode");
    varNode.setNullable(false);
    varNode.setType("id_String");
    varNode.setExpression(varDiff);
    vatTable.getNodes().add(varNode);
    data.getVarTables().add(vatTable);
    Connection connection = XmlmapFactory.eINSTANCE.createConnection();
    connection.setSource(treeNode);
    connection.setTarget(treeNode2);
    data.getConnections().add(connection);
    treeNode.getOutgoingConnections().add(connection);
    treeNode2.getIncomingConnections().add(connection);
    FilterConnection fc = XmlmapFactory.eINSTANCE.createFilterConnection();
    fc.setSource(treeNode);
    fc.setTarget(outputTree);
    data.getConnections().add(fc);
    treeNode.getFilterOutGoingConnections().add(fc);
    outputTree.getFilterIncomingConnections().add(fc);
    return data;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 15 with TreeNode

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

the class ImportTreeFromRepository method addElement.

private TreeNode addElement(TreeNode current, String currentPath, String newPath, String type, NodeType nodeType, int order) {
    TreeNode temp = createModel();
    //$NON-NLS-1$
    String name = newPath.substring(newPath.lastIndexOf("/") + 1);
    String parentPath = newPath.substring(0, newPath.lastIndexOf("/"));
    temp.setName(name);
    if (type == null) {
        type = XmlMapUtil.DEFAULT_DATA_TYPE;
    }
    temp.setType(type);
    temp.setNodeType(nodeType);
    if (type.equals("id_Date")) {
        //$NON-NLS-1$
        temp.setPattern("\"dd-MM-yyyy\"");
    }
    if (current == null) {
        // root node
        temp.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), name, nodeType));
        return temp;
    }
    if (currentPath.equals(parentPath)) {
        temp.setXpath(XmlMapUtil.getXPath(current.getXpath(), name, nodeType));
        addChildInOrder(current, temp, order);
    } else {
        //$NON-NLS-1$
        String[] nods = currentPath.split("/");
        //$NON-NLS-1$
        String[] newNods = parentPath.split("/");
        int parentLevel = 0;
        int checkLength = nods.length < newNods.length ? nods.length : newNods.length;
        for (int i = 1; i < checkLength; i++) {
            if (nods[i].equals(newNods[i])) {
                parentLevel = i;
            }
        }
        TreeNode parent = current;
        for (int i = 0; i < nods.length - (parentLevel + 1); i++) {
            TreeNode tmpParent = (TreeNode) parent.eContainer();
            if (tmpParent == null) {
                break;
            }
            parent = tmpParent;
        }
        if (parent != null) {
            temp.setXpath(XmlMapUtil.getXPath(parent.getXpath(), name, nodeType));
            addChildInOrder(parent, temp, order);
        }
    }
    return temp;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)

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