Skip to content

Commit

Permalink
DTSAM-443 + civil appt Circuit Judge (sitting in retirement) (#2026)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Nayler <57350764+mattnayler@users.noreply.github.com>
  • Loading branch information
abul-syed and mattnayler authored Aug 8, 2024
1 parent 56f068d commit db97297
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum FeatureFlagEnum {
CIVIL_WA_1_5("civil_wa_1_5"),
CIVIL_WA_1_6("civil_wa_1_6"),
CIVIL_WA_1_7("civil_wa_1_7"),
CIVIL_WA_1_8("civil_wa_1_8"),
PUBLICLAW_WA_1_3("publiclaw_wa_1_3"),
PUBLICLAW_WA_1_4("publiclaw_wa_1_4"),
IAC_JRD_1_1("iac_jrd_1_1");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- DTSAM-443: insert civil_wa_1_8 base flag into flag_config table
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'local', 'civil', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'pr', 'civil', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'aat', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'demo', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'perftest', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'ithc', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_8', 'prod', 'civil', 'false');
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,31 @@ then
.contractType($jap.getAppointmentType())
.build());
logMsg("Rule : civil_employment_judge_fee_paid_joh");
end;
end;

/*
* "CIVIL Circuit Judge (sitting in retirement) - Fee Paid" business role business role mapping to JOH.
*/
rule "civil_circuit_judge_in_retirement_fee_paid_joh"
when
$f: FeatureFlag(status && flagName == FeatureFlagEnum.CIVIL_WA_1_8.getValue())
$jap: JudicialAccessProfile(appointment == "Circuit Judge (sitting in retirement)",
appointmentType == "Fee Paid",
(endTime == null || endTime.compareTo(ZonedDateTime.now()) >= 0),
(validateAuthorisation(authorisations, "AAA6") || validateAuthorisation(authorisations, "AAA7")))
then
insert(
JudicialOfficeHolder.builder()
.userId($jap.getUserId())
.office("CIVIL Circuit Judge (sitting in retirement)-Fee-Paid")
.jurisdiction("CIVIL")
.ticketCodes($jap.getTicketCodes())
.beginTime($jap.getBeginTime())
.endTime($jap.getEndTime())
.regionId($jap.getRegionId())
.baseLocationId($jap.getBaseLocationId())
.primaryLocation($jap.getPrimaryLocationId())
.contractType($jap.getAppointmentType())
.build());
logMsg("Rule : civil_circuit_judge_in_retirement_fee_paid_joh");
end;
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ when
"CIVIL Deputy District Judge - Sitting in Retirement-Fee-Paid",
"CIVIL Recorder-Fee-Paid",
"CIVIL District Judge (sitting in retirement)-Fee-Paid",
"CIVIL Tribunal Judge-Fee-Paid"))
"CIVIL Tribunal Judge-Fee-Paid",
"CIVIL Circuit Judge (sitting in retirement)-Fee-Paid"))
then
Map<String,JsonNode> attribute = new HashMap<>();
attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid"));
Expand Down Expand Up @@ -403,7 +404,8 @@ $joh: JudicialOfficeHolder(office in ( "CIVIL District Judge-Salaried", "CIVIL P
"CIVIL Deputy District Judge - Sitting in Retirement-Fee-Paid",
"CIVIL Recorder-Fee-Paid", "CIVIL District Judge (sitting in retirement)-Fee-Paid",
"CIVIL Tribunal Judge-Salaried", "CIVIL Tribunal Judge-Fee-Paid",
"CIVIL Employment Judge-Salaried", "CIVIL Employment Judge-Fee-Paid"))
"CIVIL Employment Judge-Salaried", "CIVIL Employment Judge-Fee-Paid",
"CIVIL Circuit Judge (sitting in retirement)-Fee-Paid"))
then
Map<String,JsonNode> attribute = new HashMap<>();
if($joh.getOffice().contains("Fee-Paid")) {
Expand Down Expand Up @@ -511,7 +513,8 @@ when
$joh: JudicialOfficeHolder(office in ("CIVIL Deputy District Judge-Fee-Paid", "CIVIL Recorder-Fee-Paid",
"CIVIL Deputy District Judge - Sitting in Retirement-Fee-Paid",
"CIVIL District Judge (sitting in retirement)-Fee-Paid",
"CIVIL Tribunal Judge-Fee-Paid"))
"CIVIL Tribunal Judge-Fee-Paid",
"CIVIL Circuit Judge (sitting in retirement)-Fee-Paid"))
$bk: JudicialBooking(userId == $joh.userId)
then
Map<String,JsonNode> attribute = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.reform.orgrolemapping.domain.service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -35,109 +36,96 @@ static Stream<Arguments> endToEndData() {
Arguments.of("District Judge",
"Salaried",
true,
true,
List.of(""),
List.of("judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("",
"Salaried",
true,
true,
List.of("Presiding Judge"),
List.of("judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("",
"Salaried",
true,
true,
List.of("Resident Judge"),
List.of("judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Tribunal Judge",
"Salaried",
false,
true,
List.of(""),
List.of("judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Employment Judge",
"Salaried",
false,
true,
List.of(""),
List.of("judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("",
"Salaried",
false,
true,
List.of("Designated Civil Judge"),
List.of("judge", "leadership-judge", "task-supervisor", "hmcts-judiciary",
"case-allocator", "hearing-viewer")),
Arguments.of("Circuit Judge",
"Salaried",
false,
true,
List.of(""),
List.of("judge", "circuit-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Specialist Circuit Judge",
"Salaried",
true,
true,
List.of(""),
List.of("judge", "circuit-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Senior Circuit Judge",
"Salaried",
true,
true,
List.of(""),
List.of("judge", "circuit-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("High Court Judge",
"Salaried",
true,
true,
List.of(""),
List.of("judge", "circuit-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Deputy Circuit Judge",
"Fee Paid",
true,
true,
List.of("Deputy District Judge"),
List.of("judge", "circuit-judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Deputy District Judge- Fee-Paid",
"Fee Paid",
true,
true,
List.of(""),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Deputy District Judge- Sitting in Retirement",
"Fee Paid",
true,
true,
List.of("Deputy District Judge"),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Deputy District Judge (sitting in retirement)",
"Fee Paid",
true,
true,
List.of(""),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Recorder",
"Fee Paid",
true,
true,
List.of("Recorder - Fee Paid"),
List.of("judge", "fee-paid-judge","hmcts-judiciary", "hearing-viewer")),
Arguments.of("District Judge (sitting in retirement)",
"Fee Paid",
true,
true,
List.of("District Judge (sitting in retirement)"),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Tribunal Judge",
"Fee Paid",
true,
true,
List.of("Tribunal Judge"),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Employment Judge",
"Fee Paid",
true,
List.of(""),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer")),
Arguments.of("Circuit Judge (sitting in retirement)",
"Fee Paid",
true,
List.of(""),
List.of("judge", "fee-paid-judge", "hmcts-judiciary", "hearing-viewer"))
Expand All @@ -147,7 +135,7 @@ static Stream<Arguments> endToEndData() {
@ParameterizedTest
@MethodSource("endToEndData")
void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleAssignments(
String appointment, String appointmentType, boolean addBooking, boolean hearingFlag,
String appointment, String appointmentType, boolean addBooking,
List<String> assignedRoles, List<String> expectedRoleNames) {

allProfiles.clear();
Expand Down Expand Up @@ -181,7 +169,7 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA
);

//Execute Kie session
List<RoleAssignment> roleAssignments = buildExecuteKieSession(setFeatureFlags(hearingFlag));
List<RoleAssignment> roleAssignments = buildExecuteKieSession(setFeatureFlags());

//assertions
assertFalse(roleAssignments.isEmpty());
Expand Down Expand Up @@ -224,16 +212,17 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA

}

private List<FeatureFlag> setFeatureFlags(boolean hearingFlag) {
List<String> flags = List.of("civil_wa_1_0", "civil_wa_1_1", "civil_wa_1_2",
"civil_wa_1_3", "civil_wa_1_4", "civil_wa_1_5", "civil_wa_1_7", "sscs_hearing_1_0");
private List<FeatureFlag> setFeatureFlags() {
List<FeatureFlag> featureFlags = new ArrayList<>(getAllFeatureFlagsToggleByJurisdiction("CIVIL", true));

featureFlags.add(
FeatureFlag.builder()
.flagName("sscs_hearing_1_0")
.status(true)
.build()
);

return flags.stream()
.map(flag -> FeatureFlag.builder()
.flagName(flag)
.status(!flag.equals("sscs_hearing_1_0") || hearingFlag)
.build())
.toList();
return featureFlags;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void shouldReturnSalariedRoles(String setOffice, String expectedRoles, String re
"CIVIL Deputy District Judge - Sitting in Retirement-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Recorder-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL District Judge (sitting in retirement)-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Circuit Judge (sitting in retirement)-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Tribunal Judge-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,false",

"CIVIL Employment Judge-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',1,true",
Expand All @@ -132,20 +133,52 @@ void shouldReturnSalariedRoles(String setOffice, String expectedRoles, String re
"CIVIL Employment Judge-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',7,true",
"CIVIL Employment Judge-Fee-Paid,'judge,fee-paid-judge,hmcts-judiciary',11,false" // Scotland
})
void verifyFeePaidRolesWithBooking(String setOffice, String expectedRoles, String region,
boolean expectMultiRegion) throws IOException {
shouldReturnFeePaidRoles(setOffice, expectedRoles, region, expectMultiRegion, true);
}

@ParameterizedTest
@CsvSource({
"CIVIL Deputy Circuit Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Deputy District Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Deputy District Judge - Sitting in Retirement-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Recorder-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL District Judge (sitting in retirement)-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Circuit Judge (sitting in retirement)-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",
"CIVIL Tribunal Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,false",

"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',1,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',2,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',3,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',4,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',5,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',6,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',7,true",
"CIVIL Employment Judge-Fee-Paid,'fee-paid-judge,hmcts-judiciary',11,false" // Scotland
})
void verifyFeePaidRolesWithoutBooking(String setOffice, String expectedRoles, String region,
boolean expectMultiRegion) throws IOException {
shouldReturnFeePaidRoles(setOffice, expectedRoles, region, expectMultiRegion, false);
}

void shouldReturnFeePaidRoles(String setOffice, String expectedRoles, String region,
boolean expectMultiRegion) throws IOException {
boolean expectMultiRegion, boolean addBooking) throws IOException {

judicialOfficeHolders.forEach(joh -> {
joh.setOffice(setOffice);
joh.setRegionId(region);
});

JudicialBooking judicialBooking = TestDataBuilder.buildJudicialBooking();
judicialBooking.setUserId(judicialOfficeHolders.stream().findFirst()
.orElse(JudicialOfficeHolder.builder().build()).getUserId());
judicialBooking.setLocationId("location1");
judicialBooking.setRegionId("1");
judicialBookings = Set.of(judicialBooking);
JudicialBooking judicialBooking = null;
if (addBooking) {
judicialBooking = TestDataBuilder.buildJudicialBooking();
judicialBooking.setUserId(judicialOfficeHolders.stream().findFirst()
.orElse(JudicialOfficeHolder.builder().build()).getUserId());
judicialBooking.setLocationId("location1");
judicialBooking.setRegionId("1");
judicialBookings = Set.of(judicialBooking);
}

//Execute Kie session
List<RoleAssignment> roleAssignments =
Expand All @@ -168,9 +201,9 @@ void shouldReturnFeePaidRoles(String setOffice, String expectedRoles, String reg
multiRegionJudicialList
);

assertEquals(judicialOfficeHolders.stream().iterator().next().getUserId(),roleAssignments.get(0).getActorId());
assertEquals(judicialOfficeHolders.stream().iterator().next().getUserId(),roleAssignments.get(1).getActorId());
assertEquals(judicialOfficeHolders.stream().iterator().next().getUserId(),roleAssignments.get(2).getActorId());
for (RoleAssignment roleAssignment : roleAssignments) {
assertEquals(judicialOfficeHolders.stream().iterator().next().getUserId(), roleAssignment.getActorId());
}

Map<String, List<String>> roleNameToRegionsMap = MultiRegion.buildRoleNameToRegionsMap(rolesThatRequireRegions);

Expand All @@ -180,9 +213,13 @@ void shouldReturnFeePaidRoles(String setOffice, String expectedRoles, String reg
// check region status and add to map
MultiRegion.assertRegionStatusAndUpdateRoleToRegionMap(r, roleNameToRegionsMap);
});
RoleAssignment role = roleAssignments.stream().filter(r -> "judge".equals(r.getRoleName())).findFirst().get();
assertEquals(judicialBooking.getLocationId(), role.getAttributes().get("baseLocation").asText());
assertEquals(judicialBooking.getRegionId(), role.getAttributes().get("region").asText());

if (addBooking) {
RoleAssignment role = roleAssignments.stream()
.filter(r -> "judge".equals(r.getRoleName())).findFirst().get();
assertEquals(judicialBooking.getLocationId(), role.getAttributes().get("baseLocation").asText());
assertEquals(judicialBooking.getRegionId(), role.getAttributes().get("region").asText());
}

// verify regions add to map
MultiRegion.assertRoleNameToRegionsMapIsAsExpected(
Expand All @@ -191,7 +228,7 @@ void shouldReturnFeePaidRoles(String setOffice, String expectedRoles, String reg
expectMultiRegion,
multiRegionJudicialList,
region, // fallback if not multi-region scenario
judicialBooking.getRegionId()
judicialBooking != null ? judicialBooking.getRegionId() : null
);
}

Expand Down

0 comments on commit db97297

Please sign in to comment.