Class TaskAssignationUtils

java.lang.Object
com.bonitasoft.processbuilder.extension.TaskAssignationUtils

public final class TaskAssignationUtils extends Object
Utility class for task assignation operations.

Provides optimized methods to parse user configuration JSON and collect candidate user IDs for task assignation filters in Bonita processes.

This class is designed to work without direct BDM dependencies. All BDM access is performed through functional interfaces (Suppliers and Functions) that are provided by the calling Groovy script.

Example usage in Groovy script:


 UsersConfigRecord config = TaskAssignationUtils.parseUsersConfig(pbAction.content, logger)
 Set<Long> userIds = TaskAssignationUtils.collectAllUserIds(
     config,
     { stepRef -> getMostRecentStepInstance(stepRef, processInstanceId, dao, logger) },
     { stepInstance -> IdentityUtils.getUserIdFromObject(stepInstance, "getUserId") },
     { membershipRefs -> pBUserListDAO.findByProcessIdAndRefMemberships(processId, membershipRefs, 0, Integer.MAX_VALUE) },
     identityAPI,
     logger
 )
 
Since:
1.0
Author:
Bonitasoft
  • Method Details

    • parseUsersConfig

      public static UsersConfigRecord parseUsersConfig(String jsonContent, org.slf4j.Logger logger)
      Parses JSON content and extracts the user configuration for task assignation.

      Expected JSON structure:

      
       {
         "users": {
           "stepUser": "step_xxx",
           "stepManager": "step_yyy",
           "memberShips": ["membership_1", "membership_2"],
           "membersShipsInput": "step_zzz:field_www"
         }
       }
       
      Parameters:
      jsonContent - The JSON content string to parse (nullable)
      logger - Logger for reporting (nullable)
      Returns:
      UsersConfigRecord with parsed values, or empty config if parsing fails
    • parseUsersNode

      public static Optional<com.fasterxml.jackson.databind.JsonNode> parseUsersNode(String jsonContent, org.slf4j.Logger logger)
      Parses JSON content and returns the "users" node directly.

      This method is useful when you need more control over the JSON parsing or want to access other nodes in the JSON.

      Parameters:
      jsonContent - The JSON content string to parse (nullable)
      logger - Logger for reporting (nullable)
      Returns:
      Optional containing the users JsonNode, or empty if not found
    • collectAllUserIds

      public static <T, M> Set<Long> collectAllUserIds(UsersConfigRecord config, Function<String,T> stepInstanceFinder, Function<T,Long> userIdExtractor, Function<String[],List<M>> membershipFinder, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Collects all candidate user IDs based on the user configuration.

      This method processes all user sources defined in the configuration:

      1. stepUser - User who executed a specific step
      2. stepManager - Manager of the user who executed a specific step
      3. memberShips - Users from static membership references
      4. membersShipsInput - Users from dynamically retrieved membership

      The method uses functional interfaces to access BDM data, ensuring no direct BDM dependencies in this library.

      Type Parameters:
      T - Type of the step instance object
      M - Type of the membership list object
      Parameters:
      config - The parsed user configuration
      stepInstanceFinder - Function that finds a step instance by reference
      userIdExtractor - Function that extracts user ID from a step instance
      membershipFinder - Function that finds membership objects by reference array
      identityAPI - Bonita Identity API for user lookups
      logger - Logger for reporting (nullable)
      Returns:
      Set of unique candidate user IDs (never null, may be empty)
    • processStepUser

      public static <T> Optional<Long> processStepUser(UsersConfigRecord config, Function<String,T> stepInstanceFinder, Function<T,Long> userIdExtractor, org.slf4j.Logger logger)
      Processes the stepUser configuration and returns the user ID.
      Type Parameters:
      T - Type of the step instance object
      Parameters:
      config - The parsed user configuration
      stepInstanceFinder - Function that finds a step instance by reference
      userIdExtractor - Function that extracts user ID from a step instance
      logger - Logger for reporting (nullable)
      Returns:
      Optional containing the step user ID, or empty if not found
    • processStepManager

      public static <T> Optional<Long> processStepManager(UsersConfigRecord config, Function<String,T> stepInstanceFinder, Function<T,Long> userIdExtractor, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Processes the stepManager configuration and returns the manager's user ID.
      Type Parameters:
      T - Type of the step instance object
      Parameters:
      config - The parsed user configuration
      stepInstanceFinder - Function that finds a step instance by reference
      userIdExtractor - Function that extracts user ID from a step instance
      identityAPI - Bonita Identity API for manager lookup
      logger - Logger for reporting (nullable)
      Returns:
      Optional containing the manager user ID, or empty if not found
    • processMemberships

      public static <M> Set<Long> processMemberships(List<String> membershipRefs, Function<String[],List<M>> membershipFinder, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Processes a list of membership references and returns matching user IDs.
      Type Parameters:
      M - Type of the membership list object
      Parameters:
      membershipRefs - List of membership reference strings
      membershipFinder - Function that finds membership objects by reference array
      identityAPI - Bonita Identity API for user lookups
      logger - Logger for reporting (nullable)
      Returns:
      Set of user IDs from the memberships (never null)
    • processSingleMembership

      public static <M> Set<Long> processSingleMembership(String membershipRef, Function<String[],List<M>> membershipFinder, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Processes a single membership reference and returns matching user IDs.

      This is a convenience method for processing a single membership reference instead of a list.

      Type Parameters:
      M - Type of the membership list object
      Parameters:
      membershipRef - Single membership reference string
      membershipFinder - Function that finds membership objects by reference array
      identityAPI - Bonita Identity API for user lookups
      logger - Logger for reporting (nullable)
      Returns:
      Set of user IDs from the membership (never null)
    • extractMembershipFromStepInput

      public static <T> Optional<String> extractMembershipFromStepInput(String stepFieldRefString, Function<String,T> stepInstanceFinder, Function<T,String> jsonInputExtractor, org.slf4j.Logger logger)
      Extracts a membership ID from a step's JSON input field.

      This method parses the step's jsonInput and extracts the value of the specified field. The step and field are specified in the stepFieldRef parameter in format "step_xxx:field_yyy".

      Type Parameters:
      T - Type of the step instance object
      Parameters:
      stepFieldRefString - The step:field reference in format "step_xxx:field_yyy"
      stepInstanceFinder - Function that finds a step instance by reference
      jsonInputExtractor - Function that extracts the jsonInput string from a step instance
      logger - Logger for reporting (nullable)
      Returns:
      Optional containing the membership ID, or empty if not found
    • extractFieldFromJson

      public static Optional<String> extractFieldFromJson(String jsonString, String fieldName, org.slf4j.Logger logger)
      Extracts a field value from a JSON string.
      Parameters:
      jsonString - JSON string to parse
      fieldName - Field name to extract
      logger - Logger for reporting (nullable)
      Returns:
      Optional containing the field value, or empty if not found
    • parseAndCollectUserIds

      public static <T, M> Set<Long> parseAndCollectUserIds(String jsonContent, Function<String,T> stepInstanceFinder, Function<T,Long> userIdExtractor, Function<String[],List<M>> membershipFinder, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Complete flow: parses JSON and collects all user IDs.

      This is a convenience method that combines JSON parsing and user ID collection in a single call.

      Type Parameters:
      T - Type of the step instance object
      M - Type of the membership list object
      Parameters:
      jsonContent - The JSON content string containing user configuration
      stepInstanceFinder - Function that finds a step instance by reference
      userIdExtractor - Function that extracts user ID from a step instance
      membershipFinder - Function that finds membership objects by reference array
      identityAPI - Bonita Identity API for user lookups
      logger - Logger for reporting (nullable)
      Returns:
      Set of unique candidate user IDs (never null)
    • parseAndCollectUserIdsWithDynamicMembership

      public static <T, M> Set<Long> parseAndCollectUserIdsWithDynamicMembership(String jsonContent, Function<String,T> stepInstanceFinder, Function<T,Long> userIdExtractor, Function<T,String> jsonInputExtractor, Function<String[],List<M>> membershipFinder, org.bonitasoft.engine.api.IdentityAPI identityAPI, org.slf4j.Logger logger)
      Complete flow with dynamic membership extraction.

      This version also handles the membersShipsInput field which requires extracting a membership reference from a step's input JSON.

      Type Parameters:
      T - Type of the step instance object
      M - Type of the membership list object
      Parameters:
      jsonContent - The JSON content string containing user configuration
      stepInstanceFinder - Function that finds a step instance by reference
      userIdExtractor - Function that extracts user ID from a step instance
      jsonInputExtractor - Function that extracts jsonInput from a step instance
      membershipFinder - Function that finds membership objects by reference array
      identityAPI - Bonita Identity API for user lookups
      logger - Logger for reporting (nullable)
      Returns:
      Set of unique candidate user IDs (never null)