Search in sources :

Example 1 with ProcessInstanceNotFoundException

use of io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException in project automatiko-engine by automatiko-io.

the class ProcessInstanceNotFoundExceptionMapper method toResponse.

@Override
public Response toResponse(ProcessInstanceNotFoundException ex) {
    ProcessInstanceNotFoundException exception = (ProcessInstanceNotFoundException) ex;
    Map<String, String> response = new HashMap<>();
    response.put(MESSAGE, exception.getMessage());
    response.put(PROCESS_INSTANCE_ID, exception.getProcessInstanceId());
    return notFound(response);
}
Also used : HashMap(java.util.HashMap) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException)

Example 2 with ProcessInstanceNotFoundException

use of io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException in project automatiko-engine by automatiko-io.

the class $Type$Resource method get_tag_$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 = "403", description = "In case of instance with given id is not accessible to the caller", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully removed TagInstance from the instance", content = @Content(mediaType = "application/json", schema = @Schema(implementation = TagInstance.class, type = SchemaType.ARRAY))) })
@Operation(summary = "Removes TagInstance from $name$ instance with given id")
@DELETE()
@Path("/{id}/tags/{tagId}")
@Produces(MediaType.APPLICATION_JSON)
public Collection<? extends Tag> get_tag_$name$(@PathParam("id") @Parameter(description = "Unique identifier of the instance", required = true) String id, @Parameter(description = "TagInstance to be removed", required = true) @PathParam("tagId") String tagId, @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) {
    identitySupplier.buildIdentityProvider(user, groups);
    return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
        ProcessInstance<$Type$> pi = process.instances().findById(id, io.automatiko.engine.api.workflow.ProcessInstanceReadMode.READ_ONLY).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
        tracing(pi);
        pi.tags().remove(tagId);
        return pi.tags().get();
    });
}
Also used : ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 3 with ProcessInstanceNotFoundException

use of io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException in project automatiko-engine by automatiko-io.

the class ProcessInstanceManagementResource method exportInstance.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.OBJECT))), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Returns exported process instance for given instance id")
@SuppressWarnings("unchecked")
@GET
@Path("/{processId}/instances/{instanceId}/export")
@Produces(MediaType.APPLICATION_JSON)
public JsonExportedProcessInstance exportInstance(@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("instanceId") String instanceId, @Parameter(description = "Status of the process instance", required = false) @QueryParam("status") @DefaultValue("active") final String status, @Parameter(description = "Indicates if the instance should be aborted after export, defaults to false", required = false) @QueryParam("abort") @DefaultValue("false") final boolean abort, @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) {
    identitySupplier.buildIdentityProvider(user, groups);
    JsonExportedProcessInstance exported = UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
        Process<?> process = processData.get(processId);
        if (process == null) {
            throw new ProcessInstanceNotFoundException(instanceId);
        }
        Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(instanceId, mapStatus(status), ProcessInstanceReadMode.MUTABLE);
        if (instance.isEmpty()) {
            throw new ProcessInstanceNotFoundException(instanceId);
        }
        ProcessInstance<?> pi = instance.get();
        return exporter.exportInstance(instanceId, pi);
    });
    if (abort) {
        cancelProcessInstanceId(processId, instanceId, status, user, groups);
    }
    return exported;
}
Also used : JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) Optional(java.util.Optional) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) 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)

Example 4 with ProcessInstanceNotFoundException

use of io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException in project automatiko-engine by automatiko-io.

