Search in sources :

Example 6 with ExecutionResults

use of org.jbpm.executor.api.ExecutionResults in project jBPM5-Developer-Guide by Salaboy.

the class GetPatientDataCommand method execute.

public ExecutionResults execute(CommandContext ctx) throws MalformedURLException {
    String patientId = (String) ctx.getData("gatherdata_patientName");
    InsuranceService client = getClient();
    Patient patientData = client.getPatientData(patientId);
    ExecutionResults executionResults = new ExecutionResults();
    executionResults.setData("gatherdata_patient", patientData);
    return executionResults;
}
Also used : InsuranceService(com.salaboy.jbpm5.dev.guide.webservice.InsuranceService) ExecutionResults(org.jbpm.executor.api.ExecutionResults) Patient(com.salaboy.jbpm5.dev.guide.model.Patient)

Example 7 with ExecutionResults

use of org.jbpm.executor.api.ExecutionResults in project jBPM5-Developer-Guide by Salaboy.

the class NotifyAndChargePatientCommand method execute.

public ExecutionResults execute(CommandContext ctx) {
    Patient patient = (Patient) ctx.getData("invoice_patient");
    BigDecimal finalAmount = (BigDecimal) ctx.getData("invoice_finalAmount");
    List<ConceptCode> concepts = (List<ConceptCode>) ctx.getData("invoice_concepts");
    boolean patientNotified = false;
    try {
        InsuranceService client = getClient();
        patientNotified = client.notifyAndChargePatient(patient, finalAmount, concepts);
    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    }
    System.out.println(" >>> Patient Notified = " + patientNotified);
    ExecutionResults results = new ExecutionResults();
    results.setData("invoice_patientNotified", patientNotified);
    return results;
}
Also used : ConceptCode(com.salaboy.jbpm5.dev.guide.model.ConceptCode) MalformedURLException(java.net.MalformedURLException) InsuranceService(com.salaboy.jbpm5.dev.guide.webservice.InsuranceService) ExecutionResults(org.jbpm.executor.api.ExecutionResults) Patient(com.salaboy.jbpm5.dev.guide.model.Patient) List(java.util.List) BigDecimal(java.math.BigDecimal)

Example 8 with ExecutionResults

use of org.jbpm.executor.api.ExecutionResults in project jBPM5-Developer-Guide by Salaboy.

the class ExecutorRunnable method run.

@Transactional
public void run() {
    logger.log(Level.INFO, " >>> Executor Thread {0} Waking Up!!!", this.toString());
    List<?> resultList = em.createQuery("Select r from RequestInfo as r where r.status ='QUEUED' or r.status = 'RETRYING' ORDER BY r.time DESC").getResultList();
    logger.log(Level.INFO, " >>> Pending Requests = {0}", resultList.size());
    if (resultList.size() > 0) {
        RequestInfo r = null;
        Throwable exception = null;
        try {
            r = (RequestInfo) resultList.get(0);
            r.setStatus(STATUS.RUNNING);
            em.merge(r);
            logger.log(Level.INFO, " >> Processing Request Id: {0}", r.getId());
            logger.log(Level.INFO, " >> Request Status ={0}", r.getStatus());
            logger.log(Level.INFO, " >> Command Name to execute = {0}", r.getCommandName());
            Command cmd = this.findCommand(r.getCommandName());
            CommandContext ctx = null;
            byte[] reqData = r.getRequestData();
            if (reqData != null) {
                try {
                    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(reqData));
                    ctx = (CommandContext) in.readObject();
                } catch (IOException e) {
                    ctx = null;
                    e.printStackTrace();
                }
            }
            ExecutionResults results = cmd.execute(ctx);
            if (ctx != null && ctx.getData("callbacks") != null) {
                logger.log(Level.INFO, " ### Callback: {0}", ctx.getData("callbacks"));
                String[] callbacksArray = ((String) ctx.getData("callbacks")).split(",");
                ;
                List<String> callbacks = (List<String>) Arrays.asList(callbacksArray);
                for (String callbackName : callbacks) {
                    CommandCallback handler = this.findCommandCallback(callbackName);
                    handler.onCommandDone(ctx, results);
                }
            } else {
                logger.info(" ### Callbacks: NULL");
            }
            if (results != null) {
                try {
                    ByteArrayOutputStream bout = new ByteArrayOutputStream();
                    ObjectOutputStream out = new ObjectOutputStream(bout);
                    out.writeObject(results);
                    byte[] respData = bout.toByteArray();
                    r.setResponseData(respData);
                } catch (IOException e) {
                    r.setResponseData(null);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            exception = e;
        }
        if (exception != null) {
            logger.log(Level.SEVERE, "{0} >>> Before - Error Handling!!!{1}", new Object[] { System.currentTimeMillis(), exception.getMessage() });
            ErrorInfo errorInfo = new ErrorInfo(exception.getMessage(), ExceptionUtils.getFullStackTrace(exception.fillInStackTrace()));
            errorInfo.setRequestInfo(r);
            r.getErrorInfo().add(errorInfo);
            logger.log(Level.SEVERE, " >>> Error Number: {0}", r.getErrorInfo().size());
            if (r.getRetries() > 0) {
                r.setStatus(STATUS.RETRYING);
                r.setRetries(r.getRetries() - 1);
                r.setExecutions(r.getExecutions() + 1);
                logger.log(Level.SEVERE, " >>> Retrying ({0}) still available!", r.getRetries());
            } else {
                logger.severe(" >>> Error no retries left!");
                r.setStatus(STATUS.ERROR);
                r.setExecutions(r.getExecutions() + 1);
            }
            em.merge(r);
            logger.severe(" >>> After - Error Handling!!!");
        } else {
            r.setStatus(STATUS.DONE);
            em.merge(r);
        }
    }
}
Also used : CommandContext(org.jbpm.executor.api.CommandContext) ExecutionResults(org.jbpm.executor.api.ExecutionResults) ErrorInfo(org.jbpm.executor.entities.ErrorInfo) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RequestInfo(org.jbpm.executor.entities.RequestInfo) ObjectOutputStream(java.io.ObjectOutputStream) IOException(java.io.IOException) Command(org.jbpm.executor.api.Command) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) CommandCallback(org.jbpm.executor.api.CommandCallback) ObjectInputStream(java.io.ObjectInputStream) Transactional(org.jboss.seam.transaction.Transactional)

Aggregations

ExecutionResults (org.jbpm.executor.api.ExecutionResults)8 InsuranceService (com.salaboy.jbpm5.dev.guide.webservice.InsuranceService)5 MalformedURLException (java.net.MalformedURLException)4 ConceptCode (com.salaboy.jbpm5.dev.guide.model.ConceptCode)3 BigDecimal (java.math.BigDecimal)3 Patient (com.salaboy.jbpm5.dev.guide.model.Patient)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PatientDataServiceWorkItemHandler (com.salaboy.jbpm5.dev.guide.workitems.PatientDataServiceWorkItemHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Client (org.apache.cxf.endpoint.Client)1 JaxWsDynamicClientFactory (org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory)1 Transactional (org.jboss.seam.transaction.Transactional)1 Command (org.jbpm.executor.api.Command)1 CommandCallback (org.jbpm.executor.api.CommandCallback)1 CommandContext (org.jbpm.executor.api.CommandContext)1