Search in sources :

Example 11 with XmlMapData

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

the class XmlMapComponent method renameMetadataColumnName.

@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
    List<AbstractInOutTree> abstractTrees = new ArrayList<AbstractInOutTree>();
    XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
    abstractTrees.addAll(externalEmfData.getInputTrees());
    abstractTrees.addAll(externalEmfData.getOutputTrees());
    for (AbstractInOutTree abstractTree : abstractTrees) {
        if (abstractTree.getName() != null && abstractTree.getName().equals(conectionName)) {
            List<TreeNode> children = new ArrayList<TreeNode>();
            if (abstractTree instanceof InputXmlTree) {
                children.addAll(((InputXmlTree) abstractTree).getNodes());
            } else {
                children.addAll(((OutputXmlTree) abstractTree).getNodes());
            }
            for (TreeNode treeNode : children) {
                if (treeNode.getName() != null && treeNode.getName().equals(oldColumnName) && !oldColumnName.equals(newColumnName)) {
                    treeNode.setName(newColumnName);
                    XmlMapUtil.updateXPathAndExpression(externalEmfData, expressionManager, treeNode, newColumnName, 2, true);
                }
            }
        }
    }
}
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) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 12 with XmlMapData

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

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

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

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

XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)36 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)18 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)17 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)15 ArrayList (java.util.ArrayList)14 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)14 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)8 List (java.util.List)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)5 IConnection (org.talend.core.model.process.IConnection)4 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)4 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)3 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 CCombo (org.eclipse.swt.custom.CCombo)2 Test (org.junit.Test)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 MapperTable (org.talend.designer.gefabstractmap.model.abstractmap.MapperTable)2