use of org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData in project tdi-studio-se by Talend.
the class XmlMapComponent method renameMetadataColumnName.
@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
List<AbstractInOutTree> abstractTrees = new ArrayList<AbstractInOutTree>();
XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
abstractTrees.addAll(externalEmfData.getInputTrees());
abstractTrees.addAll(externalEmfData.getOutputTrees());
for (AbstractInOutTree abstractTree : abstractTrees) {
if (abstractTree.getName() != null && abstractTree.getName().equals(conectionName)) {
List<TreeNode> children = new ArrayList<TreeNode>();
if (abstractTree instanceof InputXmlTree) {
children.addAll(((InputXmlTree) abstractTree).getNodes());
} else {
children.addAll(((OutputXmlTree) abstractTree).getNodes());
}
for (TreeNode treeNode : children) {
if (treeNode.getName() != null && treeNode.getName().equals(oldColumnName) && !oldColumnName.equals(newColumnName)) {
treeNode.setName(newColumnName);
XmlMapUtil.updateXPathAndExpression(externalEmfData, expressionManager, treeNode, newColumnName, 2, true);
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData in project tdi-studio-se by Talend.
the class XmlMapComponent method checkNeededRoutines.
@Override
public List<String> checkNeededRoutines(List<String> possibleRoutines, String additionalString) {
List<String> routinesToAdd = new ArrayList<String>();
XmlMapData xmlMapData = (XmlMapData) getExternalEmfData();
for (String routine : possibleRoutines) {
List<OutputXmlTree> listOutput = xmlMapData.getOutputTrees();
for (OutputXmlTree outTable : listOutput) {
List<OutputTreeNode> listOutEntry = outTable.getNodes();
if (listOutEntry != null && !listOutEntry.isEmpty()) {
for (OutputTreeNode outEntry : listOutEntry) {
String expression = outEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
String filter = outTable.getExpressionFilter();
if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
List<InputXmlTree> listInput = xmlMapData.getInputTrees();
for (InputXmlTree inputTable : listInput) {
List<TreeNode> listInEntry = inputTable.getNodes();
if (listInEntry != null && !listInEntry.isEmpty()) {
for (TreeNode inEntry : listInEntry) {
String expression = inEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
String filter = inputTable.getExpressionFilter();
if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
List<VarTable> listVar = xmlMapData.getVarTables();
for (VarTable varTable : listVar) {
List<VarNode> listVarEntry = varTable.getNodes();
if (listVarEntry != null && !listVarEntry.isEmpty()) {
for (VarNode varEntry : listVarEntry) {
String expression = varEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
return routinesToAdd;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData in project tdi-studio-se by Talend.
the class XmlMapComponent method renameInputConnection.
@Override
public void renameInputConnection(String oldName, String newName) {
XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
if (inputTree.getName() != null && inputTree.getName().equals(oldName) && !oldName.equals(newName)) {
inputTree.setName(newName);
XmlMapUtil.updateXPathAndExpression(externalEmfData, expressionManager, inputTree.getNodes(), inputTree.getName(), 1);
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData in project tdi-studio-se by Talend.
the class XmlMapComponent method connectionStatusChanged.
@Override
public void connectionStatusChanged(EConnectionType newValue, String connectionToApply) {
XmlMapData externalEmfData = (XmlMapData) getExternalEmfData();
InputXmlTree mainTable = null;
InputXmlTree oldmainTable = null;
for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
if (!inputTree.isLookup()) {
oldmainTable = inputTree;
break;
}
}
for (InputXmlTree inputTree : externalEmfData.getInputTrees()) {
if (inputTree.getName() != null && inputTree.getName().equals(connectionToApply)) {
boolean value = EConnectionType.FLOW_MAIN != newValue;
inputTree.setLookup(value);
if (!value) {
mainTable = inputTree;
}
} else if (EConnectionType.FLOW_MAIN == newValue) {
inputTree.setLookup(true);
}
}
// put the main table to the first place
if (mainTable != null) {
externalEmfData.getInputTrees().remove(mainTable);
externalEmfData.getInputTrees().add(0, mainTable);
}
if (oldmainTable != null && oldmainTable != mainTable) {
boolean checkMultiLoopsStatus = XmlMapUtil.checkMultiLoopsStatus(oldmainTable);
if (checkMultiLoopsStatus) {
MessageDialog.openInformation(null, "Information", "Multiple loops in previous main table will be lost in tXmlMap");
// multipleloops status of the new main table will be false ,clean the InputLoopNodesTables for
// output will be ok
XmlMapUtil.removeloopInOutputTree(externalEmfData, mainTable, new ArrayList<TreeNode>());
// clean multipleloops and only keep the first loop of doc
for (TreeNode treeNode : oldmainTable.getNodes()) {
if (XmlMapUtil.DOCUMENT.equals(treeNode.getType())) {
List<TreeNode> oldLoops = new ArrayList<TreeNode>();
XmlMapUtil.getChildLoops(oldLoops, treeNode.getChildren());
if (oldLoops.size() > 1) {
for (int i = 1; i < oldLoops.size(); i++) {
oldLoops.get(i).setLoop(false);
}
}
}
}
oldmainTable.setMultiLoops(false);
}
}
initMapperMain();
mapperMain.getMapperManager().getProblemsAnalyser().checkProblems();
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData 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]"));
}
Aggregations