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")); + } +}