-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added functionality to generate letter when admin officer applies for ftpa for internal cases * Added/updated tests
- Loading branch information
1 parent
bccfd09
commit c633f01
Showing
14 changed files
with
494 additions
and
4 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...tionalTest/resources/scenarios/RIA-7326-internal-ada-apply-for-ftpa-appellant-letter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"description": "RIA-7326 internal ADA apply for ftpa (appellant) letter generation", | ||
"request": { | ||
"uri": "/asylum/ccdAboutToSubmit", | ||
"credentials": "AdminOfficer", | ||
"input": { | ||
"id": 7326, | ||
"eventId": "applyForFTPAAppellant", | ||
"state": "decided", | ||
"caseData": { | ||
"template": "minimal-internal-appeal-submitted.json", | ||
"replacements": { | ||
"appellantInDetention": "Yes", | ||
"isAcceleratedDetainedAppeal": "Yes" | ||
} | ||
} | ||
} | ||
}, | ||
"expectation": { | ||
"status": 200, | ||
"errors": [], | ||
"caseData": { | ||
"template": "minimal-internal-appeal-submitted.json", | ||
"replacements": { | ||
"appellantInDetention": "Yes", | ||
"notificationAttachmentDocuments": [ | ||
{ | ||
"id": "1", | ||
"value": { | ||
"document": { | ||
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/", | ||
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/", | ||
"document_filename": "PA 12345 2019-Awan-apply-for-ftpa-appellant-letter.PDF" | ||
}, | ||
"description": "", | ||
"dateUploaded": "{$TODAY}", | ||
"tag": "internalFtpaSubmittedLetter" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...lTest/resources/scenarios/RIA-7326-internal-detained-apply-for-ftpa-appellant-letter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"description": "RIA-7326 internal detained (non-ada) apply for ftpa (appellant) letter generation", | ||
"request": { | ||
"uri": "/asylum/ccdAboutToSubmit", | ||
"credentials": "AdminOfficer", | ||
"input": { | ||
"id": 7326, | ||
"eventId": "applyForFTPAAppellant", | ||
"state": "decided", | ||
"caseData": { | ||
"template": "minimal-internal-appeal-submitted.json", | ||
"replacements": { | ||
"appellantInDetention": "Yes" | ||
} | ||
} | ||
} | ||
}, | ||
"expectation": { | ||
"status": 200, | ||
"errors": [], | ||
"caseData": { | ||
"template": "minimal-internal-appeal-submitted.json", | ||
"replacements": { | ||
"appellantInDetention": "Yes", | ||
"notificationAttachmentDocuments": [ | ||
{ | ||
"id": "1", | ||
"value": { | ||
"document": { | ||
"document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/", | ||
"document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/", | ||
"document_filename": "PA 12345 2019-Awan-apply-for-ftpa-appellant-letter.PDF" | ||
}, | ||
"description": "", | ||
"dateUploaded": "{$TODAY}", | ||
"tag": "internalFtpaSubmittedLetter" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ntsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS; | ||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; | ||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.PreSubmitCallbackHandler; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentCreator; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentHandler; | ||
|
||
|
||
@Component | ||
public class InternalApplyForFtpaAppellantLetterGenerator implements PreSubmitCallbackHandler<AsylumCase> { | ||
|
||
private final DocumentCreator<AsylumCase> internalApplyForFtpaAppellantLetter; | ||
private final DocumentHandler documentHandler; | ||
|
||
public InternalApplyForFtpaAppellantLetterGenerator( | ||
@Qualifier("internalApplyForFtpaAppellantLetter") DocumentCreator<AsylumCase> internalApplyForFtpaAppellantLetter, | ||
DocumentHandler documentHandler | ||
) { | ||
this.internalApplyForFtpaAppellantLetter = internalApplyForFtpaAppellantLetter; | ||
this.documentHandler = documentHandler; | ||
} | ||
|
||
public boolean canHandle( | ||
PreSubmitCallbackStage callbackStage, | ||
Callback<AsylumCase> callback | ||
) { | ||
requireNonNull(callbackStage, "callbackStage must not be null"); | ||
requireNonNull(callback, "callback must not be null"); | ||
AsylumCase asylumCase = callback.getCaseDetails().getCaseData(); | ||
|
||
return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT | ||
&& callback.getEvent() == Event.APPLY_FOR_FTPA_APPELLANT | ||
&& isInternalCase(asylumCase) | ||
&& isAppellantInDetention(asylumCase); | ||
} | ||
|
||
public PreSubmitCallbackResponse<AsylumCase> handle( | ||
PreSubmitCallbackStage callbackStage, | ||
Callback<AsylumCase> callback | ||
) { | ||
if (!canHandle(callbackStage, callback)) { | ||
throw new IllegalStateException("Cannot handle callback"); | ||
} | ||
|
||
final CaseDetails<AsylumCase> caseDetails = callback.getCaseDetails(); | ||
final AsylumCase asylumCase = caseDetails.getCaseData(); | ||
|
||
Document documentForUpload = internalApplyForFtpaAppellantLetter.create(caseDetails); | ||
|
||
documentHandler.addWithMetadata( | ||
asylumCase, | ||
documentForUpload, | ||
NOTIFICATION_ATTACHMENT_DOCUMENTS, | ||
DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER | ||
); | ||
|
||
return new PreSubmitCallbackResponse<>(asylumCase); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...casedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; | ||
|
||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.getAppellantPersonalisation; | ||
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.DateProvider; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.DocumentTemplate; | ||
import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; | ||
|
||
|
||
@Component | ||
public class InternalApplyForFtpaAppellantLetterTemplate implements DocumentTemplate<AsylumCase> { | ||
|
||
private final String templateName; | ||
private final DateProvider dateProvider; | ||
private final CustomerServicesProvider customerServicesProvider; | ||
|
||
|
||
public InternalApplyForFtpaAppellantLetterTemplate( | ||
@Value("${internalApplyForFtpaAppellantLetter.templateName}") String templateName, | ||
DateProvider dateProvider, | ||
CustomerServicesProvider customerServicesProvider) { | ||
this.templateName = templateName; | ||
this.dateProvider = dateProvider; | ||
this.customerServicesProvider = customerServicesProvider; | ||
} | ||
|
||
public String getName() { | ||
return templateName; | ||
} | ||
|
||
public Map<String, Object> mapFieldValues( | ||
CaseDetails<AsylumCase> caseDetails | ||
) { | ||
final AsylumCase asylumCase = caseDetails.getCaseData(); | ||
final Map<String, Object> fieldValues = new HashMap<>(); | ||
|
||
fieldValues.putAll(getAppellantPersonalisation(asylumCase)); | ||
fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now())); | ||
fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); | ||
fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); | ||
|
||
return fieldValues; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.