use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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]"));
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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();
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree 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;
}
Aggregations