Search in sources :

Example 11 with ProcessInstance

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();
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) Person(io.automatiko.engine.codegen.data.Person) Test(org.junit.jupiter.api.Test) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest)

Example 12 with ProcessInstance

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);
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) Person(io.automatiko.engine.codegen.data.Person) Test(org.junit.jupiter.api.Test) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest)

Example 13 with ProcessInstance

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);
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) Test(org.junit.jupiter.api.Test) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest)

Example 14 with ProcessInstance

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();
        });
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) ProcessInstanceExecutionException(io.automatiko.engine.api.workflow.ProcessInstanceExecutionException) MediaType(javax.ws.rs.core.MediaType) Application(io.automatiko.engine.api.Application) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) InstanceMetadata(io.automatiko.engine.api.workflow.InstanceMetadata) Process(io.automatiko.engine.api.workflow.Process) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) DELETE(javax.ws.rs.DELETE) OutputStream(java.io.OutputStream) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Policy(io.automatiko.engine.api.workflow.workitem.Policy) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Sig(io.automatiko.engine.workflow.Sig) Entry(java.util.Map.Entry) WebApplicationException(javax.ws.rs.WebApplicationException) Collections(java.util.Collections) WorkItem(io.automatiko.engine.api.workflow.WorkItem) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 15 with ProcessInstance

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) {
    }
}
Also used : Optional(java.util.Optional) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)63 Model (io.automatiko.engine.api.Model)29 Application (io.automatiko.engine.api.Application)26 HashMap (java.util.HashMap)23 Test (org.junit.jupiter.api.Test)23 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)22 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)21 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)16 List (java.util.List)15 WorkItem (io.automatiko.engine.api.workflow.WorkItem)14 Process (io.automatiko.engine.api.workflow.Process)13 Optional (java.util.Optional)13 Map (java.util.Map)12 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)10 Collections (java.util.Collections)10 ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)9 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Collectors (java.util.stream.Collectors)9 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)8