Skip to content

Commit

Permalink
Merge branch 'master' into testPRforCUIR2Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rajakm authored Nov 7, 2023
2 parents 3fa2382 + 3e31b49 commit df6b90c
Show file tree
Hide file tree
Showing 17 changed files with 733 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CallbackVersion.V_1;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO;
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;
import static uk.gov.hmcts.reform.civil.enums.sdo.OrderDetailsPagesSectionsToggle.SHOW;
import static uk.gov.hmcts.reform.civil.enums.sdo.OrderType.DISPOSAL;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes;
Expand Down Expand Up @@ -219,7 +222,7 @@ private CallbackResponse prePopulateOrderDetailsPages(CallbackParams callbackPar
updatedData.fastTrackMethodInPerson(locationsList);
updatedData.smallClaimsMethodInPerson(locationsList);

List<OrderDetailsPagesSectionsToggle> checkList = List.of(OrderDetailsPagesSectionsToggle.SHOW);
List<OrderDetailsPagesSectionsToggle> checkList = List.of(SHOW);
setCheckList(updatedData, checkList);

DisposalHearingJudgesRecital tempDisposalHearingJudgesRecital = DisposalHearingJudgesRecital.builder()
Expand Down Expand Up @@ -711,17 +714,21 @@ private DynamicList getLocationList(CallbackParams callbackParams,
));
DynamicList locationsList;
if (matchingLocation.isPresent()) {
locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry,
locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry,
matchingLocation.get(), true
);
} else {
locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry,
locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry,
null, true
);
}
return locationsList;
}

private String getLocationEpimms(LocationRefData location) {
return location.getEpimmsId();
}

private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder updatedData = caseData.toBuilder();
Expand All @@ -732,9 +739,9 @@ private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) {
updatedData.setFastTrackFlag(YesOrNo.NO).build();

if (SdoHelper.isSmallClaimsTrack(caseData)) {
updatedData.setSmallClaimsFlag(YesOrNo.YES).build();
updatedData.setSmallClaimsFlag(YES).build();
} else if (SdoHelper.isFastTrack(caseData)) {
updatedData.setFastTrackFlag(YesOrNo.YES).build();
updatedData.setFastTrackFlag(YES).build();
}

return AboutToStartOrSubmitCallbackResponse.builder()
Expand Down Expand Up @@ -836,18 +843,38 @@ private CallbackResponse submitSDO(CallbackParams callbackParams) {

dataBuilder.hearingNotes(getHearingNotes(caseData));

if (featureToggleService.isLocationWhiteListedForCaseProgression(
caseData.getCaseManagementLocation().getBaseLocation())) {
log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference());
} else {
log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference());
if (featureToggleService.isEarlyAdoptersEnabled()) {
if (featureToggleService.isLocationWhiteListedForCaseProgression(
getEpimmsId(caseData))) {
log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference());
dataBuilder.eaCourtLocation(YES);
} else {
log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference());
dataBuilder.eaCourtLocation(YesOrNo.NO);
}
}

System.out.println("before about to submit");

return AboutToStartOrSubmitCallbackResponse.builder()
.data(dataBuilder.build().toMap(objectMapper))
.build();
}

private String getEpimmsId(CaseData caseData) {

if (caseData.getOrderType() != null && caseData.getOrderType().equals(DISPOSAL)) {
return caseData.getDisposalHearingMethodInPerson().getValue().getCode();
}
if (SdoHelper.isFastTrack(caseData)) {
return caseData.getFastTrackMethodInPerson().getValue().getCode();
}
if (SdoHelper.isSmallClaimsTrack(caseData)) {
return caseData.getSmallClaimsMethodInPerson().getValue().getCode();
}
throw new IllegalArgumentException("Could not determine claim track");
}

