Skip to content

Commit c811381

Browse files
Dev/connection impl (#65)
* added code to test the connectvity * Replace the url with actual url and implemented other functionlity * merge from main * update caseurnmapper to urnmapper * update caseurnmapper to urnmapper * update caseurnmapper to urnmapper * update caseurnmapper to urnmapper * update pact flow test * updated code for pact testing --------- Co-authored-by: Dmitri Algazin <dmitri.algazin@hmcts.net>
1 parent b55122e commit c811381

27 files changed

+799
-268
lines changed

.env

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
SERVER_PORT=4550
22
BASE_IMAGE=openjdk:21-jdk-slim
3-
JAR_FILENAME=service-cp-crime-schedulingandlisting-courtschedule-*.jar
4-
JAR_FILE_PATH=build/libs
3+
JAR_FILENAME=service-cp-crime-scheduleandlist-courtschedule-*.jar
4+
JAR_FILE_PATH=build/libs
5+
CASE_MAPPER_SERVICE_URL=https://devcp01.ingress01.dev.nl.cjscp.org.uk/urnmapper
6+
COURT_SCHEDULE_CLIENT_URL=https://steccm64.ingress01.dev.nl.cjscp.org.uk/listing-query-api/query/api/rest/listing/hearings/allocated-and-unallocated
7+
CJSCPPUID=d7c91866-646a-462c-9203-46678e8cddef

.github/workflows/ci-build-publish.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,24 @@ jobs:
7979
- name: Gradle Build
8080
env:
8181
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
82+
CASE_MAPPER_SERVICE_URL: ${{ vars.CASE_MAPPER_SERVICE_URL }}
83+
COURT_SCHEDULE_CLIENT_URL: ${{ vars.COURT_SCHEDULE_CLIENT_URL }}
84+
CJSCPPUID: ${{ vars.CJSCPPUID }}
8285
run: |
8386
echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION"
8487
gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION
88+
89+
if [ -z "$CASE_MAPPER_SERVICE_URL" ]; then
90+
echo "::warning::CASE_MAPPER_SERVICE_URL is null or not set"
91+
fi
92+
93+
if [ -z "$COURT_SCHEDULE_CLIENT_URL" ]; then
94+
echo "::warning::COURT_SCHEDULE_CLIENT_URL is null or not set"
95+
fi
96+
97+
if [ -z "$CJSCPPUID" ]; then
98+
echo "::warning::CJSCPPUID is null or not set"
99+
fi
85100
86101
- name: Extract repo name
87102
id: repo_vars
@@ -173,7 +188,10 @@ jobs:
173188
-DGITHUB_ACTOR=${{ github.actor }} \
174189
-DGITHUB_TOKEN=$GITHUB_TOKEN \
175190
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
176-
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
191+
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN \
192+
-DCASE_MAPPER_SERVICE_URL=$CASE_MAPPER_SERVICE_URL \
193+
-DCOURT_SCHEDULE_CLIENT_URL=$COURT_SCHEDULE_CLIENT_URL \
194+
-DCJSCPPUID=$CJSCPPUID
177195
178196
Build-Docker:
179197
needs: [ Provider-Deploy, Build, Artefact-Version ]
@@ -210,6 +228,9 @@ jobs:
210228
build-args: |
211229
BASE_IMAGE=openjdk:21-jdk-slim
212230
JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
231+
CASE_MAPPER_SERVICE_URL=${{ vars.CASE_MAPPER_SERVICE_URL }}
232+
COURT_SCHEDULE_CLIENT_URL=${{ vars.COURT_SCHEDULE_CLIENT_URL }}
233+
CJSCPPUID=${{ vars.CJSCPPUID }}
213234
214235
Deploy:
215236
needs: [ Provider-Deploy, Build, Artefact-Version ]

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ FROM ${BASE_IMAGE:-openjdk:21-jdk-slim}
55
# ---- Runtime arguments ----
66
ARG JAR_FILENAME
77
ARG JAR_FILE_PATH
8+
ARG CASE_MAPPER_SERVICE_URL
9+
ARG COURT_SCHEDULE_CLIENT_URL
10+
ARG CJSCPPUID
811

912
ENV JAR_FILENAME=${JAR_FILENAME:-app.jar}
1013
ENV JAR_FILE_PATH=${JAR_FILE_PATH:-build/libs}
1114
ENV JAR_FULL_PATH=$JAR_FILE_PATH/$JAR_FILENAME
1215

16+
ENV CASE_MAPPER_SERVICE_URL=$CASE_MAPPER_SERVICE_URL
17+
ENV COURT_SCHEDULE_CLIENT_URL=$COURT_SCHEDULE_CLIENT_URL
18+
ENV CJSCPPUID=$CJSCPPUID
19+
20+
1321
# ---- Set runtime ENV for Spring Boot to bind port
1422
ARG SERVER_PORT
1523
ENV SERVER_PORT=${SERVER_PORT:-4550}
@@ -29,4 +37,4 @@ RUN chmod 755 /opt/app/app.jar
2937
# ---- Runtime ----
3038
EXPOSE 4550
3139

32-
CMD ["java", "-jar", "/opt/app/app.jar"]
40+
CMD ["java", "-Dcom.sun.net.ssl.checkRevocation=false", "-jar", "/opt/app/app.jar"]

deploy.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Define the service name
4+
SERVICE_NAME="service-cp-crime-scheduleandlist-courtschedule"
5+
6+
# Check if the Docker container is running
7+
if [ "$(docker ps -q -f name=${SERVICE_NAME})" ]; then
8+
echo "Stopping the running Docker container..."
9+
docker-compose down
10+
fi
11+
12+
# Rebuild the Docker image
13+
echo "Rebuilding the Docker image..."
14+
docker-compose build
15+
16+
# Deploy the service
17+
echo "Starting the Docker container..."
18+
docker-compose up -d
19+
20+
echo "Deployment completed successfully."

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.8'
22

33
services:
4-
service-cp-crime-schedulingandlisting-courtschedule:
4+
service-cp-crime-scheduleandlist-courtschedule:
55
env_file:
66
- .env
77
build:
@@ -15,6 +15,10 @@ services:
1515
SERVER_PORT: ${SERVER_PORT}
1616
JAR_FILENAME: ${JAR_FILENAME}
1717
JAR_FILE_PATH: ${JAR_FILE_PATH}
18+
CASE_MAPPER_SERVICE_URL: ${CASE_MAPPER_SERVICE_URL}
19+
COURT_SCHEDULE_CLIENT_URL: ${COURT_SCHEDULE_CLIENT_URL}
20+
CJSCPPUID: ${CJSCPPUID}
21+
1822
environment:
1923
- SERVER_PORT=${SERVER_PORT:-4550}
2024
ports:
@@ -30,4 +34,4 @@ services:
3034

3135
networks:
3236
service-network:
33-
name: service-cp-crime-schedulingandlisting-courtschedule-network
37+
name: service-cp-crime-scheduleandlist-courtschedule-network
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
package uk.gov.hmcts.cp.config;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
5-
import uk.gov.hmcts.cp.repositories.CourtScheduleRepository;
6-
import uk.gov.hmcts.cp.repositories.CourtScheduleRepositoryImpl;
6+
import org.springframework.web.client.RestTemplate;
7+
import uk.gov.hmcts.cp.controllers.CourtScheduleController;
8+
import uk.gov.hmcts.cp.repositories.InMemoryCourtScheduleClientImpl;
9+
import uk.gov.hmcts.cp.services.CaseUrnMapperService;
10+
import uk.gov.hmcts.cp.services.CourtScheduleService;
711

8-
import java.net.http.HttpClient;
9-
10-
import static org.mockito.Mockito.mock;
12+
import java.util.UUID;
1113

1214
@Configuration
1315
public class TestConfig {
16+
@Bean("courtScheduleService")
17+
public CourtScheduleService courtScheduleService() {
18+
return new CourtScheduleService(new InMemoryCourtScheduleClientImpl());
19+
}
20+
21+
@Bean("testCaseUrnMapperService")
22+
public CaseUrnMapperService testCaseUrnMapperService() {
23+
RestTemplate restTemplate = new RestTemplate();
24+
return new CaseUrnMapperService(restTemplate) {
25+
@Override
26+
public String getCaseMapperServiceUrl() {
27+
return "http://mock-server/test-mapper";
28+
}
29+
public String getCaseId(final String caseUrn) {
30+
return UUID.randomUUID().toString();
31+
}
32+
};
33+
}
1434

35+
@Bean("courtScheduleController")
36+
public CourtScheduleController courtScheduleController(
37+
CourtScheduleService courtScheduleService,
38+
CaseUrnMapperService testCaseUrnMapperService) {
39+
return new CourtScheduleController(courtScheduleService, testCaseUrnMapperService);
40+
}
1541
}

src/integrationTest/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerIT.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import org.springframework.boot.test.context.SpringBootTest;
1313
import org.springframework.context.annotation.Import;
1414
import org.springframework.http.MediaType;
15+
import org.springframework.test.context.ActiveProfiles;
1516
import org.springframework.test.context.junit.jupiter.SpringExtension;
1617
import org.springframework.test.web.servlet.MockMvc;
1718
import uk.gov.hmcts.cp.config.TestConfig;
18-
import uk.gov.hmcts.cp.repositories.CourtScheduleRepository;
19+
import uk.gov.hmcts.cp.repositories.CourtScheduleClient;
20+
import uk.gov.hmcts.cp.services.CaseUrnMapperService;
1921

2022
import java.util.UUID;
2123

@@ -28,6 +30,7 @@
2830
@ExtendWith(SpringExtension.class)
2931
@SpringBootTest
3032
@AutoConfigureMockMvc
33+
@ActiveProfiles("pact-test")
3134
@Import(TestConfig.class)
3235
class CourtScheduleControllerIT {
3336
private static final Logger log = LoggerFactory.getLogger(CourtScheduleControllerIT.class);
@@ -36,15 +39,21 @@ class CourtScheduleControllerIT {
3639
private MockMvc mockMvc;
3740

3841
@Autowired
39-
@Qualifier("inMemoryCourtScheduleRepositoryImpl")
40-
private CourtScheduleRepository courtScheduleRepository;
42+
@Qualifier("inMemoryCourtScheduleClientImpl")
43+
private CourtScheduleClient courtScheduleClient;
4144

42-
/*@BeforeEach
43-
void setUp() {
44-
inMemoryCaseUrnMapper.clearAllMappings();
45-
inMemoryCaseUrnMapper.saveCaseUrnMapping("test-case-urn", "test-case-id");
45+
@Autowired
46+
@Qualifier("testCaseUrnMapperService")
47+
private CaseUrnMapperService caseUrnMapperService;
48+
49+
@Test
50+
void shouldReturnOkWhenValidUrnIsProvided1() throws Exception {
51+
String caseUrn = "test-case-urn";
52+
mockMvc.perform(get("/case/{case_urn}/courtschedule", caseUrn)
53+
.accept(MediaType.APPLICATION_JSON))
54+
.andExpect(status().isOk());
4655
}
47-
*/
56+
4857
@Test
4958
void shouldReturnOkWhenValidUrnIsProvided() throws Exception {
5059
String caseUrn = "test-case-urn";

src/main/java/uk/gov/hmcts/cp/controllers/CourtScheduleController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public ResponseEntity<CourtScheduleResponse> getCourtScheduleByCaseUrn(final Str
3131
final CourtScheduleResponse courtScheduleResponse;
3232
try {
3333
sanitizedCaseUrn = sanitizeString(caseUrn);
34-
courtScheduleResponse = courtScheduleService.getCourtScheduleByCaseId(
35-
caseUrnMapperService.getCaseId(sanitizedCaseUrn));
34+
String caseId = caseUrnMapperService.getCaseId(sanitizedCaseUrn);
35+
courtScheduleResponse = courtScheduleService.getCourtScheduleByCaseId(caseId);
3636
} catch (ResponseStatusException e) {
3737
LOG.atError().log(e.getMessage());
3838
throw e;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package uk.gov.hmcts.cp.domain;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.io.Serializable;
9+
10+
@Builder
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
@Getter
14+
public class CaseMapperResponse implements Serializable {
15+
16+
private static final long serialVersionUID = 1L;
17+
18+
private String caseId;
19+
20+
private String caseUrn;
21+
22+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package uk.gov.hmcts.cp.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@Builder
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
@Getter
17+
public class HearingResponse implements Serializable {
18+
private static final long serialVersionUID = 1L;
19+
20+
private List<HearingResult> hearings;
21+
22+
@JsonIgnoreProperties(ignoreUnknown = true)
23+
@Builder
24+
@AllArgsConstructor
25+
@NoArgsConstructor
26+
@Getter
27+
public static class HearingResult implements Serializable {
28+
29+
// private static final long serialVersionUID = 1L;
30+
31+
private String id;
32+
private Type type;
33+
private List<Judiciary> judiciary;
34+
private List<HearingDay> hearingDays;
35+
36+
@JsonIgnoreProperties(ignoreUnknown = true)
37+
@Builder
38+
@AllArgsConstructor
39+
@NoArgsConstructor
40+
@Getter
41+
public static class Type {
42+
private String description;
43+
}
44+
45+
@JsonIgnoreProperties(ignoreUnknown = true)
46+
@Builder
47+
@AllArgsConstructor
48+
@NoArgsConstructor
49+
@Getter
50+
public static class Judiciary {
51+
private String judicialId;
52+
}
53+
54+
@JsonIgnoreProperties(ignoreUnknown = true)
55+
@Builder
56+
@AllArgsConstructor
57+
@NoArgsConstructor
58+
@Getter
59+
public static class HearingDay {
60+
private String endTime;
61+
private int sequence;
62+
private String startTime;
63+
private String courtRoomId;
64+
private String hearingDate;
65+
private String courtCentreId;
66+
private int durationMinutes;
67+
}
68+
}
69+
70+
}

0 commit comments

Comments
 (0)