use of org.talend.core.model.metadata.builder.connection.ConceptTarget 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;
}
use of org.talend.core.model.metadata.builder.connection.ConceptTarget in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method prepareEmfTreeFromMdm.
private void prepareEmfTreeFromMdm(MDMConnection connection, String selectedConcept) throws Exception {
if (connection == null || selectedConcept == null) {
return;
}
EList<Concept> schemas = connection.getSchemas();
Concept selected = null;
for (int i = 0; i < schemas.size(); i++) {
Concept concept = schemas.get(i);
if (selectedConcept.equals(concept.getLabel())) {
selected = concept;
break;
}
}
if (selected != null) {
IMDMProviderService service = (IMDMProviderService) GlobalServiceRegister.getDefault().getService(IMDMProviderService.class);
if (service != null) {
boolean initConcepts = service.initConcepts(connection);
if (initConcepts) {
if (!MdmConceptType.OUTPUT.equals(selected.getConceptType())) {
String prefix = service.getXPathPrefixValue(selected);
prefix = TalendTextUtils.removeQuotes(prefix);
absoluteXPathQuery = selected.getLoopExpression();
EList<ConceptTarget> conceptTargets = selected.getConceptTargets();
if (conceptTargets == null || absoluteXPathQuery == null) {
return;
}
this.schemaTargets = conceptTargets;
// find corresponding metadata table
Set<MetadataTable> metadataTables = ConnectionHelper.getTables(connection);
for (MetadataTable table : metadataTables) {
if (selected.getLabel() != null && selected.getLabel().equals(table.getLabel())) {
metadataTable = table;
break;
}
}
List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), absoluteXPathQuery, true);
TreeNode pNode = schemaNode;
if (MdmConceptType.RECEIVE.equals(selected.getConceptType())) {
List<FOXTreeNode> updateNodesList = TreeUtil.parseMDMUpdateReport(shell, true);
schemaNode.getChildren().clear();
if (updateNodesList == null) {
if (prefix != null && !"".equals(prefix)) {
String[] preValues = prefix.split(XmlMapUtil.XPATH_SEPARATOR);
for (String value : preValues) {
if (!"".equals(value)) {
TreeNode createTreeNode = createModel();
createTreeNode.setName(value);
createTreeNode.setNodeType(NodeType.ELEMENT);
createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
createTreeNode.setXpath(XmlMapUtil.getXPath(pNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
pNode.getChildren().add(createTreeNode);
pNode = createTreeNode;
}
}
absoluteXPathQuery = prefix + absoluteXPathQuery;
}
} else {
//$NON-NLS-1$
TreeNode rootNode = createDefaultTreeNode(pNode, "exchange");
//$NON-NLS-1$
TreeNode reportNode = createDefaultTreeNode(rootNode, "report");
//$NON-NLS-1$
TreeNode itemNode = createDefaultTreeNode(rootNode, "item");
// parse the update content..
prepareEmfTree(updateNodesList, reportNode, true);
pNode = itemNode;
//$NON-NLS-1$
absoluteXPathQuery = "/exchange/item" + absoluteXPathQuery;
}
} else {
schemaNode.getChildren().clear();
}
prepareEmfTree(list, pNode);
} else {
List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), selected.getRoot().get(0).getXMLPath(), true);
schemaNode.getChildren().clear();
root = selected.getRoot();
loop = selected.getLoop();
group = selected.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);
}
}
}
}
}
}
}
Aggregations