Class TaskAssignationUtils
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 Summary
Modifier and TypeMethodDescriptioncollectAllUserIds(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.extractFieldFromJson(String jsonString, String fieldName, org.slf4j.Logger logger) Extracts a field value from a JSON 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.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.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.static UsersConfigRecordparseUsersConfig(String jsonContent, org.slf4j.Logger logger) Parses JSON content and extracts the user configuration for task assignation.static Optional<com.fasterxml.jackson.databind.JsonNode>parseUsersNode(String jsonContent, org.slf4j.Logger logger) Parses JSON content and returns the "users" node directly.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.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.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.processStepUser(UsersConfigRecord config, Function<String, T> stepInstanceFinder, Function<T, Long> userIdExtractor, org.slf4j.Logger logger) Processes the stepUser configuration and returns the user ID.
-
Method Details
-
parseUsersConfig
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:
- stepUser - User who executed a specific step
- stepManager - Manager of the user who executed a specific step
- memberShips - Users from static membership references
- 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 objectM- Type of the membership list object- Parameters:
config- The parsed user configurationstepInstanceFinder- Function that finds a step instance by referenceuserIdExtractor- Function that extracts user ID from a step instancemembershipFinder- Function that finds membership objects by reference arrayidentityAPI- Bonita Identity API for user lookupslogger- 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 configurationstepInstanceFinder- Function that finds a step instance by referenceuserIdExtractor- Function that extracts user ID from a step instancelogger- 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 configurationstepInstanceFinder- Function that finds a step instance by referenceuserIdExtractor- Function that extracts user ID from a step instanceidentityAPI- Bonita Identity API for manager lookuplogger- 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 stringsmembershipFinder- Function that finds membership objects by reference arrayidentityAPI- Bonita Identity API for user lookupslogger- 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 stringmembershipFinder- Function that finds membership objects by reference arrayidentityAPI- Bonita Identity API for user lookupslogger- 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 referencejsonInputExtractor- Function that extracts the jsonInput string from a step instancelogger- 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 parsefieldName- Field name to extractlogger- 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 objectM- Type of the membership list object- Parameters:
jsonContent- The JSON content string containing user configurationstepInstanceFinder- Function that finds a step instance by referenceuserIdExtractor- Function that extracts user ID from a step instancemembershipFinder- Function that finds membership objects by reference arrayidentityAPI- Bonita Identity API for user lookupslogger- 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 objectM- Type of the membership list object- Parameters:
jsonContent- The JSON content string containing user configurationstepInstanceFinder- Function that finds a step instance by referenceuserIdExtractor- Function that extracts user ID from a step instancejsonInputExtractor- Function that extracts jsonInput from a step instancemembershipFinder- Function that finds membership objects by reference arrayidentityAPI- Bonita Identity API for user lookupslogger- Logger for reporting (nullable)- Returns:
- Set of unique candidate user IDs (never null)
-