Class TaskRestController

  • All Implemented Interfaces:
    TaskRestOpenApi

    @RestController
    @RequestMapping("/v2.1.1/task-manager/")
    public class TaskRestController
    extends Object
    implements TaskRestOpenApi
    Task Rest Controller.
    Author:
    Mauricio Ruiz Beltrán <mauricio.ruiz@kuwaiba.org>
    • Constructor Detail

      • TaskRestController

        public TaskRestController()
    • Method Detail

      • createTask

        @RequestMapping(method=POST,
                        value="createTask/{sessionId}",
                        produces="application/json")
        public long createTask​(@RequestBody
                               Task task,
                               @PathVariable("sessionId")
                               String sessionId)
        Creates and schedule a task. A task is an application entity that allows to run jobs that will be executed depending on certain schedule.
        Specified by:
        createTask in interface TaskRestOpenApi
        Parameters:
        task - The task that contains, name, description, is the task enabled?, commitOnExecute Should this task commit the changes made (if any) after executing it?, the script to be executed, the parameters for the script, schedule When the task should be executed, notificationType How the result of the task should be notified to the associated users. With the following structure:
         
          {
              "name" : "",
              "description" : "",
              "enabled" : boolean,
              "commitOnExecute" : boolean,
              "script" : "",
              "parameters" : [
                  {
                      "key": "",
                      "value": ""
                  },
                  {
                      "key": "",
                      "value": ""
                  }
              ],
              "schedule" : {
                      "startTime": long,
                      "everyXMinutes": int,
                      "executionType": int
              },
              "notificationType": {
                  "email": "",
                  "notificationType": int
              }
          }
         
         
        sessionId - The session token id.
        Returns:
        The id of the newly created task.
      • updateTaskProperties

        @RequestMapping(method=PUT,
                        value="updateTaskProperties/{id}/{property}/{value}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor updateTaskProperties​(@PathVariable("id")
                                                     long id,
                                                     @PathVariable("property")
                                                     String property,
                                                     @PathVariable("value")
                                                     String value,
                                                     @PathVariable("sessionId")
                                                     String sessionId)
        Updates any of these properties from a task: name, description, enabled and script.
        Specified by:
        updateTaskProperties in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        property - Property name. Possible values: "name", "description", "enabled" and "script".
        value - The value of the property. For the property "enabled", the allowed values are "true" and "false".
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • updateTaskParameters

        @RequestMapping(method=PUT,
                        value="updateTaskParameters/{id}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor updateTaskParameters​(@PathVariable("id")
                                                     long id,
                                                     @RequestBody
                                                     List<StringPair> parameters,
                                                     @PathVariable("sessionId")
                                                     String sessionId)
        Updates the parameters of a task. If any of the values is null, that parameter will be deleted, if the parameter does not exist, it will be created.
        Specified by:
        updateTaskParameters in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        parameters - The parameters to be modified as pairs paramName/paramValue.
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • updateTaskSchedule

        @RequestMapping(method=PUT,
                        value="updateTaskSchedule/{id}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor updateTaskSchedule​(@PathVariable("id")
                                                   long id,
                                                   @RequestBody
                                                   TaskScheduleDescriptor schedule,
                                                   @PathVariable("sessionId")
                                                   String sessionId)
        Updates a task schedule.
        Specified by:
        updateTaskSchedule in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        schedule - New schedule.
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • updateTaskNotificationType

        @RequestMapping(method=PUT,
                        value="updateTaskNotificationType/{id}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor updateTaskNotificationType​(@PathVariable("id")
                                                           long id,
                                                           @RequestBody
                                                           TaskNotificationDescriptor notificationType,
                                                           @PathVariable("sessionId")
                                                           String sessionId)
        Updates a task notification type.
        Specified by:
        updateTaskNotificationType in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        notificationType - New notification type.
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • deleteTask

        @RequestMapping(method=DELETE,
                        value="deleteTask/{id}/{sessionId}",
                        produces="application/json")
        public void deleteTask​(@PathVariable("id")
                               long id,
                               @PathVariable("sessionId")
                               String sessionId)
        Deletes a task and unsubscribes all users from it.
        Specified by:
        deleteTask in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        sessionId - The session token id.
      • subscribeUserToTask

        @RequestMapping(method=PUT,
                        value="subscribeUserToTask/{userId}/{id}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor subscribeUserToTask​(@PathVariable("userId")
                                                    long userId,
                                                    @PathVariable("id")
                                                    long id,
                                                    @PathVariable("sessionId")
                                                    String sessionId)
        Subscribes a user to a task, so it will be notified of the result of its execution.
        Specified by:
        subscribeUserToTask in interface TaskRestOpenApi
        Parameters:
        userId - Id of the user.
        id - Id of the task.
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • unsubscribeUserFromTask

        @RequestMapping(method=PUT,
                        value="unsubscribeUserFromTask/{userId}/{id}/{sessionId}",
                        produces="application/json")
        public ChangeDescriptor unsubscribeUserFromTask​(@PathVariable("userId")
                                                        long userId,
                                                        @PathVariable("id")
                                                        long id,
                                                        @PathVariable("sessionId")
                                                        String sessionId)
        Unsubscribes a user from a task, so it will no longer be notified about the result of its execution.
        Specified by:
        unsubscribeUserFromTask in interface TaskRestOpenApi
        Parameters:
        userId - Id of the user.
        id - Id of the task.
        sessionId - The session token id.
        Returns:
        The summary of the changes.
      • getTask

        @RequestMapping(method=GET,
                        value="getTask/{id}/{sessionId}",
                        produces="application/json")
        public Task getTask​(@PathVariable("id")
                            long id,
                            @PathVariable("sessionId")
                            String sessionId)
        Retrieves the information about a particular task.
        Specified by:
        getTask in interface TaskRestOpenApi
        Parameters:
        id - Id of the task.
        sessionId - The session token id.
        Returns:
        A list with the task objects.
      • getSubscribersForTask

        @RequestMapping(method=GET,
                        value="getSubscribersForTask/{id}/{sessionId}",
                        produces="application/json")
        public List<UserProfileLight> getSubscribersForTask​(@PathVariable("id")
                                                            long id,
                                                            @PathVariable("sessionId")
                                                            String sessionId)
        Gets the subscribers of a particular task.
        Specified by:
        getSubscribersForTask in interface TaskRestOpenApi
        Parameters:
        id - Task id.
        sessionId - The session token id.
        Returns:
        The list of users subscribers to the task identified with the id taskId.
      • getTasks

        @RequestMapping(method=GET,
                        value="getTasks/{sessionId}",
                        produces="application/json")
        public List<Task> getTasks​(@PathVariable("sessionId")
                                   String sessionId)
        Gets all registered tasks.
        Specified by:
        getTasks in interface TaskRestOpenApi
        Parameters:
        sessionId - The session token id.
        Returns:
        A list with the task objects.
      • getTasksForUser

        @RequestMapping(method=GET,
                        value="getTasksForUser/{userId}/{sessionId}",
                        produces="application/json")
        public List<Task> getTasksForUser​(@PathVariable("userId")
                                          long userId,
                                          @PathVariable("sessionId")
                                          String sessionId)
        Gets the tasks associated to a particular user.
        Specified by:
        getTasksForUser in interface TaskRestOpenApi
        Parameters:
        userId - Id of the user.
        sessionId - The session token id.
        Returns:
        A list with the task objects.
      • executeTask

        @RequestMapping(method=PUT,
                        value="executeTask/{id}/{sessionId}",
                        produces="application/json")
        public TaskResult executeTask​(@PathVariable("id")
                                      long id,
                                      @PathVariable("sessionId")
                                      String sessionId)
        Executes a task on demand. The task may have user-defined parameters that must be set using #updateTaskParameters(long, java.util.List) before running the task.
        Specified by:
        executeTask in interface TaskRestOpenApi
        Parameters:
        id - Id of the task. Could be known by calling #getTasks() first.
        sessionId - The session token id.
        Returns:
        An TaskResult instance representing the task result.