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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,4 +746,11 @@ public class PCSCase {
typeParameterOverride = "CaseStateOption"
)
private CaseStateOption targetState;

@CCD(
label = "Add document",
hint = "Upload a document to the system",
searchable = false
)
private Document uploadSingleDocument;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<ListValue<Document>> relatedEvidence;

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ private SubmitResponse<State> submit(EventPayload<PCSCase, State> eventPayload)
PartyEntity applicantParty = partyService.getPartyEntityByEntityId(
caseData.getPartyRadioList().getValueCode(), caseReference);

genAppService.createGenAppEntity(
caseData.getEnterGenAppRequest(), pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED);
genAppService.createGenAppEntity(caseData, pcsCaseEntity, applicantParty, GenAppState.GEN_APP_ISSUED);

return SubmitResponse.<State>builder().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<div class="govuk-notification-banner" role="region"
aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__content">
<p class="govuk-notification-banner__heading">
Placeholder
</p>
</div>
</div>
""";

@Override
public void addTo(PageBuilder pageBuilder) {
pageBuilder
.page("uploadGeneralApplication")
.pageLabel("Upload general application")
.label("uploadGeneralApplication-lineSeparator", "---")
.label("uploadGeneralApplication-placeholder", PLACEHOLDER_BANNER);
.mandatory(PCSCase::getUploadSingleDocument);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<div class="govuk-notification-banner" role="region"
aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__content">
<p class="govuk-notification-banner__heading">
Placeholder
</p>
</div>
</div>
""";

@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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ private Optional<CaseFileCategory> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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.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;
Expand Down Expand Up @@ -33,6 +37,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;
Expand Down Expand Up @@ -122,18 +128,19 @@ public GenAppEntity createGenAppEntity(GenAppRequest genAppRequest,
return genAppRepository.save(genAppEntity);
}

public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest,
public void createGenAppEntity(PCSCase caseData,
PcsCaseEntity pcsCaseEntity,
PartyEntity applicantParty,
GenAppState initialState) {

EnterGenAppRequest enterGenAppRequest = caseData.getEnterGenAppRequest();

GenAppEntity genAppEntity = GenAppEntity.builder()
.type(enterGenAppRequest.getApplicationTypeOption().getStandardGenAppType())
.applicationSubmittedDate(LocalDateTime.now(utcClock))
.party(applicantParty)
.applicationReceivedDate(enterGenAppRequest.getDateReceived())
.within14Days(enterGenAppRequest.getWithin14Days())
.applicationSubmittedDate(LocalDateTime.now(utcClock))
.within14Days(enterGenAppRequest.getWithin14Days())
.state(initialState)
.feeAmountReceived(enterGenAppRequest.getFeeAmountReceived())
.appliedForHwf(enterGenAppRequest.getAppliedForHwf())
Expand All @@ -153,9 +160,65 @@ public void createGenAppEntity(EnterGenAppRequest enterGenAppRequest,
genAppEntity.setHelpWithFeesEntity(helpWithFeesEntity);
}

Document uploadedGenApp = caseData.getUploadSingleDocument();
DocumentEntity submissionDocument = createSubmissionDocumentEntity(
uploadedGenApp, pcsCaseEntity, genAppEntity, applicantParty.getId()
);
genAppEntity.setSubmissionDocument(submissionDocument);

List<DocumentEntity> additionalEvidenceDocuments = createRelatedEvidenceDocumentEntities(
enterGenAppRequest.getRelatedEvidence(), pcsCaseEntity, genAppEntity, applicantParty.getId()
);
genAppEntity.setDocuments(additionalEvidenceDocuments);

genAppRepository.save(genAppEntity);
}

private DocumentEntity createSubmissionDocumentEntity(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 = buildDocumentEntity(document, pcsCaseEntity, genAppEntity, renamedFilename,
CaseFileCategory.APPLICATIONS.getId(), DocumentType.GENERAL_APPLICATION);

return documentRepository.save(documentEntity);
}

private List<DocumentEntity> createRelatedEvidenceDocumentEntities(
List<ListValue<Document>> relatedEvidenceDocuments, PcsCaseEntity pcsCaseEntity, GenAppEntity genAppEntity,
UUID applicantPartyId) {

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

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

List<DocumentEntity> documentEntities = relatedEvidenceDocuments.stream()
.map(ListValue::getValue)
.map(document -> {
String renamedFilename = documentNameService
.appendGenAppPostfix(document.getFilename(), genAppEntity, mainClaimEntity, applicantPartyId);

return buildDocumentEntity(document, pcsCaseEntity, genAppEntity, renamedFilename,
null, null);
})
.toList();

return documentRepository.saveAll(documentEntities);
}

private List<DocumentEntity> createDocumentEntities(List<ListValue<UploadedDocument>> uploadedDocuments,
PcsCaseEntity pcsCaseEntity,
GenAppEntity genAppEntity,
Expand All @@ -174,23 +237,33 @@ private List<DocumentEntity> createDocumentEntities(List<ListValue<UploadedDocum
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())
.type(uploadedDocument.getDocumentType() != null
? documentService.mapAdditionalDocumentTypeToDocumentType(uploadedDocument.getDocumentType())
: null)
.contentType(uploadedDocument.getContentType())
.size(uploadedDocument.getSizeInBytes())
.build();
DocumentType type = uploadedDocument.getDocumentType() != null
? documentService.mapAdditionalDocumentTypeToDocumentType(uploadedDocument.getDocumentType())
: null;

DocumentEntity documentEntity = buildDocumentEntity(uploadedDocument.getDocument(), pcsCaseEntity,
genAppEntity, updatedFilename, CaseFileCategory.APPLICATIONS.getId(), type);
documentEntity.setContentType(uploadedDocument.getContentType());
documentEntity.setSize(uploadedDocument.getSizeInBytes());

return documentEntity;
})
.toList();

return documentRepository.saveAll(documentEntities);
}

private DocumentEntity buildDocumentEntity(Document document, PcsCaseEntity pcsCaseEntity,
GenAppEntity genAppEntity, String fileName, String categoryId,
DocumentType type) {
return DocumentEntity.builder()
.pcsCase(pcsCaseEntity)
.generalApplication(genAppEntity)
.url(document.getUrl())
.fileName(fileName)
.binaryUrl(document.getBinaryUrl())
.categoryId(categoryId)
.type(type)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void shouldCreateGenAppEntityOnSubmit() {

// Then
verify(genAppService)
.createGenAppEntity(enterGenAppRequest, pcsCaseEntity, applicantParty, GEN_APP_ISSUED);
.createGenAppEntity(caseData, pcsCaseEntity, applicantParty, GEN_APP_ISSUED);
}

}
Loading