Search in sources :

Example 1 with MEXPProcessorType

use of org.compiere.model.MEXPProcessorType in project adempiere by adempiere.

the class ExportHelper method exportRecord.

/**
	 *
	 * Process - Generate Export Format
 	 * @param po
	 * @param replicationMode
	 * @param replicationType
	 * @param replicationEvent
	 * @return info
     * @throws Exception
     */
public String exportRecord(PO po, Integer replicationMode, String replicationType, Integer replicationEvent) throws Exception {
    MClient client = MClient.get(po.getCtx(), clientId);
    log.info("Client = " + client.toString());
    log.info("po.getAD_Org_ID() = " + po.getAD_Org_ID());
    log.info("po.get_TrxName() = " + po.get_TrxName());
    if (po.get_TrxName() == null || po.get_TrxName().equals("")) {
        po.set_TrxName("exportRecord");
    }
    log.info("Table = " + po.get_TableName());
    if (po.get_KeyColumns().length < 1) {
        //TODO: Create Mesagge.
        throw new Exception(Msg.getMsg(po.getCtx(), "ExportNoneColumnKeyNotSupported"));
    }
    // TODO - get proper Export Format!
    String version = "3.8.2";
    //int EXP_Format_ID = 1000006;
    MEXPFormat exportFormat = null;
    //exportFormat = new MFormat(po.getCtx(), EXP_Format_ID, po.get_TrxName());
    exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), clientId, po.get_Table_ID(), version, po.get_TrxName());
    log.fine("exportFormat = " + exportFormat);
    if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) {
        // Fall back to System Client
        MClient systemClient = MClient.get(po.getCtx(), 0);
        log.info(systemClient.toString());
        exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), 0, po.get_Table_ID(), version, po.get_TrxName());
        if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) {
            throw new Exception(Msg.getMsg(po.getCtx(), "EXPFormatNotFound"));
        }
    }
    outDocument = createNewDocument();
    HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
    Element rootElement = outDocument.createElement(exportFormat.getValue());
    if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
        rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
    }
    rootElement.setAttribute("AD_Client_Value", client.getValue());
    rootElement.setAttribute("Version", exportFormat.getVersion());
    rootElement.setAttribute("ReplicationMode", replicationMode.toString());
    rootElement.setAttribute("ReplicationType", replicationType);
    rootElement.setAttribute("ReplicationEvent", replicationEvent.toString());
    outDocument.appendChild(rootElement);
    generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
    MEXPProcessor mExportProcessor = null;
    mExportProcessor = new MEXPProcessor(po.getCtx(), replicationStrategy.getEXP_Processor_ID(), po.get_TrxName());
    log.fine("ExportProcessor = " + mExportProcessor);
    int EXP_ProcessorType_ID = 0;
    EXP_ProcessorType_ID = mExportProcessor.getEXP_Processor_Type_ID();
    MEXPProcessorType expProcessor_Type = new MEXPProcessorType(po.getCtx(), EXP_ProcessorType_ID, po.get_TrxName());
    String javaClass = expProcessor_Type.getJavaClass();
    try {
        Class clazz = Class.forName(javaClass);
        IExportProcessor exportProcessor = (IExportProcessor) clazz.newInstance();
        exportProcessor.process(po.getCtx(), mExportProcessor, outDocument, Trx.get(po.get_TrxName(), false));
    } catch (Exception e) {
        log.severe(e.toString());
        throw e;
    }
    return outDocument.toString();
}
Also used : MEXPFormat(org.compiere.model.MEXPFormat) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) IExportProcessor(org.adempiere.process.rpl.IExportProcessor) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MEXPProcessor(org.compiere.model.MEXPProcessor) MClient(org.compiere.model.MClient) MEXPProcessorType(org.compiere.model.MEXPProcessorType)

Aggregations

SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 IExportProcessor (org.adempiere.process.rpl.IExportProcessor)1 MClient (org.compiere.model.MClient)1 MEXPFormat (org.compiere.model.MEXPFormat)1 MEXPProcessor (org.compiere.model.MEXPProcessor)1 MEXPProcessorType (org.compiere.model.MEXPProcessorType)1 Element (org.w3c.dom.Element)1