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

DTSCCI-1184 response cui form stitching improvement #5891

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
import uk.gov.hmcts.reform.civil.enums.DocCategory;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.documents.DocumentMetaData;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService;
import uk.gov.hmcts.reform.civil.service.docmosis.sealedclaim.SealedClaimLipResponseFormGenerator;
import uk.gov.hmcts.reform.civil.service.stitching.CivilDocumentStitchingService;
import uk.gov.hmcts.reform.civil.stitch.service.CivilStitchService;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;
import uk.gov.hmcts.reform.civil.utils.ElementUtils;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_RESPONSE_CUI_SEALED;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFENDANT_DEFENCE;

@Slf4j
@Service
Expand All @@ -45,7 +43,7 @@ public class GenerateCUIResponseSealedFormCallBackHandler extends CallbackHandle
private final SealedClaimLipResponseFormGenerator formGenerator;
private final SystemGeneratedDocumentService systemGeneratedDocumentService;
private final AssignCategoryId assignCategoryId;
private final CivilDocumentStitchingService civilDocumentStitchingService;
private final CivilStitchService civilStitchService;
private final FeatureToggleService featureToggleService;
@Value("${stitching.enabled}")
private boolean stitchEnabled;
Expand All @@ -66,34 +64,35 @@ public List<CaseEvent> handledEvents() {

private CallbackResponse prepareSealedForm(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
log.info("GENERATE_RESPONSE_CUI_SEALED for case {}", caseData.getCcdCaseReference());
CaseDocument sealedForm = formGenerator.generate(
caseData,
callbackParams.getParams().get(BEARER_TOKEN).toString()
);
log.info("sealedForm for case {}", caseData.getCcdCaseReference());
Long caseId = caseData.getCcdCaseReference();

log.info("Generating response cui sealed form for case {}", caseId);
String authToken = callbackParams.getParams().get(CallbackParams.Params.BEARER_TOKEN).toString();
CaseDocument sealedForm = formGenerator.generate(caseData, authToken);

CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();

log.info("isLipvLipOneVOne {} isLipVLipEnabled {} for case {}", caseData.isLipvLipOneVOne(),
featureToggleService.isLipVLipEnabled(), caseData.getCcdCaseReference());
featureToggleService.isLipVLipEnabled(), caseId);

if (stitchEnabled && caseData.isLipvLipOneVOne() && featureToggleService.isLipVLipEnabled()) {
log.info("if condition for case {}", caseData.getCcdCaseReference());
log.info("if condition for case {}", caseId);
List<DocumentMetaData> documentMetaDataList = fetchDocumentsToStitch(caseData, sealedForm);
if (documentMetaDataList.size() > 1) {
log.info("documentMetaDataList {} for case {}", documentMetaDataList.size(), caseData.getCcdCaseReference());
CaseDocument stitchedDocument = civilDocumentStitchingService.bundle(
documentMetaDataList,
callbackParams.getParams().get(CallbackParams.Params.BEARER_TOKEN).toString(),
sealedForm.getDocumentName(),
sealedForm.getDocumentName(),
caseData
);
log.info("stitched complete for case {}", caseData.getCcdCaseReference());
CaseDocument updatedStitchedDoc = stitchedDocument.toBuilder().documentType(DEFENDANT_DEFENCE).build();
caseDataBuilder.respondent1ClaimResponseDocumentSpec(updatedStitchedDoc)
.systemGeneratedCaseDocuments(systemGeneratedDocumentService.getSystemGeneratedDocumentsWithAddedDocument(
updatedStitchedDoc,
caseData
));
log.info("Calling civil stitch service from response cui sealed form for caseId {}", caseId);

CaseDocument stitchedDocument =
civilStitchService.generateStitchedCaseDocument(documentMetaDataList,
sealedForm.getDocumentName(),
caseId,
DocumentType.DEFENDANT_DEFENCE,
authToken);
log.info("Civil stitch service for response cui sealed form {} for caseId {}", stitchedDocument, caseId);

caseDataBuilder.respondent1ClaimResponseDocumentSpec(stitchedDocument)
.systemGeneratedCaseDocuments(systemGeneratedDocumentService.getSystemGeneratedDocumentsWithAddedDocument(
stitchedDocument, caseData));

assignCategoryId.assignCategoryIdToCaseDocument(stitchedDocument, DocCategory.DEF1_DEFENSE_DQ.getValue());
} else {
log.info("Inner else condition for case {}", caseData.getCcdCaseReference());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand All @@ -21,7 +20,7 @@
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService;
import uk.gov.hmcts.reform.civil.service.docmosis.sealedclaim.SealedClaimLipResponseFormGenerator;
import uk.gov.hmcts.reform.civil.service.stitching.CivilDocumentStitchingService;
import uk.gov.hmcts.reform.civil.stitch.service.CivilStitchService;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;

import java.time.LocalDateTime;
Expand All @@ -30,7 +29,10 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
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 org.mockito.Mockito.when;
Expand All @@ -54,7 +56,7 @@ class GenerateCUIResponseSealedFormCallBackHandlerTest extends BaseCallbackHandl
@Mock
private SystemGeneratedDocumentService systemGeneratedDocumentService;
@Mock
private CivilDocumentStitchingService civilDocumentStitchingService;
private CivilStitchService civilStitchService;
@Mock
private FeatureToggleService featureToggleService;

Expand All @@ -65,7 +67,7 @@ class GenerateCUIResponseSealedFormCallBackHandlerTest extends BaseCallbackHandl
void setUp() {
mapper = new ObjectMapper();
handler = new GenerateCUIResponseSealedFormCallBackHandler(mapper, formGenerator, systemGeneratedDocumentService,
assignCategoryId, civilDocumentStitchingService, featureToggleService);
assignCategoryId, civilStitchService, featureToggleService);
mapper.registerModule(new JavaTimeModule());
}

Expand Down Expand Up @@ -141,12 +143,13 @@ void shouldGenerateForm_whenIsLipVLipEnabledStitchingEnabled() {
element(CaseDocument.builder().documentName("Stitched document").build()),
element(CaseDocument.builder().documentName("document name").build()));
given(systemGeneratedDocumentService.getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class))).willReturn(documents);
when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), any(CaseData.class)))
.thenReturn(STITCHED_DOC);
when(civilStitchService.generateStitchedCaseDocument(anyList(), anyString(), anyLong(), eq(DEFENDANT_DEFENCE),
anyString())).thenReturn(STITCHED_DOC);
given(formGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM);
List<Element<CaseDocument>> systemGeneratedCaseDocuments = new ArrayList<>();
systemGeneratedCaseDocuments.add(element(DIRECTIONS_QUESTIONNAIRE_DOC));
CaseData caseData = CaseDataBuilder.builder()
.ccdCaseReference(1L)
.applicant1Represented(YesOrNo.NO)
.respondent1Represented(YesOrNo.NO)
.systemGeneratedCaseDocuments(systemGeneratedCaseDocuments).build();
Expand Down
Loading