Skip to content

Commit

Permalink
CIV-14064 Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-pearson committed Jul 15, 2024
2 parents c2850d1 + 885bc82 commit b5bab97
Show file tree
Hide file tree
Showing 21 changed files with 875 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ public enum CaseEvent {

UPLOAD_ADDL_DOCUMENTS(USER),
CREATE_SERVICE_REQUEST_CUI_GENERAL_APP(CAMUNDA),
CITIZEN_GENERAL_APP_PAYMENT(USER),
INVALID_HWF_REFERENCE_GA(USER),
NO_REMISSION_HWF_GA(USER),
MORE_INFORMATION_HWF_GA(USER),
FULL_REMISSION_HWF_GA(USER),
PARTIAL_REMISSION_HWF_GA(USER),
UPDATE_HELP_WITH_FEE_NUMBER_GA(USER),
FEE_PAYMENT_OUTCOME_GA(USER),
UPDATE_TASK_LIST_GA_CREATED(CAMUNDA),
UPDATE_TASK_LIST_GA_COMPLETE(CAMUNDA),
NO_REMISSION_HWF_GA(USER),
UPDATE_HELP_WITH_FEE_NUMBER_GA(USER);
UPDATE_TASK_LIST_GA_COMPLETE(CAMUNDA);

private final UserType userType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

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.MID;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID;

import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.PaymentRequestUpdateCallbackService;
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class FeePaymentOutcomeHWFCallBackHandler extends HWFCallbackHandlerBase {

public static final String WRONG_REMISSION_TYPE_SELECTED = "Incorrect remission type selected";
public static final String CASE_STATE_INVALID = "Case is in invalid state";
public static final String PROCESS_FEE_PAYMENT_FAILED = "Process fee payment failed";
private static final List<CaseEvent> EVENTS = List.of(CaseEvent.FEE_PAYMENT_OUTCOME_GA);

public FeePaymentOutcomeHWFCallBackHandler(ObjectMapper objectMapper,
PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService) {
super(objectMapper, EVENTS, paymentRequestUpdateCallbackService);
}

@Override
protected Map<String, Callback> callbacks() {
return new ImmutableMap.Builder<String, Callback>()
.put(callbackKey(ABOUT_TO_START), this::setData)
.put(callbackKey(ABOUT_TO_SUBMIT), this::submitFeePaymentOutcome)
.put(callbackKey(MID, "remission-type"), this::validateSelectedRemissionType)
.put(callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse)
.build();
}

private CallbackResponse validateSelectedRemissionType(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
var errors = new ArrayList<String>();

if ((caseData.isHWFTypeApplication()
&& caseData.getFeePaymentOutcomeDetails().getHwfFullRemissionGrantedForGa() == YesOrNo.YES
&& Objects.nonNull(caseData.getGaHwfDetails())
&& Objects.nonNull(caseData.getGaHwfDetails().getOutstandingFeeInPounds())
&& !Objects.equals(caseData.getGaHwfDetails().getOutstandingFeeInPounds(), BigDecimal.ZERO))
|| (caseData.isHWFTypeAdditional()
&& caseData.getFeePaymentOutcomeDetails().getHwfFullRemissionGrantedForAdditional() == YesOrNo.YES
&& Objects.nonNull(caseData.getAdditionalHwfDetails())
&& Objects.nonNull(caseData.getAdditionalHwfDetails().getOutstandingFeeInPounds())
&& !Objects.equals(caseData.getAdditionalHwfDetails().getOutstandingFeeInPounds(), BigDecimal.ZERO))) {
errors.add(WRONG_REMISSION_TYPE_SELECTED);
}
return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}

private CallbackResponse submitFeePaymentOutcome(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder();

if (caseData.isHWFTypeApplication()) {
LocalDate issueDate = LocalDate.now();
caseDataBuilder.issueDate(issueDate).build();
}
caseData = caseDataBuilder.build();
caseData = HwFFeeTypeService.updateHwfReferenceNumber(caseData);

List<String> errors = new ArrayList<>();

assert paymentRequestUpdateCallbackService != null;
CaseData processedCaseData = paymentRequestUpdateCallbackService.processHwf(caseData);
if (Objects.isNull(processedCaseData)) {
errors.add(PROCESS_FEE_PAYMENT_FAILED);
} else {
if (processedCaseData.isHWFTypeApplication()) {
caseData = processedCaseData.toBuilder()
.businessProcess(BusinessProcess.ready(INITIATE_GENERAL_APPLICATION_AFTER_PAYMENT)).build();
} else if (processedCaseData.isHWFTypeAdditional()) {
caseData = processedCaseData.toBuilder()
.businessProcess(BusinessProcess.ready(MODIFY_STATE_AFTER_ADDITIONAL_FEE_PAID)).build();
} else {
errors.add(CASE_STATE_INVALID);
}
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.FeeType;
Expand All @@ -22,22 +21,23 @@
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class FullRemissionHWFCallbackHandler extends CallbackHandler {
public class FullRemissionHWFCallbackHandler extends HWFCallbackHandlerBase {

private static final List<CaseEvent> EVENTS = List.of(FULL_REMISSION_HWF_GA);
private final ObjectMapper objectMapper;
private final Map<String, Callback> callbackMap = Map.of(
callbackKey(ABOUT_TO_START), this::setData,
callbackKey(ABOUT_TO_SUBMIT),
this::fullRemissionHWF,
callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse
);

public FullRemissionHWFCallbackHandler(ObjectMapper objectMapper) {
super(objectMapper, EVENTS);
}

@Override
protected Map<String, Callback> callbacks() {
return callbackMap;
Expand All @@ -48,14 +48,6 @@ public List<CaseEvent> handledEvents() {
return EVENTS;
}

private CallbackResponse setData(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateFeeType(caseData);
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}

private CallbackResponse fullRemissionHWF(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder updatedData = caseData.toBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.PaymentRequestUpdateCallbackService;
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService;

import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;

abstract class HWFCallbackHandlerBase extends CallbackHandler {

protected final ObjectMapper objectMapper;
protected final List<CaseEvent> events;
protected final PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService;

public HWFCallbackHandlerBase(ObjectMapper objectMapper,
List<CaseEvent> events,
PaymentRequestUpdateCallbackService paymentRequestUpdateCallbackService) {
this.objectMapper = objectMapper;
this.events = events;
this.paymentRequestUpdateCallbackService = paymentRequestUpdateCallbackService;
}

public HWFCallbackHandlerBase(ObjectMapper objectMapper,
List<CaseEvent> events) {
this.objectMapper = objectMapper;
this.events = events;
this.paymentRequestUpdateCallbackService = null;
}

@Override
public List<CaseEvent> handledEvents() {
return events;
}

protected CallbackResponse setData(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateFeeType(caseData);
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,68 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService;
import uk.gov.hmcts.reform.civil.model.genapplication.HelpWithFeesDetails;

import java.util.List;
import java.util.Map;
import java.util.Optional;

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.INVALID_HWF_REFERENCE_GA;

@Service
@RequiredArgsConstructor
public class InvalidHwFCallbackHandler extends CallbackHandler {
@Slf4j
public class InvalidHwFCallbackHandler extends HWFCallbackHandlerBase {

private static final List<CaseEvent> EVENTS = List.of(INVALID_HWF_REFERENCE_GA);
private final ObjectMapper objectMapper;

private final Map<String, Callback> callbackMap = Map.of(
callbackKey(ABOUT_TO_START), this::setData,
callbackKey(ABOUT_TO_SUBMIT), this::aboutToSubmit,
callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse
);

@Override
protected Map<String, Callback> callbacks() {
return callbackMap;
public InvalidHwFCallbackHandler(ObjectMapper objectMapper) {
super(objectMapper, EVENTS);
}

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
protected Map<String, Callback> callbacks() {
return callbackMap;
}

private CallbackResponse aboutToSubmit(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData updatedCaseData = setUpBusinessProcess(caseData);

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

private CallbackResponse setData(CallbackParams callbackParams) {
CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateFeeType(callbackParams.getCaseData());
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
private CaseData setUpBusinessProcess(CaseData caseData) {
CaseData.CaseDataBuilder updatedData = caseData.toBuilder();

if (caseData.isHWFTypeAdditional()) {
HelpWithFeesDetails hearingFeeDetails =
Optional.ofNullable(caseData.getAdditionalHwfDetails()).orElse(new HelpWithFeesDetails());
updatedData.additionalHwfDetails(hearingFeeDetails.toBuilder().hwfCaseEvent(INVALID_HWF_REFERENCE_GA).build());
}
if (caseData.isHWFTypeApplication()) {
HelpWithFeesDetails claimIssuedHwfDetails =
Optional.ofNullable(caseData.getGaHwfDetails()).orElse(new HelpWithFeesDetails());
updatedData.gaHwfDetails(claimIssuedHwfDetails.toBuilder().hwfCaseEvent(INVALID_HWF_REFERENCE_GA).build());
}
return updatedData.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.FeeType;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.genapplication.HelpWithFeesDetails;
import uk.gov.hmcts.reform.civil.model.genapplication.HelpWithFeesMoreInformation;
import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -26,43 +23,31 @@
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class MoreInformationHwfCallbackHandler extends CallbackHandler {
public class MoreInformationHwfCallbackHandler extends HWFCallbackHandlerBase {

private static final String ERROR_MESSAGE_DOCUMENT_DATE_MUST_BE_AFTER_TODAY = "Documents date must be future date";

private final ObjectMapper objectMapper;
private final Map<String, Callback> callbackMap = Map.of(
callbackKey(ABOUT_TO_START), this::setData,
callbackKey(MID, "more-information-hwf"), this::validationMoreInformation,
callbackKey(ABOUT_TO_SUBMIT), this::submitMoreInformationHwf,
callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse
);

@Override
protected Map<String, Callback> callbacks() {
return callbackMap;
public MoreInformationHwfCallbackHandler(ObjectMapper objectMapper) {
super(objectMapper, Collections.singletonList(
MORE_INFORMATION_HWF_GA
));
}

@Override
public List<CaseEvent> handledEvents() {
return Collections.singletonList(
MORE_INFORMATION_HWF_GA
);
}

private CallbackResponse setData(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateFeeType(caseData);
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
protected Map<String, Callback> callbacks() {
return callbackMap;
}

private CallbackResponse validationMoreInformation(CallbackParams callbackParams) {
Expand Down
Loading

0 comments on commit b5bab97

Please sign in to comment.