Search in sources :

Example 26 with TableEntryLocation

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

the class DataMapExpressionParserTest method testReplaceLocation_renamingColumn_underlineInColumn.

@Test
public void testReplaceLocation_renamingColumn_underlineInColumn() {
    String result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.column_A", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.column_A", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.mycolumn_A", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.mycolumn_A", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.my_column_A", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.my_column_A", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.column_AB", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.column_AB", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.column_A_B", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.column_A_B", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.mycolumn_AB", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.mycolumn_AB", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.my_column_A_B", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.my_column_A_B", result);
}
Also used : TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) Test(org.junit.Test)

Example 27 with TableEntryLocation

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

the class DataMapExpressionParserTest method testReplaceLocation_renamingColumn_same.

@Test
public void testReplaceLocation_renamingColumn_same() {
    String result = expressionParser.replaceLocation("YYY.columnA == XXXYYY.columnA", new TableEntryLocation("YYY", "columnA"), new TableEntryLocation("YYY", "columnB"));
    assertEquals("YYY.columnB == XXXYYY.columnA", result);
    result = expressionParser.replaceLocation("YYY.column_A == XXXYYY.column_A", new TableEntryLocation("YYY", "column_A"), new TableEntryLocation("YYY", "column_B"));
    assertEquals("YYY.column_B == XXXYYY.column_A", result);
}
Also used : TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) Test(org.junit.Test)

Example 28 with TableEntryLocation

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

the class DataMapExpressionParserTest method testReplaceLocation_renamingColumn_middle.

@Test
public void testReplaceLocation_renamingColumn_middle() {
    String result = expressionParser.replaceLocation("YYY.columnA == XXXYYY.mycolumnAB", new TableEntryLocation("YYY", "columnA"), new TableEntryLocation("YYY", "columnB"));
    assertEquals("YYY.columnB == XXXYYY.mycolumnAB", result);
    result = expressionParser.replaceLocation("YYY.columnA == XXXYYY.my_columnAB", new TableEntryLocation("YYY", "columnA"), new TableEntryLocation("YYY", "columnB"));
    assertEquals("YYY.columnB == XXXYYY.my_columnAB", result);
    result = expressionParser.replaceLocation("YYY.columnA == XXXYYY.my_columnA_B", new TableEntryLocation("YYY", "columnA"), new TableEntryLocation("YYY", "columnB"));
    assertEquals("YYY.columnB == XXXYYY.my_columnA_B", result);
}
Also used : TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) Test(org.junit.Test)

Example 29 with TableEntryLocation

use of org.talend.designer.mapper.model.tableentry.TableEntryLocation 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)

Example 30 with TableEntryLocation

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

the class UIManager method processColumnNameChanged.

/**
     * DOC amaumont Comment method "processNewProcessColumnName".
     * 
     * @param previousColumnName TODO
     * @param dataMapTableView
     * @param text
     * @param entry
     */
public void processColumnNameChanged(final String previousColumnName, final String newColumnName, final DataMapTableView dataMapTableView, final ITableEntry currentModifiedITableEntry) {
    mapperManager.changeColumnName(currentModifiedITableEntry, previousColumnName, newColumnName);
    Collection<DataMapTableView> tableViews = mapperManager.getTablesView();
    boolean atLeastOneLinkHasBeenRemoved = false;
    for (DataMapTableView view : tableViews) {
        IDataMapTable dataMapTable = view.getDataMapTable();
        List<IColumnEntry> metadataTableEntries = dataMapTable.getColumnEntries();
        for (IColumnEntry entry : metadataTableEntries) {
            if (parseExpression(entry.getExpression(), entry, true, true, false).isAtLeastOneLinkRemoved()) {
                atLeastOneLinkHasBeenRemoved = true;
            }
        }
        // for the input/output table expression filter
        if (dataMapTable instanceof AbstractInOutTable) {
            ExpressionFilterEntry expressionFilterEntry = ((AbstractInOutTable) dataMapTable).getExpressionFilter();
            if (expressionFilterEntry != null && expressionFilterEntry.getExpression() != null) {
                if (parseExpression(expressionFilterEntry.getExpression(), expressionFilterEntry, true, true, false).isAtLeastOneLinkRemoved()) {
                    atLeastOneLinkHasBeenRemoved = true;
                }
            }
        }
    }
    mapperManager.getUiManager().refreshBackground(false, false);
    dataMapTableView.getTableViewerCreatorForColumns().getTableViewer().refresh(currentModifiedITableEntry);
    if (atLeastOneLinkHasBeenRemoved) {
        new AsynchronousThreading(20, false, dataMapTableView.getDisplay(), new Runnable() {

            public void run() {
                TableViewerCreator tableViewerCreatorForColumns = dataMapTableView.getTableViewerCreatorForColumns();
                boolean propagate = MessageDialog.openQuestion(tableViewerCreatorForColumns.getTable().getShell(), //$NON-NLS-1$
                Messages.getString("UIManager.propagateTitle"), //$NON-NLS-1$
                Messages.getString("UIManager.propagateMessage"));
                if (propagate) {
                    TableEntryLocation previousLocation = new TableEntryLocation(currentModifiedITableEntry.getParentName(), previousColumnName);
                    TableEntryLocation newLocation = new TableEntryLocation(currentModifiedITableEntry.getParentName(), newColumnName);
                    mapperManager.replacePreviousLocationInAllExpressions(previousLocation, newLocation);
                }
            }
        }).start();
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) 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) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) AsynchronousThreading(org.talend.commons.ui.runtime.thread.AsynchronousThreading)

Aggregations

TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)33 Test (org.junit.Test)14 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)7 ArrayList (java.util.ArrayList)6 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)6 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)5 InputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView)5 OutputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)5 VarsDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView)5 HashSet (java.util.HashSet)4 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)4 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)3 DataMapExpressionParser (org.talend.designer.mapper.utils.DataMapExpressionParser)3 HashMap (java.util.HashMap)2 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Point (org.eclipse.swt.graphics.Point)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2