Search in sources :

Example 1 with IOConnection

use of org.talend.designer.mapper.external.connection.IOConnection 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 2 with IOConnection

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

the class OutputDataMapTableView method initColumnsOfTableColumns.

@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
    IOConnection connection = ((OutputTable) getDataMapTable()).getConnection();
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("OutputDataMapTableView.columnTitle.expression"));
    column.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
    expressionCellEditor = createExpressionCellEditor(tableViewerCreatorForColumns, column, new Zone[] { Zone.INPUTS, Zone.VARS }, false);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<OutputColumnTableEntry, String>() {

        public String get(OutputColumnTableEntry bean) {
            return bean.getExpression();
        }

        public void set(OutputColumnTableEntry bean, String value) {
            bean.setExpression(value);
            mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
            tableViewerCreatorForColumns.getTableViewer().refresh(bean);
        }
    });
    column.setModifiable(!mapperManager.componentIsReadOnly());
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    column.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    column.setTitle(DataMapTableView.COLUMN_NAME);
    column.setId(DataMapTableView.ID_NAME_COLUMN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<OutputColumnTableEntry, String>() {

        public String get(OutputColumnTableEntry bean) {
            return bean.getMetadataColumn().getLabel();
        }

        public void set(OutputColumnTableEntry bean, String value) {
            bean.getMetadataColumn().setLabel(value);
        }
    });
    column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
    if (PluginChecker.isTraceDebugPluginLoaded() && mapperManager.isTracesActive() && connection != null) {
        column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
        column.setTitle("Preview");
        column.setId(DataMapTableView.PREVIEW_COLUMN);
        column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
        column.setBeanPropertyAccessors(new IBeanPropertyAccessors<OutputColumnTableEntry, String>() {

            public String get(OutputColumnTableEntry bean) {
                IMetadataColumn metadataColumn = bean.getMetadataColumn();
                if (metadataColumn != null) {
                    String label = metadataColumn.getLabel();
                    TraceData preview = bean.getPreviewValue();
                    if (preview != null && preview.getData() != null) {
                        return preview.getData().get(label);
                    }
                }
                return "";
            }

            public void set(OutputColumnTableEntry bean, String value) {
            // do nothing
            }
        });
    }
    configureCellModifier(tableViewerCreatorForColumns);
}
Also used : IOConnection(org.talend.designer.mapper.external.connection.IOConnection) Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) TraceData(org.talend.core.model.process.TraceData) OutputColumnTableEntry(org.talend.designer.mapper.model.tableentry.OutputColumnTableEntry) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) OutputTable(org.talend.designer.mapper.model.table.OutputTable)

Example 3 with IOConnection

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

the class ProblemsAnalyserTest method testGetLookupTableProblem.

@Test
public void testGetLookupTableProblem() {
    MapperComponent mapperComponent = createMapperComponent();
    ExternalMapperData externalData = (ExternalMapperData) mapperComponent.getExternalData();
    MapperManager mapperManager = mapperComponent.getMapperMain().getMapperManager();
    ExternalDataConverter converter = new ExternalDataConverter(mapperManager);
    MapperMain mapperMain = ((MapperComponent) mapperManager.getAbstractMapComponent()).getMapperMain();
    List<? extends IConnection> incomingConnections = new ArrayList<IConnection>(mapperManager.getAbstractMapComponent().getIncomingConnections());
    ArrayList<IOConnection> inputsIOConnections = mapperMain.createIOConnections(incomingConnections);
    ArrayList<InputTable> inputTables = converter.prepareInputTables(inputsIOConnections, externalData);
    InputTable lookupTable = inputTables.get(1);
    ProblemsAnalyser analyser = new ProblemsAnalyser(mapperManager);
    // match mode:Unique Match +no expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.UNIQUE_MATCH);
    analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
    List<Problem> problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The lookup table 'row2' should have at least one expression key filled.");
    // match mode:All Row +expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
    lookupTable.getColumnEntries().get(0).setExpression("row1.newColumn1");
    analyser = new ProblemsAnalyser(mapperComponent.getMapperMain().getMapperManager());
    analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
    problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The expression key can't be used in lookup table 'row2' with match mode 'All Rows'.");
}
Also used : ExternalDataConverter(org.talend.designer.mapper.external.converter.ExternalDataConverter) MapperManager(org.talend.designer.mapper.managers.MapperManager) ArrayList(java.util.ArrayList) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) InputTable(org.talend.designer.mapper.model.table.InputTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) Problem(org.talend.core.model.process.Problem) MapperMain(org.talend.designer.mapper.MapperMain) MapperComponent(org.talend.designer.mapper.MapperComponent) Test(org.junit.Test)

Example 4 with IOConnection

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

the class InputTable method hasReadOnlyMetadataColumns.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.mapper.model.table.AbstractInOutTable#hasReadOnlyMetadataColumns()
     */
@Override
public boolean hasReadOnlyMetadataColumns() {
    boolean hasReadOnlyMetadataColumns = false;
    IOConnection connection = getConnection();
    if (connection != null) {
        INode source = connection.getSource();
        if (source != null) {
            hasReadOnlyMetadataColumns = connection.isReadOnly() || !connection.isActivate() || source.isReadOnly();
            if (!hasReadOnlyMetadataColumns) {
                for (IElementParameter param : source.getElementParameters()) {
                    if (param.getFieldType() == EParameterFieldType.SCHEMA_TYPE) {
                        if (param.isReadOnly()) {
                            hasReadOnlyMetadataColumns = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    return hasReadOnlyMetadataColumns;
}
Also used : INode(org.talend.core.model.process.INode) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 5 with IOConnection

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

IOConnection (org.talend.designer.mapper.external.connection.IOConnection)8 ArrayList (java.util.ArrayList)5 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)3 InputTable (org.talend.designer.mapper.model.table.InputTable)3 HashMap (java.util.HashMap)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 INode (org.talend.core.model.process.INode)2 MapperComponent (org.talend.designer.mapper.MapperComponent)2 MapperMain (org.talend.designer.mapper.MapperMain)2 ExternalDataConverter (org.talend.designer.mapper.external.converter.ExternalDataConverter)2 OutputTable (org.talend.designer.mapper.model.table.OutputTable)2 List (java.util.List)1 Test (org.junit.Test)1 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)1 ICodeProblemsChecker (org.talend.core.language.ICodeProblemsChecker)1 IODataComponent (org.talend.core.model.components.IODataComponent)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 Problem (org.talend.core.model.process.Problem)1 TraceData (org.talend.core.model.process.TraceData)1