diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLogger.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLogger.java index 25dbb5b909..fed845ac89 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLogger.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLogger.java @@ -35,7 +35,8 @@ public abstract class AbstractAuditLogger implements ProcessEventListener { public static final int BEFORE_VAR_CHANGE_EVENT_TYPE = 8; public static final int AFTER_VAR_CHANGE_EVENT_TYPE = 9; public static final int ON_ASYNC_NODE_EVENT_TYPE = 10; - + public static final int ON_DATA_CHANGE_EVENT_TYPE = 11; + protected AuditEventBuilder builder = new DefaultAuditEventBuilderImpl(); /* diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLoggerAdapter.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLoggerAdapter.java index 5ea3376c20..ad7e79fc44 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLoggerAdapter.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/AbstractAuditLoggerAdapter.java @@ -20,6 +20,7 @@ import org.jbpm.process.instance.impl.ProcessInstanceImpl; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.kie.api.event.process.ProcessCompletedEvent; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; @@ -145,4 +146,10 @@ public void afterSLAViolated(SLAViolatedEvent event) { protected abstract void slaProcessInstanceViolated(SLAViolatedEvent event); + @Override + public void onProcessDataChangedEvent(ProcessDataChangedEvent event){ + processDataChanged(event); + } + + protected abstract void processDataChanged(ProcessDataChangedEvent event); } diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java index 57ce2289d9..566fcaf15c 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/JPAWorkingMemoryDbLogger.java @@ -44,6 +44,7 @@ import org.jbpm.process.core.impl.ProcessImpl; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; import org.kie.api.event.process.ProcessCompletedEvent; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessEventListener; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; @@ -181,6 +182,27 @@ protected void processStarted(ProcessStartedEvent event) { persist(log, event); } + @Override + protected void processDataChanged(ProcessDataChangedEvent event) { + EntityManager em = getEntityManager(event); + Object tx = joinTransaction(em); + long processInstanceId = event.getProcessInstance().getId(); + ProcessInstanceLog log = (ProcessInstanceLog) getProcessInstanceMetadata(event.getProcessInstance(), METADATA_PROCESSINTANCE_LOG); + if (log == null) { + List result = em.createQuery("from ProcessInstanceLog as log where log.processInstanceId = :piId and log.end is null") + .setParameter("piId", processInstanceId).getResultList(); + if (result != null && !result.isEmpty()) { + log = result.get(result.size() - 1); + } + } + if (log != null) { + log.setSlaCompliance(((ProcessInstance) event.getProcessInstance()).getSlaCompliance()); + log.setSlaDueDate(((ProcessInstance) event.getProcessInstance()).getSlaDueDate()); + setProcessInstanceMetadata(event.getProcessInstance(), METADATA_PROCESSINTANCE_LOG, log); + em.merge(log); + } + leaveTransaction(em, tx); + } @Override protected void processCompleted(ProcessCompletedEvent event) { @@ -227,6 +249,7 @@ protected void slaProcessInstanceViolated(SLAViolatedEvent event) { } if (log != null) { log.setSlaCompliance(((ProcessInstance) event.getProcessInstance()).getSlaCompliance()); + log.setSlaDueDate(((ProcessInstance) event.getProcessInstance()).getSlaDueDate()); setProcessInstanceMetadata(event.getProcessInstance(), METADATA_PROCESSINTANCE_LOG, log); em.merge(log); } @@ -252,6 +275,7 @@ protected void slaNodeInstanceViolated(SLAViolatedEvent event) { } if (log != null) { log.setSlaCompliance(((NodeInstance) event.getNodeInstance()).getSlaCompliance()); + log.setSlaDueDate(((ProcessInstance) event.getProcessInstance()).getSlaDueDate()); setNodeInstanceMetadata(event.getNodeInstance(), METADATA_NODEINSTANCE_LOG, log); ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().put(METADATA_NODEINSTANCE_LOG, log); em.merge(log); diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/event/AuditEventBuilder.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/event/AuditEventBuilder.java index 044a110d7a..259c2bfb02 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/event/AuditEventBuilder.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/event/AuditEventBuilder.java @@ -16,6 +16,7 @@ package org.jbpm.process.audit.event; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; @@ -38,4 +39,6 @@ public interface AuditEventBuilder { AuditEvent buildEvent(ProcessAsyncNodeScheduledEvent pnle); AuditEvent buildEvent(ProcessVariableChangedEvent pvce); + + AuditEvent buildEvent(ProcessDataChangedEvent pdce); } diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/event/DefaultAuditEventBuilderImpl.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/event/DefaultAuditEventBuilderImpl.java index 107ac72de3..13f7a5ee02 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/event/DefaultAuditEventBuilderImpl.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/event/DefaultAuditEventBuilderImpl.java @@ -32,6 +32,7 @@ import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.event.process.ProcessVariableChangedEvent; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.NodeInstance; import org.kie.api.runtime.process.ProcessInstance; @@ -256,6 +257,28 @@ public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) { return log; } + @Override + public AuditEvent buildEvent(ProcessDataChangedEvent pdce) { + ProcessInstanceImpl pi = (ProcessInstanceImpl) pdce.getProcessInstance(); + ProcessInstanceLog logEvent = new ProcessInstanceLog(pi.getId(), pi.getProcessId()); + logEvent.setOutcome(pi.getOutcome()); + logEvent.setStatus(pi.getState()); + logEvent.setProcessInstanceDescription( pi.getDescription() ); + logEvent.setSlaCompliance(pi.getSlaCompliance()); + logEvent.setSlaDueDate(pi.getSlaDueDate()); + logEvent.setProcessName(pi.getProcess().getName()); + logEvent.setProcessVersion(pi.getProcess().getVersion()); + logEvent.setProcessType(((WorkflowProcess)pi.getProcess()).getProcessType()); + // store correlation key in its external form + CorrelationKey correlationKey = (CorrelationKey) pi.getMetaData().get("CorrelationKey"); + if (correlationKey != null) { + logEvent.setCorrelationKey(correlationKey.toExternalForm()); + } + long parentProcessInstanceId = (Long) pi.getMetaData().getOrDefault("ParentProcessInstanceId", -1L); + logEvent.setParentProcessInstanceId(parentProcessInstanceId); + return logEvent; + } + protected String getNodeContainerId(NodeContainer nodeContainer) { if (nodeContainer instanceof Node) { return (String) ((Node) nodeContainer).getMetaData().get("UniqueId"); diff --git a/jbpm-audit/src/main/java/org/jbpm/process/audit/jms/AsyncAuditLogProducer.java b/jbpm-audit/src/main/java/org/jbpm/process/audit/jms/AsyncAuditLogProducer.java index ff927ee0aa..ba5b32ea8e 100644 --- a/jbpm-audit/src/main/java/org/jbpm/process/audit/jms/AsyncAuditLogProducer.java +++ b/jbpm-audit/src/main/java/org/jbpm/process/audit/jms/AsyncAuditLogProducer.java @@ -33,6 +33,7 @@ import org.jbpm.process.audit.variable.ProcessIndexerManager; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.kie.api.event.process.ProcessCompletedEvent; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; @@ -185,7 +186,13 @@ public void afterProcessStarted(ProcessStartedEvent event) { @Override public void beforeProcessCompleted(ProcessCompletedEvent event) { } - + + @Override + public void onProcessDataChangedEvent(ProcessDataChangedEvent event) { + ProcessInstanceLog log = (ProcessInstanceLog) builder.buildEvent(event); + sendMessage(log, ON_DATA_CHANGE_EVENT_TYPE, 9); + } + protected void sendMessage(Object messageContent, Integer eventType, int priority) { if (connectionFactory == null && queue == null) { throw new IllegalStateException("ConnectionFactory and Queue cannot be null"); diff --git a/jbpm-flow/src/main/java/org/jbpm/process/instance/command/UpdateTimerCommand.java b/jbpm-flow/src/main/java/org/jbpm/process/instance/command/UpdateTimerCommand.java index 38734c7a63..0907d72914 100644 --- a/jbpm-flow/src/main/java/org/jbpm/process/instance/command/UpdateTimerCommand.java +++ b/jbpm-flow/src/main/java/org/jbpm/process/instance/command/UpdateTimerCommand.java @@ -27,8 +27,10 @@ import org.drools.core.command.SingleSessionCommandService; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; +import org.drools.core.common.InternalKnowledgeRuntime; import org.drools.core.impl.StatefulKnowledgeSessionImpl; import org.jbpm.process.instance.InternalProcessRuntime; +import org.jbpm.process.instance.ProcessInstance; import org.jbpm.process.instance.timer.TimerInstance; import org.jbpm.process.instance.timer.TimerManager; import org.jbpm.ruleflow.instance.RuleFlowProcessInstance; @@ -135,6 +137,7 @@ public Void execute(Context context ) { if (newTimer != null) { wfp.internalSetSlaTimerId(newTimer.getId()); wfp.internalSetSlaDueDate(new Date(System.currentTimeMillis() + newTimer.getDelay())); + fireProcessInstanceDataChangedEvent(wfp); return null; } @@ -239,4 +242,10 @@ protected TimerInstance rescheduleTimer(TimerInstance timer, TimerManager tm) { return newTimer; } + + private void fireProcessInstanceDataChangedEvent(ProcessInstance processInstance){ + InternalKnowledgeRuntime kruntime = processInstance.getKnowledgeRuntime(); + InternalProcessRuntime processRuntime = (InternalProcessRuntime) kruntime.getProcessRuntime(); + processRuntime.getProcessEventSupport().fireAfterProcessDataChanged(processInstance, kruntime); + } } diff --git a/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/ManagedAuditEventBuilderImpl.java b/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/ManagedAuditEventBuilderImpl.java index b227d5c819..23c9941b6b 100644 --- a/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/ManagedAuditEventBuilderImpl.java +++ b/jbpm-runtime-manager/src/main/java/org/jbpm/runtime/manager/impl/ManagedAuditEventBuilderImpl.java @@ -21,6 +21,7 @@ import org.jbpm.process.audit.VariableInstanceLog; import org.jbpm.process.audit.event.AuditEvent; import org.jbpm.process.audit.event.DefaultAuditEventBuilderImpl; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; @@ -77,6 +78,13 @@ public AuditEvent buildEvent(ProcessAsyncNodeScheduledEvent pnse) { return nodeInstanceLog; } + @Override + public AuditEvent buildEvent(ProcessDataChangedEvent pdce) { + ProcessInstanceLog instanceLog = (ProcessInstanceLog) super.buildEvent(pdce); + instanceLog.setExternalId(ownerId); + return instanceLog; + } + public String getOwnerId() { return ownerId; } diff --git a/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/audit/ServicesAwareAuditEventBuilder.java b/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/audit/ServicesAwareAuditEventBuilder.java index 272dc79425..a24a962f59 100644 --- a/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/audit/ServicesAwareAuditEventBuilder.java +++ b/jbpm-services/jbpm-kie-services/src/main/java/org/jbpm/kie/services/impl/audit/ServicesAwareAuditEventBuilder.java @@ -25,6 +25,7 @@ import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.instance.ProcessInstance; import org.jbpm.process.instance.context.variable.VariableScopeInstance; +import org.kie.api.event.process.ProcessDataChangedEvent; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessAsyncNodeScheduledEvent; @@ -96,6 +97,13 @@ public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) { return variableLog; } + @Override + public AuditEvent buildEvent(ProcessDataChangedEvent pdce) { + ProcessInstanceLog instanceLog = (ProcessInstanceLog) super.buildEvent(pdce); + instanceLog.setExternalId(deploymentUnitId); + return instanceLog; + } + public String getDeploymentUnitId() { return deploymentUnitId; }