use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class InsertNewColumnCommand method createOutputMetadataColumn.
private void createOutputMetadataColumn(String sourceTreeName, String targetTreeName, AbstractNode sourceNode, String targetNodeName, int index) {
String sourceNodeName = sourceNode.getName();
IMetadataTable metadataTarget = null;
List<IMetadataTable> metadataTargets = manager.getMapperComponent().getMetadataList();
if (metadataTargets != null) {
for (IMetadataTable target : metadataTargets) {
if (target.getTableName().equals(targetTreeName)) {
metadataTarget = target;
}
}
}
if (metadataTarget != null) {
IMetadataColumn columnSource = null;
if (sourceTreeName != null) {
columnSource = getSourceColumn(sourceTreeName, sourceNodeName);
}
creatMeatadataColumn(columnSource, targetNodeName, sourceNode, metadataTarget, index);
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildInputTree.
public void rebuildInputTree(InputXmlTree inputTree, IMetadataTable metadataTable, XmlMapData mapData) {
if (metadataTable != null && metadataTable.getListColumns() != null) {
List<IMetadataColumn> listColumns = metadataTable.getListColumns();
EList<TreeNode> nodes = inputTree.getNodes();
for (int i = 0; i < listColumns.size(); i++) {
IMetadataColumn column = listColumns.get(i);
TreeNode found = null;
int j = 0;
for (; j < nodes.size(); j++) {
TreeNode 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
TreeNode temp = nodes.get(j);
nodes.remove(j);
nodes.add(i, temp);
}
} else {
found = XmlmapFactory.eINSTANCE.createTreeNode();
found.setName(column.getLabel());
found.setType(column.getTalendType());
found.setNullable(column.isNullable());
found.setXpath(XmlMapUtil.getXPath(inputTree.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 type is changed from a non-document to document
if (children.isEmpty()) {
XmlMapUtil.detachNodeConnections(found, mapData, true);
TreeNode treeRoot = XmlmapFactory.eINSTANCE.createTreeNode();
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);
List<TreeNode> copyOfChildren = new ArrayList<TreeNode>(found.getChildren());
found.getChildren().clear();
if (!inputTree.isLookup() && inputTree.isMultiLoops()) {
List<TreeNode> oldLoops = new ArrayList<TreeNode>();
XmlMapUtil.getChildLoops(oldLoops, copyOfChildren);
inputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(inputTree));
XmlMapUtil.removeloopInOutputTree(mapData, inputTree, oldLoops);
}
}
}
}
if (nodes.size() > listColumns.size()) {
List unUsed = new ArrayList();
for (int i = listColumns.size(); i < nodes.size(); i++) {
XmlMapUtil.detachNodeConnections(nodes.get(i), mapData, true);
unUsed.add(nodes.get(i));
}
nodes.removeAll(unUsed);
}
}
// be deleted
if (inputTree.isLookup()) {
rebuildInputNodesConnections(inputTree.getNodes(), mapData);
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class Connection method initTraceFilterParameters.
/**
* just keep this method in case we need it again in some day, or we can delete it dirrectly, since it is never
* used.
*/
private void initTraceFilterParameters() {
List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
IMetadataTable metadataTable = this.getMetadataTable();
if (metadataTable != null) {
for (IMetadataColumn metaColumn : metadataTable.getListColumns()) {
Map<String, Object> line = new HashMap<String, Object>();
line.put(IConnection.TRACE_SCHEMA_COLUMN, metaColumn.getLabel());
line.put(IConnection.TRACE_SCHEMA_COLUMN_CHECKED, true);
line.put(IConnection.TRACE_SCHEMA_COLUMN_CONDITION, null);
values.add(line);
}
}
if (getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()) != null && values != null) {
getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()).setValue(values);
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class JavaSampleCodeFactory method generateJavaRowCode.
/**
*
* DOC YeXiaowei Comment method "generateJavaRowCode". Generates Java code for the tJavaRow component in DI and BD.
*
* @param node
* @return
*/
private String generateJavaRowCode(final Node node) {
boolean isSparkNode = false;
//$NON-NLS-1$
String sparkMapType = "MAP";
ComponentCategory componentCategory = ComponentCategory.getComponentCategoryFromName(node.getComponent().getType());
String primeVlue = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"// code sample:\r\n" + "//\r\n" + "// multiply by 2 the row identifier\r\n" + "// output_row.id = input_row.id * 2;\r\n" + "//\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"// lowercase the name\r\n" + //$NON-NLS-1$
"// output_row.name = input_row.name.toLowerCase();";
if (ComponentCategory.CATEGORY_4_SPARK == componentCategory || ComponentCategory.CATEGORY_4_SPARKSTREAMING == componentCategory) {
isSparkNode = true;
//$NON-NLS-1$
sparkMapType = node.getPropertyValue("MAPTYPE").toString();
//$NON-NLS-1$
primeVlue = "// Please add an input to the component to generate a sample code\r\n";
}
if (node.getMetadataList() == null || node.getMetadataList().get(0) == null) {
return primeVlue;
}
if (node.getIncomingConnections() == null || node.getIncomingConnections().isEmpty() || node.getIncomingConnections().get(0).getMetadataTable() == null) {
return primeVlue;
}
IMetadataTable inputTable = node.getIncomingConnections().get(0).getMetadataTable();
List<IMetadataColumn> inputColumns = inputTable.getListColumns();
IMetadataTable outputTable = node.getMetadataList().get(0);
List<IMetadataColumn> outputColumns = outputTable.getListColumns();
if (inputColumns == null || inputColumns.isEmpty() || outputColumns == null || outputColumns.isEmpty()) {
return primeVlue;
}
//$NON-NLS-1$
String javaEnding = ";";
//$NON-NLS-1$
String lineSeparator = System.getProperty("line.separator");
StringBuilder builder = new StringBuilder();
//$NON-NLS-1$
boolean isSelect = MessageDialog.openQuestion(null, null, Messages.getString("JavaSampleCodeFactory.askRegenerateCode"));
if (isSelect) {
// Add simple comment
//$NON-NLS-1$
builder.append(Messages.getString("JavaSampleCodeFactory.schema")).append(lineSeparator);
int inputRowsLength = inputColumns.size();
int ouputRowsLength = outputColumns.size();
if (inputRowsLength == 0 || ouputRowsLength == 0) {
return null;
}
if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
//$NON-NLS-1$
//$NON-NLS-1$
builder.append("Output output = new Output();\r\n");
}
if (inputRowsLength >= ouputRowsLength) {
for (int i = 0; i < inputRowsLength; i++) {
String inputLabel = inputColumns.get(i).getLabel();
String outputLabel = null;
if (i > ouputRowsLength - 1) {
outputLabel = outputColumns.get(ouputRowsLength - 1).getLabel();
} else {
outputLabel = outputColumns.get(i).getLabel();
}
if (isSparkNode) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
} else {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
}
builder.append(lineSeparator);
}
} else {
for (int i = 0; i < ouputRowsLength; i++) {
String outputLabel = outputColumns.get(i).getLabel();
String inputLabel = null;
if (i > inputRowsLength - 1) {
inputLabel = inputColumns.get(inputRowsLength - 1).getLabel();
} else {
inputLabel = inputColumns.get(i).getLabel();
}
if (isSparkNode) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output.").append(outputLabel).append(" = ").append("input.").append(inputLabel).append(javaEnding);
} else {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append("output_row.").append(outputLabel).append(" = ").append("input_row.").append(inputLabel).append(javaEnding);
}
builder.append(lineSeparator);
}
}
if (isSparkNode && (sparkMapType.equalsIgnoreCase("FLATMAP"))) {
//$NON-NLS-1$
//$NON-NLS-1$
builder.append("outputList.add(output);\r\n");
}
return builder.toString();
} else {
return null;
}
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class ParallelExecutionUtils method copyTable.
public static void copyTable(IMetadataTable source, IMetadataTable target) {
if (source == null || target == null) {
return;
}
List<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
List<String> readOnlycolumns = new ArrayList<String>();
for (IMetadataColumn column : target.getListColumns(true)) {
if (!column.isCustom()) {
columnsToRemove.add(column);
}
if (column.isReadOnly()) {
readOnlycolumns.add(column.getLabel());
}
}
target.getListColumns().removeAll(columnsToRemove);
target.getListUnusedColumns().removeAll(columnsToRemove);
List<IMetadataColumn> columnsTAdd = new ArrayList<IMetadataColumn>();
for (IMetadataColumn column : source.getListColumns(true)) {
IMetadataColumn targetColumn = target.getColumn(column.getLabel());
IMetadataColumn newTargetColumn = column.clone();
if (targetColumn == null) {
columnsTAdd.add(newTargetColumn);
newTargetColumn.setReadOnly(target.isReadOnly() || readOnlycolumns.contains(newTargetColumn.getLabel()));
} else {
if (!targetColumn.isReadOnly()) {
target.getListColumns().remove(targetColumn);
newTargetColumn.setCustom(targetColumn.isCustom());
newTargetColumn.setCustomId(targetColumn.getCustomId());
columnsTAdd.add(newTargetColumn);
}
}
}
target.getListColumns().addAll(columnsTAdd);
target.sortCustomColumns();
target.setLabel(source.getLabel());
}
Aggregations