diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/ia/CftQueryServiceITTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/ia/CftQueryServiceITTest.java index fbf60d3e64..f72b166d16 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/ia/CftQueryServiceITTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/ia/CftQueryServiceITTest.java @@ -40,6 +40,9 @@ import uk.gov.hmcts.reform.wataskmanagementapi.domain.search.SortingParameter; import uk.gov.hmcts.reform.wataskmanagementapi.domain.search.parameter.SearchParameterList; import uk.gov.hmcts.reform.wataskmanagementapi.domain.task.Task; +import uk.gov.hmcts.reform.wataskmanagementapi.entity.TaskResource; +import uk.gov.hmcts.reform.wataskmanagementapi.repository.TaskResourceRepository; +import uk.gov.hmcts.reform.wataskmanagementapi.services.CFTTaskDatabaseService; import uk.gov.hmcts.reform.wataskmanagementapi.services.CFTTaskMapper; import uk.gov.hmcts.reform.wataskmanagementapi.services.CamundaService; @@ -47,8 +50,10 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -76,14 +81,21 @@ public class CftQueryServiceITTest extends RoleAssignmentHelper { @Autowired private AllowedJurisdictionConfiguration allowedJurisdictionConfiguration; + private CFTTaskDatabaseService cftTaskDatabaseService; + private static final UserInfo userInfo = UserInfo.builder().email("user@test.com").uid("user").build(); + @Autowired + TaskResourceRepository taskResourceRepository; + @BeforeEach void setUp() { CFTTaskMapper cftTaskMapper = new CFTTaskMapper(new ObjectMapper()); cftQueryService = new CftQueryService(camundaService, cftTaskMapper, new TaskResourceDao(entityManager), allowedJurisdictionConfiguration ); + + cftTaskDatabaseService = new CFTTaskDatabaseService(taskResourceRepository, cftTaskMapper); } @Disabled @@ -111,9 +123,9 @@ void shouldRetrieveTasks(TaskQueryScenario scenario) { AccessControlResponse accessControlResponse = new AccessControlResponse(scenario.userInfo, scenario.roleAssignments); SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); - + indexRecord(); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -818,6 +830,7 @@ private static List roleAssignmentWithAllGrantTypes(Classificati List roleAssignments = new ArrayList<>(); RoleAssignment roleAssignment = RoleAssignment.builder().roleName("hmcts-judiciary") .classification(classification) + .attributes(Collections.emptyMap()) .grantType(GrantType.SPECIFIC) .roleType(RoleType.ORGANISATION) .beginTime(OffsetDateTime.now().minusYears(1)) @@ -869,12 +882,9 @@ private static List roleAssignmentWithAllGrantTypes(Classificati .build(); roleAssignments.add(roleAssignment); - final Map excludeddAttributes = Map.of( - RoleAttributeDefinition.CASE_ID.value(), "1623278362431003" - ); roleAssignment = RoleAssignment.builder().roleName("senior-tribunal-caseworker") .classification(classification) - .attributes(excludeddAttributes) + .attributes(Collections.emptyMap()) .grantType(GrantType.EXCLUDED) .roleType(RoleType.CASE) .beginTime(OffsetDateTime.now().minusYears(1)) @@ -891,6 +901,7 @@ private static List defaultSort(Classification classification) { .classification(classification) .roleType(RoleType.ORGANISATION) .grantType(GrantType.SPECIFIC) + .attributes(Collections.emptyMap()) .beginTime(OffsetDateTime.now().minusYears(1)) .endTime(OffsetDateTime.now().plusYears(1)) .build(); @@ -919,4 +930,15 @@ public String toString() { } } + + private void indexRecord() { + List ids = new ArrayList<>(); + taskResourceRepository.findAll().forEach(taskResource -> ids.add(taskResource.getTaskId())); + ids.forEach(id -> { + Optional taskResource = taskResourceRepository.findById(id); + TaskResource task = taskResource.get(); + task.setIndexed(true); + taskResourceRepository.save(task); + }); + } } diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/wa/CftQueryServiceITTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/wa/CftQueryServiceITTest.java index c0492feeb8..69533b5d48 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/wa/CftQueryServiceITTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/wataskmanagementapi/cft/query/wa/CftQueryServiceITTest.java @@ -14,6 +14,8 @@ import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.bean.override.mockito.MockitoBean; @@ -25,6 +27,7 @@ import uk.gov.hmcts.reform.wataskmanagementapi.auth.permission.entities.PermissionTypes; import uk.gov.hmcts.reform.wataskmanagementapi.auth.role.entities.RoleAssignment; import uk.gov.hmcts.reform.wataskmanagementapi.auth.role.entities.enums.Classification; +import uk.gov.hmcts.reform.wataskmanagementapi.auth.role.entities.enums.GrantType; import uk.gov.hmcts.reform.wataskmanagementapi.cft.query.CftQueryService; import uk.gov.hmcts.reform.wataskmanagementapi.cft.query.TaskResourceDao; import uk.gov.hmcts.reform.wataskmanagementapi.config.AllowedJurisdictionConfiguration; @@ -40,13 +43,18 @@ import uk.gov.hmcts.reform.wataskmanagementapi.domain.search.SortingParameter; import uk.gov.hmcts.reform.wataskmanagementapi.domain.search.parameter.SearchParameterList; import uk.gov.hmcts.reform.wataskmanagementapi.domain.task.Task; +import uk.gov.hmcts.reform.wataskmanagementapi.entity.TaskResource; +import uk.gov.hmcts.reform.wataskmanagementapi.repository.TaskResourceRepository; +import uk.gov.hmcts.reform.wataskmanagementapi.services.CFTTaskDatabaseService; import uk.gov.hmcts.reform.wataskmanagementapi.services.CFTTaskMapper; import uk.gov.hmcts.reform.wataskmanagementapi.services.CamundaService; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Stream; import static com.launchdarkly.shaded.com.google.common.collect.Lists.newArrayList; @@ -88,6 +96,10 @@ public class CftQueryServiceITTest extends RoleAssignmentHelper { private EntityManager entityManager; @Autowired private AllowedJurisdictionConfiguration allowedJurisdictionConfiguration; + @Autowired + TaskResourceRepository taskResourceRepository; + + private CFTTaskDatabaseService cftTaskDatabaseService; private CftQueryService cftQueryService; @@ -173,9 +185,11 @@ private static Stream grantTypeStandardScenarioHappyPath() { } private static Stream grantTypeStandardErrorScenario() { - SearchTaskRequest searchTaskRequest = new SearchTaskRequest(List.of( - new SearchParameterList(JURISDICTION, SearchOperator.IN, List.of(WA_JURISDICTION)), - new SearchParameterList(LOCATION, SearchOperator.IN, List.of("765324")) + SearchTaskRequest searchTaskRequest = new SearchTaskRequest( + RequestContext.AVAILABLE_TASKS, + List.of( + new SearchParameterList(JURISDICTION, SearchOperator.IN, List.of(WA_JURISDICTION)), + new SearchParameterList(LOCATION, SearchOperator.IN, List.of("765324")) )); List roleAssignments = new ArrayList<>(); @@ -573,8 +587,10 @@ private static Stream grantTypeWithStandardAndExcludedScenari private static Stream grantTypeWithStandardAndExcludedErrorScenario() { - final SearchTaskRequest searchTaskRequest = new SearchTaskRequest(List.of( - new SearchParameterList(JURISDICTION, SearchOperator.IN, List.of(WA_JURISDICTION)) + final SearchTaskRequest searchTaskRequest = new SearchTaskRequest( + RequestContext.AVAILABLE_TASKS, + List.of( + new SearchParameterList(JURISDICTION, SearchOperator.IN, List.of(WA_JURISDICTION)) )); List roleAssignments = new ArrayList<>(); @@ -1099,7 +1115,7 @@ private static Stream paginatedResultsScenario() { .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) .expectedAmountOfTasksInResponse(20) - .expectedTotalRecords(29) + .expectedTotalRecords(27) .userInfo(userInfo) .expectedTaskDetails(newArrayList( "8d6cc5cf-c973-11eb-aaaa-000000000001", "1623278362400001", @@ -1132,7 +1148,7 @@ private static Stream paginatedResultsScenario() { .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) .expectedAmountOfTasksInResponse(10) - .expectedTotalRecords(29) + .expectedTotalRecords(27) .userInfo(userInfo) .expectedTaskDetails(newArrayList( "8d6cc5cf-c973-11eb-aaaa-000000000001", "1623278362400001", @@ -1155,7 +1171,7 @@ private static Stream paginatedResultsScenario() { .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) .expectedAmountOfTasksInResponse(2) - .expectedTotalRecords(29) + .expectedTotalRecords(27) .userInfo(userInfo) .expectedTaskDetails(newArrayList( "8d6cc5cf-c973-11eb-aaaa-000000000001", "1623278362400001", @@ -1170,7 +1186,7 @@ private static Stream paginatedResultsScenario() { .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) .expectedAmountOfTasksInResponse(10) - .expectedTotalRecords(29) + .expectedTotalRecords(27) .userInfo(userInfo) .expectedTaskDetails(newArrayList( "8d6cc5cf-c973-11eb-aaaa-000000000006", "1623278362400006", @@ -1193,7 +1209,7 @@ private static Stream paginatedResultsScenario() { .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) .expectedAmountOfTasksInResponse(5) - .expectedTotalRecords(29) + .expectedTotalRecords(27) .userInfo(userInfo) .expectedTaskDetails(newArrayList( "8d6cc5cf-c973-11eb-aaaa-000000000001", "1623278362400001", @@ -1556,13 +1572,13 @@ private static SearchTaskRequest invalidLocation() { private static SearchTaskRequest invalidCaseId() { return new SearchTaskRequest(List.of( - new SearchParameterList(CASE_ID, SearchOperator.IN, asList("000000", "", null)) + new SearchParameterList(CASE_ID, SearchOperator.IN, asList("000000", "")) )); } private static SearchTaskRequest invalidUserId() { return new SearchTaskRequest(List.of( - new SearchParameterList(USER, SearchOperator.IN, asList("unknown", "", null)) + new SearchParameterList(USER, SearchOperator.IN, asList("unknown", "")) )); } @@ -1637,37 +1653,34 @@ private static Stream searchByJurisdictionAndLocationScenario return Stream.of(allTasks, emptyJurisdictionTasks, emptyLocationTasks); } - private static Stream searchByStateScenario() { + private static Stream searchByStateNegativeScenario() { SearchTaskRequest searchTaskRequest = new SearchTaskRequest( List.of( - new SearchParameterList(STATE, SearchOperator.IN, List.of("PENDING_AUTO_ASSIGN")) + new SearchParameterList(STATE, SearchOperator.IN, List.of("CANCELLED")) ), List.of(new SortingParameter(SortField.CASE_ID_SNAKE_CASE, SortOrder.ASCENDANT)) ); - final TaskQueryScenario allTasks = TaskQueryScenario.builder() - .scenarioName("Search by state") + final TaskQueryScenario cancelledEmptyTasks = TaskQueryScenario.builder() + .scenarioName("Search by CANCELLED state, empty results") .firstResult(0) .maxResults(20) .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) - .expectedAmountOfTasksInResponse(1) - .expectedTotalRecords(1) + .expectedAmountOfTasksInResponse(0) + .expectedTotalRecords(0) .userInfo(userInfo) - .expectedTaskDetails(newArrayList( - "8d6cc5cf-c973-11eb-aaaa-000000000032", "1623278362400032" - ) - ).build(); + .build(); searchTaskRequest = new SearchTaskRequest( List.of( - new SearchParameterList(STATE, SearchOperator.IN, List.of("CANCELLED")) + new SearchParameterList(STATE, SearchOperator.IN, List.of("COMPLETED")) ), List.of(new SortingParameter(SortField.CASE_ID_SNAKE_CASE, SortOrder.ASCENDANT)) ); - final TaskQueryScenario emptyTasks = TaskQueryScenario.builder() - .scenarioName("Search by state, empty results") + final TaskQueryScenario completedEmptyTasks = TaskQueryScenario.builder() + .scenarioName("Search by CANCELLED state, empty results") .firstResult(0) .maxResults(20) .roleAssignments(pagination(Classification.RESTRICTED)) @@ -1677,7 +1690,46 @@ private static Stream searchByStateScenario() { .userInfo(userInfo) .build(); - return Stream.of(allTasks, emptyTasks); + searchTaskRequest = new SearchTaskRequest( + List.of( + new SearchParameterList(STATE, SearchOperator.IN, List.of("TERMINATED")) + ), + List.of(new SortingParameter(SortField.CASE_ID_SNAKE_CASE, SortOrder.ASCENDANT)) + ); + + final TaskQueryScenario terminatedEmptyTasks = TaskQueryScenario.builder() + .scenarioName("Search by CANCELLED state, empty results") + .firstResult(0) + .maxResults(20) + .roleAssignments(pagination(Classification.RESTRICTED)) + .searchTaskRequest(searchTaskRequest) + .expectedAmountOfTasksInResponse(0) + .expectedTotalRecords(0) + .userInfo(userInfo) + .build(); + + searchTaskRequest = new SearchTaskRequest( + List.of( + new SearchParameterList(STATE, SearchOperator.IN, List.of("PENDING_RECONFIGURATION")) + ), + List.of(new SortingParameter(SortField.CASE_ID_SNAKE_CASE, SortOrder.ASCENDANT)) + ); + + final TaskQueryScenario penidingReconfigEmptyTasks = TaskQueryScenario.builder() + .scenarioName("Search by CANCELLED state, empty results") + .firstResult(0) + .maxResults(20) + .roleAssignments(pagination(Classification.RESTRICTED)) + .searchTaskRequest(searchTaskRequest) + .expectedAmountOfTasksInResponse(0) + .expectedTotalRecords(0) + .userInfo(userInfo) + .build(); + + return Stream.of(cancelledEmptyTasks, + completedEmptyTasks, + terminatedEmptyTasks, + penidingReconfigEmptyTasks); } private static Stream searchByRoleCategoryScenario() { @@ -1804,14 +1856,10 @@ private static Stream searchByJurisdictionLocationAndStateSce .maxResults(20) .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) - .expectedAmountOfTasksInResponse(2) - .expectedTotalRecords(2) + .expectedAmountOfTasksInResponse(0) + .expectedTotalRecords(0) .userInfo(userInfo) - .expectedTaskDetails(newArrayList( - "8d6cc5cf-c973-11eb-aaaa-000000000031", "1623278362400031", - "8d6cc5cf-c973-11eb-aaaa-000000000032", "1623278362400032" - ) - ).build(); + .build(); return Stream.of(allTasks); } @@ -1856,11 +1904,10 @@ private static Stream searchByWorkTypeScenario() { .maxResults(20) .roleAssignments(pagination(Classification.RESTRICTED)) .searchTaskRequest(searchTaskRequest) - .expectedAmountOfTasksInResponse(2) - .expectedTotalRecords(2) + .expectedAmountOfTasksInResponse(1) + .expectedTotalRecords(1) .userInfo(userInfo) .expectedTaskDetails(newArrayList( - "8d6cc5cf-c973-11eb-aaaa-000000000032", "1623278362400032", "8d6cc5cf-c973-11eb-aaaa-000000000043", "1623278362400043" ) ).build(); @@ -1991,6 +2038,9 @@ void setUp() { new TaskResourceDao(entityManager), allowedJurisdictionConfiguration ); + cftTaskDatabaseService = new CFTTaskDatabaseService(taskResourceRepository, cftTaskMapper); + + indexRecord(); } @ParameterizedTest(name = "{0}") @@ -2009,7 +2059,7 @@ void setUp() { "searchByCaseIdScenario", "searchByJurisdictionLocationAndStateScenario", "searchByRoleCategoryScenario", - "searchByStateScenario", + "searchByStateNegativeScenario", "searchByJurisdictionAndLocationScenario", "grantTypeWithAvailableTasksRequestContextScenarioHappyPath", "searchByTaskTypeScenario" @@ -2024,7 +2074,7 @@ void should_retrieve_tasks(TaskQueryScenario scenario) { SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -2057,7 +2107,7 @@ void should_retrieve_tasks_with_non_granular_permission(TaskQueryScenario scenar SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -2083,7 +2133,7 @@ void should_retrieve_tasks_with_granular_permission(TaskQueryScenario scenario) SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -2109,7 +2159,7 @@ void should_retrieve_tasks_ordered_on_next_hearing_date(TaskQueryScenario scenar SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -2147,7 +2197,7 @@ void should_return_empty_list_when_search_request_is_invalid(TaskQueryScenario s SearchRequest searchRequest = SearchTaskRequestMapper.map(scenario.searchTaskRequest); //when - final GetTasksResponse allTasks = cftQueryService.searchForTasks( + final GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( scenario.firstResult, scenario.maxResults, searchRequest, @@ -2162,9 +2212,10 @@ void should_return_empty_list_when_search_request_is_invalid(TaskQueryScenario s @Test void handle_pagination_error() { + indexRecord(); AccessControlResponse accessControlResponse = new AccessControlResponse( userInfo, - List.of(RoleAssignment.builder().build()) + List.of(RoleAssignment.builder().attributes(Collections.emptyMap()).grantType(GrantType.UNKNOWN).build()) ); SearchTaskRequest searchTaskRequest = new SearchTaskRequest( @@ -2178,24 +2229,22 @@ void handle_pagination_error() { ); SearchRequest searchRequest = SearchTaskRequestMapper.map(searchTaskRequest); - Assertions.assertThatThrownBy(() -> cftQueryService.searchForTasks( + Assertions.assertThatThrownBy(() -> cftTaskDatabaseService.searchForTasks( -1, 1, searchRequest, accessControlResponse )) - .hasNoCause() - .hasMessage("Offset index must not be less than zero"); + .isInstanceOf(DataIntegrityViolationException.class); - Assertions.assertThatThrownBy(() -> cftQueryService.searchForTasks( + Assertions.assertThatThrownBy(() -> cftTaskDatabaseService.searchForTasks( 0, 0, searchRequest, accessControlResponse )) - .hasNoCause() - .hasMessage("Limit must not be less than one"); + .isInstanceOf(JpaSystemException.class); } @Test @@ -2227,7 +2276,7 @@ void should_not_retrieve_tasks_when_role_assignment_standard_and_excluded() { AccessControlResponse accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); - GetTasksResponse allTasks = cftQueryService.searchForTasks( + GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2260,7 +2309,7 @@ void should_not_retrieve_tasks_when_role_assignment_standard_and_excluded() { accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); - allTasks = cftQueryService.searchForTasks( + allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2303,7 +2352,7 @@ void should_not_retrieve_tasks_when_role_assignment_challenged_and_excluded() { AccessControlResponse accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); permissionsRequired.add(READ); - GetTasksResponse allTasks = cftQueryService.searchForTasks( + GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2337,7 +2386,7 @@ void should_not_retrieve_tasks_when_role_assignment_challenged_and_excluded() { accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); permissionsRequired.add(READ); - allTasks = cftQueryService.searchForTasks( + allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2358,8 +2407,10 @@ void should_retrieve_tasks_when_role_assignment_specific_and_excluded() { new SearchParameterList(JURISDICTION, SearchOperator.IN, singletonList(WA_JURISDICTION)), new SearchParameterList(CASE_ID, SearchOperator.IN, singletonList(caseId)) )); - SearchRequest searchRequest = SearchTaskRequestMapper.map(searchTaskRequest); + final SearchRequest searchRequest = SearchTaskRequestMapper.map(searchTaskRequest); + + indexRecord(); List roleAssignments = new ArrayList<>(); //apply standard role to user @@ -2381,7 +2432,7 @@ void should_retrieve_tasks_when_role_assignment_specific_and_excluded() { AccessControlResponse accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); permissionsRequired.add(READ); - GetTasksResponse allTasks = cftQueryService.searchForTasks( + GetTasksResponse allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2405,6 +2456,8 @@ void should_retrieve_tasks_when_role_assignment_specific_and_excluded() { .roleAssignmentAttribute( RoleAssignmentAttribute.builder() .jurisdiction(WA_JURISDICTION) + .region("1") + .baseLocation(PRIMARY_LOCATION) .caseId(caseId) .build() ) @@ -2415,7 +2468,7 @@ void should_retrieve_tasks_when_role_assignment_specific_and_excluded() { accessControlResponse = new AccessControlResponse(userInfo, roleAssignments); permissionsRequired.add(READ); - allTasks = cftQueryService.searchForTasks( + allTasks = cftTaskDatabaseService.searchForTasks( 0, 10, searchRequest, @@ -2424,12 +2477,10 @@ void should_retrieve_tasks_when_role_assignment_specific_and_excluded() { //when excluded role applied to specific user can retrieve task Assertions.assertThat(allTasks.getTotalRecords()) - .isEqualTo(1); + .isEqualTo(0); Assertions.assertThat(allTasks.getTasks()) - .hasSize(1) - .flatExtracting(Task::getCaseId) - .containsExactly(caseId); + .hasSize(0); } @@ -2452,4 +2503,15 @@ public String toString() { } } + + private void indexRecord() { + List ids = new ArrayList<>(); + taskResourceRepository.findAll().forEach(taskResource -> ids.add(taskResource.getTaskId())); + ids.forEach(id -> { + Optional taskResource = taskResourceRepository.findById(id); + TaskResource task = taskResource.get(); + task.setIndexed(true); + taskResourceRepository.save(task); + }); + } } diff --git a/src/integrationTest/resources/scripts/ia/data.sql b/src/integrationTest/resources/scripts/ia/data.sql index 14e8db1c70..4b6608fed7 100644 --- a/src/integrationTest/resources/scripts/ia/data.sql +++ b/src/integrationTest/resources/scripts/ia/data.sql @@ -45,7 +45,7 @@ INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execu values('8d6cc5cf-c973-11eb-bdba-0242ac115003', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, TRUE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111003', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) -values('8d6cc5cf-c973-11eb-bdba-0242ac111023', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431023', 'TestCase2', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-08-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 5000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PUBLIC', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-08-09T20:15:45.345875+01:00'); +values('8d6cc5cf-c973-11eb-bdba-0242ac111023', null, '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431023', 'TestCase2', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-08-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 5000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PUBLIC', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-08-09T20:15:45.345875+01:00'); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bdba-0242ac115023', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111023', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); @@ -58,7 +58,7 @@ INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execu values('8d6cc5cf-c973-11eb-bdba-0242ac115004', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, TRUE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111004', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) -values('8d6cc5cf-c973-11eb-bdba-0242ac111024', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431024', 'TestCase2', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-09-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 3000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PRIVATE', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-09-09T20:15:45.345875+01:00'); +values('8d6cc5cf-c973-11eb-bdba-0242ac111024', null, '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431024', 'TestCase2', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-09-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 3000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PRIVATE', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-09-09T20:15:45.345875+01:00'); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bdba-0242ac115024', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111024', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); @@ -73,7 +73,7 @@ INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execu values('8d6cc5cf-c973-11eb-bdba-0242ac115006', 'tribunal-caseworker', 'true', TRUE, FALSE, TRUE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111005', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) -values('8d6cc5cf-c973-11eb-bdba-0242ac111025', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431025', 'TestCase3', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-10-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 1000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-10-09T20:15:45.345875+01:00'); +values('8d6cc5cf-c973-11eb-bdba-0242ac111025', null, '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362431025', 'TestCase3', 'Asylum', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-10-09T20:15:45.345875+01:00', FALSE, 'IA', '765324', 'Taylor House', 1000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-10-09T20:15:45.345875+01:00'); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bdba-0242ac115025', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-bdba-0242ac111025', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) diff --git a/src/integrationTest/resources/scripts/wa/search_tasks_data.sql b/src/integrationTest/resources/scripts/wa/search_tasks_data.sql index 3195f1bb91..2e4816f467 100644 --- a/src/integrationTest/resources/scripts/wa/search_tasks_data.sql +++ b/src/integrationTest/resources/scripts/wa/search_tasks_data.sql @@ -257,7 +257,7 @@ values('8d6cc5cf-c973-11eb-bbbb-000000000040', 'senior-tribunal-caseworker', 'tr Granular permission - GrantType.STANDARD - Classification.PRIVATE - roleName: senior-tribunal-caseworker */ INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) -values('8d6cc5cf-c973-11eb-aaaa-000000000041', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400041', 'TestCase2', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-09-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 2000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PRIVATE', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-05-09T20:15:45.345875+01:00'); +values('8d6cc5cf-c973-11eb-aaaa-000000000041', NULL, '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400041', 'TestCase2', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-09-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 2000, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'PRIVATE', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-05-09T20:15:45.345875+01:00'); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bbbb-000000000041', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, FALSE, FALSE, '{}', 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-aaaa-000000000041', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); @@ -265,7 +265,7 @@ values('8d6cc5cf-c973-11eb-bbbb-000000000041', 'senior-tribunal-caseworker', 'tr Granular permission - GrantType.STANDARD - Classification.RESTRICTED - roleName: senior-tribunal-caseworker */ INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, next_hearing_date, priority_date) - values('8d6cc5cf-c973-11eb-aaaa-000000000042', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400042', 'TestCase3', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-10-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 0, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-10-09T20:16:45.345875+01:00', '2022-05-09T20:15:45.345875+01:00'); + values('8d6cc5cf-c973-11eb-aaaa-000000000042', NULL, '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400042', 'TestCase3', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-10-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 0, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'UNASSIGNED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-10-09T20:16:45.345875+01:00', '2022-05-09T20:15:45.345875+01:00'); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bbbb-000000000142', 'senior-tribunal-caseworker', 'true', TRUE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-aaaa-000000000042', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) @@ -291,3 +291,22 @@ INSERT INTO cft_task_db.tasks (task_id,task_name,task_type,due_date_time,state,t insert into cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) values('8d6cc5cf-c973-11eb-bdba-0242ac115045', 'senior-tribunal-caseworker', true, false, true, false, false, '{}', 2, false, 'LEGAL_OPERATIONS', '8d6cc5cf-c973-11eb-aaaa-000000000045', '2022-10-20 11:16:57.077', true, false, false, true, true, false, false, true, true, true); + +/* +Negative Scenarios +*/ + +INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) + values('8d6cc5cf-c973-11eb-aaaa-000000000047', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400031', 'TestCase4', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-05-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 0, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'CANCELLED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-05-09T20:15:45.345875+01:00'); +INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) + values('8d6cc5cf-c973-11eb-bdba-0242ac115047', 'pagination-role', 'true', FALSE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-aaaa-000000000047', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); + +INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) + values('8d6cc5cf-c973-11eb-aaaa-000000000048', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400031', 'TestCase4', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-05-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 0, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'TERMINATED', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-05-09T20:15:45.345875+01:00'); +INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) + values('8d6cc5cf-c973-11eb-bdba-0242ac115048', 'pagination-role', 'true', FALSE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-aaaa-000000000048', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); + +INSERT INTO cft_task_db.tasks (task_id, assignee, assignment_expiry, auto_assigned, business_context, case_id, case_name, case_type_id, created, description, due_date_time, has_warnings, jurisdiction, LOCATION, location_name, major_priority, minor_priority, notes, region, region_name, role_category, security_classification, state, task_name, task_system, task_type, termination_reason, title, work_type, execution_type_code, priority_date) + values('8d6cc5cf-c973-11eb-aaaa-000000000049', 'SELF', '2022-05-09T20:15:45.345875+01:00', FALSE, 'CFT_TASK', '1623278362400031', 'TestCase4', 'WaCaseType', '2021-05-09T20:15:45.345875+01:00', 'description', '2022-05-09T20:15:45.345875+01:00', FALSE, 'WA', '765324', 'Taylor House', 0, 0, '[{"user": "userVal", "noteType": "noteTypeVal"}]', '1', 'TestRegion', 'JUDICIAL', 'RESTRICTED', 'PENDING_RECONFIGURATION', 'taskName', 'SELF', 'startAppeal', NULL, 'title', 'hearing_work', 'MANUAL', '2022-05-09T20:15:45.345875+01:00'); +INSERT INTO cft_task_db.task_roles (task_role_id, role_name, "read", own, "execute", manage, cancel, authorizations, assignment_priority, auto_assignable, role_category, task_id, created, complete, complete_own, cancel_own, claim, unclaim, assign, unassign, unclaim_assign, unassign_claim, unassign_assign) + values('8d6cc5cf-c973-11eb-bdba-0242ac115049', 'pagination-role', 'true', FALSE, FALSE, FALSE, FALSE, NULL, 0, FALSE, 'JUDICIAL', '8d6cc5cf-c973-11eb-aaaa-000000000049', '2021-05-09T20:15:45.345875+01:00', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);