use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.
the class ConditionalEventTest method testNonInterruptingEventSubprocessConditionalEventProcess.
@Test
public void testNonInterruptingEventSubprocessConditionalEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("conditionalevent/ConditionalEventSubprocessNonInterrupting.bpmn2");
Process<? extends Model> p = app.processes().processById("subprocessCondition");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", new Person("john", 30));
m.fromMap(parameters);
ProcessInstance processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
m.fromMap(Collections.singletonMap("person", new Person("john", 45)));
processInstance.updateVariables(m);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
m.fromMap(Collections.singletonMap("person", new Person("john", 15)));
processInstance.updateVariables(m);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
m.fromMap(Collections.singletonMap("person", new Person("john", 45)));
processInstance.updateVariables(m);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Object counter = ((Model) processInstance.variables()).toMap().get("counter");
assertThat(counter).isNotNull().asList().hasSize(2);
processInstance.abort();
}
use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.
the class ConditionalEventTest method testBoundaryConditionalEventProcess.
@Test
public void testBoundaryConditionalEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("conditionalevent/ConditionalBoundaryEvent.bpmn2");
Process<? extends Model> p = app.processes().processById("boundaryCondition");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", new Person("john", 30));
m.fromMap(parameters);
ProcessInstance processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
m.fromMap(Collections.singletonMap("person", new Person("john", 45)));
processInstance.updateVariables(m);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.
the class ConditionalEventTest method testBasicConditionalEventProcess.
@Test
public void testBasicConditionalEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("conditionalevent/ConditionalEvent.bpmn2");
Process<? extends Model> p = app.processes().processById("conditions");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
m.fromMap(Collections.singletonMap("data", "data"));
processInstance.updateVariables(m);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.
the class $Type$Resource method updateModel_$name$.
@APIResponses(value = { @APIResponse(responseCode = "500", description = "In case of processing errors", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully updated instance", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))) })
@Operation(summary = "Updates data of $name$ instance with given id")
@POST()
@Path("$prefix$/$name$/{id_$name$}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateModel_$name$(@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, $Type$ resource) {
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(), () -> {
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById($parentprocessid$ + ":" + id_$name$).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
tracing(pi);
pi.updateVariables(resource);
$Type$Output result = mapOutput(new $Type$Output(), pi.variables(), pi.businessKey(), metadata ? pi.metadata() : null);
io.automatiko.engine.workflow.http.HttpCallbacks.get().post(callbackUrl, result, 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(), () -> {
ProcessInstance<$Type$> pi = subprocess_$name$.instances().findById($parentprocessid$ + ":" + id_$name$).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
tracing(pi);
pi.updateVariables(resource);
ResponseBuilder builder = Response.ok().entity(mapOutput(new $Type$Output(), pi.variables(), pi.businessKey(), metadata ? pi.metadata() : null));
return builder.build();
});
}
}
use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.
the class DefaultWorkItemExecutionManager method error.
@SuppressWarnings("unchecked")
protected void error(String processId, WorkItem workItem, WorkItemManager manager, Throwable error) {
LOGGER.debug("Executing error callback after work item execution");
Process<?> process = processData.get(processId);
if (process == null) {
LOGGER.error("Unable to find process with id {}, completion of service invocation aborted", processId);
return;
}
try {
IdentityProvider.set(new TrustedIdentityProvider("System<async>"));
UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String id = StringUtils.isEmpty(workItem.getParentProcessInstanceId()) ? workItem.getProcessInstanceId() : workItem.getParentProcessInstanceId() + ":" + workItem.getProcessInstanceId();
Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(id);
if (instance.isPresent()) {
instance.get().failWorkItem(workItem.getId(), error);
}
return null;
});
} catch (Throwable e) {
}
}
Aggregations