use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses 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();
});
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project automatiko-engine by automatiko-io.
the class $Type$Resource method create_$name$.
@APIResponses(value = { @APIResponse(responseCode = "400", description = "In case request given does not meet expectations", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "500", description = "In case of processing errors", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "409", description = "In case an instance already exists with given business key", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "403", description = "In case an instance cannot be created due to access policy by the caller", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Successfully created instance", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))), @APIResponse(responseCode = "202", description = "Successfully accepted request to create instance (applies only to async execution mode)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = $Type$Output.class))) })
@Operation(summary = "Creates new instance of $name$")
@POST()
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response create_$name$(@Context HttpHeaders httpHeaders, @QueryParam("businessKey") @Parameter(description = "Alternative id to be assigned to the instance", required = false) String businessKey, @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 = "Indicates if instance metadata should be included", required = false) @QueryParam("metadata") @DefaultValue("false") final boolean metadata, @Parameter(description = "The input model for $name$ instance") $Type$Input resource) {
if (resource == null) {
resource = new $Type$Input();
}
final $Type$Input value = resource;
String execMode = httpHeaders.getHeaderString("X-ATK-Mode");
if ("async".equalsIgnoreCase(execMode)) {
String callbackUrl = httpHeaders.getHeaderString("X-ATK-Callback");
String startFromNode = httpHeaders.getHeaderString("X-ATK-StartFromNode");
ProcessInstance<$Type$> pi = process.createInstance(businessKey, mapInput(value, new $Type$()));
((AbstractProcessInstance<$Type$>) pi).unlock(true);
$Type$Output output = mapOutput(new $Type$Output(), pi.variables(), businessKey, pi.metadata());
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(), () -> {
if (startFromNode != null) {
pi.startFrom(startFromNode);
} else {
pi.start();
}
tracing(pi);
$Type$Output result = getModel(pi, metadata);
io.automatiko.engine.workflow.http.HttpCallbacks.get().post(callbackUrl, result, httpAuth.produce(headers), pi.status());
return null;
});
});
ResponseBuilder builder = Response.accepted().entity(output);
return builder.build();
} else {
identitySupplier.buildIdentityProvider(user, groups);
return io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<$Type$> pi = process.createInstance(businessKey, mapInput(value, new $Type$()));
String startFromNode = httpHeaders.getHeaderString("X-ATK-StartFromNode");
if (startFromNode != null) {
pi.startFrom(startFromNode);
} else {
pi.start();
}
tracing(pi);
ResponseBuilder builder = Response.ok().entity(getModel(pi, metadata));
return builder.build();
});
}
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses in project automatiko-engine by automatiko-io.
the class ProcessInstanceManagementResource method get.
@APIResponses(value = { @APIResponse(responseCode = "200", description = "List of available processes", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Lists available public processes in the service")
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public List<ProcessDTO> get(@Context UriInfo uriInfo, @Parameter(description = "Pagination - page to start on", required = false) @QueryParam(value = "page") @DefaultValue("1") int page, @Parameter(description = "Pagination - number of items to return", required = false) @QueryParam(value = "size") @DefaultValue("10") int size, @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) {
List<ProcessDTO> collected = new ArrayList<ProcessDTO>();
try {
identitySupplier.buildIdentityProvider(user, groups);
for (String id : processData.keySet()) {
Process<?> process = processData.get(id);
if (!WorkflowProcess.PUBLIC_VISIBILITY.equals(((WorkflowProcess) ((AbstractProcess<?>) process).process()).getVisibility())) {
continue;
}
String pathprefix = "";
if (process.version() != null) {
pathprefix = "v" + process.version().replaceAll("\\.", "_") + "/";
}
collected.add(new ProcessDTO(id, process.version(), process.name(), (String) ((AbstractProcess<?>) process).process().getMetaData().get("Documentation"), uriInfo.getBaseUri().toString() + pathprefix + ((AbstractProcess<?>) process).process().getId() + "/image", process.instances().size()));
}
return collected;
} finally {
IdentityProvider.set(null);
}
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses 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;
}
use of org.eclipse.microprofile.openapi.annotations.responses.APIResponses 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);
}
}
Aggregations