Class BTResourceWithInterventionSearch
java.lang.Object
overit.geocall.bl.BusinessTask<ResourceWithInterventionSearchEvent>
overit.geocallapp.utilities.core.bl.common.validexecution.ValidExecutionBusinessTask<ResourceWithInterventionSearchEvent>
overit.geocallapp.utilities.core.bl.common.validexecution.ValidPermissionBusinessTask<ResourceWithInterventionSearchEvent>
overit.geocallapp.wfm.orchestrator.workorders.bl.resourcewithintervention.task.BTResourceWithInterventionSearch
- All Implemented Interfaces:
Serializable,Tool,ValidExecution
@Event(ResourceWithInterventionSearchEvent.class)
public class BTResourceWithInterventionSearch
extends ValidPermissionBusinessTask<ResourceWithInterventionSearchEvent>
Business task that searches for resources with their associated interventions.
This task performs various validations on the provided
The task is triggered by the
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 Summary
FieldsModifier and TypeFieldDescriptionprotected Collection<Long> protected Collection<Long> protected WorkOrdersIntegrationServiceFields inherited from class overit.geocallapp.utilities.core.bl.common.validexecution.ValidPermissionBusinessTask
LOG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildInterventionTeamLeader(Map.Entry<Long, Boolean> intervention, List<InterventionTeamLeader> interventionsList) Creates and configures anInterventionTeamLeaderobject from the given intervention entry.protected voidbuildResourceWithInterventions(BOResource resource, List<ResourceWithIntervention> resourceWithInterventionList) Builds aResourceWithInterventionobject for the given resource and adds it to the result list.protected voidexecute(ResourceWithInterventionSearchEvent event, PoolKit poolKit) Executes the main task logic for searching resources with interventions.filterWorkOrderOperations(Collection<Long> workOrderOperations) Filters the collection of work order operations based on the provided input.protected WorkOrdersIntegrationServicegetIntegrationService(PoolKit poolKit) Retrieves theWorkOrdersIntegrationServiceinstance.protected DateTimeRangegetValidInterval(DateTimeRange firstInterval, DateTimeRange secondInterval) Validates the provided date ranges to ensure they form a valid interval.protected voidInitializes the class-level fields to their default values.booleanDetermines whether the task execution is valid.protected voidloadAssistantsInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter) Finds and loads interventions assigned to assistant resources (non-team leaders).protected voidloadResources(ResourceWithInterventionSearchFilter filter, PoolKit poolKit) Retrieves the collection of resources based on the provided input.loadResourceToInterventions(List<BOWorkShift> workShifts, Map<BOIntervention, List<BOScheduling>> interventionSchedulings) Processes work shifts and interventions to create resource-intervention associations.protected voidloadTeamLeaderInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter) Finds and loads interventions assigned to team leaders (foremen).protected voidloadWorkOrderOperations(ResourceWithInterventionSearchFilter input, PoolKit poolKit) Retrieves and processes work order operations based on the provided filter criteria.protected List<BOIntervention> searchInterventions(PoolKit poolKit, ResourceWithInterventionSearchFilter filter, boolean teamLeader) Searches for interventions based on the provided filter criteria.protected PageResponse<BOResource> searchPaginatedResources(Set<Long> resourceIds, ResourceWithInterventionSearchEvent event, PoolKit poolKit) Searches for resources based on the provided resource IDs and additional filter criteria.searchWorkOrderOperations(Collection<Long> workOrders, PoolKit poolKit) Searches for work order operations associated with the specified work orders.protected voidvalidate(ResourceWithInterventionSearchFilter filter, PoolKit poolKit) Validates the input parameters for the resource with intervention search.protected voidvalidateDates(Date startDate, Date endDate) Validates a date range to ensure it meets the system requirements.Methods inherited from class overit.geocallapp.utilities.core.bl.common.validexecution.ValidPermissionBusinessTask
checkValidExecution, getException, throwExceptionIfInvalidMethods inherited from class overit.geocallapp.utilities.core.bl.common.validexecution.ValidExecutionBusinessTask
body, getEventMethods inherited from class overit.geocall.bl.BusinessTask
start, start, startAlone, startInBackground
-
Field Details
-
workOrdersIntegrationService
-
resourceInterventions
-
woOperations
-
resources
-
-
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:- Initialize the task state
- Validate the input parameters
- Load work order operations based on the filter criteria
- Load resources based on the filter criteria
- 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 - Build the result by matching resources with their interventions
- Create a paginated response and write it to the event journal
- Specified by:
executein classValidExecutionBusinessTask<ResourceWithInterventionSearchEvent>- Parameters:
event- The event containing the search filter and pagination informationpoolKit- ThePoolKitfor database access- Throws:
DAException- If any error occurs in the data access layerDAValidateException- If any validation error occurs
-
buildResourceWithInterventions
protected void buildResourceWithInterventions(BOResource resource, List<ResourceWithIntervention> resourceWithInterventionList) Builds aResourceWithInterventionobject 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
ResourceWithInterventioninstance - Setting the resource ID
- Creating
InterventionTeamLeaderobjects for each intervention - Setting the team leader status for each intervention
- Adding the complete object to the result list
- Parameters:
resource- the resource for which to build the ResourceWithIntervention objectresourceWithInterventionList- the list to which the built object will be added
- Creating a new
-
buildInterventionTeamLeader
protected void buildInterventionTeamLeader(Map.Entry<Long, Boolean> intervention, List<InterventionTeamLeader> interventionsList) Creates and configures anInterventionTeamLeaderobject from the given intervention entry. This method takes an intervention entry containing the intervention ID and team leader status, creates a newInterventionTeamLeaderinstance, 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 createdInterventionTeamLeaderwill 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 validatepoolKit- ThePoolKitfor 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
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 checksecondInterval- 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
Validates a date range to ensure it meets the system requirements. This method performs two validations on the provided date range:- Checks that the start date is not after the end date
- Verifies that the date range does not exceed the maximum allowed period defined in the system properties
- Parameters:
startDate- The start date of the range to validateendDate- 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:- If work orders are specified in the filter, it retrieves all operations associated with those work orders
- 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
woOperationsfield.- Parameters:
input- The filter containing work orders and/or work order operations criteriapoolKit- ThePoolKitfor database access- Throws:
DAException- If an error occurs in the data access layerDAValidateException- 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 theWorkOrderProviderto 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 forpoolKit- ThePoolKitfor 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 layerDAValidateException- If any validation error occurs
-
filterWorkOrderOperations
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 resourcepoolKit- ThePoolKit- Throws:
DAException- If an error occurs in the data access layerDAValidateException- 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:- Searching for interventions based on the provided filter
- Finding all schedulings associated with those interventions
- Finding all work shifts associated with those schedulings
- Identifying resources assigned to those work shifts who are not team leaders
- Creating resource-intervention associations and storing them in the resourceInterventions map
- Parameters:
poolKit- ThePoolKitfor database accessfilter- The filter containing search criteria for interventions- Throws:
DAValidateException- If any validation errors occur during the searchDAException- 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- ThePoolKitfor database accessfilter- TheResourceWithInterventionSearchFiltercontaining search criteria for interventions- Throws:
DAValidateException- If any validation errors occur during the searchDAException- 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- ThePoolKitfor database accessfilter- TheResourceInterventionSearchFiltercontaining search criteria for interventionsteamLeader- If true, searches for interventions where the resources are team leaders; if false, searches for interventions without this constraint- Returns:
- A list of
BOInterventionobjects matching the search criteria - Throws:
DAValidateException- If any validation errors occur during the searchDAException- 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 aResourceSearchEventto 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 forevent- The event containing additional filter criteria (like operation center)poolKit- ThePoolKitfor database access- Returns:
- A paginated response containing the matching
BOResourceobjects - Throws:
DAValidateException- If any validation errors occur during the searchDAException- If any other errors occur during the search
-
getIntegrationService
protected WorkOrdersIntegrationService getIntegrationService(PoolKit poolKit) throws DAValidateException Retrieves theWorkOrdersIntegrationServiceinstance. If the instance hasn't been created yet, it will be created and stored for future use.- Parameters:
poolKit- ThePoolKit.- Returns:
- The
WorkOrdersIntegrationServiceinstance. - 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, loadResourceToInterventionsBoolean>> (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 ofBOWorkShiftcontaining all work shifts to be processedinterventionSchedulings- a map linkingBOInterventionto their corresponding list ofBOScheduling. Each intervention can have multiple schedulings associated with it- Returns:
- The results are stored in the
resourceInterventionsclass 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
-