Skip to content

Commit

Permalink
RIA-7326 (#663)
Browse files Browse the repository at this point in the history
* Added functionality to generate letter when admin officer applies for ftpa for internal cases
* Added/updated tests
  • Loading branch information
hussain-faruk authored Aug 30, 2023
1 parent 86dcd7a commit 9c71c35
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "RIA-7326 internal ADA apply for ftpa (appellant) letter generation",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"id": 7326,
"eventId": "applyForFTPAAppellant",
"state": "decided",
"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",
"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-apply-for-ftpa-appellant-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalFtpaSubmittedLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"description": "RIA-7326 internal detained (non-ada) apply for ftpa (appellant) letter generation",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "AdminOfficer",
"input": {
"id": 7326,
"eventId": "applyForFTPAAppellant",
"state": "decided",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "Yes"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"appellantInDetention": "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-apply-for-ftpa-appellant-letter.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalFtpaSubmittedLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum DocumentTag {
INTERNAL_DECIDE_AN_APPLICATION_LETTER("internalDecideAnApplicationLetter", CaseType.ASYLUM),
INTERNAL_APPLY_FOR_FTPA_RESPONDENT("internalApplyForFtpaRespondent", CaseType.ASYLUM),
INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER("internalDetainedTransferOutOfAdaLetter", CaseType.ASYLUM),
INTERNAL_FTPA_SUBMITTED_LETTER("internalFtpaSubmittedLetter", CaseType.ASYLUM),
BAIL_SUBMISSION("bailSubmission", CaseType.BAIL),
BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL),
BAIL_DECISION_UNSIGNED("bailDecisionUnsigned", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum Event {
REQUEST_RESPONSE_REVIEW("requestResponseReview", CaseType.ASYLUM),
MARK_APPEAL_AS_ADA("markAppealAsAda", CaseType.ASYLUM),
APPLY_FOR_FTPA_RESPONDENT("applyForFTPARespondent", CaseType.ASYLUM),
APPLY_FOR_FTPA_APPELLANT("applyForFTPAAppellant", CaseType.ASYLUM),
DECIDE_AN_APPLICATION("decideAnApplication", CaseType.ASYLUM),
TRANSFER_OUT_OF_ADA("transferOutOfAda", CaseType.ASYLUM),
SUBMIT_APPLICATION("submitApplication", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter;

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase;

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 InternalApplyForFtpaAppellantLetterGenerator implements PreSubmitCallbackHandler<AsylumCase> {

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

public InternalApplyForFtpaAppellantLetterGenerator(
@Qualifier("internalApplyForFtpaAppellantLetter") DocumentCreator<AsylumCase> internalApplyForFtpaAppellantLetter,
DocumentHandler documentHandler
) {
this.internalApplyForFtpaAppellantLetter = internalApplyForFtpaAppellantLetter;
this.documentHandler = documentHandler;
}

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

return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
&& callback.getEvent() == Event.APPLY_FOR_FTPA_APPELLANT
&& 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 documentForUpload = internalApplyForFtpaAppellantLetter.create(caseDetails);

documentHandler.addWithMetadata(
asylumCase,
documentForUpload,
NOTIFICATION_ATTACHMENT_DOCUMENTS,
DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER
);

return new PreSubmitCallbackResponse<>(asylumCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ private int bundlePositionIndex(DocumentWithMetadata document) {
case INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER:
log.warn("INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 51;
case INTERNAL_FTPA_SUBMITTED_LETTER:
log.warn("INTERNAL_FTPA_SUBMITTED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 52;
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,51 @@
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.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.DateProvider;
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 InternalApplyForFtpaAppellantLetterTemplate implements DocumentTemplate<AsylumCase> {

private final String templateName;
private final DateProvider dateProvider;
private final CustomerServicesProvider customerServicesProvider;


public InternalApplyForFtpaAppellantLetterTemplate(
@Value("${internalApplyForFtpaAppellantLetter.templateName}") String templateName,
DateProvider dateProvider,
CustomerServicesProvider customerServicesProvider) {
this.templateName = templateName;
this.dateProvider = dateProvider;
this.customerServicesProvider = customerServicesProvider;
}

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("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now()));
fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase));
fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase));

return fieldValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1044,4 +1044,25 @@ public DocumentCreator<AsylumCase> getInternalDetainedTransferOutOfAdaLetterCrea
documentUploader
);
}

@Bean("internalApplyForFtpaAppellantLetter")
public DocumentCreator<AsylumCase> getInternalApplyForFtpaAppellantLetterCreator(
@Value("${internalApplyForFtpaAppellantLetter.contentType}") String contentType,
@Value("${internalApplyForFtpaAppellantLetter.fileExtension}") String fileExtension,
@Value("${internalApplyForFtpaAppellantLetter.fileName}") String fileName,
AsylumCaseFileNameQualifier fileNameQualifier,
InternalApplyForFtpaAppellantLetterTemplate 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 @@ -319,6 +319,11 @@ internalDetainedTransferOutOfAdaLetter.fileExtension: PDF
internalDetainedTransferOutOfAdaLetter.fileName: "detained-appellant-transferred-out-of-ada"
internalDetainedTransferOutOfAdaLetter.templateName: ${IA_INTERNAL_DETAINED_TRANSFERRED_OUT_OF_ADA_LETTER_TEMPLATE:TB-IAC-DEC-ENG-00014.docx}

internalApplyForFtpaAppellantLetter.contentType: application/pdf
internalApplyForFtpaAppellantLetter.fileExtension: PDF
internalApplyForFtpaAppellantLetter.fileName: "apply-for-ftpa-appellant-letter"
internalApplyForFtpaAppellantLetter.templateName: ${IA_INTERNAL_APPLY_FOR_FTPA_APPELLANT_LETTER_TEMPLATE:TB-IAC-LET-ENG-00017.docx}

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

docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY}
Expand Down Expand Up @@ -421,6 +426,7 @@ security:
- "markAppealPaid"
- "recordRemissionDecision"
- "markAppealAsAda"
- "applyForFTPAAppellant"
citizen:
- "startAppeal"
- "editAppeal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public void has_correct_values() {
assertEquals("internalDecideAnApplicationLetter", DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER.toString());
assertEquals("internalApplyForFtpaRespondent", DocumentTag.INTERNAL_APPLY_FOR_FTPA_RESPONDENT.toString());
assertEquals("internalDetainedTransferOutOfAdaLetter", DocumentTag.INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER.toString());
assertEquals("internalFtpaSubmittedLetter", DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER.toString());
}

@Test
public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
assertEquals(59, DocumentTag.values().length);
assertEquals(60, DocumentTag.values().length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public void has_correct_values() {
assertEquals("decideAnApplication", Event.DECIDE_AN_APPLICATION.toString());
assertEquals("applyForFTPARespondent", Event.APPLY_FOR_FTPA_RESPONDENT.toString());
assertEquals("transferOutOfAda", Event.TRANSFER_OUT_OF_ADA.toString());
assertEquals("applyForFTPAAppellant", Event.APPLY_FOR_FTPA_APPELLANT.toString());
}

@Test
public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
assertEquals(54, Event.values().length);
assertEquals(55, Event.values().length);
}
}
Loading

0 comments on commit 9c71c35

Please sign in to comment.