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();
});
}
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);
}
}
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);
}
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();
}
Aggregations