Search in sources :

Example 1 with WorkItemNotFoundException

use of io.automatiko.engine.api.runtime.process.WorkItemNotFoundException in project automatiko-engine by automatiko-io.

the class $Type$Resource method $parentprocessprefix$_getTask.

@Query
@Description("Retrieves $taskName$ task instance with given id")
public $TaskInput$ $parentprocessprefix$_getTask(@Name("parentId") String id, @Name("id") String id_$name$, @Name("workItemId") final String workItemId, @Name("user") final String user, @Name("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_$name$));
            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);
    }
}
Also used : WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) WorkItem(io.automatiko.engine.api.workflow.WorkItem)

Example 2 with WorkItemNotFoundException

use of io.automatiko.engine.api.runtime.process.WorkItemNotFoundException 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);
    }
}
Also used : WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) WorkItem(io.automatiko.engine.api.workflow.WorkItem)

Example 3 with WorkItemNotFoundException

use of io.automatiko.engine.api.runtime.process.WorkItemNotFoundException in project automatiko-engine by automatiko-io.

the class $Type$Resource method completeTask.

@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 completed instance of $taskName$ task with given id", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))) })
@Operation(summary = "Completes $taskName$ task instance with given id")
@POST()
@Path("$prefix$/$name$/{id_$name$}/$taskName$/{workItemId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response completeTask(@Context HttpHeaders httpHeaders, @PathParam("id") String id, @PathParam("id_$name$") String id_$name$, @PathParam("workItemId") final String workItemId, @QueryParam("phase") @DefaultValue("complete") final String phase, @QueryParam("user") final String user, @QueryParam("group") final List<String> groups, @QueryParam("metadata") @DefaultValue("false") final boolean metadata, final $TaskOutput$ model) {
    try {
        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);
                    io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition transition = new io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition(phase, model.toMap(), io.automatiko.engine.api.auth.IdentityProvider.get());
                    pi.transitionWorkItem(workItemId, transition);
                    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);
                io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition transition = new io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition(phase, model.toMap(), io.automatiko.engine.api.auth.IdentityProvider.get());
                pi.transitionWorkItem(workItemId, transition);
                ResponseBuilder builder = Response.ok().entity(getSubModel_$name$(pi, metadata));
                return builder.build();
            });
        }
    } catch (WorkItemNotFoundException e) {
        return null;
    } finally {
        IdentityProvider.set(null);
    }
}
Also used : List(java.util.List) Sig(io.automatiko.engine.workflow.Sig) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Entry(java.util.Map.Entry) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) CompletableFuture(java.util.concurrent.CompletableFuture) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) WorkItem(io.automatiko.engine.api.workflow.WorkItem) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)

Example 4 with WorkItemNotFoundException

use of io.automatiko.engine.api.runtime.process.WorkItemNotFoundException in project automatiko-engine by automatiko-io.

the class $Type$Resource method abortTask.

@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 aborted instance of $taskName$ task with given id", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))) })
@Operation(summary = "Aborts $taskName$ task instance with given id")
@DELETE()
@Path("$prefix$/$name$/{id_$name$}/$taskName$/{workItemId}")
@Produces(MediaType.APPLICATION_JSON)
public Response abortTask(@Context HttpHeaders httpHeaders, @PathParam("id") String id, @PathParam("id_$name$") String id_$name$, @PathParam("workItemId") final String workItemId, @QueryParam("phase") @DefaultValue("abort") final String phase, @QueryParam("user") final String user, @QueryParam("group") final List<String> groups, @QueryParam("metadata") @DefaultValue("false") final boolean metadata) {
    String execMode = httpHeaders.getHeaderString("X-ATK-Mode");
    try {
        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);
                    io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition transition = new io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition(phase, null, io.automatiko.engine.api.auth.IdentityProvider.get());
                    pi.transitionWorkItem(workItemId, transition);
                    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);
                io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition transition = new io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition(phase, null, io.automatiko.engine.api.auth.IdentityProvider.get());
                pi.transitionWorkItem(workItemId, transition);
                ResponseBuilder builder = Response.ok().entity(getSubModel_$name$(pi, metadata));
                return builder.build();
            });
        }
    } catch (WorkItemNotFoundException e) {
        return null;
    }
}
Also used : List(java.util.List) Sig(io.automatiko.engine.workflow.Sig) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Entry(java.util.Map.Entry) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) CompletableFuture(java.util.concurrent.CompletableFuture) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) WorkItem(io.automatiko.engine.api.workflow.WorkItem) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)

