Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ tasks.withType(CftlibExec).configureEach {
environment 'SPRING_PROFILES_ACTIVE', 'dev'
environment 'XUI_JURISDICTIONS', 'PCS'
environment 'XUI_DOCUMENTS_API_V2', 'http://ccd-case-document-am-api-aat.service.core-compute-aat.internal'
environment 'CASE_DOCUMENT_S2S_AUTHORISED_SERVICES', 'ccd_case_document_am_api,ccd_gw,xui_webapp,ccd_data,pcs_frontend,pcs_api'
environment 'DATA_STORE_S2S_AUTHORISED_SERVICES', 'ccd_data,ccd_gw,pcs_frontend,pcs_api'
environment 'CCD_S2S-AUTHORISED_SERVICES_CASE_USER_ROLES', 'aac_manage_case_assignment,pcs_api'
}
Expand Down
1 change: 1 addition & 0 deletions charts/pcs-api/values.ccd.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ ccd-case-document-am-api:
S2S_URL: http://rpe-service-auth-provider-aat.service.core-compute-aat.internal
DM_STORE_BASE_URL: http://dm-store-aat.service.core-compute-aat.internal
CCD_DATA_STORE_API_BASE_URL: http://${SERVICE_NAME}-ccd-data-store-api
CASE_DOCUMENT_S2S_AUTHORISED_SERVICES: ccd_case_document_am_api,ccd_gw,xui_webapp,ccd_data,bulk_scan_processor,sscs,probate_backend,iac,em_npa_app,fprl_dgs_api,dg_docassembly_api,em_stitching_api,em_ccd_orchestrator,cmc_claim_store,civil_service,bulk_scan_orchestrator,ethos_repl_service,divorce_document_generator,finrem_document_generator,finrem_case_orchestration,fpl_case_service,et_cos,prl_cos_api,prl_dgs_api,et_sya_api,adoption_cos_api,adoption_web,nfdiv_case_api,divorce_frontend,sptribs_case_api,sptribs_dss_backend,civil_general_applications,pcs_api,pcs_frontend
keyVaults:
ccd:
secrets:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.gov.hmcts.reform.pcs.ccd.service.document;

import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.ClaimPartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyRole;
import uk.gov.hmcts.reform.pcs.exception.PartyNotFoundException;

import java.util.UUID;

