Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise code #198

Merged
merged 4 commits into from
Feb 14, 2024
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
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,26 +28,25 @@ 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;
}

@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);
}

Expand All @@ -60,7 +58,7 @@ public List<DefendantAccountEntity> 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();
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Loading