From 007f737d6a53108ae240d90ae011dcb3a0b607b9 Mon Sep 17 00:00:00 2001 From: Marcus Ho <99657446+MarcusHMCTS@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:30:35 +0000 Subject: [PATCH] DTSPB-4260 upload document to remove document type (#1042) * DTSPB-4260 upload document to remove document type * DTSPB-4260 upload document to remove unused import * DTSPB-4260 fix test case issue * DTSPB-4261 Document upload notification (#1045) * DTSPB-4261 Document upload notification * DTSPB-4261 Fix sonar issue * DTSPB-4261 Fix sonar issue --------- Co-authored-by: Feli Tam * DTSPB-4261 Removed response code * DTSPB-4261 Changed the return response type * DTSPB-4261 Changed the Document field and commons version * DTSPB-4261 Mapping fields in PA mapper * DTSPB-4261 Mapping fields in PA mapper * DTSPB-4261 Changed Date format * DTSPB-4261 PR Pointing * Bumping chart version/ fixing aliases * DTSPB-4260 add DocumentType.CITIZEN_HUB_UPLOAD to DocumentMapper * DTSPB-4260 fixed style issue with import * DTSPB-4261 Changed the fields to be inside the object * DTSPB-4261 Change name of the object * DTSPB-4261 Fix IT * add debug log * DTSPB-4260 adding citizenResponseCheckbox for uploadNotification * DTSPB-4261 Changed PR no. * DTSPB-4260 return String for uploadNotification * DTSPB-4260 fix style issue * DTSPB-4261 Fix Sonar issue * DTSPB-4260 change uploadNotification prodices * DTSPB-4260 fix unused import * DTSPB-4260 update uploadNotification to return void * DTSPB-4260 use citizen endpoint * DTSPB-4260 add informationNeeded and informationNeededByPost * DTSPB-4261 Changed commons version and changed response date name * DTSPB-4260 only update ccd when citizenResponseCheckbox is true * DTSPB-4260 add provideinformation.isSaveAndClose and citizenDocumentsUploaded * DTSPB-4261 Fix tests * DTSPB-4260 add isSaveAndClose * DTSPB-4261 Fix Name of citizenDocuments * DTSPB-4261 Added log * DTSPB-4261 Added log * DTSPB-4260 add condition for send email * DTSPB-4260 fix style issue * DTSPB-4260 fix welsh email for Notification * DTSPB-4260 revert chart, update logging and commons version * DTSPB-4261 Removed unnecessary log --------- Co-authored-by: Iswarya Pepakayala Co-authored-by: Feli Tam Co-authored-by: hmcts-jenkins-j-to-z <61242337+hmcts-jenkins-j-to-z[bot]@users.noreply.github.com> --- build.gradle | 4 +- .../controller/DocumentsControllerIT.java | 17 +++ .../controller/InvitationControllerIT.java | 2 + .../service/mapper/IntestacyMapperIT.java | 6 +- .../core/service/mapper/PaMapperIT.java | 6 +- .../PaMultipleExecutorTestDataCreator.java | 18 ++- .../PaSingleExecutorTestDataCreator.java | 17 ++- .../client/business/BusinessServiceApi.java | 12 ++ .../controller/DocumentsController.java | 9 ++ .../core/service/BusinessServiceImpl.java | 62 +++++++++- .../core/service/SubmitServiceImpl.java | 1 - .../core/service/mapper/DocumentsMapper.java | 3 +- .../core/service/mapper/IntestacyMapper.java | 16 ++- .../probate/core/service/mapper/PaMapper.java | 16 ++- .../probate/service/BusinessService.java | 2 + .../core/service/BusinessServiceImplTest.java | 109 ++++++++++++++++++ .../documentNotification.json | 6 + 17 files changed, 291 insertions(+), 15 deletions(-) create mode 100644 src/test/resources/businessDocuments/documentNotification.json diff --git a/build.gradle b/build.gradle index cbc5e80b1..29a72a95d 100644 --- a/build.gradle +++ b/build.gradle @@ -171,7 +171,7 @@ def versions = [ mapStruct : '1.3.0.Final', pact_version : '4.1.34', piTest : '1.17.1', - probateCommonsVersion : '2.0.27', + probateCommonsVersion : '2.0.31', restAssured : '5.5.0', serenity : '4.2.9', serviceAuthProviderClient : '5.2.0', @@ -229,7 +229,7 @@ dependencies { implementation group: 'io.github.openfeign', name: 'feign-jackson', version: versions.feign implementation group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '5.3.1' implementation group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '3.1.8' - + implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: versions.hmctsJavaLogging implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: versions.hmctsJavaLogging implementation group: 'com.github.hmcts', name: 'auth-checker-lib', version: versions.authCheckerLib diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/controller/DocumentsControllerIT.java b/src/integrationTest/java/uk/gov/hmcts/probate/controller/DocumentsControllerIT.java index 36dca9ea3..be318a7b6 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/controller/DocumentsControllerIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/controller/DocumentsControllerIT.java @@ -45,6 +45,9 @@ public class DocumentsControllerIT { DocumentsController.DOCUMENTS_BASEURL + DocumentsController.BULK_SCAN_COVERSHEET_ENDPOINT; private static final String DOCUMENT_UPLOAD_ENDPOINT = DocumentsController.DOCUMENTS_BASEURL + DocumentsController.DOCUMENT_UPLOAD_ENDPOINT; + + private static final String DOCUMENT_UPLOAD_NOTIFICATION_ENDPOINT = + DocumentsController.DOCUMENTS_BASEURL + DocumentsController.DOCUMENT_UPLOAD_NOTIFICATION_ENDPOINT; private static final String DOCUMENT_DELETE_ENDPOINT = DocumentsController.DOCUMENTS_BASEURL + DocumentsController.DOCUMENT_DELETE_ENDPOINT; @@ -59,6 +62,7 @@ public class DocumentsControllerIT { @Autowired private WebApplicationContext webApplicationContext; + private String documentNotificationStr; @BeforeEach public void setup() { @@ -160,4 +164,17 @@ public void shouldUpload() throws Exception { ArgumentMatchers.eq(Lists.newArrayList(file))); } + @Test + public void shouldReturn200ForDocumentUpload() throws Exception { + + documentNotificationStr = TestUtils.getJsonFromFile("businessDocuments/documentNotification.json"); + + mockMvc.perform(post(DOCUMENT_UPLOAD_NOTIFICATION_ENDPOINT + "/12345/true") + .header("Session-Id", "someSessionId") + .content(documentNotificationStr) + .contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))) + .andExpect(status().isOk()); + verify(businessService, times(1)).documentUploadNotification(eq("12345"), eq("true")); + } + } diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/controller/InvitationControllerIT.java b/src/integrationTest/java/uk/gov/hmcts/probate/controller/InvitationControllerIT.java index 0b1519277..9b6daa8f2 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/controller/InvitationControllerIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/controller/InvitationControllerIT.java @@ -45,6 +45,7 @@ public class InvitationControllerIT { private ObjectMapper objectMapper; private String invitationStr; + private String documentNotificationStr; private Invitation invitation; private Invitation invitation2; private List invitationsResult; @@ -61,6 +62,7 @@ public void setUp() throws Exception { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); invitationStr = TestUtils.getJsonFromFile("invite/invitation.json"); + documentNotificationStr = TestUtils.getJsonFromFile("businessDocuments/documentNotification.json"); this.invitation = objectMapper.readValue(invitationStr, Invitation.class); this.invitation2 = objectMapper.readValue(invitationStr, Invitation.class); invitationArrayStr = new StringBuilder("[").append(invitationStr).append("]").toString(); diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapperIT.java b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapperIT.java index a283a774f..3291e81b0 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapperIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapperIT.java @@ -20,7 +20,9 @@ import uk.gov.hmcts.reform.probate.model.forms.Equality; import uk.gov.hmcts.reform.probate.model.forms.InheritanceTax; import uk.gov.hmcts.reform.probate.model.forms.Language; +import uk.gov.hmcts.reform.probate.model.forms.ProvideInformation; import uk.gov.hmcts.reform.probate.model.forms.Registry; +import uk.gov.hmcts.reform.probate.model.forms.ReviewResponse; import uk.gov.hmcts.reform.probate.model.forms.intestacy.IntestacyApplicant; import uk.gov.hmcts.reform.probate.model.forms.intestacy.IntestacyDeceased; import uk.gov.hmcts.reform.probate.model.forms.intestacy.IntestacyForm; @@ -75,7 +77,7 @@ public void shouldMapNullGrantOfRepresentationToGrantOfIntestacyForm() { @Test public void shouldMapEmptyIntestacyFormToGrantOfRepresentation() { GrantOfRepresentationData expectedGrantOfRepresentation = new GrantOfRepresentationData(); - expectedGrantOfRepresentation.setBoDocumentsUploaded(new ArrayList<>()); + expectedGrantOfRepresentation.setCitizenDocumentsUploaded(new ArrayList<>()); expectedGrantOfRepresentation.setApplicationSubmittedDate(LocalDate.now()); expectedGrantOfRepresentation.setApplicationType(ApplicationType.PERSONAL); expectedGrantOfRepresentation.setGrantType(GrantType.INTESTACY); @@ -108,6 +110,8 @@ public void shouldMapEmptyGrantOfRepresentationToGrantOfIntestacyForm() { expectedIntestacyForm.setDeclaration(new Declaration()); expectedIntestacyForm.setLanguage(new Language()); expectedIntestacyForm.setEquality(new Equality()); + expectedIntestacyForm.setProvideinformation(new ProvideInformation()); + expectedIntestacyForm.setReviewresponse(new ReviewResponse()); IntestacyForm actualIntestacyForm = mapper.fromCaseData(new GrantOfRepresentationData()); assertThat(actualIntestacyForm).isEqualToComparingFieldByFieldRecursively(expectedIntestacyForm); } diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMapperIT.java b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMapperIT.java index 247ef4058..e661380aa 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMapperIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMapperIT.java @@ -21,7 +21,9 @@ import uk.gov.hmcts.reform.probate.model.forms.InheritanceTax; import uk.gov.hmcts.reform.probate.model.forms.Language; import uk.gov.hmcts.reform.probate.model.forms.LegalStatement; +import uk.gov.hmcts.reform.probate.model.forms.ProvideInformation; import uk.gov.hmcts.reform.probate.model.forms.Registry; +import uk.gov.hmcts.reform.probate.model.forms.ReviewResponse; import uk.gov.hmcts.reform.probate.model.forms.Will; import uk.gov.hmcts.reform.probate.model.forms.pa.Executors; import uk.gov.hmcts.reform.probate.model.forms.pa.PaApplicant; @@ -111,7 +113,7 @@ public void shouldMapEmptyPaFormToGrantOfRepresentation() { expectedGrantOfRepresentation.setGrantType(GrantType.GRANT_OF_PROBATE); expectedGrantOfRepresentation.setApplicationSubmittedDate(LocalDate.now()); expectedGrantOfRepresentation.setNumberOfApplicants(0L); - expectedGrantOfRepresentation.setBoDocumentsUploaded(Lists.newArrayList()); + expectedGrantOfRepresentation.setCitizenDocumentsUploaded(Lists.newArrayList()); expectedGrantOfRepresentation.setPrimaryApplicantIsApplying(true); GrantOfRepresentationData actualGrantOfRepresentation = mapper.toCaseData(new PaForm()); assertThat(actualGrantOfRepresentation) @@ -140,6 +142,8 @@ public void shouldMapEmptyGrantOfRepresentationToGrantOfPaForm() { declaration.setLegalStatement(LegalStatement.builder().build()); expectedPaForm.setDeclaration(declaration); expectedPaForm.setEquality(new Equality()); + expectedPaForm.setProvideinformation(new ProvideInformation()); + expectedPaForm.setReviewresponse(new ReviewResponse()); PaForm actualPaForm = mapper.fromCaseData(new GrantOfRepresentationData()); assertThat(actualPaForm).isEqualToComparingFieldByFieldRecursively(expectedPaForm); } diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMultipleExecutorTestDataCreator.java b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMultipleExecutorTestDataCreator.java index 3d1ed4661..e49435e4f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMultipleExecutorTestDataCreator.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaMultipleExecutorTestDataCreator.java @@ -37,7 +37,9 @@ import uk.gov.hmcts.reform.probate.model.forms.Language; import uk.gov.hmcts.reform.probate.model.forms.LegalStatementHolder; import uk.gov.hmcts.reform.probate.model.forms.Payment; +import uk.gov.hmcts.reform.probate.model.forms.ProvideInformation; import uk.gov.hmcts.reform.probate.model.forms.Registry; +import uk.gov.hmcts.reform.probate.model.forms.ReviewResponse; import uk.gov.hmcts.reform.probate.model.forms.Will; import uk.gov.hmcts.reform.probate.model.forms.pa.Executor; import uk.gov.hmcts.reform.probate.model.forms.pa.Executors; @@ -56,6 +58,9 @@ import java.util.List; import java.util.Map; +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; + public final class PaMultipleExecutorTestDataCreator { public static final String REGISTRY_ADDRESS = "old trafford"; @@ -202,6 +207,8 @@ public final class PaMultipleExecutorTestDataCreator { private static String APPLICANT_ADDRESSES = "[{\"formatted_address\":\"102 Petty France London SW1H 9EX\"}]"; + private static final String CITIZEN_RESPONSE = "response"; + private PaMultipleExecutorTestDataCreator() { } @@ -400,6 +407,10 @@ public static PaForm createPaForm() throws IOException { .url(SOT_DOCUMENT_URL) .build() ) + .provideinformation(ProvideInformation.builder() + .citizenResponse(CITIZEN_RESPONSE) + .documentUploadIssue(FALSE).build()) + .reviewresponse(ReviewResponse.builder().citizenResponseCheckbox(TRUE).build()) .legalDeclaration(objectMapper.readValue(LEGAL_DECLARATION_JSON, new TypeReference>() { })) .checkAnswersSummary(objectMapper.readValue(CHECK_ANSWERS_JSON, new TypeReference>() { @@ -557,7 +568,7 @@ public static GrantOfRepresentationData createGrantOfRepresentation() { .total(FEES_TOTAL.multiply(BigDecimal.valueOf(100)).longValue()) .build() ) - .boDocumentsUploaded(Lists.newArrayList( + .citizenDocumentsUploaded(Lists.newArrayList( CollectionMember.builder() .value(UploadDocument.builder() .documentLink(DocumentLink.builder() @@ -566,7 +577,7 @@ public static GrantOfRepresentationData createGrantOfRepresentation() { .documentBinaryUrl(DOCUMENT_URL + "/binary") .build()) .comment(DOCUMENT_FILENAME) - .documentType(DocumentType.DEATH_CERT) + .documentType(DocumentType.CITIZEN_HUB_UPLOAD) .build()) .build() @@ -576,6 +587,9 @@ public static GrantOfRepresentationData createGrantOfRepresentation() { .documentUrl(SOT_DOCUMENT_URL) .documentFilename(SOT_DOCUMENT_FILENAME) .build()) + .citizenResponse(CITIZEN_RESPONSE) + .documentUploadIssue(FALSE) + .citizenResponseCheckbox(TRUE) .legalDeclarationJson(LEGAL_DECLARATION_JSON) .checkAnswersSummaryJson(CHECK_ANSWERS_JSON) .deceasedAddresses(DECEASED_ADDRESSES) diff --git a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaSingleExecutorTestDataCreator.java b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaSingleExecutorTestDataCreator.java index a8dddd4db..df08eec7f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaSingleExecutorTestDataCreator.java +++ b/src/integrationTest/java/uk/gov/hmcts/probate/core/service/mapper/PaSingleExecutorTestDataCreator.java @@ -37,7 +37,9 @@ import uk.gov.hmcts.reform.probate.model.forms.LegalStatementExecutorApplying; import uk.gov.hmcts.reform.probate.model.forms.LegalStatementHolder; import uk.gov.hmcts.reform.probate.model.forms.Payment; +import uk.gov.hmcts.reform.probate.model.forms.ProvideInformation; import uk.gov.hmcts.reform.probate.model.forms.Registry; +import uk.gov.hmcts.reform.probate.model.forms.ReviewResponse; import uk.gov.hmcts.reform.probate.model.forms.Will; import uk.gov.hmcts.reform.probate.model.forms.pa.Executor; import uk.gov.hmcts.reform.probate.model.forms.pa.Executors; @@ -58,6 +60,7 @@ import java.util.Map; import static java.lang.Boolean.TRUE; +import static java.lang.Boolean.FALSE; public final class PaSingleExecutorTestDataCreator { @@ -221,6 +224,8 @@ public final class PaSingleExecutorTestDataCreator { private static String APPLICANT_ADDRESSES = "[{\"formatted_address\":\"102 Petty France London SW1H 9EX\"}]"; + private static String CITIZEN_RESPONSE = "response"; + private PaSingleExecutorTestDataCreator() { } @@ -435,6 +440,10 @@ public static PaForm createPaForm() throws IOException { .url(SOT_DOCUMENT_URL) .build() ) + .provideinformation(ProvideInformation.builder() + .citizenResponse(CITIZEN_RESPONSE) + .documentUploadIssue(FALSE).build()) + .reviewresponse(ReviewResponse.builder().citizenResponseCheckbox(TRUE).build()) .legalDeclaration(objectMapper.readValue(LEGAL_DECLARATION_JSON, new TypeReference>() { })) .checkAnswersSummary(objectMapper.readValue(CHECK_ANSWERS_JSON, new TypeReference>() { @@ -581,16 +590,17 @@ public static GrantOfRepresentationData createGrantOfRepresentation() { .total(FEES_TOTAL.multiply(BigDecimal.valueOf(100)).longValue()) .build() ) - .boDocumentsUploaded(Lists.newArrayList( + .citizenDocumentsUploaded(Lists.newArrayList( CollectionMember.builder() .value(UploadDocument.builder() .documentLink(DocumentLink.builder() .documentUrl(DOCUMENT_URL) .documentFilename(DOCUMENT_FILENAME) + .documentBinaryUrl(DOCUMENT_URL + "/binary") .build()) .comment(DOCUMENT_FILENAME) - .documentType(DocumentType.DEATH_CERT) + .documentType(DocumentType.CITIZEN_HUB_UPLOAD) .build()) .build() @@ -632,6 +642,9 @@ public static GrantOfRepresentationData createGrantOfRepresentation() { .codicilsDamageDateKnown(CODICILS_DAMAGE_DATE_KNOWN) .codicilsDamageDate(CODICILS_DAMAGE_DATE) .deceasedWrittenWishes(DECEASED_WRITTEN_WISHES) + .citizenResponse(CITIZEN_RESPONSE) + .documentUploadIssue(FALSE) + .citizenResponseCheckbox(TRUE) .build(); } } diff --git a/src/main/java/uk/gov/hmcts/probate/client/business/BusinessServiceApi.java b/src/main/java/uk/gov/hmcts/probate/client/business/BusinessServiceApi.java index b4c763c83..c08d796c6 100644 --- a/src/main/java/uk/gov/hmcts/probate/client/business/BusinessServiceApi.java +++ b/src/main/java/uk/gov/hmcts/probate/client/business/BusinessServiceApi.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam; import uk.gov.hmcts.reform.probate.model.documents.BulkScanCoverSheet; import uk.gov.hmcts.reform.probate.model.documents.CheckAnswersSummary; +import uk.gov.hmcts.reform.probate.model.documents.DocumentNotification; import uk.gov.hmcts.reform.probate.model.documents.LegalDeclaration; import uk.gov.hmcts.reform.probate.model.multiapplicant.ExecutorNotification; import uk.gov.hmcts.reform.probate.model.multiapplicant.Invitation; @@ -114,6 +115,17 @@ String inviteBilingual(@PathVariable("inviteId") String inviteId, @PostMapping(path = "/executor-notification/all-bilingual", consumes = MediaType.APPLICATION_JSON_VALUE) String signedExecAllBilingual(@RequestBody ExecutorNotification executorNotification); + @PostMapping(path = "/document-upload-notification/bilingual", consumes = MediaType.APPLICATION_JSON_VALUE) + String documentUploadBilingual(@RequestBody DocumentNotification executorNotification); + + @PostMapping(path = "/document-upload-notification", consumes = MediaType.APPLICATION_JSON_VALUE) + String documentUpload(@RequestBody DocumentNotification executorNotification); + + @PostMapping(path = "/document-upload-issue-notification/bilingual", consumes = MediaType.APPLICATION_JSON_VALUE) + String documentUploadIssueBilingual(@RequestBody DocumentNotification executorNotification); + + @PostMapping(path = "/document-upload-issue-notification", consumes = MediaType.APPLICATION_JSON_VALUE) + String documentUploadIssue(@RequestBody DocumentNotification executorNotification); @GetMapping(path = "/pin/bilingual") String pinNumberBilingual(@RequestParam("phoneNumber") String phoneNumber, diff --git a/src/main/java/uk/gov/hmcts/probate/controller/DocumentsController.java b/src/main/java/uk/gov/hmcts/probate/controller/DocumentsController.java index f7fb7cf43..beb4e7f1b 100644 --- a/src/main/java/uk/gov/hmcts/probate/controller/DocumentsController.java +++ b/src/main/java/uk/gov/hmcts/probate/controller/DocumentsController.java @@ -9,6 +9,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -37,6 +38,7 @@ public class DocumentsController { protected static final String LEGAL_DECLARATION_ENDPOINT = "/generate/legalDeclaration"; protected static final String BULK_SCAN_COVERSHEET_ENDPOINT = "/generate/bulkScanCoversheet"; protected static final String DOCUMENT_UPLOAD_ENDPOINT = "/upload"; + protected static final String DOCUMENT_UPLOAD_NOTIFICATION_ENDPOINT = "/notification"; protected static final String DOCUMENT_DELETE_ENDPOINT = "/delete/{documentId}"; private final BusinessService businessService; @@ -93,4 +95,11 @@ public ResponseEntity> upload(@RequestHeader(value = "Authorization return new ResponseEntity<>(backOfficeService.uploadDocument(authorizationToken, files), HttpStatus.OK); } + @PostMapping(path = DOCUMENT_UPLOAD_NOTIFICATION_ENDPOINT + "/{formdataId}/{citizenResponseCheckbox}") + public void uploadNotification(@PathVariable("formdataId") String formdataId, + @PathVariable("citizenResponseCheckbox") String citizenResponseCheckbox) { + log.info("Sending notification for document upload to Business service for case : {}", formdataId); + businessService.documentUploadNotification(formdataId,citizenResponseCheckbox); + } + } diff --git a/src/main/java/uk/gov/hmcts/probate/core/service/BusinessServiceImpl.java b/src/main/java/uk/gov/hmcts/probate/core/service/BusinessServiceImpl.java index 3bc704f85..44174a6d6 100644 --- a/src/main/java/uk/gov/hmcts/probate/core/service/BusinessServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/probate/core/service/BusinessServiceImpl.java @@ -11,14 +11,18 @@ import uk.gov.hmcts.reform.probate.model.cases.CaseType; import uk.gov.hmcts.reform.probate.model.cases.CollectionMember; import uk.gov.hmcts.reform.probate.model.cases.ProbateCaseDetails; +import uk.gov.hmcts.reform.probate.model.cases.UploadDocument; import uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.ExecutorApplying; import uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantOfRepresentationData; import uk.gov.hmcts.reform.probate.model.documents.BulkScanCoverSheet; import uk.gov.hmcts.reform.probate.model.documents.CheckAnswersSummary; +import uk.gov.hmcts.reform.probate.model.documents.DocumentNotification; import uk.gov.hmcts.reform.probate.model.documents.LegalDeclaration; import uk.gov.hmcts.reform.probate.model.multiapplicant.ExecutorNotification; import uk.gov.hmcts.reform.probate.model.multiapplicant.Invitation; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -32,6 +36,8 @@ public class BusinessServiceImpl implements BusinessService { private final SubmitServiceApi submitServiceApi; private final SecurityUtils securityUtils; private final ExecutorApplyingToInvitationMapper executorApplyingToInvitationMapper; + private static final String RESPONSE_DATE_FORMAT = "yyyy-MM-dd"; + private static final String FALSE = "false"; @Override @@ -186,6 +192,61 @@ public String inviteAgreed(String formdataId, Invitation invitation) { return invitation.getInviteId(); } + @Override + public void documentUploadNotification(String formDataId, String citizenResponseCheckbox) { + log.info("Setting response submitted date and sending document upload notification"); + ProbateCaseDetails probateCaseDetails = getProbateCaseDetails(formDataId); + GrantOfRepresentationData grantOfRepresentationData = + (GrantOfRepresentationData) probateCaseDetails.getCaseData(); + log.info("Got the case details now response submitted date: {}", formDataId); + grantOfRepresentationData.setExpectedResponseDate(getResponseSubmittedDate()); + grantOfRepresentationData.setCitizenResponseCheckbox(Boolean.parseBoolean(citizenResponseCheckbox)); + probateCaseDetails.setCaseData(grantOfRepresentationData); + if (Boolean.TRUE.equals(Boolean.parseBoolean(citizenResponseCheckbox))) { + updateCaseData(probateCaseDetails, formDataId); + } + DocumentNotification documentNotification = DocumentNotification.builder() + .applicantName(grantOfRepresentationData.getPrimaryApplicantForenames() + + " " + grantOfRepresentationData.getPrimaryApplicantSurname()) + .ccdReference(formDataId) + .deceasedDod(grantOfRepresentationData.getDeceasedDateOfDeath().toString()) + .deceasedName(grantOfRepresentationData.getDeceasedForenames() + + " " + grantOfRepresentationData.getDeceasedSurname()) + .email(grantOfRepresentationData.getPrimaryApplicantEmailAddress()) + .citizenResponse(grantOfRepresentationData.getCitizenResponse()) + .fileName(getDocumentNames(grantOfRepresentationData.getCitizenDocumentsUploaded())) + .expectedResponseDate(grantOfRepresentationData.getExpectedResponseDate()) + .build(); + if (Boolean.FALSE.equals(grantOfRepresentationData.getDocumentUploadIssue()) + && Boolean.TRUE.equals(grantOfRepresentationData.getLanguagePreferenceWelsh())) { + businessServiceApi.documentUploadBilingual(documentNotification); + } else if (Boolean.FALSE.equals(grantOfRepresentationData.getDocumentUploadIssue())) { + businessServiceApi.documentUpload(documentNotification); + } else if (Boolean.TRUE.equals(grantOfRepresentationData.getLanguagePreferenceWelsh()) + && (Boolean.TRUE.equals(grantOfRepresentationData.getDocumentUploadIssue()) + || FALSE.equals(citizenResponseCheckbox))) { + businessServiceApi.documentUploadIssueBilingual(documentNotification); + } else if (Boolean.TRUE.equals(grantOfRepresentationData.getDocumentUploadIssue()) + || FALSE.equals(citizenResponseCheckbox)) { + businessServiceApi.documentUploadIssue(documentNotification); + } + + } + + private List getDocumentNames(List> citizenDocuments) { + if (citizenDocuments == null) { + return new ArrayList<>(); + } else { + return citizenDocuments.stream().map(citizenDocument -> citizenDocument.getValue().getDocumentLink() + .getDocumentFilename()).toList(); + } + } + + private String getResponseSubmittedDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(RESPONSE_DATE_FORMAT); + return LocalDate.now().plusWeeks(7).format(formatter); + } + @Override public void resetAgreedFlags(String formdataId) { log.info("Reset agreed flags"); @@ -288,5 +349,4 @@ private void updateCaseDataAsCaseWorker(ProbateCaseDetails probateCaseDetails, S submitServiceApi.updateCaseAsCaseWorker(authorisation, serviceAuthorisation, formdataId, probateCaseDetails); } - } diff --git a/src/main/java/uk/gov/hmcts/probate/core/service/SubmitServiceImpl.java b/src/main/java/uk/gov/hmcts/probate/core/service/SubmitServiceImpl.java index 71e60cad9..788c5a577 100644 --- a/src/main/java/uk/gov/hmcts/probate/core/service/SubmitServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/probate/core/service/SubmitServiceImpl.java @@ -245,7 +245,6 @@ public Form updatePayments(String identifier, Form form) { log.info("Update case for submission"); updateCaseForSubmission(existingCase); - //TODO: PRO-5580 - Uncomment once applicationSubmittedDate has been re-added to the spreadsheet log.debug("calling create case in submitServiceApi"); ProbateCaseDetails probateCaseDetails = submitServiceApi.createCase( diff --git a/src/main/java/uk/gov/hmcts/probate/core/service/mapper/DocumentsMapper.java b/src/main/java/uk/gov/hmcts/probate/core/service/mapper/DocumentsMapper.java index 486e9f6b4..4655ee17e 100644 --- a/src/main/java/uk/gov/hmcts/probate/core/service/mapper/DocumentsMapper.java +++ b/src/main/java/uk/gov/hmcts/probate/core/service/mapper/DocumentsMapper.java @@ -42,6 +42,7 @@ public Documents fromUploadDocs(List> collectio List documentUploads = collectionMembers .stream() .map(CollectionMember::getValue) + .filter(uploadDocument -> uploadDocument.getDocumentType().equals(DocumentType.CITIZEN_HUB_UPLOAD)) .map(this::mapDocumentUpload) .collect(Collectors.toList()); @@ -50,7 +51,7 @@ public Documents fromUploadDocs(List> collectio private UploadDocument mapUploadDocument(DocumentUpload documentUpload) { return UploadDocument.builder() - .documentType(DocumentType.DEATH_CERT) + .documentType(DocumentType.CITIZEN_HUB_UPLOAD) .documentLink(DocumentLink.builder() .documentUrl(documentUpload.getUrl().trim()) .documentBinaryUrl(documentUpload.getUrl().trim() + "/" + BINARY_URL_SUFFIX) diff --git a/src/main/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapper.java b/src/main/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapper.java index c2e6a62ef..b3340cc19 100644 --- a/src/main/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapper.java +++ b/src/main/java/uk/gov/hmcts/probate/core/service/mapper/IntestacyMapper.java @@ -131,13 +131,18 @@ public interface IntestacyMapper extends FormMapper @Mapping(target = "legalDeclarationJson", source = "legalDeclaration", qualifiedBy = {FromMap.class}) @Mapping(target = "checkAnswersSummaryJson", source = "checkAnswersSummary", qualifiedBy = {FromMap.class}) @Mapping(target = "payments", source = "payment") - @Mapping(target = "boDocumentsUploaded", source = "documents", qualifiedBy = {ToUploadDocs.class}) + @Mapping(target = "citizenDocumentsUploaded", source = "documents", qualifiedBy = {ToUploadDocs.class}) @Mapping(target = "statementOfTruthDocument", source = "statementOfTruthDocument", qualifiedBy = { ToDocumentLink.class}) @Mapping(target = "languagePreferenceWelsh", source = "language.bilingual") @@ -164,6 +164,11 @@ public interface PaMapper extends FormMapper + "DeathCertificate.fromString(form.getDeceased().getDeathCertificate()) : null)") @Mapping(target = "deceasedForeignDeathCertInEnglish", source = "deceased.englishForeignDeathCert") @Mapping(target = "deceasedForeignDeathCertTranslation", source = "deceased.foreignDeathCertTranslation") + @Mapping(target = "citizenResponse", source = "provideinformation.citizenResponse") + @Mapping(target = "documentUploadIssue", source = "provideinformation.documentUploadIssue") + @Mapping(target = "isSaveAndClose", source = "provideinformation.isSaveAndClose") + @Mapping(target = "citizenResponseCheckbox", source = "reviewresponse.citizenResponseCheckbox") + @Mapping(target = "expectedResponseDate", source = "expectedResponseDate") GrantOfRepresentationData toCaseData(PaForm form); @Mapping(target = "type", expression = "java(ProbateType.PA)") @@ -235,12 +240,19 @@ public interface PaMapper extends FormMapper @Mapping(target = "checkAnswersSummary", source = "checkAnswersSummaryJson", qualifiedBy = {ToMap.class}) @Mapping(target = "payment", source = "payments") @Mapping(target = "payments", source = "payments", qualifiedBy = {FromCollectionMember.class}) - @Mapping(target = "documents", source = "boDocumentsUploaded", qualifiedBy = {FromUploadDocs.class}) + @Mapping(target = "documents", source = "citizenDocumentsUploaded", qualifiedBy = {FromUploadDocs.class}) @Mapping(target = "iht.uniqueProbateCodeId", source = "uniqueProbateCodeId") @Mapping(target = "iht.hmrcLetterId", source = "hmrcLetterId") @Mapping(target = "statementOfTruthDocument", source = "statementOfTruthDocument", qualifiedBy = { FromDocumentLink.class}) @Mapping(target = "documentsReceivedNotificationSent", source = "documentsReceivedNotificationSent") + @Mapping(target = "provideinformation.citizenResponse", source = "citizenResponse") + @Mapping(target = "provideinformation.documentUploadIssue", source = "documentUploadIssue") + @Mapping(target = "provideinformation.isSaveAndClose", source = "isSaveAndClose") + @Mapping(target = "reviewresponse.citizenResponseCheckbox", source = "citizenResponseCheckbox") + @Mapping(target = "expectedResponseDate", source = "expectedResponseDate") + @Mapping(target = "informationNeeded", source = "informationNeeded") + @Mapping(target = "informationNeededByPost", source = "informationNeededByPost") @InheritInverseConfiguration PaForm fromCaseData(GrantOfRepresentationData grantOfRepresentation); } diff --git a/src/main/java/uk/gov/hmcts/probate/service/BusinessService.java b/src/main/java/uk/gov/hmcts/probate/service/BusinessService.java index d2c3bd36e..d679b8b59 100644 --- a/src/main/java/uk/gov/hmcts/probate/service/BusinessService.java +++ b/src/main/java/uk/gov/hmcts/probate/service/BusinessService.java @@ -36,5 +36,7 @@ public interface BusinessService { String getPinNumber(String phoneNumber, String sessionId, Boolean isBilingual); List sendInvitations(List invitations, String sessionId, Boolean isBilingual); + + void documentUploadNotification(String formDataId, String citizenResponseCheckbox); } diff --git a/src/test/java/uk/gov/hmcts/probate/core/service/BusinessServiceImplTest.java b/src/test/java/uk/gov/hmcts/probate/core/service/BusinessServiceImplTest.java index 45971ac92..5687109c9 100644 --- a/src/test/java/uk/gov/hmcts/probate/core/service/BusinessServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/probate/core/service/BusinessServiceImplTest.java @@ -16,16 +16,21 @@ import uk.gov.hmcts.reform.probate.model.cases.CaseInfo; import uk.gov.hmcts.reform.probate.model.cases.CaseType; import uk.gov.hmcts.reform.probate.model.cases.CollectionMember; +import uk.gov.hmcts.reform.probate.model.cases.DocumentLink; import uk.gov.hmcts.reform.probate.model.cases.ProbateCaseDetails; +import uk.gov.hmcts.reform.probate.model.cases.UploadDocument; import uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.ExecutorApplying; import uk.gov.hmcts.reform.probate.model.cases.grantofrepresentation.GrantOfRepresentationData; import uk.gov.hmcts.reform.probate.model.documents.BulkScanCoverSheet; import uk.gov.hmcts.reform.probate.model.documents.CheckAnswersSummary; +import uk.gov.hmcts.reform.probate.model.documents.DocumentNotification; import uk.gov.hmcts.reform.probate.model.documents.LegalDeclaration; import uk.gov.hmcts.reform.probate.model.multiapplicant.ExecutorNotification; import uk.gov.hmcts.reform.probate.model.multiapplicant.Invitation; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -70,11 +75,14 @@ public class BusinessServiceImplTest { private byte[] pdfExample; private ObjectMapper objectMapper; + private static final String RESPONSE_DATE_FORMAT = "yyyy-MM-dd"; + @BeforeEach public void setUp() throws Exception { objectMapper = new ObjectMapper(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(RESPONSE_DATE_FORMAT); when(securityUtils.getAuthorisation()).thenReturn(AUTHORIZATION); when(securityUtils.getServiceAuthorisation()).thenReturn(SERVICE_AUTHORIZATION); @@ -89,6 +97,13 @@ public void setUp() throws Exception { when(mockGrantOfRepresentationData.getPrimaryApplicantSurname()).thenReturn("Testerson"); when(mockGrantOfRepresentationData.getDeceasedForenames()).thenReturn("Test"); when(mockGrantOfRepresentationData.getDeceasedSurname()).thenReturn("Testerson"); + when(mockGrantOfRepresentationData.getCitizenResponse()).thenReturn("response"); + when(mockGrantOfRepresentationData.getExpectedResponseDate()).thenReturn(LocalDate.now() + .plusWeeks(7).format(formatter)); + List> documents = new ArrayList(); + documents.add(CollectionMember.builder().value(UploadDocument.builder() + .documentLink(DocumentLink.builder().documentFilename("fileName.pdf").build()).build()).build()); + when(mockGrantOfRepresentationData.getCitizenDocumentsUploaded()).thenReturn(documents); when(mockGrantOfRepresentationData.getExecutorApplyingByInviteId(anyString())) .thenReturn(ExecutorApplying.builder().applyingExecutorName("Test Executor").build()); when(mockGrantOfRepresentationData.getPrimaryApplicantEmailAddress()).thenReturn(emailaddress); @@ -390,6 +405,100 @@ void shouldSendIfAllExecAgreedBilingual() { .updateCaseAsCaseWorker(AUTHORIZATION, SERVICE_AUTHORIZATION, formdataId, mockProbateCaseDetails); } + @Test + void shouldSendEmailForDocumentUploadSuccessful() { + when(mockGrantOfRepresentationData.getDocumentUploadIssue()).thenReturn(Boolean.FALSE); + when(mockGrantOfRepresentationData.getLanguagePreferenceWelsh()).thenReturn(Boolean.FALSE); + DocumentNotification documentNotification = DocumentNotification.builder() + .ccdReference(formdataId) + .applicantName(mockGrantOfRepresentationData.getPrimaryApplicantForenames() + + " " + mockGrantOfRepresentationData.getPrimaryApplicantSurname()) + .deceasedName(mockGrantOfRepresentationData.getDeceasedForenames() + + " " + mockGrantOfRepresentationData.getDeceasedSurname()) + .deceasedDod(mockGrantOfRepresentationData.getDeceasedDateOfDeath().toString()) + .email(mockGrantOfRepresentationData.getPrimaryApplicantEmailAddress()) + .fileName(List.of("fileName.pdf")) + .citizenResponse(mockGrantOfRepresentationData.getCitizenResponse()) + .expectedResponseDate(mockGrantOfRepresentationData.getExpectedResponseDate()) + .build(); + businessService.documentUploadNotification(formdataId, "true"); + verifyGetCaseCalls(); + verify(businessServiceApi).documentUpload(documentNotification); + verify(submitServiceApi) + .saveCase(AUTHORIZATION, SERVICE_AUTHORIZATION, formdataId, EVENT_DESCRIPTION, mockProbateCaseDetails); + } + + @Test + void shouldSendEmailForWelshDocumentUploadSuccessful() { + when(mockGrantOfRepresentationData.getDocumentUploadIssue()).thenReturn(Boolean.FALSE); + when(mockGrantOfRepresentationData.getLanguagePreferenceWelsh()).thenReturn(Boolean.TRUE); + DocumentNotification documentNotification = DocumentNotification.builder() + .ccdReference(formdataId) + .applicantName(mockGrantOfRepresentationData.getPrimaryApplicantForenames() + + " " + mockGrantOfRepresentationData.getPrimaryApplicantSurname()) + .deceasedName(mockGrantOfRepresentationData.getDeceasedForenames() + + " " + mockGrantOfRepresentationData.getDeceasedSurname()) + .deceasedDod(mockGrantOfRepresentationData.getDeceasedDateOfDeath().toString()) + .email(mockGrantOfRepresentationData.getPrimaryApplicantEmailAddress()) + .fileName(List.of("fileName.pdf")) + .citizenResponse(mockGrantOfRepresentationData.getCitizenResponse()) + .expectedResponseDate(mockGrantOfRepresentationData.getExpectedResponseDate() + .toString()) + .build(); + businessService.documentUploadNotification(formdataId, "true"); + verifyGetCaseCalls(); + verify(businessServiceApi).documentUploadBilingual(documentNotification); + verify(submitServiceApi) + .saveCase(AUTHORIZATION, SERVICE_AUTHORIZATION, formdataId, EVENT_DESCRIPTION, mockProbateCaseDetails); + } + + @Test + void shouldSendEmailForDocumentUploadIssue() { + when(mockGrantOfRepresentationData.getDocumentUploadIssue()).thenReturn(Boolean.TRUE); + when(mockGrantOfRepresentationData.getLanguagePreferenceWelsh()).thenReturn(Boolean.FALSE); + DocumentNotification documentNotification = DocumentNotification.builder() + .ccdReference(formdataId) + .applicantName(mockGrantOfRepresentationData.getPrimaryApplicantForenames() + + " " + mockGrantOfRepresentationData.getPrimaryApplicantSurname()) + .deceasedName(mockGrantOfRepresentationData.getDeceasedForenames() + + " " + mockGrantOfRepresentationData.getDeceasedSurname()) + .deceasedDod(mockGrantOfRepresentationData.getDeceasedDateOfDeath().toString()) + .email(mockGrantOfRepresentationData.getPrimaryApplicantEmailAddress()) + .fileName(List.of("fileName.pdf")) + .citizenResponse(mockGrantOfRepresentationData.getCitizenResponse()) + .expectedResponseDate(mockGrantOfRepresentationData.getExpectedResponseDate() + .toString()) + .build(); + businessService.documentUploadNotification(formdataId, "true"); + verifyGetCaseCalls(); + verify(businessServiceApi).documentUploadIssue(documentNotification); + verify(submitServiceApi) + .saveCase(AUTHORIZATION, SERVICE_AUTHORIZATION, formdataId, EVENT_DESCRIPTION, mockProbateCaseDetails); + } + + @Test + void shouldSendEmailForWelshDocumentUploadIssue() { + when(mockGrantOfRepresentationData.getDocumentUploadIssue()).thenReturn(Boolean.TRUE); + when(mockGrantOfRepresentationData.getLanguagePreferenceWelsh()).thenReturn(Boolean.TRUE); + DocumentNotification documentNotification = DocumentNotification.builder() + .ccdReference(formdataId) + .applicantName(mockGrantOfRepresentationData.getPrimaryApplicantForenames() + + " " + mockGrantOfRepresentationData.getPrimaryApplicantSurname()) + .deceasedName(mockGrantOfRepresentationData.getDeceasedForenames() + + " " + mockGrantOfRepresentationData.getDeceasedSurname()) + .deceasedDod(mockGrantOfRepresentationData.getDeceasedDateOfDeath().toString()) + .email(mockGrantOfRepresentationData.getPrimaryApplicantEmailAddress()) + .fileName(List.of("fileName.pdf")) + .citizenResponse(mockGrantOfRepresentationData.getCitizenResponse()) + .expectedResponseDate(mockGrantOfRepresentationData.getExpectedResponseDate()) + .build(); + businessService.documentUploadNotification(formdataId, "true"); + verifyGetCaseCalls(); + verify(businessServiceApi).documentUploadIssueBilingual(documentNotification); + verify(submitServiceApi) + .saveCase(AUTHORIZATION, SERVICE_AUTHORIZATION, formdataId, EVENT_DESCRIPTION, mockProbateCaseDetails); + } + @Test public void shouldResetInviteAgreedOnCase() { diff --git a/src/test/resources/businessDocuments/documentNotification.json b/src/test/resources/businessDocuments/documentNotification.json new file mode 100644 index 000000000..f7a10157e --- /dev/null +++ b/src/test/resources/businessDocuments/documentNotification.json @@ -0,0 +1,6 @@ +{ + "formdataId": "123456", + "email": "address@email.com", + "firstName": "Jon", + "lastName": "Snow" +} \ No newline at end of file