Skip to content

Commit

Permalink
SSCSSI-421: use triggerV2 (#4122)
Browse files Browse the repository at this point in the history
* SSCSSI-421: use triggerV2

* SSCSSI-421: corrected translation reuested

* SSCSSI-421: corrected checkstyles

* SSCSSI-421: corrected checkstyles2

---------

Co-authored-by: gokul <69240498+gokul-sol@users.noreply.github.com>
  • Loading branch information
sanjayparekh-hmcts and gokul-sol authored Nov 27, 2024
1 parent 71e6eeb commit ba861e0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.CASE_UPDATED;
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.REQUEST_TRANSLATION_FROM_WLU;

import java.util.List;
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.service.CcdService;
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;
Expand All @@ -23,15 +27,15 @@ public class RequestTranslationCallbackHandler implements CallbackHandler<SscsCa

private final RequestTranslationService requestTranslationService;
private final DispatchPriority dispatchPriority;
private final CcdService ccdService;
private final UpdateCcdCaseService updateCcdCaseService;
private final IdamService idamService;

@Autowired
public RequestTranslationCallbackHandler(RequestTranslationService requestTranslationService,
CcdService ccdService,
UpdateCcdCaseService updateCcdCaseService,
IdamService idamService) {
this.requestTranslationService = requestTranslationService;
this.ccdService = ccdService;
this.updateCcdCaseService = updateCcdCaseService;
this.idamService = idamService;
this.dispatchPriority = DispatchPriority.EARLIEST;
}
Expand All @@ -57,15 +61,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) {
ccdService.updateCase(callback.getCaseDetails().getCaseData(), 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,14 @@
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.List;
import java.util.Optional;
import java.util.function.Consumer;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Before;
Expand All @@ -25,11 +29,8 @@
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.service.CcdService;
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;
import uk.gov.hmcts.reform.sscs.idam.IdamService;
Expand All @@ -43,7 +44,7 @@ public class RequestTranslationCallbackHandlerTest {
private Callback<SscsCaseData> callback;

@Mock
private CcdService ccdCaseService;
private UpdateCcdCaseService updateCcdCaseService;

@Mock
private IdamService idamService;
Expand All @@ -54,11 +55,11 @@ public class RequestTranslationCallbackHandlerTest {
private RequestTranslationCallbackHandler handler;

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

@Before
public void setUp() {
handler = new RequestTranslationCallbackHandler(requestTranslationService, ccdCaseService, idamService);
handler = new RequestTranslationCallbackHandler(requestTranslationService, updateCcdCaseService, idamService);

}

Expand Down Expand Up @@ -95,7 +96,25 @@ public void requestTranslationForWelshCase() {
handler.handle(SUBMITTED, callback);

verify(requestTranslationService).sendCaseToWlu(any());
verify(ccdCaseService).updateCase(captor.capture(), 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 ba861e0

Please sign in to comment.