Search in sources :

Example 6 with InputTable

use of org.talend.designer.mapper.model.table.InputTable in project tdi-studio-se by Talend.

the class ProblemsManager method checkLookupExpressionProblem.

public boolean checkLookupExpressionProblem() {
    if (mapperManager.isBigDataProcess()) {
        List<DataMapTableView> inputsTablesView = mapperManager.getUiManager().getInputsTablesView();
        List<DataMapTableView> lookupTables = new ArrayList<DataMapTableView>();
        List<IColumnEntry> entityWithoutProblem = new ArrayList<IColumnEntry>();
        DataMapTableView firstLookup = null;
        for (int i = 0; i < inputsTablesView.size(); i++) {
            DataMapTableView inputTableView = inputsTablesView.get(i);
            InputTable dataMapTable = (InputTable) inputTableView.getDataMapTable();
            boolean mainConnection = dataMapTable.isMainConnection();
            if (mainConnection) {
                continue;
            }
            if (firstLookup == null) {
                firstLookup = inputTableView;
            } else {
                lookupTables.add(inputTableView);
            }
        }
        if (firstLookup == null || lookupTables.isEmpty()) {
            return false;
        }
        List<List<IColumnEntry>> otherLookupEntities = new ArrayList<List<IColumnEntry>>();
        for (DataMapTableView otherLookup : lookupTables) {
            otherLookupEntities.add(new ArrayList<IColumnEntry>(otherLookup.getDataMapTable().getColumnEntries()));
        }
        List<IColumnEntry> lookupEntity = firstLookup.getDataMapTable().getColumnEntries();
        for (IColumnEntry firstLookupEntity : lookupEntity) {
            String expression = firstLookupEntity.getExpression();
            if (expression == null || expression.trim().equals("")) {
                continue;
            }
            //$NON-NLS-1$//$NON-NLS-2$
            expression = expression.replaceAll("\\s*", "").trim();
            Map<List<IColumnEntry>, IColumnEntry> entitiesFound = new HashMap<List<IColumnEntry>, IColumnEntry>();
            for (List<IColumnEntry> tableEntities : otherLookupEntities) {
                for (IColumnEntry entityInOtherLookup : tableEntities) {
                    String expressionInOtherLookup = entityInOtherLookup.getExpression();
                    if (expressionInOtherLookup == null || expressionInOtherLookup.trim().equals("")) {
                        continue;
                    }
                    //$NON-NLS-1$//$NON-NLS-2$
                    expressionInOtherLookup = expressionInOtherLookup.replaceAll("\\s*", "").trim();
                    // only match the first one
                    if (expression.equals(expressionInOtherLookup)) {
                        entitiesFound.put(tableEntities, entityInOtherLookup);
                        break;
                    }
                }
            }
            if (entitiesFound.size() == otherLookupEntities.size()) {
                for (List<IColumnEntry> tableEntities : entitiesFound.keySet()) {
                    entityWithoutProblem.add(entitiesFound.get(tableEntities));
                    entityWithoutProblem.add(firstLookupEntity);
                    tableEntities.remove(entitiesFound.get(tableEntities));
                }
            }
        }
        // add back the first lookup table
        lookupTables.add(firstLookup);
        if (entityWithoutProblem.isEmpty()) {
            // no common expressions in lookup tables , then show red background color for all
            for (DataMapTableView lookupTable : lookupTables) {
                List<IColumnEntry> columnEntries = lookupTable.getDataMapTable().getColumnEntries();
                for (IColumnEntry entity : columnEntries) {
                    if (entity.getExpression() == null || entity.getExpression().trim().equals("")) {
                        continue;
                    }
                    addLookupProblem(entity);
                }
                lookupTable.getTableViewerCreatorForColumns().refresh();
            }
        } else {
            for (DataMapTableView lookupTable : lookupTables) {
                boolean needRefresh = false;
                List<IColumnEntry> columnEntries = lookupTable.getDataMapTable().getColumnEntries();
                for (IColumnEntry entity : columnEntries) {
                    if (entity.getExpression() == null || entity.getExpression().trim().equals("") || entityWithoutProblem.contains(entity)) {
                        if (entity.getProblems() != null) {
                            needRefresh = entity.getProblems().remove(lookupProblem);
                            if (entity.getProblems().isEmpty()) {
                                entity.setProblems(null);
                            }
                        }
                    } else {
                        addLookupProblem(entity);
                        needRefresh = true;
                    }
                }
                if (needRefresh) {
                    lookupTable.getTableViewerCreatorForColumns().refresh();
                }
            }
        }
        return true;
    }
    return false;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) InputTable(org.talend.designer.mapper.model.table.InputTable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with InputTable

use of org.talend.designer.mapper.model.table.InputTable in project tdi-studio-se by Talend.

the class UIManager method parseAllExpressions.

/**
     * DOC amaumont Comment method "processAllExpressions".
     * 
     * @param newLinksMustHaveSelectedState TODO
     */
@SuppressWarnings("unchecked")
public void parseAllExpressions(DataMapTableView dataMapTableView, boolean newLinksMustHaveSelectedState) {
    List<IColumnEntry> columnsEntriesList = dataMapTableView.getDataMapTable().getColumnEntries();
    parseAllExpressions(columnsEntriesList, newLinksMustHaveSelectedState);
    if (mapperManager.isAdvancedMap() && (dataMapTableView.getZone() == Zone.INPUTS || dataMapTableView.getZone() == Zone.OUTPUTS)) {
        AbstractInOutTable table = (AbstractInOutTable) dataMapTableView.getDataMapTable();
        if (dataMapTableView.getZone() == Zone.INPUTS) {
            InputTable inputTable = (InputTable) table;
            List<GlobalMapEntry> globalMapEntries = inputTable.getGlobalMapEntries();
            if (globalMapEntries != null && !inputTable.isMainConnection()) {
                parseAllExpressions(globalMapEntries, newLinksMustHaveSelectedState);
            }
        }
        if (table.isActivateExpressionFilter()) {
            ExpressionFilterEntry expressionFilter = table.getExpressionFilter();
            parseExpression(expressionFilter.getExpression(), expressionFilter, newLinksMustHaveSelectedState, false, false);
        }
    } else if (dataMapTableView.getZone() == Zone.OUTPUTS) {
        List<ITableEntry> constraintEntriesList = dataMapTableView.getTableViewerCreatorForFilters().getInputList();
        parseAllExpressions(constraintEntriesList, newLinksMustHaveSelectedState);
    }
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) ArrayList(java.util.ArrayList) List(java.util.List) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)

