Search in sources :

Example 26 with InputXmlTree

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

the class XmlMapComponent method checkNeededRoutines.

@Override
public List<String> checkNeededRoutines(List<String> possibleRoutines, String additionalString) {
    List<String> routinesToAdd = new ArrayList<String>();
    XmlMapData xmlMapData = (XmlMapData) getExternalEmfData();
    for (String routine : possibleRoutines) {
        List<OutputXmlTree> listOutput = xmlMapData.getOutputTrees();
        for (OutputXmlTree outTable : listOutput) {
            List<OutputTreeNode> listOutEntry = outTable.getNodes();
            if (listOutEntry != null && !listOutEntry.isEmpty()) {
                for (OutputTreeNode outEntry : listOutEntry) {
                    String expression = outEntry.getExpression();
                    if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
                        routinesToAdd.add(routine);
                    }
                }
            }
            String filter = outTable.getExpressionFilter();
            if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
                routinesToAdd.add(routine);
            }
        }
        List<InputXmlTree> listInput = xmlMapData.getInputTrees();
        for (InputXmlTree inputTable : listInput) {
            List<TreeNode> listInEntry = inputTable.getNodes();
            if (listInEntry != null && !listInEntry.isEmpty()) {
                for (TreeNode inEntry : listInEntry) {
                    String expression = inEntry.getExpression();
                    if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
                        routinesToAdd.add(routine);
                    }
                }
            }
            String filter = inputTable.getExpressionFilter();
            if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
                routinesToAdd.add(routine);
            }
        }
        List<VarTable> listVar = xmlMapData.getVarTables();
        for (VarTable varTable : listVar) {
            List<VarNode> listVarEntry = varTable.getNodes();
            if (listVarEntry != null && !listVarEntry.isEmpty()) {
                for (VarNode varEntry : listVarEntry) {
                    String expression = varEntry.getExpression();
                    if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
                        routinesToAdd.add(routine);
                    }
                }
            }
        }
    }
    return routinesToAdd;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) ArrayList(java.util.ArrayList) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) 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) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 27 with InputXmlTree

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

the class XmlMapComponent method renameInputConnection.

@Override
public void renameInputConnection(String oldName, String newName) {
    XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
    for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
        if (inputTree.getName() != null && inputTree.getName().equals(oldName) && !oldName.equals(newName)) {
            inputTree.setName(newName);
            XmlMapUtil.updateXPathAndExpression(externalEmfData, expressionManager, inputTree.getNodes(), inputTree.getName(), 1);
        }
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 28 with InputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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 29 with InputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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 30 with InputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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)

Aggregations

InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)52 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)34 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)28 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)26 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)18 ArrayList (java.util.ArrayList)17 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)12 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)12 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)9 List (java.util.List)5 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 IConnection (org.talend.designer.xmlmap.model.emf.xmlmap.IConnection)5 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)5 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)4 HashMap (java.util.HashMap)3 Point (org.eclipse.draw2d.geometry.Point)3 EList (org.eclipse.emf.common.util.EList)3 ExpressionFigure (org.talend.designer.gefabstractmap.figures.ExpressionFigure)3 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)3 Iterator (java.util.Iterator)2