All Implemented Interfaces:
Serializable, Tool, ValidExecution

Business task that searches for resources with their associated interventions.
This task performs various validations on the provided ResourceWithInterventionSearchFilter and then executes the search for resources with their interventions based on the filter criteria.
The task is triggered by the ResourceWithInterventionSearchEvent and returns a paginated list of ResourceWithIntervention objects, each containing a resource and its associated interventions with information about whether the resource is a team leader for each intervention.
Since:
18.0
See Also:
GCApi:
task
  • Field Details

  • Constructor Details

    • BTResourceWithInterventionSearch

      public BTResourceWithInterventionSearch()
  • Method Details

    • execute

      protected void execute(ResourceWithInterventionSearchEvent event, PoolKit poolKit) throws DAException, DAValidateException
      Executes the main task logic for searching resources with interventions. This method implements the core functionality of the task, following these steps:
      1. Initialize the task state
      2. Validate the input parameters
      3. Load work order operations based on the filter criteria
      4. Load resources based on the filter criteria
      5. If both operations and resources are found, search for interventions:
        - For assistant resources if not explicitly filtered out
        - For team leader resources if not explicitly filtered out
      6. Build the result by matching resources with their interventions
      7. Create a paginated response and write it to the event journal
      Specified by:
      execute in class ValidExecutionBusinessTask<ResourceWithInterventionSearchEvent>
      Parameters:
      event - The event containing the search filter and pagination information
      poolKit - The PoolKit for database access
      Throws:
      DAException - If any error occurs in the data access layer
      DAValidateException - If any validation error occurs
    • buildResourceWithInterventions

      protected void buildResourceWithInterventions(BOResource resource, List<ResourceWithIntervention> resourceWithInterventionList)
      Builds a ResourceWithIntervention object for the given resource and adds it to the result list. This method processes a single resource and its associated interventions by:
      • Creating a new ResourceWithIntervention instance
      • Setting the resource ID
      • Creating InterventionTeamLeader objects for each intervention
      • Setting the team leader status for each intervention
      • Adding the complete object to the result list
      The method only processes the resource if it exists in the resourceInterventions map.
      Parameters:
      resource - the resource for which to build the ResourceWithIntervention object
      resourceWithInterventionList - the list to which the built object will be added
    • buildInterventionTeamLeader

      protected void buildInterventionTeamLeader(Map.Entry<Long,Boolean> intervention, List<InterventionTeamLeader> interventionsList)
      Creates and configures an InterventionTeamLeader object from the given intervention entry. This method takes an intervention entry containing the intervention ID and team leader status, creates a new InterventionTeamLeader instance, sets its properties, and adds it to the provided interventions list.
      Parameters:
      intervention - the map entry containing the intervention ID (key) and team leader status (value)
      interventionsList - the list to which the created InterventionTeamLeader will be added
    • initialize

      protected void initialize()
      Initializes the class-level fields to their default values. This method resets the state of the task by:
      • Setting woOperations to null to clear any previous work order operations
      • Creating a new empty HashMap for resourceInterventions to store the search results
    • validate

      protected void validate(ResourceWithInterventionSearchFilter filter, PoolKit poolKit) throws DAValidateException
      Validates the input parameters for the resource with intervention search. This method checks the provided filter to ensure that at least one of the date ranges (start and end date or outcome start and end date) is provided. It also validates the provided date ranges to ensure they form a valid interval and do not exceed the maximum allowed period.
      Parameters:
      filter - The resource with intervention search filter containing the parameters to validate
      poolKit - The PoolKit for database access
      Throws:
      DAValidateException - If any validation error occurs, such as missing date ranges, invalid date order, or date ranges exceeding the maximum allowed period
    • getValidInterval

      protected DateTimeRange getValidInterval(DateTimeRange firstInterval, DateTimeRange secondInterval)
      Validates the provided date ranges to ensure they form a valid interval. This method checks the provided intervals and returns a valid date range that can be used for further validation. If both start and end dates are provided in the first interval, it returns that interval. If only one of the dates is provided, it checks the second interval and returns a range if both dates are provided there. If neither range contains both dates, it returns null.
      Parameters:
      firstInterval - The first date range to check
      secondInterval - The second date range to check
      Returns:
      A valid date range that can be used for further validation, or null if no valid range is found
    • validateDates

      protected void validateDates(Date startDate, Date endDate) throws DAValidateException
      Validates a date range to ensure it meets the system requirements. This method performs two validations on the provided date range:
      1. Checks that the start date is not after the end date
      2. Verifies that the date range does not exceed the maximum allowed period defined in the system properties
      If either date is null, no validation is performed.
      Parameters:
      startDate - The start date of the range to validate
      endDate - The end date of the range to validate
      Throws:
      DAValidateException - If the start date is after the end date or if the date range exceeds the maximum limit
    • loadWorkOrderOperations

      protected void loadWorkOrderOperations(ResourceWithInterventionSearchFilter input, PoolKit poolKit) throws DAException, DAValidateException
      Retrieves and processes work order operations based on the provided filter criteria. This method follows a two-step process:
      1. If work orders are specified in the filter, it retrieves all operations associated with those work orders
      2. If work order operations are specified in the filter, it either uses them directly (if no operations were found in step 1) or filters them to keep only those that also exist in the operations found in step 1
      The results are stored in the class-level woOperations field.
      Parameters:
      input - The filter containing work orders and/or work order operations criteria
      poolKit - The PoolKit for database access
      Throws:
      DAException - If an error occurs in the data access layer
      DAValidateException - If any validation error occurs
    • searchWorkOrderOperations

      protected Set<Long> searchWorkOrderOperations(Collection<Long> workOrders, PoolKit poolKit) throws DAException, DAValidateException
      Searches for work order operations associated with the specified work orders. This method creates a search filter with the provided work order IDs and uses the WorkOrderProvider to retrieve all operations associated with those work orders. The results are returned as a set of operation IDs.
      Parameters:
      workOrders - A collection of work order IDs to search operations for
      poolKit - The PoolKit for database access
      Returns:
      A set of work order operation IDs associated with the specified work orders
      Throws:
      DAException - If an error occurs in the data access layer
      DAValidateException - If any validation error occurs
    • filterWorkOrderOperations

      protected Set<Long> filterWorkOrderOperations(Collection<Long> workOrderOperations)
      Filters the collection of work order operations based on the provided input.
      Parameters:
      workOrderOperations - The collection of work order operation ids to be filtered
      Returns:
      A collection of work order operation ids that match the provided input filters
    • loadResources

      protected void loadResources(ResourceWithInterventionSearchFilter filter, PoolKit poolKit) throws DAException, DAValidateException
      Retrieves the collection of resources based on the provided input. First gets resources from filter, then filters by operation center if specified.
      Parameters:
      filter - The input object containing filters for returning the activities assigned to a resource
      poolKit - The PoolKit
      Throws:
      DAException - If an error occurs in the data access layer
      DAValidateException - If any validation error occurs
    • loadAssistantsInterventions

      protected void loadAssistantsInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter) throws DAValidateException, DAException
      Finds and loads interventions assigned to assistant resources (non-team leaders). This method performs a complex search process to identify all interventions that are assigned to resources who are not team leaders for those interventions. The process involves:
      1. Searching for interventions based on the provided filter
      2. Finding all schedulings associated with those interventions
      3. Finding all work shifts associated with those schedulings
      4. Identifying resources assigned to those work shifts who are not team leaders
      5. Creating resource-intervention associations and storing them in the resourceInterventions map
      Parameters:
      poolKit - The PoolKit for database access
      filter - The filter containing search criteria for interventions
      Throws:
      DAValidateException - If any validation errors occur during the search
      DAException - If any other errors occur during the search
    • loadTeamLeaderInterventions

      protected void loadTeamLeaderInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter) throws DAValidateException, DAException
      Finds and loads interventions assigned to team leaders (foremen). This method searches for interventions where the specified resources are team leaders, and then creates resource-intervention associations for each team leader and their interventions. These associations are stored in the resourceInterventions map with the team leader flag set to true. Unlike the assistant interventions search, this method directly uses the foreman field of the intervention to establish the resource-intervention relationship.
      Parameters:
      poolKit - The PoolKit for database access
      filter - The ResourceWithInterventionSearchFilter containing search criteria for interventions
      Throws:
      DAValidateException - If any validation errors occur during the search
      DAException - If any other errors occur during the search
    • searchInterventions

      protected List<BOIntervention> searchInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter, boolean teamLeader) throws DAValidateException, DAException
      Searches for interventions based on the provided filter criteria. This method creates an intervention search filter using the provided criteria and then executes the search through the execution provider. The search can be configured to find interventions for team leaders or for assistants based on the teamLeader parameter. The search filter includes:
      • Work order operations from the class-level woOperations field
      • Status criteria from the provided filter
      • Date range criteria from the provided filter
      • Team leader criteria if the teamLeader parameter is true
      Parameters:
      poolKit - The PoolKit for database access
      filter - The ResourceInterventionSearchFilter containing search criteria for interventions
      teamLeader - If true, searches for interventions where the resources are team leaders; if false, searches for interventions without this constraint
      Returns:
      A list of BOIntervention objects matching the search criteria
      Throws:
      DAValidateException - If any validation errors occur during the search
      DAException - If any other errors occur during the search
    • searchPaginatedResources

      protected PageResponse<BOResource> searchPaginatedResources(Set<Long> resourceIds, ResourceWithInterventionSearchEvent event, PoolKit poolKit) throws DAValidateException, DAException
      Searches for resources based on the provided resource IDs and additional filter criteria. This method creates a resource search filter with the specified resource IDs and, if available, operation center criteria from the event filter. It then launches a ResourceSearchEvent to retrieve the matching resources in a paginated format. The operation center filter is applied to ensure that resources from different operation centers are properly filtered, even if they appear in the resource IDs list.
      Parameters:
      resourceIds - The collection of resource IDs to search for
      event - The event containing additional filter criteria (like operation center)
      poolKit - The PoolKit for database access
      Returns:
      A paginated response containing the matching BOResource objects
      Throws:
      DAValidateException - If any validation errors occur during the search
      DAException - If any other errors occur during the search
    • getIntegrationService

      protected WorkOrdersIntegrationService getIntegrationService(PoolKit poolKit) throws DAValidateException
      Retrieves the WorkOrdersIntegrationService instance. If the instance hasn't been created yet, it will be created and stored for future use.
      Parameters:
      poolKit - The PoolKit.
      Returns:
      The WorkOrdersIntegrationService instance.
      Throws:
      DAValidateException - If any validation error occurs.
    • isValidExecution

      public boolean isValidExecution()
      Determines whether the task execution is valid. This method is required by the ValidPermissionBusinessTask parent class and is used to determine if the task should be executed. In this implementation, it always returns true, indicating that the task is always valid to execute regardless of the context.
      Returns:
      Always returns true, indicating that the task execution is valid
    • loadResourceToInterventions

      protected Map<Long,Map<Long,Boolean>> loadResourceToInterventions(List<BOWorkShift> workShifts, Map<BOIntervention,List<BOScheduling>> interventionSchedulings)
      Processes work shifts and interventions to create resource-intervention associations. This method analyzes the relationship between work shifts and interventions, creating a mapping of resources to their assigned interventions, excluding team leaders from their own interventions. The method performs the following steps: 1. Creates a temporary result map 2. For each work shift, identifies the associated resource 3. Matches the resource's work shifts with intervention schedulings 4. Excludes team leaders from their own interventions 5. Stores valid associations in the resourceInterventions map
      Parameters:
      workShifts - a list of BOWorkShift containing all work shifts to be processed
      interventionSchedulings - a map linking BOIntervention to their corresponding list of BOScheduling. Each intervention can have multiple schedulings associated with it
      Returns:
      The results are stored in the resourceInterventions class field, where: - The outer map key is the resource ID - The inner map key is the intervention (agenda) ID - The inner map value is always false, indicating a non-team-leader association