Search in sources :

Example 1 with ProcessImageNotFoundException

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

the class $Type$Resource method get_instance_image_$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 retrieved instance", content = @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))) })
@Operation(hidden = true, summary = "Retrieves $name$ instance's image for given id")
@GET()
@Path("$prefix$/$name$/{id_$name$}/image")
@Produces(MediaType.APPLICATION_JSON)
public Response get_instance_image_$name$(@Context UriInfo uri, @PathParam("id") String id, @PathParam("id_$name$") String id_$name$, @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) {
    identitySupplier.buildIdentityProvider(user, groups);
    return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
        ProcessInstance<$Type$> instance = subprocess_$name$.instances().findById($parentprocessid$ + ":" + id_$name$, mapStatus(status), io.automatiko.engine.api.workflow.ProcessInstanceReadMode.READ_ONLY).orElseThrow(() -> new ProcessInstanceNotFoundException(id));
        String image = instance.image(extractImageBaseUri(uri.getRequestUri().toString()));
        if (image == null) {
            throw new ProcessImageNotFoundException(subprocess_$name$.id());
        }
        ResponseBuilder builder = Response.ok().entity(image);
        return builder.header("Content-Type", "image/svg+xml").build();
    });
}
Also used : ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ProcessImageNotFoundException

use of io.automatiko.engine.api.workflow.ProcessImageNotFoundException 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)

Example 3 with ProcessImageNotFoundException

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

the class ProcessImageNotFoundExceptionMapper method toResponse.

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

Example 4 with ProcessImageNotFoundException

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

the class $Type$Resource method get_image_$name$.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of image does not exist for $name$", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully retrieved instance's image", content = @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))) })
@Operation(hidden = true, summary = "Retrieves image for $name$")
@GET()
@Path("$prefix$/$name$/image")
@Produces(MediaType.APPLICATION_SVG_XML)
public Response get_image_$name$() {
    String image = subprocess_$name$.image();
    if (image == null) {
        throw new ProcessImageNotFoundException(process.id());
    }
    ResponseBuilder builder = Response.ok().entity(image);
    return builder.header("Content-Type", "image/svg+xml").build();
}
Also used : ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ProcessImageNotFoundException (io.automatiko.engine.api.workflow.ProcessImageNotFoundException)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)1 ArchivedProcessInstance (io.automatiko.engine.api.workflow.ArchivedProcessInstance)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 ProcessInstanceNotFoundException (io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Operation (org.eclipse.microprofile.openapi.annotations.Operation)1 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)1