Skip to content

Commit

Permalink
Rdcc 4880 jrd (#341)
Browse files Browse the repository at this point in the history
* RDCC-4880 (Region IDs for non-Tribunal JOHs)

* RDCC-4880 (Region IDs for non-Tribunal JOHs)

* fixed the tribunal location mapping

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
nayeemshaik-hmcts and github-actions[bot] authored Jun 23, 2022
1 parent 7693739 commit 0733ca7
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private Page<UserProfile> getPageUserProfiles() {
baseLocationType.setCourtName("Social Entitlement");
baseLocationType.setCourtType("Test court type");
baseLocationType.setAreaOfExpertise("Test area of expertise");
baseLocationType.setCircuit("First Tier Tribunal");
baseLocationType.setCircuit("National");

var regionType = new RegionType();
regionType.setRegionId("1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,33 @@ void shouldReturn_200_ValidParameters_Mrd_Delete_time(String role) {
assertThat((List<?>) appointmentThree.get("service_codes")).isEmpty();

}

@DisplayName("Non-Tribunal cft region and location")
@ParameterizedTest
@ValueSource(strings = { "jrd-system-user","jrd-admin"})
void shouldReturn_200_Non_Tribunal_scenario_01(String role) {

RefreshRoleRequest refreshRoleRequest = RefreshRoleRequest.builder()
.ccdServiceNames("")
.sidamIds(Collections.emptyList())
.objectIds(Arrays.asList("d4774030-32cc-4b64-894f-d475b0b1129c"))
.build();

var response = judicialReferenceDataClient.refreshUserProfile(refreshRoleRequest,10,
0,"ASC", "objectId", role, false);
assertThat(response).containsEntry("http_status", "200 OK");

var userProfileList = (List<?>) response.get("body");

assertThat(userProfileList).hasSize(1);

var values = (LinkedHashMap<String, Object>) userProfileList.get(0);

assertThat((List<?>) values.get("appointments")).hasSize(1);
var appointment = (LinkedHashMap<String, Object>)((List<?>) values.get("appointments")).get(0);
Assertions.assertEquals("12",appointment.get("cft_region_id"));
Assertions.assertEquals("National",appointment.get("cft_region"));
Assertions.assertEquals("12",appointment.get("location_id"));
Assertions.assertEquals("National",appointment.get("location"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VALUES('1', 'National', NULL);

INSERT INTO base_location_type
(base_location_id, court_name, court_type, circuit, area_of_expertise)
VALUES('1029', 'Aberconwy', 'Old Gwynedd', 'Gwynedd', 'LJA');
VALUES('1029', 'Aberconwy', 'Old Gwynedd', 'National', 'LJA');

INSERT INTO judicial_user_profile
(per_id, personal_code, known_as, surname, full_name, post_nominals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.util.stream.Collectors;

import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.judicialapi.util.RefDataConstants.LOCATION;
import static uk.gov.hmcts.reform.judicialapi.util.RefDataConstants.REGION;
import static uk.gov.hmcts.reform.judicialapi.util.RefDataUtil.createPageableObject;
import static uk.gov.hmcts.reform.judicialapi.util.RefDataUtil.distinctByKeys;

Expand Down Expand Up @@ -329,13 +331,6 @@ private UserProfileRefreshResponse buildUserProfileRefreshResponseDto(
.build();
}

private String getStringValueFromBoolean(Boolean value) {
if (value != null) {
return value ? "Y" : "N";
}
return "";
}

private List<AppointmentRefreshResponse> getAppointmentRefreshResponseList(
UserProfile profile, List<RegionMapping> regionMappings) {
log.info("{} : starting get Appointment Refresh Response List ", loggingComponentName);
Expand All @@ -357,14 +352,20 @@ private AppointmentRefreshResponse buildAppointmentRefreshResponseDto(
.findFirst()
.orElse(null);

RegionMapping regionCircuitMapping = regionMappings.stream()
.filter(rm -> rm.getRegion().equalsIgnoreCase(appt.getBaseLocationType().getCircuit()))
.findFirst()
.orElse(null);


return AppointmentRefreshResponse.builder()
.baseLocationId(appt.getBaseLocationId())
.epimmsId(appt.getEpimmsId())
.courtName(appt.getBaseLocationType().getCourtName())
.cftRegionID(null != regionMapping ? regionMapping.getRegionId() : null)
.cftRegion(null != regionMapping ? regionMapping.getRegion() : null)
.locationId(appt.getRegionId())
.location(null != regionMapping ? regionMapping.getJrdRegion() : null)
.cftRegionID(getRegionId(appt.getEpimmsId(),regionMapping,regionCircuitMapping,REGION))
.cftRegion(getRegion(appt.getEpimmsId(),regionMapping,regionCircuitMapping,REGION))
.locationId(getRegionId(appt.getEpimmsId(),regionMapping,regionCircuitMapping,LOCATION))
.location(getRegion(appt.getEpimmsId(),regionMapping,regionCircuitMapping,LOCATION))
.isPrincipalAppointment(String.valueOf(appt.getIsPrincipleAppointment()))
.appointment(appt.getAppointment())
.appointmentType(appt.getAppointmentType())
Expand Down Expand Up @@ -419,4 +420,32 @@ private List<String> getRoleIdList(List<JudicialRoleType> judicialRoleTypes) {
.map(JudicialRoleType::getTitle).toList();
}

// For Tribunal's epimmsId is null
private String getRegionId(String epimmsId,RegionMapping regionMapping,RegionMapping regionCircuitMapping,
String type) {

if ((epimmsId == null || epimmsId.isEmpty())) {
if (LOCATION.equalsIgnoreCase(type)) {
return null != regionMapping ? regionMapping.getJrdRegionId() : null;
} else {
return null != regionMapping ? regionMapping.getRegionId() : null;
}
} else {
return null != regionCircuitMapping ? regionCircuitMapping.getRegionId() : null;
}
}

private String getRegion(String epimmsId,RegionMapping regionMapping,RegionMapping regionCircuitMapping,
String type) {

if ((epimmsId == null || epimmsId.isEmpty())) {
if (LOCATION.equalsIgnoreCase(type)) {
return null != regionMapping ? regionMapping.getJrdRegion() : null;
} else {
return null != regionMapping ? regionMapping.getRegion() : null;
}
} else {
return null != regionCircuitMapping ? regionCircuitMapping.getRegion() : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ private RefDataConstants() {
public static final String LRD_ERROR = "An error occurred while retrieving data from Location Reference Data";

public static final String SERVICE_AUTHORIZATION = "ServiceAuthorization";
public static final String LOCATION = "Location";
public static final String REGION = "Region";

}
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ UserProfile buildUserProfile() {

var appointment = new Appointment();
appointment.setPerId("1");
appointment.setEpimmsId("1234");
appointment.setOfficeAppointmentId(1L);
appointment.setIsPrincipleAppointment(true);
appointment.setStartDate(LocalDate.now());
Expand All @@ -480,6 +481,34 @@ UserProfile buildUserProfile() {
appointment.setBaseLocationType(baseLocationType);
appointment.setRegionType(regionType);

var appointmentTwo = new Appointment();
appointmentTwo.setPerId("1");
appointmentTwo.setEpimmsId(null);
appointmentTwo.setOfficeAppointmentId(1L);
appointmentTwo.setIsPrincipleAppointment(true);
appointmentTwo.setStartDate(LocalDate.now());
appointmentTwo.setEndDate(LocalDate.now());
appointmentTwo.setActiveFlag(true);
appointmentTwo.setExtractedDate(LocalDateTime.now());
appointmentTwo.setCreatedDate(LocalDateTime.now());
appointmentTwo.setLastLoadedDate(LocalDateTime.now());
appointmentTwo.setBaseLocationType(baseLocationType);
appointmentTwo.setRegionType(regionType);

var appointmentThree = new Appointment();
appointmentThree.setPerId("1");
appointmentThree.setEpimmsId("");
appointmentThree.setOfficeAppointmentId(1L);
appointmentThree.setIsPrincipleAppointment(true);
appointmentThree.setStartDate(LocalDate.now());
appointmentThree.setEndDate(LocalDate.now());
appointmentThree.setActiveFlag(true);
appointmentThree.setExtractedDate(LocalDateTime.now());
appointmentThree.setCreatedDate(LocalDateTime.now());
appointmentThree.setLastLoadedDate(LocalDateTime.now());
appointmentThree.setBaseLocationType(baseLocationType);
appointmentThree.setRegionType(regionType);

var authorisation = new Authorisation();
authorisation.setPerId("1");
authorisation.setOfficeAuthId(1L);
Expand Down Expand Up @@ -532,7 +561,7 @@ UserProfile buildUserProfile() {

authorisation.setUserProfile(userProfile);

userProfile.setAppointments(List.of(appointment));
userProfile.setAppointments(List.of(appointment,appointmentTwo,appointmentThree));
userProfile.setAuthorisations(List.of(authorisation));
userProfile.setJudicialRoleTypes(List.of(judicialRoleType,judicialRoleType1,judicialRoleType2));

Expand Down

0 comments on commit 0733ca7

Please sign in to comment.