From 3d91dc403c9d19e0df0d89fc93b2dfc92c2e261b Mon Sep 17 00:00:00 2001 From: Sabah Irfan Date: Wed, 14 Feb 2024 10:24:30 +0000 Subject: [PATCH 1/2] Optimise code --- .../properties/LegacyGatewayProperties.java | 15 +++++++++ .../opal/service/PartyServiceInterface.java | 2 +- .../legacy/LegacyAccountTransferService.java | 9 +++--- .../legacy/LegacyBusinessUnitService.java | 9 +++--- ...LegacyCommittalWarrantProgressService.java | 11 +++---- .../service/legacy/LegacyCourtService.java | 9 +++--- .../legacy/LegacyDebtorDetailService.java | 9 +++--- .../legacy/LegacyDefendantAccountService.java | 32 +++++++++---------- .../legacy/LegacyDocumentInstanceService.java | 9 +++--- .../service/legacy/LegacyDocumentService.java | 8 ++--- .../legacy/LegacyEnforcementService.java | 8 ++--- .../service/legacy/LegacyEnforcerService.java | 8 ++--- .../legacy/LegacyLocalJusticeAreaService.java | 9 +++--- .../legacy/LegacyMisDebtorService.java | 9 +++--- .../service/legacy/LegacyNoteService.java | 9 +++--- .../service/legacy/LegacyPartyService.java | 12 +++---- .../legacy/LegacyPaymentInService.java | 8 ++--- .../legacy/LegacyPaymentTermsService.java | 9 +++--- .../service/legacy/LegacyPrisonService.java | 8 ++--- .../opal/service/legacy/LegacyService.java | 25 ++++++++------- .../service/legacy/LegacyTillService.java | 8 ++--- .../service/opal/DefendantAccountService.java | 7 ++-- .../hmcts/opal/service/opal/PartyService.java | 2 +- .../proxy/EnforcementServiceProxy.java | 2 +- .../service/proxy/EnforcerServiceProxy.java | 2 +- .../proxy/LocalJusticeAreaServiceProxy.java | 2 +- .../service/proxy/MisDebtorServiceProxy.java | 2 +- .../opal/service/proxy/PartyServiceProxy.java | 2 +- .../service/proxy/PaymentInServiceProxy.java | 2 +- .../proxy/PaymentTermsServiceProxy.java | 2 +- .../service/proxy/PrisonServiceProxy.java | 2 +- .../opal/service/proxy/TillServiceProxy.java | 2 +- .../service/legacy/LegacyServiceTest.java | 2 +- .../opal/service/legacy/LegacyTestsBase.java | 4 +++ 34 files changed, 128 insertions(+), 131 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/opal/config/properties/LegacyGatewayProperties.java diff --git a/src/main/java/uk/gov/hmcts/opal/config/properties/LegacyGatewayProperties.java b/src/main/java/uk/gov/hmcts/opal/config/properties/LegacyGatewayProperties.java new file mode 100644 index 000000000..514c24132 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/config/properties/LegacyGatewayProperties.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.opal.config.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConfigurationProperties(prefix = "legacy-gateway") +public class LegacyGatewayProperties { + + private String url; + private String username; + private String password; +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/PartyServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/PartyServiceInterface.java index b1924f485..2e5b10b81 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/PartyServiceInterface.java +++ b/src/main/java/uk/gov/hmcts/opal/service/PartyServiceInterface.java @@ -1,7 +1,7 @@ package uk.gov.hmcts.opal.service; -import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.PartyDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyAccountTransferService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyAccountTransferService.java index a1d2ba974..75bffa784 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyAccountTransferService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyAccountTransferService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.AccountTransferSearchDto; import uk.gov.hmcts.opal.entity.AccountTransferEntity; import uk.gov.hmcts.opal.service.AccountTransferServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyAccountTransferService") public class LegacyAccountTransferService extends LegacyService implements AccountTransferServiceInterface { - @Autowired - protected LegacyAccountTransferService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyAccountTransferService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitService.java index e4ddadbd9..cd81a877c 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; import uk.gov.hmcts.opal.service.BusinessUnitServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyBusinessUnitService") public class LegacyBusinessUnitService extends LegacyService implements BusinessUnitServiceInterface { - @Autowired - protected LegacyBusinessUnitService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyBusinessUnitService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCommittalWarrantProgressService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCommittalWarrantProgressService.java index fa56b6bdf..ac385a156 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCommittalWarrantProgressService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCommittalWarrantProgressService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.CommittalWarrantProgressSearchDto; import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity; import uk.gov.hmcts.opal.service.CommittalWarrantProgressServiceInterface; @@ -17,10 +16,10 @@ public class LegacyCommittalWarrantProgressService extends LegacyService implements CommittalWarrantProgressServiceInterface { - @Autowired - protected LegacyCommittalWarrantProgressService(@Value("${legacy-gateway.url}") String gatewayUrl, - RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyCommittalWarrantProgressService(LegacyGatewayProperties legacyGatewayProperties, + RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCourtService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCourtService.java index 352b7243b..d8976206b 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCourtService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyCourtService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.CourtSearchDto; import uk.gov.hmcts.opal.entity.CourtEntity; import uk.gov.hmcts.opal.service.CourtServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyCourtService") public class LegacyCourtService extends LegacyService implements CourtServiceInterface { - @Autowired - protected LegacyCourtService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyCourtService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDebtorDetailService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDebtorDetailService.java index b051eb468..5f5782f15 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDebtorDetailService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDebtorDetailService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.DebtorDetailSearchDto; import uk.gov.hmcts.opal.entity.DebtorDetailEntity; import uk.gov.hmcts.opal.service.DebtorDetailServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyDebtorDetailService") public class LegacyDebtorDetailService extends LegacyService implements DebtorDetailServiceInterface { - @Autowired - protected LegacyDebtorDetailService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyDebtorDetailService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDefendantAccountService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDefendantAccountService.java index 46a297286..bf169d259 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDefendantAccountService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDefendantAccountService.java @@ -2,19 +2,18 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.AccountDetailsDto; import uk.gov.hmcts.opal.dto.AccountEnquiryDto; -import uk.gov.hmcts.opal.dto.search.AccountSearchDto; -import uk.gov.hmcts.opal.dto.search.AccountSearchResultsDto; +import uk.gov.hmcts.opal.dto.legacy.DefendantAccountSearchCriteria; +import uk.gov.hmcts.opal.dto.legacy.DefendantAccountsSearchResults; import uk.gov.hmcts.opal.dto.legacy.LegacyAccountDetailsRequestDto; import uk.gov.hmcts.opal.dto.legacy.LegacyAccountDetailsResponseDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchResultsDto; import uk.gov.hmcts.opal.entity.DefendantAccountEntity; -import uk.gov.hmcts.opal.dto.legacy.DefendantAccountSearchCriteria; -import uk.gov.hmcts.opal.dto.legacy.DefendantAccountsSearchResults; import uk.gov.hmcts.opal.service.DefendantAccountServiceInterface; import java.util.Collections; @@ -29,12 +28,11 @@ public class LegacyDefendantAccountService extends LegacyService implements Defe public static final String GET_DEFENDANT_ACCOUNT = "getDefendantAccount"; public static final String GET_ACCOUNT_DETAILS = "getAccountDetails"; - @Autowired - protected LegacyDefendantAccountService(@Value("${legacy-gateway.url}") String gatewayUrl, - RestClient legacyRestClient) { - super(gatewayUrl, legacyRestClient); + public LegacyDefendantAccountService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } + @Override public Logger getLog() { return log; @@ -42,13 +40,13 @@ public Logger getLog() { @Override public DefendantAccountEntity getDefendantAccount(AccountEnquiryDto request) { - log.info("Get defendant account for {} from {}", request.toJson(), gatewayUrl); + log.info("Get defendant account for {} from {}", request.toJson(), legacyGateway.getUrl()); return postToGateway(GET_DEFENDANT_ACCOUNT, DefendantAccountEntity.class, request); } @Override public DefendantAccountEntity putDefendantAccount(DefendantAccountEntity defendantAccountEntity) { - log.info("Sending defendantAccount to {}", gatewayUrl); + log.info("Sending defendantAccount to {}", legacyGateway.getUrl()); return postToGateway(PUT_DEFENDANT_ACCOUNT, DefendantAccountEntity.class, defendantAccountEntity); } @@ -60,7 +58,7 @@ public List getDefendantAccountsByBusinessUnit(Short bus @Override public AccountSearchResultsDto searchDefendantAccounts(AccountSearchDto accountSearchDto) { DefendantAccountSearchCriteria criteria = DefendantAccountSearchCriteria.fromAccountSearchDto(accountSearchDto); - log.info(":searchDefendantAccounts: criteria: {} via gateway {}", criteria.toJson(), gatewayUrl); + log.info(":searchDefendantAccounts: criteria: {} via gateway {}", criteria.toJson(), legacyGateway.getUrl()); return postToGateway(SEARCH_DEFENDANT_ACCOUNTS, DefendantAccountsSearchResults.class, criteria) .toAccountSearchResultsDto(); } @@ -73,9 +71,11 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc .defendantAccountId(defendantAccountId) .build(); - LegacyAccountDetailsResponseDto response = postToGateway(GET_ACCOUNT_DETAILS, - LegacyAccountDetailsResponseDto.class, - request); + LegacyAccountDetailsResponseDto response = postToGateway( + GET_ACCOUNT_DETAILS, + LegacyAccountDetailsResponseDto.class, + request + ); return LegacyAccountDetailsResponseDto.toAccountDetailsDto(response); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentInstanceService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentInstanceService.java index a35b6c511..86fb5e249 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentInstanceService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentInstanceService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.DocumentInstanceSearchDto; import uk.gov.hmcts.opal.entity.DocumentInstanceEntity; import uk.gov.hmcts.opal.service.DocumentInstanceServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyDocumentInstanceService") public class LegacyDocumentInstanceService extends LegacyService implements DocumentInstanceServiceInterface { - @Autowired - protected LegacyDocumentInstanceService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyDocumentInstanceService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java index 6f1c102fb..94349b326 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyDocumentService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.DocumentSearchDto; import uk.gov.hmcts.opal.entity.DocumentEntity; import uk.gov.hmcts.opal.service.DocumentServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyDocumentService") public class LegacyDocumentService extends LegacyService implements DocumentServiceInterface { - @Autowired - protected LegacyDocumentService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyDocumentService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcementService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcementService.java index b200a4e03..4c099724a 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcementService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcementService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; import uk.gov.hmcts.opal.entity.EnforcementEntity; import uk.gov.hmcts.opal.service.EnforcementServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyEnforcementService") public class LegacyEnforcementService extends LegacyService implements EnforcementServiceInterface { - @Autowired - protected LegacyEnforcementService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyEnforcementService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcerService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcerService.java index 3b20d1a43..adc0241e9 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcerService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyEnforcerService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; import uk.gov.hmcts.opal.entity.EnforcerEntity; import uk.gov.hmcts.opal.service.EnforcerServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyEnforcerService") public class LegacyEnforcerService extends LegacyService implements EnforcerServiceInterface { - @Autowired - protected LegacyEnforcerService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyEnforcerService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java index 158d1dac0..bfaf02aeb 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyLocalJusticeAreaService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; import uk.gov.hmcts.opal.service.LocalJusticeAreaServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyLocalJusticeAreaService") public class LegacyLocalJusticeAreaService extends LegacyService implements LocalJusticeAreaServiceInterface { - @Autowired - protected LegacyLocalJusticeAreaService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyLocalJusticeAreaService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyMisDebtorService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyMisDebtorService.java index 13548d73d..85b91746c 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyMisDebtorService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyMisDebtorService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; import uk.gov.hmcts.opal.entity.MisDebtorEntity; import uk.gov.hmcts.opal.service.MisDebtorServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyMisDebtorService") public class LegacyMisDebtorService extends LegacyService implements MisDebtorServiceInterface { - @Autowired - protected LegacyMisDebtorService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyMisDebtorService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyNoteService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyNoteService.java index a8114f29f..22b9b6608 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyNoteService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyNoteService.java @@ -2,13 +2,13 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.NoteDto; -import uk.gov.hmcts.opal.dto.search.NoteSearchDto; import uk.gov.hmcts.opal.dto.legacy.LegacySaveNoteRequestDto; import uk.gov.hmcts.opal.dto.legacy.LegacySaveNoteResponseDto; +import uk.gov.hmcts.opal.dto.search.NoteSearchDto; import uk.gov.hmcts.opal.service.NoteServiceInterface; import java.util.List; @@ -19,10 +19,11 @@ public class LegacyNoteService extends LegacyService implements NoteServiceInter public static final String POST_ACCOUNT_NOTES = "postAccountNotes"; - protected LegacyNoteService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + protected LegacyNoteService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } + @Override protected Logger getLog() { return log; diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPartyService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPartyService.java index c7ede4ba3..763a6724f 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPartyService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPartyService.java @@ -2,12 +2,11 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; -import uk.gov.hmcts.opal.dto.search.AccountSearchDto; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.PartyDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; @@ -24,9 +23,8 @@ public class LegacyPartyService extends LegacyService implements PartyServiceInt public static final String GET_PARTY = "getParty"; public static final String POST_PARTY = "postParty"; - @Autowired - protected LegacyPartyService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyPartyService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override @@ -42,7 +40,7 @@ public PartyDto getParty(long partyId) { @Override public PartyDto saveParty(PartyDto partyDto) { - log.info("Sending party to {}", gatewayUrl); + log.info("Sending party to {}", legacyGateway.getUrl()); return postToGateway(POST_PARTY, PartyDto.class, partyDto); } diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentInService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentInService.java index 9ea216d56..cf9364be3 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentInService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentInService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; import uk.gov.hmcts.opal.entity.PaymentInEntity; import uk.gov.hmcts.opal.service.PaymentInServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyPaymentInService") public class LegacyPaymentInService extends LegacyService implements PaymentInServiceInterface { - @Autowired - protected LegacyPaymentInService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyPaymentInService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentTermsService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentTermsService.java index 5d769ffe2..b0b07d667 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentTermsService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPaymentTermsService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; import uk.gov.hmcts.opal.entity.PaymentTermsEntity; import uk.gov.hmcts.opal.service.PaymentTermsServiceInterface; @@ -16,9 +15,9 @@ @Slf4j(topic = "LegacyPaymentTermsService") public class LegacyPaymentTermsService extends LegacyService implements PaymentTermsServiceInterface { - @Autowired - protected LegacyPaymentTermsService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + + public LegacyPaymentTermsService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPrisonService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPrisonService.java index 97e8f42cf..9b66189a6 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPrisonService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyPrisonService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; import uk.gov.hmcts.opal.entity.PrisonEntity; import uk.gov.hmcts.opal.service.PrisonServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyPrisonService") public class LegacyPrisonService extends LegacyService implements PrisonServiceInterface { - @Autowired - protected LegacyPrisonService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyPrisonService(LegacyGatewayProperties legacyGateway, RestClient restClient) { + super(legacyGateway, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyService.java index a7064d34c..cef1864ea 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyService.java @@ -3,27 +3,27 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.helpers.MessageFormatter; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; import org.springframework.web.util.UriComponentsBuilder; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.ToJsonString; import java.util.Map; +@Component +@RequiredArgsConstructor public abstract class LegacyService { public static final String ACTION_TYPE = "actionType"; - final String gatewayUrl; - final RestClient restClient; - - protected LegacyService(String gatewayUrl, RestClient restTemplate) { - this.gatewayUrl = gatewayUrl; - this.restClient = restTemplate; - } + protected final LegacyGatewayProperties legacyGateway; + protected final RestClient restClient; protected abstract Logger getLog(); @@ -60,14 +60,14 @@ public T extractResponse(ResponseEntity responseEntity, Class clz } public T getFromGateway(String actionType, Class responseType) { - getLog().info("getFromGateway: GET from Gateway: {}", gatewayUrl); + getLog().info("getFromGateway: GET from Gateway: {}", legacyGateway.getUrl()); // Create a UriComponentsBuilder and add parameters UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("") .queryParam(ACTION_TYPE, actionType); ResponseEntity responseEntity = restClient.get() - .uri(gatewayUrl + builder.toUriString()) + .uri(legacyGateway.getUrl() + builder.toUriString()) .retrieve() .toEntity(String.class); @@ -78,21 +78,22 @@ public T getFromGateway(String actionType, Class responseType) { public T postParamsToGateway(String actionType, Class responseType, Map requestParams) { try { return postToGateway(actionType, responseType, - ToJsonString.getObjectMapper().writeValueAsString(requestParams)); + ToJsonString.getObjectMapper().writeValueAsString(requestParams) + ); } catch (JsonProcessingException jpe) { throw new RuntimeException(jpe); } } public T postToGateway(String actionType, Class responseType, Object request) { - getLog().info("postToGateway: POST to Gateway: {}", gatewayUrl); + getLog().info("postToGateway: POST to Gateway: {}", legacyGateway.getUrl()); // Create a UriComponentsBuilder and add parameters UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("") .queryParam(ACTION_TYPE, actionType); ResponseEntity responseEntity = restClient.post() - .uri(gatewayUrl + builder.toUriString()) + .uri(legacyGateway.getUrl() + builder.toUriString()) .contentType(MediaType.APPLICATION_JSON) .body(request) .retrieve() diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTillService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTillService.java index bc8435109..1fd894f8f 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTillService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTillService.java @@ -2,10 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import uk.gov.hmcts.opal.dto.search.TillSearchDto; import uk.gov.hmcts.opal.entity.TillEntity; import uk.gov.hmcts.opal.service.TillServiceInterface; @@ -16,9 +15,8 @@ @Slf4j(topic = "LegacyTillService") public class LegacyTillService extends LegacyService implements TillServiceInterface { - @Autowired - protected LegacyTillService(@Value("${legacy-gateway.url}") String gatewayUrl, RestClient restClient) { - super(gatewayUrl, restClient); + public LegacyTillService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); } @Override diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/DefendantAccountService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/DefendantAccountService.java index fa253d098..1c0b987ae 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/DefendantAccountService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/DefendantAccountService.java @@ -9,12 +9,14 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.AccountDetailsDto; import uk.gov.hmcts.opal.dto.AccountEnquiryDto; +import uk.gov.hmcts.opal.dto.AccountSummaryDto; import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.AccountSearchResultsDto; -import uk.gov.hmcts.opal.dto.AccountSummaryDto; import uk.gov.hmcts.opal.entity.DefendantAccountEntity; import uk.gov.hmcts.opal.entity.DefendantAccountPartiesEntity; import uk.gov.hmcts.opal.entity.DefendantAccountSummary; +import uk.gov.hmcts.opal.entity.DefendantAccountSummary.PartyDefendantAccountSummary; +import uk.gov.hmcts.opal.entity.DefendantAccountSummary.PartyLink; import uk.gov.hmcts.opal.entity.EnforcerEntity; import uk.gov.hmcts.opal.entity.NoteEntity; import uk.gov.hmcts.opal.entity.PartyEntity; @@ -26,9 +28,6 @@ import uk.gov.hmcts.opal.repository.NoteRepository; import uk.gov.hmcts.opal.repository.PaymentTermsRepository; import uk.gov.hmcts.opal.repository.jpa.DefendantAccountSpecs; - -import uk.gov.hmcts.opal.entity.DefendantAccountSummary.PartyLink; -import uk.gov.hmcts.opal.entity.DefendantAccountSummary.PartyDefendantAccountSummary; import uk.gov.hmcts.opal.service.DefendantAccountServiceInterface; import java.io.InputStream; diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java index dd3589ae0..f269a6383 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/PartyService.java @@ -5,8 +5,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.PartyDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxy.java index 810adb329..3230a2055 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; import uk.gov.hmcts.opal.entity.EnforcementEntity; -import uk.gov.hmcts.opal.service.EnforcementServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.EnforcementServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyEnforcementService; import uk.gov.hmcts.opal.service.opal.EnforcementService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxy.java index c0972a0f8..9598bb0dc 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; import uk.gov.hmcts.opal.entity.EnforcerEntity; -import uk.gov.hmcts.opal.service.EnforcerServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.EnforcerServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyEnforcerService; import uk.gov.hmcts.opal.service.opal.EnforcerService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java index c433433ce..d07bcaf29 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; -import uk.gov.hmcts.opal.service.LocalJusticeAreaServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.LocalJusticeAreaServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyLocalJusticeAreaService; import uk.gov.hmcts.opal.service.opal.LocalJusticeAreaService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxy.java index 1242085e8..0f21777f5 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; import uk.gov.hmcts.opal.entity.MisDebtorEntity; -import uk.gov.hmcts.opal.service.MisDebtorServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.MisDebtorServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyMisDebtorService; import uk.gov.hmcts.opal.service.opal.MisDebtorService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxy.java index 42a3a63d5..7473a187a 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxy.java @@ -3,8 +3,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; -import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.PartyDto; +import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxy.java index ef71de6a7..0cdd2ffae 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; import uk.gov.hmcts.opal.entity.PaymentInEntity; -import uk.gov.hmcts.opal.service.PaymentInServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PaymentInServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPaymentInService; import uk.gov.hmcts.opal.service.opal.PaymentInService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxy.java index 598045c28..702a1eb93 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; import uk.gov.hmcts.opal.entity.PaymentTermsEntity; -import uk.gov.hmcts.opal.service.PaymentTermsServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PaymentTermsServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPaymentTermsService; import uk.gov.hmcts.opal.service.opal.PaymentTermsService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxy.java index aa1163856..47e1f0d86 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; import uk.gov.hmcts.opal.entity.PrisonEntity; -import uk.gov.hmcts.opal.service.PrisonServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PrisonServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPrisonService; import uk.gov.hmcts.opal.service.opal.PrisonService; diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxy.java index ddce7768b..a1348e875 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxy.java +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxy.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.opal.dto.search.TillSearchDto; import uk.gov.hmcts.opal.entity.TillEntity; -import uk.gov.hmcts.opal.service.TillServiceInterface; import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.TillServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyTillService; import uk.gov.hmcts.opal.service.opal.TillService; diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyServiceTest.java index 65d9266e4..1fe3448d3 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyServiceTest.java @@ -35,7 +35,7 @@ class LegacyServiceTest extends LegacyTestsBase { @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); - legacy = spy(new LegacyService("Gateway", restClient) { + legacy = spy(new LegacyService(properties, restClient) { @Override protected Logger getLog() { return log; diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTestsBase.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTestsBase.java index 0e895ee33..98f6033aa 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTestsBase.java +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTestsBase.java @@ -3,6 +3,7 @@ import org.mockito.Mock; import org.springframework.http.MediaType; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -21,6 +22,9 @@ public abstract class LegacyTestsBase { @Mock RestClient restClient; + @Mock + LegacyGatewayProperties properties; + @Mock RequestHeadersUriSpec requestHeaderUriSpec; From 656a42582b62387a8a79c4bdca4775d5113059cc Mon Sep 17 00:00:00 2001 From: Sabah Irfan Date: Wed, 14 Feb 2024 11:12:48 +0000 Subject: [PATCH 2/2] Optimise code --- .../config/rest/RestClientConfiguration.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/opal/config/rest/RestClientConfiguration.java b/src/main/java/uk/gov/hmcts/opal/config/rest/RestClientConfiguration.java index ae0c841c7..82e6c1225 100644 --- a/src/main/java/uk/gov/hmcts/opal/config/rest/RestClientConfiguration.java +++ b/src/main/java/uk/gov/hmcts/opal/config/rest/RestClientConfiguration.java @@ -1,33 +1,34 @@ package uk.gov.hmcts.opal.config.rest; -import org.springframework.beans.factory.annotation.Value; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; import java.util.Base64; @Configuration +@RequiredArgsConstructor public class RestClientConfiguration { - @Value("${legacy-gateway.username}") - String legacyUsername; - - @Value("${legacy-gateway.password}") - String legacyPassword; + private final LegacyGatewayProperties properties; @Bean public RestClient restClient() { return RestClient.create(); } - @Bean RestClient legacyRestClient() { + @Bean + RestClient legacyRestClient() { return RestClient.builder() .defaultHeader( HttpHeaders.AUTHORIZATION, - encodeBasic(legacyUsername, - legacyPassword) + encodeBasic( + properties.getUsername(), + properties.getPassword() + ) ).build(); }