Skip to content

Commit

Permalink
Dtsam 353 civil wa emp judge appt (#1971)
Browse files Browse the repository at this point in the history
* DTSAM-353 add civil_wa_1_5 employment judge appt

* DTSAM-353 use immutable list

* DTSAM-353 review change (add comment in flyway)

* DTSAM-353 review change (update unit tests/reorder)
  • Loading branch information
abul-syed authored Jul 3, 2024
1 parent 22f02c0 commit 2fba037
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum FeatureFlagEnum {
PRIVATELAW_WA_1_4("privatelaw_wa_1_4"),
PUBLICLAW_WA_1_2("publiclaw_wa_1_2"),
CIVIL_WA_1_4("civil_wa_1_4"),
CIVIL_WA_1_5("civil_wa_1_5"),
PUBLICLAW_WA_1_3("publiclaw_wa_1_3"),
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-353: insert civil_wa_1_5 base flag into flag_config table
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'local', 'civil', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'pr', 'civil', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'aat', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'demo', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'perftest', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'ithc', 'civil', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('civil_wa_1_5', 'prod', 'civil', 'false');
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,59 @@ then
.primaryLocation($jap.getPrimaryLocationId())
.contractType($jap.getAppointmentType())
.build());
logMsg("Rule : civil_tribunal_judge_salaried_joh");
logMsg("Rule : civil_tribunal_judge_fee_paid_joh");
end;

/*
* "CIVIL Employment Judge - Salaried" business role business role mapping to JOH.
*/
rule "civil_employment_judge_salaried_joh"
when
$f: FeatureFlag(status && flagName == FeatureFlagEnum.CIVIL_WA_1_5.getValue())
$jap: JudicialAccessProfile(appointment == "Employment Judge",
appointmentType in ("Salaried", "SPTW"),
(endTime == null || endTime.compareTo(ZonedDateTime.now()) >= 0),
(validateAuthorisation(authorisations, "AAA6") || validateAuthorisation(authorisations, "AAA7")))
then
insert(
JudicialOfficeHolder.builder()
.userId($jap.getUserId())
.office("CIVIL Employment Judge-Salaried")
.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_employment_judge_salaried_joh");
end;

/*
* "CIVIL Employment Judge - Fee Paid" business role business role mapping to JOH.
*/
rule "civil_employment_judge_fee_paid_joh"
when
$f: FeatureFlag(status && flagName == FeatureFlagEnum.CIVIL_WA_1_5.getValue())
$jap: JudicialAccessProfile(appointment == "Employment Judge",
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 Employment Judge-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_employment_judge_fee_paid_joh");
end;
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialBooking;
import java.util.ArrayList;
import uk.gov.hmcts.reform.orgrolemapping.util.JacksonUtils;
import java.util.HashMap
import java.util.List;
import java.util.Map
import com.fasterxml.jackson.databind.JsonNode;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.FeatureFlagEnum;
import function uk.gov.hmcts.reform.orgrolemapping.domain.service.RequestMappingService.logMsg;

import function uk.gov.hmcts.reform.orgrolemapping.helper.AssignmentRequestBuilder.cloneNewRoleAssignmentAndChangeRegion

/*
* CIVIL "judge" Org role mapping.
Expand Down Expand Up @@ -89,6 +90,46 @@ then
logMsg("Rule : v11_civil_judge_org_role");
end;

/*
* CIVIL "judge" Org role mapping (multi region - see DTSAM-353).
*/
rule "civil_judge_org_role_multi_region"
when
$joh: JudicialOfficeHolder(office == "CIVIL Employment Judge-Salaried")
then
Map<String,JsonNode> attribute = new HashMap<>();
attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Salaried"));
attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("CIVIL"));
attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($joh.getPrimaryLocation()));
attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($joh.getRegionId()));
attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("hearing_work,decision_making_work,applications"));

RoleAssignment ra = 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($joh.getBeginTime())
.endTime($joh.getEndTime() !=null ? $joh.getEndTime().plusDays(1):null)
.attributes(attribute)
.authorisations($joh.getTicketCodes())
.build();

