Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,24 @@ module "db-rd-location-ref-api-v16" {
azurerm.postgres_network = azurerm.postgres_network
}

admin_user_object_id = var.jenkins_AAD_objectId
business_area = "cft"
common_tags = var.common_tags
component = var.component-v16
env = var.env
admin_user_object_id = var.jenkins_AAD_objectId
business_area = "cft"
common_tags = var.common_tags
component = var.component-v16
env = var.env
enable_db_report_privileges = true
pgsql_databases = [
{
name = "dbrdlocationref"
report_privilege_schema : "locrefdata"
report_privilege_tables : ["SERVICE_TO_CCD_CASE_TYPE_ASSOC", "building_location", "court_venue", "region", "cluster", "court_type", "court_type_service_assoc", "dataload_schedular_audit", "dataload_exception_records"]
report_privilege_tables : ["SERVICE_TO_CCD_CASE_TYPE_ASSOC", "building_location", "court_venue", "backup_court_venue", "region", "cluster", "court_type", "court_type_service_assoc", "dataload_schedular_audit", "dataload_exception_records"]
}
]

# Setup Access Reader db user
# Trigger to the force user permission script to rerun
force_user_permissions_trigger = "3"
force_db_report_privileges_trigger = "1"
# Trigger to rerun and grant Access Reader role to the specified tables in the list report_privilege_tables
force_db_report_privileges_trigger = "2"

# Sets correct DB owner after migration to fix permissions
enable_schema_ownership = var.enable_schema_ownership
Expand All @@ -71,10 +72,10 @@ module "db-rd-location-ref-api-v16" {
product = "rd"
name = local.db_name

pgsql_server_configuration = var.pgsql_server_configuration
action_group_name = join("-", [var.action_group_name, local.db_name, "replica", var.env])
email_address_key = var.email_address_key
email_address_key_vault_id = data.azurerm_key_vault.rd_key_vault.id
pgsql_server_configuration = var.pgsql_server_configuration
action_group_name = join("-", [var.action_group_name, local.db_name, "replica", var.env])
email_address_key = var.email_address_key
email_address_key_vault_id = data.azurerm_key_vault.rd_key_vault.id
}

