use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class DropContextAnalyzer method checkDropOutputDocChildValid.
private boolean checkDropOutputDocChildValid(Object targetModel) {
OutputTreeNode outputNode = (OutputTreeNode) targetModel;
NodeType nodeType = outputNode.getNodeType();
if (outputNode.eContainer() instanceof OutputTreeNode && nodeType != NodeType.ATTRIBUT && nodeType != NodeType.NAME_SPACE) {
dropType = DropType.DROP_OUTPUT_DOC_CHILD;
return true;
} else if (outputNode.eContainer() instanceof OutputXmlTree && !XmlMapUtil.DOCUMENT.equals(outputNode.getType())) {
dropType = DropType.DROP_INSERT_OUTPUT;
return true;
}
return false;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildModelOutputs.
public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, XmlMapData mapData) {
for (IMetadataTable meatadataTable : outputMetadataTables) {
String name = meatadataTable.getTableName();
OutputXmlTree outputTree = null;
for (OutputXmlTree out : mapData.getOutputTrees()) {
if (out.getName() != null && out.getName().equals(name)) {
outputTree = out;
break;
}
}
if (outputTree == null) {
outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputTree.setName(name);
mapData.getOutputTrees().add(outputTree);
}
List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
if (listColumns != null) {
EList<OutputTreeNode> nodes = outputTree.getNodes();
for (int i = 0; i < listColumns.size(); i++) {
IMetadataColumn column = listColumns.get(i);
OutputTreeNode found = null;
int j = 0;
for (; j < nodes.size(); j++) {
OutputTreeNode node = nodes.get(j);
if (node.getName() != null && node.getName().equals(column.getLabel())) {
found = node;
break;
}
}
if (found != null) {
// set in case talend type changed in metadata
found.setType(column.getTalendType());
if (i != j) {
// do switch to keep the same sequence
OutputTreeNode temp = nodes.get(j);
nodes.remove(j);
nodes.add(i, temp);
}
} else {
found = XmlmapFactory.eINSTANCE.createOutputTreeNode();
found.setName(column.getLabel());
found.setType(column.getTalendType());
found.setNullable(column.isNullable());
found.setXpath(XmlMapUtil.getXPath(outputTree.getName(), found.getName(), found.getNodeType()));
nodes.add(i, found);
}
// add a default root for document
if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
EList<TreeNode> children = found.getChildren();
if (children.isEmpty()) {
XmlMapUtil.detachConnectionsSouce(found, mapData);
TreeNode treeRoot = XmlmapFactory.eINSTANCE.createOutputTreeNode();
treeRoot.setName("root");
treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
treeRoot.setNodeType(NodeType.ELEMENT);
treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
treeRoot.setLoop(true);
treeRoot.setMain(true);
children.add(treeRoot);
}
} else // remove children and connections for children if not document
{
EList<TreeNode> children = found.getChildren();
if (!children.isEmpty()) {
XmlMapUtil.detachNodeConnections(found, mapData, true);
found.getChildren().clear();
}
}
}
if (nodes.size() > listColumns.size()) {
List unUsed = new ArrayList();
for (int i = listColumns.size(); i < nodes.size(); i++) {
OutputTreeNode node = nodes.get(i);
XmlMapUtil.detachConnectionsSouce(node, mapData);
unUsed.add(node);
}
nodes.removeAll(unUsed);
}
}
mapData.getOutputTrees().add(outputTree);
// re-build the connections in case any unnecessary connections are created because of previous bugs and
// can't be deleted
rebuildOutputNodesConnections(outputTree.getNodes(), mapData);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class XMLMapperHelper method hasAggregateColumn.
private static boolean hasAggregateColumn(final INode xmlMapperNode) {
boolean hasAggregateColumn = false;
List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
for (IConnection connection : outConnections) {
hNameToConnection.put(connection.getName(), connection);
}
for (OutputXmlTree outputTable : outputTables) {
String tableName = outputTable.getName();
IConnection connection = hNameToConnection.get(tableName);
if (connection == null) {
continue;
}
List<TreeNode> editableNodes = new ArrayList<TreeNode>();
for (TreeNode node : outputTable.getNodes()) {
getEditableNodes(node, editableNodes);
}
for (TreeNode node : editableNodes) {
if (((OutputTreeNode) node).isAggregate()) {
hasAggregateColumn = true;
break;
}
}
}
}
return hasAggregateColumn;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class XMLMapperHelper method hasMultiLoops.
private static boolean hasMultiLoops(final INode xmlMapperNode) {
boolean hasMultiLoops = false;
List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
for (IConnection connection : outConnections) {
hNameToConnection.put(connection.getName(), connection);
}
for (OutputXmlTree outputTable : outputTables) {
String tableName = outputTable.getName();
IConnection connection = hNameToConnection.get(tableName);
if (connection == null) {
continue;
}
if (outputTable.isMultiLoops()) {
hasMultiLoops = true;
break;
}
}
}
return hasMultiLoops;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.
the class XMLMapperHelper method hasAllInOne.
private static boolean hasAllInOne(final INode xmlMapperNode) {
boolean hasAllInOne = false;
List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
for (IConnection connection : outConnections) {
hNameToConnection.put(connection.getName(), connection);
}
for (OutputXmlTree outputTable : outputTables) {
String tableName = outputTable.getName();
IConnection connection = hNameToConnection.get(tableName);
if (connection == null) {
continue;
}
if (outputTable.isAllInOne()) {
hasAllInOne = true;
break;
}
}
}
return hasAllInOne;
}
Aggregations