Skip to content

Commit 002ac65

Browse files
committed
refactor the case mapper urn service
1 parent 55d9a19 commit 002ac65

File tree

7 files changed

+85
-122
lines changed

7 files changed

+85
-122
lines changed

run.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Load env vars from .env if available
4+
if [ -f .env ]; then
5+
set -a
6+
source .env
7+
set +a
8+
fi
9+
10+
# Export Git metadata
11+
export GIT_COMMIT=$(git rev-parse HEAD)
12+
13+
if [ -n "$GIT_BRANCH" ]; then
14+
BRANCH_NAME="$GIT_BRANCH"
15+
else
16+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
17+
fi
18+
19+
export GIT_BRANCH="$BRANCH_NAME"
20+
21+
# Run provider verification with results published
22+
gradle pactVerificationTest \
23+
-Dpact.provider.version="$GIT_COMMIT" \
24+
-Dpact.verifier.publishResults=true \
25+
-Dpact.provider.branch="$GIT_BRANCH" \
26+
-DPACT_BROKER_TOKEN="$PACT_BROKER_TOKEN" \
27+
-DPACT_BROKER_HOST="$PACT_BROKER_URL"
28+
29+
# Tag provider in the broker
30+
pact-broker create-version-tag \
31+
--pacticipant "VPCourtScheduleProvider" \
32+
--version "$GIT_COMMIT" \
33+
--tag "$PACT_ENV" \
34+
--broker-base-url "$PACT_BROKER_URL" \
35+
--broker-token "$PACT_BROKER_TOKEN"

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: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.springframework.http.MediaType;
1515
import org.springframework.test.context.junit.jupiter.SpringExtension;
1616
import org.springframework.test.web.servlet.MockMvc;
17-
import uk.gov.hmcts.cp.config.TestConfig;
18-
import uk.gov.hmcts.cp.services.InMemoryCaseUrnMapper;
1917

2018
import java.util.UUID;
2119

@@ -26,22 +24,12 @@
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: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,67 @@
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+
40+
/* try {
41+
ResponseEntity<String> responseEntity = restTemplate.exchange(
42+
getCaseIdUrl(caseUrn),
43+
HttpMethod.GET,
44+
getRequestEntity(),
45+
String.class
46+
);
47+
return responseEntity.hasBody() ? responseEntity.getBody(): Strings.EMPTY;
48+
} catch (Exception e) {
49+
LOG.atError().log("Error while getting case id from case urn", e);
50+
}
51+
return null;*/
52+
}
53+
54+
private String getCaseIdUrl(String caseUrn) {
55+
return UriComponentsBuilder
56+
.fromUri(URI.create(caseMapperServiceUrl))
57+
.pathSegment(caseUrn)
58+
.buildAndExpand(caseUrn)
59+
.toUriString();
60+
}
61+
62+
private HttpEntity<String> getRequestEntity() {
63+
HttpHeaders headers = new HttpHeaders();
64+
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
65+
return new HttpEntity<>(headers);
66+
}
2367
}

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)