// For users with any England/Wales region, create a role assignment for each England/Wales region.
List<String> englandWalesRegions = List.of("1", "2", "3", "4", "5", "6", "7");
if (englandWalesRegions.contains($joh.getRegionId())) {
for (String regionId : englandWalesRegions) {
insert(cloneNewRoleAssignmentAndChangeRegion(ra, regionId));
}
} else {
insert(ra);
}
logMsg("Rule : civil_judge_org_role_multi_region");
end;

/*
* CIVIL "leadership-judge" Org role mapping.
Expand Down Expand Up @@ -261,6 +302,92 @@ then
logMsg("Rule : civil_fee_paid_judge_org_role");
end;

/*
* CIVIL "fee-paid-judge" Org role mapping (multi region - see DTSAM-353).
*/
rule "civil_fee_paid_judge_org_role_multi_region"
when
$joh: JudicialOfficeHolder(office == "CIVIL Employment Judge-Fee-Paid")
then
Map<String,JsonNode> attribute = new HashMap<>();
attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid"));
attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("CIVIL"));
attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($joh.getPrimaryLocation()));
attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("hearing_work,decision_making_work,applications"));
attribute.put("bookable", JacksonUtils.convertObjectIntoJsonNode("true"));
attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($joh.getRegionId()));

RoleAssignment ra = RoleAssignment.builder()
.actorIdType(ActorIdType.IDAM)
.actorId($joh.getUserId())
.roleCategory(RoleCategory.JUDICIAL)
.roleType(RoleType.ORGANISATION)
.roleName("fee-paid-judge")
.grantType(GrantType.STANDARD)
.classification(Classification.PUBLIC)
.readOnly(false)
.beginTime($joh.getBeginTime())
.endTime($joh.getEndTime() !=null ? $joh.getEndTime().plusDays(1):null)
.attributes(attribute)
.authorisations($joh.getTicketCodes())
.build();

// For users with any England/Wales region, create a role assignment for each England/Wales region.
List<String> englandWalesRegions = List.of("1", "2", "3", "4", "5", "6", "7");
if (englandWalesRegions.contains($joh.getRegionId())) {
for (String regionId : englandWalesRegions) {
insert(cloneNewRoleAssignmentAndChangeRegion(ra, regionId));
}
} else {
insert(ra);
}
logMsg("Rule : civil_fee_paid_judge_org_role_multi_region");
end;

/*
* CIVIL "judge" org role (multi region - see DTSAM-353) is created if judicial office holder
* is a "CIVIL Employment Judge-Fee-Paid" and has a booking.
*/
rule "civil_judge_org_role_for_fee_paid_judge_multi_region"
when
$joh: JudicialOfficeHolder(office == "CIVIL Employment Judge-Fee-Paid")
$bk: JudicialBooking(userId == $joh.userId)
then
Map<String,JsonNode> attribute = new HashMap<>();
attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("CIVIL"));
attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($bk.getLocationId() != null ?
$bk.getLocationId():$joh.getPrimaryLocation()));
attribute.put("baseLocation", JacksonUtils.convertObjectIntoJsonNode($bk.getLocationId()));
attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($bk.getRegionId()));
attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid"));
attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("hearing_work,decision_making_work,applications"));

RoleAssignment ra = 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();

// For users with any England/Wales region, create a role assignment for each England/Wales region.
List<String> englandWalesRegions = List.of("1", "2", "3", "4", "5", "6", "7");
if (englandWalesRegions.contains($joh.getRegionId())) {
for (String regionId : englandWalesRegions) {
insert(cloneNewRoleAssignmentAndChangeRegion(ra, regionId));
}
} else {
insert(ra);
}
logMsg("Rule : civil_judge_org_role_for_fee_paid_judge_multi_region");
end;

/*
* CIVIL "hmcts-judiciary" Org role mapping.
Expand All @@ -275,7 +402,8 @@ $joh: JudicialOfficeHolder(office in ( "CIVIL District Judge-Salaried", "CIVIL P
"CIVIL Deputy Circuit Judge-Fee-Paid", "CIVIL Deputy District Judge-Fee-Paid",
"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 Tribunal Judge-Salaried", "CIVIL Tribunal Judge-Fee-Paid",
"CIVIL Employment Judge-Salaried", "CIVIL Employment Judge-Fee-Paid"))
then
Map<String,JsonNode> attribute = new HashMap<>();
if($joh.getOffice().contains("Fee-Paid")) {
Expand Down
Loading

0 comments on commit 2fba037

Please sign in to comment.