Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIV-11381 hearing method section missing from order documents #3544

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import java.util.stream.Collectors;

import static java.lang.String.format;
import static java.util.Objects.isNull;
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;
Expand Down Expand Up @@ -164,7 +165,6 @@ protected Map<String, Callback> callbacks() {
.put(callbackKey(V_1, ABOUT_TO_START), this::prePopulateOrderDetailsPages)
.put(callbackKey(MID, "order-details-navigation"), this::setOrderDetailsFlags)
.put(callbackKey(MID, "generate-sdo-order"), this::generateSdoOrder)
.put(callbackKey(MID, "validateInputValue"), this::validateInputValue)
.put(callbackKey(V_1, MID, "generate-sdo-order"), this::generateSdoOrder)
.put(callbackKey(ABOUT_TO_SUBMIT), this::submitSDO)
.put(callbackKey(SUBMITTED), this::buildConfirmation)
Expand Down Expand Up @@ -755,17 +755,37 @@ private CallbackResponse generateSdoOrder(CallbackParams callbackParams) {
: callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> updatedData = caseData.toBuilder();

CaseDocument document = sdoGeneratorService.generate(
caseData,
callbackParams.getParams().get(BEARER_TOKEN).toString()
);
List<String> errors = new ArrayList<>();
if (nonNull(caseData.getSmallClaimsWitnessStatement())) {
String inputValue1 = caseData.getSmallClaimsWitnessStatement().getInput2();
String inputValue2 = caseData.getSmallClaimsWitnessStatement().getInput3();
final String witnessValidationErrorMessage = validateNegativeWitness(inputValue1, inputValue2);
if (!witnessValidationErrorMessage.isEmpty()) {
errors.add(witnessValidationErrorMessage);
}
} else if (nonNull(caseData.getFastTrackWitnessOfFact())) {
String inputValue1 = caseData.getFastTrackWitnessOfFact().getInput2();
String inputValue2 = caseData.getFastTrackWitnessOfFact().getInput3();
final String witnessValidationErrorMessage = validateNegativeWitness(inputValue1, inputValue2);
if (!witnessValidationErrorMessage.isEmpty()) {
errors.add(witnessValidationErrorMessage);
}
}

if (document != null) {
updatedData.sdoOrderDocument(document);
if (errors.isEmpty()) {
CaseDocument document = sdoGeneratorService.generate(
caseData,
callbackParams.getParams().get(BEARER_TOKEN).toString()
);

if (document != null) {
updatedData.sdoOrderDocument(document);
}
assignCategoryId.assignCategoryIdToCaseDocument(document, "sdo");
}
assignCategoryId.assignCategoryIdToCaseDocument(document, "sdo");

return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.data(updatedData.build().toMap(objectMapper))
.build();
}
Expand Down Expand Up @@ -854,13 +874,27 @@ private CallbackResponse submitSDO(CallbackParams callbackParams) {
}
}

dataBuilder.disposalHearingMethodInPerson(deleteLocationList(
caseData.getDisposalHearingMethodInPerson()));
dataBuilder.fastTrackMethodInPerson(deleteLocationList(
caseData.getFastTrackMethodInPerson()));
dataBuilder.smallClaimsMethodInPerson(deleteLocationList(
caseData.getSmallClaimsMethodInPerson()));

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

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

private DynamicList deleteLocationList(DynamicList list) {
if (isNull(list)) {
return null;
}
return DynamicList.builder().value(list.getValue()).build();
}

private String getEpimmsId(CaseData caseData) {

if (caseData.getOrderType() != null && caseData.getOrderType().equals(DISPOSAL)) {
Expand All @@ -883,40 +917,16 @@ private boolean nonNull(Object object) {
}
}

private CallbackResponse validateInputValue(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
//CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
List<String> errors = new ArrayList<>();
if (nonNull(caseData.getSmallClaimsWitnessStatement())) {
String inputValue1 = caseData.getSmallClaimsWitnessStatement().getInput2();
String inputValue2 = caseData.getSmallClaimsWitnessStatement().getInput3();
if (validateNegativeWitness(errors, inputValue1, inputValue2)) {
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}
} else if (nonNull(caseData.getFastTrackWitnessOfFact())) {
String inputValue1 = caseData.getFastTrackWitnessOfFact().getInput2();
String inputValue2 = caseData.getFastTrackWitnessOfFact().getInput3();
if (validateNegativeWitness(errors, inputValue1, inputValue2)) {
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}
}
return generateSdoOrder(callbackParams);
}

private boolean validateNegativeWitness(List<String> errors, String inputValue1, String inputValue2) {
private String validateNegativeWitness(String inputValue1, String inputValue2) {
final String errorMessage = "";
if (inputValue1 != null && inputValue2 != null) {
int number1 = Integer.parseInt(inputValue1);
int number2 = Integer.parseInt(inputValue2);
if (number1 < 0 || number2 < 0) {
errors.add("The number entered cannot be less than zero");
return true;
return "The number entered cannot be less than zero";
}
}
return false;
return errorMessage;
}

private CaseData.CaseDataBuilder<?, ?> getSharedData(CallbackParams callbackParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,28 +710,34 @@ private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParam
}

private CallbackResponse createOrderScreen(CallbackParams callbackParams) {
var response = (AboutToStartOrSubmitCallbackResponse) validateInputValue(callbackParams);
if (response.getErrors() != null) {
return response;
}

CaseData caseData = V_1.equals(callbackParams.getVersion())
? mapHearingMethodFields(callbackParams.getCaseData())
: callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();

CaseDocument document = defaultJudgmentOrderFormGenerator.generate(
caseData, callbackParams.getParams().get(BEARER_TOKEN).toString());
caseDataBuilder.orderSDODocumentDJ(document.getDocumentLink());

List<Element<CaseDocument>> systemGeneratedCaseDocuments = new ArrayList<>();
systemGeneratedCaseDocuments.add(element(document));
caseDataBuilder.orderSDODocumentDJCollection(systemGeneratedCaseDocuments);
caseDataBuilder.disposalHearingMethodInPersonDJ(deleteLocationList(
caseData.getDisposalHearingMethodInPersonDJ()));
caseDataBuilder.trialHearingMethodInPersonDJ(deleteLocationList(
caseData.getTrialHearingMethodInPersonDJ()));
List<String> errors = new ArrayList<>();
final String witnessValidationErrorMessage = validateInputValue(callbackParams);

if (!witnessValidationErrorMessage.isEmpty()) {
errors.add(witnessValidationErrorMessage);
}

if (errors.isEmpty()) {
CaseDocument document = defaultJudgmentOrderFormGenerator.generate(
caseData, callbackParams.getParams().get(BEARER_TOKEN).toString());
caseDataBuilder.orderSDODocumentDJ(document.getDocumentLink());

List<Element<CaseDocument>> systemGeneratedCaseDocuments = new ArrayList<>();
systemGeneratedCaseDocuments.add(element(document));
caseDataBuilder.orderSDODocumentDJCollection(systemGeneratedCaseDocuments);
caseDataBuilder.disposalHearingMethodInPersonDJ(deleteLocationList(
caseData.getDisposalHearingMethodInPersonDJ()));
caseDataBuilder.trialHearingMethodInPersonDJ(deleteLocationList(
caseData.getTrialHearingMethodInPersonDJ()));
}

return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}
Expand Down Expand Up @@ -834,7 +840,8 @@ private DynamicList getLocationListFromCaseData(DynamicList hearingList, Dynamic
}
}

private CallbackResponse validateInputValue(CallbackParams callbackParams) {
private String validateInputValue(CallbackParams callbackParams) {
final String errorMessage = "";
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder();
if (nonNull(caseData.getTrialHearingWitnessOfFactDJ())) {
Expand All @@ -845,16 +852,10 @@ private CallbackResponse validateInputValue(CallbackParams callbackParams) {
int number1 = Integer.parseInt(inputValue1);
int number2 = Integer.parseInt(inputValue2);
if (number1 < 0 || number2 < 0) {
errors.add("The number entered cannot be less than zero");
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
return "The number entered cannot be less than zero";
}
}
}

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
return errorMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ void handleEventsReturnsTheExpectedCallbackEvent() {

@Nested
class MidEventNegativeNumberOfWitness {
private static final String PAGE_ID = "validateInputValue";
private static final String PAGE_ID = "generate-sdo-order";

@Test
void shouldThrowErrorWhenEnteringNegativeNumberOfWitnessSmallClaim() {
Expand All @@ -1790,7 +1790,7 @@ void shouldThrowErrorWhenEnteringNegativeNumberOfWitnessSmallClaim() {
.claimsTrack(ClaimsTrack.smallClaimsTrack)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID);
CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, MID, PAGE_ID);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getErrors().get(0)).isEqualTo("The number entered cannot be less than zero");
Expand All @@ -1806,7 +1806,7 @@ void shouldThrowErrorWhenEnteringNegativeNumberOfWitnessFastTrack() {
.claimsTrack(ClaimsTrack.fastTrack)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID);
CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, MID, PAGE_ID);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getErrors().get(0)).isEqualTo("The number entered cannot be less than zero");
Expand All @@ -1822,11 +1822,11 @@ void shouldNotThrowErrorWhenEnteringPositiveNumberOfWitnessSmallClaim() {
.claimsTrack(ClaimsTrack.smallClaimsTrack)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID);
CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, MID, PAGE_ID);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response).isNotNull();
assertThat(response.getErrors()).isNull();
assertThat(response.getErrors()).isEmpty();
}

@Test
Expand All @@ -1839,11 +1839,11 @@ void shouldNotThrowErrorWhenEnteringPositiveNumberOfWitnessFastTrack() {
.claimsTrack(ClaimsTrack.fastTrack)
.build();

CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID);
CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, MID, PAGE_ID);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response).isNotNull();
assertThat(response.getErrors()).isNull();
assertThat(response.getErrors()).isEmpty();

}
}
Expand Down
Loading