diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/model/enums/FeatureFlagEnum.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/model/enums/FeatureFlagEnum.java index b5f30f0104..19e82f8605 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/model/enums/FeatureFlagEnum.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/model/enums/FeatureFlagEnum.java @@ -17,7 +17,8 @@ public enum FeatureFlagEnum { PUBLICLAW_WA_1_1("publiclaw_wa_1_1"), CIVIL_WA_1_2("civil_wa_1_2"), CIVIL_WA_1_3("civil_wa_1_3"), - PRIVATELAW_WA_1_3("privatelaw_wa_1_3"); + PRIVATELAW_WA_1_3("privatelaw_wa_1_3"), + PUBLICLAW_WA_1_2("publiclaw_wa_1_2"); private final String value; diff --git a/src/main/resources/db/migration/V20240125_95__DTSAM-95_PUBLICLAW_WA_1_2_base_flag_addition.sql b/src/main/resources/db/migration/V20240125_95__DTSAM-95_PUBLICLAW_WA_1_2_base_flag_addition.sql new file mode 100644 index 0000000000..450dc78679 --- /dev/null +++ b/src/main/resources/db/migration/V20240125_95__DTSAM-95_PUBLICLAW_WA_1_2_base_flag_addition.sql @@ -0,0 +1,7 @@ +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'local', 'publiclaw', 'true'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'pr', 'publiclaw', 'true'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'aat', 'publiclaw', 'false'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'demo', 'publiclaw', 'false'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'perftest', 'publiclaw', 'false'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'ithc', 'publiclaw', 'false'); +INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('publiclaw_wa_1_2', 'prod', 'publiclaw', 'false'); \ No newline at end of file diff --git a/src/main/resources/validationrules/publiclaw/publiclaw-judicial-org-role-mapping.drl b/src/main/resources/validationrules/publiclaw/publiclaw-judicial-org-role-mapping.drl index 6a2662bf55..f7a5cbe69e 100644 --- a/src/main/resources/validationrules/publiclaw/publiclaw-judicial-org-role-mapping.drl +++ b/src/main/resources/validationrules/publiclaw/publiclaw-judicial-org-role-mapping.drl @@ -54,10 +54,13 @@ end; /* * PUBLICLAW Fee Paid "judge" Org role mapping. + * Made obsolete in DTSAM-96 by PUBLICLAW_WA_1_2. + * To be removed in DTSAM-99. */ rule "publiclaw_fee_paid_judge_org_role" when $f: FeatureFlag(status && flagName == FeatureFlagEnum.PUBLICLAW_WA_1_0.getValue()) + $f2: FeatureFlag(status == false, flagName == FeatureFlagEnum.PUBLICLAW_WA_1_2.getValue()) $joh: JudicialOfficeHolder(office in ( "PUBLICLAW Deputy District Judge (MC) - Fee Paid", "PUBLICLAW Deputy District Judge (MC) - Sitting in Retirement", "PUBLICLAW Deputy District Judge - Fee Paid", "PUBLICLAW Deputy District Judge - Sitting in Retirement - Fee Paid", @@ -92,6 +95,46 @@ then logMsg("Rule : publiclaw_fee_paid_judge_org_role"); end; +/* + * PUBLICLAW Fee Paid "judge" Org role mapping v1.2 . + */ +rule "publiclaw_fee_paid_judge_org_role_v1_2" +when + $f: FeatureFlag(status && flagName == FeatureFlagEnum.PUBLICLAW_WA_1_2.getValue()) + $joh: JudicialOfficeHolder(office in ( + "PUBLICLAW Deputy District Judge (MC) - Fee Paid", "PUBLICLAW Deputy District Judge (MC) - Sitting in Retirement", + "PUBLICLAW Deputy District Judge - Fee Paid", "PUBLICLAW Deputy District Judge - Sitting in Retirement - Fee Paid", + "PUBLICLAW Deputy District Judge - PRFD - Fee Paid", "PUBLICLAW Deputy High Court Judge - Fee Paid", + "PUBLICLAW High Court Judge - Sitting in Retirement - Fee Paid","PUBLICLAW Deputy Circuit Judge - Fee Paid", + "PUBLICLAW Recorder - Fee Paid", "PUBLICLAW Circuit Judge - Sitting in Retirement - Fee Paid", + "PUBLICLAW Recorder - Sitting in Retirement - Fee Paid", "PUBLICLAW Deputy Upper Tribunal Judge - Fee Paid", + "PUBLICLAW District Judge (MC) - Sitting in Retirement - Fee Paid", "PUBLICLAW District Judge - Sitting in Retirement - Fee Paid")) + $bk: JudicialBooking(userId == $joh.userId) +then + Map attribute = new HashMap<>(); + attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid")); + attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("PUBLICLAW")); + attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($bk.getLocationId() != null ? $bk.getLocationId():$joh.getPrimaryLocation())); + attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($bk.getRegionId())); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("hearing_work,routine_work,decision_making_work,applications")); + insert( + RoleAssignment.builder() + .actorIdType(ActorIdType.IDAM) + .actorId($joh.getUserId()) + .roleCategory(RoleCategory.JUDICIAL) + .roleType(RoleType.ORGANISATION) + .roleName("judge") + .grantType(GrantType.STANDARD) + .classification(Classification.PUBLIC) + .readOnly(false) + .beginTime($bk.getBeginTime()) + .endTime($bk.getEndTime()) + .attributes(attribute) + .authorisations($joh.getTicketCodes()) + .build()); + logMsg("Rule : publiclaw_fee_paid_judge_org_role_v1_2"); +end; + /* * PUBLICLAW "magistrate" Org role mapping. */ diff --git a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolPublicLawJudicialRoleMappingTest.java b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolPublicLawJudicialRoleMappingTest.java index 85b700beb1..75418de311 100644 --- a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolPublicLawJudicialRoleMappingTest.java +++ b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolPublicLawJudicialRoleMappingTest.java @@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,7 +36,15 @@ @RunWith(MockitoJUnitRunner.class) class DroolPublicLawJudicialRoleMappingTest extends DroolBase { - String userId = "3168da13-00b3-41e3-81fa-cbc71ac28a69"; + private static final String USER_ID = "3168da13-00b3-41e3-81fa-cbc71ac28a69"; + private static final ZonedDateTime BOOKING_BEGIN_TIME = ZonedDateTime.now(ZoneOffset.UTC).minusDays(1); + private static final ZonedDateTime BOOKING_END_TIME = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1); + private static final String BOOKING_REGION_ID = "1"; + private static final String BOOKING_LOCATION_ID = "Scotland"; + private static final ZonedDateTime ACCESS_PROFILE_BEGIN_TIME = ZonedDateTime.now(ZoneOffset.UTC).minusMonths(1); + private static final ZonedDateTime ACCESS_PROFILE_END_TIME = ZonedDateTime.now(ZoneOffset.UTC).plusMonths(1); + private static final String ACCESS_PROFILE_REGION_ID = "LDN"; + private static final String ACCESS_PROFILE_PRIMARY_LOCATION_ID = "London"; static Map expectedRoleNameWorkTypesMap = new HashMap<>(); @@ -300,9 +310,12 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA judicialAccessProfiles.clear(); judicialOfficeHolders.clear(); judicialBookings.clear(); + if (addBooking) { JudicialBooking booking = JudicialBooking.builder() - .userId(userId).locationId("Scotland").regionId("1") + .userId(USER_ID).locationId(BOOKING_LOCATION_ID).regionId(BOOKING_REGION_ID) + .beginTime(BOOKING_BEGIN_TIME) + .endTime(BOOKING_END_TIME) .build(); judicialBookings.add(booking); } @@ -311,11 +324,13 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA JudicialAccessProfile.builder() .appointment(appointment) .appointmentType(appointmentType) - .userId(userId) + .userId(USER_ID) .roles(assignedRoles) - .regionId("LDN") - .primaryLocationId("London") + .regionId(ACCESS_PROFILE_REGION_ID) + .primaryLocationId(ACCESS_PROFILE_PRIMARY_LOCATION_ID) .ticketCodes(List.of("ABA3")) + .beginTime(ACCESS_PROFILE_BEGIN_TIME) + .endTime(ACCESS_PROFILE_END_TIME) .authorisations(List.of( Authorisation.builder() .serviceCodes(List.of("ABA3")) @@ -331,7 +346,8 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA buildExecuteKieSession( List.of(FeatureFlag.builder().flagName("publiclaw_wa_1_0").status(true).build(), FeatureFlag.builder().flagName("sscs_hearing_1_0").status(hearingFlag).build(), - FeatureFlag.builder().flagName("publiclaw_wa_1_1").status(true).build()) + FeatureFlag.builder().flagName("publiclaw_wa_1_1").status(true).build(), + FeatureFlag.builder().flagName("publiclaw_wa_1_2").status(true).build()) ); //assertions @@ -343,7 +359,7 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA roleAssignments.forEach(r -> { assertEquals(ActorIdType.IDAM, r.getActorIdType()); - assertEquals(userId, r.getActorId()); + assertEquals(USER_ID, r.getActorId()); assertEquals(RoleType.ORGANISATION, r.getRoleType()); assertEquals(RoleCategory.JUDICIAL, r.getRoleCategory()); @@ -354,32 +370,47 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA } assertEquals(expectedWorkTypes, actualWorkTypes); - String primaryLocation = null; - if (r.getAttributes().get("primaryLocation") != null) { - primaryLocation = r.getAttributes().get("primaryLocation").asText(); - } + assertRoleSpecificAtrributes(r, appointmentType); + }); + } + + private void assertRoleSpecificAtrributes(RoleAssignment r, String appointmentType) { + String primaryLocation = null; + if (r.getAttributes().get("primaryLocation") != null) { + primaryLocation = r.getAttributes().get("primaryLocation").asText(); + } - if (!r.getRoleName().equals("hmcts-judiciary")) { - assertEquals(Classification.PUBLIC, r.getClassification()); - assertEquals(GrantType.STANDARD, r.getGrantType()); - assertEquals("ABA3", r.getAuthorisations().get(0)); - assertEquals("London", primaryLocation); - assertEquals("PUBLICLAW", r.getAttributes().get("jurisdiction").asText()); - assertFalse(r.isReadOnly()); + if (r.getRoleName().equals("hmcts-judiciary")) { + assertEquals(Classification.PRIVATE, r.getClassification()); + assertEquals(GrantType.BASIC, r.getGrantType()); + assertTrue(r.isReadOnly()); + assertNull(r.getAttributes().get("jurisdiction")); + assertNull(primaryLocation); + assertEquals(ACCESS_PROFILE_BEGIN_TIME, r.getBeginTime()); + assertEquals(ACCESS_PROFILE_END_TIME.plusDays(1), r.getEndTime()); + } else { + assertEquals(Classification.PUBLIC, r.getClassification()); + assertEquals(GrantType.STANDARD, r.getGrantType()); + assertEquals("ABA3", r.getAuthorisations().get(0)); + assertEquals("PUBLICLAW", r.getAttributes().get("jurisdiction").asText()); + assertFalse(r.isReadOnly()); + if (r.getRoleName().equals("judge") && appointmentType.equals("Fee Paid")) { + assertEquals(BOOKING_BEGIN_TIME, r.getBeginTime()); + assertEquals(BOOKING_END_TIME, r.getEndTime()); + assertEquals(BOOKING_REGION_ID, r.getAttributes().get("region").asText()); + assertEquals(BOOKING_LOCATION_ID, primaryLocation); + } else { + assertEquals(ACCESS_PROFILE_BEGIN_TIME, r.getBeginTime()); + assertEquals(ACCESS_PROFILE_END_TIME.plusDays(1), r.getEndTime()); + assertEquals(ACCESS_PROFILE_PRIMARY_LOCATION_ID, primaryLocation); if (!r.getRoleName().equals("hearing-viewer") && !r.getRoleName().equals("hearing-manager")) { - assertEquals("LDN", r.getAttributes().get("region").asText()); + assertEquals(ACCESS_PROFILE_REGION_ID, r.getAttributes().get("region").asText()); } - } else { - assertEquals(Classification.PRIVATE, r.getClassification()); - assertEquals(GrantType.BASIC, r.getGrantType()); - assertTrue(r.isReadOnly()); - assertNull(r.getAttributes().get("jurisdiction")); - assertNull(primaryLocation); } - }); + } } @@ -393,10 +424,10 @@ void falsePublicLawFlagTest() { JudicialAccessProfile.builder() .appointment("District Judge (MC)") .appointmentType("SPTW") - .userId(userId) + .userId(USER_ID) .roles(List.of("District Judge")) - .regionId("LDN") - .primaryLocationId("London") + .regionId(ACCESS_PROFILE_REGION_ID) + .primaryLocationId(ACCESS_PROFILE_PRIMARY_LOCATION_ID) .ticketCodes(List.of("ABA3")) .authorisations(List.of( Authorisation.builder()