Skip to content

Commit

Permalink
Merge pull request #1730 from hmcts/DTSAM-95_Publiclaw_1_2_Judicial_B…
Browse files Browse the repository at this point in the history
…ooking

DTSAM-95 PUBLICLAW_WA_1_2 Correct Judicial Booking ORM service config…
  • Loading branch information
mikebrownccd authored Jan 30, 2024
2 parents ac28c18 + fe6baaf commit fa81879
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<String,JsonNode> 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> expectedRoleNameWorkTypesMap = new HashMap<>();

Expand Down Expand Up @@ -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);
}
Expand All @@ -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"))
Expand All @@ -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
Expand All @@ -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());

Expand All @@ -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);
}
});

}
}


Expand All @@ -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()
Expand Down

0 comments on commit fa81879

Please sign in to comment.