Skip to content

Commit

Permalink
CIV-16428 JBA Welsh doc (#6032)
Browse files Browse the repository at this point in the history
* CIV-16428 changes

* CIV-16428 changes

* removed added changes

* CIV-16428 changes

* checkstyle fix

* CIV-16428 - code cleanup

* CIV-16428 - added logs for testing

* CIV-16428 removed logs

* CIV-16428 template update

* CIV-16428 changes

* CIV-16428 checkstyle fix

* CIV-16428 welsh template update

---------

Co-authored-by: krishnanuthalapati <32389208+krishnanuthalapati@users.noreply.github.com>
Co-authored-by: Azam <106387766+Azam-Hmcts@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 4, 2025
1 parent d889083 commit 442231a
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.time.LocalDate;
import java.util.List;

@Builder
@Builder(toBuilder = true)
@Getter
@EqualsAndHashCode
public class JudgmentByAdmissionOrDetermination implements MappableObject {
Expand Down Expand Up @@ -61,4 +61,9 @@ public class JudgmentByAdmissionOrDetermination implements MappableObject {
private final String installmentAmount;
private final String payByDate;
private final String applicantReference;
private final String welshDate;
private final String welshPayByDate;
private final String welshRepaymentDate;
private final String welshRepaymentFrequency;
private final String welshPaymentStr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Optional;

import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY;
import static uk.gov.hmcts.reform.civil.utils.DateUtils.formatDateInWelsh;
import static uk.gov.hmcts.reform.civil.utils.JudgmentOnlineUtils.getApplicant;
import static uk.gov.hmcts.reform.civil.utils.JudgmentOnlineUtils.getApplicantSolicitorRef;
import static uk.gov.hmcts.reform.civil.utils.JudgmentOnlineUtils.getOrgDetails;
Expand All @@ -43,6 +44,7 @@ public class JudgmentByAdmissionOrDeterminationMapper {
private final JudgementService judgementService;
private final OrganisationService organisationService;
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMMM yyyy 'at' h:mma");
private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("d MMMM yyyy");

public JudgmentByAdmissionOrDetermination toClaimantResponseForm(CaseData caseData, CaseEvent caseEvent) {
Optional<CaseDataLiP> caseDataLip = Optional.ofNullable(caseData.getCaseDataLiP());
Expand Down Expand Up @@ -236,6 +238,34 @@ public JudgmentByAdmissionOrDetermination toNonDivergentDocs(CaseData caseData)
.build();
}

public JudgmentByAdmissionOrDetermination toNonDivergentWelshDocs(CaseData caseData, JudgmentByAdmissionOrDetermination builder) {
return builder.toBuilder()
.welshDate(formatDateInWelsh(LocalDate.now()))
.welshPayByDate(getWelshPayByDate(caseData))
.welshRepaymentDate(getWelshRepaymentDate(caseData))
.welshRepaymentFrequency(caseData.isPayByInstallment()
? getRepaymentFrequencyInWelsh(caseData.getRespondent1RepaymentPlan().getRepaymentFrequency()) : null)
.welshPaymentStr(caseData.isPayByInstallment() ? getRepaymentWelshString(caseData.getRespondent1RepaymentPlan().getRepaymentFrequency()) : null)
.build();
}

private String getWelshPayByDate(CaseData caseData) {
return caseData.getRespondToClaimAdmitPartLRspec() != null
? formatDateInWelsh(LocalDate.parse(
DateFormatHelper.formatLocalDate(
caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid(),
DateFormatHelper.DATE
), dateTimeFormatter)) : null;
}

private String getWelshRepaymentDate(CaseData caseData) {
return caseData.isPayByInstallment()
? formatDateInWelsh(LocalDate.parse(DateFormatHelper.formatLocalDate(
caseData.getRespondent1RepaymentPlan().getFirstRepaymentDate(),
DateFormatHelper.DATE
), dateTimeFormatter)) : null;
}

private String getRepaymentString(PaymentFrequencyLRspec repaymentFrequency) {
switch (repaymentFrequency) {
case ONCE_ONE_WEEK : return "each week";
Expand All @@ -245,6 +275,15 @@ private String getRepaymentString(PaymentFrequencyLRspec repaymentFrequency) {
}
}

private String getRepaymentWelshString(PaymentFrequencyLRspec repaymentFrequency) {
switch (repaymentFrequency) {
case ONCE_ONE_WEEK : return "pob mis";
case ONCE_ONE_MONTH: return "pob mis";
case ONCE_TWO_WEEKS: return "pob 2 wythnos";
default: return null;
}
}

private String getRepaymentFrequency(PaymentFrequencyLRspec repaymentFrequency) {
switch (repaymentFrequency) {
case ONCE_ONE_WEEK : return "per week";
Expand All @@ -254,6 +293,15 @@ private String getRepaymentFrequency(PaymentFrequencyLRspec repaymentFrequency)
}
}

private String getRepaymentFrequencyInWelsh(PaymentFrequencyLRspec repaymentFrequency) {
switch (repaymentFrequency) {
case ONCE_ONE_WEEK : return "yr wythnos";
case ONCE_ONE_MONTH: return "y mis";
case ONCE_TWO_WEEKS: return "bob pythefnos";
default: return null;
}
}

private String getPaymentTypeForNonDivergent(CaseData caseData) {
if (caseData.getDefenceAdmitPartPaymentTimeRouteRequired() != null
&& caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == IMMEDIATELY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public enum DocmosisTemplates {
DEFAULT_JUDGMENT_COVER_LETTER_DEFENDANT_LEGAL_ORG("CV-CMC-LET-ENG-LR-JO0002.docx", "cover_letter.pdf"),
JUDGMENT_BY_ADMISSION_CLAIMANT("CV-SPC-DEC-ENG-00916.docx", "Judgment_by_admission_claimant.pdf"),
JUDGMENT_BY_ADMISSION_DEFENDANT("CV-SPC-DEC-ENG-00915.docx", "Judgment_by_admission_defendant.pdf"),
JUDGMENT_BY_ADMISSION_CLAIMANT_BILINGUAL("CV-SPC-DEC-WEL-00916.docx", "Judgment_by_admission_claimant.pdf"),
JUDGMENT_BY_ADMISSION_DEFENDANT_BILINGUAL("CV-SPC-DEC-WEL-00915.docx", "Judgment_by_admission_defendant.pdf"),
JUDGMENT_BY_DETERMINATION_CLAIMANT("CV-SPC-DEC-ENG-00982.docx", "Judgment_by_determination_claimant.pdf"),
JUDGMENT_BY_DETERMINATION_DEFENDANT("CV-SPC-DEC-ENG-00981.docx", "Judgment_by_determination_defendant.pdf"),
NOTICE_OF_DISCONTINUANCE_PDF("CV-SPC-GNO-ENG-SD0002.docx", "notice_of_discontinuance_%s.pdf"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@
import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument;
import uk.gov.hmcts.reform.civil.model.docmosis.claimantresponse.JudgmentByAdmissionOrDetermination;
import uk.gov.hmcts.reform.civil.model.docmosis.claimantresponse.JudgmentByAdmissionOrDeterminationMapper;
import uk.gov.hmcts.reform.civil.model.documents.DocumentMetaData;
import uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates;
import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService;
import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator;
import uk.gov.hmcts.reform.civil.stitch.service.CivilStitchService;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.CCJ_REQUEST_ADMISSION;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.CCJ_REQUEST_DETERMINATION;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.JUDGMENT_BY_ADMISSION_CLAIMANT;
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT;
import static uk.gov.hmcts.reform.civil.helpers.hearingsmappings.HearingDetailsMapper.isWelshHearingSelected;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_OR_DETERMINATION;

@Service
Expand All @@ -34,6 +39,7 @@ public class RequestJudgmentByAdmissionOrDeterminationResponseDocGenerator imple
private final JudgmentByAdmissionOrDeterminationMapper judgmentByAdmissionOrDeterminationMapper;
private final DocumentManagementService documentManagementService;
private final DocumentGeneratorService documentGeneratorService;
private final CivilStitchService civilStitchService;
private final AssignCategoryId assignCategoryId;

public CaseDocument generate(CaseEvent caseEvent, CaseData caseData, String authorisation) {
Expand Down Expand Up @@ -75,29 +81,40 @@ private DocumentType getDocumentType(CaseEvent caseEvent) {
};
}

private DocmosisTemplates getTemplateName(CaseEvent caseEvent) {
private DocmosisTemplates getTemplateName(CaseEvent caseEvent, boolean isBilingual) {
if (caseEvent.name().equals(CaseEvent.GEN_JUDGMENT_BY_ADMISSION_DOC_CLAIMANT.name())) {
return DocmosisTemplates.JUDGMENT_BY_ADMISSION_CLAIMANT;
return isBilingual ? DocmosisTemplates.JUDGMENT_BY_ADMISSION_CLAIMANT_BILINGUAL : DocmosisTemplates.JUDGMENT_BY_ADMISSION_CLAIMANT;
} else {
return DocmosisTemplates.JUDGMENT_BY_ADMISSION_DEFENDANT;
return isBilingual ? DocmosisTemplates.JUDGMENT_BY_ADMISSION_DEFENDANT_BILINGUAL : DocmosisTemplates.JUDGMENT_BY_ADMISSION_DEFENDANT;
}
}

public List<CaseDocument> generateNonDivergentDocs(CaseData caseData, String authorisation, CaseEvent caseEvent) {
List<CaseDocument> list = new ArrayList<>();

JudgmentByAdmissionOrDetermination templateData = getTemplateDataForNonDivergentDocs(caseData);
DocmosisDocument docmosisDocument = documentGeneratorService.generateDocmosisDocument(
getTemplateDataForNonDivergentDocs(caseData),
getTemplateName(caseEvent)
templateData,
getTemplateName(caseEvent, false)
);
CaseDocument uploadedDocument = documentManagementService.uploadDocument(
CaseDocument engDocument = documentManagementService.uploadDocument(
authorisation,
new PDF(
getTemplateName(caseEvent).getDocumentTitle(),
getTemplateName(caseEvent, false).getDocumentTitle(),
docmosisDocument.getBytes(),
getDocumentType(caseEvent)
)
);
CaseDocument uploadedDocument = engDocument;
if (caseData.isClaimantBilingual() || isWelshHearingSelected(caseData) || caseData.isRespondentResponseBilingual()) {
uploadedDocument = generateNonDivergentWelshDocs(
caseData,
authorisation,
caseEvent,
templateData,
engDocument
);
}
assignCategoryId.assignCategoryIdToCaseDocument(uploadedDocument, "judgments");
list.add(uploadedDocument);

Expand All @@ -107,4 +124,52 @@ public List<CaseDocument> generateNonDivergentDocs(CaseData caseData, String aut
private JudgmentByAdmissionOrDetermination getTemplateDataForNonDivergentDocs(CaseData caseData) {
return judgmentByAdmissionOrDeterminationMapper.toNonDivergentDocs(caseData);
}

private CaseDocument generateNonDivergentWelshDocs(CaseData caseData, String auth, CaseEvent caseEvent,
JudgmentByAdmissionOrDetermination templateData, CaseDocument englishDoc) {
JudgmentByAdmissionOrDetermination welshTemplateData =
judgmentByAdmissionOrDeterminationMapper.toNonDivergentWelshDocs(caseData, templateData);

DocmosisDocument welshDocument = documentGeneratorService.generateDocmosisDocument(
welshTemplateData,
getTemplateName(caseEvent, true)
);

CaseDocument welshCaseDoc = documentManagementService.uploadDocument(
auth,
new PDF(
getTemplateName(caseEvent, true).getDocumentTitle(),
welshDocument.getBytes(),
getDocumentType(caseEvent)
)
);

List<DocumentMetaData> documentMetaDataList = appendWelshDocToDocument(englishDoc, welshCaseDoc);
Long caseId = caseData.getCcdCaseReference();
return civilStitchService.generateStitchedCaseDocument(
documentMetaDataList,
welshCaseDoc.getDocumentName(),
caseId,
getDocumentType(caseEvent),
auth
);
}

private List<DocumentMetaData> appendWelshDocToDocument(CaseDocument englishDoc, CaseDocument... welshDocuments) {
List<DocumentMetaData> documentMetaDataList = new ArrayList<>();

documentMetaDataList.add(new DocumentMetaData(
englishDoc.getDocumentLink(),
"Welsh Document",
LocalDate.now().toString()
));

Arrays.stream(welshDocuments).forEach(caseDocument -> documentMetaDataList.add(new DocumentMetaData(
caseDocument.getDocumentLink(),
"Welsh Doc to attach",
LocalDate.now().toString()
)));

return documentMetaDataList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDocumentBuilder;
import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService;
import uk.gov.hmcts.reform.civil.stitch.service.CivilStitchService;
import uk.gov.hmcts.reform.civil.utils.AssignCategoryId;

import java.util.List;

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.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_JUDGMENT_BY_ADMISSION_DOC_CLAIMANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_JUDGMENT_BY_ADMISSION_DOC_DEFENDANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_JUDGMENT_BY_DETERMINATION_RESPONSE_DOC;
Expand All @@ -34,6 +39,8 @@
import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.CCJ_REQUEST_DETERMINATION;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_CLAIMANT;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_DEFENDANT;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_CLAIMANT_BILINGUAL;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_DEFENDANT_BILINGUAL;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.JUDGMENT_BY_ADMISSION_OR_DETERMINATION;

@ExtendWith(MockitoExtension.class)
Expand All @@ -55,6 +62,9 @@ class RequestJudgmentByAdmissionOrDeterminationResponseDocGeneratorTest {
@Mock
private AssignCategoryId assignCategoryId;

@Mock
private CivilStitchService civilStitchService;

@InjectMocks
private RequestJudgmentByAdmissionOrDeterminationResponseDocGenerator generator;

Expand Down Expand Up @@ -197,4 +207,91 @@ BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_DEFEND
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT));
assertThat(actual).contains(caseDocument);
}

@Test
void shouldGenerateClaimantJudgementByAdmissionWelshDocument() {
// Given
String fileName = String.format(JUDGMENT_BY_ADMISSION_CLAIMANT.getDocumentTitle(), REFERENCE_NUMBER, "admission");
CaseDocument caseDocument = CaseDocumentBuilder.builder()
.documentName(fileName)
.documentType(DocumentType.JUDGMENT_BY_ADMISSION_CLAIMANT)
.build();
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged()
.claimantBilingualLanguagePreference("BOTH")
.build();
JudgmentByAdmissionOrDetermination builder = JudgmentByAdmissionOrDetermination.builder().build();

when(documentGeneratorService.generateDocmosisDocument(any(JudgmentByAdmissionOrDetermination.class), eq(JUDGMENT_BY_ADMISSION_CLAIMANT)))
.thenReturn(new DocmosisDocument(JUDGMENT_BY_ADMISSION_CLAIMANT.getDocumentTitle(), bytes));

when(documentGeneratorService.generateDocmosisDocument(any(JudgmentByAdmissionOrDetermination.class), eq(JUDGMENT_BY_ADMISSION_CLAIMANT_BILINGUAL)))
.thenReturn(new DocmosisDocument(JUDGMENT_BY_ADMISSION_CLAIMANT_BILINGUAL.getDocumentTitle(), bytes));

when(documentManagementService.uploadDocument(
BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_CLAIMANT))
).thenReturn(caseDocument);

when(judgmentByAdmissionOrDeterminationMapper.toNonDivergentDocs(caseData))
.thenReturn(JudgmentByAdmissionOrDetermination.builder().build());

when(judgmentByAdmissionOrDeterminationMapper.toNonDivergentWelshDocs(caseData, builder))
.thenReturn(JudgmentByAdmissionOrDetermination.builder().build());

when(civilStitchService.generateStitchedCaseDocument(anyList(), any(), anyLong(), eq(DocumentType.JUDGMENT_BY_ADMISSION_CLAIMANT),
anyString())).thenReturn(caseDocument);

// When
// When
List<CaseDocument> actual = generator.generateNonDivergentDocs(caseData, BEARER_TOKEN,
GEN_JUDGMENT_BY_ADMISSION_DOC_CLAIMANT);
// Then
verify(documentManagementService, times(2))
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_CLAIMANT));

verify(assignCategoryId)
.assignCategoryIdToCaseDocument(caseDocument, "judgments");
assertThat(actual).contains(caseDocument);
}

@Test
void shouldGenerateDefendantJudgementByAdmissionWelshDocument() {
// Given
String fileName = String.format(JUDGMENT_BY_ADMISSION_DEFENDANT.getDocumentTitle(), REFERENCE_NUMBER, "admission");
CaseDocument caseDocument = CaseDocumentBuilder.builder()
.documentName(fileName)
.documentType(DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT)
.build();
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged()
.claimantBilingualLanguagePreference("BOTH")
.build();
JudgmentByAdmissionOrDetermination builder = JudgmentByAdmissionOrDetermination.builder().build();

when(documentGeneratorService.generateDocmosisDocument(any(JudgmentByAdmissionOrDetermination.class), eq(JUDGMENT_BY_ADMISSION_DEFENDANT)))
.thenReturn(new DocmosisDocument(JUDGMENT_BY_ADMISSION_DEFENDANT.getDocumentTitle(), bytes));

when(documentGeneratorService.generateDocmosisDocument(any(JudgmentByAdmissionOrDetermination.class), eq(JUDGMENT_BY_ADMISSION_DEFENDANT_BILINGUAL)))
.thenReturn(new DocmosisDocument(JUDGMENT_BY_ADMISSION_DEFENDANT_BILINGUAL.getDocumentTitle(), bytes));

when(documentManagementService.uploadDocument(
BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT))
).thenReturn(caseDocument);

when(judgmentByAdmissionOrDeterminationMapper.toNonDivergentDocs(caseData))
.thenReturn(JudgmentByAdmissionOrDetermination.builder().build());

when(judgmentByAdmissionOrDeterminationMapper.toNonDivergentWelshDocs(caseData, builder))
.thenReturn(JudgmentByAdmissionOrDetermination.builder().build());

when(civilStitchService.generateStitchedCaseDocument(anyList(), any(), anyLong(), eq(DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT),
anyString())).thenReturn(caseDocument);

// When
List<CaseDocument> actual = generator.generateNonDivergentDocs(caseData, BEARER_TOKEN,
GEN_JUDGMENT_BY_ADMISSION_DOC_DEFENDANT);

// Then
verify(documentManagementService, times(2))
.uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, DocumentType.JUDGMENT_BY_ADMISSION_DEFENDANT));
assertThat(actual).contains(caseDocument);
}
}

0 comments on commit 442231a

Please sign in to comment.