Skip to content

Commit

Permalink
Remove non-required fields and switch search criteria to defendant_ac…
Browse files Browse the repository at this point in the history
…count_id

DefendantAccount Details service
Fix a few improperly derived fields
Unit tests and tidy up handling address and name
  • Loading branch information
DeclanClarkeCGI authored and RustyHMCTS committed Jan 11, 2024
1 parent 6e91f31 commit a6bc891
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 72 deletions.
47 changes: 47 additions & 0 deletions postman/Account Enquiry.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"info": {
"_postman_id": "b689ac72-601a-4bd1-8746-9cf76fa0caa8",
"name": "Account Enquiry",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "31122798"
},
"item": [
{
"name": "GET http://localhost:4550/api/defendant-account/details",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://opal-fines-service.staging.platform.hmcts.net/api/defendant-account/1",
"protocol": "https",
"host": [
"opal-fines-service",
"staging",
"platform",
"hmcts",
"net"
],
"path": [
"api",
"defendant-account",
"1"
]
},
"description": "Get a defendant account from opal, account number is only unique within a businessunit"
},
"response": []
}
]
}
5 changes: 4 additions & 1 deletion src/main/java/uk/gov/hmcts/opal/dto/AccountDetailsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
@AllArgsConstructor
public class AccountDetailsDto implements ToJsonString {

//defendant_accounts.defendant_account_id
private Long defendantAccountId;

//defendant_accounts.account_number
private String accountNumber;

Expand All @@ -24,7 +27,7 @@ public class AccountDetailsDto implements ToJsonString {
// business_units.business_unit_type
private String accountCT;

//parties.account_type
//defendant_accounts.originator_reference
private String accountType;

//parties.address_line_(*)
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/uk/gov/hmcts/opal/dto/PartyDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;

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

Expand Down Expand Up @@ -35,6 +34,4 @@ public class PartyDto implements ToJsonString {
private Short age;
private String niNumber;
private LocalDateTime lastChangedDate;
private String accountNo;
private BigDecimal amountImposed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "business_units")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BusinessUnitsEntity {

@Id
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/entity/CourtsEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;


@Data
@Entity
@EqualsAndHashCode(callSuper = true)
@Table(name = "courts")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CourtsEntity extends EnforcersCourtsBaseEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
Expand All @@ -23,6 +26,9 @@
@Entity
@Data
@Table(name = "defendant_accounts")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DefendantAccountEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;


@Entity
@Table(name = "defendant_account_parties")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DefendantAccountPartiesEntity {

@Id
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/entity/EnforcersEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@Entity
@EqualsAndHashCode(callSuper = true)
@Table(name = "enforcers")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EnforcersEntity extends EnforcersCourtsBaseEntity {

@Id
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/entity/NoteEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Table(name = "notes")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class NoteEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Entity
@Table(name = "payment_terms")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PaymentTermsEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package uk.gov.hmcts.opal.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import uk.gov.hmcts.opal.entity.DefendantAccountPartiesEntity;

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

@Query("""
SELECT dap FROM DefendantAccountPartiesEntity dap
JOIN dap.party p
JOIN dap.defendantAccount da
JOIN da.lastHearingCourtId c
WHERE da.defendantAccountId = :defendantAccountId""")
DefendantAccountPartiesEntity findByDefendantAccountId(@Param("defendantAccountId") Long defendantAccountId);

DefendantAccountPartiesEntity findByDefendantAccountDefendantAccountId(Long defendantAccountId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.gov.hmcts.opal.entity.DefendantAccountEntity;
import uk.gov.hmcts.opal.entity.PaymentTermsEntity;

@Repository
public interface PaymentTermsRepository extends JpaRepository<PaymentTermsEntity, Long> {

PaymentTermsEntity findByDefendantAccount_DefendantAccountId(DefendantAccountEntity defendantAccount);
PaymentTermsEntity findByDefendantAccount_DefendantAccountId(Long defendantAccountId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -130,15 +131,16 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc

//query db for defendantAccountPartiesEntity
DefendantAccountPartiesEntity defendantAccountPartiesEntity = defendantAccountPartiesRepository
.findByDefendantAccountId(defendantAccountId);
.findByDefendantAccountDefendantAccountId(defendantAccountId);

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


//query DB for PaymentTermsEntity
PaymentTermsEntity paymentTermsEntity = paymentTermsRepository.findByDefendantAccount_DefendantAccountId(
defendantAccountEntity);
defendantAccountEntity.getDefendantAccountId());

//query DB for EnforcementEntity
EnforcersEntity enforcersEntity = enforcersRepository.findByEnforcerId(defendantAccountEntity
Expand All @@ -163,6 +165,7 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc

//populate accountDetailsDto and return
return AccountDetailsDto.builder()
.defendantAccountId(defendantAccountEntity.getDefendantAccountId())
.accountNumber(defendantAccountEntity.getAccountNumber())
.fullName(fullName)
.accountCT(defendantAccountEntity.getBusinessUnitId().getBusinessUnitName())
Expand All @@ -172,13 +175,15 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc
.dob(partyEntity.getDateOfBirth())
.detailsChanged(defendantAccountEntity.getLastChangedDate())
.lastCourtAppAndCourtCode(defendantAccountEntity.getLastHearingDate().toString()
+ defendantAccountEntity.getLastHearingCourtId().getCourtCode())
+ " " + defendantAccountEntity.getLastHearingCourtId().getCourtCode())
.lastMovement(defendantAccountEntity.getLastMovementDate())
.commentField(comments)
.pcr(defendantAccountEntity.getProsecutorCaseReference())
.paymentDetails(paymentDetails)
.lumpSum(paymentTermsEntity.getInstalmentLumpSum())
.commencing(paymentTermsEntity.getEffectiveDate())
.commencing(paymentTermsEntity.getTermsTypeCode().equals("I")
? paymentTermsEntity.getEffectiveDate()
: null)
.daysInDefault(paymentTermsEntity.getJailDays())
.lastEnforcement(defendantAccountEntity.getLastEnforcement())
.override(defendantAccountEntity.getEnforcementOverrideResultId())
Expand All @@ -192,20 +197,37 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc
}

private String buildFullAddress(PartyEntity partyEntity) {
List<String> addressLines = new ArrayList<>();

addressLines.add(partyEntity.getAddressLine1());
addressLines.add(partyEntity.getAddressLine2());
addressLines.add(partyEntity.getAddressLine3());
addressLines.add(partyEntity.getAddressLine4());
addressLines.add(partyEntity.getAddressLine5());

addressLines.removeIf(Objects::isNull);

return partyEntity.getAddressLine1() + ", "
+ partyEntity.getAddressLine2() + ", "
+ partyEntity.getAddressLine3() + ", "
+ partyEntity.getAddressLine4() + ", "
+ partyEntity.getAddressLine5();
return String.join(", ", addressLines);
}


private String buildFullName(PartyEntity partyEntity) {

return partyEntity.getOrganisationName() == null ? partyEntity.getTitle() + " "
+ partyEntity.getForenames() + " "
+ partyEntity.getInitials() + " "
+ partyEntity.getSurname() : partyEntity.getOrganisationName();
if (partyEntity.getOrganisationName() != null) {

return partyEntity.getOrganisationName();
}

List<String> nameParts = new ArrayList<>();

nameParts.add(partyEntity.getTitle());
nameParts.add(partyEntity.getForenames());
nameParts.add(partyEntity.getInitials());
nameParts.add(partyEntity.getSurname());

nameParts.removeIf(Objects::isNull);

return String.join(" ", nameParts);
}

private String buildPaymentDetails(PaymentTermsEntity paymentTermsEntity) {
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/uk/gov/hmcts/opal/dto/PartyDtoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.Test;

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

Expand Down Expand Up @@ -34,8 +33,6 @@ public void testBuilder() {
assertEquals(Short.valueOf((short) 21), partyDto.getAge());
assertEquals("FF22446688", partyDto.getNiNumber());
assertEquals(LocalDateTime.of(2023, 12, 5, 15, 45), partyDto.getLastChangedDate());
assertEquals("666", partyDto.getAccountNo());
assertEquals(BigDecimal.TEN, partyDto.getAmountImposed());

assertNotNull(AccountEnquiryDto.builder().toString());
}
Expand Down Expand Up @@ -90,8 +87,6 @@ private PartyDto constructTestPartyDto() {
.age((short)21)
.niNumber("FF22446688")
.lastChangedDate(LocalDateTime.of(2023, 12, 5, 15, 45))
.accountNo("666")
.amountImposed(BigDecimal.TEN)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void testGettersAndSetters() {
assertEquals(Short.valueOf((short) 21), party.getAge());
assertEquals("FF22446688", party.getNiNumber());
assertEquals(LocalDateTime.of(2023, 12, 5, 15, 45), party.getLastChangedDate());

}

@Test
Expand Down
Loading

0 comments on commit a6bc891

Please sign in to comment.