Search in sources :

Example 6 with ExternalMapperTableEntry

use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry 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 7 with ExternalMapperTableEntry

use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.

the class MapperComponent method hasOrRenameData.

/**
     * 
     * DOC amaumont Comment method "hasOrRenameData".
     * 
     * @param oldName
     * @param newName can be null if <code>renameAction</code> is false
     * @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
     * @return
     */
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
    if (oldName == null || newName == null && renameAction) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        if (externalData.getVarsTables() != null) {
            tables.addAll(externalData.getVarsTables());
        }
        for (ExternalMapperTable table : tables) {
            if (table.getExpressionFilter() != null) {
                Pattern pattern = getRenamePattern(oldName);
                if (pattern != null) {
                    PatternMatcher matcher = new Perl5Matcher();
                    ((Perl5Matcher) matcher).setMultiline(true);
                    if (renameAction) {
                        Perl5Substitution substitution = getRenameSubstitution(newName);
                        String expression = renameDataIntoExpression(pattern, matcher, substitution, table.getExpressionFilter());
                        table.setExpressionFilter(expression);
                    } else {
                        if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
                            return true;
                        }
                    }
                }
            }
            List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
            if (metadataTableEntries != null) {
                // loop on all entries of current table
                for (ExternalMapperTableEntry entry : metadataTableEntries) {
                    if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
                        // existed
                        return true;
                    }
                }
            // for (ExternalMapperTableEntry entry : metadataTableEntries) {
            }
            if (table.getConstraintTableEntries() != null) {
                for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
                    if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
                        // existed
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 8 with ExternalMapperTableEntry

use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.

the class MapperComponent method getExternalEntities.

private List<ExternalMapperTableEntry> getExternalEntities(List<MapperTableEntry> pEntities) {
    List<ExternalMapperTableEntry> entityList = new ArrayList<ExternalMapperTableEntry>();
    if (pEntities != null && !pEntities.isEmpty()) {
        for (MapperTableEntry pEntity : pEntities) {
            ExternalMapperTableEntry externalEntity = new ExternalMapperTableEntry();
            externalEntity.setExpression(pEntity.getExpression());
            externalEntity.setName(pEntity.getName());
            externalEntity.setNullable(pEntity.isNullable());
            externalEntity.setType(pEntity.getType());
            externalEntity.setOperator(pEntity.getOperator());
            entityList.add(externalEntity);
        }
        return entityList;
    } else {
        // fix for tuj tMap_01_basics_04 , need to return null if no entity
        return null;
    }
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) MapperTableEntry(org.talend.designer.mapper.model.emf.mapper.MapperTableEntry) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList)

Example 9 with ExternalMapperTableEntry

use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.

the class ExternalDataConverter method fillExternalTable.

/**
     * 
     * DOC amaumont Comment method "fillExternalTable".
     * 
     * @param table
     * @param externalMapperTable
     */
private void fillExternalTable(InputTable table, ExternalMapperTable externalMapperTable) {
    externalMapperTable.setInnerJoin(table.isInnerJoin());
    externalMapperTable.setPersistent(table.isPersistent());
    externalMapperTable.setActivateExpressionFilter(table.isActivateExpressionFilter());
    externalMapperTable.setActivateCondensedTool(table.isActivateCondensedTool());
    externalMapperTable.setActivateColumnNameFilter(table.isActivateColumnNameFilter());
    externalMapperTable.setId(table.getId());
    String expressionFilter = null;
    if (table.getExpressionFilter() != null && table.getExpressionFilter().getExpression() != null) {
        expressionFilter = table.getExpressionFilter().getExpression();
    }
    externalMapperTable.setExpressionFilter(expressionFilter);
    String matchingMode = null;
    if (table.getMatchingMode() != null) {
        matchingMode = table.getMatchingMode().toString();
    }
    externalMapperTable.setMatchingMode(matchingMode);
    String lookupMode = null;
    if (table.getLookupMode() != null) {
        lookupMode = table.getLookupMode().toString();
    }
    externalMapperTable.setLookupMode(lookupMode);
    ArrayList<ExternalMapperTableEntry> globalMapEntries = new ArrayList<ExternalMapperTableEntry>();
    for (GlobalMapEntry constraintTableEntry : table.getGlobalMapEntries()) {
        ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
        externalMapperTableEntry.setExpression(constraintTableEntry.getExpression());
        externalMapperTableEntry.setName(constraintTableEntry.getName());
        globalMapEntries.add(externalMapperTableEntry);
    }
    externalMapperTable.setGlobalMapKeysValues(globalMapEntries);
    fillExternalTableWithCommonsData(table, externalMapperTable);
    inputTables.add(externalMapperTable);
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Example 10 with ExternalMapperTableEntry

use of org.talend.designer.mapper.external.data.ExternalMapperTableEntry in project tdi-studio-se by Talend.

the class MapperComponent method renameMetadataColumnName.

@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
    if (conectionName == null || oldColumnName == null || newColumnName == null) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        // rename metadata column name
        List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        ExternalMapperTable tableFound = null;
        for (ExternalMapperTable table : tables) {
            if (table.getName().equals(conectionName)) {
                List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
                for (ExternalMapperTableEntry entry : metadataTableEntries) {
                    if (entry.getName().equals(oldColumnName)) {
                        entry.setName(newColumnName);
                        tableFound = table;
                        break;
                    }
                }
                break;
            }
        }
        // it is necessary to update expressions only if renamed column come from input table
        if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
            TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
            TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
            replaceLocationsInAllExpressions(oldLocation, newLocation, false);
        }
    }
}
Also used : ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Aggregations

ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)22 ArrayList (java.util.ArrayList)15 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 AbstractInOutTableEntry (org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)3 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)3 HashMap (java.util.HashMap)2 Problem (org.talend.core.model.process.Problem)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)2 ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)2 ILanguage (org.talend.designer.mapper.language.ILanguage)2 MapperTableEntry (org.talend.designer.mapper.model.emf.mapper.MapperTableEntry)2 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)2 DataMapExpressionParser (org.talend.designer.mapper.utils.DataMapExpressionParser)2 List (java.util.List)1 Pattern (org.apache.oro.text.regex.Pattern)1 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)1 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)1