the class ProcessInstanceManagementResource method getInstance.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Process instance details", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Returns process instance details for given instance id")
@SuppressWarnings("unchecked")
@GET
@Path("/{processId}/instances/{instanceId}")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO getInstance(@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("instanceId") String instanceId, @Parameter(description = "Status of the process instance", required = false, schema = @Schema(enumeration = { "active", "completed", "aborted", "error" })) @QueryParam("status") @DefaultValue("active") final String status, @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) {
    try {
        identitySupplier.buildIdentityProvider(user, groups);
        return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
            Process<?> process = processData.get(processId);
            Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(instanceId, mapStatus(status), ProcessInstanceReadMode.READ_ONLY);
            if (instance.isEmpty()) {
                throw new ProcessInstanceNotFoundException(instanceId);
            }
            ProcessInstance<?> pi = instance.get();
            ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
            String id = pi.id();
            if (pi.parentProcessInstanceId() != null) {
                id = pi.parentProcessInstanceId() + ":" + id;
            }
            details.setId(id);
            details.setProcessId(processId);
            details.setBusinessKey(pi.businessKey() == null ? "" : pi.businessKey());
            details.setDescription(pi.description());
            details.setState(pi.status());
            details.setFailed(pi.errors().isPresent());
            if (pi.errors().isPresent()) {
                details.setErrors(pi.errors().get().errors().stream().map(e -> new ErrorInfoDTO(e.failedNodeId(), e.errorId(), e.errorMessage(), e.errorDetails())).collect(Collectors.toList()));
            }
            details.setImage(uriInfo.getBaseUri().toString() + "management/processes/" + processId + "/instances/" + instanceId + "/image?status=" + reverseMapStatus(pi.status()));
            details.setTags(pi.tags().values());
            details.setVariables(pi.variables());
            details.setSubprocesses(pi.subprocesses().stream().map(spi -> new ProcessInstanceDTO(spi.id(), spi.businessKey(), spi.description(), spi.tags().values(), spi.errors().isPresent(), spi.process().id(), spi.status())).collect(Collectors.toList()));
            VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) process).process()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
            details.setVersionedVariables(variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(v -> v.getName()).collect(Collectors.toList()));
            return details;
        });
    } finally {
        IdentityProvider.set(null);
    }
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ProcessInstanceExporter(io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter) MediaType(javax.ws.rs.core.MediaType) Application(io.automatiko.engine.api.Application) QueryParam(javax.ws.rs.QueryParam) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) SchemaType(org.eclipse.microprofile.openapi.annotations.enums.SchemaType) VariableNotFoundException(io.automatiko.engine.api.workflow.VariableNotFoundException) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Instance(javax.enterprise.inject.Instance) DELETE(javax.ws.rs.DELETE) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) IoUtils(io.automatiko.engine.services.utils.IoUtils) Context(javax.ws.rs.core.Context) Model(io.automatiko.engine.api.Model) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Operation(org.eclipse.microprofile.openapi.annotations.Operation) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) Parameter(org.eclipse.microprofile.openapi.annotations.parameters.Parameter) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Optional(java.util.Optional) Tag(org.eclipse.microprofile.openapi.annotations.tags.Tag) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) UriInfo(javax.ws.rs.core.UriInfo) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) PathParam(javax.ws.rs.PathParam) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.workflow.Process) ProcessDTO(io.automatiko.engine.addons.process.management.model.ProcessDTO) Content(org.eclipse.microprofile.openapi.annotations.media.Content) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UnitOfWorkExecutor(io.automatiko.engine.services.uow.UnitOfWorkExecutor) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) IOException(java.io.IOException) ExternalDocumentation(org.eclipse.microprofile.openapi.annotations.ExternalDocumentation) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Collections(java.util.Collections) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) Optional(java.util.Optional) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) 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)

Example 5 with ProcessInstanceNotFoundException

use of io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException in project automatiko-engine by automatiko-io.

the class ProcessInstanceManagementResource method getInstanceImage.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "List of available processes", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Returns process instance image with annotated active nodes")
@SuppressWarnings("unchecked")
@GET()
@Path("/{processId}/instances/{instanceId}/image")
@Produces(MediaType.APPLICATION_SVG_XML)
public Response getInstanceImage(@Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "Unique identifier of the instance", required = true) @PathParam("instanceId") String instanceId, @Parameter(description = "Status of the process instance", required = false, schema = @Schema(enumeration = { "active", "completed", "aborted", "error" })) @QueryParam("status") @DefaultValue("active") final String status, @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) {
    try {
        identitySupplier.buildIdentityProvider(user, groups);
        return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
            Process<?> process = processData.get(processId);
            String image = process.image();
            if (image == null) {
                throw new ProcessImageNotFoundException(process.id());
            }
            Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(instanceId, mapStatus(status), ProcessInstanceReadMode.READ_ONLY);
            if (instance.isEmpty()) {
                throw new ProcessInstanceNotFoundException(instanceId);
            }
            String path = ((AbstractProcess<?>) process).process().getId() + "/" + instanceId;
            if (process.version() != null) {
                path = "/v" + process.version().replaceAll("\\.", "_") + "/" + path;
            }
            ResponseBuilder builder = Response.ok().entity(instance.get().image(path));
            return builder.header("Content-Type", "image/svg+xml").build();
        });
    } finally {
        IdentityProvider.set(null);
    }
}
Also used : Optional(java.util.Optional) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) 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

ProcessInstanceNotFoundException (io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException)9 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Operation (org.eclipse.microprofile.openapi.annotations.Operation)6 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)6 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)4 ArchivedProcessInstance (io.automatiko.engine.api.workflow.ArchivedProcessInstance)4 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)4 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)4 Optional (java.util.Optional)4 GET (javax.ws.rs.GET)4 ProcessImageNotFoundException (io.automatiko.engine.api.workflow.ProcessImageNotFoundException)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 VariableNotFoundException (io.automatiko.engine.api.workflow.VariableNotFoundException)2 JsonArchiveBuilder (io.automatiko.engine.workflow.json.JsonArchiveBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 DELETE (javax.ws.rs.DELETE)2 ProcessInstanceExporter (io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter)1 ErrorInfoDTO (io.automatiko.engine.addons.process.management.model.ErrorInfoDTO)1