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

Trigger build with empty commit #4234

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
@@ -1,12 +1,12 @@
package uk.gov.hmcts.reform.sscs.callback;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.reform.sscs.helper.IntegrationTestHelper.assertHttpStatus;
import static uk.gov.hmcts.reform.sscs.helper.IntegrationTestHelper.getRequestWithAuthHeader;

Expand Down Expand Up @@ -101,24 +101,40 @@ public void givenSubmittedCallbackForCancelTranslation_shouldUpdateCaseAndTrigge

MockHttpServletResponse response = getResponse(getRequestWithAuthHeader(json, "/ccdSubmittedEvent"));
assertHttpStatus(response, HttpStatus.OK);
PreSubmitCallbackResponse<SscsCaseData> result = deserialize(response.getContentAsString());
assertNull(result.getData().getSscsWelshPreviewNextEvent());

verify(coreCaseDataApi).submitEventForCaseWorker(anyString(), anyString(), anyString(), eq("SSCS"),
eq("Benefit"), eq("12345656789"), eq(true), any(CaseDataContent.class));
}


private void mockCcd() {
Map<String, Object> caseData = new HashMap<>();
caseData.put("sscsWelshPreviewNextEvent", "sendToDwp");
caseData.put("ccdCaseId", "12345656789");

StartEventResponse startEventResponse = StartEventResponse.builder()
.caseDetails(CaseDetails.builder()
.id(12345656789L)
.data(caseData)
.build())
.build();

given(coreCaseDataApi.startEventForCaseWorker(eq("Bearer authToken"), eq("s2s token"),
eq("userId"), eq("SSCS"), eq("Benefit"), eq("12345656789"),
eq("updateCaseOnly")))
.willReturn(startEventResponse);
given(coreCaseDataApi.startEventForCaseWorker(eq("Bearer authToken"), eq("s2s token"),
eq("userId"), eq("SSCS"), eq("Benefit"), eq("12345656789"),
eq("sendToDwp")))
.willReturn(StartEventResponse.builder().build());
.willReturn(startEventResponse);

Map<String, Object> data = new HashMap<>();
data.put("sscsWelshPreviewNextEvent", null);
given(coreCaseDataApi.submitEventForCaseWorker(eq("Bearer authToken"), eq("s2s token"),
eq("userId"), eq("SSCS"), eq("Benefit"), eq("12345656789"),
eq(true), any(CaseDataContent.class)))
.willReturn(CaseDetails.builder()
.id(123L)
.id(12345656789L)
.data(data)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static uk.gov.hmcts.reform.sscs.ccd.presubmit.furtherevidence.actionfurtherevidence.FurtherEvidenceActionDynamicListItems.OTHER_DOCUMENT_MANUAL;

import java.time.LocalDate;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,21 +18,22 @@
import uk.gov.hmcts.reform.sscs.ccd.domain.*;
import uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState;
import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.sscs.ccd.presubmit.furtherevidence.actionfurtherevidence.FurtherEvidenceActionDynamicListItems;
import uk.gov.hmcts.reform.sscs.ccd.service.CcdService;
import uk.gov.hmcts.reform.sscs.ccd.service.UpdateCcdCaseService;
import uk.gov.hmcts.reform.sscs.idam.IdamService;

@Service
@Slf4j
public class UploadWelshDocumentsSubmittedHandler implements PreSubmitCallbackHandler<SscsCaseData> {

private final CcdService ccdService;
private final IdamService idamService;
private final UpdateCcdCaseService updateCcdCaseService;


@Autowired
public UploadWelshDocumentsSubmittedHandler(CcdService ccdService, IdamService idamService) {
this.ccdService = ccdService;
public UploadWelshDocumentsSubmittedHandler(IdamService idamService,
UpdateCcdCaseService updateCcdCaseService) {
this.idamService = idamService;
this.updateCcdCaseService = updateCcdCaseService;
}

@Override
Expand All @@ -41,29 +43,35 @@ public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callb

return callbackType.equals(CallbackType.SUBMITTED)
&& callback.getEvent().equals(EventType.UPLOAD_WELSH_DOCUMENT)
&& !callback.getCaseDetails().getState().equals(State.INTERLOCUTORY_REVIEW_STATE)
&& StringUtils.isNotEmpty(callback.getCaseDetails().getCaseData().getSscsWelshPreviewNextEvent());
&& !callback.getCaseDetails().getState().equals(State.INTERLOCUTORY_REVIEW_STATE);
}

@Override
public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType, Callback<SscsCaseData> callback, String userAuthorisation) {
String nextEvent = callback.getCaseDetails().getCaseData().getSscsWelshPreviewNextEvent();
log.info("Next event to submit {}", nextEvent);
Consumer<SscsCaseDetails> mutator = (SscsCaseDetails sscsCaseDetails) -> {
SscsCaseData caseData = sscsCaseDetails.getData();
caseData.setSscsWelshPreviewNextEvent(null);
};

SscsCaseData sscsCaseData = callback.getCaseDetails().getCaseData();

sscsCaseData.setSscsWelshPreviewNextEvent(null);
log.info("Next event to submit {} for case reference {}", nextEvent, sscsCaseData.getCcdCaseId());

if (isValidUrgentHearingDocument(sscsCaseData)) {
setMakeCaseUrgentTriggerEvent(sscsCaseData, callback.getCaseDetails().getId(),
OTHER_DOCUMENT_MANUAL, EventType.MAKE_CASE_URGENT, "Send a case to urgent hearing");
sscsCaseData = setMakeCaseUrgentTriggerEvent(callback.getCaseDetails().getId(), mutator).getData();
} else if (isReinstatementRequest(sscsCaseData)) {
sscsCaseData = setReinstatementRequest(sscsCaseData, callback.getCaseDetails().getId(), nextEvent);
sscsCaseData = setReinstatementRequest(sscsCaseData, callback.getCaseDetails().getId(), nextEvent, mutator);
} else {
log.info("Submitting Next Event {}", nextEvent);
ccdService.updateCase(sscsCaseData, callback.getCaseDetails().getId(),
nextEvent, "Upload welsh document",
"Upload welsh document", idamService.getIdamTokens());
if (StringUtils.isNotEmpty(nextEvent)) {
updateCcdCaseService.updateCaseV2(
callback.getCaseDetails().getId(),
nextEvent,
"Upload welsh document",
"Upload welsh document",
idamService.getIdamTokens(),
mutator
);
}
}
return new PreSubmitCallbackResponse<>(sscsCaseData);
}
Expand All @@ -85,33 +93,37 @@ private boolean isReinstatementRequest(SscsCaseData caseData) {
return (isTranslationsOutstanding && (isDocReinstatement || isWelshReinstatement));
}

private SscsCaseDetails setMakeCaseUrgentTriggerEvent(
SscsCaseData caseData, Long caseId,
FurtherEvidenceActionDynamicListItems interlocType, EventType eventType, String summary) {
return ccdService.updateCase(caseData, caseId,
eventType.getCcdType(), summary,
interlocType.getLabel(), idamService.getIdamTokens());
private SscsCaseDetails setMakeCaseUrgentTriggerEvent(Long caseId, Consumer<SscsCaseDetails> caseDataConsumer) {
return updateCcdCaseService.updateCaseV2(
caseId,
EventType.MAKE_CASE_URGENT.getCcdType(),
"Send a case to urgent hearing",
OTHER_DOCUMENT_MANUAL.getLabel(),
idamService.getIdamTokens(),
caseDataConsumer
);
}

private SscsCaseData setReinstatementRequest(SscsCaseData sscsCaseData, Long caseId, String nextEvent) {

log.info("Setting Reinstatement Request for Welsh Case {}", caseId);
private SscsCaseData setReinstatementRequest(SscsCaseData sscsCaseData, Long caseId, String nextEvent, Consumer<SscsCaseDetails> mutator) {
Consumer<SscsCaseDetails> caseDataConsumer = sscsCaseDetails -> {
mutator.accept(sscsCaseDetails);
SscsCaseData data = sscsCaseDetails.getData();
data.setReinstatementRegistered(LocalDate.now());
data.setReinstatementOutcome(RequestOutcome.IN_PROGRESS);

sscsCaseData.setReinstatementRegistered(LocalDate.now());
sscsCaseData.setReinstatementOutcome(RequestOutcome.IN_PROGRESS);
State previousState = sscsCaseData.getPreviousState();

State previousState = sscsCaseData.getPreviousState();

if (previousState != null
&& (previousState.equals(State.DORMANT_APPEAL_STATE) || previousState.equals(State.VOID_STATE))) {
sscsCaseData.setPreviousState(State.INTERLOCUTORY_REVIEW_STATE);
log.info("{} setting previousState from {} to interlocutoryReviewState", sscsCaseData.getCcdCaseId(), previousState.getId());
}
if (previousState != null
&& (previousState.equals(State.DORMANT_APPEAL_STATE) || previousState.equals(State.VOID_STATE))) {
data.setPreviousState(State.INTERLOCUTORY_REVIEW_STATE);
log.info("{} setting previousState from {} to interlocutoryReviewState", sscsCaseData.getCcdCaseId(), previousState.getId());
}

sscsCaseData.setInterlocReviewState(InterlocReviewState.REVIEW_BY_JUDGE);
data.setInterlocReviewState(InterlocReviewState.REVIEW_BY_JUDGE);
};

ccdService.updateCase(sscsCaseData, caseId, nextEvent, "Upload Welsh Document",
"Upload Welsh Document", idamService.getIdamTokens());
updateCcdCaseService.updateCaseV2(caseId, nextEvent, "Upload Welsh Document",
"Upload Welsh Document", idamService.getIdamTokens(), caseDataConsumer);

return sscsCaseData;
}
Expand Down
Loading
Loading