Skip to content

Commit

Permalink
update schemas, update defendantaccount details service to retrieve n…
Browse files Browse the repository at this point in the history
…otes (#162)
  • Loading branch information
DeclanClarkeCGI authored Jan 30, 2024
1 parent d11984b commit 0b2e0af
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 218 deletions.
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 @@ -45,9 +45,12 @@ public class AccountDetailsDto implements ToJsonString {
//defendant_accounts.last_movement_date
private LocalDate lastMovement;

//notes.note_text
//notes.note_text = AC
private List<String> commentField;

//notes.note_text = AA
private String accountNotes;

//defendant_accounts.prosecutor_case_reference
private String pcr;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package uk.gov.hmcts.opal.dto.legacy;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Builder
@Data
@AllArgsConstructor
Expand All @@ -27,7 +30,8 @@ public class AccountActivityDto {
private String activityText;

@JsonProperty("posted_date")
private String postedDate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime postedDate;

@JsonProperty("posted_by")
private String postedBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.hmcts.opal.dto.ToJsonString;
import uk.gov.hmcts.opal.service.DefendantAccountService;

import java.util.Comparator;
import java.util.List;

@Data
Expand All @@ -28,6 +29,8 @@ public static AccountDetailsDto toAccountDetailsDto(LegacyAccountDetailsResponse
DefendantAccountDto defendantAccountDto = legacy.getDefendantAccount();
PartyDto partyDto = defendantAccountDto.getParties().getParty().get(0);
PaymentTermsDto paymentTermsDto = defendantAccountDto.getPaymentTerms();
AccountActivityDto accountActivityDto = getLatestAccountActivity(defendantAccountDto.getAccountActivities()
.getAccountActivity());

return AccountDetailsDto.builder()
.defendantAccountId(defendantAccountDto.getDefendantAccountId())
Expand All @@ -50,6 +53,7 @@ public static AccountDetailsDto toAccountDetailsDto(LegacyAccountDetailsResponse
+ " " + defendantAccountDto.getLastHearingCourtCode())
.lastMovement(defendantAccountDto.getLastMovementDate())
.commentField(List.of(defendantAccountDto.getAccountComments()))
.accountNotes(accountActivityDto.getActivityText())
.pcr(defendantAccountDto.getProsecutorCaseReference())
.paymentDetails(DefendantAccountService.buildPaymentDetails(
paymentTermsDto.getTermsTypeCode(),
Expand All @@ -73,4 +77,10 @@ public static AccountDetailsDto toAccountDetailsDto(LegacyAccountDetailsResponse
.build();
}

private static AccountActivityDto getLatestAccountActivity(List<AccountActivityDto> accountActivities) {

return accountActivities.stream()
.max(Comparator.comparing(AccountActivityDto::getPostedDate))
.orElse(new AccountActivityDto());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public interface NoteRepository extends JpaRepository<NoteEntity, Long> {

List<NoteEntity> findByAssociatedRecordIdAndNoteType(String associatedRecordId, String noteType);

NoteEntity findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(
String associatedRecordId, String noteType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc
.getEnforcementOverrideEnforcerId());

//query DB for NoteEntity by associatedRecordId (defendantAccountId) and noteType ("AC")
List<NoteEntity> noteEntity = noteRepository.findByAssociatedRecordIdAndNoteType(
List<NoteEntity> noteEntityAC = noteRepository.findByAssociatedRecordIdAndNoteType(
defendantAccountEntity.getDefendantAccountId().toString(), "AC");

//query DB for NoteEntity by associatedRecordId (defendantAccountId) and noteType ("AA")
// returning only latest (postedDate)
NoteEntity noteEntityAA = noteRepository.findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(
defendantAccountEntity.getDefendantAccountId().toString(), "AA");

//build fullAddress
final String fullAddress = buildFullAddress(partyEntity.getAddressLine1(),
Expand All @@ -172,7 +176,8 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc
paymentTermsEntity.getEffectiveDate());

//build comments
final List<String> comments = buildCommentsFromAssociatedNotes(noteEntity);
final List<String> comments = buildCommentsFromAssociatedNotes(noteEntityAC);


//populate accountDetailsDto and return
return AccountDetailsDto.builder()
Expand All @@ -190,6 +195,7 @@ public AccountDetailsDto getAccountDetailsByDefendantAccountId(Long defendantAcc
+ " " + defendantAccountEntity.getLastHearingCourtId().getCourtCode())
.lastMovement(defendantAccountEntity.getLastMovementDate())
.commentField(comments)
.accountNotes(noteEntityAA.getNoteText())
.pcr(defendantAccountEntity.getProsecutorCaseReference())
.paymentDetails(paymentDetails)
.lumpSum(paymentTermsEntity.getInstalmentLumpSum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ void testGetAccountDetailsByDefendantAccountId() {
.thenReturn(buildEnforcersEntity());

when(noteRepository.findByAssociatedRecordIdAndNoteType(any(),any()))
.thenReturn(buildNotesEntity());
.thenReturn(buildNotesEntityComment());

when(noteRepository.findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(any(),any()))
.thenReturn(buildNotesEntityActivity());

//act
AccountDetailsDto result = defendantAccountService.getAccountDetailsByDefendantAccountId(1L);
Expand Down Expand Up @@ -215,7 +218,10 @@ void testGetAccountDetailsByDefendantAccountId_PaymentByDate() {
.thenReturn(buildEnforcersEntity());

when(noteRepository.findByAssociatedRecordIdAndNoteType(any(),any()))
.thenReturn(buildNotesEntity());
.thenReturn(buildNotesEntityComment());

when(noteRepository.findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(any(),any()))
.thenReturn(buildNotesEntityActivity());

AccountDetailsDto expectedDetails = buildAccountDetailsDto();
expectedDetails.setPaymentDetails(LocalDate.of(2012, 1,1).toString() + " By Date");
Expand Down Expand Up @@ -252,7 +258,10 @@ void testGetAccountDetailsByDefendantAccountId_PaymentPaid() {
.thenReturn(buildEnforcersEntity());

when(noteRepository.findByAssociatedRecordIdAndNoteType(any(),any()))
.thenReturn(buildNotesEntity());
.thenReturn(buildNotesEntityComment());

when(noteRepository.findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(any(),any()))
.thenReturn(buildNotesEntityActivity());

AccountDetailsDto expectedDetails = buildAccountDetailsDto();
expectedDetails.setPaymentDetails("Paid");
Expand Down Expand Up @@ -289,7 +298,10 @@ void testGetAccountDetailsByDefendantAccountId_Organisation() {
.thenReturn(buildEnforcersEntity());

when(noteRepository.findByAssociatedRecordIdAndNoteType(any(),any()))
.thenReturn(buildNotesEntity());
.thenReturn(buildNotesEntityComment());

when(noteRepository.findTopByAssociatedRecordIdAndNoteTypeOrderByPostedDateDesc(any(),any()))
.thenReturn(buildNotesEntityActivity());

AccountDetailsDto expectedDetails = buildAccountDetailsDto();
expectedDetails.setFullName("The Bank of England");
Expand Down Expand Up @@ -321,6 +333,7 @@ public static AccountDetailsDto buildAccountDetailsDto() {
+ " " + 1212)
.lastMovement(LocalDate.of(2012, 1,1))
.commentField(List.of("Comment1"))
.accountNotes("Activity")
.pcr("123456")
.paymentDetails("100.0 / PCM")
.lumpSum(BigDecimal.valueOf(100.00))
Expand Down Expand Up @@ -405,7 +418,7 @@ public static EnforcersEntity buildEnforcersEntity() {
.build();
}

public static List<NoteEntity> buildNotesEntity() {
public static List<NoteEntity> buildNotesEntityComment() {

List<NoteEntity> notes = new ArrayList<>();

Expand All @@ -416,6 +429,14 @@ public static List<NoteEntity> buildNotesEntity() {
return notes;
}

public static NoteEntity buildNotesEntityActivity() {

return NoteEntity.builder()
.noteType("AA")
.noteText("Activity")
.build();
}

private class TestDefendantAccountSummary implements DefendantAccountSummary {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import uk.gov.hmcts.opal.dto.AccountSearchDto;
import uk.gov.hmcts.opal.dto.AccountSearchResultsDto;
import uk.gov.hmcts.opal.dto.ToJsonString;
import uk.gov.hmcts.opal.dto.legacy.AccountActivitiesDto;
import uk.gov.hmcts.opal.dto.legacy.AccountActivityDto;
import uk.gov.hmcts.opal.dto.legacy.DefendantAccountDto;
import uk.gov.hmcts.opal.dto.legacy.DefendantAccountSearchResult;
import uk.gov.hmcts.opal.dto.legacy.ImpositionDto;
import uk.gov.hmcts.opal.dto.legacy.ImpositionsDto;
import uk.gov.hmcts.opal.dto.legacy.LegacyAccountDetailsRequestDto;
import uk.gov.hmcts.opal.dto.legacy.LegacyAccountDetailsResponseDto;
import uk.gov.hmcts.opal.dto.legacy.PartiesDto;
Expand All @@ -38,6 +42,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -459,6 +464,8 @@ private DefendantAccountDto buildDefendantAccountDto() {
.lastEnforcement("ENF")
.prosecutorCaseReference("123456")
.accountComments("Comment1")
.accountActivities(buildAccountActivitiesDto())
.impositions(buildImpositionsDto())
.build();
}

Expand All @@ -482,6 +489,7 @@ private PartyDto buildPartyDto() {
.fullName("Mr John Smith")
.organisation(false)
.birthDate(LocalDate.of(1979,12,12))
.lastChangedDate("2020-02-02")
.build();
}

Expand All @@ -494,6 +502,59 @@ private PaymentTermsDto buildPaymentTermsDto() {
.termsDate(LocalDate.of(2012, 1,1))
.jailDays(10)
.instalmentLumpSum(BigDecimal.valueOf(100.00))
.wording("wording")
.build();
}

private AccountActivitiesDto buildAccountActivitiesDto() {

return AccountActivitiesDto.builder()
.accountActivity(List.of(buildAccountActivityDto(),buildAccountActivityDtoOlder()))
.build();
}

private AccountActivityDto buildAccountActivityDto() {

return AccountActivityDto.builder()
.activityId(1)
.activityText("Activity")
.activityType("Activity")
.activityTypeCode("AA")
.postedDate(LocalDateTime.of(2021, 1,1, 21,0,0))
.build();
}

private ImpositionsDto buildImpositionsDto() {

return ImpositionsDto.builder()
.imposition(List.of(buildImpositionDto()))
.build();
}

private ImpositionDto buildImpositionDto() {

return ImpositionDto.builder()
.creditorAccountNumber("123")
.creditorName("John")
.imposedAmount(1000.00)
.imposedDate("2020-01-01")
.imposingCourtCode(12)
.impositionId(1)
.offenceTitle("A title")
.paidAmount(100.00)
.postedDate("2020-01-01")
.resultId("1")
.build();
}

private AccountActivityDto buildAccountActivityDtoOlder() {

return AccountActivityDto.builder()
.activityId(2)
.activityText("Activity OLD")
.activityType("Activity")
.activityTypeCode("AA")
.postedDate(LocalDateTime.of(2020, 1,1, 21,0,0))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"defendant_account_id": {
"type": "integer"
"$schema": "https://json-schema.org/draft-07/schema#",
"properties": {
"defendant_account_id": {"type": "integer"}
}
},
"required": ["defendant_account_id"]
}
}
Loading

0 comments on commit 0b2e0af

Please sign in to comment.