Class TaskUtil

java.lang.Object
com.ssgllc.fish.service.util.published.TaskUtil

@Component public class TaskUtil extends Object
Reads and manipulates BPM tasks from a Groovy script - assignment, completion and task data.

Called as the taskUtil bean. For the process instance around the task see ProcessUtil.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.flowable.form.api.FormService
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addGroupIdentityLink(String taskId, String roleName, String type)
    Adds a group identity link of the given type to a task, making it accessible to users holding the role.
    addNote(String taskId, String note)
    Adds a note associated with the given task to the task's process note thread and returns the created note's id.
    updateCompletedFormVariables(String taskId, Map<String,Object> variablesToUpdate)
    Updates form variables for a task that has already been completed.
    void
    updateFormVariables(String formKey, String taskId, String processInstanceId, Map<String,Object> variablesToUpdate)
    Updates form variables for the given task identifiers by applying the provided values and preserving existing ones.
    Use this overload when only the raw identifiers are available rather than a TaskEntity.
    Only fields present in the form and the update map are modified.
    void
    updateFormVariables(org.flowable.task.service.impl.persistence.entity.TaskEntity task, Map<String,Object> variablesToUpdate)
    Updates form variables for the given task by applying the provided values and preserving existing ones.
    Only fields present in the form and the update map are modified.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • formService

      @Autowired protected org.flowable.form.api.FormService formService
  • Constructor Details

    • TaskUtil

      public TaskUtil()
  • Method Details

    • updateFormVariables

      public void updateFormVariables(org.flowable.task.service.impl.persistence.entity.TaskEntity task, Map<String,Object> variablesToUpdate)
      Updates form variables for the given task by applying the provided values and preserving existing ones.
      Only fields present in the form and the update map are modified.
      Parameters:
      task - The task whose form variables are to be updated.
      variablesToUpdate - A map of field names and their new values.

      Groovy example:
      taskUtil.updateFormVariables(task, ["field1": "newVal", "field2": 42])
      Note: No update occurs if the task has no form or no fields.
    • updateFormVariables

      public void updateFormVariables(String formKey, String taskId, String processInstanceId, Map<String,Object> variablesToUpdate)
      Updates form variables for the given task identifiers by applying the provided values and preserving existing ones.
      Use this overload when only the raw identifiers are available rather than a TaskEntity.
      Only fields present in the form and the update map are modified.
      Parameters:
      formKey - The form key of the task.
      taskId - The id of the task.
      processInstanceId - The process instance id of the task.
      variablesToUpdate - A map of field names and their new values.

      For a task that is already completed, use updateCompletedFormVariables(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>) instead; this method requires the task to still be active.

      Groovy example:
      taskUtil.updateFormVariables(formKey, taskId, processInstanceId, ["field1": "newVal", "field2": 42])
      Note: No update occurs if the task has no form or no fields.
    • updateCompletedFormVariables

      public Set<String> updateCompletedFormVariables(String taskId, Map<String,Object> variablesToUpdate)
      Updates form variables for a task that has already been completed. updateFormVariables(org.flowable.task.service.impl.persistence.entity.TaskEntity, java.util.Map<java.lang.String, java.lang.Object>) cannot be used for a completed task because the underlying save rejects it. Only the saved form-instance snapshot is updated — the completed-task form is rendered from that snapshot, so the corrected values show in task history. The snapshot is persisted in task history, so this works whether or not the process instance is still active.
      Only the supplied fields are changed; no expression fields are re-evaluated.

      Supply each value in the same shape the field stores (e.g. a table field is a List of row Maps): read the current value, modify it, and pass the whole value back. Do not, for example, hand a JSON String for a field whose value is a List.
      Parameters:
      taskId - The id of the completed task.
      variablesToUpdate - A map of field names and their new values.
      Returns:
      the ids of the fields that were actually applied to the snapshot. A requested id that is not a top-level form field is ignored and omitted, so compare this against your input keys to detect a misspelled or unknown field. An empty set means nothing was applied. A hard failure (e.g. no saved form instance exists for the task) throws.

      Groovy example (simple field):
      def vars = [:]
      vars["decimal"] = 102.2
      def applied = taskUtil.updateCompletedFormVariables(taskId, vars)
      assert applied.contains("decimal")

      Groovy example (table field — pass the whole List of row Maps back):
      def table = ... // current value as List<Map>
      table[0]["score"] = 222
      taskUtil.updateCompletedFormVariables(taskId, ["table": table])
    • addGroupIdentityLink

      public void addGroupIdentityLink(String taskId, String roleName, String type)
      Adds a group identity link of the given type to a task, making it accessible to users holding the role. Works for open and completed tasks (a completed task — e.g. one copied to another process by a case merge — gets the historic link only). Does nothing if the task already has the link.
      Groovy example:
      taskUtil.addGroupIdentityLink(taskId, "ROLE_ICP", "candidate")
      Returns: nothing; the task becomes visible to users with ROLE_ICP
      Parameters:
      taskId - the id of the task (open or completed)
      roleName - the role granting access (e.g. "ROLE_ICP")
      type - the identity link type: "candidate" for candidate-group access, "viewable" for view-only access
    • addNote

      public String addNote(String taskId, String note)
      Adds a note associated with the given task to the task's process note thread and returns the created note's id. Works for open and completed tasks; the note is linked to both the task and its process instance. For a process-level note not tied to a task, use processUtil.addNote instead.
      The note is created with security bypassed: the executing user does not need access to the task, so scripts fired without an authenticated user (timers, message events) work too.
      Groovy example:
      def noteId = taskUtil.addNote(taskId, 'Documents verified')
      Returns: the id of the created ProcessNote
      Parameters:
      taskId - the id of the task (open or completed)
      note - the note text
      Returns:
      the created ProcessNote's id