Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIA-7331 Internal appellant ftpa decided - partially granted document #676

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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}"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHandler<AsylumCase> {

private final DocumentCreator<AsylumCase> internalAppellantFtpaDecidedGrantedLetter;
private final DocumentCreator<AsylumCase> internalAppellantFtpaDecidedPartiallyGrantedLetter;
private final DocumentCreator<AsylumCase> internalHoFtpaDecidedGrantedLetter;
private final DocumentCreator<AsylumCase> internalHoFtpaDecidedPartiallyGrantedLetter;
private final DocumentCreator<AsylumCase> internalHoFtpaDecidedRefusedLetter;
Expand All @@ -34,12 +35,14 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHand

public InternalFtpaDecidedLetterGenerator(
@Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator<AsylumCase> internalAppellantFtpaDecidedGrantedLetter,
@Qualifier("internalAppellantFtpaDecidedPartiallyGrantedLetter") DocumentCreator<AsylumCase> internalAppellantFtpaDecidedPartiallyGrantedLetter,
@Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator<AsylumCase> internalHoFtpaDecidedGrantedLetter,
@Qualifier("internalHoFtpaDecidedPartiallyGrantedLetter") DocumentCreator<AsylumCase> internalHoFtpaDecidedPartiallyGrantedLetter,
@Qualifier("internalHoFtpaDecidedRefusedLetter") DocumentCreator<AsylumCase> internalHoFtpaDecidedRefusedLetter,
DocumentHandler documentHandler
) {
this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter;
this.internalAppellantFtpaDecidedPartiallyGrantedLetter = internalAppellantFtpaDecidedPartiallyGrantedLetter;
this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter;
this.internalHoFtpaDecidedPartiallyGrantedLetter = internalHoFtpaDecidedPartiallyGrantedLetter;
this.internalHoFtpaDecidedRefusedLetter = internalHoFtpaDecidedRefusedLetter;
Expand Down Expand Up @@ -85,6 +88,8 @@ public PreSubmitCallbackResponse<AsylumCase> 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);
}
Expand All @@ -102,12 +107,6 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
}
documentTag = DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER;
}
documentHandler.addWithMetadata(
asylumCase,
documentForUpload,
LEGAL_REPRESENTATIVE_DOCUMENTS,
documentTag
);

documentHandler.addWithMetadata(
asylumCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AsylumCase> {

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<String, Object> mapFieldValues(
CaseDetails<AsylumCase> caseDetails
) {
final AsylumCase asylumCase = caseDetails.getCaseData();
final Map<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1149,4 +1149,25 @@ public DocumentCreator<AsylumCase> getInternalHoFtpaDecidedRefusedDocumentCreato
documentUploader
);
}

@Bean("internalAppellantFtpaDecidedPartiallyGrantedLetter")
public DocumentCreator<AsylumCase> 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
);
}
}
7 changes: 7 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
class InternalFtpaDecidedLetterGeneratorTest {

@Mock
private DocumentCreator<AsylumCase> internalAppelantFtpaDecidedCreator;
private DocumentCreator<AsylumCase> internalAppelantFtpaDecidedGrantedCreator;
@Mock
private DocumentCreator<AsylumCase> internalAppelantFtpaDecidedPartiallyGrantedCreator;
@Mock
private DocumentCreator<AsylumCase> internalHoFtpaDecidedGrantedCreator;
@Mock
Expand All @@ -59,7 +61,8 @@ class InternalFtpaDecidedLetterGeneratorTest {
public void setUp() {
internalFtpaDecidedLetterGenerator =
new InternalFtpaDecidedLetterGenerator(
internalAppelantFtpaDecidedCreator,
internalAppelantFtpaDecidedGrantedCreator,
internalAppelantFtpaDecidedPartiallyGrantedCreator,
internalHoFtpaDecidedGrantedCreator,
internalHoFtpaDecidedPartiallyGrantedCreator,
internalHoFtpaDecidedRefusedCreator,
Expand All @@ -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<AsylumCase> 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<AsylumCase> callbackResponse =
internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AsylumCase> 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<String, Object> 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<String, Object> 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<String, Object> templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails);
Assertions.assertEquals(formatDateForNotificationAttachmentDocument(now.plusDays(nonAdaDueInCalendarDays)), templateFieldValues.get("utApplicationDeadline"));
}
}
Loading