Search in sources :

Example 1 with SchemaTarget

use of org.talend.core.model.metadata.builder.connection.SchemaTarget in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method isMappedChild.

private boolean isMappedChild(String tempXpath) {
    if (targetAbsolutePath == null) {
        targetAbsolutePath = new HashMap<String, String>();
        targetDatePattern = new HashMap<String, String>();
        targetAbsolutePath.put(absoluteXPathQuery, null);
        Pattern regex = Pattern.compile(RELATIVE_PATH_PATTERN, Pattern.CANON_EQ | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
        for (int n = 0; n < schemaTargets.size(); n++) {
            Object obj = schemaTargets.get(n);
            String relativeXPathQuery = "";
            if (obj instanceof SchemaTarget) {
                relativeXPathQuery = ((SchemaTarget) obj).getRelativeXPathQuery();
            } else if (obj instanceof ConceptTarget) {
                relativeXPathQuery = ((ConceptTarget) obj).getRelativeLoopExpression();
            }
            StringBuffer tempAbsolute = new StringBuffer();
            tempAbsolute.append(absoluteXPathQuery);
            tempAbsolute.append(XmlMapUtil.XPATH_SEPARATOR);
            tempAbsolute.append(relativeXPathQuery);
            if (relativeXPathQuery.startsWith(RELATIVE_PATH)) {
                Matcher regexMatcher = regex.matcher(relativeXPathQuery);
                int relativeLength = 0;
                while (regexMatcher.find()) {
                    relativeLength++;
                }
                if (relativeLength > 0) {
                    String subRelativeQuery = relativeXPathQuery.substring(relativeLength * RELATIVE_PATH.length(), relativeXPathQuery.length());
                    String[] absoluteSplit = absoluteXPathQuery.split(XmlMapUtil.XPATH_SEPARATOR);
                    if (absoluteSplit.length > relativeLength) {
                        tempAbsolute = new StringBuffer();
                        for (int i = 0; i < absoluteSplit.length - relativeLength; i++) {
                            tempAbsolute.append(absoluteSplit[i]);
                            tempAbsolute.append(XmlMapUtil.XPATH_SEPARATOR);
                        }
                        tempAbsolute.append(subRelativeQuery);
                    }
                }
            }
            if (metadataTable != null && n < metadataTable.getColumns().size()) {
                MetadataColumn column = metadataTable.getColumns().get(n);
                targetAbsolutePath.put(tempAbsolute.toString(), column.getTalendType());
                targetDatePattern.put(tempAbsolute.toString(), column.getPattern());
            } else {
                targetAbsolutePath.put(tempAbsolute.toString(), null);
                targetDatePattern.put(tempAbsolute.toString(), null);
            }
        }
    }
    for (String absTarget : targetAbsolutePath.keySet()) {
        if (absTarget.startsWith(tempXpath)) {
            return true;
        }
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Matcher(java.util.regex.Matcher) EObject(org.eclipse.emf.ecore.EObject) SchemaTarget(org.talend.core.model.metadata.builder.connection.SchemaTarget) ConceptTarget(org.talend.core.model.metadata.builder.connection.ConceptTarget)

Example 2 with SchemaTarget

use of org.talend.core.model.metadata.builder.connection.SchemaTarget in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method prepareEmfTreeFromXml.

private void prepareEmfTreeFromXml(XmlFileConnection connection) throws Exception {
    if (!connection.isInputModel()) {
        prepareEmfTreeFromConnection(connection);
    // String file = connection.getXmlFilePath();
    // List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    // // fix for TDI-20671 , root element is loop in output
    // String rootXpath = null;
    // if (!connection.getRoot().isEmpty()) {
    // rootXpath = connection.getRoot().get(0).getXMLPath();
    // } else if (!connection.getLoop().isEmpty()) {
    // rootXpath = connection.getLoop().get(0).getXMLPath();
    // }
    // File xmlFile = new File(file);
    // if (xmlFile.exists() && !file.endsWith(".zip")) {
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), rootXpath, true);
    // } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
    // String xsdFile = initFileContent(connection);
    // if (xsdFile != null && new File(xsdFile).exists()) {
    // String targetNameSpace = connection.getTargetNameSpace();
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, rootXpath, targetNameSpace, true);
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    //
    // }
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    // }
    // schemaNode.getChildren().clear();
    // root = connection.getRoot();
    // loop = connection.getLoop();
    // group = connection.getGroup();
    // groupElements = new ArrayList<TreeNode>();
    // prepareModelFromOutput(list, schemaNode);
    // if (loopNode != null) {
    // fillGroup(loopNode, groupElements);
    // } else {
    // if (!schemaNode.getChildren().isEmpty()) {
    // schemaNode.getChildren().get(0).setLoop(true);
    // }
    // }
    } else {
        List<SchemaTarget> schemaTargets = null;
        if (!connection.getSchema().isEmpty() && connection.getSchema().get(0) instanceof XmlXPathLoopDescriptorImpl) {
            absoluteXPathQuery = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getAbsoluteXPathQuery();
            schemaTargets = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getSchemaTargets();
            metadataTable = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
        }
        // fix for TDI-8707 : only import mapped elements from connection to xml map
        if (schemaTargets == null || schemaTargets.isEmpty()) {
            return;
        }
        this.schemaTargets = schemaTargets;
        String file = connection.getXmlFilePath();
        List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
        File xmlFile = new File(file);
        if (xmlFile.exists()) {
            list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), absoluteXPathQuery, true);
        } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
            String xsdFile = initFileContent(connection);
            if (xsdFile != null && new File(xsdFile).exists()) {
                list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, absoluteXPathQuery, true);
            }
        } else {
            throw new FileNotFoundException();
        }
        schemaNode.getChildren().clear();
        prepareEmfTree(list, schemaNode);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) XmlXPathLoopDescriptorImpl(org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl) SchemaTarget(org.talend.core.model.metadata.builder.connection.SchemaTarget) File(java.io.File)

Aggregations

SchemaTarget (org.talend.core.model.metadata.builder.connection.SchemaTarget)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EObject (org.eclipse.emf.ecore.EObject)1 ConceptTarget (org.talend.core.model.metadata.builder.connection.ConceptTarget)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 XmlXPathLoopDescriptorImpl (org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl)1 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)1