Search in sources :

Example 1 with ExternalMapperData

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

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

the class TMapSaveToEmfMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            StringReader stringReader = null;
            if (nodeType.getStringData() != null && !"".equals(nodeType.getStringData())) {
                stringReader = new StringReader(nodeType.getStringData());
            }
            final String componentName = nodeType.getComponentName();
            if (stringReader != null) {
                if ("tMap".equals(componentName)) {
                    modified = true;
                    Unmarshaller unmarshaller = new Unmarshaller(ExternalMapperData.class);
                    unmarshaller.setWhitespacePreserve(true);
                    try {
                        ExternalMapperData externalData = (ExternalMapperData) unmarshaller.unmarshal(stringReader);
                        final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
                        MapperHelper.saveDataToEmf(externalData, emfMapperData);
                        nodeType.setNodeData(emfMapperData);
                        nodeType.setStringData("");
                    } catch (MarshalException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (ValidationException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } finally {
                        if (stringReader != null) {
                            stringReader.close();
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with ExternalMapperData

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

the class UIManager method removeUnsavedOutputsFromProcess.

private void removeUnsavedOutputsFromProcess() {
    AbstractMapComponent abstractMapComponent = getAbstractMapperManager().getAbstractMapComponent();
    IProcess process = abstractMapComponent.getProcess();
    List<OutputTable> currentOutputTablesList = mapperManager.getOutputTables();
    HashSet<String> currentTables = new HashSet<String>(currentOutputTablesList.size());
    for (OutputTable outputTable : currentOutputTablesList) {
        currentTables.add(outputTable.getName());
    }
    ExternalMapperData originalExternalData = (ExternalMapperData) mapperManager.getOriginalExternalData();
    HashSet<String> originalTableNames = new HashSet<String>();
    if (originalExternalData != null) {
        List<ExternalMapperTable> originalOutputTables = originalExternalData.getOutputTables();
        for (ExternalMapperTable outputTable : originalOutputTables) {
            originalTableNames.add(outputTable.getName());
        }
    }
    for (String currentTable : currentTables) {
        if (!originalTableNames.contains(currentTable)) {
            process.removeUniqueConnectionName(currentTable);
        }
    }
}
Also used : AbstractMapComponent(org.talend.designer.abstractmap.AbstractMapComponent) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) IProcess(org.talend.core.model.process.IProcess) OutputTable(org.talend.designer.mapper.model.table.OutputTable) HashSet(java.util.HashSet)

Example 4 with ExternalMapperData

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

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

the class MapperComponent method getExternalEmfData.

@Override
public AbstractExternalData getExternalEmfData() {
    final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
    initMapperMain(false);
    mapperMain.createModelFromExternalData(getIncomingConnections(), getOutgoingConnections(), externalData, getMetadataList(), false);
    ExternalMapperData data = mapperMain.buildExternalData();
    if (mapperMain != null && data != null) {
        if (externalData != null) {
            // fwang fixed bug TDI-8027
            this.externalData = data;
            MapperHelper.saveDataToEmf(data, emfMapperData);
        }
    }
    return emfMapperData;
}
Also used : MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData)

Aggregations

ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)17 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)13 ArrayList (java.util.ArrayList)6 IExternalData (org.talend.core.model.process.IExternalData)3 MapperData (org.talend.designer.mapper.model.emf.mapper.MapperData)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 IConnection (org.talend.core.model.process.IConnection)2 MapperComponent (org.talend.designer.mapper.MapperComponent)2 IOConnection (org.talend.designer.mapper.external.connection.IOConnection)2 ExternalDataConverter (org.talend.designer.mapper.external.converter.ExternalDataConverter)2 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 MarshalException (org.exolab.castor.xml.MarshalException)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1 ValidationException (org.exolab.castor.xml.ValidationException)1 Test (org.junit.Test)1 IComponent (org.talend.core.model.components.IComponent)1