Skip to content

Commit 1b8b2a3

Browse files
committed
fix PublishEventsIT
1 parent ce6441b commit 1b8b2a3

File tree

9 files changed

+54
-13
lines changed

9 files changed

+54
-13
lines changed

api/kogito-api/src/main/java/org/kie/kogito/usertask/lifecycle/UserTaskState.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ public static UserTaskState initalized() {
7878
return of(null);
7979
}
8080

81+
@Override
82+
public String toString() {
83+
return "UserTaskState [terminate=" + terminate + ", name=" + name + "]";
84+
}
85+
8186
}

api/kogito-api/src/main/java/org/kie/kogito/usertask/model/UserTaskModel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.kie.kogito.usertask.model;
2020

21+
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
@@ -39,6 +40,12 @@ public class UserTaskModel {
3940
private Map<String, Object> inputs;
4041
private Map<String, Object> outputs;
4142

43+
private Map<String, Object> metadata;
44+
45+
public UserTaskModel() {
46+
this.metadata = new HashMap<>();
47+
}
48+
4249
public Map<String, Object> getInputs() {
4350
return inputs;
4451
}
@@ -192,5 +199,17 @@ public String getExternalReferenceId() {
192199
public void setExternalReferenceId(String externalReferenceId) {
193200
this.externalReferenceId = externalReferenceId;
194201
}
202+
203+
public void setMetadata(String key, Object value) {
204+
this.metadata.put(key, value);
205+
}
206+
207+
public Map<String, Object> getMetadata() {
208+
return metadata;
209+
}
210+
211+
public void setMetadata(Map<String, Object> metadata) {
212+
this.metadata = metadata;
213+
}
195214

196215
}

api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/adapter/UserTaskStateEventDataEventAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public DataEvent<?> adapt(Object payload) {
6161

6262
UserTaskInstanceStateEventBody body = builder.build();
6363
UserTaskInstanceStateDataEvent utEvent =
64-
new UserTaskInstanceStateDataEvent(AdapterHelper.buildSource(getConfig().service(), event.getUserTaskModel().getExternalReferenceId()), getConfig().addons().toString(),
64+
new UserTaskInstanceStateDataEvent(AdapterHelper.buildSource(getConfig().service(), (String) event.getUserTaskModel().getMetadata().get("ProcessId")), getConfig().addons().toString(),
6565
event.getEventUser(),
6666
metadata, body);
6767

jbpm/jbpm-usertask/src/main/java/org/kie/kogito/jbpm/usertask/handler/UserTaskKogitoWorkItemHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.kie.kogito.usertask.model.UserTaskModel;
4343

4444
import static java.util.Collections.emptyMap;
45+
import static java.util.Collections.singletonMap;
4546
import static java.util.Optional.ofNullable;
4647

4748
/**
@@ -130,7 +131,8 @@ static public Optional<WorkItemTransition> userTaskActivateWorkItemHandler(Kogit
130131
model.setTaskDescription((String) workItem.getParameter(DESCRIPTION));
131132
model.setTaskPriority(priorityInteger);
132133
model.setExternalReferenceId(workItem.getStringId());
133-
134+
model.setMetadata("ProcessId", workItem.getProcessInstance().getProcessId());
135+
134136
ofNullable(workItem.getParameters().get(ACTOR_ID)).map(String.class::cast).map(UserTaskKogitoWorkItemHandler::toSet).ifPresent(model::setPotentialUsers);
135137
ofNullable(workItem.getParameters().get(GROUP_ID)).map(String.class::cast).map(UserTaskKogitoWorkItemHandler::toSet).ifPresent(model::setPotentialGroups);
136138
ofNullable(workItem.getParameters().get(BUSINESSADMINISTRATOR_ID)).map(String.class::cast).map(UserTaskKogitoWorkItemHandler::toSet).ifPresent(model::setAdminUsers);
@@ -140,14 +142,13 @@ static public Optional<WorkItemTransition> userTaskActivateWorkItemHandler(Kogit
140142
UserTaskInstance instance = userTask.createInstance(model);
141143
if (workItem instanceof InternalKogitoWorkItem ikw) {
142144
ikw.setExternalReferenceId(instance.id());
143-
ikw.setActualOwner(instance.getActualOwner());
144145
}
145146

146147
instance.transition(instance.createTransitionToken("activate", emptyMap()));
147148
if (instance.getActualOwner() == null) {
148149
return Optional.empty();
149150
} else {
150-
return Optional.of(handler.newTransition(TRANSITION_ACTIVATED_CLAIM.id(), workItem.getPhaseStatus(), emptyMap()));
151+
return Optional.of(handler.newTransition(TRANSITION_ACTIVATED_CLAIM.id(), workItem.getPhaseStatus(), singletonMap("ACTUAL_OWNER", instance.getActualOwner())));
151152
}
152153
}
153154

@@ -172,7 +173,6 @@ static public Optional<WorkItemTransition> userTaskClaimWorkItemHandler(KogitoWo
172173
if (workItem instanceof InternalKogitoWorkItem ikw) {
173174
ikw.setActualOwner(ut.getActualOwner());
174175
}
175-
ut.transition(ut.createTransitionToken("claim", data));
176176
});
177177
return Optional.empty();
178178
}
@@ -202,7 +202,7 @@ static public Optional<WorkItemTransition> userTaskAbortWorkItemHandler(KogitoWo
202202
UserTasks userTasks = handler.getApplication().get(UserTasks.class);
203203
UserTask userTask = userTasks.userTaskById((String) workItem.getParameter("id"));
204204
userTask.instances().findById(workItem.getExternalReferenceId()).ifPresent(ut -> {
205-
ut.transition(ut.createTransitionToken("fail", emptyMap()));
205+
ut.transition(ut.createTransitionToken("skip", emptyMap()));
206206
});
207207
return Optional.empty();
208208
}

jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskInstance.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Collections;
2222
import java.util.HashSet;
2323
import java.util.Map;
24+
import java.util.Optional;
2425
import java.util.Set;
2526
import java.util.UUID;
2627

@@ -126,9 +127,16 @@ public UserTaskTransitionToken createTransitionToken(String transitionId, Map<St
126127

127128
@Override
128129
public void transition(UserTaskTransitionToken token) {
129-
UserTaskTransition transition = token.transition();
130-
this.setUserTaskLifeCycle.transition(this, token);
131-
userTaskEventSupport.fireOneUserTaskStateChange(this, transition.source().getName(), transition.target().getName());
130+
Optional<UserTaskTransitionToken> next = Optional.of(token);
131+
while (next.isPresent()) {
132+
UserTaskTransition transition = next.get().transition();
133+
next = this.setUserTaskLifeCycle.transition(this, token);
134+
this.status = transition.target();
135+
userTaskEventSupport.fireOneUserTaskStateChange(this, transition.source().getName(), transition.target().getName());
136+
if (this.status.isTerminate().isPresent()) {
137+
this.instances.remove(this.id);
138+
}
139+
}
132140
}
133141

134142
@Override

jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/lifecycle/DefaultUserTaskLifeCycle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public class DefaultUserTaskLifeCycle implements UserTaskLifeCycle {
4141
private static final UserTaskTransition T_NEW_ACTIVE = new DefaultUserTransition("activate", INACTIVE, ACTIVE, DefaultUserTaskLifeCycle::activate);
4242
private static final UserTaskTransition T_ACTIVE_RESERVED = new DefaultUserTransition("claim", ACTIVE, RESERVED, DefaultUserTaskLifeCycle::claim);
4343
private static final UserTaskTransition T_RESERVED_ACTIVE = new DefaultUserTransition("release", RESERVED, ACTIVE, DefaultUserTaskLifeCycle::release);
44+
private static final UserTaskTransition T_ACTIVE_COMPLETED = new DefaultUserTransition("complete", ACTIVE, COMPLETED, DefaultUserTaskLifeCycle::complete);
4445
private static final UserTaskTransition T_RESERVED_COMPLETED = new DefaultUserTransition("complete", RESERVED, COMPLETED, DefaultUserTaskLifeCycle::complete);
4546
private static final UserTaskTransition T_RESERVED_SKIPPED = new DefaultUserTransition("skip", RESERVED, OBSOLETE, DefaultUserTaskLifeCycle::skip);
47+
private static final UserTaskTransition T_ACTIVE_SKIPPED = new DefaultUserTransition("skip", ACTIVE, OBSOLETE, DefaultUserTaskLifeCycle::complete);
4648
private static final UserTaskTransition T_RESERVED_ERROR = new DefaultUserTransition("fail", RESERVED, ERROR, DefaultUserTaskLifeCycle::fail);
4749

4850
private List<UserTaskTransition> transitions;
@@ -52,7 +54,9 @@ public DefaultUserTaskLifeCycle() {
5254
T_NEW_ACTIVE,
5355
T_ACTIVE_RESERVED,
5456
T_RESERVED_ACTIVE,
57+
T_ACTIVE_COMPLETED,
5558
T_RESERVED_COMPLETED,
59+
T_ACTIVE_SKIPPED,
5660
T_RESERVED_SKIPPED,
5761
T_RESERVED_ERROR);
5862
}

jbpm/process-workitems/src/main/java/org/jbpm/process/workitem/builtin/SystemOutWorkItemHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public Optional<WorkItemTransition> abortWorkItemHandler(KogitoWorkItemManager m
3939
return Optional.of(this.workItemLifeCycle.newTransition("abort", workItem.getPhaseStatus(), workItem.getResults()));
4040
}
4141

42+
43+
@Override
44+
public String getName() {
45+
return "Log";
46+
}
4247
}

jbpm/process-workitems/src/main/java/org/kie/kogito/process/workitems/impl/KogitoWorkItemImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public String getExternalReferenceId() {
543543

544544
@Override
545545
public void setExternalReferenceId(String externalReferenceId) {
546-
this.externalReferenceId = id;
546+
this.externalReferenceId = externalReferenceId;
547547
}
548548

549549
@Override

kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/java/org/kie/kogito/codegen/tests/PublishEventIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void onUserTaskState(UserTaskStateEvent event) {
252252
left = findNodeInstanceEvents(events, 2);
253253
assertThat(left).hasSize(2).extractingResultOf("getNodeType").containsOnly("HumanTaskNode", "EndNode");
254254

255-
assertUserTaskInstanceEvent(events.get(1), "SecondTask", null, "1", "Completed", "UserTasksProcess", "Second Task");
255+
assertUserTaskInstanceEvent(events.get(0), "SecondTask", null, "1", "Completed", "UserTasksProcess", "Second Task");
256256
}
257257

258258
@Test
@@ -299,12 +299,12 @@ public void testBasicUserTaskProcessAbort() throws Exception {
299299
uow.end();
300300
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
301301
events = publisher.extract();
302-
assertThat(events).hasSize(4);
302+
assertThat(events).hasSize(3);
303303

304304
triggered = findNodeInstanceEvents(events, ProcessInstanceNodeEventBody.EVENT_TYPE_ABORTED);
305305
assertThat(triggered).hasSize(1).extractingResultOf("getNodeName").containsOnly("First Task");
306306

307-
assertProcessInstanceEvent(events.get(3), "UserTasksProcess", "UserTasksProcess", ProcessInstance.STATE_ABORTED);
307+
assertProcessInstanceEvent(events.get(2), "UserTasksProcess", "UserTasksProcess", ProcessInstance.STATE_ABORTED);
308308

309309
}
310310

0 commit comments

Comments
 (0)