Skip to content

Commit

Permalink
RIA-7427 Internal upload additional evidence doc generation (#695)
Browse files Browse the repository at this point in the history
* RIA-7427 Internal upload additional evidence doc generation

* RIA-7427 Test and checkstyle fixes
  • Loading branch information
Ryan-Nesbitt authored Sep 15, 2023
1 parent e91fffa commit 53320c0
Show file tree
Hide file tree
Showing 16 changed files with 574 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "RIA-7427 Internal upload addendum evidence letter PDF - ADA",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"eventId": "uploadAddendumEvidenceAdminOfficer",
"state": "decision",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes",
"notificationAttachmentDocuments": [
{
"id": "1",
"value": {
"document": {
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/",
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/",
"document_filename": "PA 12345 2019-Awan-additional-evidence-uploaded-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalUploadAdditionalEvidenceLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "RIA-7427 Internal upload addendum evidence letter PDF - ADA",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"eventId": "uploadAddendumEvidenceAdminOfficer",
"state": "decision",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "No"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "No",
"notificationAttachmentDocuments": [
{
"id": "1",
"value": {
"document": {
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/",
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/",
"document_filename": "PA 12345 2019-Awan-additional-evidence-uploaded-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalUploadAdditionalEvidenceLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "RIA-7427 Internal upload additional evidence letter PDF - ADA",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"eventId": "uploadAdditionalEvidence",
"state": "caseBuilding",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes",
"notificationAttachmentDocuments": [
{
"id": "1",
"value": {
"document": {
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/",
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/",
"document_filename": "PA 12345 2019-Awan-additional-evidence-uploaded-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalUploadAdditionalEvidenceLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "RIA-7427 Internal upload additional evidence letter PDF - ADA",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"eventId": "uploadAdditionalEvidence",
"state": "caseBuilding",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes",
"isAcceleratedDetainedAppeal": "Yes",
"notificationAttachmentDocuments": [
{
"id": "1",
"value": {
"document": {
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/",
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/",
"document_filename": "PA 12345 2019-Awan-additional-evidence-uploaded-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalUploadAdditionalEvidenceLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum DocumentTag {
INTERNAL_HO_FTPA_DECIDED_LETTER("internalHoFtpaDecidedLetter", CaseType.ASYLUM),
INTERNAL_HEARING_REQUIREMENTS_UPDATED_LETTER("internalHearingRequirementsUpdatedLetter", CaseType.ASYLUM),
INTERNAL_MAINTAIN_CASE_LINKS_LETTER("internalMaintainCaseLinksLetter", CaseType.ASYLUM),
INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_LETTER("internalUploadAdditionalEvidenceLetter", CaseType.ASYLUM),

BAIL_SUBMISSION("bailSubmission", CaseType.BAIL),
BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public enum Event {
TRANSFER_OUT_OF_ADA("transferOutOfAda", CaseType.ASYLUM),
RESIDENT_JUDGE_FTPA_DECISION("residentJudgeFtpaDecision", CaseType.ASYLUM),
MAINTAIN_CASE_LINKS("maintainCaseLinks", CaseType.ASYLUM),
UPLOAD_ADDENDUM_EVIDENCE_ADMIN_OFFICER("uploadAddendumEvidenceAdminOfficer", CaseType.ASYLUM),

SUBMIT_APPLICATION("submitApplication", CaseType.BAIL),
RECORD_THE_DECISION("recordTheDecision", CaseType.BAIL),
END_APPLICATION("endApplication", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event.UPLOAD_ADDENDUM_EVIDENCE_ADMIN_OFFICER;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event.UPLOAD_ADDITIONAL_EVIDENCE;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase;

import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentCreator;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentHandler;

@Component
public class InternalUploadAdditionalEvidenceGenerator implements PreSubmitCallbackHandler<AsylumCase> {

private final DocumentCreator<AsylumCase> documentCreator;
private final DocumentHandler documentHandler;

public InternalUploadAdditionalEvidenceGenerator(
@Qualifier("internalUploadAdditionalEvidenceLetter") DocumentCreator<AsylumCase> documentCreator,
DocumentHandler documentHandler
) {
this.documentCreator = documentCreator;
this.documentHandler = documentHandler;
}

public boolean canHandle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
Objects.requireNonNull(callbackStage, "callbackStage must not be null");
Objects.requireNonNull(callback, "callback must not be null");

AsylumCase asylumCase = callback.getCaseDetails().getCaseData();

Event event = callback.getEvent();

return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
&& List.of(UPLOAD_ADDITIONAL_EVIDENCE, UPLOAD_ADDENDUM_EVIDENCE_ADMIN_OFFICER).contains(event)
&& isInternalCase(asylumCase)
&& isAppellantInDetention(asylumCase);
}

public PreSubmitCallbackResponse<AsylumCase> handle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
if (!canHandle(callbackStage, callback)) {
throw new IllegalStateException("Cannot handle callback");
}

final CaseDetails<AsylumCase> caseDetails = callback.getCaseDetails();
final AsylumCase asylumCase = caseDetails.getCaseData();

Document internalUploadAdditionalEvidenceLetter = documentCreator.create(caseDetails);

documentHandler.addWithMetadataWithoutReplacingExistingDocuments(
asylumCase,
internalUploadAdditionalEvidenceLetter,
NOTIFICATION_ATTACHMENT_DOCUMENTS,
DocumentTag.INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_LETTER
);

return new PreSubmitCallbackResponse<>(asylumCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ private int bundlePositionIndex(DocumentWithMetadata document) {
case INTERNAL_MAINTAIN_CASE_LINKS_LETTER:
log.warn("INTERNAL_MAINTAIN_CASE_LINKS_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 57;
case INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_LETTER:
log.warn("INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 58;
default:
throw new IllegalStateException("document has unknown tag: " + document.getTag() + ", description: " + document.getDescription());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.getAppellantPersonalisation;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.DocumentTemplate;
import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider;

@Component
public class InternalUploadAdditionalEvidenceLetterTemplate implements DocumentTemplate<AsylumCase> {

private final String templateName;
private final CustomerServicesProvider customerServicesProvider;

public InternalUploadAdditionalEvidenceLetterTemplate(
@Value("${internalUploadAdditionalEvidence.templateName}") String templateName,
CustomerServicesProvider customerServicesProvider) {
this.templateName = templateName;
this.customerServicesProvider = customerServicesProvider;
}

@Override
public String getName() {
return templateName;
}

public Map<String, Object> mapFieldValues(
CaseDetails<AsylumCase> caseDetails
) {
final AsylumCase asylumCase = caseDetails.getCaseData();

final Map<String, Object> fieldValues = new HashMap<>();

fieldValues.putAll(getAppellantPersonalisation(asylumCase));
fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase));
fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase));
fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now()));
return fieldValues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1275,4 +1275,25 @@ public DocumentCreator<AsylumCase> getInternalMaintainCaseLinksLetterCreator(
documentUploader
);
}

@Bean("internalUploadAdditionalEvidenceLetter")
public DocumentCreator<AsylumCase> getInternalUploadAdditionalEvidenceLetterCreator(
@Value("${internalUploadAdditionalEvidence.contentType}") String contentType,
@Value("${internalUploadAdditionalEvidence.fileExtension}") String fileExtension,
@Value("${internalUploadAdditionalEvidence.fileName}") String fileName,
AsylumCaseFileNameQualifier fileNameQualifier,
InternalUploadAdditionalEvidenceLetterTemplate documentTemplate,
DocumentGenerator documentGenerator,
DocumentUploader documentUploader
) {
return new DocumentCreator<>(
contentType,
fileExtension,
fileName,
fileNameQualifier,
documentTemplate,
documentGenerator,
documentUploader
);
}
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ internalDetainedMaintainCaseLinks.fileExtension: PDF
internalDetainedMaintainCaseLinks.fileName: "detained-appellant-maintain-case-links-notice"
internalDetainedMaintainCaseLinks.templateName: ${IA_INTERNAL_DETAINED_MAINTAIN_CASE_LINKS_TEMPLATE:TB-IAC-LET-ENG-00026.docx}

internalUploadAdditionalEvidence.contentType: application/pdf
internalUploadAdditionalEvidence.fileExtension: PDF
internalUploadAdditionalEvidence.fileName: "additional-evidence-uploaded-letter"
internalUploadAdditionalEvidence.templateName: ${IA_INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_TEMPLATE:TB-IAC-LET-ENG-00031.docx}

ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453}

docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY}
Expand Down Expand Up @@ -484,6 +489,7 @@ security:
- "markAppealAsAda"
- "applyForFTPAAppellant"
- "maintainCaseLinks"
- "uploadAddendumEvidenceAdminOfficer"
citizen:
- "startAppeal"
- "editAppeal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ public void has_correct_values() {
assertEquals("internalHoFtpaDecidedLetter", DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER.toString());
assertEquals("internalHearingRequirementsUpdatedLetter", DocumentTag.INTERNAL_HEARING_REQUIREMENTS_UPDATED_LETTER.toString());
assertEquals("internalMaintainCaseLinksLetter", DocumentTag.INTERNAL_MAINTAIN_CASE_LINKS_LETTER.toString());
assertEquals("internalUploadAdditionalEvidenceLetter", DocumentTag.INTERNAL_UPLOAD_ADDITIONAL_EVIDENCE_LETTER.toString());
}

@Test
public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
assertEquals(65, DocumentTag.values().length);
assertEquals(66, DocumentTag.values().length);
}
}
Loading

0 comments on commit 53320c0

Please sign in to comment.