Skip to content

Commit

Permalink
Merge branch 'master' into DTSPB-4422-resolve-caveat-stop
Browse files Browse the repository at this point in the history
  • Loading branch information
GEvans-HMCTS authored Dec 3, 2024
2 parents b7efe67 + 972dbc2 commit 712fd8e
Show file tree
Hide file tree
Showing 11 changed files with 1,333 additions and 93 deletions.
3 changes: 2 additions & 1 deletion src/main/java/uk/gov/hmcts/probate/model/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class Constants {
public static final String DOC_TYPE_CHERISHED = "cherished";
public static final String DOC_TYPE_OTHER = "other";
public static final String DATE_OF_DEATH_TYPE_DEFAULT = "diedOn";
public static final String CASE_TYPE_DEFAULT = "gop";
public static final String CASE_TYPE_GRANT_OF_PROBATE = "gop";
public static final String DOCMOSIS_OUTPUT_PDF = "pdf";
public static final String DOCMOSIS_OUTPUT_HTML = "html";
public static final String REDEC_NOTIFICATION_SENT_STATE = "BORedecNotificationSent";
Expand Down Expand Up @@ -74,6 +74,7 @@ public final class Constants {
public static final String TITLE_AND_CLEARING_PARTNER_OTHERS_RENOUNCING = "TCTPartOthersRenouncing";
public static final String TITLE_AND_CLEARING_PARTNER_SUCC_ALL_RENOUNCING = "TCTPartSuccAllRenouncing";
public static final String TITLE_AND_CLEARING_PARTNER_ALL_RENOUNCING = "TCTPartAllRenouncing";
public static final String TITLE_AND_CLEARING_NONE_OF_THESE = "TCTNoT";
public static final String REASON_FOR_NOT_APPLYING_RENUNCIATION = "Renunciation";
public static final String REASON_FOR_NOT_APPLYING_MENTALLY_INCAPABLE = "MentallyIncapable";
public static final String REASON_FOR_NOT_APPLYING_DIED_BEFORE = "DiedBefore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import lombok.extern.slf4j.Slf4j;
import uk.gov.hmcts.probate.controller.validation.AmendCaseDetailsGroup;
import uk.gov.hmcts.probate.controller.validation.ApplicationAdmonGroup;
import uk.gov.hmcts.probate.controller.validation.ApplicationCreatedGroup;
Expand Down Expand Up @@ -68,12 +69,14 @@

import static uk.gov.hmcts.probate.model.Constants.NO;
import static uk.gov.hmcts.probate.model.Constants.YES;
import static uk.gov.hmcts.probate.transformer.CallbackResponseTransformer.ANSWER_NO;

@JsonInclude(JsonInclude.Include.NON_NULL)
@SuperBuilder
@Jacksonized
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
public class CaseData extends CaseDataParent {

// Tasklist update
Expand Down Expand Up @@ -708,4 +711,28 @@ public boolean isLanguagePreferenceWelsh() {
return YES.equals(getLanguagePreferenceWelsh());
}

public void clearPrimaryApplicant() {
log.debug("Clearing primary applicant information from CaseData");


this.setPrimaryApplicantIsApplying(null);

this.setPrimaryApplicantForenames(null);
this.setPrimaryApplicantSurname(null);

// This is to be consistent with the behaviour currently exhibited by the service when creating
// a case with a non-NoneOfThese TitleAndClearingType.
this.setPrimaryApplicantHasAlias(ANSWER_NO);
this.setPrimaryApplicantAlias(null);


// As above this is to be consistent with the behaviour currently exhibited by the service when
// creating a case with a non-NoneOfThese TitleAndClearingType.
final SolsAddress nullAddress = SolsAddress.builder().build();
this.setPrimaryApplicantAddress(nullAddress);

this.setPrimaryApplicantEmailAddress(null);
this.setPrimaryApplicantPhoneNumber(null);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uk.gov.hmcts.probate.service;

import com.launchdarkly.sdk.LDUser;
import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -10,32 +10,46 @@
public class FeatureToggleService {

private final LDClient ldClient;
private final LDUser ldUser;
private final LDUser.Builder ldUserBuilder;
private final LDContext ldContext;


@Autowired
public FeatureToggleService(LDClient ldClient, @Value("${ld.user.key}") String ldUserKey,
@Value("${ld.user.firstName}") String ldUserFirstName,
@Value("${ld.user.lastName}") String ldUserLastName) {

final String contextName = new StringBuilder()
.append(ldUserFirstName)
.append(" ")
.append(ldUserLastName)
.toString();

this.ldClient = ldClient;

this.ldUserBuilder = new LDUser.Builder(ldUserKey)
.firstName(ldUserFirstName)
.lastName(ldUserLastName)
.custom("timestamp", String.valueOf(System.currentTimeMillis()));
this.ldUser = this.ldUserBuilder.build();
this.ldContext = LDContext.builder(ldUserKey)
.name(contextName)
.kind("application")
.set("timestamp", String.valueOf(System.currentTimeMillis()))
.build();

}

public boolean isNewFeeRegisterCodeEnabled() {
return this.ldClient.boolVariation("probate-newfee-register-code", this.ldUser, true);
return isFeatureToggleOn("probate-newfee-register-code", true);
}

public boolean enableNewMarkdownFiltering() {
return this.ldClient.boolVariation("probate-enable-new-markdown-filtering", this.ldUser, false);
return isFeatureToggleOn("probate-enable-new-markdown-filtering", false);
}

public boolean enableDuplicateExecutorFiltering() {
return isFeatureToggleOn("probate-enable-duplicate-executor-filtering", false);
}

public boolean isFeatureToggleOn(String featureToggleCode, boolean defaultValue) {
return this.ldClient.boolVariation(featureToggleCode, this.ldUser, defaultValue);
return this.ldClient.boolVariation(featureToggleCode, this.ldContext, defaultValue);
}

public boolean enableNewAliasTransformation() {
return this.isFeatureToggleOn("probate-enable-new-alias-transformation", false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.probate.transformer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -33,6 +34,7 @@
import uk.gov.hmcts.probate.model.payments.pba.OrganisationEntityResponse;
import uk.gov.hmcts.probate.service.ExceptedEstateDateOfDeathChecker;
import uk.gov.hmcts.probate.service.ExecutorsApplyingNotificationService;
import uk.gov.hmcts.probate.service.FeatureToggleService;
import uk.gov.hmcts.probate.service.organisations.OrganisationsRetrievalService;
import uk.gov.hmcts.probate.service.solicitorexecutor.FormattingService;
import uk.gov.hmcts.probate.service.tasklist.TaskListUpdateService;
Expand All @@ -57,6 +59,7 @@
import java.util.Optional;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.lang.Boolean.TRUE;
Expand Down Expand Up @@ -101,6 +104,7 @@

@Component
@RequiredArgsConstructor
@Slf4j
public class CallbackResponseTransformer {

public static final String ANSWER_YES = "Yes";
Expand Down Expand Up @@ -140,6 +144,8 @@ public class CallbackResponseTransformer {
private final IhtEstateDefaulter ihtEstateDefaulter;
private final Iht400421Defaulter iht400421Defaulter;
private final ExceptedEstateDateOfDeathChecker exceptedEstateDateOfDeathChecker;
private final FeatureToggleService featureToggleService;

@Value("${make_dormant.add_time_minutes}")
private int makeDormantAddTimeMinutes;

Expand Down Expand Up @@ -1008,7 +1014,7 @@ private CallbackResponse transformResponse(ResponseCaseData responseCaseData) {
return CallbackResponse.builder().data(responseCaseData).build();
}

private ResponseCaseDataBuilder<?, ?> getResponseCaseData(CaseDetails caseDetails, String eventId,
ResponseCaseDataBuilder<?, ?> getResponseCaseData(CaseDetails caseDetails, String eventId,
boolean transform) {
CaseData caseData = caseDetails.getData();

Expand Down Expand Up @@ -1044,7 +1050,6 @@ private CallbackResponse transformResponse(ResponseCaseData responseCaseData) {
.primaryApplicantAddress(caseData.getPrimaryApplicantAddress())
.primaryApplicantNotRequiredToSendDocuments(caseData.getPrimaryApplicantNotRequiredToSendDocuments())
.solsAdditionalInfo(caseData.getSolsAdditionalInfo())
.solsDeceasedAliasNamesList(getSolsDeceasedAliasNamesList(caseData))
.caseMatches(caseData.getCaseMatches())

.solsSOTNeedToUpdate(caseData.getSolsSOTNeedToUpdate())
Expand Down Expand Up @@ -1281,9 +1286,6 @@ private CallbackResponse transformResponse(ResponseCaseData responseCaseData) {
.paymentTaken(caseData.getPaymentTaken())
.hmrcLetterId(caseData.getHmrcLetterId())
.uniqueProbateCodeId(caseData.getUniqueProbateCodeId())
.deceasedAnyOtherNameOnWill(caseData.getDeceasedAnyOtherNameOnWill())
.deceasedAliasFirstNameOnWill(caseData.getDeceasedAliasFirstNameOnWill())
.deceasedAliasLastNameOnWill(caseData.getDeceasedAliasLastNameOnWill())
.boHandoffReasonList(getHandoffReasonList(caseData))
.lastModifiedDateForDormant(getLastModifiedDate(eventId, caseData.getLastModifiedDateForDormant()))
.applicationSubmittedBy(caseData.getApplicationSubmittedBy())
Expand All @@ -1297,6 +1299,19 @@ private CallbackResponse transformResponse(ResponseCaseData responseCaseData) {
.citizenDocumentsUploaded(caseData.getCitizenDocumentsUploaded())
.isSaveAndClose(caseData.getIsSaveAndClose());

if (featureToggleService.enableNewAliasTransformation()) {
handleDeceasedAliases(
builder,
caseData,
caseDetails.getId());
} else {
builder.solsDeceasedAliasNamesList(getSolsDeceasedAliasNamesList(caseData));

builder.deceasedAnyOtherNameOnWill(caseData.getDeceasedAnyOtherNameOnWill());
builder.deceasedAliasFirstNameOnWill(caseData.getDeceasedAliasFirstNameOnWill());
builder.deceasedAliasLastNameOnWill(caseData.getDeceasedAliasLastNameOnWill());
}

if (transform) {
updateCaseBuilderForTransformCase(caseData, builder);
} else {
Expand All @@ -1311,6 +1326,120 @@ private CallbackResponse transformResponse(ResponseCaseData responseCaseData) {
return builder;
}

void handleDeceasedAliases(
final ResponseCaseDataBuilder<?,?> builder,
final CaseData caseData,
final Long caseRef) {
// Question this asks is "Is the name on the will the same?" Not "Are there other names on the will?" as the
// name of the variable in the CaseData object suggests.
final String decNameOnWillSame = caseData.getDeceasedAnyOtherNameOnWill();
final var decAliases = caseData.getDeceasedAliasNameList();
final var solsDecAliases = caseData.getSolsDeceasedAliasNamesList();

{
final boolean hasAlternateNameOnWill = decNameOnWillSame != null && NO.equals(decNameOnWillSame);
final boolean hasDecAliases = decAliases != null && !decAliases.isEmpty();
final boolean hasSolsDecAliases = solsDecAliases != null && !solsDecAliases.isEmpty();

if ((hasAlternateNameOnWill || hasDecAliases) && hasSolsDecAliases) {
// This is one of the contributing causes for DTSPB-4388
log.info("For case {} found both non-sols and sols aliases: hasAltNameOnWill: {}, hasDecAliases: {},"
+ " hasSolsDecAliases: {}",
caseRef,
hasAlternateNameOnWill,
hasDecAliases,
hasSolsDecAliases);
}
}

List<CollectionMember<AliasName>> newSolsDecAliases = new ArrayList<>();

if (solsDecAliases != null) {
newSolsDecAliases.addAll(solsDecAliases);
}

newSolsDecAliases.addAll(convertDecAliasesSolsDecAliasList(decAliases));

{
final String decAliasFNOnWill = caseData.getDeceasedAliasFirstNameOnWill();
final String decAliasLNOnWill = caseData.getDeceasedAliasLastNameOnWill();

newSolsDecAliases.addAll(convertAliasOnWillToSolsDecAliasList(
caseRef,
decNameOnWillSame,
decAliasFNOnWill,
decAliasLNOnWill));
}

Set<String> seenAliasNames = new HashSet<>();

builder.solsDeceasedAliasNamesList(newSolsDecAliases.stream()
.filter(a -> seenAliasNames.add(a.getValue().getSolsAliasname()))
.toList());
}

List<CollectionMember<AliasName>> convertAliasOnWillToSolsDecAliasList(
final Long caseRef,
final String differentNameOnWill,
final String foreNames,
final String lastName) {
if (differentNameOnWill != null && NO.equals(differentNameOnWill)) {
if (foreNames != null && lastName != null) {
final String aliasValue = new StringBuilder()
.append(foreNames)
.append(" ")
.append(lastName)
.toString();

final AliasName alias = AliasName.builder()
.solsAliasname(aliasValue)
.build();

final CollectionMember<AliasName> listMember = new CollectionMember<>(alias);
return List.of(listMember);
} else {
log.info("For case {}, foreNames == null: {}, lastName == null: {},"
+ " so alias is not being added to solsDecAlias list",
caseRef,
foreNames == null,
lastName == null);
}
}
return List.of();
}

List<CollectionMember<AliasName>> convertDecAliasesSolsDecAliasList(
final List<CollectionMember<ProbateAliasName>> decAliases) {
if (decAliases == null || decAliases.isEmpty()) {
return List.of();
}

final Function<CollectionMember<ProbateAliasName>, ProbateAliasName> unwrap = c -> c.getValue();

final Function<ProbateAliasName, AliasName> convert = p -> {
final String aliasValue = new StringBuilder()
.append(p.getForenames())
.append(" ")
.append(p.getLastName())
.toString();

return AliasName.builder()
.solsAliasname(aliasValue)
.build();
};

final Function<AliasName, CollectionMember<AliasName>> wrap = a -> new CollectionMember<>(a);

Set<String> seenAliasNames = new HashSet<>();

return decAliases.stream()
.map(unwrap)
.map(convert)
.map(wrap)
.filter(cm -> seenAliasNames.add(cm.getValue().getSolsAliasname()))
.toList();
}

OrganisationPolicy buildOrganisationPolicy(CaseDetails caseDetails, String authToken) {
CaseData caseData = caseDetails.getData();
OrganisationEntityResponse organisationEntityResponse = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public void transformForSolicitorApplicationCompletion(CallbackRequest callbackR


public void transformCaseDataForValidateProbate(CallbackRequest callbackRequest) {
final var caseData = callbackRequest.getCaseDetails().getData();
final var caseDetails = callbackRequest.getCaseDetails();
final var caseData = caseDetails.getData();

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

resetCaseDataTransformer.resetExecutorLists(caseData);
solicitorApplicationCompletionTransformer.setFieldsIfSolicitorIsNotNamedInWillAsAnExecutor(caseData);
solicitorApplicationCompletionTransformer.mapSolicitorExecutorFieldsOnAppDetailsComplete(caseData);
Expand Down
Loading

0 comments on commit 712fd8e

Please sign in to comment.