Search in sources :

Example 6 with OutputXmlTree

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

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

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

the class ImportTreeFromRepository method run.

@Override
public void run() {
    targetAbsolutePath = null;
    loopNode = null;
    xpathAndOrder.clear();
    RepositoryXmlSelectionDialog reviewDialog = new RepositoryXmlSelectionDialog(shell, new String[] { "XML", "MDM" });
    if (reviewDialog.open() == Window.OK) {
        TreeNode treeNodeRoot = XmlMapUtil.getTreeNodeRoot(schemaNode);
        XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
        RepositoryNode repositoryNode = reviewDialog.getResult();
        Item item = repositoryNode.getObject().getProperty().getItem();
        String detailedMessage = "";
        try {
            if (item instanceof XmlFileConnectionItem) {
                XmlFileConnectionItem xmlitem = (XmlFileConnectionItem) item;
                XmlFileConnection connection = (XmlFileConnection) xmlitem.getConnection();
                prepareEmfTreeFromXml(connection);
            } else if (item instanceof MDMConnectionItem) {
                String selectedSchema = (String) repositoryNode.getProperties(EProperties.LABEL);
                MDMConnection connection = (MDMConnection) ((MDMConnectionItem) item).getConnection();
                prepareEmfTreeFromMdm(connection, selectedSchema);
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            StringBuffer sb = new StringBuffer();
            sb.append(e.toString());
            sb.append("\n");
            if (e.getStackTrace() != null) {
                for (StackTraceElement trace : e.getStackTrace()) {
                    sb.append(trace.toString());
                    sb.append("\n");
                }
            }
            detailedMessage = sb.toString();
        }
        boolean childrenEmpty = false;
        if (schemaNode.getChildren().isEmpty()) {
            childrenEmpty = true;
            TreeNode rootNode = createModel();
            rootNode.setName("root");
            rootNode.setNodeType(NodeType.ELEMENT);
            rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            rootNode.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), "root", NodeType.ELEMENT));
            schemaNode.getChildren().add(rootNode);
            if (loopNode == null) {
                schemaNode.getChildren().get(0).setLoop(true);
                schemaNode.getChildren().get(0).setMain(true);
            }
        }
        if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
            showError(detailedMessage);
        }
        AbstractInOutTree tree = null;
        if (schemaNode.eContainer() instanceof InputXmlTree) {
            XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
            connectionBuilder.setCheckRootNodePrefix(true);
            connectionBuilder.rebuildLinks(schemaNode, mapperManager.getExternalData());
            mapperManager.refreshTreeSchemaEditor((InputXmlTree) schemaNode.eContainer());
            // mapperManager.inputTreeSchemaBeanListModified();
            tree = (InputXmlTree) schemaNode.eContainer();
        } else if (schemaNode.eContainer() instanceof OutputXmlTree) {
            // mapperManager.outputTreeSchemaBeanListModified();
            mapperManager.refreshTreeSchemaEditor((OutputXmlTree) schemaNode.eContainer());
            tree = (OutputXmlTree) schemaNode.eContainer();
        }
        if (tree != null) {
            mapperManager.getProblemsAnalyser().checkProblems(tree);
            mapperManager.getMapperUI().updateStatusBar();
        }
    }
}
Also used : RepositoryXmlSelectionDialog(org.talend.designer.xmlmap.ui.dialog.RepositoryXmlSelectionDialog) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 9 with OutputXmlTree

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

the class TreeSettingDirectEditCommand method execute.