Example 8 with InputTable

use of org.talend.designer.mapper.model.table.InputTable in project tdi-studio-se by Talend.

the class ProblemsAnalyser method checkKeysProblems.

/**
     * DOC amaumont Comment method "checkKeysProblems".
     * 
     * @param incomingConnections
     * @param inputTables
     */
private void checkKeysProblems(ArrayList<InputTable> inputTables) {
    ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
    if (!mapperManager.isAdvancedMap()) {
        for (InputTable table : inputTables) {
            if (table.isMainConnection()) {
                continue;
            }
            String tableName = table.getName();
            List<IColumnEntry> columnEntries = table.getColumnEntries();
            for (IColumnEntry entry : columnEntries) {
                InputColumnTableEntry inputEntry = (InputColumnTableEntry) entry;
                String columnName = entry.getName();
                if (mapperManager.checkEntryHasInvalidUncheckedKey(inputEntry)) {
                    String description = //$NON-NLS-1$
                    "Key of " + currentLanguage.getLocation(tableName, columnName) + //$NON-NLS-1$
                    " input entry should be checked or expression should be removed. ";
                    addProblem(new Problem(null, description, ProblemStatus.WARNING));
                }
                if (mapperManager.checkEntryHasInvalidCheckedKey(inputEntry)) {
                    String description = //$NON-NLS-1$
                    "Key of " + currentLanguage.getLocation(tableName, columnName) + //$NON-NLS-1$
                    " input entry should be unchecked or expression should be filled. ";
                    addProblem(new Problem(null, description, ProblemStatus.WARNING));
                }
            }
        }
    }
}
Also used : ILanguage(org.talend.designer.mapper.language.ILanguage) InputTable(org.talend.designer.mapper.model.table.InputTable) Problem(org.talend.core.model.process.Problem) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)

Example 9 with InputTable

use of org.talend.designer.mapper.model.table.InputTable in project tdi-studio-se by Talend.

the class ProblemsAnalyser method checkProblems.

