From 84bcae0cb3e31625b2e446169fa064af58554c43 Mon Sep 17 00:00:00 2001 From: ikirsanov <105438011+ikirsanov@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:05:50 +0200 Subject: [PATCH 1/5] RIA-7360 ho_ftpa_decided_granted (#671) * RIA-7552_appeal_can_proceed: Add Asylum case definition for Record out of time decision, Letter template, Letter generator and configuration, tests * RIA-7360_ho_ftpa_decided_granted: Add Letter, Configuration, changes to InternalFtpaDecidedLetterGenerator for HO FTPA decided granted. Add Tests and functional test, Document.tag, Definitions. --- ...rnal-ho-ftpa-decided-granted-document.json | 48 ++++++++++++ .../domain/entities/AsylumCaseDefinition.java | 9 ++- .../domain/entities/DocumentTag.java | 1 + .../InternalFtpaDecidedLetterGenerator.java | 43 ++++++---- .../domain/service/BundleOrder.java | 5 +- ...nalHoFtpaDecidedGrantedLetterTemplate.java | 47 +++++++++++ .../config/DocumentCreatorConfiguration.java | 21 +++++ src/main/resources/application.yaml | 5 ++ .../domain/entities/DocumentTagTest.java | 3 +- ...nternalFtpaDecidedLetterGeneratorTest.java | 31 +++++++- .../domain/service/BundleOrderTest.java | 2 +- ...oFtpaDecidedGrantedLetterTemplateTest.java | 78 +++++++++++++++++++ 12 files changed, 271 insertions(+), 22 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json b/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json new file mode 100644 index 000000000..2f5a19603 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7360 Internal HO ftpa decided - granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7360, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "granted", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "granted", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java index 044eb3ae2..6cff1682a 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java @@ -562,14 +562,21 @@ public enum AsylumCaseDefinition { DECIDE_AN_APPLICATION_ID( "decideAnApplicationId", new TypeReference(){}), + TRANSFER_OUT_OF_ADA_REASON( "transferOutOfAdaReason", new TypeReference(){}), + TRANSFER_OUT_OF_ADA_MORE_DETAILS( "transferOutOfAdaMoreDetails", new TypeReference(){}), + FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE( "ftpaAppellantRjDecisionOutcomeType", new TypeReference(){}), + FTPA_APPLICANT_TYPE( - "ftpaApplicantType", new TypeReference(){}); + "ftpaApplicantType", new TypeReference(){}), + + FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE( + "ftpaRespondentRjDecisionOutcomeType", new TypeReference(){}); private final String value; private final TypeReference typeReference; diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java index f8980e271..557938e29 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java @@ -59,6 +59,7 @@ public enum DocumentTag { INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER("internalDetainedTransferOutOfAdaLetter", CaseType.ASYLUM), INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER("internalFtpaSubmittedAppellantLetter", CaseType.ASYLUM), INTERNAL_APPELLANT_FTPA_DECIDED_LETTER("internalAppellantFtpaDecidedLetter", CaseType.ASYLUM), + INTERNAL_HO_FTPA_DECIDED_LETTER("internalHoFtpaDecidedLetter", CaseType.ASYLUM), BAIL_SUBMISSION("bailSubmission", CaseType.BAIL), BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java index c6b44defd..3ee5a5d73 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java @@ -26,34 +26,37 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHandler { private final DocumentCreator internalAppellantFtpaDecidedGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedGrantedLetter; private final DocumentHandler documentHandler; private final String ftpaApplicantAppellant = "appellant"; public InternalFtpaDecidedLetterGenerator( - @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, - DocumentHandler documentHandler + @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, + @Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator internalHoFtpaDecidedGrantedLetter, + DocumentHandler documentHandler ) { this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter; + this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter; this.documentHandler = documentHandler; } public boolean canHandle( - PreSubmitCallbackStage callbackStage, - Callback callback + PreSubmitCallbackStage callbackStage, + Callback 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.RESIDENT_JUDGE_FTPA_DECISION - && isInternalCase(asylumCase) - && isAppellantInDetention(asylumCase); + && callback.getEvent() == Event.RESIDENT_JUDGE_FTPA_DECISION + && isInternalCase(asylumCase) + && isAppellantInDetention(asylumCase); } public PreSubmitCallbackResponse handle( - PreSubmitCallbackStage callbackStage, - Callback callback + PreSubmitCallbackStage callbackStage, + Callback callback ) { if (!canHandle(callbackStage, callback)) { throw new IllegalStateException("Cannot handle callback"); @@ -63,11 +66,15 @@ public PreSubmitCallbackResponse handle( final AsylumCase asylumCase = caseDetails.getCaseData(); Optional ftpaAppellantDecisionOutcomeType = asylumCase - .read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); + .read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); + + Optional ftpaRespondentDecisionOutcomeType = asylumCase + .read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); Optional ftpaApplicantType = asylumCase.read(FTPA_APPLICANT_TYPE, String.class); Document documentForUpload; + DocumentTag documentTag; if (ftpaApplicantType.equals(Optional.of(ftpaApplicantAppellant))) { if (ftpaAppellantDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { @@ -75,15 +82,21 @@ public PreSubmitCallbackResponse handle( } else { return new PreSubmitCallbackResponse<>(asylumCase); } + documentTag = DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER; } else { - return new PreSubmitCallbackResponse<>(asylumCase); + if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { + documentForUpload = internalHoFtpaDecidedGrantedLetter.create(caseDetails); + } else { + return new PreSubmitCallbackResponse<>(asylumCase); + } + documentTag = DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER; } documentHandler.addWithMetadata( - asylumCase, - documentForUpload, - NOTIFICATION_ATTACHMENT_DOCUMENTS, - DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER + asylumCase, + documentForUpload, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + documentTag ); return new PreSubmitCallbackResponse<>(asylumCase); diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java index c2ca84a86..d7a0eb2f8 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java @@ -157,8 +157,11 @@ private int bundlePositionIndex(DocumentWithMetadata document) { log.warn("INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); return 52; case INTERNAL_APPELLANT_FTPA_DECIDED_LETTER: - log.warn("INTERNAL_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); + log.warn("INTERNAL_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); return 53; + case INTERNAL_HO_FTPA_DECIDED_LETTER: + log.warn("INTERNAL_HO_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); + return 54; default: throw new IllegalStateException("document has unknown tag: " + document.getTag() + ", description: " + document.getDescription()); } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java new file mode 100644 index 000000000..eba60f729 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java @@ -0,0 +1,47 @@ +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 InternalHoFtpaDecidedGrantedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + + public InternalHoFtpaDecidedGrantedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java index affd0bd90..ad7562f8e 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java @@ -1086,4 +1086,25 @@ public DocumentCreator getInternalAppellantFtpaDecidedGrantedLetterC documentUploader ); } + + @Bean("internalHoFtpaDecidedGrantedLetter") + public DocumentCreator getInternalHoFtpaDecidedGrantedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 90a1c1ef3..9eaec3742 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -329,6 +329,11 @@ internalAppellantFtpaDecidedGrantedLetter.fileExtension: PDF internalAppellantFtpaDecidedGrantedLetter.fileName: "appellant-ftpa-decided-granted-letter" internalAppellantFtpaDecidedGrantedLetter.templateName: ${IA_INTERNAL_APPELLANT_FTPA_DECIDED_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00018.docx} +internalDetainedHoFtpaDecidedGrantedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedGrantedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedGrantedLetter.fileName: "ho-ftpa-decided-granted-letter" +internalDetainedHoFtpaDecidedGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00019.docx} + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java index 518fef2e1..f2dd6d973 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java @@ -62,10 +62,11 @@ public void has_correct_values() { assertEquals("internalDetainedTransferOutOfAdaLetter", DocumentTag.INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER.toString()); assertEquals("internalFtpaSubmittedAppellantLetter", DocumentTag.INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER.toString()); assertEquals("internalAppellantFtpaDecidedLetter", DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER.toString()); + assertEquals("internalHoFtpaDecidedLetter", DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER.toString()); } @Test public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() { - assertEquals(61, DocumentTag.values().length); + assertEquals(62, DocumentTag.values().length); } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java index 3ba7a274d..5363e2128 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java @@ -32,7 +32,9 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock - private DocumentCreator internalFtpaDecidedCreator; + private DocumentCreator internalAppelantFtpaDecidedCreator; + @Mock + private DocumentCreator internalHoFtpaDecidedCreator; @Mock private DocumentHandler documentHandler; @Mock @@ -44,13 +46,15 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock private Document uploadedDocument; private final String ftpaApplicantAppellant = "appellant"; + private final String ftpaApplicantRespondent = "respondent"; private InternalFtpaDecidedLetterGenerator internalFtpaDecidedLetterGenerator; @BeforeEach public void setUp() { internalFtpaDecidedLetterGenerator = new InternalFtpaDecidedLetterGenerator( - internalFtpaDecidedCreator, + internalAppelantFtpaDecidedCreator, + internalHoFtpaDecidedCreator, documentHandler ); @@ -67,7 +71,7 @@ void should_create_internal_appellant_ftpa_decided_granted_letter_and_append_to_ when(asylumCase.read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantAppellant)); - when(internalFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalAppelantFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); PreSubmitCallbackResponse callbackResponse = internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); @@ -83,6 +87,27 @@ void should_create_internal_appellant_ftpa_decided_granted_letter_and_append_to_ ); } + @Test + void should_create_internal_ho_ftpa_decided_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + @Test void handling_should_throw_if_cannot_actually_handle() { when(callback.getCaseDetails()).thenReturn(caseDetails); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java index 99c7fb384..e56c62bce 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java @@ -37,7 +37,7 @@ public void should_sort_in_correct_order_excluding_bail_tags() { .map(DocumentWithMetadata::getTag) .collect(Collectors.toList()); - assertEquals(55, sortedTags.size()); + assertEquals(56, sortedTags.size()); List documentTagList = Arrays.asList( DocumentTag.CASE_SUMMARY, diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java new file mode 100644 index 000000000..c68e8f0cb --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java @@ -0,0 +1,78 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +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.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedGrantedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private String appealSubmissionDate = "2023-07-01"; + private String remissionRejectedDate = "14 Jul 2023"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_GRANTED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private InternalHoFtpaDecidedGrantedLetterTemplate internalHoFtpaDecidedGrantedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedGrantedLetterTemplate = + new InternalHoFtpaDecidedGrantedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedGrantedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + when(asylumCase.read(APPELLANT_GIVEN_NAMES, String.class)).thenReturn(Optional.of(appellantGivenNames)); + when(asylumCase.read(APPELLANT_FAMILY_NAME, String.class)).thenReturn(Optional.of(appellantFamilyName)); + when(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + } + + @Test + void should_populate_template() { + dataSetup(); + fieldValuesMap = internalHoFtpaDecidedGrantedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + } +} \ No newline at end of file From 45bbf1ab966d038ebd5e8fe1c40ec8eb89e05101 Mon Sep 17 00:00:00 2001 From: ikirsanov <105438011+ikirsanov@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:52:21 +0200 Subject: [PATCH 2/5] RIA-7361 ho_ftpa_decided_partially_granted (#672) * RIA-7552_appeal_can_proceed: Add Asylum case definition for Record out of time decision, Letter template, Letter generator and configuration, tests * RIA-7361_ho_ftpa_decided_partially_granted: Add Letter, Configuration, changes to InternalFtpaDecidedLetterGenerator for HO FTPA decided partially granted. Add Tests and functional test --- ...pa-decided-partially-granted-document.json | 48 ++++++++++++ .../InternalFtpaDecidedLetterGenerator.java | 6 ++ ...aDecidedPatiallyGrantedLetterTemplate.java | 47 +++++++++++ .../config/DocumentCreatorConfiguration.java | 21 +++++ src/main/resources/application.yaml | 5 ++ ...nternalFtpaDecidedLetterGeneratorTest.java | 34 ++++++-- ...idedPatiallyGrantedLetterTemplateTest.java | 78 +++++++++++++++++++ 7 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json b/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json new file mode 100644 index 000000000..aa295f208 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7361 Internal HO ftpa decided - partially granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7361, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-partially-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java index 3ee5a5d73..fa29f7ece 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_GRANTED; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; @@ -27,16 +28,19 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHand private final DocumentCreator internalAppellantFtpaDecidedGrantedLetter; private final DocumentCreator internalHoFtpaDecidedGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter; private final DocumentHandler documentHandler; private final String ftpaApplicantAppellant = "appellant"; public InternalFtpaDecidedLetterGenerator( @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, @Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator internalHoFtpaDecidedGrantedLetter, + @Qualifier("internalHoFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter, DocumentHandler documentHandler ) { this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter; this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter; + this.internalHoFtpaDecidedPartiallyGrantedLetter = internalHoFtpaDecidedPartiallyGrantedLetter; this.documentHandler = documentHandler; } @@ -86,6 +90,8 @@ public PreSubmitCallbackResponse handle( } else { if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { documentForUpload = internalHoFtpaDecidedGrantedLetter.create(caseDetails); + } else if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_PARTIALLY_GRANTED))) { + documentForUpload = internalHoFtpaDecidedPartiallyGrantedLetter.create(caseDetails); } else { return new PreSubmitCallbackResponse<>(asylumCase); } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java new file mode 100644 index 000000000..643c07e07 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java @@ -0,0 +1,47 @@ +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 InternalHoFtpaDecidedPatiallyGrantedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + + public InternalHoFtpaDecidedPatiallyGrantedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java index ad7562f8e..0bbd38268 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java @@ -1107,4 +1107,25 @@ public DocumentCreator getInternalHoFtpaDecidedGrantedDocumentCreato documentUploader ); } + + @Bean("internalHoFtpaDecidedPartiallyGrantedLetter") + public DocumentCreator getInternalHoFtpaDecidedPartiallyGrantedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedPatiallyGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 9eaec3742..55f27aba0 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -334,6 +334,11 @@ internalDetainedHoFtpaDecidedGrantedLetter.fileExtension: PDF internalDetainedHoFtpaDecidedGrantedLetter.fileName: "ho-ftpa-decided-granted-letter" internalDetainedHoFtpaDecidedGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00019.docx} +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName: "ho-ftpa-decided-partially-granted-letter" +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_PARTIALLY_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00021.docx} + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java index 5363e2128..f32f2c4eb 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java @@ -34,7 +34,9 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock private DocumentCreator internalAppelantFtpaDecidedCreator; @Mock - private DocumentCreator internalHoFtpaDecidedCreator; + private DocumentCreator internalHoFtpaDecidedGrantedCreator; + @Mock + private DocumentCreator internalHoFtpaDecidedPartiallyGrantedCreator; @Mock private DocumentHandler documentHandler; @Mock @@ -53,9 +55,10 @@ class InternalFtpaDecidedLetterGeneratorTest { public void setUp() { internalFtpaDecidedLetterGenerator = new InternalFtpaDecidedLetterGenerator( - internalAppelantFtpaDecidedCreator, - internalHoFtpaDecidedCreator, - documentHandler + internalAppelantFtpaDecidedCreator, + internalHoFtpaDecidedGrantedCreator, + internalHoFtpaDecidedPartiallyGrantedCreator, + documentHandler ); when(callback.getEvent()).thenReturn(Event.RESIDENT_JUDGE_FTPA_DECISION); @@ -92,7 +95,28 @@ void should_create_internal_ho_ftpa_decided_granted_letter_and_append_to_notific when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); - when(internalHoFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalHoFtpaDecidedGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + + @Test + void should_create_internal_ho_ftpa_decided_partially_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedPartiallyGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); PreSubmitCallbackResponse callbackResponse = internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java new file mode 100644 index 000000000..db24955c4 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java @@ -0,0 +1,78 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +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.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private String appealSubmissionDate = "2023-07-01"; + private String remissionRejectedDate = "14 Jul 2023"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_GRANTED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private InternalHoFtpaDecidedPatiallyGrantedLetterTemplate internalHoFtpaDecidedPatiallyGrantedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedPatiallyGrantedLetterTemplate = + new InternalHoFtpaDecidedPatiallyGrantedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedPatiallyGrantedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + when(asylumCase.read(APPELLANT_GIVEN_NAMES, String.class)).thenReturn(Optional.of(appellantGivenNames)); + when(asylumCase.read(APPELLANT_FAMILY_NAME, String.class)).thenReturn(Optional.of(appellantFamilyName)); + when(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + } + + @Test + void should_populate_template() { + dataSetup(); + fieldValuesMap = internalHoFtpaDecidedPatiallyGrantedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + } +} \ No newline at end of file From 6148b11f43ea9b7e9357e21a99755d9e4c609287 Mon Sep 17 00:00:00 2001 From: hussain-faruk <118450580+hussain-faruk@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:15:22 +0100 Subject: [PATCH 3/5] RIA-7326 (#673) * Give LR permission for applyForFTPAAppellant event doc generation --- src/main/resources/application.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 55f27aba0..2b98db0dc 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -387,6 +387,7 @@ security: - "submitApplication" - "makeNewApplication" - "requestHearingRequirementsFeature" + - "applyForFTPAAppellant" caseworker-ia-caseofficer: - "sendDirection" - "changeDirectionDueDate" From 961915c20b2d02337d5a135ea1c4ffcf460436b7 Mon Sep 17 00:00:00 2001 From: ikirsanov <105438011+ikirsanov@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:30:32 +0200 Subject: [PATCH 4/5] RIA-7362 ho_ftpa_decided_refused (#675) * RIA-7552_appeal_can_proceed: Add Asylum case definition for Record out of time decision, Letter template, Letter generator and configuration, tests * RIA-7362_ho_ftpa_decided_refused: Add Letter, Configuration, changes to InternalFtpaDecidedLetterGenerator for HO FTPA decided refused. Add Tests and functional test * RIA-7362_ho_ftpa_decided_refused: Fix typo --- ...rnal-ho-ftpa-decided-refused-document.json | 48 +++++++++ .../entities/FtpaDecisionOutcomeType.java | 3 +- .../InternalFtpaDecidedLetterGenerator.java | 15 ++- ...ecidedPartiallyGrantedLetterTemplate.java} | 4 +- ...nalHoFtpaDecidedRefusedLetterTemplate.java | 55 ++++++++++ .../config/DocumentCreatorConfiguration.java | 23 +++- src/main/resources/application.yaml | 5 + ...nternalFtpaDecidedLetterGeneratorTest.java | 27 +++++ ...edPartiallyGrantedLetterTemplateTest.java} | 16 ++- ...oFtpaDecidedRefusedLetterTemplateTest.java | 100 ++++++++++++++++++ 10 files changed, 281 insertions(+), 15 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json rename src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java => InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java} (92%) create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java rename src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java => InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java} (82%) create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json b/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json new file mode 100644 index 000000000..f007d1375 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7362 Internal HO ftpa decided - refused letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7362, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "refused", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "refused", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-refused-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java index 5e478c5f5..93c0fc86f 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java @@ -6,7 +6,8 @@ public enum FtpaDecisionOutcomeType { FTPA_GRANTED("granted"), FTPA_PARTIALLY_GRANTED("partiallyGranted"), - FTPA_REFUSED("refused"); + FTPA_REFUSED("refused"), + FTPA_NOT_ADMITTED("notAdmitted"); @JsonValue private final String value; diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java index fa29f7ece..b569beff5 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java @@ -2,8 +2,7 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_GRANTED; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.*; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; @@ -29,6 +28,7 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHand private final DocumentCreator internalAppellantFtpaDecidedGrantedLetter; private final DocumentCreator internalHoFtpaDecidedGrantedLetter; private final DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedRefusedLetter; private final DocumentHandler documentHandler; private final String ftpaApplicantAppellant = "appellant"; @@ -36,11 +36,13 @@ public InternalFtpaDecidedLetterGenerator( @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, @Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator internalHoFtpaDecidedGrantedLetter, @Qualifier("internalHoFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter, + @Qualifier("internalHoFtpaDecidedRefusedLetter") DocumentCreator internalHoFtpaDecidedRefusedLetter, DocumentHandler documentHandler ) { this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter; this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter; this.internalHoFtpaDecidedPartiallyGrantedLetter = internalHoFtpaDecidedPartiallyGrantedLetter; + this.internalHoFtpaDecidedRefusedLetter = internalHoFtpaDecidedRefusedLetter; this.documentHandler = documentHandler; } @@ -92,11 +94,20 @@ public PreSubmitCallbackResponse handle( documentForUpload = internalHoFtpaDecidedGrantedLetter.create(caseDetails); } else if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_PARTIALLY_GRANTED))) { documentForUpload = internalHoFtpaDecidedPartiallyGrantedLetter.create(caseDetails); + } else if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_REFUSED)) + || ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_NOT_ADMITTED))) { + documentForUpload = internalHoFtpaDecidedRefusedLetter.create(caseDetails); } else { return new PreSubmitCallbackResponse<>(asylumCase); } documentTag = DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER; } + documentHandler.addWithMetadata( + asylumCase, + documentForUpload, + LEGAL_REPRESENTATIVE_DOCUMENTS, + documentTag + ); documentHandler.addWithMetadata( asylumCase, diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java similarity index 92% rename from src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java rename to src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java index 643c07e07..d90ffe4de 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplate.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java @@ -14,12 +14,12 @@ import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; @Component -public class InternalHoFtpaDecidedPatiallyGrantedLetterTemplate implements DocumentTemplate { +public class InternalHoFtpaDecidedPartiallyGrantedLetterTemplate implements DocumentTemplate { private final String templateName; private final CustomerServicesProvider customerServicesProvider; - public InternalHoFtpaDecidedPatiallyGrantedLetterTemplate( + public InternalHoFtpaDecidedPartiallyGrantedLetterTemplate( @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName}") String templateName, CustomerServicesProvider customerServicesProvider) { this.templateName = templateName; diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java new file mode 100644 index 000000000..0580d65c5 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java @@ -0,0 +1,55 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_REFUSED; +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.FtpaDecisionOutcomeType; +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 InternalHoFtpaDecidedRefusedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + private final String refused = "refused"; + private final String notAdmitted = "not admitted"; + + public InternalHoFtpaDecidedRefusedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + fieldValues.put("refused", asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class) + .map(it -> it.equals(FTPA_REFUSED) ? refused : notAdmitted) + .orElseThrow(() -> new IllegalStateException("Judge decision 'refused' or 'not admitted' must be present"))); + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java index 0bbd38268..d129026f4 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java @@ -1114,7 +1114,28 @@ public DocumentCreator getInternalHoFtpaDecidedPartiallyGrantedDocum @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension}") String fileExtension, @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName}") String fileName, AsylumCaseFileNameQualifier fileNameQualifier, - InternalHoFtpaDecidedPatiallyGrantedLetterTemplate documentTemplate, + InternalHoFtpaDecidedPartiallyGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalHoFtpaDecidedRefusedLetter") + public DocumentCreator getInternalHoFtpaDecidedRefusedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedRefusedLetterTemplate documentTemplate, DocumentGenerator documentGenerator, DocumentUploader documentUploader ) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2b98db0dc..46f54cd27 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -339,6 +339,11 @@ internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension: PDF internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName: "ho-ftpa-decided-partially-granted-letter" internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_PARTIALLY_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00021.docx} +internalDetainedHoFtpaDecidedRefusedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedRefusedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedRefusedLetter.fileName: "ho-ftpa-decided-refused-letter" +internalDetainedHoFtpaDecidedRefusedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00022.docx} + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java index f32f2c4eb..135c3726f 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; @@ -38,6 +40,8 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock private DocumentCreator internalHoFtpaDecidedPartiallyGrantedCreator; @Mock + private DocumentCreator internalHoFtpaDecidedRefusedCreator; + @Mock private DocumentHandler documentHandler; @Mock private Callback callback; @@ -58,6 +62,7 @@ public void setUp() { internalAppelantFtpaDecidedCreator, internalHoFtpaDecidedGrantedCreator, internalHoFtpaDecidedPartiallyGrantedCreator, + internalHoFtpaDecidedRefusedCreator, documentHandler ); @@ -132,6 +137,28 @@ void should_create_internal_ho_ftpa_decided_partially_granted_letter_and_append_ ); } + @ParameterizedTest + @EnumSource(value = FtpaDecisionOutcomeType.class, names = {"FTPA_REFUSED", "FTPA_NOT_ADMITTED"}) + void should_create_internal_ho_ftpa_decided_refused_letter_and_append_to_notification_attachment_documents(FtpaDecisionOutcomeType ftpaDecisionOutcomeType) { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(ftpaDecisionOutcomeType)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedRefusedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + @Test void handling_should_throw_if_cannot_actually_handle() { when(callback.getCaseDetails()).thenReturn(caseDetails); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java similarity index 82% rename from src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java rename to src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java index db24955c4..ec7f3e418 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java @@ -22,7 +22,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) @SuppressWarnings("unchecked") @ExtendWith(MockitoExtension.class) -class InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest { +class InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest { @Mock private CaseDetails caseDetails; @@ -36,22 +36,20 @@ class InternalHoFtpaDecidedPatiallyGrantedLetterTemplateTest { private String appellantFamilyName = "Smith"; private String homeOfficeReferenceNumber = "123654"; private String appealReferenceNumber = "HU/11111/2022"; - private String appealSubmissionDate = "2023-07-01"; - private String remissionRejectedDate = "14 Jul 2023"; - private final String templateName = "INTERNAL_HO_FTPA_DECIDED_GRANTED_NOTICE_TEMPLATE.docx"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_PARTIALLY_GRANTED_NOTICE_TEMPLATE.docx"; private final String logo = "[userImage:hmcts.png]"; - private InternalHoFtpaDecidedPatiallyGrantedLetterTemplate internalHoFtpaDecidedPatiallyGrantedLetterTemplate; + private InternalHoFtpaDecidedPartiallyGrantedLetterTemplate internalHoFtpaDecidedPartiallyGrantedLetterTemplate; private Map fieldValuesMap; @BeforeEach public void setUp() { - internalHoFtpaDecidedPatiallyGrantedLetterTemplate = - new InternalHoFtpaDecidedPatiallyGrantedLetterTemplate(templateName, customerServicesProvider); + internalHoFtpaDecidedPartiallyGrantedLetterTemplate = + new InternalHoFtpaDecidedPartiallyGrantedLetterTemplate(templateName, customerServicesProvider); } @Test void should_return_template_name() { - assertEquals(templateName, internalHoFtpaDecidedPatiallyGrantedLetterTemplate.getName()); + assertEquals(templateName, internalHoFtpaDecidedPartiallyGrantedLetterTemplate.getName()); } void dataSetup() { @@ -67,7 +65,7 @@ void dataSetup() { @Test void should_populate_template() { dataSetup(); - fieldValuesMap = internalHoFtpaDecidedPatiallyGrantedLetterTemplate.mapFieldValues(caseDetails); + fieldValuesMap = internalHoFtpaDecidedPartiallyGrantedLetterTemplate.mapFieldValues(caseDetails); assertEquals(logo, fieldValuesMap.get("hmcts")); assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java new file mode 100644 index 000000000..db73ddc38 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java @@ -0,0 +1,100 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedRefusedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_REFUSED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private final String refused = "refused"; + private final String notAdmitted = "not admitted"; + private InternalHoFtpaDecidedRefusedLetterTemplate internalHoFtpaDecidedRefusedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedRefusedLetterTemplate = + new InternalHoFtpaDecidedRefusedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedRefusedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + when(asylumCase.read(APPELLANT_GIVEN_NAMES, String.class)).thenReturn(Optional.of(appellantGivenNames)); + when(asylumCase.read(APPELLANT_FAMILY_NAME, String.class)).thenReturn(Optional.of(appellantFamilyName)); + when(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_REFUSED)); + } + + @ParameterizedTest + @EnumSource(value = FtpaDecisionOutcomeType.class, names = {"FTPA_REFUSED", "FTPA_NOT_ADMITTED"}) + void should_populate_template(FtpaDecisionOutcomeType ftpaDecisionOutcomeType) { + dataSetup(); + + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(ftpaDecisionOutcomeType)); + + fieldValuesMap = internalHoFtpaDecidedRefusedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + assertEquals(ftpaDecisionOutcomeType.equals(FtpaDecisionOutcomeType.FTPA_REFUSED) + ? refused + : notAdmitted, fieldValuesMap.get("refused")); + } + + @Test + void should_throw_if_refused_decision_is_not_present() { + dataSetup(); + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.empty()); + + assertThatThrownBy(() -> internalHoFtpaDecidedRefusedLetterTemplate.mapFieldValues(caseDetails)) + .isExactlyInstanceOf(IllegalStateException.class) + .hasMessage("Judge decision 'refused' or 'not admitted' must be present"); + } +} \ No newline at end of file From c6f3893837dea2466d8337bdd6d6b348b9726ff4 Mon Sep 17 00:00:00 2001 From: Ryan-Nesbitt <95298094+Ryan-Nesbitt@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:52:56 +0100 Subject: [PATCH 5/5] RIA-7331 Internal appellant ftpa decided - partially granted document (#676) * RIA-7331 Internal appellant ftpa decided - partially granted document * RIA-7331 Corrected deadline date values for ada and non-ada --- ...ellant-ftpa-decided-partially-granted.json | 48 +++++++ .../InternalFtpaDecidedLetterGenerator.java | 11 +- ...ntFtpaDecidedPartiallyGrantedTemplate.java | 62 ++++++++++ .../config/DocumentCreatorConfiguration.java | 21 ++++ src/main/resources/application.yaml | 7 ++ ...nternalFtpaDecidedLetterGeneratorTest.java | 30 ++++- ...paDecidedPartiallyGrantedTemplateTest.java | 117 ++++++++++++++++++ 7 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json b/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json new file mode 100644 index 000000000..e935c7845 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7331 Internal appellant ftpa decided - partially granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7331, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaAppellantRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "appellant" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaAppellantRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "appellant", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalAppellantFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-appellant-ftpa-decided-partially-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java index b569beff5..2eac9e30b 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java @@ -26,6 +26,7 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHandler { private final DocumentCreator internalAppellantFtpaDecidedGrantedLetter; + private final DocumentCreator internalAppellantFtpaDecidedPartiallyGrantedLetter; private final DocumentCreator internalHoFtpaDecidedGrantedLetter; private final DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter; private final DocumentCreator internalHoFtpaDecidedRefusedLetter; @@ -34,12 +35,14 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHand public InternalFtpaDecidedLetterGenerator( @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, + @Qualifier("internalAppellantFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalAppellantFtpaDecidedPartiallyGrantedLetter, @Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator internalHoFtpaDecidedGrantedLetter, @Qualifier("internalHoFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter, @Qualifier("internalHoFtpaDecidedRefusedLetter") DocumentCreator internalHoFtpaDecidedRefusedLetter, DocumentHandler documentHandler ) { this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter; + this.internalAppellantFtpaDecidedPartiallyGrantedLetter = internalAppellantFtpaDecidedPartiallyGrantedLetter; this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter; this.internalHoFtpaDecidedPartiallyGrantedLetter = internalHoFtpaDecidedPartiallyGrantedLetter; this.internalHoFtpaDecidedRefusedLetter = internalHoFtpaDecidedRefusedLetter; @@ -85,6 +88,8 @@ public PreSubmitCallbackResponse handle( if (ftpaApplicantType.equals(Optional.of(ftpaApplicantAppellant))) { if (ftpaAppellantDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { documentForUpload = internalAppellantFtpaDecidedGrantedLetter.create(caseDetails); + } else if (ftpaAppellantDecisionOutcomeType.equals(Optional.of(FTPA_PARTIALLY_GRANTED))) { + documentForUpload = internalAppellantFtpaDecidedPartiallyGrantedLetter.create(caseDetails); } else { return new PreSubmitCallbackResponse<>(asylumCase); } @@ -102,12 +107,6 @@ public PreSubmitCallbackResponse handle( } documentTag = DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER; } - documentHandler.addWithMetadata( - asylumCase, - documentForUpload, - LEGAL_REPRESENTATIVE_DOCUMENTS, - documentTag - ); documentHandler.addWithMetadata( asylumCase, diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java new file mode 100644 index 000000000..de71fed5a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java @@ -0,0 +1,62 @@ +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.AsylumCaseUtils.isAcceleratedDetainedAppeal; +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.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 InternalAppellantFtpaDecidedPartiallyGrantedTemplate implements DocumentTemplate { + + private final String templateName; + private final DateProvider dateProvider; + private final CustomerServicesProvider customerServicesProvider; + private final int adaDueInCalendarDays; + private final int nonAdaDueInCalendarDays; + + public InternalAppellantFtpaDecidedPartiallyGrantedTemplate( + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.templateName}") String templateName, + DateProvider dateProvider, + CustomerServicesProvider customerServicesProvider, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaAdaDueCalendarDays}") int adaDueInCalendarDays, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaNonAdaDueCalendarDays}") int nonAdaDueInCalendarDays) { + this.templateName = templateName; + this.dateProvider = dateProvider; + this.customerServicesProvider = customerServicesProvider; + this.adaDueInCalendarDays = adaDueInCalendarDays; + this.nonAdaDueInCalendarDays = nonAdaDueInCalendarDays; + } + + public String getName() { + return templateName; + } + + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + final Map fieldValues = new HashMap<>(); + + LocalDate dueDate = isAcceleratedDetainedAppeal(asylumCase) + ? LocalDate.now().plusDays(adaDueInCalendarDays) + : LocalDate.now().plusDays(nonAdaDueInCalendarDays); + + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now())); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("utApplicationDeadline", formatDateForNotificationAttachmentDocument(dueDate)); + + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java index d129026f4..4f4ae29f2 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java @@ -1149,4 +1149,25 @@ public DocumentCreator getInternalHoFtpaDecidedRefusedDocumentCreato documentUploader ); } + + @Bean("internalAppellantFtpaDecidedPartiallyGrantedLetter") + public DocumentCreator getInternalAppellantFtpaDecidedPartiallyGrantedLetterCreator( + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.contentType}") String contentType, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalAppellantFtpaDecidedPartiallyGrantedTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 46f54cd27..452734031 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -344,6 +344,13 @@ internalDetainedHoFtpaDecidedRefusedLetter.fileExtension: PDF internalDetainedHoFtpaDecidedRefusedLetter.fileName: "ho-ftpa-decided-refused-letter" internalDetainedHoFtpaDecidedRefusedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00022.docx} +internalAppellantFtpaDecidedPartiallyGrantedLetter.contentType: application/pdf +internalAppellantFtpaDecidedPartiallyGrantedLetter.fileExtension: PDF +internalAppellantFtpaDecidedPartiallyGrantedLetter.fileName: "appellant-ftpa-decided-partially-granted-letter" +internalAppellantFtpaDecidedPartiallyGrantedLetter.templateName: ${IA_INTERNAL_APPELLANT_FTPA_DECIDED_PARTIALLY_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00020.docx} +internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaAdaDueCalendarDays: 7 +internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaNonAdaDueCalendarDays: 14 + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java index 135c3726f..6581233c7 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java @@ -34,7 +34,9 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock - private DocumentCreator internalAppelantFtpaDecidedCreator; + private DocumentCreator internalAppelantFtpaDecidedGrantedCreator; + @Mock + private DocumentCreator internalAppelantFtpaDecidedPartiallyGrantedCreator; @Mock private DocumentCreator internalHoFtpaDecidedGrantedCreator; @Mock @@ -59,7 +61,8 @@ class InternalFtpaDecidedLetterGeneratorTest { public void setUp() { internalFtpaDecidedLetterGenerator = new InternalFtpaDecidedLetterGenerator( - internalAppelantFtpaDecidedCreator, + internalAppelantFtpaDecidedGrantedCreator, + internalAppelantFtpaDecidedPartiallyGrantedCreator, internalHoFtpaDecidedGrantedCreator, internalHoFtpaDecidedPartiallyGrantedCreator, internalHoFtpaDecidedRefusedCreator, @@ -79,7 +82,28 @@ void should_create_internal_appellant_ftpa_decided_granted_letter_and_append_to_ when(asylumCase.read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantAppellant)); - when(internalAppelantFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalAppelantFtpaDecidedGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER + ); + } + + @Test + void should_create_internal_appellant_ftpa_decided_partially_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantAppellant)); + + when(internalAppelantFtpaDecidedPartiallyGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); PreSubmitCallbackResponse callbackResponse = internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java new file mode 100644 index 000000000..2e42b97cd --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java @@ -0,0 +1,117 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +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.entities.ccd.field.YesOrNo; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private DateProvider dateProvider; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String templateName = "TB-IAC-LET-ENG-00020.docx"; + private final String customerServicesTelephone = "0300 123 1711"; + private final String customerServicesEmail = "email@example.com"; + private final String appealReferenceNumber = "RP/11111/2020"; + private final String homeOfficeReferenceNumber = "A1234567/001"; + private final String appellantGivenNames = "John"; + private final String appellantFamilyName = "Doe"; + private final int adaDueInCalendarDays = 7; + private final int nonAdaDueInCalendarDays = 14; + private final LocalDate now = LocalDate.now(); + private InternalAppellantFtpaDecidedPartiallyGrantedTemplate internalAppellantFtpaDecidedPartiallyGrantedTemplate; + + @BeforeEach + void setUp() { + internalAppellantFtpaDecidedPartiallyGrantedTemplate = + new InternalAppellantFtpaDecidedPartiallyGrantedTemplate( + templateName, + dateProvider, + customerServicesProvider, + adaDueInCalendarDays, + nonAdaDueInCalendarDays + ); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + when(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + when(asylumCase.read(APPELLANT_GIVEN_NAMES, String.class)).thenReturn(Optional.of(appellantGivenNames)); + when(asylumCase.read(APPELLANT_FAMILY_NAME, String.class)).thenReturn(Optional.of(appellantFamilyName)); + when(asylumCase.read(APPELLANT_IN_DETENTION, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)) + .thenReturn(customerServicesTelephone); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)) + .thenReturn(customerServicesEmail); + + when(dateProvider.now()).thenReturn(LocalDate.now()); + } + + @Test + void should_return_template_name() { + Assertions.assertEquals(templateName, internalAppellantFtpaDecidedPartiallyGrantedTemplate.getName()); + } + + @Test + void should_map_case_data_to_template_field_values() { + dataSetup(); + + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + + assertEquals(9, templateFieldValues.size()); + assertEquals("[userImage:hmcts.png]", templateFieldValues.get("hmcts")); + assertEquals(appealReferenceNumber, templateFieldValues.get("appealReferenceNumber")); + assertEquals(homeOfficeReferenceNumber, templateFieldValues.get("homeOfficeReferenceNumber")); + assertEquals(appellantGivenNames, templateFieldValues.get("appellantGivenNames")); + assertEquals(appellantFamilyName, templateFieldValues.get("appellantFamilyName")); + assertEquals(customerServicesTelephone, templateFieldValues.get("customerServicesTelephone")); + assertEquals(customerServicesEmail, templateFieldValues.get("customerServicesEmail")); + + assertEquals(formatDateForNotificationAttachmentDocument(dateProvider.now()), templateFieldValues.get("dateLetterSent")); + + } + + @Test + void should_return_7_calendar_days_for_ada() { + dataSetup(); + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + Assertions.assertEquals(formatDateForNotificationAttachmentDocument(now.plusDays(adaDueInCalendarDays)), templateFieldValues.get("utApplicationDeadline")); + } + + @Test + void should_return_14_calendar_days_for_non_ada() { + dataSetup(); + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.NO)); + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + Assertions.assertEquals(formatDateForNotificationAttachmentDocument(now.plusDays(nonAdaDueInCalendarDays)), templateFieldValues.get("utApplicationDeadline")); + } +}