@Service
public class DocumentNameService {

public String appendGenAppPostfix(String originalFilename,
GenAppEntity genAppEntity,
ClaimEntity mainClaim,
UUID applicantPartyId) {

if (originalFilename == null) {
return null;
}

String baseName = FilenameUtils.getBaseName(originalFilename);
String extension = FilenameUtils.getExtension(originalFilename);

// Example label: General Application (GA2) - Defendant 1.pdf
String partyLabel = getPartyLabel(mainClaim, applicantPartyId);
String filename = "%s GA%d".formatted(baseName, genAppEntity.getRank());
if (partyLabel != null) {
filename += " - " + partyLabel;
}

if (!extension.isBlank()) {
filename += "." + extension;
}

return filename;
}

private static String getPartyLabel(ClaimEntity mainClaim, UUID partyId) {
Comment thread
tvr-hmcts marked this conversation as resolved.
ClaimPartyEntity applicantClaimParty = getClaimParty(mainClaim, partyId);

if (applicantClaimParty.getRole() == PartyRole.CLAIMANT) {
return "Claimant %d".formatted(applicantClaimParty.getRank());
} else if (applicantClaimParty.getRole() == PartyRole.DEFENDANT) {
return "Defendant %d".formatted(applicantClaimParty.getRank());
} else {
return null;
}
}

private static ClaimPartyEntity getClaimParty(ClaimEntity claim, UUID partyId) {
Comment thread
tvr-hmcts marked this conversation as resolved.
return claim.getClaimParties().stream()
.filter(claimPartyEntity -> partyId.equals(claimPartyEntity.getParty().getId()))
.findFirst()
.orElseThrow(() -> new PartyNotFoundException("Party not found"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest;
import uk.gov.hmcts.reform.pcs.ccd.entity.AddressEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.ClaimPartyEntity;
Expand All @@ -21,6 +22,7 @@
import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService;
import uk.gov.hmcts.reform.pcs.ccd.util.AddressFormatter;
import uk.gov.hmcts.reform.pcs.ccd.util.AddressMapper;
import uk.gov.hmcts.reform.pcs.document.model.Document;
import uk.gov.hmcts.reform.pcs.document.model.StatementOfTruth;
import uk.gov.hmcts.reform.pcs.document.model.genapp.GenAppFormPayload;
import uk.gov.hmcts.reform.pcs.document.service.DocAssemblyService;
Expand Down Expand Up @@ -82,8 +84,12 @@ public String generateSubmissionDocument(long caseReference,
UUID applicantUserId = securityContextService.getCurrentUserId();
String outputFilename = getDocumentFilename(mainClaim, genAppEntity, applicantUserId);

GenAppFormPayload genAppFormPayload
= createGenAppFormPayload(caseReference, pcsCaseEntity, mainClaim, citizenGenAppRequest, applicantUserId);
GenAppFormPayload genAppFormPayload = createGenAppFormPayload(caseReference,
pcsCaseEntity,
mainClaim,
citizenGenAppRequest,
genAppEntity,
applicantUserId);

return docAssemblyService
.generateDocument(genAppFormPayload, TEMPLATE_ID, OutputType.PDF, outputFilename);
Expand All @@ -93,6 +99,7 @@ private GenAppFormPayload createGenAppFormPayload(long caseReference,
PcsCaseEntity pcsCaseEntity,
ClaimEntity mainClaim,
CitizenGenAppRequest citizenGenAppRequest,
GenAppEntity genAppEntity,
UUID applicantUserId) {

LocalDate currentUkDate = LocalDate.now(ukClock);
Expand Down Expand Up @@ -122,6 +129,8 @@ private GenAppFormPayload createGenAppFormPayload(long caseReference,
.otherPartiesAgreed(citizenGenAppRequest.getOtherPartiesAgreed())
.withoutNotice(citizenGenAppRequest.getWithoutNotice())
.withoutNoticeReason(citizenGenAppRequest.getWithoutNoticeReason())
.documentUploadWanted(citizenGenAppRequest.getHasSupportingDocuments())
.uploadedDocuments(getDocumentList(genAppEntity))
.statementOfTruth(StatementOfTruth.builder()
.fullName(citizenGenAppRequest.getSotFullName())
.submittedOn(currentUkDate)
Expand All @@ -130,6 +139,14 @@ private GenAppFormPayload createGenAppFormPayload(long caseReference,
.build();
}

private List<Document> getDocumentList(GenAppEntity genAppEntity) {
List<DocumentEntity> uploadedDocuments = genAppEntity.getDocuments();

return uploadedDocuments.stream()
.map(documentEntity -> Document.builder().filename(documentEntity.getFileName()).build())
.toList();
}

private String buildCaseName(ClaimEntity mainClaim) {
Map<PartyRole, List<Party>> partyMap = getPartyMap(mainClaim);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
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.UploadedDocument;
import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo;
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest;
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppState;
import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.HelpWithFeesEntity;
Expand All @@ -15,24 +17,29 @@
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.repository.DocumentRepository;
import uk.gov.hmcts.reform.pcs.ccd.repository.GenAppRepository;
import uk.gov.hmcts.reform.pcs.ccd.service.document.DocumentNameService;

import java.time.Clock;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import static uk.gov.hmcts.reform.pcs.ccd.util.YesOrNoConverter.toYesOrNo;

@Service
public class GenAppService {

private final GenAppRepository genAppRepository;
private final DocumentNameService documentNameService;
private final DocumentRepository documentRepository;
private final Clock utcClock;

public GenAppService(GenAppRepository genAppRepository,
DocumentNameService documentNameService,
DocumentRepository documentRepository,
@Qualifier("utcClock") Clock utcClock) {
this.genAppRepository = genAppRepository;
this.documentNameService = documentNameService;
this.documentRepository = documentRepository;
this.utcClock = utcClock;
}
Expand All @@ -51,6 +58,10 @@ public GenAppEntity createGenAppEntity(CitizenGenAppRequest citizenCreateGenApp,
.appliedForHwf(citizenCreateGenApp.getAppliedForHwf())
.build();

// Adding the Gen App to the PcsCaseEntity allocates it a rank,
// which we rely on later on in this method to rename the supporting documents
pcsCaseEntity.addGenApp(genAppEntity);
Comment thread
tvr-hmcts marked this conversation as resolved.

if (citizenCreateGenApp.getAppliedForHwf() == VerticalYesNo.YES
&& citizenCreateGenApp.getHwfReference() != null) {
HelpWithFeesEntity helpWithFeesEntity = new HelpWithFeesEntity();
Expand All @@ -71,7 +82,10 @@ public GenAppEntity createGenAppEntity(CitizenGenAppRequest citizenCreateGenApp,
genAppEntity.setDocumentsUploaded(citizenCreateGenApp.getHasSupportingDocuments());
if (citizenCreateGenApp.getHasSupportingDocuments() == VerticalYesNo.YES) {
List<DocumentEntity> documentEntities
= createDocumentEntities(citizenCreateGenApp.getUploadedDocuments(), pcsCaseEntity, genAppEntity);
= createDocumentEntities(citizenCreateGenApp.getUploadedDocuments(),
pcsCaseEntity,
genAppEntity,
applicantParty.getId());

genAppEntity.setDocuments(documentEntities);
}
Expand All @@ -88,31 +102,38 @@ public GenAppEntity createGenAppEntity(CitizenGenAppRequest citizenCreateGenApp,
genAppEntity.setStatementOfTruth(statementOfTruthEntity);
}

pcsCaseEntity.addGenApp(genAppEntity);

return genAppRepository.save(genAppEntity);
}

public List<DocumentEntity> createDocumentEntities(List<ListValue<UploadedDocument>> uploadedDocuments,
PcsCaseEntity pcsCaseEntity,
GenAppEntity genAppEntity) {
GenAppEntity genAppEntity,
UUID applicantPartyId) {

if (uploadedDocuments == null) {
return List.of();
}

ClaimEntity mainClaimEntity = pcsCaseEntity.getClaims().getFirst();

List<DocumentEntity> documentEntities = uploadedDocuments.stream()
.map(ListValue::getValue)
.map(defDoc -> DocumentEntity.builder()
.pcsCase(pcsCaseEntity)
.generalApplication(genAppEntity)
.url(defDoc.getDocument().getUrl())
.fileName(defDoc.getDocument().getFilename())
.binaryUrl(defDoc.getDocument().getBinaryUrl())
.categoryId(null)
.contentType(defDoc.getContentType())
.size(defDoc.getSizeInBytes())
.build())
.map(uploadedDocument -> {
String originalFilename = uploadedDocument.getDocument().getFilename();
String updatedFilename = documentNameService
.appendGenAppPostfix(originalFilename, genAppEntity, mainClaimEntity, applicantPartyId);

return DocumentEntity.builder()
.pcsCase(pcsCaseEntity)
.generalApplication(genAppEntity)
.url(uploadedDocument.getDocument().getUrl())
.fileName(updatedFilename)
.binaryUrl(uploadedDocument.getDocument().getBinaryUrl())
.categoryId(CaseFileCategory.APPLICATIONS.getId())
.contentType(uploadedDocument.getContentType())
.size(uploadedDocument.getSizeInBytes())
.build();
})
.toList();

return documentRepository.saveAll(documentEntities);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/GenAppsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private ListValue<GeneralApplication> createListValue(GenAppEntity genAppEntity)
.party(party)
.submittedOn(genAppEntity.getApplicationSubmittedDate())
.submissionDocument(getSubmissionDocument(genAppEntity))
.supportingDocuments(createSupportingDocumentList(genAppEntity))
.build();

return new ListValue<>(genAppEntity.getId().toString(), generalApplication);
Expand Down Expand Up @@ -76,6 +77,18 @@ private DocumentWithId getSubmissionDocument(GenAppEntity genAppEntity) {
.orElse(null);
}

private List<ListValue<Document>> createSupportingDocumentList(GenAppEntity genAppEntity) {
return genAppEntity.getDocuments().stream()
.map(documentEntity -> {
Document document = modelMapper.map(documentEntity, Document.class);
return ListValue.<Document>builder()
.id(documentEntity.getId().toString())
.value(document)
.build();
})
.toList();
}

private boolean isVisibleToUser(GenAppEntity genAppEntity, UUID userId) {
return genAppEntity.getWithoutNotice() != VerticalYesNo.YES
|| userId.equals(genAppEntity.getParty().getIdamId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package uk.gov.hmcts.reform.pcs.ccd.service.document;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.ClaimPartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyRole;

import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.argumentSet;

class DocumentNameServiceTest {

private DocumentNameService underTest;

@BeforeEach
void setUp() {
underTest = new DocumentNameService();
}

@ParameterizedTest
@MethodSource("genAppNamingScenarios")
void shouldAddGenAppNumberAndPartyLabelToGenAppDocument(PartyRole partyRole,
String originalFilename,
String expectedFilename) {
// Given
UUID applicantPartyId = UUID.randomUUID();
GenAppEntity genAppEntity = GenAppEntity.builder()
.rank(5)
.build();

PartyEntity party1 = PartyEntity.builder()
.id(applicantPartyId)
.build();

ClaimPartyEntity claimParty1 = ClaimPartyEntity.builder()
.party(party1)
.rank(2)
.role(partyRole)
.build();

ClaimEntity mainClaim = ClaimEntity.builder()
.claimParties(List.of(claimParty1))
.build();

// When
String updatedFilename
= underTest.appendGenAppPostfix(originalFilename, genAppEntity, mainClaim, applicantPartyId);

// Then
assertThat(updatedFilename).isEqualTo(expectedFilename);
}

private static Stream<Arguments> genAppNamingScenarios() {
return Stream.of(
// Party role, original filename, expected updated filename
argumentSet("null filename",
PartyRole.DEFENDANT, null, null),
argumentSet("no extension, defendant",
PartyRole.DEFENDANT, "sample", "sample GA5 - Defendant 2"),
argumentSet("with extension, defendant",
PartyRole.DEFENDANT, "sample.pdf", "sample GA5 - Defendant 2.pdf"),
argumentSet("no extension, claimant",
PartyRole.CLAIMANT, "sample", "sample GA5 - Claimant 2"),
argumentSet("with extension, claimant",
PartyRole.CLAIMANT, "sample.pdf", "sample GA5 - Claimant 2.pdf"),
argumentSet("no extension, other party type",
PartyRole.UNDERLESSEE_OR_MORTGAGEE, "sample", "sample GA5"),
argumentSet("with extension, other party type",
PartyRole.UNDERLESSEE_OR_MORTGAGEE, "sample.pdf", "sample GA5.pdf")
);
}

}
Loading
Loading