use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class CompensationEventTest method testIntermediateCompensationEventProcess.
@Test
public void testIntermediateCompensationEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("compensation/UserTaskBeforeAssociatedActivity.bpmn2");
Process<? extends Model> p = app.processes().processById("CompensateIntermediateThrowEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("x", "0");
m.fromMap(parameters);
ProcessInstance<? extends Model> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertEquals(1, workItems.size());
assertEquals("task", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(processInstance.variables().toMap()).containsEntry("x", "1");
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class AdHocSubProcessTest method testActivationAdHoc.
@Test
void testActivationAdHoc() throws Exception {
Application app = generateCodeProcessesOnly("cases/ActivationAdHoc.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.ActivationAdHoc_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "yellow");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems.size()).isEqualTo(1);
WorkItem workItem = workItems.get(0);
params = new HashMap<>();
params.put("favouriteColour", "blue");
processInstance.completeWorkItem(workItem.getId(), params);
assertState(processInstance, ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class SignalEventTest method testIntermediateSignalEventWithDataControlledByUnitOfWork.
@Test
public void testIntermediateSignalEventWithDataControlledByUnitOfWork() throws Exception {
Application app = generateCode(Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"), Collections.singletonList("ruletask/BusinessRuleTask.drl"));
assertThat(app).isNotNull();
// create first unit of work
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.processes().processById("IntermediateCatchEvent");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// since unit of work is not ended yet there are no instance added
assertThat(p.instances().values(1, 10)).hasSize(0);
uow.end();
// after the unit of work is ended process instance shows up in the list
assertThat(p.instances().values(1, 10)).hasSize(1);
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems).hasSize(1);
processInstance.completeWorkItem(workItems.get(0).getId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
uow.end();
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
assertThat(p.instances().values(1, 10)).hasSize(1);
processInstance.send(Sig.of("MyMessage", "test"));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKey("x");
assertThat(result.toMap().get("x")).isEqualTo("test");
// since the unit of work is not ended yet there is still instance visible
assertThat(p.instances().values(ProcessInstanceReadMode.READ_ONLY, ProcessInstance.STATE_COMPLETED, 1, 10)).hasSize(1);
uow.end();
// after unit of work is ended instance is gone from the list
assertThat(p.instances().values(1, 10)).hasSize(0);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class $Type$Resource method getTask.
@APIResponses(value = { @APIResponse(responseCode = "500", description = "In case of processing errors", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "404", description = "In case of task instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully retrieved instance of $taskName$ task with given id", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $TaskInput$.class))) })
@Operation(summary = "Retrieves $taskName$ task instance with given id")
@GET()
@Path("$prefix$/$name$/{id_$name$}/$taskName$/{workItemId}")
@Produces(MediaType.APPLICATION_JSON)
public $TaskInput$ getTask(@PathParam("id") String id, @PathParam("id_$name$") String id_$name$, @PathParam("workItemId") String workItemId, @QueryParam("user") final String user, @QueryParam("group") final List<String> groups) {
try {
identitySupplier.buildIdentityProvider(user, groups);
return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String combinedId;
if (id_$name$.contains(":")) {
combinedId = id_$name$;
} else {
combinedId = $parentprocessid$ + ":" + id_$name$;
}
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById(combinedId, io.automatiko.engine.api.workflow.ProcessInstanceReadMode.READ_ONLY).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
WorkItem workItem = pi.workItem(workItemId, policies(user, groups));
if (workItem == null) {
return null;
}
return $TaskInput$.fromMap(workItem.getId(), workItem.getName(), workItem.getParameters());
});
} catch (WorkItemNotFoundException e) {
return null;
} finally {
IdentityProvider.set(null);
}
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class $Type$Resource method signal.
@APIResponses(value = { @APIResponse(responseCode = "500", description = "In case of processing errors", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "404", description = "In case of task instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully created new instance of $taskName$ task", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))) })
@Operation(summary = "Adds new $taskName$ task instance")
@POST
@Path("$prefix$/$name$/{id_$name$}/$taskName$")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public javax.ws.rs.core.Response signal(@Context HttpHeaders httpHeaders, @PathParam("id") String id, @PathParam("id_$name$") String id_$name$, @Parameter(description = "User identifier as alternative autroization info", required = false, hidden = true) @QueryParam("user") final String user, @Parameter(description = "Groups as alternative autroization info", required = false, hidden = true) @QueryParam("group") final List<String> groups, @Parameter(description = "Indicates if instance metadata should be included", required = false) @QueryParam("metadata") @DefaultValue("false") final boolean metadata) {
String execMode = httpHeaders.getHeaderString("X-ATK-Mode");
if ("async".equalsIgnoreCase(execMode)) {
String callbackUrl = httpHeaders.getHeaderString("X-ATK-Callback");
Map<String, String> headers = httpHeaders.getRequestHeaders().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().get(0)));
IdentityProvider identity = identitySupplier.buildIdentityProvider(user, groups);
IdentityProvider.set(null);
CompletableFuture.runAsync(() -> {
IdentityProvider.set(identity);
io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String combinedId;
if (id_$name$.contains(":")) {
combinedId = id_$name$;
} else {
combinedId = $parentprocessid$ + ":" + id_$name$;
}
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById(combinedId).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
tracing(pi);
pi.send(Sig.of("$taskNodeName$", java.util.Collections.emptyMap()));
io.automatiko.engine.workflow.http.HttpCallbacks.get().post(callbackUrl, getSubModel_$name$(pi, metadata), httpAuth.produce(headers), pi.status());
return null;
});
});
ResponseBuilder builder = Response.accepted().entity(Collections.singletonMap("id", id));
return builder.build();
} else {
identitySupplier.buildIdentityProvider(user, groups);
return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String combinedId;
if (id_$name$.contains(":")) {
combinedId = id_$name$;
} else {
combinedId = $parentprocessid$ + ":" + id_$name$;
}
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById(combinedId).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
tracing(pi);
pi.send(Sig.of("$taskNodeName$", java.util.Collections.emptyMap()));
java.util.Optional<WorkItem> task = pi.workItems().stream().filter(wi -> wi.getName().equals("$taskName$")).findFirst();
if (task.isPresent()) {
return javax.ws.rs.core.Response.ok(getSubModel_$name$(pi, metadata)).header("Link", "</" + id + "/$taskName$/" + task.get().getId() + ">; rel='instance'").build();
}
return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.NOT_FOUND).build();
});
}
}
Aggregations