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());
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class CompleteDropTargetListener method insertNewInOutEntryFromInputEntry.
private void insertNewInOutEntryFromInputEntry(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, // MetadataEditorEvent metadataEditorEvent,
ITableEntry tableEntrySource, IMetadataColumn metadataColumnDragged, String columnName) {
MetadataColumn metadataColumn = new MetadataColumn(metadataColumnDragged);
metadataColumn.setLabel(columnName);
metadataColumnsBeingAdded.add(metadataColumn);
// metadataEditorEvent.entries.add(metadataColumn);
sources.add(tableEntrySource);
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class CompleteDropTargetListener method drop.
// private void showInfos(DropTargetEvent event) {
// System.out.println(event);
// System.out.println("event.feedback=" + event.feedback);
// System.out.println("event.detail=" + event.detail);
// System.out.println("event.operations=" + event.operations);
//
// System.out.println("DND.DROP_DEFAULT=" + DND.DROP_DEFAULT);
// System.out.println("DND.DROP_COPY=" + DND.DROP_COPY);
// System.out.println("DND.DROP_MOVE=" + DND.DROP_MOVE);
// System.out.println("DND.DROP_LINK=" + DND.DROP_LINK);
// System.out.println("DND.DROP_TARGET_MOVE=" + DND.DROP_TARGET_MOVE);
// }
//
@Override
public void drop(DropTargetEvent event) {
super.drop(event);
retrieveInsertionIndicator().setVisible(false);
UIManager uiManager = getUiManager();
DraggedData draggedData = TableEntriesTransfer.getInstance().getDraggedData();
DropContextAnalyzer analyzer = analyzeDropTarget(event, draggedData);
// System.out.println("\n>>drop");
// System.out.println(event);
Point cursorPosition = new Point(event.x, event.y);
// int startInsertAtThisIndex = getItemIndexWhereInsertFromPosition(cursorPosition);
int startInsertAtThisIndex = TableUtils.getItemIndexWhereInsertFromPosition(draggableTable, cursorPosition);
IDbLanguage currentLanguage = getMapperManager().getCurrentLanguage();
DataMapTableView dataMapTableViewTarget = getMapperManager().retrieveDataMapTableView(draggableTable);
Zone zoneTarget = dataMapTableViewTarget.getZone();
uiManager.selectDataMapTableView(dataMapTableViewTarget, true, false);
MetadataTableEditorView metadataEditorView = getUiManager().getMetadataEditorView(dataMapTableViewTarget.getZone());
List<TransferableEntry> transferableEntryList = draggedData.getTransferableEntryList();
int currentIndex = startInsertAtThisIndex;
uiManager.clearLastCreatedInOutColumnEntries();
draggableTable.deselectAll();
ITableEntry currentEntryTarget = getEntryFromPosition(cursorPosition);
ArrayList<String> columnsBeingAdded = new ArrayList<String>();
ArrayList<Integer> columnIndicesToSelect = new ArrayList<Integer>();
ArrayList<ITableEntry> sourceEntriesOfEntriesBeingAdded = new ArrayList<ITableEntry>();
ArrayList<IMetadataColumn> metadataColumnsBeingAdded = new ArrayList<IMetadataColumn>();
boolean targetTableIsFiltersTable = analyzer.targetTableIsFiltersTable();
boolean atLeastOneEntryInserted = false;
boolean insertionEntryMode = analyzer.isInsertionEntryMode();
boolean mapEachSourceToNextTargets = analyzer.isMapOneToOneMode();
TableViewerCreator tableViewerCreatorTarget = null;
if (targetTableIsFiltersTable) {
if (analyzer.targetTableIsWhereFiltersTable()) {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForWhereFilters();
} else {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForOtherFilters();
}
} else {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForColumns();
}
// MapperDropCommand dropCommand = new MapperDropCommand();
// MetadataEditorEvent metadataEditorEvent = new MetadataEditorEvent(MetadataEditorEvent.TYPE.ADD);
ITableEntry lastEntryTarget = null;
for (TransferableEntry transferableEntry : transferableEntryList) {
ITableEntry tableEntrySource = transferableEntry.getTableEntrySource();
IMetadataColumn metadataColumnDragged = transferableEntry.getMetadataColumn();
Zone zoneSourceEntry = (Zone) transferableEntry.getZoneSourceEntry();
TableEntryLocation tableEntryLocationTarget = new TableEntryLocation(dataMapTableViewTarget.getDataMapTable().getName(), tableEntrySource.getName());
if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.INPUTS && tableEntrySource.getParentName().equals(tableEntryLocationTarget.tableName)) {
continue;
} else if (currentEntryTarget != null && !insertionEntryMode) {
modifyExistingEntry(uiManager, analyzer, currentLanguage, currentEntryTarget, columnIndicesToSelect, tableViewerCreatorTarget, lastEntryTarget, tableEntrySource, zoneSourceEntry);
} else {
String columnName = transferableEntry.getTableEntrySource().getName();
tableEntryLocationTarget = getMapperManager().findUniqueLocation(tableEntryLocationTarget, dataMapTableViewTarget.getDataMapTable());
columnName = tableEntryLocationTarget.columnName;
if (currentEntryTarget == null && analyzer.isMapOneToOneMode()) {
currentIndex = tableViewerCreatorTarget.getInputList().size();
columnIndicesToSelect.add(currentIndex);
}
if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.OUTPUTS) {
insertNewInOutEntryFromInputEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, metadataColumnDragged, columnName);
atLeastOneEntryInserted = true;
} else if (zoneSourceEntry == Zone.OUTPUTS && zoneTarget == Zone.OUTPUTS) {
insertOutpuEntryCopyToOtherOutput(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, metadataColumnDragged, columnName);
atLeastOneEntryInserted = true;
} else {
// throw new IllegalStateException("Drop case not found !");
}
columnsBeingAdded.add(columnName);
}
lastEntryTarget = currentEntryTarget;
if (mapEachSourceToNextTargets && currentEntryTarget != null) {
currentEntryTarget = getNextEntryTarget(currentEntryTarget, tableViewerCreatorTarget);
}
}
if (!atLeastOneEntryInserted) {
tableViewerCreatorTarget.getTableViewer().refresh();
} else {
updateExpressionsOfInsertedEntries(currentLanguage, metadataEditorView, currentIndex, sourceEntriesOfEntriesBeingAdded, targetTableIsFiltersTable, tableViewerCreatorTarget, // , metadataEditorEvent
metadataColumnsBeingAdded);
for (int i = currentIndex; i < currentIndex + sourceEntriesOfEntriesBeingAdded.size(); i++) {
columnIndicesToSelect.add(i);
}
}
dataMapTableViewTarget.resizeAtExpandedSize();
uiManager.unselectAllEntriesOfAllTables();
uiManager.refreshBackground(true, false);
if (metadataEditorView != null && !targetTableIsFiltersTable) {
metadataEditorView.getTableViewerCreator().getTableViewer().refresh();
}
int[] selection = ArrayUtils.toPrimitive(columnIndicesToSelect.toArray(new Integer[0]));
tableViewerCreatorTarget.getSelectionHelper().setSelection(selection);
ISelection iselection = tableViewerCreatorTarget.getTableViewer().getSelection();
List<ITableEntry> selectedEntries = uiManager.extractSelectedTableEntries(iselection);
uiManager.unselectAllOutputMetaDataEntries();
uiManager.unselectAllInputMetaDataEntries();
uiManager.parseAllExpressionsForAllTables();
getMapperManager().getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
getUiManager().refreshSqlExpression();
uiManager.selectLinks(dataMapTableViewTarget, selectedEntries, targetTableIsFiltersTable, true);
tableViewerCreatorTarget.getTable().setFocus();
uiManager.setDragging(false);
}
use of org.talend.core.model.metadata.IMetadataColumn in project tdi-studio-se by Talend.
the class CompleteDropTargetListener method insertNewOutputEntryFromVarEntry.
private void insertNewOutputEntryFromVarEntry(ArrayList<ITableEntry> sources, ArrayList<IMetadataColumn> metadataColumnsBeingAdded, ITableEntry tableEntrySource, String columnName) {
MetadataColumn metadataColumn = new MetadataColumn();
metadataColumn.setLabel(columnName);
metadataColumn.setTalendType(((VarTableEntry) tableEntrySource).getType());
metadataColumn.setNullable(((VarTableEntry) tableEntrySource).isNullable());
metadataColumnsBeingAdded.add(metadataColumn);
sources.add(tableEntrySource);
}
Aggregations