Search in sources :

Example 1 with DataMapExpressionParser

use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.

the class OutputTable method initFromExternalData.

public void initFromExternalData(ExternalMapperTable externalMapperTable) {
    super.initFromExternalData(externalMapperTable);
    if (externalMapperTable != null) {
        this.reject = externalMapperTable.isReject();
        this.rejectInnerJoin = externalMapperTable.isRejectInnerJoin();
        this.isJoinTableOf = externalMapperTable.getIsJoinTableOf();
        this.isErrorRejectTable = externalMapperTable.isErrorRejectTable();
        List<ExternalMapperTableEntry> externalConstraintTableEntries = externalMapperTable.getConstraintTableEntries();
        if (externalConstraintTableEntries != null) {
            if (!mapperManager.isAdvancedMap()) {
                for (ExternalMapperTableEntry entry : externalConstraintTableEntries) {
                    FilterTableEntry filterTableEntry = new FilterTableEntry(this, entry.getName(), entry.getExpression());
                    // mapperManager.getProblemsManager().checkProblemsForTableEntry(filterTableEntry, false);
                    addFilterEntry(filterTableEntry);
                }
            } else {
                ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
                JavaGenerationManager javaGenerationManager = new JavaGenerationManager(currentLanguage);
                DataMapExpressionParser expressionParser = new DataMapExpressionParser(currentLanguage);
                String expressionFilter = javaGenerationManager.buildConditions(externalConstraintTableEntries, expressionParser);
                if (!expressionFilter.trim().equals("")) {
                    //$NON-NLS-1$
                    this.getExpressionFilter().setExpression(expressionFilter);
                    this.setActivateExpressionFilter(true);
                }
            }
        }
    }
}
Also used : ILanguage(org.talend.designer.mapper.language.ILanguage) JavaGenerationManager(org.talend.designer.mapper.language.generation.JavaGenerationManager) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry)

Example 2 with DataMapExpressionParser

use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.

the class MapperComponent method replaceLocationsInAllExpressions.

/**
     * DOC amaumont Comment method "replaceLocations".
     * 
     * @param oldLocation
     * @param newLocation
     * @param tableRenamed TODO
     * @param newTableName
     * @param newColumnName
     */
private void replaceLocationsInAllExpressions(TableEntryLocation oldLocation, TableEntryLocation newLocation, boolean tableRenamed) {
    // replace old location by new location for all expressions in mapper
    List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
    tables.addAll(new ArrayList<ExternalMapperTable>(externalData.getVarsTables()));
    tables.addAll(new ArrayList<ExternalMapperTable>(externalData.getOutputTables()));
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
    // loop on all tables
    for (ExternalMapperTable table : tables) {
        List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
        String expressionFilter = replaceLocation(oldLocation, newLocation, table.getExpressionFilter(), dataMapExpressionParser, tableRenamed);
        if (expressionFilter != null) {
            table.setExpressionFilter(expressionFilter);
        }
        if (metadataTableEntries != null) {
            // loop on all entries of current table
            for (ExternalMapperTableEntry entry : metadataTableEntries) {
                String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
                if (expression != null) {
                    entry.setExpression(expression);
                }
            }
        // for (ExternalMapperTableEntry entry : metadataTableEntries) {
        }
        if (table.getConstraintTableEntries() != null) {
            for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
                String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
                if (expression != null) {
                    entry.setExpression(expression);
                }
            }
        }
        if (table.getGlobalMapKeysValues() != null) {
            for (ExternalMapperTableEntry entry : table.getGlobalMapKeysValues()) {
                String expression = replaceLocation(oldLocation, newLocation, entry.getExpression(), dataMapExpressionParser, tableRenamed);
                if (expression != null) {
                    entry.setExpression(expression);
                }
            }
        }
    }
// for (ExternalMapperTable table : tables) {
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 3 with DataMapExpressionParser

use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.

the class ExternalMapperData method getLinkedTableColumnsMapping.

public Map<String, Set<String>> getLinkedTableColumnsMapping() {
    Map<String, Set<String>> tableColumnsMapping = new HashMap<String, Set<String>>();
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
    List<ExternalMapperTable> tablesHasFilter = new ArrayList<ExternalMapperTable>();
    tablesHasFilter.addAll(inputTables);
    tablesHasFilter.addAll(outputTables);
    for (ExternalMapperTable table : tablesHasFilter) {
        TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(table.getExpressionFilter());
        for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
            if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
                Set<String> columns = new HashSet<String>();
                columns.add(tableEntryLocation.columnName);
                tableColumnsMapping.put(tableEntryLocation.tableName, columns);
            } else {
                tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
            }
        }
    }
    List<ExternalMapperTable> tablesHasColumnExpression = new ArrayList<ExternalMapperTable>();
    tablesHasColumnExpression.addAll(varsTables);
    tablesHasColumnExpression.addAll(outputTables);
    for (ExternalMapperTable table : tablesHasColumnExpression) {
        List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
        for (ExternalMapperTableEntry entry : metadataTableEntries) {
            TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(entry.getExpression());
            for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
                if (!tableColumnsMapping.containsKey(tableEntryLocation.tableName)) {
                    Set<String> columns = new HashSet<String>();
                    columns.add(tableEntryLocation.columnName);
                    tableColumnsMapping.put(tableEntryLocation.tableName, columns);
                } else {
                    tableColumnsMapping.get(tableEntryLocation.tableName).add(tableEntryLocation.columnName);
                }
            }
        }
    }
    return tableColumnsMapping;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) HashSet(java.util.HashSet)

