Skip to content

Commit

Permalink
Po 130 rework to align with capita (#116)
Browse files Browse the repository at this point in the history
* initial commit to expose test endpoint

* Remove non-required fields and switch search criteria to defendant_account_id

* Remove non-required fields and switch search criteria to defendant_account_id

* reintroduce controller test

* reintroduce controller test
  • Loading branch information
DeclanClarkeCGI authored Jan 9, 2024
1 parent 3de3939 commit 3cf15ab
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import uk.gov.hmcts.opal.dto.AccountEnquiryDto;
import uk.gov.hmcts.opal.dto.AccountSearchDto;
import uk.gov.hmcts.opal.dto.AccountSearchResultsDto;
import uk.gov.hmcts.opal.dto.AccountSummaryDto;
import uk.gov.hmcts.opal.entity.DefendantAccountEntity;
import uk.gov.hmcts.opal.service.DefendantAccountService;

Expand Down Expand Up @@ -79,12 +78,12 @@ public ResponseEntity<List<DefendantAccountEntity>> getDefendantAccountsByBusine
return ResponseEntity.ok(response);
}

@GetMapping(value = "/details", consumes = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/details")
@Operation(summary = "Get defendant account details by providing the defendant account summary")
public ResponseEntity<AccountDetailsDto> getAccountDetailsByAccountSummary(
@RequestBody AccountSummaryDto accountSummary) {
@RequestParam(name = "defendantAccountId") Long defendantAccountId) {

AccountDetailsDto response = defendantAccountService.getAccountDetailsByAccountSummary(accountSummary);
AccountDetailsDto response = defendantAccountService.getAccountDetailsByDefendantAccountId(defendantAccountId);

if (response == null) {
return ResponseEntity.noContent().build();
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/uk/gov/hmcts/opal/dto/AccountDetailsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public class AccountDetailsDto implements ToJsonString {
//defendant_accounts.prosecutor_case_reference
private String pcr;

//debtor_detail.document_language
private String documentLanguage;

//debtor_detail.hearing_language
private String hearingLanguage;

//payment_terms.installment_amount / payment_terms.installment_period
private String paymentDetails;

Expand All @@ -69,9 +63,6 @@ public class AccountDetailsDto implements ToJsonString {
//payment_terms.jail_days
private int daysInDefault;

//defendant_accounts.suspended_committal_date
private LocalDate sentencedDate;

//defendant_accounts.last_enforcement
private String lastEnforcement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import org.springframework.stereotype.Repository;
import uk.gov.hmcts.opal.entity.DefendantAccountPartiesEntity;

import java.math.BigDecimal;
import java.time.LocalDate;

@Repository
public interface DefendantAccountPartiesRepository extends JpaRepository<DefendantAccountPartiesEntity, Long> {

Expand All @@ -17,20 +14,6 @@ public interface DefendantAccountPartiesRepository extends JpaRepository<Defenda
JOIN dap.party p
JOIN dap.defendantAccount da
JOIN da.lastHearingCourtId c
WHERE da.accountNumber = :accountNumber
AND p.dateOfBirth = :dateOfBirth
AND p.surname = :surname
AND p.forenames = :forenames
AND p.title = :title
and p.addressLine1 = :addressLine1
AND da.accountBalance = :balance
AND da.lastHearingCourtId = :court""")
DefendantAccountPartiesEntity findByDefendantAccountDetailsCustomQuery(@Param("accountNumber") String accountNumber,
@Param("dateOfBirth") LocalDate dateOfBirth,
@Param("surname") String surname,
@Param("forenames") String forenames,
@Param("title") String title,
@Param("addressLine1") String addressLine1,
@Param("balance") BigDecimal balance,
@Param("court") String court);
WHERE da.defendantAccountId = :defendantAccountId""")
DefendantAccountPartiesEntity findByDefendantAccountId(@Param("defendantAccountId") Long defendantAccountId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import uk.gov.hmcts.opal.dto.AccountSearchDto;
import uk.gov.hmcts.opal.dto.AccountSearchResultsDto;
import uk.gov.hmcts.opal.dto.AccountSummaryDto;
import uk.gov.hmcts.opal.entity.DebtorDetailEntity;
import uk.gov.hmcts.opal.entity.DefendantAccountEntity;
import uk.gov.hmcts.opal.entity.DefendantAccountPartiesEntity;
import uk.gov.hmcts.opal.entity.DefendantAccountSummary;
Expand All @@ -24,7 +23,6 @@
import uk.gov.hmcts.opal.repository.EnforcersRepository;
import uk.gov.hmcts.opal.repository.NoteRepository;
import uk.gov.hmcts.opal.repository.PaymentTermsRepository;
import uk.gov.hmcts.opal.util.NamesUtil;

import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -92,10 +90,10 @@ public AccountSearchResultsDto searchDefendantAccounts(AccountSearchDto accountS
.build();
}

public AccountDetailsDto getAccountDetailsByAccountSummary(AccountSummaryDto accountSummary) {
public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAccountId) {


if ("test".equalsIgnoreCase(accountSummary.getCourt())) {
if (defendantAccountId.equals(0L)) {


try (InputStream in = Thread.currentThread().getContextClassLoader()
Expand All @@ -104,36 +102,26 @@ public AccountDetailsDto getAccountDetailsByAccountSummary(AccountSummaryDto acc
ObjectMapper mapper = newObjectMapper();
AccountDetailsDto dto = mapper.readValue(in, AccountDetailsDto.class);
log.info(
":getAccountDetailsByAccountSummary: temporary Hack for Front End testing. Read JSON file: \n{}",
"""
:getAccountDetailsByDefendantAccountId:
" temporary Hack for Front End testing. Read JSON file: \n{}
""",
dto.toPrettyJsonString());
return dto;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

//split name into parts for db query
final String[] nameParts = NamesUtil.splitFullName(accountSummary.getName());

//query db for defendantAccountPartiesEntity
DefendantAccountPartiesEntity defendantAccountPartiesEntity = defendantAccountPartiesRepository
.findByDefendantAccountDetailsCustomQuery(
accountSummary.getAccountNo(),
accountSummary.getDateOfBirth(),
nameParts[0],
nameParts[1],
nameParts[2],
accountSummary.getAddressLine1(),
accountSummary.getBalance(),
accountSummary.getCourt());
.findByDefendantAccountId(defendantAccountId);

//Extract unique defendantAccount and party entities
final DefendantAccountEntity defendantAccountEntity = defendantAccountPartiesEntity.getDefendantAccount();
final PartyEntity partyEntity = defendantAccountPartiesEntity.getParty();

//query DB for debtorDetailsEntity
DebtorDetailEntity debtorDetailEntity = debtorDetailRepository.findByParty_PartyId(partyEntity);

//query DB for PaymentTermsEntity
PaymentTermsEntity paymentTermsEntity = paymentTermsRepository.findByDefendantAccount_DefendantAccountId(
defendantAccountEntity);
Expand Down Expand Up @@ -174,13 +162,10 @@ public AccountDetailsDto getAccountDetailsByAccountSummary(AccountSummaryDto acc
.lastMovement(defendantAccountEntity.getLastMovementDate())
.commentField(comments)
.pcr(defendantAccountEntity.getProsecutorCaseReference())
.documentLanguage(debtorDetailEntity.getDocumentLanguage())
.hearingLanguage(debtorDetailEntity.getHearingLanguage())
.paymentDetails(paymentDetails)
.lumpSum(paymentTermsEntity.getInstalmentLumpSum())
.commencing(paymentTermsEntity.getEffectiveDate())
.daysInDefault(paymentTermsEntity.getJailDays())
.sentencedDate(defendantAccountEntity.getImposedHearingDate())
.lastEnforcement(defendantAccountEntity.getLastEnforcement())
.override(defendantAccountEntity.getEnforcementOverrideResultId())
.enforcer(enforcersEntity.getEnforcerCode())
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/tempDetailsData.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
"lastMovement": [2022, 11 , 1],
"commentField": ["Comment 1", "Comment 2"],
"pcr": "PC123456",
"documentLanguage": "English",
"hearingLanguage": "English",
"paymentDetails": "1000/month",
"lumpSum": 500.00,
"commencing": [2021, 9 , 1],
"daysInDefault": 30,
"sentencedDate": [2020, 12 , 21],
"lastEnforcement": "lastEn",
"override": "123456",
"enforcer": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import uk.gov.hmcts.opal.dto.AccountEnquiryDto;
import uk.gov.hmcts.opal.dto.AccountSearchDto;
import uk.gov.hmcts.opal.dto.AccountSearchResultsDto;
import uk.gov.hmcts.opal.dto.AccountSummaryDto;
import uk.gov.hmcts.opal.entity.DefendantAccountEntity;
import uk.gov.hmcts.opal.service.DefendantAccountService;

Expand Down Expand Up @@ -108,18 +107,18 @@ public void testGetDefendantAccountDetails_Success() {
// Arrange
AccountDetailsDto mockResponse = new AccountDetailsDto();

when(defendantAccountService.getAccountDetailsByAccountSummary(any(AccountSummaryDto.class)))
when(defendantAccountService.getAccountDetailsByDefendantAccountId(any(Long.class)))
.thenReturn(mockResponse);

// Act
ResponseEntity<AccountDetailsDto> responseEntity = defendantAccountController
.getAccountDetailsByAccountSummary(AccountSummaryDto.builder().build());
.getAccountDetailsByAccountSummary(1L);

// Assert
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertEquals(mockResponse, responseEntity.getBody());
verify(defendantAccountService, times(1)).getAccountDetailsByAccountSummary(any(
AccountSummaryDto.class));
verify(defendantAccountService, times(1)).getAccountDetailsByDefendantAccountId(any(
Long.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

Expand Down Expand Up @@ -166,8 +165,8 @@ void testGetAccountDetailsByAccountSummaryTemporary() {
PartyEntity mockPartyEntity = PartyEntity.builder().build();
mockAccountPartyEntity.setParty(mockPartyEntity);

when(defendantAccountPartiesRepository.findByDefendantAccountDetailsCustomQuery(
any(), any(), any(), any(), any(), any(), any(), any()))
when(defendantAccountPartiesRepository.findByDefendantAccountId(
any()))
.thenReturn(mockAccountPartyEntity);

DebtorDetailEntity mockDebtorDetail = new DebtorDetailEntity();
Expand All @@ -186,23 +185,12 @@ void testGetAccountDetailsByAccountSummaryTemporary() {
List<NoteEntity> mockNotes = List.of(NoteEntity.builder().build());
when(noteRepository.findByAssociatedRecordIdAndNoteType(any(), any())).thenReturn(mockNotes);

defendantAccountService.getAccountDetailsByAccountSummary(constructTestAccountSummaryDto(LocalDate.now()));
defendantAccountService.getAccountDetailsByDefendantAccountId(1L);
}

@Test
void testGetAccountDetailsByAccountSummaryTemporary2() {
var testAccountSummary = AccountSummaryDto.builder().court("test").build();
defendantAccountService.getAccountDetailsByAccountSummary(testAccountSummary);
defendantAccountService.getAccountDetailsByDefendantAccountId(0L);
}

private AccountSummaryDto constructTestAccountSummaryDto(final LocalDate today) {
return AccountSummaryDto.builder()
.accountNo("accountNameNo")
.name("Smith, Mr JJ")
.dateOfBirth(today)
.addressLine1("Scotland")
.balance(BigDecimal.valueOf(1000))
.court("London")
.build();
}
}

0 comments on commit 3cf15ab

Please sign in to comment.