Skip to content

Commit

Permalink
[incubator-kie-issues-1522] Transition object to make extensible user…
Browse files Browse the repository at this point in the history
…task transition restendpoint (#3708)
  • Loading branch information
elguardian authored Oct 21, 2024
1 parent 4635074 commit 1474ab9
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.model;

import java.util.Collections;
import java.util.Map;

public class TransitionInfo {

private String transitionId;

private Map<String, Object> data;

public TransitionInfo() {
// do nothing
}

public TransitionInfo(String transitionId) {
this(transitionId, Collections.emptyMap());
}

public TransitionInfo(String transitionId, Map<String, Object> data) {
this.transitionId = transitionId;
this.data = data;
}

public Map<String, Object> getData() {
return data;
}

public void setData(Map<String, Object> data) {
this.data = data;
}

public String getTransitionId() {
return transitionId;
}

public void setTransitionId(String transitionId) {
this.transitionId = transitionId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import org.jbpm.test.utils.ProcessTestHelper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.kie.api.event.process.ProcessStartedEvent;
import org.kie.api.io.Resource;
import org.kie.internal.io.ResourceFactory;
Expand Down Expand Up @@ -384,7 +383,6 @@ public void testEventBasedSplitAfter() {
}

@Test
@Timeout(10)
public void testEventBasedSplit2() throws Exception {
ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2);
Application app = ProcessTestHelper.newApplication();
Expand Down Expand Up @@ -537,7 +535,6 @@ public void testErrorBoundaryEvent() throws Exception {
}

@Test
@Timeout(10)
public void testTimerBoundaryEvent() throws Exception {
Application app = ProcessTestHelper.newApplication();
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
Expand All @@ -556,7 +553,6 @@ public void testTimerBoundaryEvent() throws Exception {
}

@Test
@Timeout(10)
public void testTimerBoundaryEventInterrupting() {
Application app = ProcessTestHelper.newApplication();
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
Expand Down Expand Up @@ -697,7 +693,6 @@ public void testIntermediateCatchEventMessage() {
}

@Test
@Timeout(10)
public void testIntermediateCatchEventTimer() {
Application app = ProcessTestHelper.newApplication();
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
Expand Down Expand Up @@ -786,7 +781,6 @@ public void testConditionalStart() throws Exception {
}

@Test
@Timeout(1000)
public void testTimerStart() throws Exception {
Application app = ProcessTestHelper.newApplication();
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public UserTaskView find(@PathParam("taskId") String taskId, @QueryParam("user")
@Produces(MediaType.APPLICATION_JSON)
public UserTaskView transition(
@PathParam("taskId") String taskId,
@QueryParam("transitionId") String transitionId,
@QueryParam("user") String user,
@QueryParam("group") List<String> groups, Map<String, Object> data) {
return userTaskService.transition(taskId, transitionId, data, IdentityProviders.of(user, groups)).orElseThrow(UserTaskInstanceNotFoundException::new);
@QueryParam("group") List<String> groups,
TransitionInfo transitionInfo) {
return userTaskService.transition(taskId, transitionInfo.getTransitionId(), transitionInfo.getData(), IdentityProviders.of(user, groups)).orElseThrow(UserTaskInstanceNotFoundException::new);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ public UserTaskView find(@PathVariable("taskId") String taskId, @RequestParam("u
@PostMapping(value = "/{taskId}/transition")
public UserTaskView transition(
@PathVariable("taskId") String taskId,
@RequestParam("transitionId") String transitionId,
@RequestParam("user") String user,
@RequestParam("group") List<String> groups,
@RequestBody Map<String, Object> data) {
return userTaskService.transition(taskId, transitionId, data, IdentityProviders.of(user, groups)).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
@RequestBody TransitionInfo transitionInfo) {
return userTaskService.transition(taskId, transitionInfo.getTransitionId(), transitionInfo.getData(), IdentityProviders.of(user, groups)).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}

@GetMapping(value = "/{taskId}/transition", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<bpmn2:collaboration id="_4DD91E78-A982-46F9-A427-611946D40403" name="Default Collaboration">
<bpmn2:participant id="_239FEF97-E424-41F3-B3E9-D626D7EC319D" name="Pool Participant" processRef="addedtask"/>
</bpmn2:collaboration>
<bpmn2:process id="AddedTask" drools:packageName="com.example" drools:version="1.0" drools:adHoc="false" name="addedtask" isExecutable="true" processType="Public">
<bpmn2:process id="AddedTask" drools:packageName="com.example" drools:version="1.0" drools:adHoc="false" name="AddedTask" isExecutable="true" processType="Public">
<bpmn2:sequenceFlow id="_D0E6CA53-1ECE-4F8D-AAF0-829B30A2719F" sourceRef="_74EA6719-7F99-48CD-A98E-17D422668B87" targetRef="_1D65864A-96AF-44FC-92CE-2073B9FBA7D0">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.target">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.kogito.AddressType;
import org.kie.kogito.Person;
import org.kie.kogito.Status;
import org.kie.kogito.usertask.model.TransitionInfo;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
Expand All @@ -42,11 +43,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.emptyOrNullString;

public abstract class PersistenceTest {
private static final String USER_TASK_BASE_PATH = "/usertasks/instance";

public static final Duration TIMEOUT = Duration.ofSeconds(10);
public static final String PROCESS_ID = "hello";
Expand All @@ -59,6 +62,71 @@ public abstract class PersistenceTest {
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}

@Test
public void testStartApprovalAuthorized() {
// start new approval
String id = given()
.body("{}")
.contentType(ContentType.JSON)
.when()
.post("/AddedTask")
.then()
.statusCode(201)
.body("id", notNullValue()).extract().path("id");
// get all active approvals
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask")
.then()
.statusCode(200)
.body("size()", is(1), "[0].id", is(id));

// get just started approval
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask/" + id)
.then()
.statusCode(200)
.body("id", is(id));

// tasks assigned in just started approval

String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "mary")
.queryParam("group", "managers")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200)
.extract()
.body()
.path("[0].id");

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "mary")
.queryParam("group", "managers")
.body(new TransitionInfo("complete"))
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

// get all active approvals
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask")
.then()
.statusCode(200)
.body("size()", is(1));
}

@Test
void testPersistence() {
Person person = new Person("Name", 10, BigDecimal.valueOf(5.0), Instant.now().truncatedTo(ChronoUnit.MILLIS), ZonedDateTime.now(ZoneOffset.UTC));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,84 +18,9 @@
*/
package org.kie.kogito.it;

import java.util.Collections;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;

@QuarkusIntegrationTest
class InfinispanPersistenceIT extends PersistenceTest {
private static final String USER_TASK_BASE_PATH = "/usertasks/instance";

@Test
public void testStartApprovalAuthorized() {
// start new approval
String id = given()
.body("{}")
.contentType(ContentType.JSON)
.when()
.post("/AddedTask")
.then()
.statusCode(201)
.body("id", notNullValue()).extract().path("id");
// get all active approvals
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask")
.then()
.statusCode(200)
.body("size()", is(1), "[0].id", is(id));

// get just started approval
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask/" + id)
.then()
.statusCode(200)
.body("id", is(id));

// tasks assigned in just started approval

String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "mary")
.queryParam("group", "managers")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200)
.extract()
.body()
.path("[0].id");

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "complete")
.queryParam("user", "mary")
.queryParam("group", "managers")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

// get all active approvals
given()
.accept(ContentType.JSON)
.when()
.get("/AddedTask")
.then()
.statusCode(200)
.body("size()", is(1));
}
}

0 comments on commit 1474ab9

Please sign in to comment.