Search in sources :

Example 1 with MapExpressionParser

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;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) MapExpressionParser(org.talend.designer.dbmap.language.generation.MapExpressionParser) IElementParameter(org.talend.core.model.process.IElementParameter) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Aggregations

IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IConnection (org.talend.core.model.process.IConnection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 INode (org.talend.core.model.process.INode)1 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)1 ExternalDbMapTable (org.talend.designer.dbmap.external.data.ExternalDbMapTable)1 MapExpressionParser (org.talend.designer.dbmap.language.generation.MapExpressionParser)1