Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
36d273a
FPVTL-2412 : initial commit
mrafeeqhmcts Mar 26, 2026
83f3045
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Mar 26, 2026
f3c652a
FPVTL-2412: added tests
mrafeeqhmcts Mar 26, 2026
0bb5bb7
FPVTL-2412: fixed sonar issues
mrafeeqhmcts Mar 26, 2026
fc6a958
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Mar 26, 2026
1996c68
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Mar 26, 2026
6ce20c5
FPVTL-2412: resolved merge conflicts in build.gradle
mrafeeqhmcts Mar 26, 2026
2b7928e
FPVTL-2431 - Update local env acr commands (#3686)
hisamuran-sun Mar 26, 2026
38dfe46
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Mar 26, 2026
6e6f2ed
FPVTL-2412: added FTs
mrafeeqhmcts Mar 27, 2026
aa6ccfc
FPVTL-2412 : refactored uploaded document category variable name
mrafeeqhmcts Mar 27, 2026
442b24a
FPVTL-2412 : excluded the cafcass england doc category from bundling
mrafeeqhmcts Mar 30, 2026
a35b32c
FPVTL-2412 : FT failure in cos api resolved
mrafeeqhmcts Mar 30, 2026
ed5eb05
FPVTL-2412 : integrated with DMN Changes
mrafeeqhmcts Mar 30, 2026
da10404
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Mar 31, 2026
f74921d
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Mar 31, 2026
7cad464
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 1, 2026
b216837
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 1, 2026
ab1aae2
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 2, 2026
bf246b8
FPVTL-2412: trigger preview rebuild
mrafeeqhmcts Apr 2, 2026
0df9ad9
FPVTL-2412: trigger preview rebuild
mrafeeqhmcts Apr 2, 2026
6517de3
FPVTL-2412 added debug information
mrafeeqhmcts Apr 2, 2026
b80e0dd
FPVTL-2412: add upload request logging
mrafeeqhmcts Apr 2, 2026
b5d6902
FPVTL-2412 : added debug statement
mrafeeqhmcts Apr 2, 2026
c30d13d
FPVTL-2412 : added debug statement
mrafeeqhmcts Apr 7, 2026
2ba3d73
FPVTL-2412 : added debug statement
mrafeeqhmcts Apr 7, 2026
ad0e969
FPVTL-2412 : review comments
mrafeeqhmcts Apr 7, 2026
f86ca58
FPVTL-2412: corrected logic for subsequent document uploads
mrafeeqhmcts Apr 8, 2026
ee4c127
FPVTL-2412: fixed FT failure issue
mrafeeqhmcts Apr 8, 2026
02745c9
FPVTL-2412: rolled back an earlier trial fix to FT
mrafeeqhmcts Apr 8, 2026
f7a86c4
FPVTL-2043 : Fix NPE in removeBarristerIfPresent (#3677)
Jefex7 Apr 8, 2026
c3b8a63
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 8, 2026
ad39152
FPVTL-2412 : minor refactor
mrafeeqhmcts Apr 8, 2026
a5102a1
FPVTL-2593: Add/Remove Local Authority and Grant LAs permissions to u…
Jude-hmcts Apr 9, 2026
37b0832
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 9, 2026
0e85ceb
FPVTL-2412: made only one urgent task appear for mutiple documents of…
mrafeeqhmcts Apr 9, 2026
776edba
FPVTL-2412: made only one urgent task appear for mutiple documents of…
mrafeeqhmcts Apr 9, 2026
8e4ac82
FPVTL-2412: made only one urgent task appear for mutiple documents of…
mrafeeqhmcts Apr 9, 2026
dd8315e
FPVTL-2412: enhanced logic to check no second task is created for sam…
mrafeeqhmcts Apr 9, 2026
a00464f
FPVTL:2412: simplified duplicate task creation avoidance logic
mrafeeqhmcts Apr 10, 2026
0fa7707
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 10, 2026
2c64168
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 13, 2026
05bde1e
FPVTL-2412 : AC6 the cirextensionrequest & cirtransfer request docume…
mrafeeqhmcts Apr 13, 2026
5ede584
FPVTL-2412 : AC6 the 3 document types should not appear in bundling …
mrafeeqhmcts Apr 13, 2026
05044b7
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 14, 2026
d653b58
FPVTL-2412: fixed a merge issue
mrafeeqhmcts Apr 14, 2026
72c1d32
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 14, 2026
f7f5402
FPVTL-2412: handled a NPE that can prevent bundles tab from appearing…
mrafeeqhmcts Apr 14, 2026
9e548fa
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 15, 2026
db576f9
FPVTL-2412: added log statements
mrafeeqhmcts Apr 15, 2026
64636f2
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 15, 2026
89cfac5
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 15, 2026
657569c
FPVTL-2412: added more debug information
mrafeeqhmcts Apr 15, 2026
3018d9f
FPVTL-2051. (#3609)
yogeshdhonde2025 Apr 15, 2026
99b3421
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 15, 2026
110b854
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 15, 2026
d0cd341
Merge remote-tracking branch 'origin/FPVTL-2412-cafcass-england-exten…
mrafeeqhmcts Apr 15, 2026
8d1dee0
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 15, 2026
c77b4db
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 16, 2026
147fad9
FPVTL-2412: addressed sonar issues
mrafeeqhmcts Apr 16, 2026
c4fca01
Merge branch 'FPVTL-2412-cafcass-england-extensions' of github-hmcts:…
mrafeeqhmcts Apr 16, 2026
73aed60
Merge remote-tracking branch 'origin/master' into FPVTL-2412-cafcass-…
mrafeeqhmcts Apr 16, 2026
9c037ac
FPVTL-2412 : made the files with a 'Confidential_' prefix even if the…
mrafeeqhmcts Apr 17, 2026
3ea2096
FPVTL-2412 : handled NPE
mrafeeqhmcts Apr 17, 2026
fe09cbb
FPVTL-2412: added log statements
mrafeeqhmcts Apr 17, 2026
94b9c71
FPVTL-2412: made categoryid as an list to comply with dmn changes
mrafeeqhmcts Apr 18, 2026
55f96b6
FPVTL-2412: fixed failing FT
mrafeeqhmcts Apr 20, 2026
4101bdf
FPVTL-2412: refactored code
mrafeeqhmcts Apr 20, 2026
290db70
FPVTL-2412: addressed checkstyle issues
mrafeeqhmcts Apr 20, 2026
49fdd75
FPVTL-2412 : merged master changes
mrafeeqhmcts Apr 20, 2026
7453913
FPVTL-2412: fixed failing FT
mrafeeqhmcts Apr 20, 2026
64a9ae6
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 21, 2026
693f69c
FPVTL-2412: code refactor
mrafeeqhmcts Apr 21, 2026
dc447fb
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 21, 2026
ae8e84d
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 21, 2026
fe0b97b
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 21, 2026
c2e9274
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 22, 2026
7cd6caa
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 23, 2026
7e0d317
Merge branch 'master' into FPVTL-2412-cafcass-england-extensions
mrafeeqhmcts Apr 23, 2026
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ src/main/resources/application.yaml
/.aat-env
/bin/ccd-config-PRL-local.xlsx
/.mirrord/mirrord.json
/node_modules/.yarn-integrity
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to ignore this files?

/node_modules/.yarn-state.yml
/.yarnrc.yml
/gradle-8.7-bin.zip
/.yarn/install-state.gz
/package.json
/yarn.lock
/.yarn/releases/yarn-4.12.0.cjs
/.aat-env*
/target/poitl-output/*

Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ apply plugin: 'net.serenity-bdd.aggregator'
group = 'uk.gov.hmcts.reform.prl'
version = '0.0.1'

mainClassName = 'uk.gov.hmcts.reform.prl.Application'
if (GradleVersion.current() >= GradleVersion.version('9.0')) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, What is the reason for this change?

springBoot {
mainClass.set('uk.gov.hmcts.reform.prl.Application')
}
} else {
mainClassName = 'uk.gov.hmcts.reform.prl.Application'
}

bootJar {
getArchiveFileName().set(provider {
Expand Down Expand Up @@ -468,7 +474,6 @@ dependencies {
integrationTestImplementation(sourceSets.test.output)
}


processContractTestResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,38 @@ public void givenValidDocumentData_then200Response() throws IOException {
.body("message", equalTo("Document has been uploaded successfully: Dummy_pdf_file.pdf"));

}

@Test
@Order(3)
public void givenCirTransferDocument_then200Response() throws IOException {
final File fileToUpload = readFile(CAFCASS_DUMMY_UPLOAD_FILE);

request
.header("Authorization", idamTokenGenerator.generateIdamTokenForCafcass())
.header("ServiceAuthorization", serviceAuthenticationGenerator.generateTokenForCcd())
.multiPart("file", fileToUpload)
.param("typeOfDocument", "cirTransferRequest")
.pathParam("caseId", caseDetails.getId())
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
.post("/{caseId}/document")
.then().assertThat().statusCode(200)
.body("message", equalTo("Document has been uploaded successfully: Dummy_pdf_file.pdf"));
}

@Test
@Order(4)
public void givenCirExtensionDocument_then200Response() throws IOException {
final File fileToUpload = readFile(CAFCASS_DUMMY_UPLOAD_FILE);

request
.header("Authorization", idamTokenGenerator.generateIdamTokenForCafcass())
.header("ServiceAuthorization", serviceAuthenticationGenerator.generateTokenForCcd())
.multiPart("file", fileToUpload)
.param("typeOfDocument", "cirExtensionRequest")
.pathParam("caseId", caseDetails.getId())
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
.post("/{caseId}/document")
.then().assertThat().statusCode(200)
.body("message", equalTo("Document has been uploaded successfully: Dummy_pdf_file.pdf"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public enum CafcassReportAndGuardianEnum {

riskAssessment("16aRiskAssessment", "16a risk assessment"),

cirTransferRequest("cirTransferRequest", "CIR Transfer Request"),

cirExtensionRequest("cirExtensionRequest", "CIR Extension Request"),

guardianReport("guardianReport", "Guardian report"),

specialGuardianshipReport("specialGuardianshipReport", "Special guardianship report"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import uk.gov.hmcts.reform.prl.models.dto.bundle.BundlingRequestDocument;
import uk.gov.hmcts.reform.prl.models.dto.ccd.CaseData;
import uk.gov.hmcts.reform.prl.models.dto.ccd.MiamDetails;
import uk.gov.hmcts.reform.prl.models.dto.ccd.ReviewDocuments;
import uk.gov.hmcts.reform.prl.models.dto.hearings.CaseHearing;
import uk.gov.hmcts.reform.prl.models.dto.hearings.HearingDaySchedule;
import uk.gov.hmcts.reform.prl.models.dto.hearings.Hearings;
Expand Down Expand Up @@ -78,7 +79,6 @@
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SECTION_47_LA;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SECTION_7_ADDENDUM_REPORT_LA;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SECTION_7_REPORT_LA;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SIXTEEN_A_RISK_ASSESSMENT;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SPECIAL_GUARDIANSHIP_REPORT;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.TRANSCRIPTS_OF_JUDGEMENTS;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.BLANK_STRING;
Expand Down Expand Up @@ -410,37 +410,18 @@ void addOrderDocument(List<BundlingRequestDocument> orders, Document document) {
//Updated to retrieve otherDocuments according to the new manageDocuments event
private List<Element<BundlingRequestDocument>> mapOtherDocumentsFromCaseData(
CaseData caseData) {
List<Element<QuarantineLegalDoc>> allDocuments = new ArrayList<>();
if (null != caseData.getReviewDocuments().getCourtStaffUploadDocListDocTab()
&& !caseData.getReviewDocuments().getCourtStaffUploadDocListDocTab().isEmpty()) {
List<Element<QuarantineLegalDoc>> courtStaffUploadDocList = caseData.getReviewDocuments().getCourtStaffUploadDocListDocTab();
allDocuments.addAll(courtStaffUploadDocList);
}
if (null != caseData.getReviewDocuments().getCafcassUploadDocListDocTab()
&& !caseData.getReviewDocuments().getCafcassUploadDocListDocTab().isEmpty()) {
List<Element<QuarantineLegalDoc>> cafcassUploadDocList = caseData.getReviewDocuments().getCafcassUploadDocListDocTab();
allDocuments.addAll(cafcassUploadDocList);
}
if (null != caseData.getReviewDocuments().getLocalAuthorityUploadDocListDocTab()
&& !caseData.getReviewDocuments().getLocalAuthorityUploadDocListDocTab().isEmpty()) {
List<Element<QuarantineLegalDoc>> localAuthorityUploadDocList = caseData.getReviewDocuments().getLocalAuthorityUploadDocListDocTab();
allDocuments.addAll(localAuthorityUploadDocList);
}
if (null != caseData.getReviewDocuments().getLegalProfUploadDocListDocTab()
&& !caseData.getReviewDocuments().getLegalProfUploadDocListDocTab().isEmpty()) {
List<Element<QuarantineLegalDoc>> legalProfUploadDocList = caseData.getReviewDocuments().getLegalProfUploadDocListDocTab();
allDocuments.addAll(legalProfUploadDocList);
}

if (null != caseData.getReviewDocuments().getCitizenUploadedDocListDocTab()
&& !caseData.getReviewDocuments().getCitizenUploadedDocListDocTab().isEmpty()) {
List<Element<QuarantineLegalDoc>> citizenUploadedDocuments = caseData.getReviewDocuments().getCitizenUploadedDocListDocTab();
allDocuments.addAll(citizenUploadedDocuments);
List<Element<QuarantineLegalDoc>> allDocuments = new ArrayList<>();
ReviewDocuments reviewDocuments = caseData.getReviewDocuments();
if (null != reviewDocuments) {
addIfNotEmpty(allDocuments, reviewDocuments.getCourtStaffUploadDocListDocTab());
addIfNotEmpty(allDocuments, reviewDocuments.getCafcassUploadDocListDocTab());
addIfNotEmpty(allDocuments, reviewDocuments.getLocalAuthorityUploadDocListDocTab());
addIfNotEmpty(allDocuments, reviewDocuments.getLegalProfUploadDocListDocTab());
addIfNotEmpty(allDocuments, reviewDocuments.getCitizenUploadedDocListDocTab());
}

List<BundlingRequestDocument> otherBundlingDocuments = new ArrayList<>();
List<QuarantineLegalDoc> allDocs = ElementUtils.unwrapElements(allDocuments);
for (QuarantineLegalDoc doc : allDocs) {
for (QuarantineLegalDoc doc : ElementUtils.unwrapElements(allDocuments)) {
BundlingRequestDocument otherDoc = mapBundlingRequestDocumentForOtherDocs(doc);
if (null != otherDoc) {
log.info("otherDoc in bundle with filename: {} for case: {}", otherDoc.documentFileName, caseData.getId());
Expand All @@ -450,6 +431,12 @@ private List<Element<BundlingRequestDocument>> mapOtherDocumentsFromCaseData(
return ElementUtils.wrapElements(otherBundlingDocuments);
}

private <T> void addIfNotEmpty(List<T> target, List<T> source) {
if (null != source && !source.isEmpty()) {
target.addAll(source);
}
}


private BundlingRequestDocument mapBundlingRequestDocumentForOtherDocs(QuarantineLegalDoc doc) {
HashMap<String, BundlingRequestDocument> bundleMap = new HashMap<>();
Expand Down Expand Up @@ -619,13 +606,6 @@ private static void mapCafcassLaReports(QuarantineLegalDoc doc, HashMap<String,
.documentFileName(doc.getSection7ReportDocument().getDocumentFileName())
.documentGroup(BundlingDocGroupEnum.section7Report).build() : null
);
bundleMap.put(
SIXTEEN_A_RISK_ASSESSMENT,
Objects.nonNull(doc.getSixteenARiskAssessmentDocument()) ? BundlingRequestDocument.builder()
.documentLink(doc.getSixteenARiskAssessmentDocument())
.documentFileName(doc.getSixteenARiskAssessmentDocument().getDocumentFileName())
.documentGroup(BundlingDocGroupEnum.sixteenARiskAssessment).build() : null
);
bundleMap.put(
GUARDIAN_REPORT,
Objects.nonNull(doc.getGuardianReportDocument()) ? BundlingRequestDocument.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class QuarantineLegalDoc {
private final Document section7ReportDocument;
private final Document section37ReportDocument;
private final Document sixteenARiskAssessmentDocument; // 16aRiskAssessment
private final Document cirTransferRequestDocument;
private final Document cirExtensionRequestDocument;
private final Document guardianReportDocument;
private final Document specialGuardianshipReportDocument;
private final Document otherDocsDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -47,6 +48,7 @@
@Builder(toBuilder = true)
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ManageOrders implements MappableObject {

private final String childListForSpecialGuardianship;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class CitizenDocumentsManagement {
Set.of(
"section37Report",
"16aRiskAssessment",
"cirTransferRequest",
"cirExtensionRequest",
"publicFundingCertificates",
"noticesOfActingDischarge",
"requestForFASFormsToBeChanged",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ private BundleCreateResponse createBundle(String authorization, String serviceAu
BundleCreateResponse bundleCreateResponse = null;
try {
bundleCreateResponse = bundleApiClient.createBundleServiceRequest(authorization, serviceAuthorization, bundleCreateRequest);
} catch (feign.FeignException e) {
log.error("Error in creating bundle service request — status: {}, headers: {}, body: {}",
e.status(), e.responseHeaders(), e.contentUTF8(), e);
} catch (Exception e) {
log.error("Error in creating bundle service request",e);
log.error("Error in creating bundle service request", e);
}
return bundleCreateResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
Expand All @@ -18,8 +19,10 @@
import uk.gov.hmcts.reform.prl.enums.CaseEvent;
import uk.gov.hmcts.reform.prl.enums.managedocuments.CafcassReportAndGuardianEnum;
import uk.gov.hmcts.reform.prl.enums.managedocuments.DocumentPartyEnum;
import uk.gov.hmcts.reform.prl.models.Element;
import uk.gov.hmcts.reform.prl.models.complextypes.QuarantineLegalDoc;
import uk.gov.hmcts.reform.prl.models.documents.Document.DocumentBuilder;
import uk.gov.hmcts.reform.prl.models.dto.ccd.CaseData;
import uk.gov.hmcts.reform.prl.services.managedocuments.ManageDocumentsService;
import uk.gov.hmcts.reform.prl.services.tab.alltabs.AllTabServiceImpl;

Expand All @@ -37,19 +40,38 @@
import static uk.gov.hmcts.reform.prl.services.cafcass.CafcassServiceUtil.checkFileFormat;
import static uk.gov.hmcts.reform.prl.services.cafcass.CafcassServiceUtil.checkTypeOfDocument;
import static uk.gov.hmcts.reform.prl.services.managedocuments.ManageDocumentsService.MANAGE_DOCUMENTS_TRIGGERED_BY;
import static uk.gov.hmcts.reform.prl.utils.ElementUtils.element;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CafcassUploadDocService {

public static final List<String> ALLOWED_FILE_TYPES = List.of("pdf", "docx");

public static final String DOC_TYPE_CIR_TRANSFER = "cirTransferRequest";
public static final String DOC_TYPE_CIR_EXTENSION = "cirExtensionRequest";
public static final String DOC_TYPE_S16A_RISK_ASSESSMENT = "S_16A_Risk_Assessment";

public static final List<String> URGENT_CAFCASS_DOC_TYPES = List.of(
DOC_TYPE_CIR_TRANSFER, DOC_TYPE_CIR_EXTENSION, DOC_TYPE_S16A_RISK_ASSESSMENT
);

// These Cafcass England doc types must always be prefixed with Confidential_
// regardless of the admin's restricted decision see https://tools.hmcts.net/jira/browse/FPVTL-2412
public static final List<String> ALWAYS_CONFIDENTIAL_CAFCASS_DOC_TYPES = List.of(
DOC_TYPE_CIR_TRANSFER, DOC_TYPE_CIR_EXTENSION, DOC_TYPE_S16A_RISK_ASSESSMENT
);
public static final String MANAGE_DOC_UPLOADED_CATEGORY = "manageDocUploadedCategory";

public static final List<String> ALLOWED_TYPE_OF_DOCS = List.of(
"16_4_Report", "CR_1", "CR_2", "CIR_Part1", "CIR_Part2", "CIR_Review", "CMO_report",
"16_4_Report", "CR_1", "CR_2", "CIR_Part1", "CIR_Part2", "CIR_Review",
DOC_TYPE_CIR_TRANSFER, DOC_TYPE_CIR_EXTENSION,
"CMO_report",
"Contact_Centre_Recordings", "Correspondence", "Direct_work", "Enforcement_report",
"FAO_Report", "FAO_Workplan", "Letter_from_Child", "Other_Non_Section_7_Report",
"Position_Statement", "Positive_Parenting_Programme_Report", "Re_W_Report",
"S_11H_Monitoring", "S_16A_Risk_Assessment", "Safeguarding_Letter",
"S_11H_Monitoring", DOC_TYPE_S16A_RISK_ASSESSMENT, "Safeguarding_Letter",
Comment thread
mrafeeqhmcts marked this conversation as resolved.
"Safeguarding_Letter_Returner", "Safeguarding_Letter_Shorter_Template",
"Safeguarding_Letter_Update", "Second_Gatekeeping_Safeguarding_Letter",
"Section7_Addendum_Report", "Section7_Report_Child_Impact_Analysis", "Suitability_report"
Expand All @@ -65,6 +87,8 @@ public class CafcassUploadDocService {

public void uploadDocument(String authorisation, MultipartFile document,
String typeOfDocument, String caseId) {
log.info("Cafcass document upload request received for caseId: {}, typeOfDocument: {}", caseId,
typeOfDocument);
if (isValidDocument(document, typeOfDocument)) {
CaseDetails caseDetails = checkIfCasePresent(caseId, authorisation);
if (caseDetails == null) {
Expand Down Expand Up @@ -105,7 +129,25 @@ private void updateCcdAfterUploadingDocument(MultipartFile document, String type
quarantineLegalDoc
);

caseDataUpdated.putIfAbsent(MANAGE_DOCUMENTS_TRIGGERED_BY, null);
if (URGENT_CAFCASS_DOC_TYPES.contains(typeOfDocument)) {
boolean isDuplicate = hasCafcassQuarantineDocOfSameCategory(
startAllTabsUpdateDataContent.caseData(),
quarantineLegalDoc.getCategoryId()
);
log.info("Cafcass urgent doc upload caseId={} type={} categoryId={} isDuplicate={}",
caseId, typeOfDocument, quarantineLegalDoc.getCategoryId(), isDuplicate);
if (!isDuplicate) {
caseDataUpdated.put(MANAGE_DOCUMENTS_TRIGGERED_BY, "CAFCASS");
caseDataUpdated.put(MANAGE_DOC_UPLOADED_CATEGORY,
List.of(element(quarantineLegalDoc.getCategoryId()))
);
} else {
caseDataUpdated.put(MANAGE_DOCUMENTS_TRIGGERED_BY, null);
caseDataUpdated.put(MANAGE_DOC_UPLOADED_CATEGORY, null);
}
} else {
caseDataUpdated.putIfAbsent(MANAGE_DOCUMENTS_TRIGGERED_BY, null);
}

manageDocumentsService.moveDocumentsToQuarantineTab(
quarantineLegalDoc,
Expand All @@ -125,6 +167,15 @@ private void updateCcdAfterUploadingDocument(MultipartFile document, String type
log.info("Document has been saved in CCD {}", document.getOriginalFilename());
}

private boolean hasCafcassQuarantineDocOfSameCategory(CaseData caseData, String categoryId) {
List<Element<QuarantineLegalDoc>> quarantineDocs = caseData.getDocumentManagementDetails() != null
? caseData.getDocumentManagementDetails().getCafcassQuarantineDocsList()
: null;
return !CollectionUtils.isEmpty(quarantineDocs) && quarantineDocs.stream()
.map(Element::getValue)
.anyMatch(doc -> categoryId.equals(doc.getCategoryId()));
}

private QuarantineLegalDoc createQuarantineDocFromCafcassUploadedDoc(String typeOfDocument,
Document document) {
DocumentBuilder uploadedDoc = uk.gov.hmcts.reform.prl.models.documents.Document.builder()
Expand Down Expand Up @@ -190,6 +241,8 @@ private static Map<String, CafcassReportAndGuardianEnum> createDocumentTypeMap()
map.put("CIR_Part1", CafcassReportAndGuardianEnum.section7Report);
map.put("CIR_Part2", CafcassReportAndGuardianEnum.section7Report);
map.put("CIR_Review", CafcassReportAndGuardianEnum.section7Report);
map.put(DOC_TYPE_CIR_TRANSFER, CafcassReportAndGuardianEnum.cirTransferRequest);
map.put(DOC_TYPE_CIR_EXTENSION, CafcassReportAndGuardianEnum.cirExtensionRequest);
map.put("CMO_report", CafcassReportAndGuardianEnum.otherDocs);
map.put("Contact_Centre_Recordings", CafcassReportAndGuardianEnum.otherDocs);
map.put("Correspondence", CafcassReportAndGuardianEnum.otherDocs);
Expand All @@ -203,7 +256,7 @@ private static Map<String, CafcassReportAndGuardianEnum> createDocumentTypeMap()
map.put("Positive_Parenting_Programme_Report", CafcassReportAndGuardianEnum.otherDocs);
map.put("Re_W_Report", CafcassReportAndGuardianEnum.otherDocs);
map.put("S_11H_Monitoring", CafcassReportAndGuardianEnum.otherDocs);
map.put("S_16A_Risk_Assessment", CafcassReportAndGuardianEnum.riskAssessment);
map.put(DOC_TYPE_S16A_RISK_ASSESSMENT, CafcassReportAndGuardianEnum.riskAssessment);
map.put("Safeguarding_Letter", CafcassReportAndGuardianEnum.safeguardingLetter);
map.put("Safeguarding_Letter_Returner", CafcassReportAndGuardianEnum.safeguardingLetter);
map.put("Safeguarding_Letter_Shorter_Template", CafcassReportAndGuardianEnum.safeguardingLetter);
Expand Down
Loading