Skip to content

Commit

Permalink
RIA-7701 Added transfer out of ADA letter
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKKC committed Aug 29, 2023
1 parent bccfd09 commit 3396567
Show file tree
Hide file tree
Showing 13 changed files with 471 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"description": "RIA-7701 Internal detained transfer out of ada letter",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "CaseOfficer",
"input": {
"eventId": "transferOutOfAda",
"state": "appealSubmitted",
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"transferOutOfAdaReason": "Determined unsuitable following Suitability Assessment",
"transferOutOfAdaMoreDetails": "More transfer out of ADA details",
"isAcceleratedDetainedAppeal": "No",
"appellantInDetention": "Yes"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-internal-appeal-submitted.json",
"replacements": {
"transferOutOfAdaReason": "Determined unsuitable following Suitability Assessment",
"transferOutOfAdaMoreDetails": "More transfer out of ADA details",
"isAcceleratedDetainedAppeal": "No",
"appellantInDetention": "Yes",
"notificationAttachmentDocuments": [
{
"id": "1",
"value": {
"document": {
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/",
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/",
"document_filename": "PA 12345 2019-Awan-detained-appellant-transferred-out-of-ada.PDF"
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "internalDetainedTransferOutOfAdaLetter"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ public enum AsylumCaseDefinition {
"makeAnApplications", new TypeReference<List<IdValue<MakeAnApplication>>>(){}),

DECIDE_AN_APPLICATION_ID(
"decideAnApplicationId", new TypeReference<String>(){});
"decideAnApplicationId", new TypeReference<String>(){}),
TRANSFER_OUT_OF_ADA_REASON(
"transferOutOfAdaReason", new TypeReference<String>(){}),
TRANSFER_OUT_OF_ADA_MORE_DETAILS(
"transferOutOfAdaMoreDetails", new TypeReference<String>(){});


private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum DocumentTag {
INTERNAL_DET_MARK_AS_ADA_LETTER("internalDetMarkAsAdaLetter", CaseType.ASYLUM),
INTERNAL_DECIDE_AN_APPLICATION_LETTER("internalDecideAnApplicationLetter", CaseType.ASYLUM),
INTERNAL_APPLY_FOR_FTPA_RESPONDENT("internalApplyForFtpaRespondent", CaseType.ASYLUM),
INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER("internalDetainedTransferOutOfAdaLetter", CaseType.ASYLUM),
BAIL_SUBMISSION("bailSubmission", CaseType.BAIL),
BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL),
BAIL_DECISION_UNSIGNED("bailDecisionUnsigned", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum Event {
MARK_APPEAL_AS_ADA("markAppealAsAda", CaseType.ASYLUM),
APPLY_FOR_FTPA_RESPONDENT("applyForFTPARespondent", CaseType.ASYLUM),
DECIDE_AN_APPLICATION("decideAnApplication", CaseType.ASYLUM),
TRANSFER_OUT_OF_ADA("transferOutOfAda", CaseType.ASYLUM),
SUBMIT_APPLICATION("submitApplication", CaseType.BAIL),
RECORD_THE_DECISION("recordTheDecision", CaseType.BAIL),
END_APPLICATION("endApplication", CaseType.BAIL),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter;

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

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentCreator;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentHandler;

@Component
public class InternalDetainedTransferOutOfAdaDocumentGenerator implements PreSubmitCallbackHandler<AsylumCase> {

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

public InternalDetainedTransferOutOfAdaDocumentGenerator(
@Qualifier("internalDetainedTransferOutOfAdaLetter") DocumentCreator<AsylumCase> internalDetainedTransferOutOfAdaLetterCreator,
DocumentHandler documentHandler
) {
this.internalDetainedTransferOutOfAdaLetterCreator = internalDetainedTransferOutOfAdaLetterCreator;
this.documentHandler = documentHandler;
}

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

AsylumCase asylumCase = callback.getCaseDetails().getCaseData();

return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
&& callback.getEvent() == Event.TRANSFER_OUT_OF_ADA
&& isInternalCase(asylumCase)
&& isAppellantInDetention(asylumCase);
}

public PreSubmitCallbackResponse<AsylumCase> handle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
if (!canHandle(callbackStage, callback)) {
throw new IllegalStateException("Cannot handle callback");
}

final CaseDetails<AsylumCase> caseDetails = callback.getCaseDetails();
final AsylumCase asylumCase = caseDetails.getCaseData();

Document internalDetainedTransferOutOfAdaDocument =
internalDetainedTransferOutOfAdaLetterCreator.create(caseDetails);

documentHandler.addWithMetadata(
asylumCase,
internalDetainedTransferOutOfAdaDocument,
NOTIFICATION_ATTACHMENT_DOCUMENTS,
DocumentTag.INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER
);

return new PreSubmitCallbackResponse<>(asylumCase);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ private int bundlePositionIndex(DocumentWithMetadata document) {
return 49;
case INTERNAL_APPLY_FOR_FTPA_RESPONDENT:
log.warn("INTERNAL_APPLY_FOR_FTPA_RESPONDENT_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 49;
return 50;
case INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER:
log.warn("INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription());
return 51;
default:
throw new IllegalStateException("document has unknown tag: " + document.getTag() + ", description: " + document.getDescription());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.TRANSFER_OUT_OF_ADA_MORE_DETAILS;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.TRANSFER_OUT_OF_ADA_REASON;
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.RequiredFieldMissingException;
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 InternalDetainedTransferOutOfAdaTemplate implements DocumentTemplate<AsylumCase> {

private final String templateName;
private final CustomerServicesProvider customerServicesProvider;

public InternalDetainedTransferOutOfAdaTemplate(
@Value("${internalDetainedTransferOutOfAdaLetter.templateName}") String templateName,
CustomerServicesProvider customerServicesProvider) {
this.templateName = templateName;
this.customerServicesProvider = customerServicesProvider;
}

@Override
public String getName() {
return templateName;
}

@Override
public Map<String, Object> mapFieldValues(
CaseDetails<AsylumCase> caseDetails
) {
final AsylumCase asylumCase = caseDetails.getCaseData();

final Map<String, Object> fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase));
fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase));
fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase));
fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now()));
fieldValues.put("transferOutOfAdaReason", asylumCase.read(TRANSFER_OUT_OF_ADA_REASON, String.class)
.orElseThrow(() -> new RequiredFieldMissingException("Transfer out of ADA reason is not present")));
fieldValues.put("transferOutOfAdaMoreDetails", asylumCase.read(TRANSFER_OUT_OF_ADA_MORE_DETAILS, String.class).orElse(""));
return fieldValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1023,4 +1023,25 @@ public DocumentCreator<AsylumCase> getInternalFtpaSubmittedDocumentCreator(
documentUploader
);
}

@Bean("internalDetainedTransferOutOfAdaLetter")
public DocumentCreator<AsylumCase> getInternalDetainedTransferOutOfAdaLetterCreator(
@Value("${internalDetainedTransferOutOfAdaLetter.contentType}") String contentType,
@Value("${internalDetainedTransferOutOfAdaLetter.fileExtension}") String fileExtension,
@Value("${internalDetainedTransferOutOfAdaLetter.fileName}") String fileName,
AsylumCaseFileNameQualifier fileNameQualifier,
InternalDetainedTransferOutOfAdaTemplate 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 @@ -314,6 +314,11 @@ internalDetainedApplyForFtpaRespondentLetter.fileExtension: PDF
internalDetainedApplyForFtpaRespondentLetter.fileName: "apply-for-ftpa-respondent-letter"
internalDetainedApplyForFtpaRespondentLetter.templateName: ${IA_INTERNAL_DETAINED_APPLY_FOR_FTPA_RESPONDENT_LETTER_TEMPLATE:TB-IAC-LET-ENG-00009.docx}

internalDetainedTransferOutOfAdaLetter.contentType: application/pdf
internalDetainedTransferOutOfAdaLetter.fileExtension: PDF
internalDetainedTransferOutOfAdaLetter.fileName: "detained-appellant-transferred-out-of-ada"
internalDetainedTransferOutOfAdaLetter.templateName: ${IA_INTERNAL_DETAINED_TRANSFERRED_OUT_OF_ADA_LETTER_TEMPLATE:TB-IAC-DEC-ENG-00014.docx}

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

docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY}
Expand Down Expand Up @@ -390,6 +395,7 @@ security:
- "requestHearingRequirementsFeature"
- "markAppealAsAda"
- "decideAnApplication"
- "transferOutOfAda"
caseworker-ia-admofficer:
- "listCase"
- "submitAppeal"
Expand Down Expand Up @@ -437,6 +443,7 @@ security:
- "adaSuitabilityReview"
- "generateHearingBundle"
- "decideAnApplication"
- "transferOutOfAda"
caseworker-ia-homeofficebail:
- "submitApplication"
- "makeNewApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public void has_correct_values() {
assertEquals("internalDetMarkAsAdaLetter", DocumentTag.INTERNAL_DET_MARK_AS_ADA_LETTER.toString());
assertEquals("internalDecideAnApplicationLetter", DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER.toString());
assertEquals("internalApplyForFtpaRespondent", DocumentTag.INTERNAL_APPLY_FOR_FTPA_RESPONDENT.toString());
assertEquals("internalDetainedTransferOutOfAdaLetter", DocumentTag.INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER.toString());
}

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

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

0 comments on commit 3396567

Please sign in to comment.