Search in sources :

Example 1 with ExternalMapperTable

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

the class DesignerMapperService method getRepositorySchemaIds.

public List<String> getRepositorySchemaIds(IExternalData nodeData) {
    List<String> schemaIds = new ArrayList<String>();
    if (nodeData != null && nodeData instanceof ExternalMapperData) {
        ExternalMapperData mapperData = (ExternalMapperData) nodeData;
        List<ExternalMapperTable> inputTables = mapperData.getInputTables();
        if (inputTables != null && inputTables.size() > 0) {
            for (ExternalMapperTable inputTable : inputTables) {
                String id = inputTable.getId();
                if (id != null && !schemaIds.contains(id)) {
                    schemaIds.add(id);
                }
            }
        }
        List<ExternalMapperTable> outputTables = mapperData.getOutputTables();
        if (outputTables != null && outputTables.size() > 0) {
            for (ExternalMapperTable outputTable : outputTables) {
                String id = outputTable.getId();
                if (id != null && !schemaIds.contains(id)) {
                    schemaIds.add(id);
                }
            }
        }
    }
    return schemaIds;
}
Also used : ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData)

Example 2 with ExternalMapperTable

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

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

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

the class ExternalDataConverter method prepareVarsTables.

private List<VarsTable> prepareVarsTables(ExternalMapperData externalData) {
    List<VarsTable> varsTablesList = new ArrayList<VarsTable>();
    if (externalData != null) {
        List<ExternalMapperTable> varsExternalTables = externalData.getVarsTables();
        for (ExternalMapperTable persistentTable : varsExternalTables) {
            VarsTable varsTable = new VarsTable(this.mapperManager, persistentTable.getName());
            varsTable.initFromExternalData(persistentTable);
            varsTablesList.add(varsTable);
        }
    }
    if (varsTablesList.size() == 0) {
        VarsTable varsTable = new VarsTable(this.mapperManager, VarsTable.PREFIX_VARS_TABLE_NAME);
        varsTable.setMinimized(true);
        varsTablesList.add(varsTable);
    }
    return varsTablesList;
}
Also used : VarsTable(org.talend.designer.mapper.model.table.VarsTable) ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 5 with ExternalMapperTable

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

the class ExternalDataConverter method prepareInputTables.

public ArrayList<InputTable> prepareInputTables(List<IOConnection> inputConnections, ExternalMapperData externalData) {
    ArrayList<InputTable> inputDataMapTables = new ArrayList<InputTable>();
    ArrayList<IOConnection> remainingConnections = new ArrayList<IOConnection>(inputConnections);
    // case externalData IS NOT initialized
    if (externalData == null || externalData.getInputTables().size() == 0) {
        for (IOConnection connection : inputConnections) {
            InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
            inputTable.initFromExternalData(null);
            if (EConnectionType.FLOW_MAIN != connection.getConnectionType()) {
                inputTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
            }
            if (connection.getTable() == null) {
                inputTable.setReadOnly(true);
            }
            inputDataMapTables.add(inputTable);
        }
    } else {
        // case externalData IS initialized
        Map<String, IOConnection> nameToInputConnection = new HashMap<String, IOConnection>();
        for (IOConnection connection : inputConnections) {
            nameToInputConnection.put(connection.getName(), connection);
        }
        for (ExternalMapperTable persistentTable : externalData.getInputTables()) {
            IOConnection connection = nameToInputConnection.get(persistentTable.getName());
            if (connection != null) {
                InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
                inputTable.initFromExternalData(persistentTable);
                inputDataMapTables.add(inputTable);
                remainingConnections.remove(connection);
                // remove table settings in main ,set false in case the value is true in previous version
                if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
                    inputTable.setActivateCondensedTool(false);
                    // bug TDI-8027
                    inputTable.setPersistent(false);
                }
                if (connection.getTable() == null) {
                    inputTable.setReadOnly(true);
                }
            }
        }
        for (IOConnection connection : remainingConnections) {
            InputTable inputTable = new InputTable(this.mapperManager, connection, connection.getName());
            inputTable.initFromExternalData(null);
            inputDataMapTables.add(inputTable);
            // remove table settings in main ,set false in case the value is true in previous version
            if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
                inputTable.setActivateCondensedTool(false);
                // bug TDI-8027
                inputTable.setPersistent(false);
            } else {
                inputTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
            }
            if (connection.getTable() == null) {
                inputTable.setReadOnly(true);
            }
        }
    }
    // sort for put table with main connection at top position of the list
    Collections.sort(inputDataMapTables, new Comparator<InputTable>() {

        public int compare(InputTable o1, InputTable o2) {
            if (o1.isMainConnection()) {
                return -1;
            } else if (o2.isMainConnection()) {
                return 1;
            }
            return 0;
        }
    });
    return inputDataMapTables;
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Aggregations

ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)34 ArrayList (java.util.ArrayList)20 ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)13 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)11 List (java.util.List)5 HashMap (java.util.HashMap)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)4 IExternalData (org.talend.core.model.process.IExternalData)4 IOConnection (org.talend.designer.mapper.external.connection.IOConnection)4 IConnection (org.talend.core.model.process.IConnection)3 Problem (org.talend.core.model.process.Problem)3 MapperComponent (org.talend.designer.mapper.MapperComponent)3 OutputTable (org.talend.designer.mapper.model.table.OutputTable)3 Element (org.dom4j.Element)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)2 InputTable (org.talend.designer.mapper.model.emf.mapper.InputTable)2 OutputTable (org.talend.designer.mapper.model.emf.mapper.OutputTable)2 UiProperties (org.talend.designer.mapper.model.emf.mapper.UiProperties)2