Example 4 with DataMapExpressionParser

use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.

the class ExternalMapperTable method isSelfFilter.

public boolean isSelfFilter() {
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
    TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(this.expressionFilter);
    for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
        if (!this.name.equals(tableEntryLocation.tableName)) {
            return false;
        }
    }
    return true;
}
Also used : DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation)

Example 5 with DataMapExpressionParser

use of org.talend.designer.mapper.utils.DataMapExpressionParser in project tdi-studio-se by Talend.

the class UIManager method parseFilterColumn.

public ParseExpressionResult parseFilterColumn(String expression, ITableEntry currentModifiedITableEntry, boolean linkMustHaveSelectedState, boolean checkInputKeyAutomatically, boolean inputExpressionAppliedOrCanceled) {
    if (currentModifiedITableEntry instanceof InputColumnTableEntry) {
        InputColumnTableEntry entry = (InputColumnTableEntry) currentModifiedITableEntry;
        if (StringUtils.trimToNull(expression) == null) {
            entry.setOperator(null);
        }
    }
    DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedITableEntry);
    boolean linkHasBeenAdded = false;
    boolean linkHasBeenRemoved = false;
    DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
    TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
    Set<TableEntryLocation> alreadyProcessed = new HashSet<TableEntryLocation>();
    Set<ITableEntry> sourcesForTarget = mapperManager.getSourcesForTarget(currentModifiedITableEntry);
    Set<ITableEntry> sourcesForTargetToDelete = new HashSet<ITableEntry>(sourcesForTarget);
    boolean isInputEntry = currentModifiedITableEntry instanceof InputColumnTableEntry;
    ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
    for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
        TableEntryLocation location = tableEntriesLocationsSource;
        // tests to know if link must be removed if key is unchecked
        boolean dontRemoveLink = (!isInputEntry || isInputEntry && (inputExpressionAppliedOrCanceled || !inputExpressionAppliedOrCanceled && !mapperManager.checkEntryHasInvalidUncheckedKey((InputColumnTableEntry) currentModifiedITableEntry)));
        if (!alreadyProcessed.contains(location) && checkSourceLocationIsValid(location, currentModifiedITableEntry) && (mapperManager.isAdvancedMap() || !mapperManager.isAdvancedMap() && dontRemoveLink)) {
            ITableEntry sourceTableEntry = mapperManager.retrieveTableEntry(location);
            if (sourceTableEntry != null && sourcesForTarget.contains(sourceTableEntry)) {
                Set<IMapperLink> targets = mapperManager.getGraphicalLinksFromTarget(currentModifiedITableEntry);
                Set<IMapperLink> linksFromTarget = new HashSet<IMapperLink>(targets);
                for (IMapperLink link : linksFromTarget) {
                    link.calculate();
                }
            }
        }
    }
    mapperManager.orderLinks();
    if (!mapperManager.isAdvancedMap()) {
        if (dataMapTableView.getZone() == Zone.INPUTS) {
            if (linkHasBeenAdded || linkHasBeenRemoved) {
                checkTargetInputKey(currentModifiedITableEntry, checkInputKeyAutomatically, inputExpressionAppliedOrCanceled);
            }
            if (inputExpressionAppliedOrCanceled) {
                openChangeKeysDialog((InputDataMapTableView) dataMapTableView);
            }
        }
    }
    return new ParseExpressionResult(linkHasBeenAdded, linkHasBeenRemoved);
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) ParseExpressionResult(org.talend.designer.mapper.utils.ParseExpressionResult) DataMapExpressionParser(org.talend.designer.mapper.utils.DataMapExpressionParser) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry) HashSet(java.util.HashSet) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

DataMapExpressionParser (org.talend.designer.mapper.utils.DataMapExpressionParser)7 TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)2 IMapperLink (org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink)2 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)2 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)2 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)2 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)2 InputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView)2 OutputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)2 VarsDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView)2 ParseExpressionResult (org.talend.designer.mapper.utils.ParseExpressionResult)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)1 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)1 PointLinkDescriptor (org.talend.designer.abstractmap.ui.visualmap.link.PointLinkDescriptor)1