private boolean nonNull(Object object) {
if (object != null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import uk.gov.hmcts.reform.civil.config.ToggleConfiguration;
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType;
import uk.gov.hmcts.reform.civil.enums.AllocatedTrack;
import uk.gov.hmcts.reform.civil.enums.CaseCategory;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.enums.DocCategory;
import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.helpers.LocationHelper;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
Expand All @@ -36,6 +34,7 @@
import uk.gov.hmcts.reform.civil.service.Time;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;
import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser;
import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils;
import uk.gov.hmcts.reform.civil.utils.LocationRefDataUtil;
import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils;
import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator;
Expand All @@ -56,7 +55,6 @@
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE;
import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.getAllocatedTrack;
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP;
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP;
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE;
Expand Down Expand Up @@ -288,57 +286,12 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) {

return AboutToStartOrSubmitCallbackResponse.builder()
.data(builder.build().toMap(objectMapper))
.state((shouldMoveToJudicialReferral(caseData)
.state((JudicialReferralUtils.shouldMoveToJudicialReferral(caseData)
? CaseState.JUDICIAL_REFERRAL
: CaseState.PROCEEDS_IN_HERITAGE_SYSTEM).name())
.build();
}

/**
* Computes whether the case data should move to judicial referral or not.
*
* @param caseData a case data such that defendants rejected the claim, and claimant(s) wants to proceed
* vs all the defendants
* @return true if and only if the case should move to judicial referral
*/
public static boolean shouldMoveToJudicialReferral(CaseData caseData) {
CaseCategory caseCategory = caseData.getCaseAccessCategory();

if (CaseCategory.SPEC_CLAIM.equals(caseCategory)) {
MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData);
boolean addRespondent2 = YES.equals(caseData.getAddRespondent2());

return switch (multiPartyScenario) {
case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES;
case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimSpec2v1() == YesOrNo.YES;
case ONE_V_TWO_ONE_LEGAL_REP -> addRespondent2
&& YES.equals(caseData.getRespondentResponseIsSame());
case ONE_V_TWO_TWO_LEGAL_REP -> addRespondent2
&& caseData.getRespondentResponseIsSame() == null;
};
} else {
AllocatedTrack allocatedTrack =
getAllocatedTrack(
CaseCategory.UNSPEC_CLAIM.equals(caseCategory)
? caseData.getClaimValue().toPounds()
: caseData.getTotalClaimAmount(),
caseData.getClaimType()
);
if (AllocatedTrack.MULTI_CLAIM.equals(allocatedTrack)) {
return false;
}
MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData);
return switch (multiPartyScenario) {
case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES;
case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimMultiParty2v1() == YES
&& caseData.getApplicant2ProceedWithClaimMultiParty2v1() == YES;
case ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP ->
caseData.getApplicant1ProceedWithClaimAgainstRespondent1MultiParty1v2() == YES
&& caseData.getApplicant1ProceedWithClaimAgainstRespondent2MultiParty1v2() == YES;
};
}
}

private void updateApplicants(CaseData caseData, CaseData.CaseDataBuilder builder, StatementOfTruth statementOfTruth) {
if (caseData.getApplicant1DQ() != null
&& caseData.getApplicant1DQ().getApplicant1DQFileDirectionsQuestionnaire() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService;
import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser;
import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils;
import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils;
import uk.gov.hmcts.reform.civil.utils.MonetaryConversions;
import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils;
import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator;
Expand Down Expand Up @@ -384,7 +385,7 @@ private void updateDQCourtLocations(CallbackParams callbackParams, CaseData case

private void putCaseStateInJudicialReferral(CaseData caseData, AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response) {
if (caseData.isRespondentResponseFullDefence()
&& RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(caseData)) {
&& JudicialReferralUtils.shouldMoveToJudicialReferral(caseData)) {
response.state(CaseState.JUDICIAL_REFERRAL.name());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
Expand All @@ -17,6 +18,7 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.enums.CaseCategory;
import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.enums.dj.DisposalAndTrialHearingDJToggle;
import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingMethodDJ;
import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle;
Expand Down Expand Up @@ -57,6 +59,7 @@
import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService;
import uk.gov.hmcts.reform.civil.service.CategoryService;
import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.docmosis.dj.DefaultJudgmentOrderFormGenerator;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;
import uk.gov.hmcts.reform.civil.utils.HearingMethodUtils;
Expand Down Expand Up @@ -88,6 +91,7 @@
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;
import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes;

@Slf4j
@Service
@RequiredArgsConstructor
public class StandardDirectionOrderDJ extends CallbackHandler {
Expand All @@ -99,6 +103,7 @@ public class StandardDirectionOrderDJ extends CallbackHandler {
private final ObjectMapper objectMapper;
private final DefaultJudgmentOrderFormGenerator defaultJudgmentOrderFormGenerator;
private final LocationRefDataService locationRefDataService;
private final FeatureToggleService featureToggleService;
String participantString;
public static final String DISPOSAL_HEARING = "DISPOSAL_HEARING";
public static final String ORDER_1_CLAI = "The directions order has been sent to: "
Expand Down Expand Up @@ -628,9 +633,22 @@ private DynamicList getLocationList(CallbackParams callbackParams,
);
Optional<LocationRefData> matchingLocation = Optional.ofNullable(preferredCourt)
.flatMap(requestedCourt -> locationHelper.getMatching(locations, preferredCourt));
return DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry,
matchingLocation.orElse(null), true
);

DynamicList locationsList;
if (matchingLocation.isPresent()) {
locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry,
matchingLocation.get(), true
);
} else {
locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry,
null, true
);
}
return locationsList;
}

private String getLocationEpimms(LocationRefData location) {
return location.getEpimmsId();
}

private CallbackResponse generateSDONotifications(CallbackParams callbackParams) {
Expand All @@ -643,7 +661,6 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams)
caseDataBuilder.orderSDODocumentDJ(null);
assignCategoryId.assignCategoryIdToCollection(caseData.getOrderSDODocumentDJCollection(), document -> document.getValue().getDocumentLink(), "sdo");
caseDataBuilder.businessProcess(BusinessProcess.ready(STANDARD_DIRECTION_ORDER_DJ));
var state = "CASE_PROGRESSION";
String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
List<LocationRefData> locations = (locationRefDataService
.getCourtLocationsForDefaultJudgments(authToken));
Expand All @@ -655,15 +672,35 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams)
.ifPresent(caseDataBuilder::locationName);

}

var state = "CASE_PROGRESSION";
caseDataBuilder.hearingNotes(getHearingNotes(caseData));

if (featureToggleService.isEarlyAdoptersEnabled()) {
if (featureToggleService.isLocationWhiteListedForCaseProgression(
getEpimmsId(caseData))) {
log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference());
caseDataBuilder.eaCourtLocation(YesOrNo.YES);
} else {
log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference());
caseDataBuilder.eaCourtLocation(YesOrNo.NO);
}
}

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.state(state)
.build();
}

