Search in sources :

Example 1 with MapperData

use of org.talend.designer.mapper.model.emf.mapper.MapperData 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 2 with MapperData

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

Example 3 with MapperData

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

the class DesignerMapperService method createAutoMappedNode.

public void createAutoMappedNode(INode node, IConnection inputConnection, IConnection outputConnection) {
    MapperData data = (MapperData) node.getExternalNode().getExternalEmfData();
    data.setUiProperties(MapperFactory.eINSTANCE.createUiProperties());
    data.getUiProperties().setShellMaximized(true);
    data.getInputTables().clear();
    InputTable inputTable = MapperFactory.eINSTANCE.createInputTable();
    data.getInputTables().add(inputTable);
    inputTable.setName(inputConnection.getName());
    for (IMetadataColumn column : inputConnection.getMetadataTable().getListColumns()) {
        MapperTableEntry tableEntry = MapperFactory.eINSTANCE.createMapperTableEntry();
        tableEntry.setName(column.getLabel());
        tableEntry.setType(column.getTalendType());
        tableEntry.setNullable(column.isNullable());
        inputTable.getMapperTableEntries().add(tableEntry);
    }
    data.getOutputTables().clear();
    OutputTable outputTable = MapperFactory.eINSTANCE.createOutputTable();
    data.getOutputTables().add(outputTable);
    outputTable.setName(outputConnection.getName());
    for (IMetadataColumn column : outputConnection.getMetadataTable().getListColumns()) {
        MapperTableEntry tableEntry = MapperFactory.eINSTANCE.createMapperTableEntry();
        tableEntry.setName(column.getLabel());
        tableEntry.setType(column.getTalendType());
        tableEntry.setNullable(column.isNullable());
        tableEntry.setExpression(inputConnection.getName() + "." + column.getLabel());
        outputTable.getMapperTableEntries().add(tableEntry);
    }
    ((MapperComponent) node.getExternalNode()).buildExternalData(data);
}
Also used : InputTable(org.talend.designer.mapper.model.emf.mapper.InputTable) MapperTableEntry(org.talend.designer.mapper.model.emf.mapper.MapperTableEntry) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) OutputTable(org.talend.designer.mapper.model.emf.mapper.OutputTable)

Example 4 with MapperData

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

the class DesignerMapperService method getRepositorySchemaIds.

public List<String> getRepositorySchemaIds(AbstractExternalData nodeData) {
    List<String> schemaIds = new ArrayList<String>();
    if (nodeData != null && nodeData instanceof MapperData) {
        MapperData mapperData = (MapperData) nodeData;
        EList<InputTable> inputTables = mapperData.getInputTables();
        if (inputTables != null && inputTables.size() > 0) {
            for (InputTable inputTable : inputTables) {
                String id = inputTable.getId();
                if (id != null && !schemaIds.contains(id)) {
                    schemaIds.add(id);
                }
            }
        }
        EList<OutputTable> outputTables = mapperData.getOutputTables();
        if (outputTables != null && outputTables.size() > 0) {
            for (OutputTable outputTable : outputTables) {
                String id = outputTable.getId();
                if (id != null && !schemaIds.contains(id)) {
                    schemaIds.add(id);
                }
            }
        }
    }
    return schemaIds;
}
Also used : InputTable(org.talend.designer.mapper.model.emf.mapper.InputTable) ArrayList(java.util.ArrayList) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) OutputTable(org.talend.designer.mapper.model.emf.mapper.OutputTable)

Example 5 with MapperData

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

the class MapperComponent method buildExternalData.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.AbstractExternalNode#setExternalXmlData(java.io.InputStream)
     */
// public void loadDataIn(InputStream in, Reader stringReader) throws IOException, ClassNotFoundException {
//
// if (stringReader != null) {
// Unmarshaller unmarshaller = new Unmarshaller(ExternalMapperData.class);
// unmarshaller.setWhitespacePreserve(true);
// try {
// externalData = (ExternalMapperData) unmarshaller.unmarshal(stringReader);
// } catch (MarshalException e) {
// ExceptionHandler.process(e);
// } catch (ValidationException e) {
// ExceptionHandler.process(e);
// } finally {
// if (stringReader != null) {
// stringReader.close();
// }
// }
// }
//
// }
/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.IExternalNode#loadDataOut(java.io.OutputStream, java.io.Writer)
     */
