Skip to content

Commit 3df5ded

Browse files
committed
refactor the case mapper urn service
1 parent 55d9a19 commit 3df5ded

File tree

6 files changed

+54
-125
lines changed

6 files changed

+54
-125
lines changed

src/integrationTest/java/uk/gov/hmcts/cp/config/TestConfig.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,34 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import org.junit.jupiter.api.BeforeEach;
65
import org.junit.jupiter.api.Test;
76
import org.junit.jupiter.api.extension.ExtendWith;
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;
109
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1211
import org.springframework.boot.test.context.SpringBootTest;
13-
import org.springframework.context.annotation.Import;
1412
import org.springframework.http.MediaType;
1513
import org.springframework.test.context.junit.jupiter.SpringExtension;
1614
import org.springframework.test.web.servlet.MockMvc;
17-
import uk.gov.hmcts.cp.config.TestConfig;
18-
import uk.gov.hmcts.cp.services.InMemoryCaseUrnMapper;
1915

2016
import java.util.UUID;
2117

22-
import static org.junit.jupiter.api.Assertions.*;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2321
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2422
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2523

2624
@ExtendWith(SpringExtension.class)
2725
@SpringBootTest
2826
@AutoConfigureMockMvc
29-
@Import(TestConfig.class)
3027
class CourtScheduleControllerIT {
3128
private static final Logger log = LoggerFactory.getLogger(CourtScheduleControllerIT.class);
3229

3330
@Autowired
3431
private MockMvc mockMvc;
3532

36-
@Autowired
37-
private InMemoryCaseUrnMapper inMemoryCaseUrnMapper;
38-
39-
@BeforeEach
40-
void setUp() {
41-
inMemoryCaseUrnMapper.clearAllMappings();
42-
inMemoryCaseUrnMapper.saveCaseUrnMapping("test-case-urn", "test-case-id");
43-
}
44-
4533
@Test
4634
void shouldReturnOkWhenValidUrnIsProvided() throws Exception {
4735
String caseUrn = "test-case-urn";
Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,68 @@
11
package uk.gov.hmcts.cp.services;
22

33
import lombok.RequiredArgsConstructor;
4-
import org.apache.logging.log4j.util.Strings;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76
import org.springframework.beans.factory.annotation.Value;
87
import org.springframework.http.HttpEntity;
98
import org.springframework.http.HttpHeaders;
10-
import org.springframework.http.HttpMethod;
119
import org.springframework.http.MediaType;
12-
import org.springframework.http.ResponseEntity;
1310
import org.springframework.stereotype.Service;
1411
import org.springframework.web.client.RestTemplate;
1512
import org.springframework.web.util.UriComponentsBuilder;
1613

1714
import java.net.URI;
1815
import java.util.List;
16+
import java.util.Map;
17+
import java.util.UUID;
18+
import java.util.concurrent.ConcurrentHashMap;
1919

20+
@Service
21+
@RequiredArgsConstructor
22+
public class CaseUrnMapperService {
2023

21-
public interface CaseUrnMapperService {
22-
public String getCaseId(final String caseUrn) ;
24+
private static final Logger LOG = LoggerFactory.getLogger(CaseUrnMapperService.class);
25+
26+
private final RestTemplate restTemplate;
27+
28+
@Value("${service.case-mapper-service.url}")
29+
private String caseMapperServiceUrl;
30+
31+
private static final String CASEURN_ID = "caseurn/{caseurn}";
32+
33+
private final Map<String, String> caseUrnToCaseIdMap = new ConcurrentHashMap<>();
34+
35+
36+
37+
public String getCaseId(final String caseUrn) {
38+
return UUID.randomUUID().toString();
39+
// This below code is commented out as it is will be used when the case mapper service is available.
40+
41+
/* try {
42+
ResponseEntity<String> responseEntity = restTemplate.exchange(
43+
getCaseIdUrl(caseUrn),
44+
HttpMethod.GET,
45+
getRequestEntity(),
46+
String.class
47+
);
48+
return responseEntity.hasBody() ? responseEntity.getBody(): Strings.EMPTY;
49+
} catch (Exception e) {
50+
LOG.atError().log("Error while getting case id from case urn", e);
51+
}
52+
return null;*/
53+
}
54+
55+
private String getCaseIdUrl(String caseUrn) {
56+
return UriComponentsBuilder
57+
.fromUri(URI.create(caseMapperServiceUrl))
58+
.pathSegment(caseUrn)
59+
.buildAndExpand(caseUrn)
60+
.toUriString();
61+
}
62+
63+
private HttpEntity<String> getRequestEntity() {
64+
HttpHeaders headers = new HttpHeaders();
65+
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
66+
return new HttpEntity<>(headers);
67+
}
2368
}

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import uk.gov.hmcts.cp.openapi.model.Hearing;
1616
import uk.gov.hmcts.cp.repositories.InMemoryCourtScheduleRepositoryImpl;
1717
import uk.gov.hmcts.cp.services.CaseUrnMapperService;
18-
import uk.gov.hmcts.cp.services.CaseUrnMapperServiceImpl;
1918
import uk.gov.hmcts.cp.services.CourtScheduleService;
20-
import uk.gov.hmcts.cp.services.InMemoryCaseUrnMapper;
2119

2220
import java.util.UUID;
2321

@@ -36,7 +34,7 @@ class CourtScheduleControllerTest {
3634
@BeforeEach
3735
void setUp() {
3836
CourtScheduleService courtScheduleService = new CourtScheduleService(new InMemoryCourtScheduleRepositoryImpl());
39-
CaseUrnMapperService caseUrnMapperService = new InMemoryCaseUrnMapper();
37+
CaseUrnMapperService caseUrnMapperService = new CaseUrnMapperService(new RestTemplate());
4038
courtScheduleController = new CourtScheduleController(courtScheduleService, caseUrnMapperService);
4139
}
4240

0 commit comments

Comments
 (0)