jomarko commented on code in PR #4105:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4105#discussion_r2497425529
##########
jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskConfig.java:
##########
@@ -67,18 +67,17 @@ public DefaultUserTaskConfig(
Iterable<UnitOfWorkManager> unitOfWorkManager,
Iterable<JobsService> jobService,
Iterable<IdentityProvider> identityProvider,
- Iterable<UserTaskLifeCycle> userTaskLifeCycle,
+ Iterable<UserTaskLifeCycles> userTaskLifeCycles,
Review Comment:
very minor comment, it seems this API has multiple `Iterable` parameters,
but we do not use plural for them.
we have
```
Iterable<UnitOfWorkManager> unitOfWorkManager,
Iterable<JobsService> jobService,
Iterable<IdentityProvider> identityProvider,
```
We do not have
```
Iterable<UnitOfWorkManager> unitOfWorkManagers,
Iterable<JobsService> jobServices,
Iterable<IdentityProvider> identityProviders,
```
so just asking if we want `userTaskLifeCycles` or `userTaskLifeCycle`. The
second one would be more consistent with the exisiting naming, but I am fine
with any decision we make here, however wanted to ask.
##########
jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/lifecycle/WsHumanTaskLifeCycle.java:
##########
@@ -0,0 +1,429 @@
+/*
+ * 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.usertask.impl.lifecycle;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import org.kie.kogito.auth.IdentityProvider;
+import org.kie.kogito.usertask.UserTaskAssignmentStrategy;
+import org.kie.kogito.usertask.UserTaskInstance;
+import org.kie.kogito.usertask.UserTaskInstanceNotAuthorizedException;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycle;
+import org.kie.kogito.usertask.lifecycle.UserTaskState;
+import org.kie.kogito.usertask.lifecycle.UserTaskState.TerminationType;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransition;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransitionException;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransitionToken;
+
+public class WsHumanTaskLifeCycle implements UserTaskLifeCycle {
+ public static final String WORKFLOW_ENGINE_USER = "WORKFLOW_ENGINE_USER";
+
+ public static final String PARAMETER_USER = "USER";
+ public static final String PARAMETER_NOTIFY = "NOTIFY";
+ private static final String PARAMETER_DELEGATED_USER = "DELEGATED_USER";
+ private static final String PARAMETER_FORWARDED_USERS = "FORWARDED_USERS";
+ private static final String PARAMETER_NOMINATED_USERS = "NOMINATED_USERS";
+
+ private static final String SKIPPABLE = "Skippable";
+
+ // Actions
+ public static final String ACTIVATE = "activate";
+ public static final String NOMINATE = "nominate";
+ public static final String CLAIM = "claim";
+ public static final String DELEGATE = "delegate";
+ public static final String RELEASE = "release";
+ public static final String FORWARD = "forward";
+ public static final String START = "start";
+ public static final String STOP = "stop";
+ public static final String COMPLETE = "complete";
+ public static final String FAIL = "fail";
+ public static final String FAULT = "fault";
+ public static final String EXIT = "exit";
+ public static final String SKIP = "skip";
+ public static final String SUSPEND = "suspend";
+ public static final String RESUME = "resume";
+
+ public static final UserTaskState CREATED = UserTaskState.initalized();
+ public static final UserTaskState READY = UserTaskState.of("Ready");
+ public static final UserTaskState RESERVED = UserTaskState.of("Reserved");
+ public static final UserTaskState INPROGRESS =
UserTaskState.of("InProgress");
+ public static final UserTaskState COMPLETED =
UserTaskState.of("Completed", TerminationType.COMPLETED);
+ public static final UserTaskState FAILED = UserTaskState.of("Failed",
TerminationType.FAILED);
+ public static final UserTaskState ERROR = UserTaskState.of("Error",
TerminationType.ERROR);
+ public static final UserTaskState EXITED = UserTaskState.of("Exited",
TerminationType.EXITED);
+ public static final UserTaskState OBSOLETE = UserTaskState.of("Obsolete",
TerminationType.OBSOLETE);
+ public static final UserTaskState SUSPENDED =
UserTaskState.of("Suspended");
+
+ private final UserTaskTransition T_CREATED_READY_ACTIVATE = new
DefaultUserTransition(ACTIVATE, CREATED, READY, this::activate);
+ private final UserTaskTransition T_CREATED_READY_NOMINATE = new
DefaultUserTransition(NOMINATE, CREATED, READY, this::nominate);
+
+ private final UserTaskTransition T_READY_READY_FORWARD = new
DefaultUserTransition(FORWARD, READY, READY, this::forward);
+ private final UserTaskTransition T_READY_RESERVED_CLAIM = new
DefaultUserTransition(CLAIM, READY, RESERVED, this::claim);
+ private final UserTaskTransition T_READY_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, READY, RESERVED, this::delegate);
+ private final UserTaskTransition T_READY_INPROGRESS = new
DefaultUserTransition(START, READY, INPROGRESS, this::start);
+ private final UserTaskTransition T_READY_ERROR = new
DefaultUserTransition(FAULT, READY, ERROR, this::fault);
+ private final UserTaskTransition T_READY_EXITED = new
DefaultUserTransition(EXIT, READY, EXITED, this::exit);
+ private final UserTaskTransition T_READY_OBSOLETE = new
DefaultUserTransition(SKIP, READY, OBSOLETE, this::skip);
+ private final UserTaskTransition T_READY_SUSPENDED = new
DefaultUserTransition(SUSPEND, READY, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_RESERVED_READY_RELEASE = new
DefaultUserTransition(RELEASE, RESERVED, READY, this::release);
+ private final UserTaskTransition T_RESERVED_READY_FORWARD = new
DefaultUserTransition(FORWARD, RESERVED, READY, this::forward);
+ private final UserTaskTransition T_RESERVED_INPROGRESS = new
DefaultUserTransition(START, RESERVED, INPROGRESS, this::start);
+ private final UserTaskTransition T_RESERVED_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, RESERVED, RESERVED, this::delegate);
+ private final UserTaskTransition T_RESERVED_ERROR = new
DefaultUserTransition(FAULT, RESERVED, ERROR, this::fault);
+ private final UserTaskTransition T_RESERVED_EXITED = new
DefaultUserTransition(EXIT, RESERVED, EXITED, this::exit);
+ private final UserTaskTransition T_RESERVED_OBSOLETE = new
DefaultUserTransition(SKIP, RESERVED, OBSOLETE, this::skip);
+ private final UserTaskTransition T_RESERVED_SUSPENDED = new
DefaultUserTransition(SUSPEND, RESERVED, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_INPROGRESS_RESERVED_STOP = new
DefaultUserTransition(STOP, INPROGRESS, RESERVED, this::stop);
+ private final UserTaskTransition T_INPROGRESS_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, INPROGRESS, RESERVED, this::delegate);
+ private final UserTaskTransition T_INPROGRESS_READY_RELEASE = new
DefaultUserTransition(RELEASE, INPROGRESS, READY, this::release);
+ private final UserTaskTransition T_INPROGRESS_READY_FORWARD = new
DefaultUserTransition(FORWARD, INPROGRESS, READY, this::forward);
+ private final UserTaskTransition T_INPROGRESS_COMPLETED = new
DefaultUserTransition(COMPLETE, INPROGRESS, COMPLETED, this::complete);
+ private final UserTaskTransition T_INPROGRESS_FAILED = new
DefaultUserTransition(FAIL, INPROGRESS, FAILED, this::fail);
+ private final UserTaskTransition T_INPROGRESS_ERROR = new
DefaultUserTransition(FAULT, INPROGRESS, ERROR, this::fault);
+ private final UserTaskTransition T_INPROGRESS_EXITED = new
DefaultUserTransition(EXIT, INPROGRESS, EXITED, this::exit);
+ private final UserTaskTransition T_INPROGRESS_OBSOLETE = new
DefaultUserTransition(SKIP, INPROGRESS, OBSOLETE, this::skip);
+ private final UserTaskTransition T_INPROGRESS_SUSPENDED = new
DefaultUserTransition(SUSPEND, INPROGRESS, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_SUSPENDED_READY = new
DefaultUserTransition(RESUME, SUSPENDED, READY, this::resume);
+ private final UserTaskTransition T_SUSPENDED_RESERVED = new
DefaultUserTransition(RESUME, SUSPENDED, RESERVED, this::resume);
+ private final UserTaskTransition T_SUSPENDED_INPROGRESS = new
DefaultUserTransition(RESUME, SUSPENDED, INPROGRESS, this::resume);
Review Comment:
minor comment, we do not have consistent naming for transitions, we mix
`T_FROM_TO` and `T_FROM_TO_ACTION
##########
api/kogito-api/src/main/java/org/kie/kogito/usertask/lifecycle/UserTaskLifeCycles.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.usertask.lifecycle;
+
+public interface UserTaskLifeCycles {
+
+ String getDefaultUserTaskLifeCycleId();
+
+ UserTaskLifeCycle getUserTaskLifeCycleById(String userTaskLifeCycleId);
Review Comment:
Am I correct on this place I can pass `kogito` and `ws-human-task` as a
`userTaskLifeCycleId`?
My assumption is because of:
```
private void registerUserTaskLifeCycles() {
registerUserTaskLifeCycle("kogito", new DefaultUserTaskLifeCycle());
registerUserTaskLifeCycle("ws-human-task", new
WsHumanTaskLifeCycle());
}
```
Me, as new user of this API, I really miss this information, what values
should I use for `userTaskLifeCycleId`? Not sure if possible, but asking,
wouldn't be possible to change `String userTaskLifeCycleId` to
`UserTaskLifeCycleId userTaskLifeCycleId` where `UserTaskLifeCycleId` is an
enumeration? Then all string occurences of `kogito` and `ws-human-task` could
be replaced with this enumeration. The `UserTaskLifeCycleId` is just proposal,
for sure it could have other, maybe better name. What do you think?
Or would it be possible to add at least some javadoc, what values should be
used here in the API?
##########
quarkus/integration-tests/integration-tests-quarkus-wshumantasks/src/test/java/org/jbpm/userTask/jpa/it/WsHumanTaskLifeCycleIT.java:
##########
@@ -0,0 +1,550 @@
+/*
+ * 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.jbpm.userTask.jpa.it;
Review Comment:
minor thing, but this is not java convention to have uppercase letter in
package name.
##########
quarkus/integration-tests/integration-tests-quarkus-wshumantasks/src/test/java/org/jbpm/userTask/jpa/it/WsHumanTaskLifeCycleIT.java:
##########
@@ -0,0 +1,550 @@
+/*
+ * 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.jbpm.userTask.jpa.it;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.testcontainers.quarkus.PostgreSqlQuarkusTestResource;
+import org.kie.kogito.usertask.model.TransitionInfo;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.emptyOrNullString;
+
+@QuarkusIntegrationTest
+@QuarkusTestResource(value = PostgreSqlQuarkusTestResource.class,
restrictToAnnotatedClass = true)
+public class WsHumanTaskLifeCycleIT {
+ public static final String USER_TASKS_ENDPOINT = "/usertasks/instance";
+ public static final String USER_TASKS_INSTANCE_ENDPOINT =
USER_TASKS_ENDPOINT + "/{taskId}";
+ public static final String USER_TASKS_INSTANCE_TRANSITION_ENDPOINT =
USER_TASKS_INSTANCE_ENDPOINT + "/transition";
+
+ static {
+ RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+ }
+
+ @Test
+ public void testUserTaskLifeCycle() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+ claim(taskId, user);
+ start(taskId, user);
+ complete(taskId, user);
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testForwardTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var forwardedUsers = new String[] { "mark", "eric" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+ potentialUsers = forward(taskId, user, potentialUsers,
forwardedUsers).toArray(String[]::new);
+
+ user = "mark";
+ claim(taskId, user);
+ forwardedUsers = new String[] { "adam" };
+ potentialUsers = forward(taskId, user, potentialUsers,
forwardedUsers).toArray(String[]::new);
+
+ user = "adam";
+ claim(taskId, user);
+ forwardedUsers = new String[] { "bob" };
+ potentialUsers = forward(taskId, user, potentialUsers,
forwardedUsers).toArray(String[]::new);
+
+ user = "bob";
+ claim(taskId, user);
+ start(taskId, user);
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testDelegateTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ var delegatedUser = "adam";
+ potentialUsers = delegate(taskId, user, potentialUsers,
delegatedUser).toArray(String[]::new);
+
+ user = "adam";
+ delegatedUser = "john";
+ potentialUsers = delegate(taskId, user, potentialUsers,
delegatedUser).toArray(String[]::new);
+
+ user = "john";
+ start(taskId, user);
+ delegatedUser = "mark";
+ potentialUsers = delegate(taskId, user, potentialUsers,
delegatedUser).toArray(String[]::new);
+
+ user = "mark";
+ start(taskId, user);
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testReleaseTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ release(taskId, user);
+
+ user = "john";
+ claim(taskId, user);
+ start(taskId, user);
+ release(taskId, user);
+
+ user = "dave";
+ claim(taskId, user);
+ start(taskId, user);
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testStopTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ start(taskId, user);
+ stop(taskId, user);
+
+ start(taskId, user);
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testFailTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ start(taskId, user);
+ fail(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testSuspendAndResumeTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ suspend(taskId, user);
+ resume(taskId, user, "Ready");
+
+ claim(taskId, user);
+ suspend(taskId, user);
+ resume(taskId, user, "Reserved");
+
+ start(taskId, user);
+ suspend(taskId, user);
+ resume(taskId, user, "InProgress");
+
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testSkipTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ start(taskId, user);
+ skip(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testFaultTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ start(taskId, user);
+ fault(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testExitTransition() {
+ var user = "dave";
+ var potentialUsers = new String[] { "john", "dave" };
+ var processId = "manager_multiple_users";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId(user);
+ verifyTask(processId, pid, taskId, user, "Ready", potentialUsers);
+
+ claim(taskId, user);
+ start(taskId, user);
+ exit(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ @Test
+ public void testNominateTransition() {
+ var user = "carl";
+ var processId = "manager_admin";
+ var pid = startProcessInstance(processId);
+ var taskId = getTaskId("carl");
+ verifyTask(processId, pid, taskId, user, "Created", new String[] {});
+
+ var nominatedUsers = new String[] { "john", "dave" };
+ nominate(taskId, user, "Ready", nominatedUsers);
+
+ user = "john";
+ start(taskId, user);
+ complete(taskId, user);
+
+ isProcessCompleted(processId);
+ }
+
+ private void nominate(String taskId, String user, String status, String[]
nominatedUsers) {
+ given()
+ .contentType(ContentType.JSON)
+ .when()
+ .queryParam("user", user)
+ .body(new TransitionInfo("nominate", Map.of("NOMINATED_USERS",
nominatedUsers)))
+ .post(USER_TASKS_INSTANCE_TRANSITION_ENDPOINT, taskId)
+ .then()
+ .statusCode(200)
+ .body("id", equalTo(taskId))
+ .body("status.name", equalTo(status))
+ .body("status.terminate", equalTo(null))
+ .body("potentialUsers", hasItems(nominatedUsers));
+ }
Review Comment:
I was reviewing the test setup and noticed that we have these private
methods (nominate, claim, start ....) duplicated between the Quarkus and Spring
Boot modules. Since these methods are crucial for testing task transitions,
would it make sense to move them into a shared module like kogito-test-utils?
This would help us avoid potential desynchronization issues and make
maintenance easier going forward.
Let me know what you think.
##########
jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/lifecycle/DefaultUserTaskLifeCycles.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.usertask.impl.lifecycle;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycle;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycleException;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultUserTaskLifeCycles implements UserTaskLifeCycles {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(DefaultUserTaskLifeCycles.class);
+
+ private final Map<String, UserTaskLifeCycle> userTaskLifeCycleRegistry =
new HashMap<>();
+ private String defaultUserTaskLifeCycleId;
+
+ public DefaultUserTaskLifeCycles() {
+ this.defaultUserTaskLifeCycleId = "kogito";
+ registerUserTaskLifeCycles();
+ LOG.info("Registered UserTaskLifeCycles {} with default lifecycle:
{}", userTaskLifeCycleRegistry, this.defaultUserTaskLifeCycleId);
+ }
+
+ public DefaultUserTaskLifeCycles(String defaultUserTaskLifeCycleId,
Iterable<UserTaskLifeCycle> userTaskLifeCycle) {
+ this.defaultUserTaskLifeCycleId = defaultUserTaskLifeCycleId;
+ registerCustomUserTaskLifeCycleIfAny(userTaskLifeCycle);
+ registerUserTaskLifeCycles();
+ LOG.info("Registered UserTaskLifeCycles {} with default lifecycle:
{}", userTaskLifeCycleRegistry, this.defaultUserTaskLifeCycleId);
+ }
Review Comment:
Is this constructor actually needed? I do not see its usage in our codebase.
It is also , for me as newcomer, not easy to understand the use of `Iterable`
for `userTaskLifeCycle`. Because looking on
`registerCustomUserTaskLifeCycleIfAny`, we force `userTaskLifeCycle` to be
always collection of maximal size 1. Shouldn't then, if the constructor is
needed, be `Iterable` replaced with `Optional`? Optional is self documented
class - it is from definition zero or one element size.
##########
jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/lifecycle/DefaultUserTaskLifeCycles.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.usertask.impl.lifecycle;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycle;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycleException;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultUserTaskLifeCycles implements UserTaskLifeCycles {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(DefaultUserTaskLifeCycles.class);
+
+ private final Map<String, UserTaskLifeCycle> userTaskLifeCycleRegistry =
new HashMap<>();
+ private String defaultUserTaskLifeCycleId;
+
+ public DefaultUserTaskLifeCycles() {
+ this.defaultUserTaskLifeCycleId = "kogito";
+ registerUserTaskLifeCycles();
+ LOG.info("Registered UserTaskLifeCycles {} with default lifecycle:
{}", userTaskLifeCycleRegistry, this.defaultUserTaskLifeCycleId);
+ }
+
+ public DefaultUserTaskLifeCycles(String defaultUserTaskLifeCycleId,
Iterable<UserTaskLifeCycle> userTaskLifeCycle) {
+ this.defaultUserTaskLifeCycleId = defaultUserTaskLifeCycleId;
+ registerCustomUserTaskLifeCycleIfAny(userTaskLifeCycle);
+ registerUserTaskLifeCycles();
+ LOG.info("Registered UserTaskLifeCycles {} with default lifecycle:
{}", userTaskLifeCycleRegistry, this.defaultUserTaskLifeCycleId);
+ }
+
+ private void registerUserTaskLifeCycles() {
+ registerUserTaskLifeCycle("kogito", new DefaultUserTaskLifeCycle());
+ registerUserTaskLifeCycle("ws-human-task", new WsHumanTaskLifeCycle());
+ }
+
+ private void
registerCustomUserTaskLifeCycleIfAny(Iterable<UserTaskLifeCycle>
userTaskLifeCycle) {
+ var iterator = userTaskLifeCycle.iterator();
+ if (iterator.hasNext()) {
+ defaultUserTaskLifeCycleId = "custom";
+ registerUserTaskLifeCycle("custom", iterator.next());
+
+ if (iterator.hasNext()) {
+ var message = "Multiple custom usertask lifecycle
implementations found";
+ LOG.error(message);
+ throw new UserTaskLifeCycleException(message);
+ }
+ }
+ }
+
+ private void registerUserTaskLifeCycle(String userTaskLifeCycleId,
UserTaskLifeCycle userTaskLifeCycle) {
+ userTaskLifeCycleRegistry.put(userTaskLifeCycleId, userTaskLifeCycle);
+ }
+
+ @Override
+ public String getDefaultUserTaskLifeCycleId() {
+ return defaultUserTaskLifeCycleId;
+ }
+
+ @Override
+ public UserTaskLifeCycle getUserTaskLifeCycleById(String
userTaskLifeCycleId) {
+ return userTaskLifeCycleRegistry.getOrDefault(userTaskLifeCycleId,
+ defaultUserTaskLifeCycleId.equals("custom") ?
userTaskLifeCycleRegistry.get("custom") :
userTaskLifeCycleRegistry.get("kogito"));
+ }
Review Comment:
This is a follow up for the comment above. If we remove the constructor,
then basically there is no way to register something under key "custom" and
then we could simplify this `getUserTaskLifeCycleById` method.
##########
jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/lifecycle/WsHumanTaskLifeCycle.java:
##########
@@ -0,0 +1,429 @@
+/*
+ * 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.usertask.impl.lifecycle;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import org.kie.kogito.auth.IdentityProvider;
+import org.kie.kogito.usertask.UserTaskAssignmentStrategy;
+import org.kie.kogito.usertask.UserTaskInstance;
+import org.kie.kogito.usertask.UserTaskInstanceNotAuthorizedException;
+import org.kie.kogito.usertask.lifecycle.UserTaskLifeCycle;
+import org.kie.kogito.usertask.lifecycle.UserTaskState;
+import org.kie.kogito.usertask.lifecycle.UserTaskState.TerminationType;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransition;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransitionException;
+import org.kie.kogito.usertask.lifecycle.UserTaskTransitionToken;
+
+public class WsHumanTaskLifeCycle implements UserTaskLifeCycle {
+ public static final String WORKFLOW_ENGINE_USER = "WORKFLOW_ENGINE_USER";
+
+ public static final String PARAMETER_USER = "USER";
+ public static final String PARAMETER_NOTIFY = "NOTIFY";
+ private static final String PARAMETER_DELEGATED_USER = "DELEGATED_USER";
+ private static final String PARAMETER_FORWARDED_USERS = "FORWARDED_USERS";
+ private static final String PARAMETER_NOMINATED_USERS = "NOMINATED_USERS";
+
+ private static final String SKIPPABLE = "Skippable";
+
+ // Actions
+ public static final String ACTIVATE = "activate";
+ public static final String NOMINATE = "nominate";
+ public static final String CLAIM = "claim";
+ public static final String DELEGATE = "delegate";
+ public static final String RELEASE = "release";
+ public static final String FORWARD = "forward";
+ public static final String START = "start";
+ public static final String STOP = "stop";
+ public static final String COMPLETE = "complete";
+ public static final String FAIL = "fail";
+ public static final String FAULT = "fault";
+ public static final String EXIT = "exit";
+ public static final String SKIP = "skip";
+ public static final String SUSPEND = "suspend";
+ public static final String RESUME = "resume";
+
+ public static final UserTaskState CREATED = UserTaskState.initalized();
+ public static final UserTaskState READY = UserTaskState.of("Ready");
+ public static final UserTaskState RESERVED = UserTaskState.of("Reserved");
+ public static final UserTaskState INPROGRESS =
UserTaskState.of("InProgress");
+ public static final UserTaskState COMPLETED =
UserTaskState.of("Completed", TerminationType.COMPLETED);
+ public static final UserTaskState FAILED = UserTaskState.of("Failed",
TerminationType.FAILED);
+ public static final UserTaskState ERROR = UserTaskState.of("Error",
TerminationType.ERROR);
+ public static final UserTaskState EXITED = UserTaskState.of("Exited",
TerminationType.EXITED);
+ public static final UserTaskState OBSOLETE = UserTaskState.of("Obsolete",
TerminationType.OBSOLETE);
+ public static final UserTaskState SUSPENDED =
UserTaskState.of("Suspended");
+
+ private final UserTaskTransition T_CREATED_READY_ACTIVATE = new
DefaultUserTransition(ACTIVATE, CREATED, READY, this::activate);
+ private final UserTaskTransition T_CREATED_READY_NOMINATE = new
DefaultUserTransition(NOMINATE, CREATED, READY, this::nominate);
+
+ private final UserTaskTransition T_READY_READY_FORWARD = new
DefaultUserTransition(FORWARD, READY, READY, this::forward);
+ private final UserTaskTransition T_READY_RESERVED_CLAIM = new
DefaultUserTransition(CLAIM, READY, RESERVED, this::claim);
+ private final UserTaskTransition T_READY_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, READY, RESERVED, this::delegate);
+ private final UserTaskTransition T_READY_INPROGRESS = new
DefaultUserTransition(START, READY, INPROGRESS, this::start);
+ private final UserTaskTransition T_READY_ERROR = new
DefaultUserTransition(FAULT, READY, ERROR, this::fault);
+ private final UserTaskTransition T_READY_EXITED = new
DefaultUserTransition(EXIT, READY, EXITED, this::exit);
+ private final UserTaskTransition T_READY_OBSOLETE = new
DefaultUserTransition(SKIP, READY, OBSOLETE, this::skip);
+ private final UserTaskTransition T_READY_SUSPENDED = new
DefaultUserTransition(SUSPEND, READY, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_RESERVED_READY_RELEASE = new
DefaultUserTransition(RELEASE, RESERVED, READY, this::release);
+ private final UserTaskTransition T_RESERVED_READY_FORWARD = new
DefaultUserTransition(FORWARD, RESERVED, READY, this::forward);
+ private final UserTaskTransition T_RESERVED_INPROGRESS = new
DefaultUserTransition(START, RESERVED, INPROGRESS, this::start);
+ private final UserTaskTransition T_RESERVED_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, RESERVED, RESERVED, this::delegate);
+ private final UserTaskTransition T_RESERVED_ERROR = new
DefaultUserTransition(FAULT, RESERVED, ERROR, this::fault);
+ private final UserTaskTransition T_RESERVED_EXITED = new
DefaultUserTransition(EXIT, RESERVED, EXITED, this::exit);
+ private final UserTaskTransition T_RESERVED_OBSOLETE = new
DefaultUserTransition(SKIP, RESERVED, OBSOLETE, this::skip);
+ private final UserTaskTransition T_RESERVED_SUSPENDED = new
DefaultUserTransition(SUSPEND, RESERVED, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_INPROGRESS_RESERVED_STOP = new
DefaultUserTransition(STOP, INPROGRESS, RESERVED, this::stop);
+ private final UserTaskTransition T_INPROGRESS_RESERVED_DELEGATE = new
DefaultUserTransition(DELEGATE, INPROGRESS, RESERVED, this::delegate);
+ private final UserTaskTransition T_INPROGRESS_READY_RELEASE = new
DefaultUserTransition(RELEASE, INPROGRESS, READY, this::release);
+ private final UserTaskTransition T_INPROGRESS_READY_FORWARD = new
DefaultUserTransition(FORWARD, INPROGRESS, READY, this::forward);
+ private final UserTaskTransition T_INPROGRESS_COMPLETED = new
DefaultUserTransition(COMPLETE, INPROGRESS, COMPLETED, this::complete);
+ private final UserTaskTransition T_INPROGRESS_FAILED = new
DefaultUserTransition(FAIL, INPROGRESS, FAILED, this::fail);
+ private final UserTaskTransition T_INPROGRESS_ERROR = new
DefaultUserTransition(FAULT, INPROGRESS, ERROR, this::fault);
+ private final UserTaskTransition T_INPROGRESS_EXITED = new
DefaultUserTransition(EXIT, INPROGRESS, EXITED, this::exit);
+ private final UserTaskTransition T_INPROGRESS_OBSOLETE = new
DefaultUserTransition(SKIP, INPROGRESS, OBSOLETE, this::skip);
+ private final UserTaskTransition T_INPROGRESS_SUSPENDED = new
DefaultUserTransition(SUSPEND, INPROGRESS, SUSPENDED, this::suspend);
+
+ private final UserTaskTransition T_SUSPENDED_READY = new
DefaultUserTransition(RESUME, SUSPENDED, READY, this::resume);
+ private final UserTaskTransition T_SUSPENDED_RESERVED = new
DefaultUserTransition(RESUME, SUSPENDED, RESERVED, this::resume);
+ private final UserTaskTransition T_SUSPENDED_INPROGRESS = new
DefaultUserTransition(RESUME, SUSPENDED, INPROGRESS, this::resume);
+
+ private List<UserTaskTransition> transitions;
+
+ public WsHumanTaskLifeCycle() {
+ transitions = List.of(
+ T_CREATED_READY_ACTIVATE,
+ T_CREATED_READY_NOMINATE,
+ T_READY_READY_FORWARD,
+ T_READY_RESERVED_CLAIM,
+ T_READY_RESERVED_DELEGATE,
+ T_READY_INPROGRESS,
+ T_READY_ERROR,
+ T_READY_EXITED,
+ T_READY_OBSOLETE,
+ T_READY_SUSPENDED,
+ T_RESERVED_READY_RELEASE,
+ T_RESERVED_READY_FORWARD,
+ T_RESERVED_INPROGRESS,
+ T_RESERVED_RESERVED_DELEGATE,
+ T_RESERVED_ERROR,
+ T_RESERVED_EXITED,
+ T_RESERVED_OBSOLETE,
+ T_RESERVED_SUSPENDED,
+ T_INPROGRESS_RESERVED_STOP,
+ T_INPROGRESS_RESERVED_DELEGATE,
+ T_INPROGRESS_READY_RELEASE,
+ T_INPROGRESS_READY_FORWARD,
+ T_INPROGRESS_COMPLETED,
+ T_INPROGRESS_FAILED,
+ T_INPROGRESS_ERROR,
+ T_INPROGRESS_EXITED,
+ T_INPROGRESS_OBSOLETE,
+ T_INPROGRESS_SUSPENDED,
+ T_SUSPENDED_READY,
+ T_SUSPENDED_RESERVED,
+ T_SUSPENDED_INPROGRESS);
+ }
+
+ @Override
+ public List<UserTaskTransition> allowedTransitions(UserTaskInstance
userTaskInstance, IdentityProvider identity) {
+ checkPermission(userTaskInstance, identity);
+ return transitions.stream()
+ .filter(t -> t.source().equals(userTaskInstance.getStatus())
+ && (!t.id().equals(SKIP) ||
"true".equals(userTaskInstance.getMetadata().get("Skippable"))))
+ .toList();
+ }
+
+ @Override
+ public String startTransition() {
+ return ACTIVATE;
+ }
+
+ @Override
+ public String reassignTransition() {
+ return FORWARD;
+ }
+
+ @Override
+ public String abortTransition() {
+ return EXIT;
+ }
+
+ @Override
+ public Optional<UserTaskTransitionToken> transition(UserTaskInstance
userTaskInstance, UserTaskTransitionToken token, IdentityProvider
identityProvider) {
+ checkPermission(userTaskInstance, identityProvider);
+ UserTaskTransition transition = transitions.stream()
+ .filter(t -> t.source().equals(userTaskInstance.getStatus())
&& t.id().equals(token.transitionId()) && t.target().equals(token.target()))
+ .findFirst()
+ .orElseThrow(() -> new UserTaskTransitionException("Invalid
transition from " + userTaskInstance.getStatus()));
+ return transition.executor().execute(userTaskInstance, token,
identityProvider);
+ }
+
+ @Override
+ public UserTaskTransitionToken newCompleteTransitionToken(UserTaskInstance
userTaskInstance, Map<String, Object> data) {
+ return newTransitionToken(COMPLETE, userTaskInstance.getStatus(),
null, data);
+ }
+
+ @Override
+ public UserTaskTransitionToken newAbortTransitionToken(UserTaskInstance
userTaskInstance, Map<String, Object> data) {
+ return newTransitionToken(FAIL, userTaskInstance.getStatus(), null,
data);
+ }
+
+ @Override
+ public UserTaskTransitionToken newTransitionToken(String transitionId,
UserTaskInstance userTaskInstance, Map<String, Object> data) {
+ if (transitionId.equals(ACTIVATE) &&
userTaskInstance.getPotentialUsers().isEmpty()) {
+ return null;
+ }
+ return newTransitionToken(transitionId, userTaskInstance.getStatus(),
(String) userTaskInstance.getMetadata().get("PreviousStatus"), data);
+ }
+
+ public UserTaskTransitionToken newTransitionToken(String transitionId,
UserTaskState state, String previousState, Map<String, Object> data) {
+ var transition = transitions.stream()
+ .filter(e -> e.source().equals(state) &&
e.id().equals(transitionId) && (!transitionId.equals(RESUME) ||
e.target().getName().equals(previousState)))
+ .findAny()
+ .orElseThrow(() -> new UserTaskTransitionException("Invalid
transition " + transitionId + " from " + state));
+
+ return new DefaultUserTaskTransitionToken(transition.id(),
transition.source(), transition.target(), data);
+ }
+
+ public Optional<UserTaskTransitionToken> activate(UserTaskInstance
userTaskInstance, UserTaskTransitionToken token, IdentityProvider
identityProvider) {
Review Comment:
even method signatures for `activate`, `nominate` .... declares returning
`Optional<UserTaskTransitionToken>` however it seems always it is
`Optional.empty` is that intentional?
##########
springboot/integration-tests/integration-tests-springboot-wshumantasks-it/src/test/java/org/jbpm/userTask/jpa/it/WsHumanTaskLifeCycleIT.java:
##########
@@ -0,0 +1,561 @@
+/*
+ * 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.jbpm.userTask.jpa.it;
Review Comment:
minor thing, but this is not java convention to have uppercase letter in
package name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]