Example 5 with WorkItemNotFoundException

use of io.automatiko.engine.api.runtime.process.WorkItemNotFoundException in project automatiko-engine by automatiko-io.

the class UserTaskManagementResource method get.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "text/html")), @APIResponse(responseCode = "200", description = "List of available processes", content = @Content(mediaType = "text/html")) })
@Operation(summary = "Retrives user task form for given user task", operationId = "getUserTaskForm")
@SuppressWarnings("unchecked")
@GET
@Path("{processId}/{pInstanceId}/{taskId}")
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get(@Context UriInfo uriInfo, @Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "Unique identifier of the instance", required = true) @PathParam("pInstanceId") String pInstanceId, @Parameter(description = "Unique identifier of the task", required = true) @PathParam("taskId") String taskId, @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) {
    IdentityProvider identityProvider = identitySupplier.buildIdentityProvider(user, groups);
    try {
        Process<?> process = processData.get(processId);
        if (process == null) {
            return getTemplate("process-not-found", PROCESS_INSTANCE_NOT_FOUND).instance().data("instanceId", pInstanceId);
        }
        Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(pInstanceId, ProcessInstanceReadMode.READ_ONLY);
        if (instance.isEmpty()) {
            return getTemplate("process-instance-not-found", PROCESS_INSTANCE_NOT_FOUND).instance().data("instanceId", pInstanceId);
        }
        ProcessInstance<?> pi = instance.get();
        WorkItem task = pi.workItem(taskId, SecurityPolicy.of(identityProvider));
        Template template = getTemplate(process.id(), task);
        if (template == null) {
            template = engine.getTemplate(DEFAULT_TEMPLATE);
        }
        String link = task.getReferenceId() + "?redirect=true";
        if (user != null && !user.isEmpty()) {
            link += "&user=" + user;
        }
        if (groups != null && !groups.isEmpty()) {
            for (String group : groups) {
                link += "&group=" + group;
            }
        }
        TemplateInstance templateInstance = template.data("task", task).data("url", new RawString(link));
        templateInstance.data("inputs", process.taskInputs(task.getId(), task.getName(), task.getParameters()));
        Map<String, Object> results = task.getResults();
        task.getParameters().entrySet().stream().forEach(e -> results.putIfAbsent(e.getKey(), e.getValue()));
        templateInstance.data("results", process.taskOutputs(task.getId(), task.getName(), results));
        return templateInstance;
    } catch (WorkItemNotFoundException e) {
        return getTemplate("task-not-found", TASK_INSTANCE_NOT_FOUND).instance().data("taskId", taskId);
    } finally {
        IdentityProvider.set(null);
    }
}
Also used : Optional(java.util.Optional) RawString(io.quarkus.qute.RawString) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) RawString(io.quarkus.qute.RawString) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Template(io.quarkus.qute.Template) TemplateInstance(io.quarkus.qute.TemplateInstance) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Aggregations

WorkItemNotFoundException (io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)6 WorkItem (io.automatiko.engine.api.workflow.WorkItem)5 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)3 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)3 ProcessInstanceReadMode (io.automatiko.engine.api.workflow.ProcessInstanceReadMode)2 Sig (io.automatiko.engine.workflow.Sig)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Collectors (java.util.stream.Collectors)2 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)1 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)1 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)1 RawString (io.quarkus.qute.RawString)1 Template (io.quarkus.qute.Template)1 TemplateInstance (io.quarkus.qute.TemplateInstance)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1