use of org.talend.designer.dbmap.language.generation.MapExpressionParser in project tdi-studio-se by Talend.
the class PostgresGenerationManager method initExpression.
@Override
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = super.initExpression(component, dbMapEntry);
// String expression = dbMapEntry.getExpression();
if (expression != null) {
List<? extends IConnection> inputConnections = component.getIncomingConnections();
ExternalDbMapData data = (ExternalDbMapData) component.getExternalData();
if (inputConnections == null) {
return expression;
}
for (ExternalDbMapTable input : data.getInputTables()) {
ExternalDbMapTable inputTable = input;
IConnection connection = null;
for (IConnection iconn : inputConnections) {
if (iconn.getName().equals(input.getTableName())) {
connection = iconn;
break;
}
}
if (connection == null) {
return expression;
}
INode source = connection.getSource();
String schemaStr = "";
String tableNameStr = "";
if (source != null) {
if (isELTDBMap(source)) {
tableNameStr = connection.getName();
} else {
IElementParameter schema = source.getElementParameter("ELT_SCHEMA_NAME");
IElementParameter tableName = source.getElementParameter("ELT_TABLE_NAME");
if (schema != null && schema.getValue() != null) {
schemaStr = TalendTextUtils.removeQuotes(schema.getValue().toString());
}
if (tableName != null && tableName.getValue() != null) {
tableNameStr = TalendTextUtils.removeQuotes(tableName.getValue().toString());
}
}
}
for (IMetadataColumn co : connection.getMetadataTable().getListColumns()) {
String columnLabel = co.getOriginalDbColumnName();
if (columnLabel == null || "".equals(columnLabel)) {
columnLabel = co.getLabel();
}
String[] patternSubs = getPattenSubs(schemaStr, tableNameStr, columnLabel);
MapExpressionParser parser = new MapExpressionParser(patternSubs[0]);
expression = parser.replaceLocation(expression, patternSubs[0], patternSubs[1]);
if (inputTable.getAlias() != null && !"".equals(inputTable.getAlias())) {
patternSubs = getPattenSubs("", inputTable.getAlias(), columnLabel);
parser = new MapExpressionParser(patternSubs[0]);
expression = parser.replaceLocation(expression, patternSubs[0], patternSubs[1]);
}
}
}
}
List<IMetadataTable> metadataList = component.getMetadataList();
if (metadataList != null) {
for (IMetadataTable table : metadataList) {
String tableName = table.getLabel();
for (IMetadataColumn column : table.getListColumns()) {
String columnLabel = column.getOriginalDbColumnName();
if (columnLabel == null || "".equals(columnLabel)) {
columnLabel = column.getLabel();
}
String[] patternSubs = getPattenSubs("", tableName, columnLabel);
MapExpressionParser parser = new MapExpressionParser(patternSubs[0]);
expression = parser.replaceLocation(expression, patternSubs[0], patternSubs[1]);
}
}
}
return expression;
}
Aggregations