@Override
public void execute() {
    try {
        if (model instanceof InputXmlTree) {
            InputXmlTree inputTree = (InputXmlTree) model;
            if (type != null) {
                switch(type) {
                    case LOOKUP_MODEL:
                        inputTree.setLookupMode(getLookupModelByLabel((String) newValue));
                        break;
                    case MATCH_MODEL:
                        inputTree.setMatchingMode(getMatchModelByLabel((String) newValue));
                        break;
                    case JOIN_MODEL:
                        if (TreeSettingsConstant.INNER_JOIN.equals(newValue)) {
                            inputTree.setInnerJoin(true);
                        } else {
                            inputTree.setInnerJoin(false);
                        }
                        break;
                    case PERSISTENT_MODEL:
                        inputTree.setPersistent(Boolean.valueOf((String) newValue));
                        break;
                    case EXPRESSION_FILTER:
                        calculateFilterConnections(inputTree, (String) newValue);
                        inputTree.setExpressionFilter((String) newValue);
                        break;
                    default:
                        break;
                }
            }
        } else if (model instanceof OutputXmlTree) {
            OutputXmlTree outputTree = (OutputXmlTree) model;
            if (type != null) {
                switch(type) {
                    case OUTPUT_REJECT:
                        outputTree.setReject(Boolean.valueOf((String) newValue));
                        break;
                    case LOOK_UP_INNER_JOIN_REJECT:
                        outputTree.setRejectInnerJoin(Boolean.valueOf((String) newValue));
                        break;
                    case EXPRESSION_FILTER:
                        calculateFilterConnections(outputTree, (String) newValue);
                        outputTree.setExpressionFilter((String) newValue);
                        break;
                    case ALL_IN_ONE:
                        outputTree.setAllInOne(Boolean.valueOf((String) newValue));
                        break;
                    case ENABLE_EMPTY_ELEMENT:
                        outputTree.setEnableEmptyElement(Boolean.valueOf((String) newValue));
                }
            }
        }
    } catch (PatternSyntaxException ex) {
    // Syntax error in the regular expression
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 10 with OutputXmlTree

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

the class DropContextAnalyzer method checkDropIsValid.

private boolean checkDropIsValid() {
    if (objects == null || objects.getToTransfer().isEmpty() || targetEditPart == null) {
        return false;
    }
    Object targetModel = targetEditPart.getModel();
    targetFigure = targetEditPart.getFigure().findFigureAt(dropLocation.x, dropLocation.y);
    boolean isTragetOutputNode = targetModel instanceof OutputTreeNode;
    boolean isTragetInputNode = targetModel instanceof TreeNode && !(targetModel instanceof OutputTreeNode);
    boolean isVar = targetModel instanceof VarNode;
    boolean isDropInputTree = targetModel instanceof InputXmlTree;
    boolean isDropOutputTree = targetModel instanceof OutputXmlTree;
    boolean isDropVarTable = targetModel instanceof VarTable;
    // drop expression
    if (targetFigure instanceof ExpressionFigure) {
        dropType = DropType.DROP_EXPRESSION;
        if (isTragetOutputNode) {
            // INPUT => OUTPUT
            return XmlMapUtil.isExpressionEditable((TreeNode) targetModel);
        } else if (isTragetInputNode) {
            // INPUT => INPUT ,can't dnd in the same tree
            boolean isValid = checkDropInputValid(targetModel);
            if (isValid) {
                isValid = XmlMapUtil.isExpressionEditable((TreeNode) targetModel);
            }
            return isValid;
        }
        return true;
    } else // drop tree filter
    if (targetFigure instanceof FilterTextArea) {
        dropType = DropType.DROP_FILTER;
        return true;
    } else {
        if (objects.getType() == TransferdType.INPUT) {
            if (isTragetOutputNode) {
                return checkDropOutputDocChildValid(targetModel);
            } else if (isVar || isDropVarTable) {
                dropType = DropType.DROP_INSERT_VAR;
                return true;
            } else if (isDropInputTree) {
                dropType = DropType.DROP_INSERT_INPUT;
                return checkDropInputValid(targetModel);
            } else if (isDropOutputTree) {
                dropType = DropType.DROP_INSERT_OUTPUT;
                return true;
            }
        } else if (objects.getType() == TransferdType.VAR) {
            if (isTragetOutputNode) {
                return checkDropOutputDocChildValid(targetModel);
            } else if (isDropOutputTree) {
                dropType = DropType.DROP_INSERT_OUTPUT;
                return true;
            }
        }
    }
    return false;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) ExpressionFigure(org.talend.designer.gefabstractmap.figures.ExpressionFigure) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) FilterTextArea(org.talend.designer.gefabstractmap.figures.treesettings.FilterTextArea) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Aggregations

OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)49 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)30 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)26 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)26 ArrayList (java.util.ArrayList)17 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)15 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)13 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)12 List (java.util.List)11 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)9 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)9 OutputXmlTreeEditPart (org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart)7 EList (org.eclipse.emf.common.util.EList)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)6 HashMap (java.util.HashMap)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)5 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)5 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)4 EditPart (org.eclipse.gef.EditPart)3 Command (org.eclipse.gef.commands.Command)3