Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
@Value("${service.case-mapper-service.url}")
private String caseMapperServiceUrl;

@Value("${service.case-mapper-service.path}")
private String caseMapperServicePath;


public String getCaseId(final String caseUrn) {
try {
ignoreCertificates();
ResponseEntity<CaseMapperResponse> responseEntity = restTemplate.exchange(

Check warning on line 37 in src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

View workflow job for this annotation

GitHub Actions / pmd-analysis

Local variable 'responseEntity' could be declared final

A local variable assigned only once can be declared final. LocalVariableCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#localvariablecouldbefinal
getCaseIdUrl(caseUrn),
HttpMethod.GET,
getRequestEntity(),
Expand All @@ -39,7 +43,7 @@
LOG.atInfo().log(" CaseMapperResponse is : {} and body : {} caseurn : {} ", responseEntity.getStatusCode(), responseEntity.getBody(), caseUrn);

if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
CaseMapperResponse body = responseEntity.getBody();

Check warning on line 46 in src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

View workflow job for this annotation

GitHub Actions / pmd-analysis

Local variable 'body' could be declared final

A local variable assigned only once can be declared final. LocalVariableCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#localvariablecouldbefinal
return body.getCaseId();
}
} catch (Exception e) {
Expand All @@ -57,17 +61,23 @@
return this.caseMapperServiceUrl;
}

public String getCaseMapperServicePath() {
LOG.info(" caseMapperServicePath is : {}", this.caseMapperServicePath);
return this.caseMapperServicePath;
}

private String getCaseIdUrl(String caseUrn) {

Check warning on line 69 in src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

View workflow job for this annotation

GitHub Actions / pmd-analysis

Parameter 'caseUrn' is not assigned and could be declared final

Reports method and constructor parameters that can be made final because they are never reassigned within the body of the method. This rule ignores unused parameters so as not to overlap with the rule {% rule java/bestpractices/UnusedFormalParameter %}. It will also ignore the parameters of abstract methods. MethodArgumentCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#methodargumentcouldbefinal
LOG.atDebug().log("Fetching case id for case urn: {}", caseUrn);
return UriComponentsBuilder
.fromUriString(getCaseMapperServiceUrl())
.pathSegment(getCaseMapperServicePath())
.pathSegment(caseUrn)
.buildAndExpand(caseUrn)
.toUriString();
}

private HttpEntity<String> getRequestEntity() {
HttpHeaders headers = new HttpHeaders();

Check warning on line 80 in src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

View workflow job for this annotation

GitHub Actions / pmd-analysis

Local variable 'headers' could be declared final

A local variable assigned only once can be declared final. LocalVariableCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#localvariablecouldbefinal
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
return new HttpEntity<>(headers);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spring:
service:
case-mapper-service:
url: ${CASE_MAPPER_SERVICE_URL}
path: /urnmapper

court-schedule-client:
url: ${CP_BACKEND_URL}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.hmcts.cp.services;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
Expand All @@ -25,6 +24,7 @@ class CaseUrnMapperServiceTest {
private RestTemplate restTemplate;

private final String mockUrl = "http://mock-server/mapper";
private final String mockPath = "/urnmapper";

@BeforeEach
void setUp() {
Expand All @@ -34,6 +34,11 @@ void setUp() {
public String getCaseMapperServiceUrl() {
return mockUrl ;
}

@Override
public String getCaseMapperServicePath() {
return mockPath;
}
};
}

Expand Down
Loading