Search in sources :

Example 6 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.

the class ServicesAwareAuditEventBuilder method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte) {
    NodeInstanceLog nodeInstanceLog = (NodeInstanceLog) super.buildEvent(pnte);
    nodeInstanceLog.setExternalId(deploymentUnitId);
    return nodeInstanceLog;
}
Also used : NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog)

Example 7 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.

the class AsyncAuditLogProducer method beforeNodeTriggered.

@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
    NodeInstanceLog log = (NodeInstanceLog) builder.buildEvent(event);
    sendMessage(log, BEFORE_NODE_ENTER_EVENT_TYPE);
    ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().put("NodeInstanceLog", log);
}
Also used : NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog)

Example 8 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.

the class AsyncAuditLogReceiver method onMessage.

@SuppressWarnings("unchecked")
@Override
public void onMessage(Message message) {
    if (message instanceof TextMessage) {
        EntityManager em = getEntityManager();
        TextMessage textMessage = (TextMessage) message;
        try {
            String messageContent = textMessage.getText();
            Integer eventType = textMessage.getIntProperty("EventType");
            Object event = xstream.fromXML(messageContent);
            switch(eventType) {
                case AbstractAuditLogger.AFTER_NODE_ENTER_EVENT_TYPE:
                    NodeInstanceLog nodeAfterEnterEvent = (NodeInstanceLog) event;
                    if (nodeAfterEnterEvent.getWorkItemId() != null) {
                        List<NodeInstanceLog> result = em.createQuery("from NodeInstanceLog as log where log.nodeInstanceId = :nodeId and log.type = 0").setParameter("nodeId", nodeAfterEnterEvent.getNodeInstanceId()).getResultList();
                        if (result != null && result.size() != 0) {
                            NodeInstanceLog log = result.get(result.size() - 1);
                            log.setWorkItemId(nodeAfterEnterEvent.getWorkItemId());
                            em.merge(log);
                        }
                    }
                    break;
                case AbstractAuditLogger.AFTER_COMPLETE_EVENT_TYPE:
                    ProcessInstanceLog processCompletedEvent = (ProcessInstanceLog) event;
                    List<ProcessInstanceLog> result = em.createQuery("from ProcessInstanceLog as log where log.processInstanceId = :piId and log.end is null").setParameter("piId", processCompletedEvent.getProcessInstanceId()).getResultList();
                    if (result != null && result.size() != 0) {
                        ProcessInstanceLog log = result.get(result.size() - 1);
                        log.setOutcome(processCompletedEvent.getOutcome());
                        log.setStatus(processCompletedEvent.getStatus());
                        log.setEnd(processCompletedEvent.getEnd());
                        log.setDuration(processCompletedEvent.getDuration());
                        em.merge(log);
                    }
                    break;
                default:
                    em.persist(event);
                    break;
            }
            em.flush();
            em.close();
        } catch (JMSException e) {
            e.printStackTrace();
            throw new RuntimeException("Exception when receiving audit event event", e);
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 9 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte, Object log) {
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
    NodeInstanceLog logEvent = null;
    if (log != null) {
        logEvent = (NodeInstanceLog) log;
        if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
            logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
        }
        if (nodeInstance instanceof SubProcessNodeInstance) {
            logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
        }
        return logEvent;
    }
    return null;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 10 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pnte.getProcessInstance();
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
    Node node = nodeInstance.getNode();
    String nodeId = null;
    String nodeType = null;
    String nodeContainerId = null;
    if (node != null) {
        nodeId = (String) node.getMetaData().get("UniqueId");
        nodeType = node.getClass().getSimpleName();
        nodeContainerId = getNodeContainerId(node.getNodeContainer());
    } else {
        nodeId = Long.toString(nodeInstance.getNodeId());
        nodeType = (String) nodeInstance.getMetaData("NodeType");
    }
    NodeInstanceLog log = new NodeInstanceLog(NodeInstanceLog.TYPE_ENTER, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
    if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
        log.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
    }
    if (nodeInstance instanceof SubProcessNodeInstance) {
        log.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
    }
    String connection = (String) nodeInstance.getMetaData().get("IncomingConnection");
    log.setConnection(connection);
    log.setExternalId("" + ((KieSession) pnte.getKieRuntime()).getIdentifier());
    log.setNodeType(nodeType);
    log.setNodeContainerId(nodeContainerId);
    log.setDate(pnte.getEventDate());
    log.setSlaCompliance(nodeInstance.getSlaCompliance());
    log.setSlaDueDate(nodeInstance.getSlaDueDate());
    return log;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Aggregations

NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)25 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)8 Test (org.junit.Test)8 KieSession (org.kie.api.runtime.KieSession)7 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 AuditLogService (org.jbpm.process.audit.AuditLogService)6 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)6 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)6 KieBase (org.kie.api.KieBase)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)4 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)4 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)4 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)4 Environment (org.kie.api.runtime.Environment)4 EntityManager (javax.persistence.EntityManager)3 VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)3 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)3