Skip to content

Commit

Permalink
CIV-8903 Implement claim statuses for CmcClaim
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-pearson committed Nov 14, 2023
1 parent f5b09a3 commit 7aa2ffd
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public boolean hasDefendantRejectedSettlementAgreement() {
&& !caseData.isRespondentSignedSettlementAgreement();
}

public boolean hasClaimantSignedSettlementAgreementAndDeadlineNotExpired() {
public boolean hasClaimantSignedSettlementAgreement() {
return caseData.hasApplicant1SignedSettlementAgreement() && !caseData.isSettlementAgreementDeadlineExpired();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface Claim {

boolean hasDefendantRejectedSettlementAgreement();

boolean hasClaimantSignedSettlementAgreementAndDeadlineNotExpired();
boolean hasClaimantSignedSettlementAgreement();

boolean hasClaimantSignedSettlementAgreementAndDeadlineExpired();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public enum DashboardClaimStatus {
DEFENDANT_REJECTED_SETTLEMENT_AGREEMENT(
Claim::hasDefendantRejectedSettlementAgreement
),
CLAIMANT_SEND_SETTLEMENT_AGREEMENT(
Claim::hasClaimantSignedSettlementAgreementAndDeadlineNotExpired
),
CLAIMANT_SEND_SETTLEMENT_AGREEMENT_DEADLINE_EXPIRED(
Claim::hasClaimantSignedSettlementAgreementAndDeadlineExpired
),
CLAIMANT_SEND_SETTLEMENT_AGREEMENT(
Claim::hasClaimantSignedSettlementAgreement
),
HEARING_FORM_GENERATED(Claim::isHearingFormGenerated),
REQUESTED_CCJ_BY_REDETERMINATION(
Claim::hasCCJByRedetermination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ClaimantResponse {
private String paymentReceived;
private String settleForAmount;
private CourtDetermination courtDetermination;
private FormaliseOption formaliseOption;

@JsonIgnore
public boolean hasCourtDetermination() {
Expand Down
31 changes: 26 additions & 5 deletions src/main/java/uk/gov/hmcts/reform/cmc/model/CmcClaim.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class CmcClaim implements Claim {
@JsonSerialize(using = LocalDateSerializer.class)
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate intentionToProceedDeadline;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DATE_TIME_FORMAT)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime claimantRespondedAt;

private ClaimantResponse claimantResponse;
private ClaimState state;
private ProceedOfflineReasonType proceedOfflineReason;
Expand Down Expand Up @@ -227,23 +233,38 @@ public boolean hasClaimantAskedToSignSettlementAgreement() {
}

@Override
public boolean hasClaimantSignedSettlementAgreementAndDeadlineNotExpired() {
return false;
public boolean hasClaimantSignedSettlementAgreement() {
return hasClaimantSignedSettlementAgreementOfferAccepted() || hasClaimantSignedSettlementAgreementChosenByCourt();
}

private boolean hasClaimantSignedSettlementAgreementOfferAccepted() {
return Objects.nonNull(settlement) && settlement.isOfferAccepted() && settlement.isThroughAdmissions()
&& Objects.nonNull(claimantResponse) && !claimantResponse.hasCourtDetermination();
}

private boolean hasClaimantSignedSettlementAgreementChosenByCourt() {
return Objects.nonNull(settlement) && settlement.isOfferAccepted() && !settlement.isRejectedByDefendant() && settlement.isThroughAdmissions()
&& Objects.nonNull(claimantResponse) && claimantResponse.hasCourtDetermination();
}

@Override
public boolean hasClaimantSignedSettlementAgreementAndDeadlineExpired() {
return false;
return Objects.nonNull(settlement) && settlement.isOfferAccepted() && settlement.isThroughAdmissions()
&& Objects.nonNull(claimantRespondedAt) && claimantRespondedAt.plusDays(7).isBefore(LocalDateTime.now());
}

@Override
public boolean hasClaimantAndDefendantSignedSettlementAgreement() {
return false;
return Objects.nonNull(settlement) && !settlement.isRejectedByDefendant() && settlement.isSettled() && settlement.isThroughAdmissions();
}

@Override
public boolean hasDefendantRejectedSettlementAgreement() {
return false;
if (!Objects.nonNull(claimantResponse) || !ClaimantResponseType.ACCEPTATION.equals(claimantResponse.getType())) {
return false;
}
return claimantResponse.getFormaliseOption() == FormaliseOption.SETTLEMENT
&& Objects.nonNull(settlement) && settlement.isOfferRejected();
}

@Override
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/cmc/model/FormaliseOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package uk.gov.hmcts.reform.cmc.model;

import lombok.Getter;

@Getter
public enum FormaliseOption {
CCJ("County Court Judgment"),
SETTLEMENT("Settlement"),
REFER_TO_JUDGE("Refer to Judge");

private final String description;

FormaliseOption(String description) {
this.description = description;
}
}
17 changes: 17 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/cmc/model/Settlement.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ public boolean isAcceptedByDefendant() {
&& partyStatement.isMadeByDefendant());
}

@JsonIgnore
public boolean isRejectedByDefendant() {
return getPartyStatementStream()
.anyMatch(partyStatement -> partyStatement.isRejected()
&& partyStatement.isMadeByDefendant());
}

@JsonIgnore
public boolean isOfferAccepted() {
return getPartyStatementStream().anyMatch(PartyStatement::isAccepted);
}

@JsonIgnore
public boolean isOfferRejected() {
return getPartyStatementStream().anyMatch(PartyStatement::isRejected);
}

@JsonIgnore
public boolean isSettled() {
Stream<PartyStatement> partyStatementsStream = getPartyStatementStream();
Expand Down
127 changes: 127 additions & 0 deletions src/test/java/uk/gov/hmcts/reform/cmc/model/CmcClaimTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.reform.cmc.model;

import java.time.LocalDateTime;
import org.assertj.core.api.AssertionsForClassTypes;
import org.elasticsearch.core.List;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -143,4 +144,130 @@ void given_claimantNotRespondedWithInDeadLine_whenGetStatus_claimEnded() {
AssertionsForClassTypes.assertThat(status).isEqualTo(DashboardClaimStatus.CLAIM_ENDED);
}

@Test
void shouldReturnTrueIfOfferAcceptedAndClaimantSignedSettlementAgreement() {
//Given
CmcClaim claim = CmcClaim.builder()
.response(Response.builder()
.responseType(RespondentResponseType.FULL_ADMISSION)
.build())
.settlement(Settlement.builder()
.partyStatements(List.of(
PartyStatement.builder()
.type(StatementType.OFFER)
.build(),
PartyStatement.builder()
.type(StatementType.ACCEPTATION)
.build()))
.build())
.claimantResponse(ClaimantResponse.builder().build())
.build();
//When
boolean signed = claim.hasClaimantSignedSettlementAgreement();
//Then
assertThat(signed).isTrue();
}

@Test
void shouldReturnTrueIfClaimantSignedSettlementAgreementChosenByCourt() {
//Given
CmcClaim claim = CmcClaim.builder()
.response(Response.builder()
.responseType(RespondentResponseType.FULL_ADMISSION)
.build())
.settlement(Settlement.builder()
.partyStatements(List.of(
PartyStatement.builder()
.type(StatementType.OFFER)
.build(),
PartyStatement.builder()
.type(StatementType.ACCEPTATION)
.build()))
.build())
.claimantResponse(ClaimantResponse.builder()
.courtDetermination(CourtDetermination.builder().build())
.build())
.build();
//When
boolean signed = claim.hasClaimantSignedSettlementAgreement();
//Then
assertThat(signed).isTrue();
}

@Test
void shouldReturnTrueIfSettlementAgreementDeadlineExpired() {
//Given
CmcClaim claim = CmcClaim.builder()
.response(Response.builder()
.responseType(RespondentResponseType.FULL_ADMISSION)
.build())
.settlement(Settlement.builder()
.partyStatements(List.of(
PartyStatement.builder()
.type(StatementType.OFFER)
.build(),
PartyStatement.builder()
.type(StatementType.ACCEPTATION)
.build()))
.build())
.claimantRespondedAt(LocalDateTime.MIN)
.build();
//When
boolean signed = claim.hasClaimantSignedSettlementAgreementAndDeadlineExpired();
//Then
assertThat(signed).isTrue();
}

@Test
void shouldReturnTrueIfBothSignedSettlementAgreement() {
//Given
CmcClaim claim = CmcClaim.builder()
.response(Response.builder()
.responseType(RespondentResponseType.FULL_ADMISSION)
.build())
.settlement(Settlement.builder()
.partyStatements(List.of(
PartyStatement.builder()
.type(StatementType.OFFER)
.build(),
PartyStatement.builder()
.type(StatementType.ACCEPTATION)
.build(),
PartyStatement.builder()
.type(StatementType.COUNTERSIGNATURE)
.build()))
.build())
.build();
//When
boolean signed = claim.hasClaimantAndDefendantSignedSettlementAgreement();
//Then
assertThat(signed).isTrue();
}

@Test
void shouldReturnTrueIfDefendantRejectedSettlementAgreement() {
//Given
CmcClaim claim = CmcClaim.builder()
.response(Response.builder()
.responseType(RespondentResponseType.FULL_ADMISSION)
.build())
.settlement(Settlement.builder()
.partyStatements(List.of(
PartyStatement.builder()
.type(StatementType.OFFER)
.build(),
PartyStatement.builder()
.type(StatementType.REJECTION)
.build()))
.build())
.claimantResponse(ClaimantResponse.builder()
.type(ClaimantResponseType.ACCEPTATION)
.formaliseOption(FormaliseOption.SETTLEMENT)
.build())
.build();
//When
boolean signed = claim.hasDefendantRejectedSettlementAgreement();
//Then
assertThat(signed).isTrue();
}
}

0 comments on commit 7aa2ffd

Please sign in to comment.