Search in sources :

Example 16 with TreeNode

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

the class ImportTreeFromRepository method prepareEmfTreeFromConnection.

private void prepareEmfTreeFromConnection(XmlFileConnection connection) {
    schemaNode.getChildren().clear();
    EList root = connection.getRoot();
    EList loop = connection.getLoop();
    EList group = connection.getGroup();
    TreeNode rootNode = null;
    TreeNode current = null;
    TreeNode temp = null;
    TreeNode mainNode = null;
    // xpath in item file
    String mainPath = null;
    // xpath in item file
    String currentPath = "";
    String defaultValue = null;
    // build root tree
    for (int i = 0; i < root.size(); i++) {
        XMLFileNode node = (XMLFileNode) root.get(i);
        String newPath = node.getXMLPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        if (node.getAttribute().equals("attri")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.ATTRIBUT, defaultValue);
        } else if (node.getAttribute().equals("ns")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.NAME_SPACE, defaultValue);
        } else {
            temp = this.addElement(current, currentPath, newPath, type, NodeType.ELEMENT, node.getOrder());
            if (rootNode == null) {
                rootNode = temp;
            }
            if (node.getAttribute().equals("main")) {
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            current = temp;
            currentPath = newPath;
        }
    }
    // build group tree
    current = mainNode;
    currentPath = mainPath;
    boolean isFirst = true;
    groupElements = new ArrayList<TreeNode>();
    for (int i = 0; i < group.size(); i++) {
        XMLFileNode node = (XMLFileNode) group.get(i);
        String newPath = node.getXMLPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        if (node.getAttribute().equals("attri")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.ATTRIBUT, defaultValue);
        } else if (node.getAttribute().equals("ns")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.NAME_SPACE, defaultValue);
        } else {
            temp = this.addElement(current, currentPath, newPath, type, NodeType.ELEMENT, node.getOrder());
            groupElements.add(temp);
            if (node.getAttribute().equals("main")) {
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            current = temp;
            currentPath = newPath;
        }
    }
    // build loop tree
    current = mainNode;
    currentPath = mainPath;
    isFirst = true;
    for (int i = 0; i < loop.size(); i++) {
        XMLFileNode node = (XMLFileNode) loop.get(i);
        String newPath = node.getXMLPath();
        defaultValue = node.getDefaultValue();
        String type = node.getType();
        if (node.getAttribute().equals("attri")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.ATTRIBUT, defaultValue);
        } else if (node.getAttribute().equals("ns")) {
            this.addAttributeNamespace(current, currentPath, newPath, type, NodeType.NAME_SPACE, defaultValue);
        } else {
            temp = this.addElement(current, currentPath, newPath, type, NodeType.ELEMENT, node.getOrder());
            // if root node is loop
            if (rootNode == null) {
                rootNode = temp;
            }
            if (node.getAttribute().equals("main")) {
                temp.setMain(true);
                mainNode = temp;
                mainPath = newPath;
            }
            if (isFirst) {
                temp.setLoop(true);
                loopNode = temp;
                isFirst = false;
            }
            current = temp;
            currentPath = newPath;
        }
    }
    if (rootNode != null) {
        schemaNode.getChildren().add(rootNode);
    }
    if (loopNode != null) {
        fillGroup(loopNode, groupElements);
    }
}
Also used : XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) EList(org.eclipse.emf.common.util.EList) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)

Example 17 with TreeNode

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

the class ImportTreeFromRepository method prepareModelFromOutput.

