From 60991be3e5aa46cc17742beee60aecf62ed99b94 Mon Sep 17 00:00:00 2001 From: sanjayparekh-hmcts Date: Fri, 15 Nov 2024 16:51:41 +0000 Subject: [PATCH] SSCSSI-421: corrected translation reuested --- .../RequestTranslationCallbackHandler.java | 18 ++++++++-- ...RequestTranslationCallbackHandlerTest.java | 33 +++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandler.java index e537ba35618..d798358e8ac 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandler.java @@ -5,18 +5,23 @@ import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.REQUEST_TRANSLATION_FROM_WLU; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.ListUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.sscs.callback.CallbackHandler; import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType; import uk.gov.hmcts.reform.sscs.ccd.callback.DispatchPriority; +import uk.gov.hmcts.reform.sscs.ccd.domain.AbstractDocument; import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsDocumentTranslationStatus; import uk.gov.hmcts.reform.sscs.ccd.service.UpdateCcdCaseService; import uk.gov.hmcts.reform.sscs.evidenceshare.exception.WelshException; import uk.gov.hmcts.reform.sscs.evidenceshare.service.RequestTranslationService; import uk.gov.hmcts.reform.sscs.idam.IdamService; +import java.util.List; + @Slf4j @Service public class RequestTranslationCallbackHandler implements CallbackHandler { @@ -57,15 +62,24 @@ public void handle(CallbackType callbackType, Callback callback) { try { log.info("sending email for case id {}", callback.getCaseDetails().getId()); if (requestTranslationService.sendCaseToWlu(callback.getCaseDetails()) && callback.getEvent() == REQUEST_TRANSLATION_FROM_WLU) { - updateCcdCaseService.triggerCaseEventV2(Long.valueOf(callback.getCaseDetails().getCaseData().getCcdCaseId()), + updateCcdCaseService.updateCaseV2(Long.valueOf(callback.getCaseDetails().getCaseData().getCcdCaseId()), CASE_UPDATED.getCcdType(), "Case translations sent to wlu", "Updated case with date sent to wlu", - idamService.getIdamTokens()); + idamService.getIdamTokens(), sscsCaseDetails -> { + updateDocumentStatus(sscsCaseDetails.getData().getSscsDocument()); + updateDocumentStatus(sscsCaseDetails.getData().getDwpDocuments()); + }); } } catch (WelshException e) { log.error("Error when sending to request translation from wlu: {}", callback.getCaseDetails().getId(), e); } } + private void updateDocumentStatus(List docs) { + ListUtils.emptyIfNull(docs).stream().filter(doc -> SscsDocumentTranslationStatus.TRANSLATION_REQUIRED.equals(doc.getValue().getDocumentTranslationStatus())) + .forEach(doc -> { + doc.getValue().setDocumentTranslationStatus(SscsDocumentTranslationStatus.TRANSLATION_REQUESTED); + }); + } @Override public DispatchPriority getPriority() { diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandlerTest.java index ad1ff2c906f..3110c4ec90f 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/callback/handlers/RequestTranslationCallbackHandlerTest.java @@ -7,10 +7,16 @@ import static org.mockito.Mockito.*; import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.REQUEST_TRANSLATION_FROM_WLU; +import static uk.gov.hmcts.reform.sscs.ccd.domain.SscsDocumentTranslationStatus.*; import static uk.gov.hmcts.reform.sscs.ccd.domain.State.APPEAL_CREATED; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Optional; +import java.util.function.Consumer; + import junitparams.JUnitParamsRunner; import junitparams.Parameters; import org.junit.Before; @@ -25,10 +31,7 @@ import org.mockito.junit.MockitoRule; import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType; -import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal; -import uk.gov.hmcts.reform.sscs.ccd.domain.CaseDetails; -import uk.gov.hmcts.reform.sscs.ccd.domain.EventType; -import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.*; import uk.gov.hmcts.reform.sscs.ccd.service.UpdateCcdCaseService; import uk.gov.hmcts.reform.sscs.evidenceshare.exception.WelshException; import uk.gov.hmcts.reform.sscs.evidenceshare.service.RequestTranslationService; @@ -54,7 +57,7 @@ public class RequestTranslationCallbackHandlerTest { private RequestTranslationCallbackHandler handler; @Captor - ArgumentCaptor captor; + ArgumentCaptor> captor; @Before public void setUp() { @@ -95,7 +98,25 @@ public void requestTranslationForWelshCase() { handler.handle(SUBMITTED, callback); verify(requestTranslationService).sendCaseToWlu(any()); - verify(updateCcdCaseService).triggerCaseEventV2(eq(123L), eq(EventType.CASE_UPDATED.getCcdType()), eq("Case translations sent to wlu"), eq("Updated case with date sent to wlu"), any()); + verify(updateCcdCaseService).updateCaseV2(eq(123L), eq(EventType.CASE_UPDATED.getCcdType()), eq("Case translations sent to wlu"), eq("Updated case with date sent to wlu"), any(), captor.capture()); + + List sscsDocs = new ArrayList<>(); + SscsDocument sscsDoc1 = SscsDocument.builder().value(SscsDocumentDetails.builder().documentFileName("sscsDoc1").documentTranslationStatus(TRANSLATION_REQUIRED).build()).build(); + sscsDocs.add(sscsDoc1); + SscsDocument sscsDoc2 = SscsDocument.builder().value(SscsDocumentDetails.builder().documentFileName("sscsDoc2").documentTranslationStatus(TRANSLATION_NOT_REQUIRED).build()).build(); + sscsDocs.add(sscsDoc2); + List dwpDocs = new ArrayList<>(); + DwpDocument dwpDoc1 = DwpDocument.builder().value(DwpDocumentDetails.builder().documentTranslationStatus(TRANSLATION_REQUIRED).build()).build(); + DwpDocument dwpDoc2 = DwpDocument.builder().value(DwpDocumentDetails.builder().build()).build(); + dwpDocs.add(dwpDoc1); + dwpDocs.add(dwpDoc2); + + SscsCaseDetails sscsCaseDetails = SscsCaseDetails.builder().data(SscsCaseData.builder().sscsDocument(sscsDocs).dwpDocuments(dwpDocs).build()).build(); + captor.getValue().accept(sscsCaseDetails); + assertEquals(TRANSLATION_REQUESTED, sscsCaseDetails.getData().getSscsDocument().get(0).getValue().getDocumentTranslationStatus()); + assertNotEquals(TRANSLATION_REQUESTED, sscsCaseDetails.getData().getSscsDocument().get(1).getValue().getDocumentTranslationStatus()); + assertEquals(TRANSLATION_REQUESTED, sscsCaseDetails.getData().getDwpDocuments().get(0).getValue().getDocumentTranslationStatus()); + assertNotEquals(TRANSLATION_REQUESTED, sscsCaseDetails.getData().getDwpDocuments().get(1).getValue().getDocumentTranslationStatus()); } @Test