private String getEpimmsId(CaseData caseData) {
if (caseData.getTrialHearingMethodInPersonDJ() != null) {
return caseData.getTrialHearingMethodInPersonDJ().getValue().getCode();
} else if (caseData.getDisposalHearingMethodInPersonDJ() != null) {
return caseData.getDisposalHearingMethodInPersonDJ().getValue().getCode();
}
throw new IllegalArgumentException("Epimms Id is not provided");
}

private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
return SubmittedCallbackResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public class CaseDataParent implements MappableObject {

private CaseDocument sdoOrderDocument;

private final YesOrNo eaCourtLocation;

// sdo ui flags
private final YesOrNo setSmallClaimsFlag;
private final YesOrNo setFastTrackFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
@Data
@Jacksonized
@Builder
@Builder(toBuilder = true)
public class DynamicList {

/**
Expand All @@ -39,18 +39,20 @@ public static DynamicList fromList(List<String> list) {
}

/**
* Sometimes a dynamic list can be prepopulated with a value.
* A dynamic list can be pre-populated with a code and value.
*
* @param list the original list of items
* @param toCode (optional) how to populate the DynamicListElement code, defaults to random UUID
* @param toLabel how to create the label
* @param value (optional) value to be selected
* @param <T> type of element
* @return dynamic list, possibly with value set
*/
public static <T> DynamicList fromList(List<T> list, Function<T, String> toLabel, T value, boolean sort) {
public static <T> DynamicList fromList(List<T> list, Function<T, String> toCode, Function<T, String> toLabel, T value, boolean sort) {
List<DynamicListElement> items = list.stream()
.map(toLabel)
.map(DynamicListElement::dynamicElement)
.map(item -> toCode != null
? DynamicListElement.dynamicElementFromCode(toCode.apply(item), toLabel.apply(item))
: DynamicListElement.dynamicElement(toLabel.apply(item)))
.collect(toList());

int index = value != null ? list.indexOf(value) : -1;
Expand All @@ -68,6 +70,19 @@ public static <T> DynamicList fromList(List<T> list, Function<T, String> toLabel
return DynamicList.builder().listItems(items).value(chosen).build();
}

/**
* Sometimes a dynamic list can be pre-populated with a value.
*
* @param list the original list of items
* @param toLabel how to create the label
* @param value (optional) value to be selected
* @param <T> type of element
* @return dynamic list, possibly with value set
*/
public static <T> DynamicList fromList(List<T> list, Function<T, String> toLabel, T value, boolean sort) {
return fromList(list, null, toLabel, value, sort);
}

public static DynamicList fromDynamicListElementList(List<DynamicListElement> list) {
return DynamicList.builder().listItems(list).value(DynamicListElement.EMPTY).build();
}
Expand Down
Loading

0 comments on commit df6b90c

Please sign in to comment.