Search in sources :

Example 1 with XmlMapConnectionBuilder

use of org.talend.designer.xmlmap.util.XmlMapConnectionBuilder 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 2 with XmlMapConnectionBuilder

use of org.talend.designer.xmlmap.util.XmlMapConnectionBuilder in project tdi-studio-se by Talend.

the class XmlMapService method externalEmfDataClone.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.core.service.IXmlMapService#externalEmfDataClone(org.talend.designer.core.model.utils.emf.talendfile
     * .AbstractExternalData)
     */
@Override
public AbstractExternalData externalEmfDataClone(AbstractExternalData externalEmfData) {
    if (!(externalEmfData instanceof XmlMapData)) {
        return externalEmfData;
    }
    Map<EObject, EObject> nodeMaps = new HashMap<EObject, EObject>();
    XmlMapData newXmlMapData = XmlmapFactory.eINSTANCE.createXmlMapData();
    XmlMapData xmlMapData = (XmlMapData) externalEmfData;
    EList<InputXmlTree> oriInputs = xmlMapData.getInputTrees();
    EList<OutputXmlTree> oriOutputs = xmlMapData.getOutputTrees();
    EList<VarTable> oriVars = xmlMapData.getVarTables();
    EList<IConnection> oriConns = xmlMapData.getConnections();
    for (IConnection oriConn : oriConns) {
        if (oriConn instanceof INodeConnection) {
            AbstractNode sourceNode = ((INodeConnection) oriConn).getSource();
            AbstractNode targetNode = ((INodeConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            if (oriConn instanceof Connection) {
                new XmlMapConnectionBuilder().createConnection((AbstractNode) source, (AbstractNode) target, newXmlMapData);
            } else if (oriConn instanceof LookupConnection) {
                new XmlMapConnectionBuilder().createLookupConnection((TreeNode) source, (TreeNode) target, newXmlMapData);
            }
        } else if (oriConn instanceof FilterConnection) {
            AbstractNode sourceNode = ((FilterConnection) oriConn).getSource();
            AbstractInOutTree targetNode = ((FilterConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            new XmlMapConnectionBuilder().createFilterConnection((AbstractNode) source, (AbstractInOutTree) target, newXmlMapData);
        }
    }
    for (InputXmlTree inputXml : oriInputs) {
        InputXmlTree newInputXml = null;
        if (nodeMaps.get(inputXml) == null) {
            newInputXml = (InputXmlTree) cloneTreeNode(inputXml);
        } else {
            newInputXml = (InputXmlTree) nodeMaps.get(inputXml);
        }
        if (inputXml.getNodes() != null) {
            for (TreeNode treeNode : inputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newInputXml.getNodes().contains(obj)) {
                    newInputXml.getNodes().add((TreeNode) obj);
                }
            }
        }
        if (!newXmlMapData.getInputTrees().contains(newInputXml)) {
            newXmlMapData.getInputTrees().add(newInputXml);
        }
        nodeMaps.put(inputXml, newInputXml);
    }
    for (OutputXmlTree outputXml : oriOutputs) {
        OutputXmlTree newOutputXml = null;
        if (nodeMaps.get(outputXml) == null) {
            newOutputXml = (OutputXmlTree) cloneTreeNode(outputXml);
        } else {
            newOutputXml = (OutputXmlTree) nodeMaps.get(outputXml);
        }
        if (outputXml.getNodes() != null) {
            for (OutputTreeNode treeNode : outputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newOutputXml.getNodes().contains(obj)) {
                    newOutputXml.getNodes().add((OutputTreeNode) obj);
                }
            }
        }
        // }
        if (!newXmlMapData.getOutputTrees().contains(newOutputXml)) {
            newXmlMapData.getOutputTrees().add(newOutputXml);
        }
        nodeMaps.put(outputXml, newOutputXml);
    }
    for (VarTable varXml : oriVars) {
        VarTable newVarXml = null;
        if (nodeMaps.get(varXml) == null) {
            newVarXml = XmlmapFactory.eINSTANCE.createVarTable();
            newVarXml.setMinimized(varXml.isMinimized());
            newVarXml.setName(varXml.getName());
            if (varXml.getNodes() != null) {
                for (VarNode treeNode : varXml.getNodes()) {
                    EObject obj = nodeMaps.get(treeNode);
                    if (obj != null) {
                        newVarXml.getNodes().add((VarNode) obj);
                    }
                }
            }
            if (!newXmlMapData.getVarTables().contains(newVarXml)) {
                newXmlMapData.getVarTables().add(newVarXml);
            }
            nodeMaps.put(varXml, newVarXml);
        }
    }
    return newXmlMapData;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) HashMap(java.util.HashMap) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EObject(org.eclipse.emf.ecore.EObject) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 3 with XmlMapConnectionBuilder

use of org.talend.designer.xmlmap.util.XmlMapConnectionBuilder in project tdi-studio-se by Talend.

the class ImportTreeFromXml method run.

@Override
public void run() {
    List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    FileDialog f = new FileDialog(shell);
    String file = f.open();
    if (file != null) {
        boolean clickOk = false;
        TreeNode treeNodeRoot = null;
        String detailedMessage = "";
        try {
            clickOk = TreeUtil.getFoxTreeNodesForXmlMap(file, shell, list);
            if (!clickOk) {
                return;
            }
            treeNodeRoot = XmlMapUtil.getTreeNodeRoot(parentNode);
            XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
            parentNode.getChildren().clear();
            prepareEmfTreeNode(list, parentNode);
        } 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 (parentNode.getChildren().isEmpty()) {
            childrenEmpty = true;
            TreeNode rootNode = null;
            if (input) {
                rootNode = XmlmapFactory.eINSTANCE.createTreeNode();
            } else {
                rootNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
            }
            rootNode.setName("root");
            rootNode.setNodeType(NodeType.ELEMENT);
            rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            rootNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), "root", NodeType.ELEMENT));
            parentNode.getChildren().add(rootNode);
        }
        // set a default loop
        parentNode.getChildren().get(0).setLoop(true);
        parentNode.getChildren().get(0).setMain(true);
        if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
            showError(detailedMessage);
        }
        if (parentNode.eContainer() instanceof InputXmlTree) {
            XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
            connectionBuilder.setCheckRootNodePrefix(true);
            connectionBuilder.rebuildLinks(parentNode, mapperManager.getExternalData());
            mapperManager.refreshTreeSchemaEditor((InputXmlTree) parentNode.eContainer());
        // mapperManager.inputTreeSchemaBeanListModified();
        } else if (parentNode.eContainer() instanceof OutputXmlTree) {
            mapperManager.refreshTreeSchemaEditor((OutputXmlTree) parentNode.eContainer());
        // mapperManager.outputTreeSchemaBeanListModified();
        }
        if (treeNodeRoot != null && treeNodeRoot.eContainer() instanceof AbstractInOutTree) {
            mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) treeNodeRoot.eContainer());
            mapperManager.getMapperUI().updateStatusBar();
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)3 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 XmlMapConnectionBuilder (org.talend.designer.xmlmap.util.XmlMapConnectionBuilder)3 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EObject (org.eclipse.emf.ecore.EObject)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 MDMConnection (org.talend.core.model.metadata.builder.connection.MDMConnection)1 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)1 Item (org.talend.core.model.properties.Item)1 MDMConnectionItem (org.talend.core.model.properties.MDMConnectionItem)1 XmlFileConnectionItem (org.talend.core.model.properties.XmlFileConnectionItem)1 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)1 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)1