use of io.quarkus.qute.RawString in project automatiko-engine by automatiko-io.
the class UserTaskManagementResource method get.
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "text/html")), @APIResponse(responseCode = "200", description = "List of available processes", content = @Content(mediaType = "text/html")) })
@Operation(summary = "Retrives user task form for given user task", operationId = "getUserTaskForm")
@SuppressWarnings("unchecked")
@GET
@Path("{processId}/{pInstanceId}/{taskId}")
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get(@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("pInstanceId") String pInstanceId, @Parameter(description = "Unique identifier of the task", required = true) @PathParam("taskId") String taskId, @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) {
IdentityProvider identityProvider = identitySupplier.buildIdentityProvider(user, groups);
try {
Process<?> process = processData.get(processId);
if (process == null) {
return getTemplate("process-not-found", PROCESS_INSTANCE_NOT_FOUND).instance().data("instanceId", pInstanceId);
}
Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(pInstanceId, ProcessInstanceReadMode.READ_ONLY);
if (instance.isEmpty()) {
return getTemplate("process-instance-not-found", PROCESS_INSTANCE_NOT_FOUND).instance().data("instanceId", pInstanceId);
}
ProcessInstance<?> pi = instance.get();
WorkItem task = pi.workItem(taskId, SecurityPolicy.of(identityProvider));
Template template = getTemplate(process.id(), task);
if (template == null) {
template = engine.getTemplate(DEFAULT_TEMPLATE);
}
String link = task.getReferenceId() + "?redirect=true";
if (user != null && !user.isEmpty()) {
link += "&user=" + user;
}
if (groups != null && !groups.isEmpty()) {
for (String group : groups) {
link += "&group=" + group;
}
}
TemplateInstance templateInstance = template.data("task", task).data("url", new RawString(link));
templateInstance.data("inputs", process.taskInputs(task.getId(), task.getName(), task.getParameters()));
Map<String, Object> results = task.getResults();
task.getParameters().entrySet().stream().forEach(e -> results.putIfAbsent(e.getKey(), e.getValue()));
templateInstance.data("results", process.taskOutputs(task.getId(), task.getName(), results));
return templateInstance;
} catch (WorkItemNotFoundException e) {
return getTemplate("task-not-found", TASK_INSTANCE_NOT_FOUND).instance().data("taskId", taskId);
} finally {
IdentityProvider.set(null);
}
}
Aggregations