Skip to content

Commit

Permalink
fix job data event
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Nov 9, 2023
1 parent 8367051 commit a91f104
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ default boolean isCancelled() {

Date getSlaDueDate();

default Map<String, Object> getMetadata() {
default Map<String, Object> getMetaData() {
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.kie.kogito.internal.process.event.KogitoProcessVariableChangedEvent;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance;
import org.kie.kogito.process.workitem.HumanTaskWorkItem;
Expand Down Expand Up @@ -149,6 +150,7 @@ private void handleProcesssVariableEvent(ProcessVariableChangedEvent event) {

private void handleProcesssNodeEvent(SLAViolatedEvent event) {
Map<String, Object> metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance());
KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance();

ProcessInstanceSLAEventBody.Builder builder = ProcessInstanceSLAEventBody.create()
.eventDate(new Date())
Expand All @@ -165,8 +167,9 @@ private void handleProcesssNodeEvent(SLAViolatedEvent event) {
}

ProcessInstanceSLAEventBody body = builder.build();
ProcessInstanceSLADataEvent pieEvent = new ProcessInstanceSLADataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body);
processedEvents.add(pieEvent);
ProcessInstanceSLADataEvent piEvent = new ProcessInstanceSLADataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body);
piEvent.setKogitoBusinessKey(pi.getBusinessKey());
processedEvents.add(piEvent);
}

private void handleProcesssNodeEvent(ProcessNodeLeftEvent event) {
Expand Down Expand Up @@ -212,11 +215,19 @@ private ProcessInstanceNodeDataEvent toProcessInstanceNodeEvent(ProcessNodeEvent
.nodeType(event.getNodeInstance().getNode().getClass().getSimpleName())
.nodeInstanceId(event.getNodeInstance().getId())
.nodeDefinitionId(event.getNodeInstance().getNode().getNodeUniqueId())
.slaDueDate(nodeInstance.getSlaDueDate())
.connectionNodeDefinitionId((String) nodeInstance.getMetadata().get("OutgoingConnection"));
.slaDueDate(nodeInstance.getSlaDueDate());

if (eventType == ProcessInstanceNodeEventBody.EVENT_TYPE_ENTER) {
builder.connectionNodeDefinitionId((String) nodeInstance.getMetaData().get("IncomingConnection"));
} else {
builder.connectionNodeDefinitionId((String) nodeInstance.getMetaData().get("OutgoingConnection"));
}

if (nodeInstance instanceof KogitoWorkItemNodeInstance) {
builder.workItemId(((KogitoWorkItemNodeInstance) nodeInstance).getWorkItem().getStringId());
KogitoWorkItem workItem = ((KogitoWorkItemNodeInstance) nodeInstance).getWorkItem();
if (workItem != null) {
builder.workItemId(workItem.getStringId());
}
}

ProcessInstanceNodeEventBody body = builder.build();
Expand Down Expand Up @@ -464,6 +475,9 @@ private void handleUserTaskDeadlineEvent(UserTaskDeadlineEvent event) {
}

private void handleUserTaskStateEvent(UserTaskStateEvent event) {
if (event.getNewStatus() == null) {
return;
}
Map<String, Object> metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem());
metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()));
KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kie.kogito.event.job;

import org.kie.kogito.event.AbstractDataEvent;

public class JobInstanceDataEvent extends AbstractDataEvent<byte[]> {

public JobInstanceDataEvent(String type,
String source,
byte[] data,
String kogitoProcessInstanceId,
String kogitoRootProcessInstanceId,
String kogitoProcessId,
String kogitoRootProcessId,
String kogitoIdentity) {
super(type, source, data, kogitoProcessInstanceId, kogitoRootProcessInstanceId, kogitoProcessId,
kogitoRootProcessId, null, kogitoIdentity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,18 @@ public void setTaskName(String taskName) {
@Override
public void setTaskDescription(String taskDescription) {
delegate.setTaskDescription(taskDescription);
if (delegate.getPhaseStatus() == null) {
return;
}
getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), delegate.getPhaseStatus(), delegate.getPhaseStatus()));
}

@Override
public void setTaskPriority(String taskPriority) {
delegate.setTaskPriority(taskPriority);
if (delegate.getPhaseStatus() == null) {
return;
}
getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), delegate.getPhaseStatus(), delegate.getPhaseStatus()));
}

Expand All @@ -405,6 +411,9 @@ public void setReferenceName(String referenceName) {
public void setActualOwner(String actualOwner) {
String currentPhaseStatus = delegate.getPhaseStatus();
delegate.setActualOwner(actualOwner);
if (currentPhaseStatus == null) {
return;
}
getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), currentPhaseStatus, currentPhaseStatus));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ public String getUniqueId() {
return result.toString();
}

@Override
public Map<String, Object> getMetaData() {
return this.metaData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public List<NodeInstance> getNodeInstances(final long nodeId, final List<NodeIns

@Override
public String getBusinessKey() {
return correlationKey;
return getCorrelationKey();
}

@Override
Expand Down

0 comments on commit a91f104

Please sign in to comment.