Skip to content

Commit e7c0c1b

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

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

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: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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.HttpMethod;
1314
import org.springframework.http.MediaType;
1415
import org.springframework.http.ResponseEntity;
1516
import org.springframework.stereotype.Service;
@@ -19,6 +20,8 @@
1920
import java.net.URI;
2021
import java.util.List;
2122

23+
import static uk.gov.hmcts.cp.utils.Utils.ignoreCertificates;
24+
2225
@Service
2326
@RequiredArgsConstructor
2427
public class CaseUrnMapperService {
@@ -30,20 +33,19 @@ public class CaseUrnMapperService {
3033
private String caseMapperServiceUrl;
3134

3235
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;
36+
try {
37+
ignoreCertificates();
38+
ResponseEntity<String> responseEntity = restTemplate.exchange(
39+
getCaseIdUrl(caseUrn),
40+
HttpMethod.GET,
41+
getRequestEntity(),
42+
String.class
43+
);
44+
return getCaseId(responseEntity);
45+
} catch (Exception e) {
46+
LOG.atError().log("Error while getting case id from case urn", e);
47+
}
48+
return null;
4749
}
4850

4951
public String getCaseMapperServiceUrl() {
@@ -60,16 +62,18 @@ public String getCaseId(ResponseEntity<String> responseEntity) throws JsonProces
6062

6163
private String getCaseIdUrl(String caseUrn) {
6264
LOG.atDebug().log("Fetching case id for case urn: {}", caseUrn);
63-
return UriComponentsBuilder
64-
.fromUri(URI.create(getCaseMapperServiceUrl()))
65-
.pathSegment(caseUrn)
66-
.buildAndExpand(caseUrn)
67-
.toUriString();
65+
return URI.create(getCaseMapperServiceUrl() + "/" + caseUrn).toString();
66+
// return UriComponentsBuilder
67+
// .fromUri(URI.create(getCaseMapperServiceUrl()))
68+
// .pathSegment(caseUrn)
69+
// .buildAndExpand(caseUrn)
70+
// .toUriString();
6871
}
6972

7073
private HttpEntity<String> getRequestEntity() {
7174
HttpHeaders headers = new HttpHeaders();
72-
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
75+
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
76+
//headers.setAccept(List.of(MediaType.APPLICATION_JSON));
7377
return new HttpEntity<>(headers);
7478
}
7579
}

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)