Skip to content

Commit

Permalink
SSCSSI-421: corrected translation reuested
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayparekh-hmcts committed Nov 15, 2024
1 parent 32cc4ff commit 60991be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SscsCaseData> {
Expand Down Expand Up @@ -57,15 +62,24 @@ public void handle(CallbackType callbackType, Callback<SscsCaseData> 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<? extends AbstractDocument> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -54,7 +57,7 @@ public class RequestTranslationCallbackHandlerTest {
private RequestTranslationCallbackHandler handler;

@Captor
ArgumentCaptor<SscsCaseData> captor;
ArgumentCaptor<Consumer<SscsCaseDetails>> captor;

@Before
public void setUp() {
Expand Down Expand Up @@ -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<SscsDocument> 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<DwpDocument> 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
Expand Down

0 comments on commit 60991be

Please sign in to comment.