Class TasksResource

java.lang.Object
io.goobi.viewer.api.rest.v1.tasks.TasksResource

@Path("/tasks") public class TasksResource extends Object
REST resource for creating and monitoring asynchronous TaskManager tasks within the viewer, such as PDF pre-rendering.
Author:
Florian Alpers
  • Constructor Details

  • Method Details

    • addTask

      @POST @Consumes("application/json") @Produces("application/json") public Response addTask(TaskParameter desc) throws WebApplicationException
      Creates a task for the given TaskParameter.getType() and starts it asynchronously.

      If the internal message queue broker is enabled in the configuration, which is the default, only the three task types that carry a dedicated TaskParameter subtype are queued as a ViewerMessage and processed by the message queue consumer (sitemap update, data repository name update, PDF pre-rendering); any other type is accepted but creates no task. With the broker disabled, the task runs as an in-memory Task on a fixed pool of five worker threads. The task type also determines, via Task.getAccessibility(ITaskType), the authorization required to create it (token, admin or session, depending on the type).

      Parameters:
      desc - parameters describing the task to create, including its type
      Returns:
      the created Task or ViewerMessage
      Throws:
      WebApplicationException - if no task type is given, the caller is not authorized to create it, or the message queue rejects the task
    • getTask

      @GET @Path("/{id}") @Produces("application/json") public Response getTask(@PathParam("id") String id) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
      Returns a single task or message-queue job by id, provided the request is authorized to access it.

      A purely numeric id is looked up among the tasks held in memory by the viewer's task manager; any other id is treated as a message queue job id and looked up first via the message broker, then, if not found there, in the database. Authorization depends on the Task.Accessibility of the underlying task type: token tasks require the same authorization header as other protected endpoints, admin tasks require an active admin session, and session tasks are only visible to the session that created them.

      Parameters:
      id - the id of the task
      Returns:
      the Task or ViewerMessage with the given id
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - if no task or job is found for the given id, or the request is not authorized to access it
    • getTasks

      @GET @Produces("application/json") public List<Task> getTasks()
      Returns the tasks held in memory by the viewer's task manager that the current request is authorized to see.

      Unlike getTask(String), this only lists locally tracked tasks, not asynchronous message queue jobs. Visibility of each task depends on its accessibility: token tasks require the same authorization token as other protected endpoints, admin tasks require an active admin session, and session tasks are included only for the session that created them.

      Returns:
      the list of tasks visible to the current request
    • isAuthorized

      public boolean isAuthorized(ITaskType type, Optional<String> jobSessionId, HttpServletRequest request)