resource "azurerm_key_vault_secret" "POSTGRES-HOST" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ private static LrdBuildingLocationResponse buildingLocation1() {
.postcode("AB11 7KT")
.courtAddress("AB2, 49 HUNTLY STREET, ABERDEEN")
.courtVenueId("2")
.serviceCode("AAA3")
.build();

courtVenueResponses.add(response3);
Expand Down Expand Up @@ -581,6 +582,7 @@ private static LrdBuildingLocationResponse buildingLocation2() {
.locationType("Court")
.parentLocation("366559")
.welshVenueName("testVenue")
.serviceCode("AAA2")
.build();

courtVenueResponses.add(response3);
Expand Down Expand Up @@ -610,6 +612,7 @@ private static LrdBuildingLocationResponse buildingLocation3() {
.postcode("AB11 4RT")
.courtAddress("AB4, 51 HUNTLY STREET, ABERDEEN")
.courtVenueId("4")
.serviceCode("ABA4")
.build();

courtVenueResponses.add(response3);
Expand Down Expand Up @@ -647,6 +650,7 @@ private static LrdBuildingLocationResponse buildingLocation4() {
.postcode("AB11 3RP")
.courtAddress("AB9, 56 HUNTLY STREET, ABERDEEN")
.courtVenueId("9")
.serviceCode("AAA2")
.build();

courtVenueResponses.add(response3);
Expand Down Expand Up @@ -686,6 +690,7 @@ private LrdBuildingLocationResponse getBuildingLocationSampleResponse() {
.postcode("AB11 8IP")
.courtAddress("AB3, 50 HUNTLY STREET, ABERDEEN")
.courtVenueId("3")
.serviceCode("AAA6")
.build();

courtVenueResponses.add(response3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,64 @@ void shouldReturn200WhenParameterEpmIdsValueAllWithYAndSpacePassed() throws

assertThat(response).isNotEmpty().hasSize(1);
}

@Test
@SuppressWarnings("unchecked")
void retrieveCourtVenues_WithEpimmsId_ShouldReturnServiceCodeInResponse() throws JsonProcessingException {

final var response = (List<LrdCourtVenueResponse>)
lrdApiClient.retrieveCourtVenueResponseForGivenRequest("?epimms_id=123456789",
LrdCourtVenueResponse[].class, path);

assertThat(response).isNotEmpty().hasSize(1);
LrdCourtVenueResponse venueResponse = response.get(0);
assertNotNull(venueResponse.getServiceCode());
assertTrue(venueResponse.getServiceCode().matches("[A-Z0-9]+"));
}

@ParameterizedTest
@CsvSource({
"123456789,AAA6",
"123461,AAA2",
"123462,AAA3"
})
@SuppressWarnings("unchecked")
void retrieveCourtVenues_WithEpimmsId_ShouldReturnCorrectServiceCode(String epimmsId, String expectedServiceCode)
throws JsonProcessingException {

final var response = (List<LrdCourtVenueResponse>)
lrdApiClient.retrieveCourtVenueResponseForGivenRequest("?epimms_id=" + epimmsId,
LrdCourtVenueResponse[].class, path);

assertThat(response).isNotEmpty().hasSize(1);
assertEquals(expectedServiceCode, response.get(0).getServiceCode());
}

@Test
@SuppressWarnings("unchecked")
void retrieveCourtVenues_AllVenues_ShouldAllHaveServiceCode() throws JsonProcessingException {

final var response = (List<LrdCourtVenueResponse>)
lrdApiClient.retrieveCourtVenueResponseForGivenRequest("?epimms_id=ALL",
LrdCourtVenueResponse[].class, path);

assertThat(response).isNotEmpty();
assertTrue(response.stream().allMatch(venue -> venue.getServiceCode() != null
&& !venue.getServiceCode().isEmpty()));
}

@Test
@SuppressWarnings("unchecked")
void retrieveCourtVenues_WithEpimmsIdAndServiceCode_ShouldEnforceUniqueConstraint() throws JsonProcessingException {

final var response = (List<LrdCourtVenueResponse>)
lrdApiClient.retrieveCourtVenueResponseForGivenRequest("?epimms_id=123456789",
LrdCourtVenueResponse[].class, path);

assertThat(response).isNotEmpty().hasSize(1);
LrdCourtVenueResponse venueResponse = response.get(0);
assertNotNull(venueResponse.getEpimmsId());
assertNotNull(venueResponse.getServiceCode());
assertEquals("123456789", venueResponse.getEpimmsId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private List<LrdCourtVenueResponse> buildCourtVenueResponses() {
.isHearingLocation("N")
.locationType("NBC")
.isTemporaryLocation("N")
.serviceCode("AAA6")
.build();

LrdCourtVenueResponse response2 = LrdCourtVenueResponse.builder()
Expand All @@ -149,6 +150,7 @@ private List<LrdCourtVenueResponse> buildCourtVenueResponses() {
.isHearingLocation("N")
.locationType("NBC")
.isTemporaryLocation("N")
.serviceCode("ABA4")
.build();

expectedCourtVenueResponses.add(response1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Add service_code column to court_venue table
ALTER TABLE court_venue ADD COLUMN IF NOT EXISTS service_code VARCHAR(16);

-- Drop the existing unique constraint on (epimms_id, court_type_id)
ALTER TABLE court_venue DROP CONSTRAINT IF EXISTS court_location_unique;

-- Add a new unique constraint with epimms_id and service_code
ALTER TABLE court_venue ADD CONSTRAINT court_location_unique UNIQUE (epimms_id, service_code);

-- Add foreign key constraint for service_code
ALTER TABLE court_venue ADD CONSTRAINT court_venue_service_code_fk FOREIGN KEY (service_code) REFERENCES SERVICE (service_code);

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
UPDATE court_venue SET service_code = 'AAA2' WHERE court_venue_id = 1;
UPDATE court_venue SET service_code = 'AAA3' WHERE court_venue_id = 2;
UPDATE court_venue SET service_code = 'AAA6' WHERE court_venue_id = 3;
UPDATE court_venue SET service_code = 'ABA4' WHERE court_venue_id = 4;
UPDATE court_venue SET service_code = 'AAA2' WHERE court_venue_id = 5;
UPDATE court_venue SET service_code = 'AAA3' WHERE court_venue_id = 6;
UPDATE court_venue SET service_code = 'AAA6' WHERE court_venue_id = 7;
UPDATE court_venue SET service_code = 'ABA4' WHERE court_venue_id = 8;
UPDATE court_venue SET service_code = 'AAA2' WHERE court_venue_id = 9;
UPDATE court_venue SET service_code = 'AAA3' WHERE court_venue_id = 10;
UPDATE court_venue SET service_code = 'AAA6' WHERE court_venue_id = 11;
UPDATE court_venue SET service_code = 'ABA4' WHERE court_venue_id = 12;
UPDATE court_venue SET service_code = 'AAA2' WHERE court_venue_id = 13;
UPDATE court_venue SET service_code = 'AAA3' WHERE court_venue_id = 14;
UPDATE court_venue SET service_code = 'AAA6' WHERE court_venue_id = 15;
COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,4 @@ public ResponseEntity<Object> retrieveBuildingLocationDetailsBySearchString(
Object responseEntity = buildingLocationService.searchBuildingLocationsBySearchString(trimmedSearchString);
return ResponseEntity.status(HttpStatus.OK).body(responseEntity);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class LrdCourtVenueResponse implements Serializable {
@JsonProperty("epimms_id")
private String epimmsId;

@JsonProperty("service_code")
private String serviceCode;

@JsonProperty("site_name")
private String siteName;

Expand Down Expand Up @@ -151,6 +154,7 @@ public LrdCourtVenueResponse(CourtVenue courtVenue) {
this.courtType = courtVenue.getCourtType().getTypeOfCourt();
this.dxAddress = courtVenue.getDxAddress();
this.epimmsId = courtVenue.getEpimmsId();
this.serviceCode = courtVenue.getServiceCode();
this.openForPublic = Boolean.TRUE.equals(courtVenue.getOpenForPublic()) ? "YES" : "NO";
this.phoneNumber = courtVenue.getPhoneNumber();
this.welshCourtAddress = courtVenue.getWelshCourtAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Setter
@Builder
@EqualsAndHashCode
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"epimms_id","site_name","court_type_id"}))
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"epimms_id","service_code"}))
public class CourtVenue implements Serializable {

@Id
Expand All @@ -42,6 +42,9 @@ public class CourtVenue implements Serializable {
@Column(name = "epimms_id")
private String epimmsId;

@Column(name = "service_code")
private String serviceCode;

@CreatedDate
private LocalDateTime createdTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Add service_code column to court_venue table
ALTER TABLE court_venue ADD COLUMN IF NOT EXISTS service_code VARCHAR(16);

-- Drop the existing unique constraint on (epimms_id, court_type_id)
ALTER TABLE court_venue DROP CONSTRAINT IF EXISTS court_location_unique;

-- Add a new unique constraint with epimms_id and service_code
ALTER TABLE court_venue ADD CONSTRAINT court_location_unique UNIQUE (epimms_id, service_code);

-- Add foreign key constraint for service_code
ALTER TABLE court_venue ADD CONSTRAINT court_venue_service_code_fk FOREIGN KEY (service_code) REFERENCES SERVICE (service_code);

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void testCourtVenuesByServiceCodeResponse() {
.venueName("venueName")
.isCaseManagementLocation("Y")
.isHearingLocation("Y")
.serviceCode("ABC1")
.build();

courtType.setCourtVenues(Collections.singletonList(courtVenue));
Expand All @@ -57,6 +58,6 @@ void testCourtVenuesByServiceCodeResponse() {
assertNotNull(courtVenuesByServiceCodeResponse.getCourtVenues().get(0).getVenueName());
assertNotNull(courtVenuesByServiceCodeResponse.getCourtVenues().get(0).getIsCaseManagementLocation());
assertNotNull(courtVenuesByServiceCodeResponse.getCourtVenues().get(0).getIsHearingLocation());

assertEquals("ABC1", courtVenuesByServiceCodeResponse.getCourtVenues().get(0).getServiceCode());
}
}
Loading