Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ src/main/resources/application.yaml
/.aat-env
/bin/ccd-config-PRL-local.xlsx
/.mirrord/mirrord.json
/node_modules/.yarn-integrity
/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
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,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 @@ -49,7 +49,6 @@
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SAFEGUARDING_LETTER;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SECTION7_REPORT;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.SECTION_37_REPORT;
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.SPIP_REFERRAL_REQUESTS;
import static uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants.WITNESS_AVAILABILITY;
Expand Down Expand Up @@ -141,7 +140,7 @@ public void givenCaseId_whenAboutToStartEndPoint_thenRespWithDocumentCategories(
PREVIOUS_ORDERS_SUBMITTED_WITH_APPLICATION, RESPONDENT_APPLICATION,
RESPONDENT_C1A_APPLICATION, RESPONDENT_C1A_RESPONSE, ORDERS_FROM_OTHER_PROCEEDINGS,
NOTICE_OF_HEARING, COURT_BUNDLE, CASE_SUMMARY, CHILD_IMPACT_REPORT1, CHILD_IMPACT_REPORT2,
SAFEGUARDING_LETTER, SECTION7_REPORT, SECTION_37_REPORT, SIXTEEN_A_RISK_ASSESSMENT, GUARDIAN_REPORT,
SAFEGUARDING_LETTER, SECTION7_REPORT, SECTION_37_REPORT, GUARDIAN_REPORT,
SPECIAL_GUARDIANSHIP_REPORT, OTHER_DOCS, EMAILS_TO_COURT_TO_REQUEST_HEARINGS_ADJOURNED,
PUBLIC_FUNDING_CERTIFICATES, NOTICES_OF_ACTING_DISCHARGE, REQUEST_FOR_FAS_FORMS_TO_BE_CHANGED,
WITNESS_AVAILABILITY, LETTERS_OF_COMPLAINTS, SPIP_REFERRAL_REQUESTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ManageDocumentsCategoryConstants {
public static final String SECTION7_REPORT = "section7Report";
public static final String SECTION_37_REPORT = "section37Report";
public static final String SIXTEEN_A_RISK_ASSESSMENT = "16aRiskAssessment";
public static final String CIR_EXTENSION_REQUEST = "cirExtensionRequest";
public static final String CIR_TRANSFER_REQUEST = "cirTransferRequest";
public static final String GUARDIAN_REPORT = "guardianReport";
public static final String SPECIAL_GUARDIANSHIP_REPORT = "specialGuardianshipReport";
public static final String OTHER_DOCS = "otherDocs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public enum DocTypeOtherDocumentsEnum {
section37Report("section37Report","Section 37 report"),
@JsonProperty("16ariskAssessment")
riskAssessment("16aRiskAssessment","16a risk assessment"),
@JsonProperty("cirTransferRequest")
cirTransferRequest("cirTransferRequest","CIR Transfer Request"),
@JsonProperty("cirExtensionRequest")
cirExtensionRequest("cirExtensionRequest","CIR Extension Request"),
@JsonProperty("guardianReport")
guardianReport("guardianReport","Guardian report"),
@JsonProperty("specialGuardianshipReport")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ public enum BundlingDocGroupEnum {
@JsonProperty("cafcassSection37Report")
cafcassSection37Report("cafcassSection37Report", "cafcassSection37Report"),

@JsonProperty("sixteenARiskAssessment")
sixteenARiskAssessment("sixteenARiskAssessment", "sixteenARiskAssessment"),

@JsonProperty("guardianReport")
guardianReport("guardianReport", "guardianReport"),

Expand Down
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 @@ -28,6 +28,10 @@ public enum CafcassCymruDocumentsEnum {
updateToSafeGuardingLetter("updateToSafeGuardingLetter", "Update to safeguarding letter"),
@JsonProperty("s16RiskAssessment")
s16RiskAssessment("s16RiskAssessment", "S16A risk assessment"),
@JsonProperty("cirTransferRequest")
cirTransferRequest("cirTransferRequest", "CIR Transfer Request"),
@JsonProperty("cirExtensionRequest")
cirExtensionRequest("cirExtensionRequest", "CIR Extension Request"),
@JsonProperty("otherReports")
otherReports("otherReports", "Other reports");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,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 @@ -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 @@ -44,12 +44,24 @@
public class CafcassUploadDocService {

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

static final String DOC_TYPE_CIR_TRANSFER = "cirTransferRequest";
static final String DOC_TYPE_CIR_EXTENSION = "cirExtensionRequest";
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
);
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",
"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 +77,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 +119,12 @@ private void updateCcdAfterUploadingDocument(MultipartFile document, String type
quarantineLegalDoc
);

caseDataUpdated.putIfAbsent(MANAGE_DOCUMENTS_TRIGGERED_BY, null);
if (URGENT_CAFCASS_DOC_TYPES.contains(typeOfDocument)) {
caseDataUpdated.put(MANAGE_DOCUMENTS_TRIGGERED_BY, "CAFCASS");
caseDataUpdated.put(MANAGE_DOC_UPLOADED_CATEGORY, quarantineLegalDoc.getCategoryId());
} else {
caseDataUpdated.putIfAbsent(MANAGE_DOCUMENTS_TRIGGERED_BY, null);
}

manageDocumentsService.moveDocumentsToQuarantineTab(
quarantineLegalDoc,
Expand Down Expand Up @@ -179,7 +198,8 @@ private boolean isValidDocument(MultipartFile document, String typeOfDocument) {
}

log.error("Unacceptable format/type of document: {}", typeOfDocument);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, INVALID_DOCUMENT_TYPE.formatted(typeOfDocument));
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, INVALID_DOCUMENT_TYPE.formatted(typeOfDocument) + " "
+ document.getOriginalFilename());
}

private static Map<String, CafcassReportAndGuardianEnum> createDocumentTypeMap() {
Expand All @@ -190,6 +210,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 +225,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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import uk.gov.hmcts.reform.prl.clients.RoleAssignmentApi;
import uk.gov.hmcts.reform.prl.clients.ccd.records.StartAllTabsUpdateDataContent;
import uk.gov.hmcts.reform.prl.config.launchdarkly.LaunchDarklyClient;
import uk.gov.hmcts.reform.prl.constants.ManageDocumentsCategoryConstants;
import uk.gov.hmcts.reform.prl.constants.PrlAppsConstants;
import uk.gov.hmcts.reform.prl.enums.Roles;
import uk.gov.hmcts.reform.prl.enums.YesOrNo;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Predicate;

import static org.springframework.http.MediaType.APPLICATION_PDF_VALUE;
import static org.springframework.util.CollectionUtils.isEmpty;
Expand Down Expand Up @@ -118,6 +120,7 @@ public class ManageDocumentsService {
public static final String CONFIDENTIAL = "Confidential_";

public static final String MANAGE_DOCUMENTS_TRIGGERED_BY = "manageDocumentsTriggeredBy";
public static final String MANAGE_DOCUMENTS_UPLOADED_CATEGORY = "manageDocUploadedCategory";
public static final String DETAILS_ERROR_MESSAGE
= "You must give a reason why the document should be restricted";
public static final String DETAILS_ERROR_MESSAGE_WELSH
Expand Down Expand Up @@ -418,6 +421,11 @@ public void setFlagsForWaTask(CaseData caseData, Map<String, Object> caseDataUpd
} else {
caseDataUpdated.remove(MANAGE_DOCUMENTS_RESTRICTED_FLAG);
}

if (userRole.equals(CAFCASS)) {
caseDataUpdated.put(MANAGE_DOCUMENTS_UPLOADED_CATEGORY, quarantineLegalDoc.getCategoryId());
}

if (CollectionUtils.isNotEmpty(caseData.getDocumentManagementDetails().getCourtStaffQuarantineDocsList())
|| CollectionUtils.isNotEmpty(caseData.getDocumentManagementDetails().getCafcassQuarantineDocsList())
|| CollectionUtils.isNotEmpty(caseData.getDocumentManagementDetails().getLocalAuthorityQuarantineDocsList())
Expand All @@ -426,12 +434,70 @@ public void setFlagsForWaTask(CaseData caseData, Map<String, Object> caseDataUpd
|| CollectionUtils.isNotEmpty(caseData.getDocumentManagementDetails().getCourtNavQuarantineDocumentList())
|| (CollectionUtils.isNotEmpty(caseData.getScannedDocuments())
&& caseData.getScannedDocuments().size() > 1)) {
caseDataUpdated.remove(MANAGE_DOCUMENTS_TRIGGERED_BY);
if (!userRole.equals(CAFCASS)) {
caseDataUpdated.remove(MANAGE_DOCUMENTS_TRIGGERED_BY);
} else {
updateTriggeredByForSpecificRestrictedDocuments(caseData, caseDataUpdated, quarantineLegalDoc, userRole);
}
} else {
updateCaseDataUpdatedByRole(caseDataUpdated, userRole);
}
}

private void updateTriggeredByForSpecificRestrictedDocuments(CaseData caseData, Map<String, Object> caseDataUpdated,
QuarantineLegalDoc quarantineLegalDoc, String userRole) {
boolean newTaskRequired = false;
//for cafcass
if (userRole.equals(CAFCASS) && ManageDocumentsCategoryConstants.SIXTEEN_A_RISK_ASSESSMENT.equals(quarantineLegalDoc.getCategoryId())) {
if (isGivenDocumentExists(caseData, getSixteenARiskAssessmentPredicate()).isEmpty()) {
newTaskRequired = true;
}
} else if (ManageDocumentsCategoryConstants.CIR_EXTENSION_REQUEST.equals(quarantineLegalDoc.getCategoryId())) {
if (isGivenDocumentExists(caseData, getCirExtensionRequestPredicate()).isEmpty()) {
newTaskRequired = true;
}
} else if (ManageDocumentsCategoryConstants.CIR_TRANSFER_REQUEST.equals(quarantineLegalDoc.getCategoryId())) {
if (isGivenDocumentExists(caseData, getCirTransferRequestPredicate()).isEmpty()) {
newTaskRequired = true;
}
} else {
if (isGivenDocumentExists(caseData, getOtherDocumentsPredicate()).isEmpty()) {
newTaskRequired = true;
}
}
if (newTaskRequired) {
updateCaseDataUpdatedByRole(caseDataUpdated, userRole);
} else {
caseDataUpdated.remove(MANAGE_DOCUMENTS_TRIGGERED_BY);
}
}

private Optional<Element<QuarantineLegalDoc>> isGivenDocumentExists(CaseData caseData, Predicate<Element<QuarantineLegalDoc>> predicate) {
return caseData.getDocumentManagementDetails().getCafcassQuarantineDocsList().stream().filter(predicate).findAny();
}

private Predicate<Element<QuarantineLegalDoc>> getSixteenARiskAssessmentPredicate() {
return a -> a.getValue().getCategoryId()
.equals(ManageDocumentsCategoryConstants.SIXTEEN_A_RISK_ASSESSMENT);
}

private Predicate<Element<QuarantineLegalDoc>> getCirExtensionRequestPredicate() {
return a -> a.getValue().getCategoryId()
.equals(ManageDocumentsCategoryConstants.CIR_EXTENSION_REQUEST);
}

private Predicate<Element<QuarantineLegalDoc>> getCirTransferRequestPredicate() {
return a -> a.getValue().getCategoryId()
.equals(ManageDocumentsCategoryConstants.CIR_TRANSFER_REQUEST);
}

private Predicate<Element<QuarantineLegalDoc>> getOtherDocumentsPredicate() {
return a ->
!a.getValue().getCategoryId().equals(ManageDocumentsCategoryConstants.SIXTEEN_A_RISK_ASSESSMENT)
&& !a.getValue().getCategoryId().equals(ManageDocumentsCategoryConstants.CIR_EXTENSION_REQUEST)
&& !a.getValue().getCategoryId().equals(ManageDocumentsCategoryConstants.CIR_TRANSFER_REQUEST);
}

public void moveDocumentsToQuarantineTab(QuarantineLegalDoc quarantineLegalDoc,
CaseData caseData,
Map<String, Object> caseDataUpdated,
Expand Down
Loading