Skip to content

Commit

Permalink
DTSAM-182 PRL OGA listed-hearing-viewer changes (#1844)
Browse files Browse the repository at this point in the history
[DTSAM-182](https://tools.hmcts.net/jira/browse/DTSAM-182)

Private Law: changes to listed-hearing-viewer mappings.

Co-authored-by: mikebrownccd <104495891+mikebrownccd@users.noreply.github.com>
  • Loading branch information
mattnayler and mikebrownccd authored Apr 4, 2024
1 parent 75d4825 commit 587cfb1
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum FeatureFlagEnum {
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_4("privatelaw_wa_1_4"),
PUBLICLAW_WA_1_2("publiclaw_wa_1_2"),
CIVIL_WA_1_4("civil_wa_1_4"),
PUBLICLAW_WA_1_3("publiclaw_wa_1_3"),
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 ('privatelaw_wa_1_4', 'local', 'privatelaw', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'pr', 'privatelaw', 'true');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'aat', 'privatelaw', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'demo', 'privatelaw', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'perftest', 'privatelaw', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'ithc', 'privatelaw', 'false');
INSERT INTO flag_config (flag_name, env, service_name, status) VALUES ('privatelaw_wa_1_4', 'prod', 'privatelaw', 'false');
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import function uk.gov.hmcts.reform.orgrolemapping.util.UtilityFunctions.getJuri

/*
* Private Law "listed-hearing-viewer" Org role mapping.
* Made obsolete in DTSAM-182 by PRIVATELAW_WA_1_4.
* To be removed in DTSAM-246.
*/
rule "private_law_cymru_caseworker_hearing_viewer_other_gov_dept"
when
$f: FeatureFlag(status && flagName == FeatureFlagEnum.PRIVATELAW_WA_1_2.getValue())
$f2: FeatureFlag(status == false, flagName == FeatureFlagEnum.PRIVATELAW_WA_1_4.getValue())
$up: CaseWorkerAccessProfile(roleId in ("18"), serviceCode in ("ABA5"), !suspended)
then
Map<String,JsonNode> attribute = new HashMap<>();
Expand Down Expand Up @@ -66,4 +69,4 @@ then
.attributes(attribute)
.build());
logMsg("Rule : private_law_caseworker_externaluser_viewonly_other_gov_dept");
end;
end;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialBooking;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialOfficeHolder;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.RoleAssignment;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.FeatureFlagEnum;
import uk.gov.hmcts.reform.orgrolemapping.helper.TestDataBuilder;
import uk.gov.hmcts.reform.orgrolemapping.util.ValidationUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -92,4 +94,16 @@ protected List<FeatureFlag> getFeatureFlags(String flagName, Boolean status) {
return Collections.singletonList(FeatureFlag.builder().flagName(flagName).status(status).build());
}

}
@NotNull
protected List<FeatureFlag> getAllFeatureFlagsToggleByJurisdiction(String jurisdiction, Boolean status) {
// build list of all flags...
return Arrays.stream(FeatureFlagEnum.values())
.map(featureFlagEnum -> FeatureFlag.builder()
.flagName(featureFlagEnum.getValue())
// ... toggle those that start with jurisdiction (otherwise false)
.status(featureFlagEnum.name().startsWith(jurisdiction.toUpperCase() + "_") ? status : false)
.build())
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DroolPrivateLawJudicialRoleMappingTest extends DroolBase {
static final String SERVICE_CODES = "ABA5";
static Map<String, String> expectedRoleNameWorkTypesMap = new HashMap<>();

{
static {
expectedRoleNameWorkTypesMap.put("judge", "hearing_work,decision_making_work,applications");
expectedRoleNameWorkTypesMap.put("hmcts-judiciary", null);
expectedRoleNameWorkTypesMap.put("leadership-judge", null);
Expand Down Expand Up @@ -226,7 +226,7 @@ void shouldTakeJudicialAccessProfileConvertToJudicialOfficeHolderThenReturnRoleA
);

//Execute Kie session
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags());
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(true));

//assertions
assertFalse(roleAssignments.isEmpty());
Expand Down Expand Up @@ -266,21 +266,14 @@ void falsePrivateLawFlagTest() {
);

//Execute Kie session
List<RoleAssignment> roleAssignments =
buildExecuteKieSession(List.of(
FeatureFlag.builder().flagName("privatelaw_wa_1_0").status(false).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_1").status(false).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_2").status(false).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_3").status(false).build()));
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(false));

//assertions
assertTrue(roleAssignments.isEmpty());
}

