Skip to content

Commit dd2a67f

Browse files
committed
update caseurnmapper to urnmapper
1 parent 10c3e77 commit dd2a67f

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ SERVER_PORT=4550
22
BASE_IMAGE=openjdk:21-jdk-slim
33
JAR_FILENAME=service-cp-crime-scheduleandlist-courtschedule-*.jar
44
JAR_FILE_PATH=build/libs
5-
CASE_MAPPER_SERVICE_URL=https://steccm64.ingress01.dev.nl.cjscp.org.uk/system-id-mapper-api/rest/systemid/mappings
5+
CASE_MAPPER_SERVICE_URL=https://devcp01.ingress01.dev.nl.cjscp.org.uk/urnmapper
66
COURT_SCHEDULE_CLIENT_URL=https://steccm64.ingress01.dev.nl.cjscp.org.uk/listing-query-api/query/api/rest/listing/hearings/allocated-and-unallocated
77
CJSCPPUID=d7c91866-646a-462c-9203-46678e8cddef

src/main/java/uk/gov/hmcts/cp/repositories/CourtScheduleClientImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,14 @@ private List<Hearing> getHearings(String caseId){
7979
try {
8080
//ignoreCertificates();
8181
HttpRequest request = HttpRequest.newBuilder()
82-
//.uri(new URI("https://steccm64.ingress01.dev.nl.cjscp.org.uk/listing-query-api/query/api/rest/listing/hearings/allocated-and-unallocated?caseId=f552dee6-f092-415b-839c-5e5b5f46635e"))
8382
.uri(new URI(buildUrl(caseId)))
8483
.GET()
8584
.header("Accept", "application/vnd.listing.search.hearings+json")
86-
//.header("CJSCPPUID", "d7c91866-646a-462c-9203-46678e8cddef")
8785
.header("CJSCPPUID", getCjscppuid())
8886
.build();
8987

90-
// Send the request
9188
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
9289

93-
// Check response status
9490
if (response.statusCode() != HttpStatus.OK.value()) {
9591
LOG.error("Failed to fetch hearing data. HTTP Status: {}", response.statusCode());
9692
return null;
@@ -107,7 +103,6 @@ private List<Hearing> getHearings(String caseId){
107103

108104
private String buildUrl(String caseId) {
109105
return UriComponentsBuilder
110-
//.fromUri(URI.create("https://steccm64.ingress01.dev.nl.cjscp.org.uk/listing-query-api/query/api/rest/listing/hearings/allocated-and-unallocated"))
111106
.fromUri(URI.create(getCourtScheduleClientUrl()))
112107
.queryParam("caseId", caseId)
113108
.toUriString();
@@ -160,5 +155,4 @@ private List<CourtSitting> getCourtSittings(JsonNode hearingNode, String judicia
160155
}
161156
return courtSittings;
162157
}
163-
164158
}

src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
import org.springframework.beans.factory.annotation.Value;
1111
import org.springframework.http.HttpEntity;
1212
import org.springframework.http.HttpHeaders;
13-
import org.springframework.http.MediaType;
13+
import org.springframework.http.HttpMethod;
1414
import org.springframework.http.ResponseEntity;
1515
import org.springframework.stereotype.Service;
1616
import org.springframework.web.client.RestTemplate;
1717
import org.springframework.web.util.UriComponentsBuilder;
1818

1919
import java.net.URI;
20-
import java.util.List;
20+
21+
import static uk.gov.hmcts.cp.utils.Utils.ignoreCertificates;
2122

2223
@Service
2324
@RequiredArgsConstructor
@@ -30,28 +31,27 @@ public class CaseUrnMapperService {
3031
private String caseMapperServiceUrl;
3132

3233
public String getCaseId(final String caseUrn) {
33-
return "f552dee6-f092-415b-839c-5e5b5f46635e";
34-
// try {
35-
// ignoreCertificates();
36-
// ResponseEntity<String> responseEntity = restTemplate.exchange(
37-
// getCaseIdUrl(caseUrn),
38-
// HttpMethod.GET,
39-
// getRequestEntity(),
40-
// String.class
41-
// );
42-
// return getCaseId(responseEntity);
43-
// } catch (Exception e) {
44-
// LOG.atError().log("Error while getting case id from case urn", e);
45-
// }
46-
// return null;
34+
try {
35+
ignoreCertificates();
36+
ResponseEntity<String> responseEntity = restTemplate.exchange(
37+
getCaseIdUrl(caseUrn),
38+
HttpMethod.GET,
39+
getRequestEntity(),
40+
String.class
41+
);
42+
return getCaseId(responseEntity);
43+
} catch (Exception e) {
44+
LOG.atError().log("Error while getting case id from case urn", e);
45+
}
46+
return null;
4747
}
4848

4949
public String getCaseMapperServiceUrl() {
5050
return this.caseMapperServiceUrl;
5151
}
5252

5353
public String getCaseId(ResponseEntity<String> responseEntity) throws JsonProcessingException {
54-
if (responseEntity != null || !responseEntity.hasBody()) {
54+
if (responseEntity != null || responseEntity.hasBody()) {
5555
JsonNode root = objectMapper.readTree(responseEntity.getBody());
5656
return root.get("caseId").asText();
5757
}
@@ -69,7 +69,7 @@ private String getCaseIdUrl(String caseUrn) {
6969

7070
private HttpEntity<String> getRequestEntity() {
7171
HttpHeaders headers = new HttpHeaders();
72-
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
72+
headers.set("Accept", "application/json, application/*+json");
7373
return new HttpEntity<>(headers);
7474
}
7575
}

src/main/resources/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spring:
3232

3333
service:
3434
case-mapper-service:
35-
url: ${CASE_MAPPER_SERVICE_URL:https://devcp01.ingress01.dev.nl.cjscp.org.uk/caseurnmapper}
35+
url: ${CASE_MAPPER_SERVICE_URL:https://devcp01.ingress01.dev.nl.cjscp.org.uk/urnmapper}
3636

3737
court-schedule-client:
3838
url: ${COURT_SCHEDULE_CLIENT_URL:https://steccm64.ingress01.dev.nl.cjscp.org.uk/listing-query-api/query/api/rest/listing/hearings/allocated-and-unallocated}

src/test/java/uk/gov/hmcts/cp/services/CaseUrnMapperServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String getCaseMapperServiceUrl() {
3737
};
3838
}
3939

40-
//@Test uncoment when casemapperserivce method is uncommented
40+
@Test
4141
void shouldReturnCaseIdWhenResponseIsSuccessful() {
4242
String caseUrn = "test-case-urn";
4343
String caseId = "7a2e94c4-38af-43dd-906b-40d632d159b0";
@@ -69,7 +69,7 @@ void shouldReturnCaseIdWhenResponseIsSuccessful() {
6969
assertEquals(caseId, result);
7070
}
7171

72-
//@Test uncoment when casemapperserivce method is uncommented
72+
@Test
7373
void shouldReturnNullWhenExceptionOccurs() {
7474
String caseUrn = "test-case-urn";
7575

0 commit comments

Comments
 (0)