Search in sources :

Example 16 with ProcessInstanceLog

use of org.jbpm.process.audit.ProcessInstanceLog 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 17 with ProcessInstanceLog

use of org.jbpm.process.audit.ProcessInstanceLog 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 18 with ProcessInstanceLog

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

the class AuditTaskDeleteTest method produceTaskInstances.

private void produceTaskInstances() {
    InternalTaskService taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    Calendar cal = randomCal();
    String processId = "process";
    taskTestData = new Task[10];
    List<ProcessInstanceLog> pLogs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").setProcessId(processId + i).setProcessInstanceId(i).setCreatedOn(cal.getTime()).getTask();
        taskService.addTask(task, new HashMap<String, Object>());
        taskTestData[i] = task;
        ProcessInstanceLog plog = buildCompletedProcessInstance(i);
        pLogs.add(plog);
    }
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    Object tx = jtaHelper.joinTransaction(em);
    pLogs.forEach(pl -> {
        em.persist(pl);
    });
    jtaHelper.leaveTransaction(em, tx);
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskFluent(org.jbpm.services.task.utils.TaskFluent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) EntityManager(javax.persistence.EntityManager) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 19 with ProcessInstanceLog

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

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerComplete.

@Test
public void testAsyncAuditLoggerComplete() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 2000, 11);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(processInstance.getId()).isEqualTo(nodeInstance.getProcessInstanceId().longValue());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow");
    logService.dispose();
    Assertions.assertThat(processInstances).isEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 20 with ProcessInstanceLog

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

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariables.

@Test
public void testAsyncAuditLoggerCompleteWithVariables() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", "test value");
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow3", params);
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 3000, 13);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow3");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    // verify variables
    List<VariableInstanceLog> variables = logService.findVariableInstances(processInstance.getId());
    Assertions.assertThat(variables).isNotNull();
    Assertions.assertThat(variables).hasSize(2);
    VariableInstanceLog var = variables.get(0);
    // initial value from rule flow definition
    Assertions.assertThat(var.getValue()).isEqualTo("InitialValue");
    Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
    Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
    Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
    Assertions.assertThat(var.getVariableId()).isEqualTo("s");
    Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
    // value given at process start
    var = variables.get(1);
    // initial value from rule flow definition
    Assertions.assertThat(var.getValue()).isEqualTo("test value");
    Assertions.assertThat(var.getOldValue()).isEqualTo("InitialValue");
    Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
    Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
    Assertions.assertThat(var.getVariableId()).isEqualTo("s");
    Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    logService.dispose();
    Assertions.assertThat(processInstances).isNullOrEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)27 Test (org.junit.Test)9 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)8 KieBase (org.kie.api.KieBase)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)7 HashMap (java.util.HashMap)6 EntityManager (javax.persistence.EntityManager)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 AuditLogService (org.jbpm.process.audit.AuditLogService)6 KieSession (org.kie.api.runtime.KieSession)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 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 Environment (org.kie.api.runtime.Environment)4 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)3