private void prepareModelFromOutput(List<FOXTreeNode> foxTreeNodes, TreeNode parent) {
    TreeNode realParent = XmlMapUtil.getRealParentNode(parent);
    for (FOXTreeNode foxNode : foxTreeNodes) {
        TreeNode createTreeNode = createModel();
        createTreeNode.setOptional(foxNode.isOptional());
        String label = foxNode.getLabel();
        createTreeNode.setName(label);
        if (foxNode instanceof Element) {
            createTreeNode.setNodeType(NodeType.ELEMENT);
            if (foxNode.isChoice()) {
                createTreeNode.setChoice(foxNode.isChoice());
            } else if (foxNode.isSubstitution()) {
                createTreeNode.setSubstitution(foxNode.isSubstitution());
            }
        } else if (foxNode instanceof Attribute) {
            createTreeNode.setNodeType(NodeType.ATTRIBUT);
        } else if (foxNode instanceof NameSpaceNode) {
            createTreeNode.setNodeType(NodeType.NAME_SPACE);
            createTreeNode.setDefaultValue(foxNode.getDefaultValue());
            if (createTreeNode.getName() == null || createTreeNode.getName().equals("")) {
                createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
            }
        }
        String xPath = XmlMapUtil.getXPath(realParent.getXpath(), label, createTreeNode.getNodeType());
        createTreeNode.setXpath(xPath);
        if (createTreeNode.isSubstitution() || createTreeNode.isChoice()) {
            if (isMappedChoiceSubsOutput(foxNode, realParent.getXpath())) {
                parent.getChildren().add(createTreeNode);
            }
        } else {
            String subXpath = xPath.substring(schemaNode.getXpath().length() + 1, xPath.length());
            XMLFileNode found = findXmlFileNode(subXpath, root);
            if (found == null) {
                found = findXmlFileNode(subXpath, group);
                if (found != null) {
                    groupElements.add(createTreeNode);
                }
            }
            if (found == null) {
                found = findXmlFileNode(subXpath, loop);
                if (found != null) {
                    if (loopNode == null) {
                        loopNode = createTreeNode;
                        loopNode.setLoop(true);
                        loopNode.setOptional(foxNode.isOptional());
                    }
                }
            }
            if (found == null) {
                continue;
            } else {
                String dataType = found.getType();
                if (dataType == null || dataType.equals("")) {
                    dataType = foxNode.getDataType();
                }
                if (dataType != null && !"".equals(dataType)) {
                    if (dataType.equals("id_Date")) {
                        //$NON-NLS-1$
                        createTreeNode.setPattern("\"dd-MM-yyyy\"");
                    }
                    createTreeNode.setType(dataType);
                } else {
                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                }
                addChildInOrder(parent, createTreeNode, found.getOrder());
            }
        }
        prepareModelFromOutput(foxNode.getChildren(), createTreeNode);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 18 with TreeNode

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

the class ImportTreeFromRepository method prepareEmfTree.

private void prepareEmfTree(List<FOXTreeNode> list, TreeNode parent, boolean ignoreMapped) {
    if (list == null || list.isEmpty()) {
        return;
    }
    String xPath = parent.getXpath();
    TreeNode realParentNode = parent;
    if (parent.isSubstitution() || parent.isChoice()) {
        realParentNode = XmlMapUtil.getRealParentNode(parent);
        if (realParentNode != null) {
            xPath = realParentNode.getXpath();
        }
    }
    for (FOXTreeNode foxNode : list) {
        TreeNode createTreeNode = createModel();
        createTreeNode.setOptional(foxNode.isOptional());
        String label = foxNode.getLabel();
        createTreeNode.setName(label);
        if (foxNode instanceof Element) {
            createTreeNode.setNodeType(NodeType.ELEMENT);
            if (foxNode.isChoice()) {
                createTreeNode.setChoice(foxNode.isChoice());
            } else if (foxNode.isSubstitution()) {
                createTreeNode.setSubstitution(foxNode.isSubstitution());
            }
        } else if (foxNode instanceof Attribute) {
            createTreeNode.setNodeType(NodeType.ATTRIBUT);
        } else if (foxNode instanceof NameSpaceNode) {
            createTreeNode.setNodeType(NodeType.NAME_SPACE);
            createTreeNode.setDefaultValue(foxNode.getDefaultValue());
            if (createTreeNode.getName() == null || createTreeNode.getName().equals("")) {
                createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
            }
        }
        createTreeNode.setXpath(XmlMapUtil.getXPath(xPath, label, createTreeNode.getNodeType()));
        // tempXpath is current xpath remove schema node xpath like: row1:newColumn1
        String tempXpath = createTreeNode.getXpath().substring(schemaNode.getXpath().length() + 1);
        if (createTreeNode.isChoice() || createTreeNode.isSubstitution()) {
            if (!isMappedChoiceSubs(foxNode, xPath)) {
                continue;
            }
        } else if (!ignoreMapped && !isMappedChild(tempXpath)) {
            continue;
        }
        // get talend type from metadata table
        String dataType = null;
        if (targetAbsolutePath != null) {
            dataType = targetAbsolutePath.get(tempXpath);
        }
        if (dataType == null) {
            dataType = foxNode.getDataType();
        }
        if (dataType != null && !"".equals(dataType)) {
            if (dataType.equals("id_Date")) {
                String datePattern = targetDatePattern.get(tempXpath);
                if (datePattern == null || "".equals(datePattern)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    datePattern = "\"dd-MM-yyyy\"";
                }
                createTreeNode.setPattern(datePattern);
            }
            createTreeNode.setType(dataType);
        } else {
            createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
        }
        if (tempXpath.equals(absoluteXPathQuery)) {
            createTreeNode.setLoop(true);
            createTreeNode.setOptional(foxNode.isOptional());
            loopNode = createTreeNode;
        }
        parent.getChildren().add(createTreeNode);
        if (createTreeNode.isLoop()) {
            XmlMapUtil.upsetMainNode(createTreeNode);
        }
        if (foxNode.getChildren() != null && !foxNode.getChildren().isEmpty()) {
            prepareEmfTree(foxNode.getChildren(), createTreeNode, ignoreMapped);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 19 with TreeNode

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

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

the class CreateDocChildrenCommand method execute.

@Override
public void execute() {
    // only drop output can create a new node now
    OutputTreeNode targetOutputNode = (OutputTreeNode) targetEditPart.getModel();
    String expression = "";
    if (objects.getToTransfer() != null) {
        for (Object obj : objects.getToTransfer()) {
            OutputTreeNode createdNode = (OutputTreeNode) rq.getNewObject();
            AbstractNode source = null;
            if (objects.getType() == TransferdType.INPUT) {
                TreeNodeEditPart part = (TreeNodeEditPart) obj;
                TreeNode sourceNode = (TreeNode) part.getModel();
                source = sourceNode;
                createdNode.setName(sourceNode.getName());
                createdNode.setType(sourceNode.getType());
                createdNode.setPattern(sourceNode.getPattern());
                expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
                createdNode.setExpression(expression);
                // INPUT => OUTPUT
                if (createdNode instanceof OutputTreeNode) {
                    if (NodeType.NAME_SPACE.equals(sourceNode.getNodeType())) {
                        // namespace and only be droped as namespace
                        createdNode.setDefaultValue(sourceNode.getDefaultValue());
                    }
                    createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
                    createdNode.setExpression(XmlMapUtil.convertToExpression(sourceNode.getXpath()));
                    EList<TreeNode> sourceChildren = sourceNode.getChildren();
                    if (!sourceChildren.isEmpty()) {
                        // children must be attribute or namespace
                        for (TreeNode child : sourceChildren) {
                            OutputTreeNode childTarget = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                            childTarget.setName(child.getName());
                            childTarget.setType(child.getType());
                            childTarget.setPattern(child.getPattern());
                            childTarget.setNodeType(child.getNodeType());
                            childTarget.setXpath(XmlMapUtil.getXPath(createdNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
                            createdNode.getChildren().add(childTarget);
                            if (NodeType.NAME_SPACE.equals(child.getNodeType())) {
                                childTarget.setDefaultValue(child.getDefaultValue());
                                // default value is already set as from source , no need the expression to get
                                // default value
                                childTarget.setExpression("");
                            } else {
                                childTarget.setExpression(XmlMapUtil.convertToExpression(child.getXpath()));
                                createConnection(child, childTarget);
                            }
                        }
                    }
                // disable function of add source loop to target InputLoopNodesTable
                // InputLoopTableUtil
                // .addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, manager.getMainInputTree());
                }
            } else if (objects.getType() == TransferdType.VAR) {
                // VARE ==>OUTPUT
                VarNodeEditPart part = (VarNodeEditPart) obj;
                VarNode sourceNode = (VarNode) part.getModel();
                source = sourceNode;
                String variable = sourceNode.getName();
                createdNode.setName(variable);
                createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
                if (sourceNode.eContainer() instanceof VarTable) {
                    VarTable container = (VarTable) sourceNode.eContainer();
                    variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
                }
                createdNode.setExpression(variable);
            }
            targetOutputNode.getChildren().add(createdNode);
            createConnection(source, createdNode);
            if (!XmlMapUtil.isExpressionEditable(targetOutputNode)) {
                targetOutputNode.setExpression("");
                if (targetOutputNode.isAggregate()) {
                    targetOutputNode.setAggregate(false);
                }
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) 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) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

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