// public void loadDataOut(final OutputStream out, Writer writer) throws IOException {
// // System.out.println("loadDataOut");
//
// initMapperMain(false);
//
// mapperMain.createModelFromExternalData(getIncomingConnections(), getOutgoingConnections(), externalData,
// getMetadataList(), false);
// ExternalMapperData data = mapperMain.buildExternalData();
// if (mapperMain != null && data != null) {
//
// try {
// Marshaller marshaller = new Marshaller(writer);
// marshaller.marshal(externalData);
//
// } catch (MarshalException e) {
// ExceptionHandler.process(e);
// } catch (ValidationException e) {
// ExceptionHandler.process(e);
// } catch (IOException e) {
// ExceptionHandler.process(e);
// } finally {
// if (writer != null) {
// writer.close();
// }
// }
//
// // ObjectOutputStream objectOut = null;
// // try {
// // objectOut = new ObjectOutputStream(out);
// // objectOut.writeObject(data);
// // } catch (IOException e) {
// // ExceptionHandler.process(e);
// // } finally {
// // if (objectOut != null) {
// // objectOut.close();
// // }
// // }
// }
// }
@Override
public void buildExternalData(AbstractExternalData abstractData) {
    externalData = new ExternalMapperData();
    if (abstractData instanceof MapperData) {
        MapperData mapperData = (MapperData) abstractData;
        List<ExternalMapperTable> externalTables = new ArrayList<ExternalMapperTable>();
        // input
        for (InputTable pTable : mapperData.getInputTables()) {
            ExternalMapperTable externalTable = new ExternalMapperTable();
            setExternalTable(externalTable, pTable);
            externalTable.setLookupMode(pTable.getLookupMode());
            externalTable.setMatchingMode(pTable.getMatchingMode());
            externalTable.setInnerJoin(pTable.isInnerJoin());
            externalTable.setPersistent(pTable.isPersistent());
            externalTable.setGlobalMapKeysValues(getExternalEntities(pTable.getGlobalMapKeysValues()));
            externalTables.add(externalTable);
        }
        externalData.setInputTables(externalTables);
        // output
        externalTables = new ArrayList<ExternalMapperTable>();
        for (OutputTable pTable : mapperData.getOutputTables()) {
            ExternalMapperTable externalTable = new ExternalMapperTable();
            setExternalTable(externalTable, pTable);
            externalTable.setReject(pTable.isReject());
            externalTable.setRejectInnerJoin(pTable.isRejectInnerJoin());
            externalTable.setErrorRejectTable(pTable.isIsErrorRejectTable());
            externalTable.setIsJoinTableOf(pTable.getIsJoinTableOf());
            externalTables.add(externalTable);
        }
        externalData.setOutputTables(externalTables);
        // var tables
        externalTables = new ArrayList<ExternalMapperTable>();
        for (VarTable varTable : mapperData.getVarTables()) {
            ExternalMapperTable externalTable = new ExternalMapperTable();
            externalTable.setSizeState(varTable.getSizeState().getLiteral());
            externalTable.setMinimized(varTable.isMinimized());
            externalTable.setName(varTable.getName());
            externalTable.setMetadataTableEntries(getExternalEntities(varTable.getMapperTableEntries()));
            externalTables.add(externalTable);
        }
        externalData.setVarsTables(externalTables);
        ExternalMapperUiProperties uiProperties = new ExternalMapperUiProperties();
        UiProperties uiPro = mapperData.getUiProperties();
        if (uiPro != null) {
            uiProperties.setShellMaximized(uiPro.isShellMaximized());
        }
    }
    this.setExternalData(externalData);
}
Also used : VarTable(org.talend.designer.mapper.model.emf.mapper.VarTable) InputTable(org.talend.designer.mapper.model.emf.mapper.InputTable) ExternalMapperUiProperties(org.talend.designer.mapper.external.data.ExternalMapperUiProperties) ArrayList(java.util.ArrayList) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) OutputTable(org.talend.designer.mapper.model.emf.mapper.OutputTable) UiProperties(org.talend.designer.mapper.model.emf.mapper.UiProperties) ExternalMapperUiProperties(org.talend.designer.mapper.external.data.ExternalMapperUiProperties)

Aggregations

ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)5 MapperData (org.talend.designer.mapper.model.emf.mapper.MapperData)5 InputTable (org.talend.designer.mapper.model.emf.mapper.InputTable)3 OutputTable (org.talend.designer.mapper.model.emf.mapper.OutputTable)3 ArrayList (java.util.ArrayList)2 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 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)1 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)1 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)1 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)1 ExternalMapperUiProperties (org.talend.designer.mapper.external.data.ExternalMapperUiProperties)1 MapperTableEntry (org.talend.designer.mapper.model.emf.mapper.MapperTableEntry)1 UiProperties (org.talend.designer.mapper.model.emf.mapper.UiProperties)1 VarTable (org.talend.designer.mapper.model.emf.mapper.VarTable)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1