From 0349352741fc15af7cd8854803d77397ce953ff7 Mon Sep 17 00:00:00 2001 From: Liban Abdirahman Date: Mon, 13 Jul 2026 17:11:19 +0100 Subject: [PATCH 1/4] HDPI-6639: Persisting general application paper & related evidence docs --- .../reform/pcs/ccd/domain/DocumentType.java | 1 + .../hmcts/reform/pcs/ccd/domain/PCSCase.java | 7 ++ .../domain/caseworker/EnterGenAppRequest.java | 10 +++ .../caseworker/entergenapp/EnterGenApp.java | 3 +- .../entergenapp/UploadGeneralApplication.java | 14 +--- .../entergenapp/UploadRelatedEvidence.java | 17 ++--- .../ccd/service/document/DocumentService.java | 2 + .../pcs/ccd/service/genapp/GenAppService.java | 73 +++++++++++++++++++ 8 files changed, 102 insertions(+), 25 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/DocumentType.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/DocumentType.java index 2ebad4bcf0..b169a92189 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/DocumentType.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/DocumentType.java @@ -34,6 +34,7 @@ public enum DocumentType implements HasLabel { ELECTRICAL_INSTALLATION_CONDITION("Electrical installation condition"), DEFENDANT_RESPONSE("Defendant response"), COUNTERCLAIM("Counterclaim"), + GENERAL_APPLICATION("General application"), OTHER("Other document"); private final String label; diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java index bd56f2ea98..1bf65f2219 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java @@ -735,4 +735,11 @@ public class PCSCase { @CCD private String dateIssuedString; + + @CCD( + label = "Add document", + hint = "Upload a document to the system", + searchable = false + ) + private Document uploadSingleDocument; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/caseworker/EnterGenAppRequest.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/caseworker/EnterGenAppRequest.java index cd7e33bd7a..34de40a988 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/caseworker/EnterGenAppRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/caseworker/EnterGenAppRequest.java @@ -7,12 +7,15 @@ import lombok.Data; import lombok.NoArgsConstructor; import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.Document; import uk.gov.hmcts.ccd.sdk.type.FieldType; +import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.reform.pcs.ccd.annotation.JacksonMoneyGBP; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import java.math.BigDecimal; import java.time.LocalDate; +import java.util.List; import static uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase.MAX_MONETARY_AMOUNT; @@ -57,4 +60,11 @@ public class EnterGenAppRequest { ) private String hwfReference; + @CCD( + label = "Add document", + hint = "Upload a document to the system", + searchable = false + ) + private List> relatedEvidence; + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java index b7164cb74c..5153e23eec 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java @@ -109,7 +109,8 @@ private SubmitResponse submit(EventPayload eventPayload) caseData.getPartyRadioList().getValueCode(), caseReference); genAppService.createGenAppEntity( - caseData.getEnterGenAppRequest(), pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED); + caseData.getEnterGenAppRequest(), caseData.getUploadSingleDocument(), + pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED); return SubmitResponse.builder().build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadGeneralApplication.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadGeneralApplication.java index 6fd6c70a07..9310f9af96 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadGeneralApplication.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadGeneralApplication.java @@ -2,27 +2,17 @@ import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; public class UploadGeneralApplication implements CcdPageConfiguration { - private static final String PLACEHOLDER_BANNER = """ -
-
-

- Placeholder -

-
-
- """; - @Override public void addTo(PageBuilder pageBuilder) { pageBuilder .page("uploadGeneralApplication") .pageLabel("Upload general application") .label("uploadGeneralApplication-lineSeparator", "---") - .label("uploadGeneralApplication-placeholder", PLACEHOLDER_BANNER); + .mandatory(PCSCase::getUploadSingleDocument); } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadRelatedEvidence.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadRelatedEvidence.java index 5da267d493..8d15a88386 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadRelatedEvidence.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/caseworker/entergenapp/UploadRelatedEvidence.java @@ -2,27 +2,20 @@ import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.caseworker.EnterGenAppRequest; public class UploadRelatedEvidence implements CcdPageConfiguration { - private static final String PLACEHOLDER_BANNER = """ -
-
-

- Placeholder -

-
-
- """; - @Override public void addTo(PageBuilder pageBuilder) { pageBuilder .page("uploadRelatedEvidence") .pageLabel("Upload related evidence") .label("uploadRelatedEvidence-lineSeparator", "---") - .label("uploadRelatedEvidence-placeholder", PLACEHOLDER_BANNER); + .complex(PCSCase::getEnterGenAppRequest) + .optional(EnterGenAppRequest::getRelatedEvidence) + .done(); } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentService.java index a0a274e389..8cbad07884 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentService.java @@ -405,6 +405,8 @@ private Optional mapDocumentTypeToCategory(DocumentType docume case CERTIFICATE_OF_SUITABILITY_AS_LF, LEGAL_AID_CERTIFICATE -> Optional.of(CaseFileCategory.CORRESPONDENCE); + case GENERAL_APPLICATION -> + Optional.of(CaseFileCategory.APPLICATIONS); case NOTICE_SERVED, POLICE_REPORT, // Defendant access-code letters aren't shown on the case file diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java index 792e437950..3019a3c184 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java @@ -1,9 +1,12 @@ package uk.gov.hmcts.reform.pcs.ccd.service.genapp; +import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; +import uk.gov.hmcts.ccd.sdk.type.Document; import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.reform.pcs.ccd.domain.CaseFileCategory; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.UploadedDocument; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.caseworker.EnterGenAppRequest; @@ -33,6 +36,8 @@ @Service public class GenAppService { + private static final String GENERAL_APPLICATION_FILENAME = "General Application"; + private final GenAppRepository genAppRepository; private final DocumentService documentService; private final DocumentNameService documentNameService; @@ -123,6 +128,7 @@ public GenAppEntity createGenAppEntity(GenAppRequest genAppRequest, } public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest, + Document uploadedGenApp, PcsCaseEntity pcsCaseEntity, PartyEntity applicantParty, GenAppState initialState) { @@ -131,6 +137,7 @@ public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest, .type(enterGenAppRequest.getApplicationTypeOption().getStandardGenAppType()) .party(applicantParty) .applicationReceivedDate(enterGenAppRequest.getDateReceived()) + .applicationSubmittedDate(LocalDateTime.now(utcClock)) .within14Days(enterGenAppRequest.getWithin14Days()) .state(initialState) .feeAmountReceived(enterGenAppRequest.getFeeAmountReceived()) @@ -151,9 +158,75 @@ public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest, genAppEntity.setHelpWithFeesEntity(helpWithFeesEntity); } + DocumentEntity submissionDocument = createDocumentEntity(uploadedGenApp, pcsCaseEntity, + genAppEntity, applicantParty.getId()); + genAppEntity.setSubmissionDocument(submissionDocument); + + List additionalEvidenceDocuments = createRelatedEvidenceDocumentEntities( + enterGenAppRequest.getRelatedEvidence(), pcsCaseEntity, genAppEntity, applicantParty.getId()); + genAppEntity.setDocuments(additionalEvidenceDocuments); + genAppRepository.save(genAppEntity); } + private DocumentEntity createDocumentEntity(Document document, + PcsCaseEntity pcsCaseEntity, + GenAppEntity genAppEntity, + UUID applicantPartyId) { + + if (document == null) { + return null; + } + + ClaimEntity mainClaimEntity = pcsCaseEntity.getClaims().getFirst(); + String extension = FilenameUtils.getExtension(document.getFilename()); + String newFileName = GENERAL_APPLICATION_FILENAME + "." + extension; + String renamedFilename = documentNameService + .appendGenAppPostfix(newFileName, genAppEntity, mainClaimEntity, applicantPartyId); + + DocumentEntity documentEntity = DocumentEntity.builder() + .pcsCase(pcsCaseEntity) + .generalApplication(genAppEntity) + .url(document.getUrl()) + .fileName(renamedFilename) + .binaryUrl(document.getBinaryUrl()) + .categoryId(CaseFileCategory.APPLICATIONS.getId()) + .type(DocumentType.GENERAL_APPLICATION) + .build(); + + return documentRepository.save(documentEntity); + } + + private List createRelatedEvidenceDocumentEntities( + List> relatedEvidenceDocuments, PcsCaseEntity pcsCaseEntity, GenAppEntity genAppEntity, + UUID applicantPartyId) { + + if (relatedEvidenceDocuments == null) { + return List.of(); + } + + ClaimEntity mainClaimEntity = pcsCaseEntity.getClaims().getFirst(); + + List documentEntities = relatedEvidenceDocuments.stream() + .map(ListValue::getValue) + .map(document -> { + String renamedFilename = documentNameService + .appendGenAppPostfix(document.getFilename(), genAppEntity, mainClaimEntity, applicantPartyId); + + return DocumentEntity.builder() + .pcsCase(pcsCaseEntity) + .generalApplication(genAppEntity) + .url(document.getUrl()) + .fileName(renamedFilename) + .binaryUrl(document.getBinaryUrl()) + .type(DocumentType.OTHER) + .build(); + }) + .toList(); + + return documentRepository.saveAll(documentEntities); + } + private List createDocumentEntities(List> uploadedDocuments, PcsCaseEntity pcsCaseEntity, GenAppEntity genAppEntity, From 9d9735e231fb691e9217200bae0a6ae63845e261 Mon Sep 17 00:00:00 2001 From: Liban Abdirahman Date: Mon, 13 Jul 2026 17:13:44 +0100 Subject: [PATCH 2/4] HDPI-6639: Adding test coverage --- .../entergenapp/EnterGenAppTest.java | 2 +- .../ccd/service/genapp/GenAppServiceTest.java | 141 ++++++++++++++++-- 2 files changed, 132 insertions(+), 11 deletions(-) diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java index 8d6332782c..65c7c4e495 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java @@ -143,7 +143,7 @@ void shouldCreateGenAppEntityOnSubmit() { // Then verify(genAppService) - .createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + .createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); } } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java index c28bf7c9c2..97177831a8 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java @@ -64,6 +64,7 @@ import static org.mockito.Mock.Strictness.LENIENT; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppState.GEN_APP_ISSUED; @@ -94,6 +95,8 @@ class GenAppServiceTest { @Captor private ArgumentCaptor genAppEntityCaptor; @Captor + private ArgumentCaptor documentEntityCaptor; + @Captor private ArgumentCaptor> documentEntityListCaptor; private GenAppService underTest; @@ -673,7 +676,7 @@ void shouldAddCreatedEntityToCase() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then verify(pcsCaseEntity).addGenApp(genAppEntityCaptor.capture()); @@ -690,7 +693,7 @@ void shouldSetGenAppType(EnterGenAppType enterGenAppType) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -706,7 +709,7 @@ void shouldSetSomethingElseDetailsForSomethingElseType() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -724,7 +727,7 @@ void shouldNotSetSomethingElseDetailsIfNotSomethingElseType(EnterGenAppType ente .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -740,7 +743,7 @@ void shouldSetGenAppState(GenAppState genAppState) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, genAppState); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, genAppState); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -757,7 +760,7 @@ void shouldSetApplicationReceivedDate() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -774,7 +777,7 @@ void shouldSetWithin14DaysFlag(VerticalYesNo within14Days) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -792,7 +795,7 @@ void shouldSetFeeAmountReceived() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -811,7 +814,7 @@ void shouldSetHwfFlagAndReferenceWhenYes() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -831,7 +834,7 @@ void shouldSetHwfFlagButNotReferenceWhenNo() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -839,6 +842,124 @@ void shouldSetHwfFlagButNotReferenceWhenNo() { assertThat(genAppEntity.getHelpWithFeesEntity()).isNull(); } + @Test + void shouldSaveUploadedGenAppAsSubmissionDocument() { + // Given + UUID applicantPartyId = UUID.randomUUID(); + when(applicantParty.getId()).thenReturn(applicantPartyId); + + String renamedFilename = "General Application GA1 - Claimant 1.docx"; + when(documentNameService.appendGenAppPostfix(eq("General Application.docx"), isA(GenAppEntity.class), + eq(mainClaim), eq(applicantPartyId) + )) + .thenReturn(renamedFilename); + + DocumentEntity savedDocumentEntity = mock(DocumentEntity.class); + when(documentRepository.save(isA(DocumentEntity.class))).thenReturn(savedDocumentEntity); + + EnterGenAppRequest enterGenAppRequest = EnterGenAppRequest.builder() + .applicationTypeOption(EnterGenAppType.SET_ASIDE) + .build(); + + Document uploadedGenApp = Document.builder() + .filename("my application.docx") + .url("test url") + .binaryUrl("test binary url") + .build(); + + // When + underTest.createGenAppEntity(enterGenAppRequest, uploadedGenApp, pcsCaseEntity, applicantParty, + GEN_APP_ISSUED); + + // Then + GenAppEntity genAppEntity = getSavedGenAppEntity(); + assertThat(genAppEntity.getSubmissionDocument()).isEqualTo(savedDocumentEntity); + + verify(documentRepository).save(documentEntityCaptor.capture()); + DocumentEntity documentEntity = documentEntityCaptor.getValue(); + assertThat(documentEntity.getFileName()).isEqualTo(renamedFilename); + assertThat(documentEntity.getUrl()).isEqualTo("test url"); + assertThat(documentEntity.getBinaryUrl()).isEqualTo("test binary url"); + assertThat(documentEntity.getType()).isEqualTo(DocumentType.GENERAL_APPLICATION); + assertThat(documentEntity.getCategoryId()).isEqualTo(CaseFileCategory.APPLICATIONS.getId()); + } + + @Test + void shouldNotSaveSubmissionDocumentWhenUploadedGenAppIsNull() { + // Given + EnterGenAppRequest enterGenAppRequest = EnterGenAppRequest.builder() + .applicationTypeOption(EnterGenAppType.SET_ASIDE) + .build(); + + // When + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + + // Then + GenAppEntity genAppEntity = getSavedGenAppEntity(); + assertThat(genAppEntity.getSubmissionDocument()).isNull(); + verify(documentRepository, never()).save(any(DocumentEntity.class)); + } + + @Test + void shouldSaveRelatedEvidenceDocuments() { + // Given + Document evidenceDocument = Document.builder() + .filename("circumstance statement.docx") + .url("evidence url") + .binaryUrl("evidence binary url") + .build(); + + UUID applicantPartyId = UUID.randomUUID(); + when(applicantParty.getId()).thenReturn(applicantPartyId); + + String renamedFilename = "circumstance statement GA1 - Claimant 1.docx"; + when(documentNameService.appendGenAppPostfix(eq("circumstance statement.docx"), isA(GenAppEntity.class), + eq(mainClaim), eq(applicantPartyId) + )) + .thenReturn(renamedFilename); + + List savedDocumentEntities = List.of(mock(DocumentEntity.class)); + when(documentRepository.saveAll(anyList())).thenReturn(savedDocumentEntities); + + EnterGenAppRequest enterGenAppRequest = EnterGenAppRequest.builder() + .applicationTypeOption(EnterGenAppType.SET_ASIDE) + .relatedEvidence(List.of(ListValue.builder().value(evidenceDocument).build())) + .build(); + + // When + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + + // Then + GenAppEntity genAppEntity = getSavedGenAppEntity(); + assertThat(genAppEntity.getDocuments()).isEqualTo(savedDocumentEntities); + + verify(documentRepository).saveAll(documentEntityListCaptor.capture()); + assertThat(documentEntityListCaptor.getValue()).hasSize(1); + DocumentEntity documentEntity = documentEntityListCaptor.getValue().getFirst(); + assertThat(documentEntity.getFileName()).isEqualTo(renamedFilename); + assertThat(documentEntity.getUrl()).isEqualTo("evidence url"); + assertThat(documentEntity.getBinaryUrl()).isEqualTo("evidence binary url"); + assertThat(documentEntity.getType()).isEqualTo(DocumentType.OTHER); + assertThat(documentEntity.getCategoryId()).isNull(); + } + + @Test + void shouldNotSaveRelatedEvidenceDocumentsWhenListIsNull() { + // Given + EnterGenAppRequest enterGenAppRequest = EnterGenAppRequest.builder() + .applicationTypeOption(EnterGenAppType.SET_ASIDE) + .relatedEvidence(null) + .build(); + + // When + underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + + // Then + GenAppEntity genAppEntity = getSavedGenAppEntity(); + assertThat(genAppEntity.getDocuments()).isEmpty(); + verify(documentRepository, never()).saveAll(anyList()); + } + } private GenAppEntity getSavedGenAppEntity() { From 1c94c5470990bac9af3a49dec2afd590ab4ab209 Mon Sep 17 00:00:00 2001 From: Liban Abdirahman Date: Tue, 14 Jul 2026 10:31:51 +0100 Subject: [PATCH 3/4] HDPI-6639:Minor refactoring --- .../caseworker/entergenapp/EnterGenApp.java | 4 +- .../pcs/ccd/service/genapp/GenAppService.java | 13 ++-- .../entergenapp/EnterGenAppTest.java | 2 +- .../ccd/service/genapp/GenAppServiceTest.java | 62 ++++++++++++++----- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java index 5153e23eec..a6fcdadbcb 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenApp.java @@ -108,9 +108,7 @@ private SubmitResponse submit(EventPayload eventPayload) PartyEntity applicantParty = partyService.getPartyEntityByEntityId( caseData.getPartyRadioList().getValueCode(), caseReference); - genAppService.createGenAppEntity( - caseData.getEnterGenAppRequest(), caseData.getUploadSingleDocument(), - pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED); + genAppService.createGenAppEntity(caseData, pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED); return SubmitResponse.builder().build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java index 3019a3c184..5531b76159 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java @@ -7,6 +7,7 @@ import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.reform.pcs.ccd.domain.CaseFileCategory; import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.UploadedDocument; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.caseworker.EnterGenAppRequest; @@ -127,11 +128,12 @@ public GenAppEntity createGenAppEntity(GenAppRequest genAppRequest, return genAppRepository.save(genAppEntity); } - public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest, - Document uploadedGenApp, - PcsCaseEntity pcsCaseEntity, - PartyEntity applicantParty, - GenAppState initialState) { + public void createGenAppEntity(PCSCase caseData, + PcsCaseEntity pcsCaseEntity, + PartyEntity applicantParty, + GenAppState initialState) { + + EnterGenAppRequest enterGenAppRequest = caseData.getEnterGenAppRequest(); GenAppEntity genAppEntity = GenAppEntity.builder() .type(enterGenAppRequest.getApplicationTypeOption().getStandardGenAppType()) @@ -158,6 +160,7 @@ public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest, genAppEntity.setHelpWithFeesEntity(helpWithFeesEntity); } + Document uploadedGenApp = caseData.getUploadSingleDocument(); DocumentEntity submissionDocument = createDocumentEntity(uploadedGenApp, pcsCaseEntity, genAppEntity, applicantParty.getId()); genAppEntity.setSubmissionDocument(submissionDocument); diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java index 65c7c4e495..ab8629be88 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/caseworker/entergenapp/EnterGenAppTest.java @@ -143,7 +143,7 @@ void shouldCreateGenAppEntityOnSubmit() { // Then verify(genAppService) - .createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + .createGenAppEntity(caseData, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); } } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java index 8041cb34c0..08796d4c6b 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java @@ -22,6 +22,7 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.CaseFileCategory; import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.LanguageUsed; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.UploadedDocument; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.caseworker.EnterGenAppRequest; @@ -676,7 +677,9 @@ void shouldAddCreatedEntityToCase() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then verify(pcsCaseEntity).addGenApp(genAppEntityCaptor.capture()); @@ -692,7 +695,9 @@ void shouldSetApplicationSubmittedDate() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest,null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -708,7 +713,9 @@ void shouldSetGenAppType(EnterGenAppType enterGenAppType) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -724,7 +731,9 @@ void shouldSetSomethingElseDetailsForSomethingElseType() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -742,7 +751,9 @@ void shouldNotSetSomethingElseDetailsIfNotSomethingElseType(EnterGenAppType ente .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -758,7 +769,9 @@ void shouldSetGenAppState(GenAppState genAppState) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, genAppState); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, genAppState); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -775,7 +788,9 @@ void shouldSetApplicationReceivedDate() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -792,7 +807,9 @@ void shouldSetWithin14DaysFlag(VerticalYesNo within14Days) { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -810,7 +827,9 @@ void shouldSetFeeAmountReceived() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -829,7 +848,9 @@ void shouldSetHwfFlagAndReferenceWhenYes() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -849,7 +870,9 @@ void shouldSetHwfFlagButNotReferenceWhenNo() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -883,8 +906,9 @@ void shouldSaveUploadedGenAppAsSubmissionDocument() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, uploadedGenApp, pcsCaseEntity, applicantParty, - GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).uploadSingleDocument(uploadedGenApp).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -907,7 +931,9 @@ void shouldNotSaveSubmissionDocumentWhenUploadedGenAppIsNull() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -942,7 +968,9 @@ void shouldSaveRelatedEvidenceDocuments() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); @@ -967,7 +995,9 @@ void shouldNotSaveRelatedEvidenceDocumentsWhenListIsNull() { .build(); // When - underTest.createGenAppEntity(enterGenAppRequest, null, pcsCaseEntity, applicantParty, GEN_APP_ISSUED); + underTest.createGenAppEntity( + PCSCase.builder().enterGenAppRequest(enterGenAppRequest).build(), + pcsCaseEntity, applicantParty, GEN_APP_ISSUED); // Then GenAppEntity genAppEntity = getSavedGenAppEntity(); From 98c0ffdedd5d459ecd75db80e4f1d65d4fc8bc70 Mon Sep 17 00:00:00 2001 From: Liban Abdirahman Date: Tue, 14 Jul 2026 15:47:57 +0100 Subject: [PATCH 4/4] HDPI-6639:Actioning review comments --- .../pcs/ccd/service/genapp/GenAppService.java | 73 +++++++++---------- .../ccd/service/genapp/GenAppServiceTest.java | 2 +- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java index 5531b76159..6584f323b4 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java @@ -161,21 +161,23 @@ public void createGenAppEntity(PCSCase caseData, } Document uploadedGenApp = caseData.getUploadSingleDocument(); - DocumentEntity submissionDocument = createDocumentEntity(uploadedGenApp, pcsCaseEntity, - genAppEntity, applicantParty.getId()); + DocumentEntity submissionDocument = createSubmissionDocumentEntity( + uploadedGenApp, pcsCaseEntity, genAppEntity, applicantParty.getId() + ); genAppEntity.setSubmissionDocument(submissionDocument); List additionalEvidenceDocuments = createRelatedEvidenceDocumentEntities( - enterGenAppRequest.getRelatedEvidence(), pcsCaseEntity, genAppEntity, applicantParty.getId()); + enterGenAppRequest.getRelatedEvidence(), pcsCaseEntity, genAppEntity, applicantParty.getId() + ); genAppEntity.setDocuments(additionalEvidenceDocuments); genAppRepository.save(genAppEntity); } - private DocumentEntity createDocumentEntity(Document document, - PcsCaseEntity pcsCaseEntity, - GenAppEntity genAppEntity, - UUID applicantPartyId) { + private DocumentEntity createSubmissionDocumentEntity(Document document, + PcsCaseEntity pcsCaseEntity, + GenAppEntity genAppEntity, + UUID applicantPartyId) { if (document == null) { return null; @@ -187,15 +189,8 @@ private DocumentEntity createDocumentEntity(Document document, String renamedFilename = documentNameService .appendGenAppPostfix(newFileName, genAppEntity, mainClaimEntity, applicantPartyId); - DocumentEntity documentEntity = DocumentEntity.builder() - .pcsCase(pcsCaseEntity) - .generalApplication(genAppEntity) - .url(document.getUrl()) - .fileName(renamedFilename) - .binaryUrl(document.getBinaryUrl()) - .categoryId(CaseFileCategory.APPLICATIONS.getId()) - .type(DocumentType.GENERAL_APPLICATION) - .build(); + DocumentEntity documentEntity = buildDocumentEntity(document, pcsCaseEntity, genAppEntity, renamedFilename, + CaseFileCategory.APPLICATIONS.getId(), DocumentType.GENERAL_APPLICATION); return documentRepository.save(documentEntity); } @@ -216,14 +211,8 @@ private List createRelatedEvidenceDocumentEntities( String renamedFilename = documentNameService .appendGenAppPostfix(document.getFilename(), genAppEntity, mainClaimEntity, applicantPartyId); - return DocumentEntity.builder() - .pcsCase(pcsCaseEntity) - .generalApplication(genAppEntity) - .url(document.getUrl()) - .fileName(renamedFilename) - .binaryUrl(document.getBinaryUrl()) - .type(DocumentType.OTHER) - .build(); + return buildDocumentEntity(document, pcsCaseEntity, genAppEntity, renamedFilename, + null, null); }) .toList(); @@ -248,23 +237,33 @@ private List createDocumentEntities(List