Skip to content

Commit

Permalink
Merge branch 'master' into Sprint_6_t4
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekPierchala authored Jan 19, 2024
2 parents 275e72d + e10f2c9 commit 828e156
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine;
import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser;
import uk.gov.hmcts.reform.civil.utils.CaseNameUtils;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -137,6 +138,9 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) {
populateWithPartyIds(caseDataUpdated);
}

caseDataUpdated.caseNameHmctsInternal(CaseNameUtils.buildCaseName(caseDataUpdated.build()));
caseDataUpdated.caseNamePublic(CaseNameUtils.buildCaseName(caseDataUpdated.build()));

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataUpdated.build().toMap(objectMapper))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;
import static uk.gov.hmcts.reform.civil.utils.CaseListSolicitorReferenceUtils.getAllDefendantSolicitorReferences;
import static uk.gov.hmcts.reform.civil.utils.CaseListSolicitorReferenceUtils.getAllOrganisationPolicyReferences;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseNameInternal;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseName;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.populateWithPartyIds;
Expand Down Expand Up @@ -496,7 +496,7 @@ private CallbackResponse submitClaim(CallbackParams callbackParams) {

//assign casemanagementcategory to the case and assign casenamehmctsinternal
//casename
dataBuilder.caseNameHmctsInternal(buildCaseNameInternal(caseData));
dataBuilder.caseNameHmctsInternal(buildCaseName(caseData));

//case management category
CaseManagementCategoryElement civil =
Expand Down Expand Up @@ -524,7 +524,7 @@ private CallbackResponse submitClaim(CallbackParams callbackParams) {
//assign category ids to documents uploaded as part of particulars of claim
assignParticularOfClaimCategoryIds(caseData);

dataBuilder.caseNamePublic(CaseNameUtils.buildCaseNamePublic(caseData));
dataBuilder.caseNamePublic(CaseNameUtils.buildCaseName(caseData));

caseFlagInitialiser.initialiseCaseFlags(CREATE_CLAIM, dataBuilder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE_TIME_AT;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDateTime;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseNameInternal;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseName;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.populateWithPartyIds;

Expand Down Expand Up @@ -477,7 +477,7 @@ private CallbackResponse submitClaim(CallbackParams callbackParams) {
dataBuilder.featureToggleWA(toggleConfiguration.getFeatureToggle());

//assign case management category to the case and caseNameHMCTSinternal
dataBuilder.caseNameHmctsInternal(buildCaseNameInternal(caseData));
dataBuilder.caseNameHmctsInternal(buildCaseName(caseData));

CaseManagementCategoryElement civil =
CaseManagementCategoryElement.builder().code("Civil").label("Civil").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class JudgeDecisionOnReconsiderationRequestCallbackHandler extends Callba
" \n" +
"To make a bespoke order in this claim, select 'General order' from the dropdown menu on the right of the " +
"screen on your dashboard.";
private static final String upholdingPreviousOrderReason = "Having read the application for reconsideration of " +
private static final String UPHOLDING_PREVIOUS_ORDER_REASON = "Having read the application for reconsideration of" +
" " +
"the Legal Advisor's order dated %s and the court file \n 1.The application for reconsideration of the order " +
"is dismissed.";

Expand All @@ -75,7 +76,7 @@ private CallbackResponse getUpholdingPreviousOrderReason(CallbackParams callback
String sdoDate = formatLocalDateTime(sdoDocLatest.get().getValue().getCreatedDatetime(), DATE);
caseDataBuilder.upholdingPreviousOrderReason(UpholdingPreviousOrderReason.builder()
.reasonForReconsiderationTxtYes(String.format(
upholdingPreviousOrderReason,
UPHOLDING_PREVIOUS_ORDER_REASON,
sdoDate
)).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import uk.gov.hmcts.reform.civil.service.CoreCaseUserService;
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser;
import uk.gov.hmcts.reform.civil.utils.CaseNameUtils;
import uk.gov.hmcts.reform.civil.validation.PostcodeValidator;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

Expand All @@ -54,8 +55,7 @@
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario;
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO;
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseNameInternal;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseNamePublic;
import static uk.gov.hmcts.reform.civil.utils.CaseNameUtils.buildCaseName;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements;
import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_EXPERTS_ID;
import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID;
Expand Down Expand Up @@ -421,8 +421,8 @@ private CallbackResponse submitChanges(CallbackParams callbackParams) {

if (isParty(partyChosenId) || isLitigationFriend(partyChosenId)) {
// update case name for hmc if applicant/respondent/litigation friend was updated
builder.caseNameHmctsInternal(buildCaseNameInternal(caseData));
builder.caseNamePublic(buildCaseNamePublic(caseData));
builder.caseNameHmctsInternal(CaseNameUtils.buildCaseName(caseData));
builder.caseNamePublic(buildCaseName(caseData));
}

// last step before clearing update details form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.sdo.ReasonForReconsideration;
import uk.gov.hmcts.reform.civil.service.CoreCaseUserService;
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;
import uk.gov.hmcts.reform.civil.model.common.Element;

import java.time.LocalDateTime;
Expand All @@ -24,10 +28,15 @@
import java.util.Map;
import java.util.Optional;

import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_FOR_RECONSIDERATION;
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isApplicantSolicitor;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorTwo;

@Service
@RequiredArgsConstructor
Expand All @@ -37,6 +46,8 @@ public class RequestForReconsiderationCallbackHandler extends CallbackHandler {
protected final ObjectMapper objectMapper;
private static final String ERROR_MESSAGE_DEADLINE_EXPIRED
= "You can no longer request a reconsideration because the deadline has expired";
private final UserService userService;
private final CoreCaseUserService coreCaseUserService;
private static final String CONFIRMATION_HEADER = "# Your request has been submitted";
private static final String CONFIRMATION_BODY = "### What happens next \n" +
"You should receive an update on your request for determination after 10 days, please monitor" +
Expand All @@ -45,13 +56,13 @@ public class RequestForReconsiderationCallbackHandler extends CallbackHandler {
@Override
protected Map<String, Callback> callbacks() {
return new ImmutableMap.Builder<String, Callback>()
.put(callbackKey(ABOUT_TO_START), this::validateRequestEligibility)
.put(callbackKey(ABOUT_TO_START), this::validateRequestEligibilityAndGetPartyDetails)
.put(callbackKey(ABOUT_TO_SUBMIT), this::saveRequestForReconsiderationReason)
.put(callbackKey(SUBMITTED), this::buildConfirmation)
.build();
}

private CallbackResponse validateRequestEligibility(CallbackParams callbackParams) {
private CallbackResponse validateRequestEligibilityAndGetPartyDetails(CallbackParams callbackParams) {
List<String> errors = new ArrayList<>();
Optional<Element<CaseDocument>> sdoDocLatest = callbackParams.getCaseData().getSystemGeneratedCaseDocuments()
.stream().filter(caseDocumentElement -> caseDocumentElement.getValue().getDocumentType()
Expand All @@ -64,18 +75,89 @@ private CallbackResponse validateRequestEligibility(CallbackParams callbackParam
errors.add(ERROR_MESSAGE_DEADLINE_EXPIRED);
}
}
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
if (errors.isEmpty()) {
CaseData.CaseDataBuilder<?, ?> updatedData = getPartyDetails(callbackParams);
return AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedData.build().toMap(objectMapper))
.build();
} else {
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}
}

private CaseData.CaseDataBuilder<?, ?> getPartyDetails(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> updatedData = caseData.toBuilder();
List<String> roles = getUserRole(callbackParams);
if (isApplicantSolicitor(roles)) {
updatedData.casePartyRequestForReconsideration("Applicant");
} else if (isRespondentSolicitorOne(roles)) {
updatedData.casePartyRequestForReconsideration("Respondent1");
} else if (isRespondentSolicitorTwo(roles)) {
updatedData.casePartyRequestForReconsideration("Respondent2");
}
return updatedData;
}

private boolean applicant2Present(CaseData caseData) {
return caseData.getAddApplicant2() != null && caseData.getAddApplicant2() == YES;
}

private boolean respondent2Present(CaseData caseData) {
return caseData.getAddRespondent2() != null
&& caseData.getAddRespondent2() == YES;
}

private boolean respondent2HasSameLegalRep(CaseData caseData) {
return caseData.getRespondent2SameLegalRepresentative() != null
&& caseData.getRespondent2SameLegalRepresentative() == YES;
}

private CallbackResponse saveRequestForReconsiderationReason(CallbackParams callbackParams) {
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = callbackParams.getCaseData().toBuilder();
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> updatedData = caseData.toBuilder();
List<String> roles = getUserRole(callbackParams);
StringBuilder partyName = new StringBuilder();
if (isApplicantSolicitor(roles)) {
partyName.append("Applicant - ");
partyName.append(caseData.getApplicant1().getPartyName());
partyName.append(applicant2Present(caseData)
? " and " + caseData.getApplicant2().getPartyName() : "");
ReasonForReconsideration reasonForReconsideration = caseData.getReasonForReconsiderationApplicant();
reasonForReconsideration.setRequestor(partyName.toString());
updatedData.reasonForReconsiderationApplicant(reasonForReconsideration);
} else if (isRespondentSolicitorOne(roles)) {
partyName.append("Defendant - ");
partyName.append(caseData.getRespondent1().getPartyName());
partyName.append(respondent2Present(caseData) && respondent2HasSameLegalRep(caseData)
? " and " + caseData.getRespondent2().getPartyName() : "");

ReasonForReconsideration reasonForReconsideration = caseData.getReasonForReconsiderationRespondent1();
reasonForReconsideration.setRequestor(partyName.toString());
updatedData.reasonForReconsiderationRespondent1(reasonForReconsideration);
} else if (isRespondentSolicitorTwo(roles)) {
partyName.append("Defendant - ");
partyName.append(respondent2Present(caseData) ? caseData.getRespondent2().getPartyName() : "");
ReasonForReconsideration reasonForReconsideration = caseData.getReasonForReconsiderationRespondent2();
reasonForReconsideration.setRequestor(partyName.toString());
updatedData.reasonForReconsiderationRespondent2(reasonForReconsideration);
}
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.data(updatedData.build().toMap(objectMapper))
.build();
}

private List<String> getUserRole(CallbackParams callbackParams) {
UserInfo userInfo = userService.getUserInfo(callbackParams.getParams().get(BEARER_TOKEN).toString());

return coreCaseUserService.getUserCaseRoles(
callbackParams.getCaseData().getCcdCaseReference().toString(),
userInfo.getUid()
);
}

private CallbackResponse buildConfirmation(CallbackParams callbackParams) {
return SubmittedCallbackResponse.builder()
.confirmationHeader(CONFIRMATION_HEADER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static String getHmctsInternalCaseName(CaseData caseData) {

public static String getPublicCaseName(CaseData caseData) {
return caseData.getCaseNamePublic() != null ? caseData.getCaseNamePublic()
: CaseNameUtils.buildCaseNamePublic(caseData);
: CaseNameUtils.buildCaseName(caseData);
}

public static String getCaseDeepLink(Long caseId,
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ public boolean hasNoOngoingBusinessProcess() {
//SDO-R2
private YesOrNo isFlightDelayClaim;
private FlightDelayDetails flightDelayDetails;
private ReasonForReconsideration reasonForReconsideration;
private ReasonForReconsideration reasonForReconsiderationApplicant;
private ReasonForReconsideration reasonForReconsiderationRespondent1;
private ReasonForReconsideration reasonForReconsiderationRespondent2;
private String casePartyRequestForReconsideration;
private DecisionOnRequestReconsiderationOptions decisionOnRequestReconsiderationOptions;
private UpholdingPreviousOrderReason upholdingPreviousOrderReason;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public class ReasonForReconsideration {

private String reasonForReconsiderationTxt;
private String requestor;
}
30 changes: 3 additions & 27 deletions src/main/java/uk/gov/hmcts/reform/civil/utils/CaseNameUtils.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package uk.gov.hmcts.reform.civil.utils;

import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.LitigationFriend;
import uk.gov.hmcts.reform.civil.model.Party;

import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario;

public class CaseNameUtils {

private CaseNameUtils() {
//no op
}

public static String buildCaseNamePublic(CaseData caseData) {
public static String buildCaseName(CaseData caseData) {
return new StringBuilder()
.append(getFormattedPartyName(caseData.getApplicant1()))
.append(getFormattedLitigationFriendName(caseData.getApplicant1LitigationFriend()))
.append(getFormattedPartyName(caseData.getApplicant2(), true))
.append(getFormattedLitigationFriendName(caseData.getApplicant2LitigationFriend()))
.append(" v ")
.append(getFormattedPartyName(caseData.getRespondent1()))
.append(getFormattedLitigationFriendName(caseData.getRespondent1LitigationFriend()))
.append(getFormattedPartyName(caseData.getRespondent2(), true))
.append(getFormattedLitigationFriendName(caseData.getRespondent2LitigationFriend()))
.toString();
}

Expand All @@ -41,27 +40,4 @@ public static String getFormattedLitigationFriendName(LitigationFriend litigatio
litigationFriend.getLastName()
) : "";
}

public static String buildCaseNameInternal(CaseData caseData) {
StringBuilder participantString = new StringBuilder();
MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData);
if (multiPartyScenario.equals(MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP)
|| multiPartyScenario.equals(MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP)) {
participantString.append(caseData.getApplicant1().getPartyName())
.append(" v ").append(caseData.getRespondent1().getPartyName())
.append(" and ").append(caseData.getRespondent2().getPartyName());

} else if (multiPartyScenario.equals(MultiPartyScenario.TWO_V_ONE)) {
participantString.append(caseData.getApplicant1().getPartyName())
.append(" and ").append(caseData.getApplicant2().getPartyName()).append(" v ")
.append(caseData.getRespondent1()
.getPartyName());

} else {
participantString.append(caseData.getApplicant1().getPartyName()).append(" v ")
.append(caseData.getRespondent1()
.getPartyName());
}
return participantString.toString();
}
}
Loading

0 comments on commit 828e156

Please sign in to comment.