Skip to content

Commit

Permalink
RIA-7326
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 committed Aug 29, 2023
1 parent bccfd09 commit c633f01
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 4 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 @@ -56,6 +56,7 @@ public enum DocumentTag {
INTERNAL_DET_MARK_AS_ADA_LETTER("internalDetMarkAsAdaLetter", CaseType.ASYLUM),
INTERNAL_DECIDE_AN_APPLICATION_LETTER("internalDecideAnApplicationLetter", CaseType.ASYLUM),
INTERNAL_APPLY_FOR_FTPA_RESPONDENT("internalApplyForFtpaRespondent", 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),
SUBMIT_APPLICATION("submitApplication", CaseType.BAIL),
RECORD_THE_DECISION("recordTheDecision", 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 @@ -149,7 +149,10 @@ private int bundlePositionIndex(DocumentWithMetadata document) {
return 49;
case INTERNAL_APPLY_FOR_FTPA_RESPONDENT:
log.warn("INTERNAL_APPLY_FOR_FTPA_RESPONDENT_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 49;
return 50;
case INTERNAL_FTPA_SUBMITTED_LETTER:
log.warn("INTERNAL_FTPA_SUBMITTED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 51;
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 @@ -1023,4 +1023,25 @@ public DocumentCreator<AsylumCase> getInternalFtpaSubmittedDocumentCreator(
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 @@ -314,6 +314,11 @@ internalDetainedApplyForFtpaRespondentLetter.fileExtension: PDF
internalDetainedApplyForFtpaRespondentLetter.fileName: "apply-for-ftpa-respondent-letter"
internalDetainedApplyForFtpaRespondentLetter.templateName: ${IA_INTERNAL_DETAINED_APPLY_FOR_FTPA_RESPONDENT_LETTER_TEMPLATE:TB-IAC-LET-ENG-00009.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 @@ -415,6 +420,7 @@ security:
- "markAppealPaid"
- "recordRemissionDecision"
- "markAppealAsAda"
- "applyForFTPAAppellant"
citizen:
- "startAppeal"
- "editAppeal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public void has_correct_values() {
assertEquals("internalDetMarkAsAdaLetter", DocumentTag.INTERNAL_DET_MARK_AS_ADA_LETTER.toString());
assertEquals("internalDecideAnApplicationLetter", DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER.toString());
assertEquals("internalApplyForFtpaRespondent", DocumentTag.INTERNAL_APPLY_FOR_FTPA_RESPONDENT.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(58, DocumentTag.values().length);
assertEquals(59, DocumentTag.values().length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public void has_correct_values() {
assertEquals("markAppealAsAda", Event.MARK_APPEAL_AS_ADA.toString());
assertEquals("decideAnApplication", Event.DECIDE_AN_APPLICATION.toString());
assertEquals("applyForFTPARespondent", Event.APPLY_FOR_FTPA_RESPONDENT.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(53, Event.values().length);
assertEquals(54, Event.values().length);
}
}
Loading

0 comments on commit c633f01

Please sign in to comment.