List<FeatureFlag> getFeatureFlags() {
return List.of(FeatureFlag.builder().flagName("privatelaw_wa_1_0").status(true).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_1").status(true).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_2").status(true).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_3").status(true).build());
List<FeatureFlag> getFeatureFlags(Boolean status) {
return getAllFeatureFlagsToggleByJurisdiction("PRIVATELAW", status);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package uk.gov.hmcts.reform.orgrolemapping.domain.service;

import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.CaseWorkerAccessProfile;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.FeatureFlag;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.RoleAssignment;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.Classification;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.GrantType;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.RoleCategory;

import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static uk.gov.hmcts.reform.orgrolemapping.helper.TestDataBuilder.buildUserAccessProfile3;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -25,36 +29,56 @@ class DroolPrivateLawOtherGovDeptStaffRoleMappingTest extends DroolBase {

@ParameterizedTest
@CsvSource({
"18,ABA5,PRIVATELAW"
"18,ABA5,PRIVATELAW,caseworker-privatelaw-externaluser-viewonly"
})
void shouldReturnListedHearingViewerCaseWorker_otherGovDept(String roleId,
String serviceCode,
String jurisdiction) {
String jurisdiction,
String expectedRoles) {

CaseWorkerAccessProfile cap = buildUserAccessProfile3(serviceCode, roleId, "");
cap.setRegionId("1");

allProfiles.add(cap);

//Execute Kie session
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(LD_FLAG, true));
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(true));

//assertion
assertFalse(roleAssignments.isEmpty());
assertEquals(2, roleAssignments.size());
assertEquals(expectedRoles.split(",").length, roleAssignments.size());
MatcherAssert.assertThat(roleAssignments.stream().map(RoleAssignment::getRoleName).collect(Collectors.toList()),
containsInAnyOrder(expectedRoles.split(",")));
roleAssignments.forEach(r -> {
assertEquals(RoleCategory.OTHER_GOV_DEPT, r.getRoleCategory());
assertEquals(usersAccessProfiles.keySet().stream().iterator().next(), r.getActorId());
assertEquals(jurisdiction, r.getAttributes().get("jurisdiction").asText());
assertEquals(Classification.PUBLIC, r.getClassification());
assertEquals(GrantType.STANDARD, r.getGrantType());
assertThat(r.getRoleName())
.matches(s -> Stream.of("listed-hearing-viewer", "caseworker-privatelaw-externaluser-viewonly")
.anyMatch(s::contains));

if ("caseworker-privatelaw-externaluser-viewonly".equals(r.getRoleName())) {
assertEquals("1", r.getAttributes().get("region").asText());
}
});
}

@Test
void falsePrivateLawFlagTest() {

CaseWorkerAccessProfile cap = buildUserAccessProfile3("ABA5", "18", "");
cap.setRegionId("1");

allProfiles.add(cap);

//Execute Kie session
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(false));

//assertions
assertTrue(roleAssignments.isEmpty());
}

List<FeatureFlag> getFeatureFlags(Boolean status) {
return getAllFeatureFlagsToggleByJurisdiction("PRIVATELAW", status);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DroolPrivateLawStaffOrgRolesTest extends DroolBase {

static Map<String, String> expectedRoleNameWorkTypesMap = new HashMap<>();

{
static {
expectedRoleNameWorkTypesMap.put("hmcts-admin", null);
expectedRoleNameWorkTypesMap.put("hearing-centre-team-leader", "routine_work,hearing_work,applications");
expectedRoleNameWorkTypesMap.put("hmcts-ctsc", null);
Expand Down Expand Up @@ -72,7 +72,7 @@ static void assertCommonRoleAssignmentAttributes(RoleAssignment r, String roleId
r.getRoleName())) {
assertEquals(Classification.PRIVATE, r.getClassification());
assertEquals(GrantType.BASIC, r.getGrantType());
assertEquals(null, r.getAttributes().get("jurisdiction"));
assertNull(r.getAttributes().get("jurisdiction"));
assertTrue(r.isReadOnly());
assertNull(primaryLocation);
assertNull(r.getAttributes().get("region"));
Expand Down Expand Up @@ -145,7 +145,7 @@ void shouldReturnPrivateLawMappings(String roleId, String serviceCode, String ex
allProfiles.add(cap);

//Execute Kie session
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags());
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(true));


//assertion
Expand Down Expand Up @@ -174,19 +174,14 @@ void shouldNotReturnCtsRoles_disabledFlag() {
allProfiles.add(cap);

//Execute Kie session
List<RoleAssignment> roleAssignments =
buildExecuteKieSession(
List.of(FeatureFlag.builder().flagName("privatelaw_wa_1_0").status(false).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_1").status(false).build())
);
List<RoleAssignment> roleAssignments = buildExecuteKieSession(getFeatureFlags(false));

//assertion
assertTrue(roleAssignments.isEmpty());
}


List<FeatureFlag> getFeatureFlags() {
return List.of(FeatureFlag.builder().flagName("privatelaw_wa_1_0").status(true).build(),
FeatureFlag.builder().flagName("privatelaw_wa_1_1").status(true).build());
List<FeatureFlag> getFeatureFlags(Boolean status) {
return getAllFeatureFlagsToggleByJurisdiction("PRIVATELAW", status);
}
}

}

0 comments on commit 587cfb1

Please sign in to comment.