public List<Problem> checkProblems(ExternalMapperData externalData) {
    problems.clear();
    if (externalData != null) {
        checkLookupTablesKeyProblems(externalData);
        ICodeProblemsChecker codeChecker = LanguageProvider.getCurrentLanguage().getCodeChecker();
        if (mapperManager.isCheckSyntaxEnabled()) {
            List<ExternalMapperTable> extInputTables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
            List<ExternalMapperTable> extVarTables = new ArrayList<ExternalMapperTable>(externalData.getVarsTables());
            List<ExternalMapperTable> extOutputTables = new ArrayList<ExternalMapperTable>(externalData.getOutputTables());
            checkExpressionSyntaxProblems(extInputTables, codeChecker);
            checkExpressionSyntaxProblems(extVarTables, codeChecker);
            checkExpressionSyntaxProblems(extOutputTables, codeChecker);
            List<? extends IConnection> incomingConnections = new ArrayList<IConnection>(this.mapperManager.getAbstractMapComponent().getIncomingConnections());
            ExternalDataConverter converter = new ExternalDataConverter(mapperManager);
            MapperMain mapperMain = ((MapperComponent) mapperManager.getAbstractMapComponent()).getMapperMain();
            ArrayList<IOConnection> inputsIOConnections = mapperMain.createIOConnections(incomingConnections);
            ArrayList<InputTable> inputTables = converter.prepareInputTables(inputsIOConnections, externalData);
            checkKeysProblems(inputTables);
            checkOutputTablesProblems(extOutputTables);
        }
    }
    return getProblems();
}
Also used : ExternalDataConverter(org.talend.designer.mapper.external.converter.ExternalDataConverter) InputTable(org.talend.designer.mapper.model.table.InputTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) ArrayList(java.util.ArrayList) ICodeProblemsChecker(org.talend.core.language.ICodeProblemsChecker) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) MapperMain(org.talend.designer.mapper.MapperMain) MapperComponent(org.talend.designer.mapper.MapperComponent)

Example 10 with InputTable

use of org.talend.designer.mapper.model.table.InputTable in project tdi-studio-se by Talend.

the class ExpressionProposalProvider method getProposals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
     */
public IContentProposal[] getProposals(String contents, int position) {
    List<IContentProposal> proposals = new ArrayList<IContentProposal>();
    TableEntryLocation sourceEntryLocation = new TableEntryLocation();
    for (IDataMapTable table : this.tables) {
        List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
        for (IColumnEntry entrySource : dataMapTableEntries) {
            sourceEntryLocation.tableName = entrySource.getParentName();
            sourceEntryLocation.columnName = entrySource.getName();
            if (mapperManager.getUiManager().checkSourceLocationIsValid(entrySource, currentModifiedEntry)) {
                proposals.add(new EntryContentProposal(entrySource, this.currentLanguage));
            }
        }
        // for the globalMap
        if (table instanceof InputTable) {
            InputTable inputTable = (InputTable) table;
            List<GlobalMapEntry> globalMapEntries = inputTable.getGlobalMapEntries();
            for (GlobalMapEntry entry : globalMapEntries) {
                proposals.add(new EntryContentProposal(entry, this.currentLanguage));
            }
        }
    }
    for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
        proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
    }
    IContentProposal[] res = new IContentProposal[proposals.size()];
    res = proposals.toArray(res);
    return res;
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) InputTable(org.talend.designer.mapper.model.table.InputTable) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Aggregations

InputTable (org.talend.designer.mapper.model.table.InputTable)24 ArrayList (java.util.ArrayList)10 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)8 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)8 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)8 OutputTable (org.talend.designer.mapper.model.table.OutputTable)5 HashMap (java.util.HashMap)4 List (java.util.List)4 VarsTable (org.talend.designer.mapper.model.table.VarsTable)4 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)4 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)4 Point (org.eclipse.swt.graphics.Point)3 GridData (org.eclipse.swt.layout.GridData)3 Table (org.eclipse.swt.widgets.Table)3 TableItem (org.eclipse.swt.widgets.TableItem)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 IOConnection (org.talend.designer.mapper.external.connection.IOConnection)3 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)3 AbstractInOutTable (org.talend.designer.mapper.model.table.AbstractInOutTable)3 ExpressionFilterEntry (org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)3