Search in sources :

Example 1 with ImportHelper

use of org.adempiere.process.rpl.imp.ImportHelper in project adempiere by adempiere.

the class FileImportProcessor method process.

public void process(Properties ctx, ReplicationProcessor replicationProcessor, String trxName) throws Exception {
    MIMPProcessor impProcessor = replicationProcessor.getMImportProcessor();
    X_IMP_ProcessorParameter[] processorParameters = impProcessor.getIMP_ProcessorParameters(trxName);
    String fileName = null;
    String folder = "";
    if (processorParameters != null && processorParameters.length > 0) {
        for (int i = 0; i < processorParameters.length; i++) {
            log.info("ProcesParameter          Value = " + processorParameters[i].getValue());
            log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue());
            if (processorParameters[i].getValue().equals("fileName")) {
                fileName = processorParameters[i].getParameterValue();
            } else if (processorParameters[i].getValue().equals("folder")) {
                folder = processorParameters[i].getParameterValue();
            }
        }
    }
    if (fileName == null || fileName.length() == 0) {
        throw new Exception("Missing IMP_ProcessorParameter with key 'fileName'!");
    }
    Document documentToBeImported = XMLHelper.createDocumentFromFile(folder + fileName);
    StringBuffer result = new StringBuffer();
    ImportHelper impHelper = new ImportHelper(ctx);
    impHelper.importXMLDocument(result, documentToBeImported, trxName);
//		addLog(0, null, null, Msg.getMsg(ctx, "ImportModelProcessResult") + "\n" + result.toString());
}
Also used : MIMPProcessor(org.compiere.model.MIMPProcessor) Document(org.w3c.dom.Document) X_IMP_ProcessorParameter(org.compiere.model.X_IMP_ProcessorParameter) ImportHelper(org.adempiere.process.rpl.imp.ImportHelper)

Example 2 with ImportHelper

use of org.adempiere.process.rpl.imp.ImportHelper in project adempiere by adempiere.

the class TopicListener method onMessage.

/**
	 * 
	 */
public void onMessage(Message message) {
    if (message instanceof TextMessage) {
        try {
            TextMessage txtMessage = (TextMessage) message;
            String text = txtMessage.getText();
            log.finest("Received message: \n" + text);
            Document documentToBeImported = XMLHelper.createDocumentFromString(text);
            StringBuffer result = new StringBuffer();
            ImportHelper impHelper = new ImportHelper(ctx);
            impHelper.importXMLDocument(result, documentToBeImported, trxName);
            log.finest("Message processed ...");
            if (replicationProcessor != null) {
                MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Imported Document!");
                //pLog.setReference("topicName = " + topicName );
                if (text.length() > 2000) {
                    pLog.setTextMsg(text.substring(0, 1999));
                } else {
                    pLog.setTextMsg(text);
                }
                pLog.saveEx();
            }
            session.commit();
        } catch (Exception e) {
            log.finest("Rollback = " + e.toString());
            try {
                session.rollback();
                stop();
                //replicationProcessor.interrupt();
                //replicationProcessor.join();	
                replicationProcessor.setProcessRunning(false);
            }/*catch (InterruptedException e1) {
				    // TODO Auto-generated catch block
				    e1.printStackTrace();
				}*/
             catch (JMSException e2) {
                e2.printStackTrace();
            }
            e.printStackTrace();
        }
    } else {
        log.finest("Received NO TEXT Message: ");
    }
}
Also used : MIMPProcessorLog(org.compiere.model.MIMPProcessorLog) JMSException(javax.jms.JMSException) Document(org.w3c.dom.Document) TextMessage(javax.jms.TextMessage) ImportHelper(org.adempiere.process.rpl.imp.ImportHelper) JMSException(javax.jms.JMSException)

Aggregations

ImportHelper (org.adempiere.process.rpl.imp.ImportHelper)2 Document (org.w3c.dom.Document)2 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1 MIMPProcessor (org.compiere.model.MIMPProcessor)1 MIMPProcessorLog (org.compiere.model.MIMPProcessorLog)1 X_IMP_ProcessorParameter (org.compiere.model.X_IMP_ProcessorParameter)1