Search in sources :

Example 6 with DBMapData

use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.

the class DbMapComponent method getExternalEmfData.

@Override
public AbstractExternalData getExternalEmfData() {
    final DBMapData emfMapperData = DbmapFactory.eINSTANCE.createDBMapData();
    if (mapperMain == null) {
        initMapperMain(false);
    }
    mapperMain.createModelFromExternalData(getIncomingConnections(), getOutgoingConnections(), externalData, getMetadataList(), false);
    ExternalDbMapData data = mapperMain.buildExternalData();
    if (mapperMain != null && data != null) {
        if (externalData != null) {
            DBMapHelper.saveDataToEmf(emfMapperData, externalData);
        }
    }
    return emfMapperData;
}
Also used : DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData)

Example 7 with DBMapData

use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.

the class DbMapService method updateEMFDBMapData.

@Override
public void updateEMFDBMapData(NodeType nodeType, String oldValue, String newValue) {
    AbstractExternalData nodeData = nodeType.getNodeData();
    if (nodeData instanceof DBMapData) {
        DBMapData dbMapData = (DBMapData) nodeData;
        for (InputTable input : dbMapData.getInputTables()) {
            if (input.getName().equals(oldValue) || input.getTableName().equals(oldValue)) {
                input.setName(newValue);
                input.setTableName(newValue);
            }
        }
        for (OutputTable output : dbMapData.getOutputTables()) {
            List<DBMapperTableEntry> entries = output.getDBMapperTableEntries();
            for (DBMapperTableEntry entry : entries) {
                String expression = entry.getExpression();
                if (expression != null && !"".equals(expression.trim())) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    int index = expression.lastIndexOf(".");
                    // at least "a.b"
                    if (index > 0) {
                        String connectionName = expression.substring(0, index);
                        if (oldValue.equals(connectionName)) {
                            entry.setExpression(newValue + expression.substring(index, expression.length()));
                        }
                    }
                }
            }
        }
    }
}
Also used : AbstractExternalData(org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData) InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)

Example 8 with DBMapData

use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.

the class ELTMapSaveToEmfMigrationTask 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 (componentName != null && componentName.startsWith("tELT") && componentName.endsWith("Map")) {
                    modified = true;
                    StringBuilder input = null;
                    Unmarshaller unmarshaller = new Unmarshaller(ExternalDbMapData.class);
                    unmarshaller.setWhitespacePreserve(true);
                    try {
                        BufferedReader r = new BufferedReader(stringReader);
                        input = new StringBuilder();
                        String line;
                        while ((line = r.readLine()) != null) {
                            input.append(line);
                            //$NON-NLS-0$
                            input.append("\r\n");
                        }
                        //$NON-NLS-0$ //$NON-NLS-1$
                        String buf = input.toString().replaceAll("<table-entries .*?>.*?</table-entries>", "");
                        stringReader.close();
                        stringReader = new StringReader(buf);
                        ExternalDbMapData externalData = (ExternalDbMapData) unmarshaller.unmarshal(stringReader);
                        DBMapData emfMapperData = DbmapFactory.eINSTANCE.createDBMapData();
                        DBMapHelper.saveDataToEmf(emfMapperData, externalData);
                        nodeType.setNodeData(emfMapperData);
                        nodeType.setStringData("");
                    } catch (MarshalException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (ValidationException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (IOException 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) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ValidationException(org.exolab.castor.xml.ValidationException) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) IOException(java.io.IOException) IOException(java.io.IOException) 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) BufferedReader(java.io.BufferedReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 9 with DBMapData

use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.

the class DbMapServiceTest method testUpdateEMFDBMapData.

@Test
public void testUpdateEMFDBMapData() {
    DbMapService service = new DbMapService();
    service.updateEMFDBMapData(nodeType, oldValue, newValue);
    DBMapData data = (DBMapData) nodeType.getNodeData();
    InputTable input = data.getInputTables().get(0);
    assertEquals("context.schema.context.table", input.getName());
    assertEquals("context.schema.context.table", input.getTableName());
    OutputTable out = data.getOutputTables().get(0);
    // output connection name should not be updated.
    assertEquals("output", out.getName());
    DBMapperTableEntry outEntry = out.getDBMapperTableEntries().get(0);
    assertEquals("context.schema.context.table.column", outEntry.getExpression());
}
Also used : InputTable(org.talend.designer.dbmap.model.emf.dbmap.InputTable) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) DBMapperTableEntry(org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry) Test(org.junit.Test)

Aggregations

DBMapData (org.talend.designer.dbmap.model.emf.dbmap.DBMapData)9 InputTable (org.talend.designer.dbmap.model.emf.dbmap.InputTable)5 OutputTable (org.talend.designer.dbmap.model.emf.dbmap.OutputTable)5 DBMapperTableEntry (org.talend.designer.dbmap.model.emf.dbmap.DBMapperTableEntry)4 ExternalDbMapData (org.talend.designer.dbmap.external.data.ExternalDbMapData)3 ArrayList (java.util.ArrayList)2 IODataComponentContainer (org.talend.core.model.components.IODataComponentContainer)2 AbstractExternalData (org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)2 FilterEntry (org.talend.designer.dbmap.model.emf.dbmap.FilterEntry)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MarshalException (org.exolab.castor.xml.MarshalException)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1 ValidationException (org.exolab.castor.xml.ValidationException)1 Before (org.junit.Before)1 Test (org.junit.Test)1