use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method archiveInstance.
@SuppressWarnings("unchecked")
@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 archived process instance for given instance id as zip")
@GET()
@Path("/{processId}/instances/{instanceId}/archive")
@Produces("application/zip")
public Response archiveInstance(@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 = "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);
ArchivedProcessInstance archived = 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);
if (instance.isEmpty()) {
throw new ProcessInstanceNotFoundException(instanceId);
}
ProcessInstance<?> pi = instance.get();
return pi.archive(new JsonArchiveBuilder());
});
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
archived.writeAsZip(output);
ResponseBuilder builder = Response.ok().entity(output.toByteArray());
if (abort) {
cancelProcessInstanceId(processId, instanceId, "active", user, groups);
}
return builder.header("Content-Type", "application/zip").header("Content-Disposition", "attachment; filename=" + archived.getId() + ".zip").build();
} catch (Exception e) {
LOGGER.error("Error generating process instance archive", e);
return Response.serverError().entity("Error generating process instance archive").build();
}
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method importInstance.
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given process id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Imports exported process instance and returns its details after the import")
@POST
@Path("/{processId}/instances")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO importInstance(@Context UriInfo uriInfo, @Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @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 = "The input model for orders instance", schema = @Schema(type = SchemaType.OBJECT, implementation = Map.class)) JsonExportedProcessInstance instance) {
identitySupplier.buildIdentityProvider(user, groups);
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<?> pi = exporter.importInstance(instance);
ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
details.setId(pi.id());
details.setProcessId(processId);
details.setBusinessKey(pi.businessKey());
details.setDescription(pi.description());
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/" + pi.id() + "/image");
details.setTags(pi.tags().values());
details.setVariables(pi.variables());
VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) pi.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;
});
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project trellis by trellis-ldp.
the class TrellisHttpResource method setResource.
/**
* Perform a PUT operation on a LDP Resource.
*
* @param body the body
* @return the async response
*/
@PUT
@Timed
@Operation(summary = "Create or update a linked data resource")
@APIResponses(value = { @APIResponse(responseCode = "201", description = "The linked data resource was successfully created", content = {}), @APIResponse(responseCode = "204", description = "The linked data resource was successfully updated", content = {}) })
public CompletionStage<Response> setResource(@RequestBody(description = "The updated resource", content = @Content(mediaType = "*/*", schema = @Schema(implementation = LinkedDataResource.class))) final InputStream body) {
final TrellisRequest req = new TrellisRequest(request, uriInfo, headers, security);
final String urlBase = getBaseUrl(req);
final IRI identifier = services.getResourceService().getResourceIdentifier(urlBase, req.getPath());
final PutHandler putHandler = new PutHandler(req, body, services, extensions, preconditionRequired, createUncontained, urlBase);
return getParent(identifier).thenCombine(services.getResourceService().get(identifier), putHandler::initialize).thenCompose(putHandler::setResource).thenCompose(putHandler::updateMemento).thenApply(ResponseBuilder::build).exceptionally(this::handleException);
}
Aggregations