Skip to content

Commit

Permalink
Merge pull request #66 from hmcts/PUB-1974
Browse files Browse the repository at this point in the history
PUB-1974 Add list type friendly name
  • Loading branch information
ChrisS1512 authored Aug 2, 2023
2 parents 90bb2b7 + ca1748f commit 190797b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ publishing {
}

group = 'com.github.hmcts'
version = '2.1.2'
version = '2.1.3'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uk.gov.hmcts.reform.pip.model.account.Roles;
import uk.gov.hmcts.reform.pip.model.account.UserProvenances;
import uk.gov.hmcts.reform.pip.model.location.LocationType;
import uk.gov.hmcts.reform.pip.model.publication.helpers.ListTypeHelper;

import java.util.List;

Expand All @@ -25,8 +26,8 @@
@AllArgsConstructor
public enum ListType {
SJP_PUBLIC_LIST(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES),
SJP_PRESS_LIST(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES),
SJP_DELTA_PRESS_LIST(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES, SJP_PRESS_LIST),
SJP_PRESS_LIST(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES, null, "SJP Press List (Full list)"),
SJP_DELTA_PRESS_LIST(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES, SJP_PRESS_LIST, "SJP Press List (New Cases)"),
SJP_PRESS_REGISTER(NATIONAL, PI_AAD, ALL_VERIFIED_THIRD_PARTY_PRESS_ROLES),
CROWN_DAILY_LIST(VENUE, CRIME_IDAM, ALL_VERIFIED_THIRD_PARTY_CRIME_ROLES),
CROWN_FIRM_LIST(VENUE, CRIME_IDAM, ALL_VERIFIED_THIRD_PARTY_CRIME_ROLES),
Expand All @@ -40,8 +41,8 @@ public enum ListType {
ET_FORTNIGHTLY_PRESS_LIST(OWNING_HEARING_LOCATION, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES),
ET_DAILY_LIST(OWNING_HEARING_LOCATION, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES),
SSCS_DAILY_LIST(OWNING_HEARING_LOCATION, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES),
SSCS_DAILY_LIST_ADDITIONAL_HEARINGS(OWNING_HEARING_LOCATION, CFT_IDAM,
ALL_VERIFIED_THIRD_PARTY_CFT_ROLES, SSCS_DAILY_LIST),
SSCS_DAILY_LIST_ADDITIONAL_HEARINGS(OWNING_HEARING_LOCATION, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES,
SSCS_DAILY_LIST, "SSCS Daily List - Additional Hearings"),
IAC_DAILY_LIST(VENUE, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES),
CARE_STANDARDS_LIST(NATIONAL, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES),
PRIMARY_HEALTH_LIST(NATIONAL, CFT_IDAM, ALL_VERIFIED_THIRD_PARTY_CFT_ROLES);
Expand All @@ -66,9 +67,18 @@ public enum ListType {
*/
private ListType parentListType;

/**
* Friendly name of the list if it is different to the list type name.
*/
private String friendlyName;

ListType(LocationType listLocationLevel, UserProvenances allowedProvenance, List<Roles> allowedThirdPartyRoles) {
this.listLocationLevel = listLocationLevel;
this.allowedProvenance = allowedProvenance;
this.allowedThirdPartyRoles = allowedThirdPartyRoles;
}

public String getFriendlyName() {
return friendlyName == null ? ListTypeHelper.buildFriendlyName(this) : friendlyName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.gov.hmcts.reform.pip.model.publication.helpers;

import org.apache.commons.text.WordUtils;
import uk.gov.hmcts.reform.pip.model.publication.ListType;

import java.util.Arrays;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

public final class ListTypeHelper {
private static final Set<String> ACRONYMS = Set.of("COP", "ET", "IAC", "SSCS", "SJP");
private static final Set<String> CONJUNCTIONS = Set.of("and");

private ListTypeHelper() {
}

public static String buildFriendlyName(ListType listType) {
return Arrays.stream(WordUtils.capitalizeFully(listType.name(), '_').split("_"))
.map(word -> ACRONYMS.contains(word.toUpperCase(Locale.ENGLISH))
? word.toUpperCase(Locale.ENGLISH) : word)
.map(word -> CONJUNCTIONS.contains(word.toLowerCase(Locale.ENGLISH))
? word.toLowerCase(Locale.ENGLISH) : word)
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package uk.gov.hmcts.reform.pip.model.publication;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.hmcts.reform.pip.model.publication.ListType.CIVIL_AND_FAMILY_DAILY_CAUSE_LIST;
import static uk.gov.hmcts.reform.pip.model.publication.ListType.COP_DAILY_CAUSE_LIST;
import static uk.gov.hmcts.reform.pip.model.publication.ListType.MAGISTRATES_PUBLIC_LIST;
import static uk.gov.hmcts.reform.pip.model.publication.ListType.SSCS_DAILY_LIST_ADDITIONAL_HEARINGS;

class ListTypeTest {
private static final String LIST_TYPE_NAME_MESSAGE = "List type name does not match";

@Test
void testStandardListTypeFriendlyName() {
assertThat(MAGISTRATES_PUBLIC_LIST.getFriendlyName())
.as(LIST_TYPE_NAME_MESSAGE)
.isEqualTo("Magistrates Public List");
}

@Test
void testListTypeWithAcronymFriendlyName() {
assertThat(COP_DAILY_CAUSE_LIST.getFriendlyName())
.as(LIST_TYPE_NAME_MESSAGE)
.isEqualTo("COP Daily Cause List");
}

@Test
void testListTypeWithConjunctionFriendlyName() {
assertThat(CIVIL_AND_FAMILY_DAILY_CAUSE_LIST.getFriendlyName())
.as(LIST_TYPE_NAME_MESSAGE)
.isEqualTo("Civil and Family Daily Cause List");
}

@Test
void testListTypeWithCustomFriendlyName() {
assertThat(SSCS_DAILY_LIST_ADDITIONAL_HEARINGS.getFriendlyName())
.as(LIST_TYPE_NAME_MESSAGE)
.isEqualTo("SSCS Daily List - Additional Hearings");
}
}

0 comments on commit 190797b

Please sign in to comment.