Search in sources :

Example 6 with ProcessInstanceImpl

use of org.jbpm.process.instance.impl.ProcessInstanceImpl in project jbpm by kiegroup.

the class JPAWorkingMemoryDbLogger method afterProcessCompleted.

@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
    long processInstanceId = event.getProcessInstance().getId();
    EntityManager em = getEntityManager(event);
    Object tx = joinTransaction(em);
    ProcessInstanceLog log = (ProcessInstanceLog) ((ProcessInstanceImpl) event.getProcessInstance()).getMetaData().get("ProcessInstanceLog");
    if (log == null) {
        List<ProcessInstanceLog> result = em.createQuery("from ProcessInstanceLog as log where log.processInstanceId = :piId and log.end is null").setParameter("piId", processInstanceId).getResultList();
        if (result != null && result.size() != 0) {
            log = result.get(result.size() - 1);
        }
    }
    if (log != null) {
        log = (ProcessInstanceLog) builder.buildEvent(event, log);
        em.merge(log);
    }
    leaveTransaction(em, tx);
}
Also used : EntityManager(javax.persistence.EntityManager) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl)

Example 7 with ProcessInstanceImpl

use of org.jbpm.process.instance.impl.ProcessInstanceImpl in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessStartedEvent pse) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pse.getProcessInstance();
    ProcessInstanceLog log = new ProcessInstanceLog(pi.getId(), pi.getProcessId());
    log.setExternalId("" + ((KieSession) pse.getKieRuntime()).getIdentifier());
    log.setProcessName(pi.getProcess().getName());
    log.setProcessVersion(pi.getProcess().getVersion());
    log.setStatus(ProcessInstance.STATE_ACTIVE);
    log.setProcessInstanceDescription(pi.getDescription());
    log.setProcessType(((WorkflowProcess) pi.getProcess()).getProcessType());
    log.setSlaCompliance(pi.getSlaCompliance());
    log.setSlaDueDate(pi.getSlaDueDate());
    // store correlation key in its external form
    CorrelationKey correlationKey = (CorrelationKey) pi.getMetaData().get("CorrelationKey");
    if (correlationKey != null) {
        log.setCorrelationKey(correlationKey.toExternalForm());
    }
    long parentProcessInstanceId = (Long) pi.getMetaData().getOrDefault("ParentProcessInstanceId", -1L);
    log.setParentProcessInstanceId(parentProcessInstanceId);
    return log;
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 8 with ProcessInstanceImpl

use of org.jbpm.process.instance.impl.ProcessInstanceImpl in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessCompletedEvent pce, Object log) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pce.getProcessInstance();
    ProcessInstanceLog logEvent = null;
    if (log != null) {
        logEvent = (ProcessInstanceLog) log;
    } else {
        logEvent = new ProcessInstanceLog(pi.getId(), pi.getProcessId());
    }
    logEvent.setOutcome(pi.getOutcome());
    logEvent.setStatus(pi.getState());
    logEvent.setEnd(pce.getEventDate());
    logEvent.setDuration(logEvent.getEnd().getTime() - logEvent.getStart().getTime());
    logEvent.setProcessInstanceDescription(pi.getDescription());
    logEvent.setSlaCompliance(pi.getSlaCompliance());
    return logEvent;
}
Also used : ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 9 with ProcessInstanceImpl

use of org.jbpm.process.instance.impl.ProcessInstanceImpl 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)

Example 10 with ProcessInstanceImpl

use of org.jbpm.process.instance.impl.ProcessInstanceImpl in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeLeftEvent pnle, Object log) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pnle.getProcessInstance();
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnle.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 logEvent = null;
    if (log != null) {
        logEvent = (NodeInstanceLog) log;
    } else {
        logEvent = new NodeInstanceLog(NodeInstanceLog.TYPE_EXIT, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
    }
    if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
        logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
    }
    if (nodeInstance instanceof SubProcessNodeInstance) {
        logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
    }
    String connection = (String) nodeInstance.getMetaData().get("OutgoingConnection");
    logEvent.setConnection(connection);
    logEvent.setExternalId("" + ((KieSession) pnle.getKieRuntime()).getIdentifier());
    logEvent.setNodeType(nodeType);
    logEvent.setNodeContainerId(nodeContainerId);
    logEvent.setDate(pnle.getEventDate());
    logEvent.setSlaCompliance(nodeInstance.getSlaCompliance());
    logEvent.setSlaDueDate(nodeInstance.getSlaDueDate());
    return logEvent;
}
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

ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)15 KieSession (org.kie.api.runtime.KieSession)6 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)4 Process (org.kie.api.definition.process.Process)4 ArrayList (java.util.ArrayList)3 RegistryContext (org.drools.core.command.impl.RegistryContext)3 CorrelationKey (org.kie.internal.process.CorrelationKey)3 EntityManager (javax.persistence.EntityManager)2 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)2 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)2 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)2 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)2 KieBase (org.kie.api.KieBase)2 Node (org.kie.api.definition.process.Node)2 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)2 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2