From 64bb99001a34472e90aa7f9b6bb2bef34e99f941 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Fri, 28 Jun 2024 15:19:18 +0100 Subject: [PATCH 01/51] add dummy controller for API gateway POC --- .../cafcass/CafcassCasesController.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java new file mode 100644 index 00000000000..acfb9e8400c --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -0,0 +1,65 @@ +package uk.gov.hmcts.reform.fpl.controllers.cafcass; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; + +import java.time.DateTimeException; +import java.time.LocalDateTime; +import java.util.UUID; + +import static org.apache.commons.lang3.ObjectUtils.isEmpty; + +@RestController +@RequestMapping("/cases") +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassCasesController { + private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-ddThh:mm:ss.SSS"; + private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; + + @GetMapping + public ResponseEntity searchCases(@RequestParam(name = "startDate") String startDate, + @RequestParam(name = "endDate") String endDate) { + try { + if (!isEmpty(startDate) && !isEmpty(endDate)) { + LocalDateTime startLocalDateTime = + DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); + LocalDateTime endLocalDateTime = + DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); + + return ResponseEntity.ok(String.format("searchCases - Start date: [%s], End date: [%s]", + DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(startLocalDateTime, DATE_TIME_FORMAT_OUT), + DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(endLocalDateTime, DATE_TIME_FORMAT_OUT) + )); + } else { + throw new DateTimeException("empty"); + } + } catch (DateTimeException e) { + return ResponseEntity.status(400).body("bad input parameter"); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } + + @GetMapping("documents/{documentId}/binary") + public ResponseEntity getDocumentBinary(@PathVariable String documentId) { + try { + if (!isEmpty(documentId)) { + UUID docId = UUID.fromString(documentId); + return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", docId)); + } else { + throw new IllegalArgumentException("empty"); + } + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter"); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } +} From 6026a6fe75ff1b1578933163292a3a3a1885a09f Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 2 Jul 2024 15:56:15 +0100 Subject: [PATCH 02/51] update CafcassCasesController for POC --- .../cafcass/CafcassCasesControllerTest.java | 76 +++++++++++++++ .../cafcass/CafcassCasesController.java | 95 +++++++++++++++---- 2 files changed, 151 insertions(+), 20 deletions(-) create mode 100644 service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java new file mode 100644 index 00000000000..39cc22f6845 --- /dev/null +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -0,0 +1,76 @@ +package uk.gov.hmcts.reform.fpl.controllers.cafcass; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; + +@WebMvcTest(CafcassCasesController.class) +@OverrideAutoConfiguration(enabled = true) +public class CafcassCasesControllerTest extends AbstractTest { + @Autowired + private MockMvc mockMvc; + + @Test + void searchCases() { + getEvent("/cases/start_date=2023-03-28T12:32:54.541&end_date=2024-03-27T12:32:54.54", Object.class); + assertTrue(true); + } + + + private T getEvent(String path, Class responseType, String... userRoles) { + try { + MvcResult response = mockMvc + .perform(post(path) + .header("user-roles", String.join(",", userRoles))) + .andReturn(); + + byte[] responseBody = response.getResponse().getContentAsByteArray(); + + if (responseBody.length > 0) { + return mapper.readValue(responseBody, responseType); + } else { + return null; + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private T postEvent(String path, byte[] data, Class responseType, String... userRoles) { + try { + MvcResult response = mockMvc + .perform(post(path) + .header("user-roles", String.join(",", userRoles)) + .contentType(MediaType.APPLICATION_JSON) + .content(data)) + .andReturn(); + + byte[] responseBody = response.getResponse().getContentAsByteArray(); + + if (responseBody.length > 0) { + return mapper.readValue(responseBody, responseType); + } else { + return null; + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private byte[] toBytes(Object o) { + try { + return mapper.writeValueAsString(o).getBytes(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index acfb9e8400c..30e86ecd269 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -5,13 +5,18 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; import java.time.DateTimeException; import java.time.LocalDateTime; +import java.util.Map; import java.util.UUID; import static org.apache.commons.lang3.ObjectUtils.isEmpty; @@ -23,25 +28,28 @@ public class CafcassCasesController { private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-ddThh:mm:ss.SSS"; private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; - @GetMapping + @GetMapping("") public ResponseEntity searchCases(@RequestParam(name = "startDate") String startDate, @RequestParam(name = "endDate") String endDate) { try { - if (!isEmpty(startDate) && !isEmpty(endDate)) { - LocalDateTime startLocalDateTime = - DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); - LocalDateTime endLocalDateTime = - DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); - - return ResponseEntity.ok(String.format("searchCases - Start date: [%s], End date: [%s]", - DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(startLocalDateTime, DATE_TIME_FORMAT_OUT), - DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(endLocalDateTime, DATE_TIME_FORMAT_OUT) - )); - } else { - throw new DateTimeException("empty"); + if (isEmpty(startDate)) { + throw new IllegalArgumentException("startDate empty"); + } + if (isEmpty(endDate)) { + throw new IllegalArgumentException("endDate empty"); } + + LocalDateTime startLocalDateTime = + DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); + LocalDateTime endLocalDateTime = + DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); + + return ResponseEntity.ok(String.format("searchCases - Start date: [%s], End date: [%s]", + DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(startLocalDateTime, DATE_TIME_FORMAT_OUT), + DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(endLocalDateTime, DATE_TIME_FORMAT_OUT) + )); } catch (DateTimeException e) { - return ResponseEntity.status(400).body("bad input parameter"); + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); } catch (Exception e) { return ResponseEntity.status(500).body("Internal server error"); } @@ -50,14 +58,61 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri @GetMapping("documents/{documentId}/binary") public ResponseEntity getDocumentBinary(@PathVariable String documentId) { try { - if (!isEmpty(documentId)) { - UUID docId = UUID.fromString(documentId); - return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", docId)); - } else { - throw new IllegalArgumentException("empty"); + if (isEmpty(documentId)) { + throw new IllegalArgumentException("documentId empty"); + } + + return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", + UUID.fromString(documentId))); + + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } + + @PostMapping("{caseId}/document") + public ResponseEntity uploadDocument(@PathVariable String caseId, + @RequestPart(value = "file") MultipartFile file, + @RequestPart(value = "typeOfDocument") String typeOfDocument) { + try { + if (isEmpty(caseId)) { + throw new IllegalArgumentException("caseId empty"); } + if (isEmpty(file)) { + throw new IllegalArgumentException("file empty"); + } + if (isEmpty(typeOfDocument)) { + throw new IllegalArgumentException("typeOfDocument empty"); + } + + return ResponseEntity.ok(String.format( + "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", + UUID.fromString(caseId), file.getSize(), typeOfDocument)); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } + + @PostMapping("{caseId}/guardians") + public ResponseEntity uploadGuardians(@PathVariable String caseId, + @RequestBody Map requestBody) { + try { + if (isEmpty(caseId)) { + throw new IllegalArgumentException("caseId empty"); + } + if (isEmpty(requestBody)) { + throw new IllegalArgumentException("requestBody empty"); + } + + return ResponseEntity.ok(String.format( + "uploadGuardians - caseId: [%s], guardianName: [%s], children: [%s]", + UUID.fromString(caseId), requestBody.get("guardianName"), requestBody.get("children"))); } catch (IllegalArgumentException e) { - return ResponseEntity.status(400).body("bad input parameter"); + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); } catch (Exception e) { return ResponseEntity.status(500).body("Internal server error"); } From 1eb519df0bb67771079020e2adc49db83b5212fb Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 2 Jul 2024 16:41:41 +0100 Subject: [PATCH 03/51] update CafcassCasesController for POC --- .../cafcass/CafcassCasesControllerTest.java | 46 +++++- .../cafcass/CafcassCasesController.java | 153 +++++++++--------- 2 files changed, 116 insertions(+), 83 deletions(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index 39cc22f6845..c79ae481ce4 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -10,8 +10,10 @@ import org.springframework.test.web.servlet.MvcResult; import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(CafcassCasesController.class) @OverrideAutoConfiguration(enabled = true) @@ -20,16 +22,50 @@ public class CafcassCasesControllerTest extends AbstractTest { private MockMvc mockMvc; @Test - void searchCases() { - getEvent("/cases/start_date=2023-03-28T12:32:54.541&end_date=2024-03-27T12:32:54.54", Object.class); - assertTrue(true); + void searchCases() throws Exception { + MvcResult response = mockMvc + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(",")) + .queryParam("startDate", "2023-03-28T12:32:54.541") + .queryParam("endDate", "2024-03-27T12:32:54.542")) + .andExpect(status().is(200)) + .andReturn(); + + assertEquals("searchCases - Start date: [2023-03-28], End date: [2024-03-27]", + response.getResponse().getContentAsString()); } + @Test + void searchCasesEmptyParam400() throws Exception { + MvcResult response = mockMvc + .perform(get("/cases")) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + } + + @Test + void searchCases500() throws Exception { + MvcResult response = mockMvc + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(",")) + .queryParam("startDate", "2024-03-28T12:32:54.541") + .queryParam("endDate", "2023-03-27T12:32:54.542")) + .andExpect(status().is(500)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 500); + } private T getEvent(String path, Class responseType, String... userRoles) { try { MvcResult response = mockMvc - .perform(post(path) + .perform(get(path) .header("user-roles", String.join(",", userRoles))) .andReturn(); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 30e86ecd269..3c99ac1bd6e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -4,20 +4,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; import java.time.DateTimeException; -import java.time.LocalDateTime; -import java.util.Map; -import java.util.UUID; +import java.time.LocalDate; import static org.apache.commons.lang3.ObjectUtils.isEmpty; @@ -25,7 +18,7 @@ @RequestMapping("/cases") @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassCasesController { - private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-ddThh:mm:ss.SSS"; + private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-dd'T'hh:mm:ss.SSS"; private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; @GetMapping("") @@ -39,82 +32,86 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri throw new IllegalArgumentException("endDate empty"); } - LocalDateTime startLocalDateTime = - DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); - LocalDateTime endLocalDateTime = - DateFormatterHelper.parseLocalDateTimeFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); + LocalDate startLocalDateTime = + DateFormatterHelper.parseLocalDateFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); + LocalDate endLocalDateTime = + DateFormatterHelper.parseLocalDateFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); + + if (startLocalDateTime.isAfter(endLocalDateTime)) { + throw new Exception("startDate after endDate"); + } return ResponseEntity.ok(String.format("searchCases - Start date: [%s], End date: [%s]", - DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(startLocalDateTime, DATE_TIME_FORMAT_OUT), - DateFormatterHelper.formatLocalDateTimeBaseUsingFormat(endLocalDateTime, DATE_TIME_FORMAT_OUT) + DateFormatterHelper.formatLocalDateToString(startLocalDateTime, DATE_TIME_FORMAT_OUT), + DateFormatterHelper.formatLocalDateToString(endLocalDateTime, DATE_TIME_FORMAT_OUT) )); } catch (DateTimeException e) { return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); } catch (Exception e) { - return ResponseEntity.status(500).body("Internal server error"); + return ResponseEntity.status(500).body("Internal server error - " + e.getMessage()); } } - @GetMapping("documents/{documentId}/binary") - public ResponseEntity getDocumentBinary(@PathVariable String documentId) { - try { - if (isEmpty(documentId)) { - throw new IllegalArgumentException("documentId empty"); - } - - return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", - UUID.fromString(documentId))); - - } catch (IllegalArgumentException e) { - return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); - } catch (Exception e) { - return ResponseEntity.status(500).body("Internal server error"); - } - } - - @PostMapping("{caseId}/document") - public ResponseEntity uploadDocument(@PathVariable String caseId, - @RequestPart(value = "file") MultipartFile file, - @RequestPart(value = "typeOfDocument") String typeOfDocument) { - try { - if (isEmpty(caseId)) { - throw new IllegalArgumentException("caseId empty"); - } - if (isEmpty(file)) { - throw new IllegalArgumentException("file empty"); - } - if (isEmpty(typeOfDocument)) { - throw new IllegalArgumentException("typeOfDocument empty"); - } - - return ResponseEntity.ok(String.format( - "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", - UUID.fromString(caseId), file.getSize(), typeOfDocument)); - } catch (IllegalArgumentException e) { - return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); - } catch (Exception e) { - return ResponseEntity.status(500).body("Internal server error"); - } - } - - @PostMapping("{caseId}/guardians") - public ResponseEntity uploadGuardians(@PathVariable String caseId, - @RequestBody Map requestBody) { - try { - if (isEmpty(caseId)) { - throw new IllegalArgumentException("caseId empty"); - } - if (isEmpty(requestBody)) { - throw new IllegalArgumentException("requestBody empty"); - } - - return ResponseEntity.ok(String.format( - "uploadGuardians - caseId: [%s], guardianName: [%s], children: [%s]", - UUID.fromString(caseId), requestBody.get("guardianName"), requestBody.get("children"))); - } catch (IllegalArgumentException e) { - return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); - } catch (Exception e) { - return ResponseEntity.status(500).body("Internal server error"); - } - } +// @GetMapping("documents/{documentId}/binary") +// public ResponseEntity getDocumentBinary(@PathVariable String documentId) { +// try { +// if (isEmpty(documentId)) { +// throw new IllegalArgumentException("documentId empty"); +// } +// +// return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", +// UUID.fromString(documentId))); +// +// } catch (IllegalArgumentException e) { +// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); +// } catch (Exception e) { +// return ResponseEntity.status(500).body("Internal server error"); +// } +// } +// +// @PostMapping("{caseId}/document") +// public ResponseEntity uploadDocument(@PathVariable String caseId, +// @RequestPart(value = "file") MultipartFile file, +// @RequestPart(value = "typeOfDocument") String typeOfDocument) { +// try { +// if (isEmpty(caseId)) { +// throw new IllegalArgumentException("caseId empty"); +// } +// if (isEmpty(file)) { +// throw new IllegalArgumentException("file empty"); +// } +// if (isEmpty(typeOfDocument)) { +// throw new IllegalArgumentException("typeOfDocument empty"); +// } +// +// return ResponseEntity.ok(String.format( +// "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", +// UUID.fromString(caseId), file.getSize(), typeOfDocument)); +// } catch (IllegalArgumentException e) { +// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); +// } catch (Exception e) { +// return ResponseEntity.status(500).body("Internal server error"); +// } +// } +// +// @PostMapping("{caseId}/guardians") +// public ResponseEntity uploadGuardians(@PathVariable String caseId, +// @RequestBody Map requestBody) { +// try { +// if (isEmpty(caseId)) { +// throw new IllegalArgumentException("caseId empty"); +// } +// if (isEmpty(requestBody)) { +// throw new IllegalArgumentException("requestBody empty"); +// } +// +// return ResponseEntity.ok(String.format( +// "uploadGuardians - caseId: [%s], guardianName: [%s], children: [%s]", +// UUID.fromString(caseId), requestBody.get("guardianName"), requestBody.get("children"))); +// } catch (IllegalArgumentException e) { +// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); +// } catch (Exception e) { +// return ResponseEntity.status(500).body("Internal server error"); +// } +// } } From 3f639b7c8b0b336aecb58efd2ea0e05368e662db Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 2 Jul 2024 16:59:52 +0100 Subject: [PATCH 04/51] Update CafcassCasesController.java --- .../cafcass/CafcassCasesController.java | 63 ------------------- 1 file changed, 63 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 3c99ac1bd6e..d2032ec1153 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -51,67 +51,4 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri return ResponseEntity.status(500).body("Internal server error - " + e.getMessage()); } } - -// @GetMapping("documents/{documentId}/binary") -// public ResponseEntity getDocumentBinary(@PathVariable String documentId) { -// try { -// if (isEmpty(documentId)) { -// throw new IllegalArgumentException("documentId empty"); -// } -// -// return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", -// UUID.fromString(documentId))); -// -// } catch (IllegalArgumentException e) { -// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); -// } catch (Exception e) { -// return ResponseEntity.status(500).body("Internal server error"); -// } -// } -// -// @PostMapping("{caseId}/document") -// public ResponseEntity uploadDocument(@PathVariable String caseId, -// @RequestPart(value = "file") MultipartFile file, -// @RequestPart(value = "typeOfDocument") String typeOfDocument) { -// try { -// if (isEmpty(caseId)) { -// throw new IllegalArgumentException("caseId empty"); -// } -// if (isEmpty(file)) { -// throw new IllegalArgumentException("file empty"); -// } -// if (isEmpty(typeOfDocument)) { -// throw new IllegalArgumentException("typeOfDocument empty"); -// } -// -// return ResponseEntity.ok(String.format( -// "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", -// UUID.fromString(caseId), file.getSize(), typeOfDocument)); -// } catch (IllegalArgumentException e) { -// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); -// } catch (Exception e) { -// return ResponseEntity.status(500).body("Internal server error"); -// } -// } -// -// @PostMapping("{caseId}/guardians") -// public ResponseEntity uploadGuardians(@PathVariable String caseId, -// @RequestBody Map requestBody) { -// try { -// if (isEmpty(caseId)) { -// throw new IllegalArgumentException("caseId empty"); -// } -// if (isEmpty(requestBody)) { -// throw new IllegalArgumentException("requestBody empty"); -// } -// -// return ResponseEntity.ok(String.format( -// "uploadGuardians - caseId: [%s], guardianName: [%s], children: [%s]", -// UUID.fromString(caseId), requestBody.get("guardianName"), requestBody.get("children"))); -// } catch (IllegalArgumentException e) { -// return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); -// } catch (Exception e) { -// return ResponseEntity.status(500).body("Internal server error"); -// } -// } } From b308de6813b61c6a92f383a3e92d20c921cc252b Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 2 Jul 2024 17:15:55 +0100 Subject: [PATCH 05/51] Update CafcassCasesControllerTest.java --- .../cafcass/CafcassCasesControllerTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index c79ae481ce4..cd64be0b674 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -37,6 +37,21 @@ void searchCases() throws Exception { response.getResponse().getContentAsString()); } + @Test + void searchCasesInvalidFormat400() throws Exception { + MvcResult response = mockMvc + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(",")) + .queryParam("startDate", "123") + .queryParam("endDate", "321")) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + } + @Test void searchCasesEmptyParam400() throws Exception { MvcResult response = mockMvc From 680242dc02fdf94fb5872fb8c4872c05f9430a5e Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 2 Jul 2024 19:23:22 +0100 Subject: [PATCH 06/51] Update CafcassCasesController.java --- .../fpl/controllers/cafcass/CafcassCasesController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index d2032ec1153..dbf0dcacdd0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.fpl.controllers.cafcass; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -14,6 +15,7 @@ import static org.apache.commons.lang3.ObjectUtils.isEmpty; +@Slf4j @RestController @RequestMapping("/cases") @RequiredArgsConstructor(onConstructor = @__(@Autowired)) @@ -24,6 +26,7 @@ public class CafcassCasesController { @GetMapping("") public ResponseEntity searchCases(@RequestParam(name = "startDate") String startDate, @RequestParam(name = "endDate") String endDate) { + log.info("searchCases request received"); try { if (isEmpty(startDate)) { throw new IllegalArgumentException("startDate empty"); @@ -32,6 +35,7 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri throw new IllegalArgumentException("endDate empty"); } + log.info("searchCases, " + startDate + ", " + endDate); LocalDate startLocalDateTime = DateFormatterHelper.parseLocalDateFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); LocalDate endLocalDateTime = From 1a46c8747d4e27d98528b661898390d3623b19fe Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 3 Jul 2024 14:05:35 +0100 Subject: [PATCH 07/51] add all endpoint for POC --- .../cafcass/CafcassCasesControllerTest.java | 221 ++++++++++++++---- .../cafcass/CafcassCasesController.java | 82 +++++++ 2 files changed, 261 insertions(+), 42 deletions(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index cd64be0b674..abd76c993c6 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -6,10 +6,16 @@ import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; +import java.util.List; +import java.util.Map; +import java.util.UUID; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -77,51 +83,182 @@ void searchCases500() throws Exception { assertEquals(response.getResponse().getStatus(), 500); } - private T getEvent(String path, Class responseType, String... userRoles) { - try { - MvcResult response = mockMvc - .perform(get(path) - .header("user-roles", String.join(",", userRoles))) - .andReturn(); - - byte[] responseBody = response.getResponse().getContentAsByteArray(); - - if (responseBody.length > 0) { - return mapper.readValue(responseBody, responseType); - } else { - return null; - } - } catch (Exception e) { - throw new RuntimeException(e); - } + @Test + void getDocumentBinary() throws Exception { + UUID docId = UUID.randomUUID(); + MvcResult response = mockMvc + .perform(get("/cases/documents/%s/binary".formatted(docId)) + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(200)) + .andReturn(); + + assertEquals("getDocumentBinary - document id: [%s]".formatted(docId), + response.getResponse().getContentAsString()); + } + + @Test + void getDocumentBinary400() throws Exception { + MvcResult response = mockMvc + .perform(get("/cases/documents/123/binary") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + + response = mockMvc + .perform(get("/cases/documents/ /binary") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + } + + @Test + void uploadDocument() throws Exception { + UUID caseId = UUID.randomUUID(); + byte[] fileBytes = "This is a file. Trust me!".getBytes(); + MockMultipartFile file = new MockMultipartFile( + "file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, fileBytes); + + MvcResult response = mockMvc + .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) + .file(file) + .param("typeOfDocument", "type Of Document") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(200)) + .andReturn(); + + assertEquals("uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]" + .formatted(caseId, fileBytes.length, "type Of Document"), + response.getResponse().getContentAsString()); + } + + @Test + void uploadDocument400() throws Exception { + UUID caseId = UUID.randomUUID(); + + MvcResult response = mockMvc + .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) + .param("typeOfDocument", "type Of Document") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + + + byte[] fileBytes = "This is a file. Trust me!".getBytes(); + MockMultipartFile file = new MockMultipartFile( + "file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, fileBytes); + + response = mockMvc + .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(" ")) + .file(file) + .param("typeOfDocument", "type Of Document") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + } + + @Test + void uploadGuardians() throws Exception { + UUID caseId = UUID.randomUUID(); + + MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId)) + .content("[\n" + + " {\n" + + " \"guardianName\": \"John Smith\",\n" + + " \"telephoneNumber\": \"01234567890\",\n" + + " \"email\": \"john.smith@example.com\",\n" + + " \"children\": [\n" + + " \"Joe Bloggs\"\n" + + " ]\n" + + " }\n" + + "]") + .contentType(MediaType.APPLICATION_JSON) + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(200)) + .andReturn(); + + assertEquals("uploadGuardians - caseId: [%s], no of guardians: [%s]\nguardianName: [%s], children: [%s]\n" + .formatted(caseId, 1, "John Smith", "Joe Bloggs"), + response.getResponse().getContentAsString()); } - private T postEvent(String path, byte[] data, Class responseType, String... userRoles) { - try { - MvcResult response = mockMvc - .perform(post(path) - .header("user-roles", String.join(",", userRoles)) - .contentType(MediaType.APPLICATION_JSON) - .content(data)) - .andReturn(); - - byte[] responseBody = response.getResponse().getContentAsByteArray(); - - if (responseBody.length > 0) { - return mapper.readValue(responseBody, responseType); - } else { - return null; - } - } catch (Exception e) { - throw new RuntimeException(e); - } + @Test + void uploadGuardians400() throws Exception { + UUID caseId = UUID.randomUUID(); + + MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId)) + .content("[]") + .contentType(MediaType.APPLICATION_JSON) + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + + response = mockMvc.perform(post("/cases/%s/guardians".formatted(" ")) + .content("[\n" + + " {\n" + + " \"guardianName\": \"John Smith\",\n" + + " \"telephoneNumber\": \"01234567890\",\n" + + " \"email\": \"john.smith@example.com\",\n" + + " \"children\": [\n" + + " \"Joe Bloggs\"\n" + + " ]\n" + + " }\n" + + "]") + .contentType(MediaType.APPLICATION_JSON) + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); } - private byte[] toBytes(Object o) { - try { - return mapper.writeValueAsString(o).getBytes(); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } + @Test + void uploadGuardians500() throws Exception { + UUID caseId = UUID.randomUUID(); + + MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId)) + .content("[\n" + + " {\n" + + " \"guardianName\": \"John Smith\",\n" + + " \"telephoneNumber\": \"01234567890\",\n" + + " \"email\": \"john.smith@example.com\",\n" + + " \"children\": \"12313\"" + + " }\n" + + "]") + .contentType(MediaType.APPLICATION_JSON) + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(","))) + .andExpect(status().is(500)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 500); } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index dbf0dcacdd0..ce2db4168d3 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -5,13 +5,22 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; import java.time.DateTimeException; import java.time.LocalDate; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; import static org.apache.commons.lang3.ObjectUtils.isEmpty; @@ -55,4 +64,77 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri return ResponseEntity.status(500).body("Internal server error - " + e.getMessage()); } } + + @GetMapping("documents/{documentId}/binary") + public ResponseEntity getDocumentBinary(@PathVariable String documentId) { + try { + if (isEmpty(documentId)) { + throw new IllegalArgumentException("documentId empty"); + } + + return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", + UUID.fromString(documentId))); + + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } + + @PostMapping("{caseId}/document") + public ResponseEntity uploadDocument(@PathVariable String caseId, + @RequestParam(value = "file") MultipartFile file, + @RequestParam(value = "typeOfDocument") String typeOfDocument) { + try { + if (isEmpty(caseId)) { + throw new IllegalArgumentException("caseId empty"); + } + if (isEmpty(file)) { + throw new IllegalArgumentException("file empty"); + } + if (isEmpty(typeOfDocument)) { + throw new IllegalArgumentException("typeOfDocument empty"); + } + + return ResponseEntity.ok(String.format( + "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", + UUID.fromString(caseId), file.getSize(), typeOfDocument)); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } + + @SuppressWarnings("unchecked") + @PostMapping("{caseId}/guardians") + public ResponseEntity uploadGuardians(@PathVariable String caseId, + @RequestBody List> guardians) { + try { + if (isEmpty(caseId)) { + throw new IllegalArgumentException("caseId empty"); + } + if (isEmpty(guardians)) { + throw new IllegalArgumentException("list empty"); + } + + StringBuilder sb = new StringBuilder(); + sb.append("uploadGuardians - caseId: [%s], no of guardians: [%s]\n" + .formatted(UUID.fromString(caseId), guardians.size())); + + guardians.forEach(guardian -> { + sb.append("guardianName: [%s], ".formatted(guardian.get("guardianName"))); + sb.append("children: [%s]".formatted(String.join(", ", + ((List) guardian.get("children"))))); + sb.append("\n"); + }); + + return ResponseEntity.ok(sb); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(500).body("Internal server error"); + } + } } From 8aecb859462a10eb85c21a40e3c6b8474570e463 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 3 Jul 2024 15:51:33 +0100 Subject: [PATCH 08/51] remove unused import --- .../fpl/controllers/cafcass/CafcassCasesControllerTest.java | 3 --- .../reform/fpl/controllers/cafcass/CafcassCasesController.java | 2 -- 2 files changed, 5 deletions(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index abd76c993c6..3c1cd744164 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.fpl.controllers.cafcass; -import com.fasterxml.jackson.core.JsonProcessingException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; @@ -12,8 +11,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; -import java.util.List; -import java.util.Map; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index ce2db4168d3..cf8aa796d30 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; @@ -20,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; import static org.apache.commons.lang3.ObjectUtils.isEmpty; From 9b7784ccf96b0adbeb09eb255459faeef21e61af Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 3 Jul 2024 17:22:52 +0100 Subject: [PATCH 09/51] Update CafcassCasesControllerTest.java --- .../cafcass/CafcassCasesControllerTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index 3c1cd744164..e1f50aacf82 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -63,6 +63,28 @@ void searchCasesEmptyParam400() throws Exception { .andReturn(); assertEquals(response.getResponse().getStatus(), 400); + + response = mockMvc + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(",")) + .queryParam("startDate", "2023-03-28T12:32:54.541")) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); + + response = mockMvc + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN) + .header("user-id", USER_ID) + .header("user-roles", String.join(",")) + .queryParam("endDate", "2024-03-27T12:32:54.542")) + .andExpect(status().is(400)) + .andReturn(); + + assertEquals(response.getResponse().getStatus(), 400); } @Test @@ -161,7 +183,7 @@ void uploadDocument400() throws Exception { "file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, fileBytes); response = mockMvc - .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(" ")) + .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) .file(file) .param("typeOfDocument", "type Of Document") .header("authorization", USER_AUTH_TOKEN) From 6fb7d74c4138deb2715af19f9a705f3fedb4bb0d Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 3 Jul 2024 17:36:05 +0100 Subject: [PATCH 10/51] Update CafcassCasesController.java --- .../cafcass/CafcassCasesController.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index cf8aa796d30..744c76fc034 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -35,12 +35,12 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri @RequestParam(name = "endDate") String endDate) { log.info("searchCases request received"); try { - if (isEmpty(startDate)) { - throw new IllegalArgumentException("startDate empty"); - } - if (isEmpty(endDate)) { - throw new IllegalArgumentException("endDate empty"); - } +// if (isEmpty(startDate)) { +// throw new IllegalArgumentException("startDate empty"); +// } +// if (isEmpty(endDate)) { +// throw new IllegalArgumentException("endDate empty"); +// } log.info("searchCases, " + startDate + ", " + endDate); LocalDate startLocalDateTime = @@ -66,9 +66,9 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri @GetMapping("documents/{documentId}/binary") public ResponseEntity getDocumentBinary(@PathVariable String documentId) { try { - if (isEmpty(documentId)) { - throw new IllegalArgumentException("documentId empty"); - } +// if (isEmpty(documentId)) { +// throw new IllegalArgumentException("documentId empty"); +// } return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", UUID.fromString(documentId))); @@ -85,15 +85,15 @@ public ResponseEntity uploadDocument(@PathVariable String caseId, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "typeOfDocument") String typeOfDocument) { try { - if (isEmpty(caseId)) { - throw new IllegalArgumentException("caseId empty"); - } - if (isEmpty(file)) { - throw new IllegalArgumentException("file empty"); - } - if (isEmpty(typeOfDocument)) { - throw new IllegalArgumentException("typeOfDocument empty"); - } +// if (isEmpty(caseId)) { +// throw new IllegalArgumentException("caseId empty"); +// } +// if (isEmpty(file)) { +// throw new IllegalArgumentException("file empty"); +// } +// if (isEmpty(typeOfDocument)) { +// throw new IllegalArgumentException("typeOfDocument empty"); +// } return ResponseEntity.ok(String.format( "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", @@ -110,9 +110,9 @@ public ResponseEntity uploadDocument(@PathVariable String caseId, public ResponseEntity uploadGuardians(@PathVariable String caseId, @RequestBody List> guardians) { try { - if (isEmpty(caseId)) { - throw new IllegalArgumentException("caseId empty"); - } +// if (isEmpty(caseId)) { +// throw new IllegalArgumentException("caseId empty"); +// } if (isEmpty(guardians)) { throw new IllegalArgumentException("list empty"); } From cf02f563d4fb5ed116cdd3641267f4111ef712f3 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 3 Jul 2024 17:37:29 +0100 Subject: [PATCH 11/51] Update CafcassCasesController.java --- .../cafcass/CafcassCasesController.java | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 744c76fc034..6f7bc3fbf4a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -35,13 +35,6 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri @RequestParam(name = "endDate") String endDate) { log.info("searchCases request received"); try { -// if (isEmpty(startDate)) { -// throw new IllegalArgumentException("startDate empty"); -// } -// if (isEmpty(endDate)) { -// throw new IllegalArgumentException("endDate empty"); -// } - log.info("searchCases, " + startDate + ", " + endDate); LocalDate startLocalDateTime = DateFormatterHelper.parseLocalDateFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); @@ -65,11 +58,8 @@ public ResponseEntity searchCases(@RequestParam(name = "startDate") Stri @GetMapping("documents/{documentId}/binary") public ResponseEntity getDocumentBinary(@PathVariable String documentId) { + log.info("getDocumentBinary request received"); try { -// if (isEmpty(documentId)) { -// throw new IllegalArgumentException("documentId empty"); -// } - return ResponseEntity.ok(String.format("getDocumentBinary - document id: [%s]", UUID.fromString(documentId))); @@ -84,17 +74,8 @@ public ResponseEntity getDocumentBinary(@PathVariable String documentId) public ResponseEntity uploadDocument(@PathVariable String caseId, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "typeOfDocument") String typeOfDocument) { + log.info("uploadDocument request received"); try { -// if (isEmpty(caseId)) { -// throw new IllegalArgumentException("caseId empty"); -// } -// if (isEmpty(file)) { -// throw new IllegalArgumentException("file empty"); -// } -// if (isEmpty(typeOfDocument)) { -// throw new IllegalArgumentException("typeOfDocument empty"); -// } - return ResponseEntity.ok(String.format( "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", UUID.fromString(caseId), file.getSize(), typeOfDocument)); @@ -109,10 +90,8 @@ public ResponseEntity uploadDocument(@PathVariable String caseId, @PostMapping("{caseId}/guardians") public ResponseEntity uploadGuardians(@PathVariable String caseId, @RequestBody List> guardians) { + log.info("uploadGuardians request received"); try { -// if (isEmpty(caseId)) { -// throw new IllegalArgumentException("caseId empty"); -// } if (isEmpty(guardians)) { throw new IllegalArgumentException("list empty"); } @@ -120,6 +99,7 @@ public ResponseEntity uploadGuardians(@PathVariable String caseId, StringBuilder sb = new StringBuilder(); sb.append("uploadGuardians - caseId: [%s], no of guardians: [%s]\n" .formatted(UUID.fromString(caseId), guardians.size())); + log.info("uploadGuardians guardians size " + guardians.size()); guardians.forEach(guardian -> { sb.append("guardianName: [%s], ".formatted(guardian.get("guardianName"))); From 2b2e78d5414ff69c54ccafe284ed8c99da7facb7 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 4 Jul 2024 13:50:59 +0100 Subject: [PATCH 12/51] update CafcassCasesController --- .../cafcass/CafcassCasesControllerTest.java | 16 ++++++++-------- .../cafcass/CafcassCasesController.java | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index e1f50aacf82..ae877c3c3d9 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -21,6 +21,11 @@ @WebMvcTest(CafcassCasesController.class) @OverrideAutoConfiguration(enabled = true) public class CafcassCasesControllerTest extends AbstractTest { + private static final UUID CASE_ID = UUID.randomUUID(); + private static final byte[] FILE_BYTES = "This is a file. Trust me!".getBytes(); + private static final MockMultipartFile FILE = new MockMultipartFile( + "file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, FILE_BYTES); + @Autowired private MockMvc mockMvc; @@ -142,14 +147,10 @@ void getDocumentBinary400() throws Exception { @Test void uploadDocument() throws Exception { - UUID caseId = UUID.randomUUID(); - byte[] fileBytes = "This is a file. Trust me!".getBytes(); - MockMultipartFile file = new MockMultipartFile( - "file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, fileBytes); MvcResult response = mockMvc - .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) - .file(file) + .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(CASE_ID)) + .file(FILE) .param("typeOfDocument", "type Of Document") .header("authorization", USER_AUTH_TOKEN) .header("user-id", USER_ID) @@ -158,7 +159,7 @@ void uploadDocument() throws Exception { .andReturn(); assertEquals("uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]" - .formatted(caseId, fileBytes.length, "type Of Document"), + .formatted(CASE_ID, FILE_BYTES.length, "type Of Document"), response.getResponse().getContentAsString()); } @@ -185,7 +186,6 @@ void uploadDocument400() throws Exception { response = mockMvc .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) .file(file) - .param("typeOfDocument", "type Of Document") .header("authorization", USER_AUTH_TOKEN) .header("user-id", USER_ID) .header("user-roles", String.join(","))) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 6f7bc3fbf4a..ce54fad3020 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -75,6 +75,7 @@ public ResponseEntity uploadDocument(@PathVariable String caseId, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "typeOfDocument") String typeOfDocument) { log.info("uploadDocument request received"); + try { return ResponseEntity.ok(String.format( "uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]", From 80db602cb0f42368e92f9e9805552486d62ce366 Mon Sep 17 00:00:00 2001 From: Chak Shing Lo <95437003+chak-shing-lo-justice@users.noreply.github.com> Date: Tue, 9 Jul 2024 14:04:25 +0100 Subject: [PATCH 13/51] DFPL-2449 Add interceptor and exception handling for Cafcass API (#5493) * Fix ES/logstash configuration in preview (#5488) * Copy adoption configuration to attempt to persist ES a bit more between pipeline runs * fix template variable in ES * fix template variable in ES * DFPL-2427 POC controllers for FPL API gateway (#5481) * add dummy controller for API gateway POC * update CafcassCasesController for POC * update CafcassCasesController for POC * Update CafcassCasesController.java * Update CafcassCasesControllerTest.java * Update CafcassCasesController.java * add all endpoint for POC * remove unused import * Update CafcassCasesControllerTest.java * Update CafcassCasesController.java * Update CafcassCasesController.java * update CafcassCasesController * add interceptor for verifying user role * add other exception * add unit test * fix check style --------- Co-authored-by: Daniel Catchpole --- .../values.preview.template.yaml | 16 +---- .../cafcass/CafcassApiConfiguration.java | 21 +++++++ .../gov/hmcts/reform/fpl/enums/UserRole.java | 1 + .../api/AuthorizationException.java | 15 +++++ .../fpl/exceptions/api/BadInputException.java | 15 +++++ .../fpl/exceptions/api/NotFoundException.java | 15 +++++ .../interceptors/CafcassApiInterceptor.java | 35 +++++++++++ .../CafcassApiInterceptorTest.java | 62 +++++++++++++++++++ 8 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/AuthorizationException.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/BadInputException.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/NotFoundException.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java diff --git a/charts/fpl-case-service/values.preview.template.yaml b/charts/fpl-case-service/values.preview.template.yaml index 0ce1e923c5f..3e2526b6121 100644 --- a/charts/fpl-case-service/values.preview.template.yaml +++ b/charts/fpl-case-service/values.preview.template.yaml @@ -260,16 +260,6 @@ ccd: nameOverride: ${SERVICE_NAME}-es clusterName: "es" replicas: 1 - minimumMasterNodes: 1 - antiAffinity: "soft" - esJavaOpts: "-Xmx512m -Xms512m" - extraEnvs: - - name: discovery.type - value: single-node - - name: cluster.initial_master_nodes - value: "" - persistence: - enabled: false logstash: image: hmctspublic.azurecr.io/ccd/logstash @@ -285,13 +275,13 @@ ccd: port: 9200 configTpl: xpack.monitoring.enabled: "false" - db.url: jdbc:postgresql://${SERVICE_NAME}-postgresql:5432/data-store?ssl=disable&stringtype=unspecified + db.url: 'jdbc:postgresql://${SERVICE_NAME}-postgresql:5432/pr-${CHANGE_ID}-data-store?ssl=disable&stringtype=unspecified' db.user: hmcts db.pwd: hmcts es.data.nodes.url: http://${SERVICE_NAME}-es-master:9200 extraEnvs: - name: DATA_STORE_URL - value: jdbc:postgresql://family-public-law-preview.postgres.database.azure.com:5432/{{ .Values.global.databaseNamePrefix }}data-store?sslmode=require&stringtype=unspecified + value: 'jdbc:postgresql://family-public-law-preview.postgres.database.azure.com:5432/pr-${CHANGE_ID}-data-store?sslmode=require&stringtype=unspecified' - name: DATA_STORE_USER value: hmcts - name: DATA_STORE_PASS @@ -300,7 +290,7 @@ ccd: name: postgres key: PASSWORD - name: DB_URL - value: jdbc:postgresql://family-public-law-preview.postgres.database.azure.com:5432/{{ .Values.global.databaseNamePrefix }}data-store?sslmode=require&stringtype=unspecified + value: 'jdbc:postgresql://family-public-law-preview.postgres.database.azure.com:5432/pr-${CHANGE_ID}-data-store?sslmode=require&stringtype=unspecified' - name: DB_USER value: hmcts - name: DB_PWD diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java new file mode 100644 index 00000000000..3fcaa5892d3 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.reform.fpl.config.cafcass; + +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import uk.gov.hmcts.reform.fpl.interceptors.CafcassApiInterceptor; +import uk.gov.hmcts.reform.fpl.service.UserService; + +@Configuration +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassApiConfiguration implements WebMvcConfigurer { + private final CafcassApiInterceptor cafcassApiInterceptor; + + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(cafcassApiInterceptor).addPathPatterns("/cases"); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java index dcbcd5b72e5..4da3be2e3b7 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java @@ -8,6 +8,7 @@ public enum UserRole { LOCAL_AUTHORITY("caseworker-publiclaw-solicitor"), HMCTS_ADMIN("caseworker-publiclaw-courtadmin"), CAFCASS("caseworker-publiclaw-cafcass"), + CAFCASS_SYSTEM_UPDATE("caseworker-publiclaw-cafcasssystemupdate"), GATEKEEPER("caseworker-publiclaw-gatekeeper"), JUDICIARY("caseworker-publiclaw-judiciary"), HMCTS_SUPERUSER("caseworker-publiclaw-superuser"); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/AuthorizationException.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/AuthorizationException.java new file mode 100644 index 00000000000..b9e306545ca --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/AuthorizationException.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.exceptions.api; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.FORBIDDEN) +public class AuthorizationException extends RuntimeException { + public AuthorizationException() { + super("Auth error"); + } + + public AuthorizationException(String message) { + super(message); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/BadInputException.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/BadInputException.java new file mode 100644 index 00000000000..ca5aba80339 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/BadInputException.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.exceptions.api; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.BAD_REQUEST) +public class BadInputException extends RuntimeException { + public BadInputException() { + super("Bad input parameter"); + } + + public BadInputException(String message) { + super(message); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/NotFoundException.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/NotFoundException.java new file mode 100644 index 00000000000..97de571656b --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/exceptions/api/NotFoundException.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.exceptions.api; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.NOT_FOUND) +public class NotFoundException extends RuntimeException { + public NotFoundException() { + super("Not found"); + } + + public NotFoundException(String message) { + super(message); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java new file mode 100644 index 00000000000..4e4612f08f9 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java @@ -0,0 +1,35 @@ +package uk.gov.hmcts.reform.fpl.interceptors; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.HandlerInterceptor; +import uk.gov.hmcts.reform.fpl.exceptions.api.AuthorizationException; +import uk.gov.hmcts.reform.idam.client.IdamClient; +import uk.gov.hmcts.reform.idam.client.models.UserInfo; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; +import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; + +@Slf4j +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassApiInterceptor implements HandlerInterceptor { + private final IdamClient idamClient; + + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + String authToken = request.getHeader("Authorization"); + if (isNotEmpty(authToken)) { + UserInfo userInfo = idamClient.getUserInfo(authToken); + if (userInfo != null && userInfo.getRoles().contains(CAFCASS_SYSTEM_UPDATE.getRoleName())) { + return true; + } + } + throw new AuthorizationException(); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java new file mode 100644 index 00000000000..f36ad98f3c4 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java @@ -0,0 +1,62 @@ +package uk.gov.hmcts.reform.fpl.interceptors; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.fpl.exceptions.api.AuthorizationException; +import uk.gov.hmcts.reform.idam.client.IdamClient; +import uk.gov.hmcts.reform.idam.client.models.UserInfo; + +import java.util.List; +import javax.servlet.http.HttpServletRequest; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; +import static uk.gov.hmcts.reform.fpl.enums.UserRole.LOCAL_AUTHORITY; + +@ExtendWith(MockitoExtension.class) +public class CafcassApiInterceptorTest { + private final static String AUTH_TOKEN_TEST = "bearerToken"; + private final static UserInfo CAFCASS_SYSTEM_UPDATE_USER = + UserInfo.builder().roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName())).build(); + private final static UserInfo LOCAL_AUTHORITY_UPDATE_USER = + UserInfo.builder().roles(List.of(LOCAL_AUTHORITY.getRoleName())).build(); + + @Mock + private IdamClient idamClient; + @InjectMocks + private CafcassApiInterceptor underTest; + + @Test + public void shouldReturnTrueIfCafcassSystemUpdateUser() throws Exception { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getHeader("Authorization")).thenReturn(AUTH_TOKEN_TEST); + when(idamClient.getUserInfo(AUTH_TOKEN_TEST)).thenReturn(CAFCASS_SYSTEM_UPDATE_USER); + + assertTrue(underTest.preHandle(request, null, null)); + } + + @Test + public void shouldThrowAuthExceptionIfNotCafcassSystemUpdateUser() throws Exception { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getHeader("Authorization")).thenReturn(AUTH_TOKEN_TEST); + when(idamClient.getUserInfo(AUTH_TOKEN_TEST)).thenReturn(LOCAL_AUTHORITY_UPDATE_USER); + + assertThrows(AuthorizationException.class, + () -> underTest.preHandle(request, null, null)); + } + + @Test + public void shouldThrowAuthExceptionWhenNoAuthorizationToken() throws Exception { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getHeader("Authorization")).thenReturn(null); + + assertThrows(AuthorizationException.class, + () -> underTest.preHandle(request, null, null)); + } +} From dc38342605c174e5ca7c742ed39bbdd2765d97a8 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 9 Jul 2024 15:02:04 +0100 Subject: [PATCH 14/51] fix unit test --- .../cafcass/CafcassCasesControllerTest.java | 65 +++++++------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index ae877c3c3d9..3f68d249c0b 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.fpl.controllers.cafcass; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; @@ -10,17 +11,23 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; +import uk.gov.hmcts.reform.idam.client.models.UserInfo; +import java.util.List; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; @WebMvcTest(CafcassCasesController.class) @OverrideAutoConfiguration(enabled = true) public class CafcassCasesControllerTest extends AbstractTest { + private static final UserInfo CAFCASS_SYSTEM_UPDATE_USER_INFO = UserInfo.builder() + .roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName())) + .build(); private static final UUID CASE_ID = UUID.randomUUID(); private static final byte[] FILE_BYTES = "This is a file. Trust me!".getBytes(); private static final MockMultipartFile FILE = new MockMultipartFile( @@ -29,13 +36,16 @@ public class CafcassCasesControllerTest extends AbstractTest { @Autowired private MockMvc mockMvc; + @BeforeEach + void setUp() { + givenCurrentUser(CAFCASS_SYSTEM_UPDATE_USER_INFO); + } + @Test void searchCases() throws Exception { MvcResult response = mockMvc .perform(get("/cases") .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(",")) .queryParam("startDate", "2023-03-28T12:32:54.541") .queryParam("endDate", "2024-03-27T12:32:54.542")) .andExpect(status().is(200)) @@ -50,8 +60,6 @@ void searchCasesInvalidFormat400() throws Exception { MvcResult response = mockMvc .perform(get("/cases") .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(",")) .queryParam("startDate", "123") .queryParam("endDate", "321")) .andExpect(status().is(400)) @@ -63,7 +71,8 @@ void searchCasesInvalidFormat400() throws Exception { @Test void searchCasesEmptyParam400() throws Exception { MvcResult response = mockMvc - .perform(get("/cases")) + .perform(get("/cases") + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -72,8 +81,6 @@ void searchCasesEmptyParam400() throws Exception { response = mockMvc .perform(get("/cases") .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(",")) .queryParam("startDate", "2023-03-28T12:32:54.541")) .andExpect(status().is(400)) .andReturn(); @@ -83,8 +90,6 @@ void searchCasesEmptyParam400() throws Exception { response = mockMvc .perform(get("/cases") .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(",")) .queryParam("endDate", "2024-03-27T12:32:54.542")) .andExpect(status().is(400)) .andReturn(); @@ -97,8 +102,6 @@ void searchCases500() throws Exception { MvcResult response = mockMvc .perform(get("/cases") .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(",")) .queryParam("startDate", "2024-03-28T12:32:54.541") .queryParam("endDate", "2023-03-27T12:32:54.542")) .andExpect(status().is(500)) @@ -112,9 +115,7 @@ void getDocumentBinary() throws Exception { UUID docId = UUID.randomUUID(); MvcResult response = mockMvc .perform(get("/cases/documents/%s/binary".formatted(docId)) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(200)) .andReturn(); @@ -126,9 +127,7 @@ void getDocumentBinary() throws Exception { void getDocumentBinary400() throws Exception { MvcResult response = mockMvc .perform(get("/cases/documents/123/binary") - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -136,9 +135,7 @@ void getDocumentBinary400() throws Exception { response = mockMvc .perform(get("/cases/documents/ /binary") - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -152,9 +149,7 @@ void uploadDocument() throws Exception { .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(CASE_ID)) .file(FILE) .param("typeOfDocument", "type Of Document") - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(200)) .andReturn(); @@ -170,9 +165,7 @@ void uploadDocument400() throws Exception { MvcResult response = mockMvc .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) .param("typeOfDocument", "type Of Document") - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -186,9 +179,7 @@ void uploadDocument400() throws Exception { response = mockMvc .perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId)) .file(file) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -211,9 +202,7 @@ void uploadGuardians() throws Exception { + " }\n" + "]") .contentType(MediaType.APPLICATION_JSON) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(200)) .andReturn(); @@ -229,9 +218,7 @@ void uploadGuardians400() throws Exception { MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId)) .content("[]") .contentType(MediaType.APPLICATION_JSON) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -249,9 +236,7 @@ void uploadGuardians400() throws Exception { + " }\n" + "]") .contentType(MediaType.APPLICATION_JSON) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(400)) .andReturn(); @@ -272,9 +257,7 @@ void uploadGuardians500() throws Exception { + " }\n" + "]") .contentType(MediaType.APPLICATION_JSON) - .header("authorization", USER_AUTH_TOKEN) - .header("user-id", USER_ID) - .header("user-roles", String.join(","))) + .header("authorization", USER_AUTH_TOKEN)) .andExpect(status().is(500)) .andReturn(); From d22da945904ab0f353191ffccae7cf6d70a1f42a Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 9 Jul 2024 18:23:52 +0100 Subject: [PATCH 15/51] implement es search --- .../cafcass/CafcassCasesController.java | 41 ++++++++----------- .../fpl/model/api/cafcass/CafcassApiCase.java | 15 +++++++ .../model/api/cafcass/CafcassApiCaseData.java | 28 +++++++++++++ .../CafcassApiSearchCasesResponse.java | 12 ++++++ .../service/cafcass/CafcassApiService.java | 35 ++++++++++++++++ 5 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index ce54fad3020..cbbacd6dc91 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -12,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper; +import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; +import uk.gov.hmcts.reform.fpl.service.cafcass.CafcassApiService; -import java.time.DateTimeException; -import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.UUID; @@ -30,30 +31,22 @@ public class CafcassCasesController { private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-dd'T'hh:mm:ss.SSS"; private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; + private final CafcassApiService cafcassApiService; + @GetMapping("") - public ResponseEntity searchCases(@RequestParam(name = "startDate") String startDate, - @RequestParam(name = "endDate") String endDate) { - log.info("searchCases request received"); - try { - log.info("searchCases, " + startDate + ", " + endDate); - LocalDate startLocalDateTime = - DateFormatterHelper.parseLocalDateFromStringUsingFormat(startDate, DATE_TIME_FORMAT_IN); - LocalDate endLocalDateTime = - DateFormatterHelper.parseLocalDateFromStringUsingFormat(endDate, DATE_TIME_FORMAT_IN); - - if (startLocalDateTime.isAfter(endLocalDateTime)) { - throw new Exception("startDate after endDate"); - } + public ResponseEntity searchCases( + @RequestParam(name = "startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate, + @RequestParam(name = "endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate) { + log.info("searchCases, " + startDate + ", " + endDate); - return ResponseEntity.ok(String.format("searchCases - Start date: [%s], End date: [%s]", - DateFormatterHelper.formatLocalDateToString(startLocalDateTime, DATE_TIME_FORMAT_OUT), - DateFormatterHelper.formatLocalDateToString(endLocalDateTime, DATE_TIME_FORMAT_OUT) - )); - } catch (DateTimeException e) { - return ResponseEntity.status(400).body("bad input parameter - " + e.getMessage()); - } catch (Exception e) { - return ResponseEntity.status(500).body("Internal server error - " + e.getMessage()); + // TODO a generice work flow for validation? + // TODO should put the 15 mins range to configuration instead? + if (startDate.isAfter(endDate) || startDate.plusMinutes(15).isBefore(endDate)) { + throw new BadInputException(); } + + // TODO return CafcassApiSearchCasesResponse + return ResponseEntity.ok(cafcassApiService.searchCaseByDateRange(startDate, endDate)); } @GetMapping("documents/{documentId}/binary") diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java new file mode 100644 index 00000000000..0bb1e43b50c --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; + +@Builder +public class CafcassApiCase { + private String caseId; + private String jurisdiction; + private String state; + private String caseTypeId; + private String createdDate; + private String lastModified; + private String lastStateModifiedDate; + private CafcassApiCaseData caseData; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java new file mode 100644 index 00000000000..a9be8285410 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java @@ -0,0 +1,28 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; + +import java.util.List; + +@Builder +public class CafcassApiCaseData { + private String familyManCaseNumber; + private String dateSubmitted; + private String applicationType; + private List ordersSought; + private String dateOfCourtIssue; + private boolean citizenIsApplicant; + private String applicantLA; + private String respondentLA; + private List applicants; + private List children; + private List respondents; + private List others; + private Object internationalElement; + private List previousProceedings; + private List hearingDetails; + private List caseDocuments; + private Object risks; + private Object factorsParenting; + private Object caseManagementLocation; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java new file mode 100644 index 00000000000..093e24f88ef --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java @@ -0,0 +1,12 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import uk.gov.hmcts.reform.fpl.model.Child; + +import java.util.List; + +@Builder +public class CafcassApiSearchCasesResponse { + private int total; + private List cases; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java new file mode 100644 index 00000000000..4bb6918ff89 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java @@ -0,0 +1,35 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.fpl.enums.State; +import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSearchCasesResponse; +import uk.gov.hmcts.reform.fpl.service.search.SearchService; +import uk.gov.hmcts.reform.fpl.utils.elasticsearch.MatchQuery; +import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassApiService { + private final SearchService searchService; + + public List searchCaseByDateRange(LocalDateTime startDate, LocalDateTime endDate) { + + final RangeQuery searchRange = RangeQuery.builder() + .field("last_modified") + .greaterThanOrEqual(startDate) + .lessThanOrEqual(endDate).build(); + + return searchService.search(searchRange, 10000 , 0); + } +} From b252e5fa6983a443e4360e183aa393f18af74fa1 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 15 Jul 2024 17:36:26 +0100 Subject: [PATCH 16/51] search case response object --- .../cafcass/CafcassCasesController.java | 16 +- .../model/api/cafcass/CafcassApiAddress.java | 16 ++ .../api/cafcass/CafcassApiApplicant.java | 18 ++ .../fpl/model/api/cafcass/CafcassApiCase.java | 10 +- .../model/api/cafcass/CafcassApiCaseData.java | 15 +- .../api/cafcass/CafcassApiColleague.java | 16 ++ .../api/cafcass/CafcassApiRespondent.java | 27 +++ .../CafcassApiSearchCasesResponse.java | 3 +- .../api/cafcass/CafcassApiSolicitor.java | 14 ++ .../cafcass/CafcassApiCaseService.java | 175 ++++++++++++++++++ .../service/cafcass/CafcassApiService.java | 35 ---- .../CafcassApiApplicantConverter.java | 55 ++++++ .../CafcassApiCaseDataConverter.java | 9 + 13 files changed, 360 insertions(+), 49 deletions(-) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java delete mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index cbbacd6dc91..ee74340edf2 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -14,7 +14,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; -import uk.gov.hmcts.reform.fpl.service.cafcass.CafcassApiService; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSearchCasesResponse; +import uk.gov.hmcts.reform.fpl.service.cafcass.CafcassApiCaseService; import java.time.LocalDateTime; import java.util.List; @@ -31,10 +33,10 @@ public class CafcassCasesController { private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-dd'T'hh:mm:ss.SSS"; private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; - private final CafcassApiService cafcassApiService; + private final CafcassApiCaseService cafcassApiCaseService; @GetMapping("") - public ResponseEntity searchCases( + public CafcassApiSearchCasesResponse searchCases( @RequestParam(name = "startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate, @RequestParam(name = "endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate) { log.info("searchCases, " + startDate + ", " + endDate); @@ -45,8 +47,12 @@ public ResponseEntity searchCases( throw new BadInputException(); } - // TODO return CafcassApiSearchCasesResponse - return ResponseEntity.ok(cafcassApiService.searchCaseByDateRange(startDate, endDate)); + List caseDetails = cafcassApiCaseService.searchCaseByDateRange(startDate, endDate); + + return CafcassApiSearchCasesResponse.builder() + .total(caseDetails.size()) + .cases(caseDetails) + .build(); } @GetMapping("documents/{documentId}/binary") diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java new file mode 100644 index 00000000000..ea310a16b03 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java @@ -0,0 +1,16 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiAddress { + private final String addressLine1; + private final String addressLine2; + private final String addressLine3; + private final String postTown; + private final String county; + private final String postcode; + private final String country; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java new file mode 100644 index 00000000000..9b72f908a59 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java @@ -0,0 +1,18 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class CafcassApiApplicant { + private String id; + private String name; + private String email; + private String phone; + private CafcassApiAddress address; + private List colleagues; + private boolean designated; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java index 0bb1e43b50c..0afe893a0ba 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java @@ -1,15 +1,19 @@ package uk.gov.hmcts.reform.fpl.model.api.cafcass; import lombok.Builder; +import lombok.Getter; +import java.time.LocalDateTime; + +@Getter @Builder public class CafcassApiCase { - private String caseId; + private Long caseId; private String jurisdiction; private String state; private String caseTypeId; - private String createdDate; - private String lastModified; + private LocalDateTime createdDate; + private LocalDateTime lastModified; private String lastStateModifiedDate; private CafcassApiCaseData caseData; } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java index a9be8285410..06bc2e29015 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java @@ -1,20 +1,25 @@ package uk.gov.hmcts.reform.fpl.model.api.cafcass; import lombok.Builder; +import lombok.Getter; +import uk.gov.hmcts.reform.ccd.model.CaseLocation; +import uk.gov.hmcts.reform.fpl.enums.OrderType; +import java.time.LocalDate; import java.util.List; +@Getter @Builder public class CafcassApiCaseData { private String familyManCaseNumber; - private String dateSubmitted; + private LocalDate dateSubmitted; private String applicationType; - private List ordersSought; - private String dateOfCourtIssue; + private List ordersSought; + private LocalDate dateOfCourtIssue; private boolean citizenIsApplicant; private String applicantLA; private String respondentLA; - private List applicants; + private List applicants; private List children; private List respondents; private List others; @@ -24,5 +29,5 @@ public class CafcassApiCaseData { private List caseDocuments; private Object risks; private Object factorsParenting; - private Object caseManagementLocation; + private CaseLocation caseManagementLocation; } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java new file mode 100644 index 00000000000..cba9bfa5be6 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java @@ -0,0 +1,16 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiColleague { + private String role; + private String title; + private String email; + private String phone; + private String fullName; + private boolean mainContact; + private boolean notificationRecipient; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java new file mode 100644 index 00000000000..fc07c28ddb2 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.List; + +@Getter +@Builder +public class CafcassApiRespondent { + private String firstName; + private String lastName; + private String gender; + private String genderIdentification; + private boolean addressKnown; + private String addressUnknownReason; + private CafcassApiAddress address; + private LocalDate dateOfBirth; + private String telephoneNumber; + private String litigationIssues; + private String litigationIssuesDetails; + private String contactDetailsHidden; + private String contactDetailsHiddenReason; + private String relationshipToChild; + private CafcassApiSolicitor solicitor; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java index 093e24f88ef..839d0394694 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java @@ -1,10 +1,11 @@ package uk.gov.hmcts.reform.fpl.model.api.cafcass; import lombok.Builder; -import uk.gov.hmcts.reform.fpl.model.Child; +import lombok.Getter; import java.util.List; +@Getter @Builder public class CafcassApiSearchCasesResponse { private int total; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java new file mode 100644 index 00000000000..c120d7396cc --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java @@ -0,0 +1,14 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiSolicitor { + private String email; + private String firstName; + private String lastName; + private String organisationId; + private String organisationName; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java new file mode 100644 index 00000000000..3f1934ea53f --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java @@ -0,0 +1,175 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.Address; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.RespondentParty; +import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiAddress; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRespondent; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.cafcass.CafcassData; +import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.common.Telephone; +import uk.gov.hmcts.reform.fpl.service.CaseConverter; +import uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders.CafcassApiCaseDataConverter; +import uk.gov.hmcts.reform.fpl.service.search.SearchService; +import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; + +import static org.apache.commons.lang3.ObjectUtils.isEmpty; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; +import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; +import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; + +@Slf4j +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassApiCaseService { + private final CaseConverter caseConverter; + private final SearchService searchService; + + public List searchCaseByDateRange(LocalDateTime startDate, LocalDateTime endDate) { + + final RangeQuery searchRange = RangeQuery.builder() + .field("last_modified") + .greaterThanOrEqual(startDate) + .lessThanOrEqual(endDate).build(); + + List caseDetails = searchService.search(searchRange, 10000 , 0); + + return caseDetails.stream() + .map(this::convertToCafcassApiCase) + .toList(); + } + + private CafcassApiCase convertToCafcassApiCase(CaseDetails caseDetails) { + return CafcassApiCase.builder() + .caseId(caseDetails.getId()) + .jurisdiction(caseDetails.getJurisdiction()) + .state(caseDetails.getState()) + .caseTypeId(caseDetails.getCaseTypeId()) + .createdDate(caseDetails.getCreatedDate()) + .lastModified(caseDetails.getLastModified()) + .caseData(getCafcassApiCaseData(caseConverter.convert(caseDetails))) + .build(); + } + + private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { + return CafcassApiCaseData.builder() + .familyManCaseNumber(caseData.getFamilyManCaseNumber()) + .dateSubmitted(caseData.getDateSubmitted()) + .applicationType(caseData.isC1Application() ? "C1" : "C110A") + .ordersSought(caseData.getOrders().getOrderType()) + .dateOfCourtIssue(caseData.getDateOfIssue()) + .caseManagementLocation(caseData.getCaseManagementLocation()) + .citizenIsApplicant(NO.equals(caseData.getIsLocalAuthority())) + .applicantLA(caseData.getCaseLocalAuthority()) + .respondentLA(caseData.getRelatingLA()) + .applicants(getCafcassApiApplicant(caseData)) + .respondents(getCafcassApiRespondents(caseData)) + .build(); + } + + private List getCafcassApiApplicant(CaseData caseData) { + return caseData.getLocalAuthorities().stream() + .map(applicantElement -> { + LocalAuthority applicant = applicantElement.getValue(); + + return CafcassApiApplicant.builder() + .id(applicantElement.getId().toString()) + .name(applicant.getName()) + .email(applicant.getEmail()) + .phone(applicant.getPhone()) + .address(getCafcassApiAddress(applicant.getAddress())) + .designated(YES.equals(YesNo.valueOf(applicant.getDesignated()))) + .colleagues(applicant.getColleagues().stream() + .map(Element::getValue) + .map(colleague -> CafcassApiColleague.builder() + .role(colleague.getRole().toString()) + .title(colleague.getTitle()) + .email(colleague.getEmail()) + .phone(colleague.getPhone()) + .fullName(colleague.getFullName()) + .mainContact(YES.equals(YesNo.valueOf(colleague.getMainContact()))) + .notificationRecipient(YES.equals(YesNo.valueOf(colleague.getNotificationRecipient()))) + .build()) + .toList()) + .build(); + }) + .toList(); + } + + private CafcassApiAddress getCafcassApiAddress(Address address) { + return Optional.ofNullable(address) + .map(add -> CafcassApiAddress.builder() + .addressLine1(add.getAddressLine1()) + .addressLine2(add.getAddressLine2()) + .addressLine3(add.getAddressLine3()) + .postTown(add.getPostTown()) + .county(add.getCounty()) + .postcode(add.getPostcode()) + .country(add.getCountry()) + .build()) + .orElse(null); + } + + private List getCafcassApiRespondents(CaseData caseData) { + return caseData.getRespondents1().stream() + .map(Element::getValue) + .map(respondent -> { + RespondentParty respondentParty = respondent.getParty(); + return CafcassApiRespondent.builder() + .firstName(respondentParty.getFirstName()) + .lastName(respondentParty.getLastName()) + .gender(respondentParty.getGender()) + .addressKnown(YES.equals(YesNo.valueOf(respondentParty.getAddressKnow()))) + .addressUnknownReason(respondentParty.getAddressNotKnowReason()) + .address(getCafcassApiAddress(respondentParty.getAddress())) + .dateOfBirth(respondentParty.getDateOfBirth()) + .telephoneNumber(getTelephoneNumber(respondentParty.getTelephoneNumber())) + .litigationIssues(respondentParty.getLitigationIssues()) + .litigationIssuesDetails(respondentParty.getLitigationIssuesDetails()) + .contactDetailsHidden(respondentParty.getContactDetailsHidden()) + .contactDetailsHiddenReason(respondentParty.getContactDetailsHiddenReason()) + .relationshipToChild(respondentParty.getRelationshipToChild()) + .solicitor(getCafcassApiSolicitor(respondent.getSolicitor())) + .build(); + }) + .toList(); + } + + private String getTelephoneNumber(Telephone telephone) { + return Optional.ofNullable(telephone) + .map(Telephone::getTelephoneNumber) + .orElse(null); + } + + private CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { + + CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder() + .email(respondentSolicitor.getEmail()) + .firstName(respondentSolicitor.getFirstName()) + .lastName(respondentSolicitor.getLastName()); + + if (respondentSolicitor.getOrganisation() != null) { + builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); + builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); + } + + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java deleted file mode 100644 index 4bb6918ff89..00000000000 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiService.java +++ /dev/null @@ -1,35 +0,0 @@ -package uk.gov.hmcts.reform.fpl.service.cafcass; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; -import uk.gov.hmcts.reform.fpl.enums.State; -import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSearchCasesResponse; -import uk.gov.hmcts.reform.fpl.service.search.SearchService; -import uk.gov.hmcts.reform.fpl.utils.elasticsearch.MatchQuery; -import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.List; - -@Slf4j -@Service -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) -public class CafcassApiService { - private final SearchService searchService; - - public List searchCaseByDateRange(LocalDateTime startDate, LocalDateTime endDate) { - - final RangeQuery searchRange = RangeQuery.builder() - .field("last_modified") - .greaterThanOrEqual(startDate) - .lessThanOrEqual(endDate).build(); - - return searchService.search(searchRange, 10000 , 0); - } -} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java new file mode 100644 index 00000000000..5e2fbe08921 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java @@ -0,0 +1,55 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; + +@Component +public class CafcassApiApplicantConverter implements CafcassApiCaseDataConverter{ + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.applicants(getCafcassApiApplicant(caseData)); + } + + private List getCafcassApiApplicant(CaseData caseData) { + return caseData.getLocalAuthorities().stream() + .map(applicantElement -> { + LocalAuthority applicant = applicantElement.getValue(); + + return CafcassApiApplicant.builder() + .id(applicantElement.getId().toString()) + .name(applicant.getName()) + .email(applicant.getEmail()) + .phone(applicant.getPhone()) + .address(applicant.getAddress()) + .designated(YES.equals(YesNo.valueOf(applicant.getDesignated()))) + .colleagues(getColleagues(applicant)) + .build(); + }) + .toList(); + } + + private List getColleagues(LocalAuthority applicant) { + return applicant.getColleagues().stream() + .map(Element::getValue) + .map(colleague -> CafcassApiColleague.builder() + .role(colleague.getRole().toString()) + .title(colleague.getTitle()) + .email(colleague.getEmail()) + .phone(colleague.getPhone()) + .fullName(colleague.getFullName()) + .mainContact(YES.equals(YesNo.valueOf(colleague.getMainContact()))) + .notificationRecipient(YES.equals(YesNo.valueOf(colleague.getNotificationRecipient()))) + .build()) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java new file mode 100644 index 00000000000..bf86db493b4 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java @@ -0,0 +1,9 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders; + +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; + +public interface CafcassApiCaseDataConverter { + CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder); +} From b1e7629788990c8813763cf1843966d1e20202c9 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 15 Jul 2024 18:28:06 +0100 Subject: [PATCH 17/51] response field child and other --- .../model/api/cafcass/CafcassApiCaseData.java | 8 +- .../model/api/cafcass/CafcassApiChild.java | 29 ++++++ .../model/api/cafcass/CafcassApiOther.java | 22 +++++ .../api/cafcass/CafcassApiRespondent.java | 1 - .../cafcass/CafcassApiCaseService.java | 92 +++++++++++++++---- 5 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java index 06bc2e29015..abbd73efd85 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java @@ -20,9 +20,11 @@ public class CafcassApiCaseData { private String applicantLA; private String respondentLA; private List applicants; - private List children; - private List respondents; - private List others; + private List respondents; + private List children; + private List others; + + // TODO following field private Object internationalElement; private List previousProceedings; private List hearingDetails; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java new file mode 100644 index 00000000000..a887b9101df --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java @@ -0,0 +1,29 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@Builder +public class CafcassApiChild { + private String firstName; + private String lastName; + private LocalDate dateOfBirth; + private String gender; + private String genderIdentification; + private String livingSituation; + private String livingSituationDetails; + private CafcassApiAddress address; + private String careAndContactPlan; + private boolean detailsHidden; + private String socialWorkerName; + private String socialWorkerTelephoneNumber; + private boolean additionalNeeds; + private String additionalNeedsDetails; + private String litigationIssues; + private String litigationIssuesDetails; + private CafcassApiSolicitor solicitor; + private String fathersResponsibility; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java new file mode 100644 index 00000000000..75cab492d11 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java @@ -0,0 +1,22 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiOther { + private String name; + private String dateOfBirth; + private String gender; + private String genderIdentification; + private String birthPlace; + private boolean addressKnown; + private String addressUnknownReason; + private CafcassApiAddress address; + private String telephone; + private String litigationIssues; + private String litigationIssuesDetails; + private boolean detailsHidden; + private String detailsHiddenReason; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java index fc07c28ddb2..68fb029e291 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java @@ -4,7 +4,6 @@ import lombok.Getter; import java.time.LocalDate; -import java.util.List; @Getter @Builder diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java index 3f1934ea53f..d6fa80dafbc 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java @@ -8,6 +8,7 @@ import uk.gov.hmcts.reform.fpl.enums.YesNo; import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.ChildParty; import uk.gov.hmcts.reform.fpl.model.LocalAuthority; import uk.gov.hmcts.reform.fpl.model.RespondentParty; import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; @@ -15,25 +16,27 @@ import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiChild; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiOther; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRespondent; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSolicitor; -import uk.gov.hmcts.reform.fpl.model.cafcass.CafcassData; import uk.gov.hmcts.reform.fpl.model.common.Element; import uk.gov.hmcts.reform.fpl.model.common.Telephone; import uk.gov.hmcts.reform.fpl.service.CaseConverter; -import uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders.CafcassApiCaseDataConverter; import uk.gov.hmcts.reform.fpl.service.search.SearchService; import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; import java.time.LocalDateTime; import java.util.List; +import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; -import static org.apache.commons.lang3.ObjectUtils.isEmpty; -import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; +import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Slf4j @Service @@ -81,11 +84,13 @@ private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { .respondentLA(caseData.getRelatingLA()) .applicants(getCafcassApiApplicant(caseData)) .respondents(getCafcassApiRespondents(caseData)) + .children(getCafcassApiChild(caseData)) + .others(getCafcassApiOthers(caseData)) .build(); } private List getCafcassApiApplicant(CaseData caseData) { - return caseData.getLocalAuthorities().stream() + return Optional.ofNullable(caseData.getLocalAuthorities()).orElse(List.of()).stream() .map(applicantElement -> { LocalAuthority applicant = applicantElement.getValue(); @@ -95,7 +100,7 @@ private List getCafcassApiApplicant(CaseData caseData) { .email(applicant.getEmail()) .phone(applicant.getPhone()) .address(getCafcassApiAddress(applicant.getAddress())) - .designated(YES.equals(YesNo.valueOf(applicant.getDesignated()))) + .designated(equalsIgnoreCase(applicant.getDesignated(), YES.getValue())) .colleagues(applicant.getColleagues().stream() .map(Element::getValue) .map(colleague -> CafcassApiColleague.builder() @@ -128,7 +133,7 @@ private CafcassApiAddress getCafcassApiAddress(Address address) { } private List getCafcassApiRespondents(CaseData caseData) { - return caseData.getRespondents1().stream() + return Optional.ofNullable(caseData.getRespondents1()).orElse(List.of()).stream() .map(Element::getValue) .map(respondent -> { RespondentParty respondentParty = respondent.getParty(); @@ -159,17 +164,72 @@ private String getTelephoneNumber(Telephone telephone) { } private CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { - - CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder() - .email(respondentSolicitor.getEmail()) - .firstName(respondentSolicitor.getFirstName()) - .lastName(respondentSolicitor.getLastName()); - - if (respondentSolicitor.getOrganisation() != null) { - builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); - builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); + CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder(); + if (respondentSolicitor != null) { + builder = builder.email(respondentSolicitor.getEmail()); + builder = builder.firstName(respondentSolicitor.getFirstName()); + builder = builder.lastName(respondentSolicitor.getLastName()); + + if (respondentSolicitor.getOrganisation() != null) { + builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); + builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); + } } return builder.build(); } + + private List getCafcassApiChild(CaseData caseData) { + return Optional.ofNullable(caseData.getChildren1()).orElse(List.of()).stream() + .map(Element::getValue) + .map(child -> { + ChildParty childParty = child.getParty(); + return CafcassApiChild.builder() + .firstName(childParty.getFirstName()) + .lastName(childParty.getLastName()) + .dateOfBirth(childParty.getDateOfBirth()) + .gender(childParty.getGender().toString()) + .genderIdentification(childParty.getGenderIdentification()) + .livingSituation(childParty.getLivingSituation()) + .livingSituationDetails(childParty.getLivingSituationDetails()) + .address(getCafcassApiAddress(childParty.getAddress())) + .careAndContactPlan(childParty.getCareAndContactPlan()) + .detailsHidden(equalsIgnoreCase(childParty.getDetailsHidden(), YES.getValue())) + .socialWorkerName(childParty.getSocialWorkerName()) + .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) + .additionalNeeds(equalsIgnoreCase(childParty.getAdditionalNeeds(), YES.getValue())) + .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) + .litigationIssues(childParty.getLitigationIssues()) + .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) + .solicitor(getCafcassApiSolicitor(child.getSolicitor())) + .fathersResponsibility(childParty.getFathersResponsibility()) + .build(); + }) + .toList(); + } + + private List getCafcassApiOthers(CaseData caseData) { + return Optional.ofNullable(caseData.getOthers()) + .map(others -> Stream.concat(Optional.ofNullable(others.getFirstOther()).stream(), + unwrapElements(others.getAdditionalOthers()).stream()) + .filter(Objects::nonNull) + .map(other -> CafcassApiOther.builder() + .name(other.getName()) + .dateOfBirth(other.getDateOfBirth()) + .gender(other.getGender()) + .genderIdentification(other.getGenderIdentification()) + .birthPlace(other.getBirthPlace()) + .addressKnown(equalsIgnoreCase(other.getAddressKnow(), YES.getValue())) + .addressUnknownReason(other.getAddressNotKnowReason()) + .address(getCafcassApiAddress(other.getAddress())) + .telephone(other.getTelephone()) + .litigationIssues(other.getLitigationIssues()) + .litigationIssuesDetails(other.getLitigationIssuesDetails()) + .detailsHidden(equalsIgnoreCase(other.getDetailsHidden(), YES.getValue())) + .detailsHiddenReason(other.getDetailsHiddenReason()) + .build()) + .toList() + ) + .orElse(List.of()); + } } From 35c88ec8a5d99e848a80082efa9edeccaf5f79db Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 16 Jul 2024 13:01:47 +0100 Subject: [PATCH 18/51] remove converters chain --- .../CafcassApiApplicantConverter.java | 55 ------------------- .../CafcassApiCaseDataConverter.java | 9 --- 2 files changed, 64 deletions(-) delete mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java delete mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java deleted file mode 100644 index 5e2fbe08921..00000000000 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiApplicantConverter.java +++ /dev/null @@ -1,55 +0,0 @@ -package uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders; - -import org.springframework.stereotype.Component; -import uk.gov.hmcts.reform.fpl.enums.YesNo; -import uk.gov.hmcts.reform.fpl.model.CaseData; -import uk.gov.hmcts.reform.fpl.model.LocalAuthority; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; -import uk.gov.hmcts.reform.fpl.model.common.Element; - -import java.util.List; - -import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; - -@Component -public class CafcassApiApplicantConverter implements CafcassApiCaseDataConverter{ - @Override - public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { - return builder.applicants(getCafcassApiApplicant(caseData)); - } - - private List getCafcassApiApplicant(CaseData caseData) { - return caseData.getLocalAuthorities().stream() - .map(applicantElement -> { - LocalAuthority applicant = applicantElement.getValue(); - - return CafcassApiApplicant.builder() - .id(applicantElement.getId().toString()) - .name(applicant.getName()) - .email(applicant.getEmail()) - .phone(applicant.getPhone()) - .address(applicant.getAddress()) - .designated(YES.equals(YesNo.valueOf(applicant.getDesignated()))) - .colleagues(getColleagues(applicant)) - .build(); - }) - .toList(); - } - - private List getColleagues(LocalAuthority applicant) { - return applicant.getColleagues().stream() - .map(Element::getValue) - .map(colleague -> CafcassApiColleague.builder() - .role(colleague.getRole().toString()) - .title(colleague.getTitle()) - .email(colleague.getEmail()) - .phone(colleague.getPhone()) - .fullName(colleague.getFullName()) - .mainContact(YES.equals(YesNo.valueOf(colleague.getMainContact()))) - .notificationRecipient(YES.equals(YesNo.valueOf(colleague.getNotificationRecipient()))) - .build()) - .toList(); - } -} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java deleted file mode 100644 index bf86db493b4..00000000000 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/apibuilders/CafcassApiCaseDataConverter.java +++ /dev/null @@ -1,9 +0,0 @@ -package uk.gov.hmcts.reform.fpl.service.cafcass.apibuilders; - -import uk.gov.hmcts.reform.fpl.model.CaseData; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; - -public interface CafcassApiCaseDataConverter { - CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, - CafcassApiCaseData.CafcassApiCaseDataBuilder builder); -} From 4d0765f3a0bde2cff7b15d6e20f3987116f85c2d Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 16 Jul 2024 17:59:30 +0100 Subject: [PATCH 19/51] other application details --- .../model/api/cafcass/CafcassApiCaseData.java | 12 +- .../CafcassApiCaseManagementLocation.java | 11 ++ .../cafcass/CafcassApiFactorsParenting.java | 15 ++ .../model/api/cafcass/CafcassApiHearing.java | 26 ++++ .../CafcassApiInternationalElement.java | 19 +++ .../api/cafcass/CafcassApiProceeding.java | 19 +++ .../fpl/model/api/cafcass/CafcassApiRisk.java | 15 ++ .../cafcass/CafcassApiCaseService.java | 141 ++++++++++++++++-- 8 files changed, 243 insertions(+), 15 deletions(-) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java index abbd73efd85..17e1d3c9e19 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java @@ -23,13 +23,13 @@ public class CafcassApiCaseData { private List respondents; private List children; private List others; + private List hearingDetails; + private CafcassApiInternationalElement internationalElement; + private List previousProceedings; + private CafcassApiRisk risks; + private CafcassApiFactorsParenting factorsParenting; + private CafcassApiCaseManagementLocation caseManagementLocation; // TODO following field - private Object internationalElement; - private List previousProceedings; - private List hearingDetails; private List caseDocuments; - private Object risks; - private Object factorsParenting; - private CaseLocation caseManagementLocation; } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java new file mode 100644 index 00000000000..aea4dbac298 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiCaseManagementLocation { + private String region; + private String baseLocation; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java new file mode 100644 index 00000000000..0191e778d8b --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiFactorsParenting { + private boolean alcoholDrugAbuse; + private String alcoholDrugAbuseReason; + private boolean domesticViolence; + private String domesticViolenceReason; + private boolean anythingElse; + private String anythingElseReason; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java new file mode 100644 index 00000000000..c2cb259d8ba --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java @@ -0,0 +1,26 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; +import uk.gov.hmcts.reform.fpl.enums.HearingStatus; +import uk.gov.hmcts.reform.fpl.enums.HearingType; +import uk.gov.hmcts.reform.fpl.enums.hearing.HearingAttendance; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@Builder +public class CafcassApiHearing { + private String id; + private HearingType type; + private String typeDetails; + private String venue; + private HearingStatus status; + private LocalDateTime startDate; + private LocalDateTime endDate; + private List attendance; + private String cancellationReason; + private String preAttendanceDetails; + private String attendanceDetails; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java new file mode 100644 index 00000000000..0607fc3980b --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiInternationalElement { + private boolean possibleCarer; + private String possibleCarerReason; + private boolean significantEvents; + private String significantEventsReason; + private boolean issues; + private String issuesReason; + private boolean proceedings; + private String proceedingsReason; + private boolean internationalAuthorityInvolvement; + private String internationalAuthorityInvolvementDetails; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java new file mode 100644 index 00000000000..817ac3ff508 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiProceeding { + private String proceedingStatus; + private String caseNumber; + private String started; + private String ended; + private String ordersMade; + private String judge; + private String children; + private String guardian; + private boolean sameGuardianNeeded; + private String sameGuardianDetails; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java new file mode 100644 index 00000000000..567e9c0d561 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java @@ -0,0 +1,15 @@ +package uk.gov.hmcts.reform.fpl.model.api.cafcass; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class CafcassApiRisk { + private List neglectOccurrences; + private List sexualAbuseOccurrences; + private List physicalHarmOccurrences; + private List emotionalHarmOccurrences; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java index d6fa80dafbc..3c73bf2f344 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java @@ -3,23 +3,36 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.ccd.model.CaseLocation; import uk.gov.hmcts.reform.fpl.enums.YesNo; import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.ChildParty; +import uk.gov.hmcts.reform.fpl.model.FactorsParenting; +import uk.gov.hmcts.reform.fpl.model.HearingBooking; +import uk.gov.hmcts.reform.fpl.model.InternationalElement; import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.Proceeding; import uk.gov.hmcts.reform.fpl.model.RespondentParty; import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.Risks; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiAddress; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseManagementLocation; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiChild; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiFactorsParenting; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiHearing; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiInternationalElement; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiOther; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiProceeding; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRespondent; +import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRisk; import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSolicitor; import uk.gov.hmcts.reform.fpl.model.common.Element; import uk.gov.hmcts.reform.fpl.model.common.Telephone; @@ -78,7 +91,6 @@ private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { .applicationType(caseData.isC1Application() ? "C1" : "C110A") .ordersSought(caseData.getOrders().getOrderType()) .dateOfCourtIssue(caseData.getDateOfIssue()) - .caseManagementLocation(caseData.getCaseManagementLocation()) .citizenIsApplicant(NO.equals(caseData.getIsLocalAuthority())) .applicantLA(caseData.getCaseLocalAuthority()) .respondentLA(caseData.getRelatingLA()) @@ -86,6 +98,12 @@ private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { .respondents(getCafcassApiRespondents(caseData)) .children(getCafcassApiChild(caseData)) .others(getCafcassApiOthers(caseData)) + .hearingDetails(getCafcassApiHearing(caseData)) + .internationalElement(getCafcassApiInternationalElement(caseData)) + .previousProceedings(getCafcassApiProceeding(caseData)) + .risks(getCafcassApiRisk(caseData)) + .factorsParenting(getCafcassApiFactorsParenting(caseData)) + .caseManagementLocation(getCafcassApiCaseManagementLocation(caseData)) .build(); } @@ -100,7 +118,7 @@ private List getCafcassApiApplicant(CaseData caseData) { .email(applicant.getEmail()) .phone(applicant.getPhone()) .address(getCafcassApiAddress(applicant.getAddress())) - .designated(equalsIgnoreCase(applicant.getDesignated(), YES.getValue())) + .designated(isYes(applicant.getDesignated())) .colleagues(applicant.getColleagues().stream() .map(Element::getValue) .map(colleague -> CafcassApiColleague.builder() @@ -109,8 +127,8 @@ private List getCafcassApiApplicant(CaseData caseData) { .email(colleague.getEmail()) .phone(colleague.getPhone()) .fullName(colleague.getFullName()) - .mainContact(YES.equals(YesNo.valueOf(colleague.getMainContact()))) - .notificationRecipient(YES.equals(YesNo.valueOf(colleague.getNotificationRecipient()))) + .mainContact(isYes(colleague.getMainContact())) + .notificationRecipient(isYes(colleague.getNotificationRecipient())) .build()) .toList()) .build(); @@ -118,6 +136,10 @@ private List getCafcassApiApplicant(CaseData caseData) { .toList(); } + private boolean isYes(String yesNo) { + return YES.getValue().equalsIgnoreCase(yesNo); + } + private CafcassApiAddress getCafcassApiAddress(Address address) { return Optional.ofNullable(address) .map(add -> CafcassApiAddress.builder() @@ -141,7 +163,7 @@ private List getCafcassApiRespondents(CaseData caseData) { .firstName(respondentParty.getFirstName()) .lastName(respondentParty.getLastName()) .gender(respondentParty.getGender()) - .addressKnown(YES.equals(YesNo.valueOf(respondentParty.getAddressKnow()))) + .addressKnown(isYes(respondentParty.getAddressKnow())) .addressUnknownReason(respondentParty.getAddressNotKnowReason()) .address(getCafcassApiAddress(respondentParty.getAddress())) .dateOfBirth(respondentParty.getDateOfBirth()) @@ -194,10 +216,10 @@ private List getCafcassApiChild(CaseData caseData) { .livingSituationDetails(childParty.getLivingSituationDetails()) .address(getCafcassApiAddress(childParty.getAddress())) .careAndContactPlan(childParty.getCareAndContactPlan()) - .detailsHidden(equalsIgnoreCase(childParty.getDetailsHidden(), YES.getValue())) + .detailsHidden(isYes(childParty.getDetailsHidden())) .socialWorkerName(childParty.getSocialWorkerName()) .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) - .additionalNeeds(equalsIgnoreCase(childParty.getAdditionalNeeds(), YES.getValue())) + .additionalNeeds(isYes(childParty.getAdditionalNeeds())) .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) .litigationIssues(childParty.getLitigationIssues()) .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) @@ -219,17 +241,118 @@ private List getCafcassApiOthers(CaseData caseData) { .gender(other.getGender()) .genderIdentification(other.getGenderIdentification()) .birthPlace(other.getBirthPlace()) - .addressKnown(equalsIgnoreCase(other.getAddressKnow(), YES.getValue())) + .addressKnown(isYes(other.getAddressKnow())) .addressUnknownReason(other.getAddressNotKnowReason()) .address(getCafcassApiAddress(other.getAddress())) .telephone(other.getTelephone()) .litigationIssues(other.getLitigationIssues()) .litigationIssuesDetails(other.getLitigationIssuesDetails()) - .detailsHidden(equalsIgnoreCase(other.getDetailsHidden(), YES.getValue())) + .detailsHidden(isYes(other.getDetailsHidden())) .detailsHiddenReason(other.getDetailsHiddenReason()) .build()) .toList() ) .orElse(List.of()); } + + private List getCafcassApiHearing(CaseData caseData) { + return Optional.ofNullable(caseData.getHearingDetails()).orElse(List.of()).stream() + .map(hearingBookingElement -> { + HearingBooking hearingBooking = hearingBookingElement.getValue(); + return CafcassApiHearing.builder() + .id(hearingBookingElement.getId().toString()) + .type(hearingBooking.getType()) + .typeDetails(hearingBooking.getTypeDetails()) + .venue(hearingBooking.getVenue()) + .status(hearingBooking.getStatus()) + .startDate(hearingBooking.getStartDate()) + .endDate(hearingBooking.getEndDate()) + .attendance(hearingBooking.getAttendance()) + .cancellationReason(hearingBooking.getCancellationReason()) + .preAttendanceDetails(hearingBooking.getPreAttendanceDetails()) + .attendanceDetails(hearingBooking.getAttendanceDetails()) + .build(); + }) + .toList(); + } + + private CafcassApiInternationalElement getCafcassApiInternationalElement(CaseData caseData) { + CafcassApiInternationalElement.CafcassApiInternationalElementBuilder builder = + CafcassApiInternationalElement.builder(); + + final InternationalElement internationalElement = caseData.getInternationalElement(); + if (internationalElement != null) { + builder = builder.possibleCarer(isYes(internationalElement.getPossibleCarer())) + .possibleCarerReason(internationalElement.getPossibleCarerReason()) + .significantEvents(isYes(internationalElement.getSignificantEvents())) + .significantEventsReason(internationalElement.getSignificantEventsReason()) + .issues(isYes(internationalElement.getIssues())) + .issuesReason(internationalElement.getIssuesReason()) + .proceedings(isYes(internationalElement.getProceedings())) + .proceedingsReason(internationalElement.getProceedingsReason()) + .internationalAuthorityInvolvement(isYes(internationalElement.getInternationalAuthorityInvolvement())) + .internationalAuthorityInvolvementDetails(internationalElement + .getInternationalAuthorityInvolvementDetails()); + } + + return builder.build(); + } + + private List getCafcassApiProceeding(CaseData caseData) { + return caseData.getAllProceedings().stream() + .map(Element::getValue) + .map(proceeding -> CafcassApiProceeding.builder() + .proceedingStatus(proceeding.getProceedingStatus()) + .caseNumber(proceeding.getCaseNumber()) + .started(proceeding.getProceedingStatus()) + .ended(proceeding.getEnded()) + .ordersMade(proceeding.getOrdersMade()) + .judge(proceeding.getJudge()) + .children(proceeding.getChildren()) + .guardian(proceeding.getGuardian()) + .sameGuardianNeeded(isYes(proceeding.getSameGuardianNeeded())) + .sameGuardianDetails(proceeding.getSameGuardianDetails()) + .build()) + .toList(); + } + + private CafcassApiRisk getCafcassApiRisk(CaseData caseData) { + CafcassApiRisk.CafcassApiRiskBuilder builder = CafcassApiRisk.builder(); + + Risks risk = caseData.getRisks(); + if (risk != null) { + builder = builder + .neglectOccurrences(risk.getNeglectOccurrences()) + .sexualAbuseOccurrences(risk.getSexualAbuseOccurrences()) + .physicalHarmOccurrences(risk.getPhysicalHarmOccurrences()) + .emotionalHarmOccurrences(risk.getEmotionalHarmOccurrences()); + } + return builder.build(); + } + + private CafcassApiFactorsParenting getCafcassApiFactorsParenting(CaseData caseData) { + CafcassApiFactorsParenting.CafcassApiFactorsParentingBuilder builder = CafcassApiFactorsParenting.builder(); + + FactorsParenting factorsParenting = caseData.getFactorsParenting(); + if (factorsParenting != null) { + builder = builder.alcoholDrugAbuse(isYes(factorsParenting.getAlcoholDrugAbuse())) + .alcoholDrugAbuseReason(factorsParenting.getAlcoholDrugAbuseReason()) + .domesticViolence(isYes(factorsParenting.getDomesticViolence())) + .domesticViolenceReason(factorsParenting.getDomesticViolenceReason()) + .anythingElse(isYes(factorsParenting.getAnythingElse())) + .anythingElseReason(factorsParenting.getAnythingElseReason()); + } + return builder.build(); + } + + private CafcassApiCaseManagementLocation getCafcassApiCaseManagementLocation(CaseData caseData) { + CafcassApiCaseManagementLocation.CafcassApiCaseManagementLocationBuilder builder = + CafcassApiCaseManagementLocation.builder(); + + CaseLocation caseLocation = caseData.getCaseManagementLocation(); + if (caseLocation != null) { + builder = builder.region(caseLocation.getRegion()).baseLocation(caseLocation.getBaseLocation()); + } + return builder.build(); + } } From 301e43b1c929f063367a8c3f0b33342982e0e262 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 17 Jul 2024 17:55:50 +0100 Subject: [PATCH 20/51] refactor to chain pattern --- .../cafcass/CafcassCasesController.java | 6 +- .../api}/CafcassApiAddress.java | 2 +- .../api}/CafcassApiApplicant.java | 2 +- .../api}/CafcassApiCase.java | 2 +- .../api}/CafcassApiCaseData.java | 7 +- .../cafcass/api/CafcassApiCaseDocument.java | 13 + .../CafcassApiCaseManagementLocation.java | 2 +- .../api}/CafcassApiChild.java | 2 +- .../api}/CafcassApiColleague.java | 2 +- .../api}/CafcassApiFactorsParenting.java | 2 +- .../api}/CafcassApiHearing.java | 2 +- .../api}/CafcassApiInternationalElement.java | 2 +- .../api}/CafcassApiOther.java | 2 +- .../api}/CafcassApiProceeding.java | 2 +- .../api}/CafcassApiRespondent.java | 2 +- .../api}/CafcassApiRisk.java | 2 +- .../api}/CafcassApiSearchCasesResponse.java | 2 +- .../api}/CafcassApiSolicitor.java | 2 +- .../cafcass/CafcassApiCaseService.java | 358 ------------------ .../api/CafcassApiApplicantsConverter.java | 53 +++ .../api/CafcassApiCaseDataConverter.java | 9 + .../api/CafcassApiCaseDocumentsConverter.java | 21 + ...assApiCaseManagementLocationConverter.java | 27 ++ .../cafcass/api/CafcassApiCaseService.java | 96 +++++ .../api/CafcassApiChildrenConverter.java | 54 +++ .../CafcassApiFactorsParentingConverter.java | 33 ++ .../CafcassApiHearingDetailsConverter.java | 40 ++ ...fcassApiInternationalElementConverter.java | 41 ++ .../api/CafcassApiMetaDataConverter.java | 23 ++ .../api/CafcassApiOthersConverter.java | 49 +++ ...afcassApiPreviousProceedingsConverter.java | 38 ++ .../api/CafcassApiRespondentsConverter.java | 50 +++ .../cafcass/api/CafcassApiRisksConverter.java | 30 ++ .../reform/fpl/utils/CafcassApiHelper.java | 53 +++ 34 files changed, 650 insertions(+), 381 deletions(-) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiAddress.java (87%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiApplicant.java (87%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiCase.java (88%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiCaseData.java (86%) create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiCaseManagementLocation.java (77%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiChild.java (94%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiColleague.java (85%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiFactorsParenting.java (87%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiHearing.java (93%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiInternationalElement.java (91%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiOther.java (91%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiProceeding.java (89%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiRespondent.java (93%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiRisk.java (86%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiSearchCasesResponse.java (79%) rename service/src/main/java/uk/gov/hmcts/reform/fpl/model/{api/cafcass => cafcass/api}/CafcassApiSolicitor.java (83%) delete mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDataConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java create mode 100644 service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index ee74340edf2..23d4c8b8dd5 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSearchCasesResponse; -import uk.gov.hmcts.reform.fpl.service.cafcass.CafcassApiCaseService; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSearchCasesResponse; +import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseService; import java.time.LocalDateTime; import java.util.List; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java similarity index 87% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java index ea310a16b03..f54d792eace 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiAddress.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java similarity index 87% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java index 9b72f908a59..d3d2a318ce4 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiApplicant.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java similarity index 88% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java index 0afe893a0ba..996ca2d396d 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCase.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java similarity index 86% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java index 17e1d3c9e19..4c67beee3e9 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseData.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java @@ -1,8 +1,7 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; -import uk.gov.hmcts.reform.ccd.model.CaseLocation; import uk.gov.hmcts.reform.fpl.enums.OrderType; import java.time.LocalDate; @@ -29,7 +28,5 @@ public class CafcassApiCaseData { private CafcassApiRisk risks; private CafcassApiFactorsParenting factorsParenting; private CafcassApiCaseManagementLocation caseManagementLocation; - - // TODO following field - private List caseDocuments; + private List caseDocuments; } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java new file mode 100644 index 00000000000..d9c9891feb3 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.reform.fpl.model.cafcass.api; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CafcassApiCaseDocument { + private String document_filename; + private boolean removed; + private String documentCategory; + private String documentId; +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java similarity index 77% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java index aea4dbac298..558baa4f66f 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiCaseManagementLocation.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java similarity index 94% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java index a887b9101df..bedc52648c4 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiChild.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java similarity index 85% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java index cba9bfa5be6..36bde068e60 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiColleague.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java similarity index 87% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java index 0191e778d8b..6664e406c7d 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiFactorsParenting.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java similarity index 93% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java index c2cb259d8ba..4060b54220b 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiHearing.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java similarity index 91% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java index 0607fc3980b..f745547e2f3 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiInternationalElement.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java similarity index 91% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java index 75cab492d11..658675da87e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiOther.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java similarity index 89% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java index 817ac3ff508..d8dc2c3f1e0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiProceeding.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java similarity index 93% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java index 68fb029e291..623b76d9844 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRespondent.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java similarity index 86% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java index 567e9c0d561..b5192517c53 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiRisk.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java similarity index 79% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java index 839d0394694..884b8d23dd7 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSearchCasesResponse.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java similarity index 83% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java index c120d7396cc..9bfbb9abb81 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/api/cafcass/CafcassApiSolicitor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.fpl.model.api.cafcass; +package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; import lombok.Getter; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java deleted file mode 100644 index 3c73bf2f344..00000000000 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/CafcassApiCaseService.java +++ /dev/null @@ -1,358 +0,0 @@ -package uk.gov.hmcts.reform.fpl.service.cafcass; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.parameters.P; -import org.springframework.stereotype.Service; -import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; -import uk.gov.hmcts.reform.ccd.model.CaseLocation; -import uk.gov.hmcts.reform.fpl.enums.YesNo; -import uk.gov.hmcts.reform.fpl.model.Address; -import uk.gov.hmcts.reform.fpl.model.CaseData; -import uk.gov.hmcts.reform.fpl.model.ChildParty; -import uk.gov.hmcts.reform.fpl.model.FactorsParenting; -import uk.gov.hmcts.reform.fpl.model.HearingBooking; -import uk.gov.hmcts.reform.fpl.model.InternationalElement; -import uk.gov.hmcts.reform.fpl.model.LocalAuthority; -import uk.gov.hmcts.reform.fpl.model.Proceeding; -import uk.gov.hmcts.reform.fpl.model.RespondentParty; -import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; -import uk.gov.hmcts.reform.fpl.model.Risks; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiAddress; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiApplicant; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCase; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseData; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiCaseManagementLocation; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiChild; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiColleague; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiFactorsParenting; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiHearing; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiInternationalElement; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiOther; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiProceeding; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRespondent; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiRisk; -import uk.gov.hmcts.reform.fpl.model.api.cafcass.CafcassApiSolicitor; -import uk.gov.hmcts.reform.fpl.model.common.Element; -import uk.gov.hmcts.reform.fpl.model.common.Telephone; -import uk.gov.hmcts.reform.fpl.service.CaseConverter; -import uk.gov.hmcts.reform.fpl.service.search.SearchService; -import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; -import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; -import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; -import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; - -@Slf4j -@Service -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) -public class CafcassApiCaseService { - private final CaseConverter caseConverter; - private final SearchService searchService; - - public List searchCaseByDateRange(LocalDateTime startDate, LocalDateTime endDate) { - - final RangeQuery searchRange = RangeQuery.builder() - .field("last_modified") - .greaterThanOrEqual(startDate) - .lessThanOrEqual(endDate).build(); - - List caseDetails = searchService.search(searchRange, 10000 , 0); - - return caseDetails.stream() - .map(this::convertToCafcassApiCase) - .toList(); - } - - private CafcassApiCase convertToCafcassApiCase(CaseDetails caseDetails) { - return CafcassApiCase.builder() - .caseId(caseDetails.getId()) - .jurisdiction(caseDetails.getJurisdiction()) - .state(caseDetails.getState()) - .caseTypeId(caseDetails.getCaseTypeId()) - .createdDate(caseDetails.getCreatedDate()) - .lastModified(caseDetails.getLastModified()) - .caseData(getCafcassApiCaseData(caseConverter.convert(caseDetails))) - .build(); - } - - private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { - return CafcassApiCaseData.builder() - .familyManCaseNumber(caseData.getFamilyManCaseNumber()) - .dateSubmitted(caseData.getDateSubmitted()) - .applicationType(caseData.isC1Application() ? "C1" : "C110A") - .ordersSought(caseData.getOrders().getOrderType()) - .dateOfCourtIssue(caseData.getDateOfIssue()) - .citizenIsApplicant(NO.equals(caseData.getIsLocalAuthority())) - .applicantLA(caseData.getCaseLocalAuthority()) - .respondentLA(caseData.getRelatingLA()) - .applicants(getCafcassApiApplicant(caseData)) - .respondents(getCafcassApiRespondents(caseData)) - .children(getCafcassApiChild(caseData)) - .others(getCafcassApiOthers(caseData)) - .hearingDetails(getCafcassApiHearing(caseData)) - .internationalElement(getCafcassApiInternationalElement(caseData)) - .previousProceedings(getCafcassApiProceeding(caseData)) - .risks(getCafcassApiRisk(caseData)) - .factorsParenting(getCafcassApiFactorsParenting(caseData)) - .caseManagementLocation(getCafcassApiCaseManagementLocation(caseData)) - .build(); - } - - private List getCafcassApiApplicant(CaseData caseData) { - return Optional.ofNullable(caseData.getLocalAuthorities()).orElse(List.of()).stream() - .map(applicantElement -> { - LocalAuthority applicant = applicantElement.getValue(); - - return CafcassApiApplicant.builder() - .id(applicantElement.getId().toString()) - .name(applicant.getName()) - .email(applicant.getEmail()) - .phone(applicant.getPhone()) - .address(getCafcassApiAddress(applicant.getAddress())) - .designated(isYes(applicant.getDesignated())) - .colleagues(applicant.getColleagues().stream() - .map(Element::getValue) - .map(colleague -> CafcassApiColleague.builder() - .role(colleague.getRole().toString()) - .title(colleague.getTitle()) - .email(colleague.getEmail()) - .phone(colleague.getPhone()) - .fullName(colleague.getFullName()) - .mainContact(isYes(colleague.getMainContact())) - .notificationRecipient(isYes(colleague.getNotificationRecipient())) - .build()) - .toList()) - .build(); - }) - .toList(); - } - - private boolean isYes(String yesNo) { - return YES.getValue().equalsIgnoreCase(yesNo); - } - - private CafcassApiAddress getCafcassApiAddress(Address address) { - return Optional.ofNullable(address) - .map(add -> CafcassApiAddress.builder() - .addressLine1(add.getAddressLine1()) - .addressLine2(add.getAddressLine2()) - .addressLine3(add.getAddressLine3()) - .postTown(add.getPostTown()) - .county(add.getCounty()) - .postcode(add.getPostcode()) - .country(add.getCountry()) - .build()) - .orElse(null); - } - - private List getCafcassApiRespondents(CaseData caseData) { - return Optional.ofNullable(caseData.getRespondents1()).orElse(List.of()).stream() - .map(Element::getValue) - .map(respondent -> { - RespondentParty respondentParty = respondent.getParty(); - return CafcassApiRespondent.builder() - .firstName(respondentParty.getFirstName()) - .lastName(respondentParty.getLastName()) - .gender(respondentParty.getGender()) - .addressKnown(isYes(respondentParty.getAddressKnow())) - .addressUnknownReason(respondentParty.getAddressNotKnowReason()) - .address(getCafcassApiAddress(respondentParty.getAddress())) - .dateOfBirth(respondentParty.getDateOfBirth()) - .telephoneNumber(getTelephoneNumber(respondentParty.getTelephoneNumber())) - .litigationIssues(respondentParty.getLitigationIssues()) - .litigationIssuesDetails(respondentParty.getLitigationIssuesDetails()) - .contactDetailsHidden(respondentParty.getContactDetailsHidden()) - .contactDetailsHiddenReason(respondentParty.getContactDetailsHiddenReason()) - .relationshipToChild(respondentParty.getRelationshipToChild()) - .solicitor(getCafcassApiSolicitor(respondent.getSolicitor())) - .build(); - }) - .toList(); - } - - private String getTelephoneNumber(Telephone telephone) { - return Optional.ofNullable(telephone) - .map(Telephone::getTelephoneNumber) - .orElse(null); - } - - private CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { - CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder(); - if (respondentSolicitor != null) { - builder = builder.email(respondentSolicitor.getEmail()); - builder = builder.firstName(respondentSolicitor.getFirstName()); - builder = builder.lastName(respondentSolicitor.getLastName()); - - if (respondentSolicitor.getOrganisation() != null) { - builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); - builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); - } - } - - return builder.build(); - } - - private List getCafcassApiChild(CaseData caseData) { - return Optional.ofNullable(caseData.getChildren1()).orElse(List.of()).stream() - .map(Element::getValue) - .map(child -> { - ChildParty childParty = child.getParty(); - return CafcassApiChild.builder() - .firstName(childParty.getFirstName()) - .lastName(childParty.getLastName()) - .dateOfBirth(childParty.getDateOfBirth()) - .gender(childParty.getGender().toString()) - .genderIdentification(childParty.getGenderIdentification()) - .livingSituation(childParty.getLivingSituation()) - .livingSituationDetails(childParty.getLivingSituationDetails()) - .address(getCafcassApiAddress(childParty.getAddress())) - .careAndContactPlan(childParty.getCareAndContactPlan()) - .detailsHidden(isYes(childParty.getDetailsHidden())) - .socialWorkerName(childParty.getSocialWorkerName()) - .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) - .additionalNeeds(isYes(childParty.getAdditionalNeeds())) - .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) - .litigationIssues(childParty.getLitigationIssues()) - .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) - .solicitor(getCafcassApiSolicitor(child.getSolicitor())) - .fathersResponsibility(childParty.getFathersResponsibility()) - .build(); - }) - .toList(); - } - - private List getCafcassApiOthers(CaseData caseData) { - return Optional.ofNullable(caseData.getOthers()) - .map(others -> Stream.concat(Optional.ofNullable(others.getFirstOther()).stream(), - unwrapElements(others.getAdditionalOthers()).stream()) - .filter(Objects::nonNull) - .map(other -> CafcassApiOther.builder() - .name(other.getName()) - .dateOfBirth(other.getDateOfBirth()) - .gender(other.getGender()) - .genderIdentification(other.getGenderIdentification()) - .birthPlace(other.getBirthPlace()) - .addressKnown(isYes(other.getAddressKnow())) - .addressUnknownReason(other.getAddressNotKnowReason()) - .address(getCafcassApiAddress(other.getAddress())) - .telephone(other.getTelephone()) - .litigationIssues(other.getLitigationIssues()) - .litigationIssuesDetails(other.getLitigationIssuesDetails()) - .detailsHidden(isYes(other.getDetailsHidden())) - .detailsHiddenReason(other.getDetailsHiddenReason()) - .build()) - .toList() - ) - .orElse(List.of()); - } - - private List getCafcassApiHearing(CaseData caseData) { - return Optional.ofNullable(caseData.getHearingDetails()).orElse(List.of()).stream() - .map(hearingBookingElement -> { - HearingBooking hearingBooking = hearingBookingElement.getValue(); - return CafcassApiHearing.builder() - .id(hearingBookingElement.getId().toString()) - .type(hearingBooking.getType()) - .typeDetails(hearingBooking.getTypeDetails()) - .venue(hearingBooking.getVenue()) - .status(hearingBooking.getStatus()) - .startDate(hearingBooking.getStartDate()) - .endDate(hearingBooking.getEndDate()) - .attendance(hearingBooking.getAttendance()) - .cancellationReason(hearingBooking.getCancellationReason()) - .preAttendanceDetails(hearingBooking.getPreAttendanceDetails()) - .attendanceDetails(hearingBooking.getAttendanceDetails()) - .build(); - }) - .toList(); - } - - private CafcassApiInternationalElement getCafcassApiInternationalElement(CaseData caseData) { - CafcassApiInternationalElement.CafcassApiInternationalElementBuilder builder = - CafcassApiInternationalElement.builder(); - - final InternationalElement internationalElement = caseData.getInternationalElement(); - if (internationalElement != null) { - builder = builder.possibleCarer(isYes(internationalElement.getPossibleCarer())) - .possibleCarerReason(internationalElement.getPossibleCarerReason()) - .significantEvents(isYes(internationalElement.getSignificantEvents())) - .significantEventsReason(internationalElement.getSignificantEventsReason()) - .issues(isYes(internationalElement.getIssues())) - .issuesReason(internationalElement.getIssuesReason()) - .proceedings(isYes(internationalElement.getProceedings())) - .proceedingsReason(internationalElement.getProceedingsReason()) - .internationalAuthorityInvolvement(isYes(internationalElement.getInternationalAuthorityInvolvement())) - .internationalAuthorityInvolvementDetails(internationalElement - .getInternationalAuthorityInvolvementDetails()); - } - - return builder.build(); - } - - private List getCafcassApiProceeding(CaseData caseData) { - return caseData.getAllProceedings().stream() - .map(Element::getValue) - .map(proceeding -> CafcassApiProceeding.builder() - .proceedingStatus(proceeding.getProceedingStatus()) - .caseNumber(proceeding.getCaseNumber()) - .started(proceeding.getProceedingStatus()) - .ended(proceeding.getEnded()) - .ordersMade(proceeding.getOrdersMade()) - .judge(proceeding.getJudge()) - .children(proceeding.getChildren()) - .guardian(proceeding.getGuardian()) - .sameGuardianNeeded(isYes(proceeding.getSameGuardianNeeded())) - .sameGuardianDetails(proceeding.getSameGuardianDetails()) - .build()) - .toList(); - } - - private CafcassApiRisk getCafcassApiRisk(CaseData caseData) { - CafcassApiRisk.CafcassApiRiskBuilder builder = CafcassApiRisk.builder(); - - Risks risk = caseData.getRisks(); - if (risk != null) { - builder = builder - .neglectOccurrences(risk.getNeglectOccurrences()) - .sexualAbuseOccurrences(risk.getSexualAbuseOccurrences()) - .physicalHarmOccurrences(risk.getPhysicalHarmOccurrences()) - .emotionalHarmOccurrences(risk.getEmotionalHarmOccurrences()); - } - return builder.build(); - } - - private CafcassApiFactorsParenting getCafcassApiFactorsParenting(CaseData caseData) { - CafcassApiFactorsParenting.CafcassApiFactorsParentingBuilder builder = CafcassApiFactorsParenting.builder(); - - FactorsParenting factorsParenting = caseData.getFactorsParenting(); - if (factorsParenting != null) { - builder = builder.alcoholDrugAbuse(isYes(factorsParenting.getAlcoholDrugAbuse())) - .alcoholDrugAbuseReason(factorsParenting.getAlcoholDrugAbuseReason()) - .domesticViolence(isYes(factorsParenting.getDomesticViolence())) - .domesticViolenceReason(factorsParenting.getDomesticViolenceReason()) - .anythingElse(isYes(factorsParenting.getAnythingElse())) - .anythingElseReason(factorsParenting.getAnythingElseReason()); - } - return builder.build(); - } - - private CafcassApiCaseManagementLocation getCafcassApiCaseManagementLocation(CaseData caseData) { - CafcassApiCaseManagementLocation.CafcassApiCaseManagementLocationBuilder builder = - CafcassApiCaseManagementLocation.builder(); - - CaseLocation caseLocation = caseData.getCaseManagementLocation(); - if (caseLocation != null) { - builder = builder.region(caseLocation.getRegion()).baseLocation(caseLocation.getBaseLocation()); - } - return builder.build(); - } -} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java new file mode 100644 index 00000000000..af7b12ffc14 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java @@ -0,0 +1,53 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; +import java.util.Optional; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiApplicantsConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.applicants(getCafcassApiApplicant(caseData)); + } + + private List getCafcassApiApplicant(CaseData caseData) { + return Optional.ofNullable(caseData.getLocalAuthorities()).orElse(List.of()).stream() + .map(applicantElement -> { + LocalAuthority applicant = applicantElement.getValue(); + + return CafcassApiApplicant.builder() + .id(applicantElement.getId().toString()) + .name(applicant.getName()) + .email(applicant.getEmail()) + .phone(applicant.getPhone()) + .address(getCafcassApiAddress(applicant.getAddress())) + .designated(isYes(applicant.getDesignated())) + .colleagues(applicant.getColleagues().stream() + .map(Element::getValue) + .map(colleague -> CafcassApiColleague.builder() + .role(colleague.getRole().toString()) + .title(colleague.getTitle()) + .email(colleague.getEmail()) + .phone(colleague.getPhone()) + .fullName(colleague.getFullName()) + .mainContact(isYes(colleague.getMainContact())) + .notificationRecipient(isYes(colleague.getNotificationRecipient())) + .build()) + .toList()) + .build(); + }) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDataConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDataConverter.java new file mode 100644 index 00000000000..3ea47479709 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDataConverter.java @@ -0,0 +1,9 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; + +public interface CafcassApiCaseDataConverter { + CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder); +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java new file mode 100644 index 00000000000..7db51f639d9 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; + +import java.util.List; + +@Component +public class CafcassApiCaseDocumentsConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.caseDocuments(getCafcassApiCaseDocument(caseData)); + } + + private List getCafcassApiCaseDocument(CaseData caseData) { + //TODO + return List.of(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java new file mode 100644 index 00000000000..9784f4c6288 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.ccd.model.CaseLocation; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseManagementLocation; + +@Component +public class CafcassApiCaseManagementLocationConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.caseManagementLocation(getCafcassApiCaseManagementLocation(caseData)); + } + + private CafcassApiCaseManagementLocation getCafcassApiCaseManagementLocation(CaseData caseData) { + CafcassApiCaseManagementLocation.CafcassApiCaseManagementLocationBuilder builder = + CafcassApiCaseManagementLocation.builder(); + + CaseLocation caseLocation = caseData.getCaseManagementLocation(); + if (caseLocation != null) { + builder = builder.region(caseLocation.getRegion()).baseLocation(caseLocation.getBaseLocation()); + } + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java new file mode 100644 index 00000000000..b09256457b8 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java @@ -0,0 +1,96 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.ccd.model.CaseLocation; +import uk.gov.hmcts.reform.fpl.model.Address; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.ChildParty; +import uk.gov.hmcts.reform.fpl.model.FactorsParenting; +import uk.gov.hmcts.reform.fpl.model.HearingBooking; +import uk.gov.hmcts.reform.fpl.model.InternationalElement; +import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.RespondentParty; +import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.Risks; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiAddress; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseManagementLocation; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiFactorsParenting; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiHearing; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiInternationalElement; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiOther; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiProceeding; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRespondent; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRisk; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.common.Document; +import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.common.Telephone; +import uk.gov.hmcts.reform.fpl.service.CaseConverter; +import uk.gov.hmcts.reform.fpl.service.search.SearchService; +import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; + +import java.lang.reflect.Field; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; +import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; + +@Slf4j +@Service +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class CafcassApiCaseService { + private final CaseConverter caseConverter; + private final SearchService searchService; + private final List cafcassApiCaseDataConverters; + + public List searchCaseByDateRange(LocalDateTime startDate, LocalDateTime endDate) { + + final RangeQuery searchRange = RangeQuery.builder() + .field("last_modified") + .greaterThanOrEqual(startDate) + .lessThanOrEqual(endDate).build(); + + List caseDetails = searchService.search(searchRange, 10000 , 0); + + return caseDetails.stream() + .map(this::convertToCafcassApiCase) + .toList(); + } + + private CafcassApiCase convertToCafcassApiCase(CaseDetails caseDetails) { + return CafcassApiCase.builder() + .caseId(caseDetails.getId()) + .jurisdiction(caseDetails.getJurisdiction()) + .state(caseDetails.getState()) + .caseTypeId(caseDetails.getCaseTypeId()) + .createdDate(caseDetails.getCreatedDate()) + .lastModified(caseDetails.getLastModified()) + .caseData(getCafcassApiCaseData(caseConverter.convert(caseDetails))) + .build(); + } + + private CafcassApiCaseData getCafcassApiCaseData(CaseData caseData) { + CafcassApiCaseData.CafcassApiCaseDataBuilder builder = CafcassApiCaseData.builder(); + + for (CafcassApiCaseDataConverter converter : cafcassApiCaseDataConverters) { + builder = converter.convert(caseData, builder); + } + + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java new file mode 100644 index 00000000000..375db0daa87 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java @@ -0,0 +1,54 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.ChildParty; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; +import java.util.Optional; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiSolicitor; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getTelephoneNumber; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiChildrenConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.children(getCafcassApiChild(caseData)); + } + + private List getCafcassApiChild(CaseData caseData) { + return Optional.ofNullable(caseData.getChildren1()).orElse(List.of()).stream() + .map(Element::getValue) + .map(child -> { + ChildParty childParty = child.getParty(); + return CafcassApiChild.builder() + .firstName(childParty.getFirstName()) + .lastName(childParty.getLastName()) + .dateOfBirth(childParty.getDateOfBirth()) + .gender(childParty.getGender().toString()) + .genderIdentification(childParty.getGenderIdentification()) + .livingSituation(childParty.getLivingSituation()) + .livingSituationDetails(childParty.getLivingSituationDetails()) + .address(getCafcassApiAddress(childParty.getAddress())) + .careAndContactPlan(childParty.getCareAndContactPlan()) + .detailsHidden(isYes(childParty.getDetailsHidden())) + .socialWorkerName(childParty.getSocialWorkerName()) + .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) + .additionalNeeds(isYes(childParty.getAdditionalNeeds())) + .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) + .litigationIssues(childParty.getLitigationIssues()) + .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) + .solicitor(getCafcassApiSolicitor(child.getSolicitor())) + .fathersResponsibility(childParty.getFathersResponsibility()) + .build(); + }) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java new file mode 100644 index 00000000000..3f1e5d245da --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.FactorsParenting; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiFactorsParenting; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiFactorsParentingConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.factorsParenting(getCafcassApiFactorsParenting(caseData)); + } + + private CafcassApiFactorsParenting getCafcassApiFactorsParenting(CaseData caseData) { + CafcassApiFactorsParenting.CafcassApiFactorsParentingBuilder builder = CafcassApiFactorsParenting.builder(); + + FactorsParenting factorsParenting = caseData.getFactorsParenting(); + if (factorsParenting != null) { + builder = builder.alcoholDrugAbuse(isYes(factorsParenting.getAlcoholDrugAbuse())) + .alcoholDrugAbuseReason(factorsParenting.getAlcoholDrugAbuseReason()) + .domesticViolence(isYes(factorsParenting.getDomesticViolence())) + .domesticViolenceReason(factorsParenting.getDomesticViolenceReason()) + .anythingElse(isYes(factorsParenting.getAnythingElse())) + .anythingElseReason(factorsParenting.getAnythingElseReason()); + } + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java new file mode 100644 index 00000000000..89523e6ed6a --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java @@ -0,0 +1,40 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.HearingBooking; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiHearing; + +import java.util.List; +import java.util.Optional; + +@Component +public class CafcassApiHearingDetailsConverter implements CafcassApiCaseDataConverter{ + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.hearingDetails(getCafcassApiHearing(caseData)); + } + + private List getCafcassApiHearing(CaseData caseData) { + return Optional.ofNullable(caseData.getHearingDetails()).orElse(List.of()).stream() + .map(hearingBookingElement -> { + HearingBooking hearingBooking = hearingBookingElement.getValue(); + return CafcassApiHearing.builder() + .id(hearingBookingElement.getId().toString()) + .type(hearingBooking.getType()) + .typeDetails(hearingBooking.getTypeDetails()) + .venue(hearingBooking.getVenue()) + .status(hearingBooking.getStatus()) + .startDate(hearingBooking.getStartDate()) + .endDate(hearingBooking.getEndDate()) + .attendance(hearingBooking.getAttendance()) + .cancellationReason(hearingBooking.getCancellationReason()) + .preAttendanceDetails(hearingBooking.getPreAttendanceDetails()) + .attendanceDetails(hearingBooking.getAttendanceDetails()) + .build(); + }) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java new file mode 100644 index 00000000000..ca48eb84e1f --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java @@ -0,0 +1,41 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.InternationalElement; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiInternationalElement; +import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseDataConverter; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiInternationalElementConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.internationalElement(getCafcassApiInternationalElement(caseData)); + } + + private CafcassApiInternationalElement getCafcassApiInternationalElement(CaseData caseData) { + CafcassApiInternationalElement.CafcassApiInternationalElementBuilder builder = + CafcassApiInternationalElement.builder(); + + final InternationalElement internationalElement = caseData.getInternationalElement(); + if (internationalElement != null) { + builder = builder.possibleCarer(isYes(internationalElement.getPossibleCarer())) + .possibleCarerReason(internationalElement.getPossibleCarerReason()) + .significantEvents(isYes(internationalElement.getSignificantEvents())) + .significantEventsReason(internationalElement.getSignificantEventsReason()) + .issues(isYes(internationalElement.getIssues())) + .issuesReason(internationalElement.getIssuesReason()) + .proceedings(isYes(internationalElement.getProceedings())) + .proceedingsReason(internationalElement.getProceedingsReason()) + .internationalAuthorityInvolvement(isYes(internationalElement.getInternationalAuthorityInvolvement())) + .internationalAuthorityInvolvementDetails(internationalElement + .getInternationalAuthorityInvolvementDetails()); + } + + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java new file mode 100644 index 00000000000..a919ee551ac --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java @@ -0,0 +1,23 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; + +@Component +public class CafcassApiMetaDataConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder + .familyManCaseNumber(caseData.getFamilyManCaseNumber()) + .dateSubmitted(caseData.getDateSubmitted()) + .applicationType(caseData.isC1Application() ? "C1" : "C110A") + .ordersSought(caseData.getOrders().getOrderType()) + .dateOfCourtIssue(caseData.getDateOfIssue()) + .citizenIsApplicant(YesNo.NO.equals(caseData.getIsLocalAuthority())) + .applicantLA(caseData.getCaseLocalAuthority()) + .respondentLA(caseData.getRelatingLA()); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java new file mode 100644 index 00000000000..83c99b4f321 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java @@ -0,0 +1,49 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiOther; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiOthersConverter implements CafcassApiCaseDataConverter{ + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.others(getCafcassApiOthers(caseData)); + } + + private List getCafcassApiOthers(CaseData caseData) { + return Optional.ofNullable(caseData.getOthers()) + .map(others -> Stream.concat(Optional.ofNullable(others.getFirstOther()).stream(), + unwrapElements(others.getAdditionalOthers()).stream()) + .filter(Objects::nonNull) + .map(other -> CafcassApiOther.builder() + .name(other.getName()) + .dateOfBirth(other.getDateOfBirth()) + .gender(other.getGender()) + .genderIdentification(other.getGenderIdentification()) + .birthPlace(other.getBirthPlace()) + .addressKnown(isYes(other.getAddressKnow())) + .addressUnknownReason(other.getAddressNotKnowReason()) + .address(getCafcassApiAddress(other.getAddress())) + .telephone(other.getTelephone()) + .litigationIssues(other.getLitigationIssues()) + .litigationIssuesDetails(other.getLitigationIssuesDetails()) + .detailsHidden(isYes(other.getDetailsHidden())) + .detailsHiddenReason(other.getDetailsHiddenReason()) + .build()) + .toList() + ) + .orElse(List.of()); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java new file mode 100644 index 00000000000..d445e83aaef --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiProceeding; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiPreviousProceedingsConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.previousProceedings(getCafcassApiProceeding(caseData)); + } + + private List getCafcassApiProceeding(CaseData caseData) { + return caseData.getAllProceedings().stream() + .map(Element::getValue) + .map(proceeding -> CafcassApiProceeding.builder() + .proceedingStatus(proceeding.getProceedingStatus()) + .caseNumber(proceeding.getCaseNumber()) + .started(proceeding.getProceedingStatus()) + .ended(proceeding.getEnded()) + .ordersMade(proceeding.getOrdersMade()) + .judge(proceeding.getJudge()) + .children(proceeding.getChildren()) + .guardian(proceeding.getGuardian()) + .sameGuardianNeeded(isYes(proceeding.getSameGuardianNeeded())) + .sameGuardianDetails(proceeding.getSameGuardianDetails()) + .build()) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java new file mode 100644 index 00000000000..77e1c78ba03 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java @@ -0,0 +1,50 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.RespondentParty; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRespondent; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; +import java.util.Optional; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiSolicitor; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getTelephoneNumber; +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; + +@Component +public class CafcassApiRespondentsConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.respondents(getCafcassApiRespondents(caseData)); + } + + private List getCafcassApiRespondents(CaseData caseData) { + return Optional.ofNullable(caseData.getRespondents1()).orElse(List.of()).stream() + .map(Element::getValue) + .map(respondent -> { + RespondentParty respondentParty = respondent.getParty(); + return CafcassApiRespondent.builder() + .firstName(respondentParty.getFirstName()) + .lastName(respondentParty.getLastName()) + .gender(respondentParty.getGender()) + .addressKnown(isYes(respondentParty.getAddressKnow())) + .addressUnknownReason(respondentParty.getAddressNotKnowReason()) + .address(getCafcassApiAddress(respondentParty.getAddress())) + .dateOfBirth(respondentParty.getDateOfBirth()) + .telephoneNumber(getTelephoneNumber(respondentParty.getTelephoneNumber())) + .litigationIssues(respondentParty.getLitigationIssues()) + .litigationIssuesDetails(respondentParty.getLitigationIssuesDetails()) + .contactDetailsHidden(respondentParty.getContactDetailsHidden()) + .contactDetailsHiddenReason(respondentParty.getContactDetailsHiddenReason()) + .relationshipToChild(respondentParty.getRelationshipToChild()) + .solicitor(getCafcassApiSolicitor(respondent.getSolicitor())) + .build(); + }) + .toList(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java new file mode 100644 index 00000000000..0d320c7d7a8 --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java @@ -0,0 +1,30 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Risks; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRisk; + +@Component +public class CafcassApiRisksConverter implements CafcassApiCaseDataConverter { + @Override + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + return builder.risks(getCafcassApiRisk(caseData)); + } + + private CafcassApiRisk getCafcassApiRisk(CaseData caseData) { + CafcassApiRisk.CafcassApiRiskBuilder builder = CafcassApiRisk.builder(); + + Risks risk = caseData.getRisks(); + if (risk != null) { + builder = builder + .neglectOccurrences(risk.getNeglectOccurrences()) + .sexualAbuseOccurrences(risk.getSexualAbuseOccurrences()) + .physicalHarmOccurrences(risk.getPhysicalHarmOccurrences()) + .emotionalHarmOccurrences(risk.getEmotionalHarmOccurrences()); + } + return builder.build(); + } +} diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java new file mode 100644 index 00000000000..b8387004b6c --- /dev/null +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java @@ -0,0 +1,53 @@ +package uk.gov.hmcts.reform.fpl.utils; + +import uk.gov.hmcts.reform.fpl.model.Address; +import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiAddress; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.common.Telephone; + +import java.util.Optional; + +import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; + +public class CafcassApiHelper { + public static CafcassApiAddress getCafcassApiAddress(Address address) { + return Optional.ofNullable(address) + .map(add -> CafcassApiAddress.builder() + .addressLine1(add.getAddressLine1()) + .addressLine2(add.getAddressLine2()) + .addressLine3(add.getAddressLine3()) + .postTown(add.getPostTown()) + .county(add.getCounty()) + .postcode(add.getPostcode()) + .country(add.getCountry()) + .build()) + .orElse(null); + } + + public static boolean isYes(String yesNo) { + return YES.getValue().equalsIgnoreCase(yesNo); + } + + public static String getTelephoneNumber(Telephone telephone) { + return Optional.ofNullable(telephone) + .map(Telephone::getTelephoneNumber) + .orElse(null); + } + + public static CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { + CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder(); + if (respondentSolicitor != null) { + builder = builder.email(respondentSolicitor.getEmail()); + builder = builder.firstName(respondentSolicitor.getFirstName()); + builder = builder.lastName(respondentSolicitor.getLastName()); + + if (respondentSolicitor.getOrganisation() != null) { + builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); + builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); + } + } + + return builder.build(); + } +} From a8dfe590164ab8fc6e63a06dd903b87c75f4b9ee Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 22 Jul 2024 14:34:36 +0100 Subject: [PATCH 21/51] orders document and manage document --- .../reform/fpl/enums/cfv/DocumentType.java | 78 +++++----- .../fpl/service/SecureDocStoreService.java | 8 +- .../api/CafcassApiCaseDocumentsConverter.java | 143 +++++++++++++++++- .../CafcassApiHearingDetailsConverter.java | 2 +- .../document/ManageDocumentService.java | 4 +- .../reform/fpl/utils/DocumentsHelper.java | 9 ++ 6 files changed, 194 insertions(+), 50 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java index e7a7d786bc6..3e633c55cba 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java @@ -50,7 +50,7 @@ public enum DocumentType { .courtBundle(List.of(courtBundleElement)) .build(); }, - null, 10, COURT_BUNDLE_NOTIFICATION_CONFIG), + null, 10, COURT_BUNDLE_NOTIFICATION_CONFIG, "bundle"), CASE_SUMMARY("Case Summary", standardResolver("hearingDocuments.caseSummaryList"), false, false, false, (bundle) -> CaseSummary.builder().document(bundle.getDocument()) @@ -59,24 +59,24 @@ public enum DocumentType { .markAsConfidential(YesNo.from(bundle.isConfidential()).getValue()) .translationRequirements(bundle.getTranslationRequirement()) .build(), - null,20, CASE_SUMMARY_NOTIFICATION_CONFIG), + null,20, CASE_SUMMARY_NOTIFICATION_CONFIG, "caseSummary"), POSITION_STATEMENTS("Position Statements", standardResolver("hearingDocuments.posStmtList"), false, false, false, defaultWithDocumentBuilder(), - null, 30, POSITION_STATEMENT_NOTIFICATION_CONFIG), + null, 30, POSITION_STATEMENT_NOTIFICATION_CONFIG, "positionStatements"), POSITION_STATEMENTS_CHILD("Position Statements (Child)", standardResolver("hearingDocuments.posStmtChildList"), true, true, true, null, - null, 31, null), + null, 31, null, "positionStatements"), POSITION_STATEMENTS_RESPONDENT("Position Statements (Respondent)", standardResolver("hearingDocuments.posStmtRespList"), true, true, true, null, - null, 32, null), + null, 32, null, "positionStatements"), THRESHOLD("Threshold", standardResolver("thresholdList"), false, false, false, defaultWithDocumentBuilder(), - null, 40, DEFAULT_NOTIFICATION_CONFIG), + null, 40, DEFAULT_NOTIFICATION_CONFIG, "threshold"), SKELETON_ARGUMENTS("Skeleton arguments", standardResolver("hearingDocuments.skeletonArgumentList"), false, false, false, (bundle) -> SkeletonArgument.builder() @@ -86,71 +86,71 @@ public enum DocumentType { .markAsConfidential(YesNo.from(bundle.isConfidential()).getValue()) .translationRequirements(bundle.getTranslationRequirement()) .build(), - null, 50, SKELETON_ARGUMENT_NOTIFICATION_CONFIG), + null, 50, SKELETON_ARGUMENT_NOTIFICATION_CONFIG, "skeletonArguments"), AA_PARENT_ORDERS("Orders", null, false, false, false, null, - null, 60, null), + null, 60, null, "orders"), JUDGEMENTS("└─ Judgements/facts and reasons", standardResolver("judgementList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_ORDERS, 70, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_ORDERS, 70, DEFAULT_NOTIFICATION_CONFIG, "judgementsFactsAndReasons"), TRANSCRIPTS("└─ Transcripts", standardResolver("transcriptList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_ORDERS, 80, NO_TRANSLATION_NOTIFICATION_CONFIG), + AA_PARENT_ORDERS, 80, NO_TRANSLATION_NOTIFICATION_CONFIG, "transcripts"), AA_PARENT_APPLICANTS_DOCUMENTS("Applicant's documents", null, false, false, false, null, - null, 90, null), + null, 90, null, "applicantsDocuments"), DOCUMENTS_FILED_ON_ISSUE("└─ Documents filed on issue", standardResolver("documentsFiledOnIssueList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 100, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 100, DEFAULT_NOTIFICATION_CONFIG, "documentsFiledOnIssue"), APPLICANTS_WITNESS_STATEMENTS("└─ Witness statements", standardResolver("applicantWitnessStmtList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 110, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 110, DEFAULT_NOTIFICATION_CONFIG, "applicantWitnessStatements"), CARE_PLAN("└─ Care plan", standardResolver("carePlanList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 120, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 120, DEFAULT_NOTIFICATION_CONFIG, "carePlan"), PARENT_ASSESSMENTS("└─ Parent assessments", standardResolver("parentAssessmentList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 130, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 130, DEFAULT_NOTIFICATION_CONFIG, "parentAssessments "), FAMILY_AND_VIABILITY_ASSESSMENTS("└─ Family and viability assessments", standardResolver("famAndViabilityList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 140, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 140, DEFAULT_NOTIFICATION_CONFIG, "familyAndViabilityAssessments"), APPLICANTS_OTHER_DOCUMENTS("└─ Applicant's other documents", standardResolver("applicantOtherDocList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 150, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 150, DEFAULT_NOTIFICATION_CONFIG, "applicantsOtherDocuments"), MEETING_NOTES("└─ Meeting notes", standardResolver("meetingNoteList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 160, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 160, DEFAULT_NOTIFICATION_CONFIG, "meetingNotes"), CONTACT_NOTES("└─ Contact notes", standardResolver("contactNoteList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICANTS_DOCUMENTS, 170, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_APPLICANTS_DOCUMENTS, 170, DEFAULT_NOTIFICATION_CONFIG, "contactNotes"), AA_PARENT_APPLICATIONS("Applications", null, false, false, false, null, - null, 180, null), + null, 180, null, "applications"), C1_APPLICATION_DOCUMENTS("└─ C1 application supporting documents", standardResolver("c1ApplicationDocList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICATIONS, 190, ADDITIONAL_APPLCIATION_NOTIFICAITON_CONFIG), + AA_PARENT_APPLICATIONS, 190, ADDITIONAL_APPLCIATION_NOTIFICAITON_CONFIG, "c1AndOtherApplications"), C2_APPLICATION_DOCUMENTS("└─ C2 application supporting documents", standardResolver("c2ApplicationDocList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_APPLICATIONS, 200, ADDITIONAL_APPLCIATION_NOTIFICAITON_CONFIG), + AA_PARENT_APPLICATIONS, 200, ADDITIONAL_APPLCIATION_NOTIFICAITON_CONFIG, "c2Applications"), AA_PARENT_RESPONDENTS_STATEMENTS("Respondent statements", null, false, false, false, null, - null, 210, null), + null, 210, null, "parent_respondentsStatements"), RESPONDENTS_STATEMENTS("└─ Respondent statements", standardResolver("respStmtList"), false, false, false, (bundle) -> RespondentStatementV2.builder() @@ -160,59 +160,59 @@ public enum DocumentType { .markAsConfidential(YesNo.from(bundle.isConfidential()).getValue()) .translationRequirements(bundle.getTranslationRequirement()) .build(), - AA_PARENT_RESPONDENTS_STATEMENTS, 220, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_RESPONDENTS_STATEMENTS, 220, DEFAULT_NOTIFICATION_CONFIG, "respondentWitnessStatements"), RESPONDENTS_WITNESS_STATEMENTS("└─ Witness statements", standardResolver("respWitnessStmtList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_RESPONDENTS_STATEMENTS, 230, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_RESPONDENTS_STATEMENTS, 230, DEFAULT_NOTIFICATION_CONFIG, "applicantWitnessStatements"), GUARDIAN_EVIDENCE("Guardian's evidence", standardResolver("guardianEvidenceList"), false, false, false, defaultWithDocumentBuilder(), - null, 240, NO_CAFCASS_NOTIFICATION_CONFIG), + null, 240, NO_CAFCASS_NOTIFICATION_CONFIG, "guardiansEvidence"), AA_PARENT_EXPERT_REPORTS("Expert Reports", null, false, false, false, null, - null, 250, null), + null, 250, null, "parent_expertReports"), EXPERT_REPORTS("└─ Expert Reports", standardResolver("expertReportList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_EXPERT_REPORTS, 260, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_EXPERT_REPORTS, 260, DEFAULT_NOTIFICATION_CONFIG, "expertReports"), DRUG_AND_ALCOHOL_REPORTS("└─ Drug and alcohol reports", standardResolver("drugAndAlcoholReportList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_EXPERT_REPORTS, 270, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_EXPERT_REPORTS, 270, DEFAULT_NOTIFICATION_CONFIG, "drugAndAlcoholReports"), LETTER_OF_INSTRUCTION("└─ Letters of instruction / referrals", standardResolver("lettersOfInstructionList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_EXPERT_REPORTS, 280, DEFAULT_NOTIFICATION_CONFIG), + AA_PARENT_EXPERT_REPORTS, 280, DEFAULT_NOTIFICATION_CONFIG, "lettersOfInstructionReferrals"), POLICE_DISCLOSURE("Police disclosure", standardResolver("policeDisclosureList"), false, false, false, defaultWithDocumentBuilder(), - null, 290, DEFAULT_NOTIFICATION_CONFIG), + null, 290, DEFAULT_NOTIFICATION_CONFIG, "policeDisclosure"), MEDICAL_RECORDS("Medical records", standardResolver("medicalRecordList"), false, false, false, defaultWithDocumentBuilder(), - null, 300, DEFAULT_NOTIFICATION_CONFIG), + null, 300, DEFAULT_NOTIFICATION_CONFIG, "medicalRecords"), COURT_CORRESPONDENCE("Court correspondence", standardResolver("correspondenceDocList"), false, false, false, defaultWithDocumentBuilder(), - null, 310, COURT_CORRESPONDENCE_NOTIFICATION_CONFIG), + null, 310, COURT_CORRESPONDENCE_NOTIFICATION_CONFIG, "courtCorrespondence"), NOTICE_OF_ACTING_OR_ISSUE("Notice of acting / notice of issue", standardResolver("noticeOfActingOrIssueList"), false, false, false, defaultWithDocumentBuilder(), - null, 320, DEFAULT_NOTIFICATION_CONFIG), + null, 320, DEFAULT_NOTIFICATION_CONFIG, "hearingNotices"), PREVIOUS_PROCEEDING("Previous Proceeding", standardResolver("previousProceedingList"), - false, false, false, + false, false, false, defaultWithDocumentBuilder(), - null, 330, NO_CAFCASS_NOTIFICATION_CONFIG), + null, 330, NO_CAFCASS_NOTIFICATION_CONFIG, "previousProceedings"), PLACEMENT_RESPONSES("Placement responses", null, false, false, false, null, - null, 340, null), + null, 340, null, "placementApplicationsAndResponses"), ARCHIVED_DOCUMENTS("Archived migrated data", standardResolver("archivedDocumentsList"), true, true, true, defaultWithDocumentBuilder(), - null, 999, DEFAULT_NOTIFICATION_CONFIG); + null, 999, DEFAULT_NOTIFICATION_CONFIG, "archivedDocuments"); @Getter private String description; @@ -232,6 +232,8 @@ public enum DocumentType { private final int displayOrder; @Getter private final DocumentUploadedNotificationConfiguration notificationConfiguration; + @Getter + private final String category; public boolean isUploadable() { if (isHiddenFromSolicitorUpload() || isHiddenFromLAUpload() || isHiddenFromCTSCUpload()) { diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/SecureDocStoreService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/SecureDocStoreService.java index 4d297b296fd..2803a629953 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/SecureDocStoreService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/SecureDocStoreService.java @@ -25,6 +25,7 @@ import static com.launchdarkly.shaded.com.google.common.collect.Lists.newArrayList; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; +import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; @Service @Slf4j @@ -80,11 +81,4 @@ public Document getDocumentMetadata(final String documentUrlString) { documentId ); } - - private UUID getDocumentIdFromUrl(final String documentUrlString) { - String selfHref = documentUrlString.replace("/binary", ""); - UUID documentId = UUID.fromString(selfHref.substring(selfHref.length() - 36)); - - return documentId; - } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index 7db51f639d9..2d8d9b93fd0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -1,21 +1,160 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; +import com.google.common.collect.ImmutableList; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; +import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; +import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; +import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.interfaces.WithDocument; +import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; +import uk.gov.hmcts.reform.fpl.model.order.generated.GeneratedOrder; +import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; +import java.util.stream.Stream; + +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.AA_PARENT_ORDERS; +import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Component +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassApiCaseDocumentsConverter implements CafcassApiCaseDataConverter { + private final ManageDocumentService manageDocumentService; + @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { - return builder.caseDocuments(getCafcassApiCaseDocument(caseData)); + return builder.caseDocuments(getCaseDocuments(caseData)); + } + + private List getCaseDocuments(CaseData caseData) { + List resultList = new ArrayList<>(); + + //draftOrderForReviewPriorToHearing + //applications + //originalApplications + // c1AndOtherApplications (main application form) + // c2Applications (main application form) + //orders + //draftOrders + //applicantsDocuments + //parent_expertReports + //documentsSentToParties + resultList.addAll(getOrders(caseData)); + resultList.addAll(getApplicationForm(caseData)); + resultList.addAll(getPlacementApplications(caseData)); + resultList.addAll(getAdditionalApplications(caseData)); + resultList.addAll(getHearingNotice(caseData)); + resultList.addAll(getManageDocuments(caseData)); + + return ImmutableList.copyOf(resultList); + } + + private List getOrders(CaseData caseData) { + List resultList = new ArrayList<>(); + // TODO check ccd config, only add to the list if Cafcass can view it + + // TODO urgentDirectionsOrder + caseData.getUrgentDirectionsOrder(); + // TODO standardDirectionOrder + caseData.getStandardDirectionOrder(); + + // draft orders (hearingOrdersBundlesDrafts, hearingOrdersBundlesDraftReview) + // Remarks: cafcass don't have permission to read draftUploadedCMOs and refusedHearingOrders + resultList.addAll(Stream.of(unwrapElements(caseData.getHearingOrdersBundlesDrafts()), + unwrapElements(caseData.getHearingOrdersBundlesDraftReview())) + .flatMap(List::stream) + // convert Stream to Stream + .map(draftOrderBundles -> + Stream.of(draftOrderBundles.getOrders(), draftOrderBundles.getAllChildConfidentialOrders()) + .flatMap(List::stream) + .map(Element::getValue) + .toList()) + .flatMap(List::stream) + .map(draftOrder -> (draftOrder.isConfidentialOrder()) + ? draftOrder.getOrderConfidential() : draftOrder.getOrder()) + .map(draftOrderDoc -> buildCafcassApiCaseDocument("draftOrders", draftOrderDoc, false)) + .toList()); + + // approved CMOs + resultList.addAll(unwrapElements(caseData.getSealedCMOs()).stream() + .map(sealedCmo -> (sealedCmo.isConfidentialOrder()) + ? sealedCmo.getOrderConfidential() : sealedCmo.getOrder()) + .map(sealedCmoDoc -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, sealedCmoDoc, false)) + .toList()); + + // approved orders (only those can be read by cafcass) + resultList.addAll(Stream.of(caseData.getOrderCollection(), + caseData.getConfidentialOrders().getAllChildConfidentialOrders()) + .flatMap(List::stream) + .map(Element::getValue) + .map(order -> (order.isConfidential()) ? order.getDocumentConfidential() : order.getDocument()) + .map(orderDoc -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, orderDoc, false)) + .toList()); + + return resultList; } - private List getCafcassApiCaseDocument(CaseData caseData) { + private List getApplicationForm(CaseData caseData) { //TODO return List.of(); } + + private List getPlacementApplications(CaseData caseData) { + //TODO + return List.of(); + } + + private List getAdditionalApplications(CaseData caseData) { + //TODO + return List.of(); + } + + private List getHearingNotice(CaseData caseData) { + //TODO + return List.of(); + } + + private List getManageDocuments(CaseData caseData) { + return Arrays.stream(DocumentType.values()) + .filter(documentType -> documentType.getBaseFieldNameResolver() != null) + .map(documentType -> + Stream.concat( + Stream.of(ConfidentialLevel.NON_CONFIDENTIAL, ConfidentialLevel.LA) + .map(confidentialLevel -> manageDocumentService + .toFieldNameToListOfElementMap(caseData, documentType, confidentialLevel).values()) + .flatMap(Collection::stream).flatMap(List::stream), + manageDocumentService.getListOfRemovedElement(caseData, documentType).stream()) + .map(Element::getValue) +// .filter(object -> object instanceof WithDocument) + .map(object -> (WithDocument) object) + .map(doc -> buildCafcassApiCaseDocument(documentType, doc.getDocument(), false)) + .toList()) + .flatMap(List::stream) + .toList(); + } + + private CafcassApiCaseDocument buildCafcassApiCaseDocument(String category, DocumentReference docRef, + boolean removed) { + return CafcassApiCaseDocument.builder() + .documentId(getDocumentIdFromUrl(docRef.getUrl()).toString()) + .document_filename(docRef.getFilename()) + .documentCategory(category) + .removed(removed) + .build(); + } + + private CafcassApiCaseDocument buildCafcassApiCaseDocument(DocumentType docType, DocumentReference docRef, + boolean removed) { + return buildCafcassApiCaseDocument(docType.getCategory(), docRef, removed); + } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java index 89523e6ed6a..1a57499ed47 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java @@ -10,7 +10,7 @@ import java.util.Optional; @Component -public class CafcassApiHearingDetailsConverter implements CafcassApiCaseDataConverter{ +public class CafcassApiHearingDetailsConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/document/ManageDocumentService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/document/ManageDocumentService.java index 08f6fa56d87..68ce9522277 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/document/ManageDocumentService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/document/ManageDocumentService.java @@ -464,7 +464,7 @@ private Element handleGeneralDocumentTypeRemoval(Documen } } - private List> getListOfRemovedElement(CaseData caseData, DocumentType documentType) { + public List> getListOfRemovedElement(CaseData caseData, DocumentType documentType) { return Optional.ofNullable(readFromFieldName(caseData, documentType.getFieldNameOfRemovedList())).orElse(new ArrayList<>()); } @@ -701,7 +701,7 @@ private Element mimicAdditionalApplicationsBundle( .build()); } - private Map>> toFieldNameToListOfElementMap(CaseData caseData, DocumentType documentType, + public Map>> toFieldNameToListOfElementMap(CaseData caseData, DocumentType documentType, ConfidentialLevel level) { Map>> ret = new LinkedHashMap<>(); if (documentType.getBaseFieldNameResolver() != null) { diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/DocumentsHelper.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/DocumentsHelper.java index 56242718e80..e575c297789 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/DocumentsHelper.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/DocumentsHelper.java @@ -6,6 +6,8 @@ import uk.gov.hmcts.reform.fpl.model.common.Document; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; +import java.util.UUID; + @Slf4j public class DocumentsHelper { @@ -43,4 +45,11 @@ public static String updateExtension(String filename, String newExtension) { } return filename; } + + public static UUID getDocumentIdFromUrl(final String documentUrlString) { + String selfHref = documentUrlString.replace("/binary", ""); + UUID documentId = UUID.fromString(selfHref.substring(selfHref.length() - 36)); + + return documentId; + } } From cab24c8205a087d18ddd56ea9b93f07302bbd49e Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Tue, 23 Jul 2024 17:56:34 +0100 Subject: [PATCH 22/51] case documents --- ...ionalApplicationsUploadedEventHandler.java | 13 +- .../cmo/DraftOrdersApprovedEventHandler.java | 5 +- .../common/AdditionalApplicationsBundle.java | 12 ++ .../reform/fpl/model/order/HearingOrder.java | 6 + .../model/order/generated/GeneratedOrder.java | 5 + .../api/CafcassApiCaseDocumentsConverter.java | 198 +++++++++++++----- .../AmendOrderToDownloadPrePopulator.java | 2 +- 7 files changed, 174 insertions(+), 67 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/AdditionalApplicationsUploadedEventHandler.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/AdditionalApplicationsUploadedEventHandler.java index c07a238f0d2..ea1e02d8694 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/AdditionalApplicationsUploadedEventHandler.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/AdditionalApplicationsUploadedEventHandler.java @@ -98,7 +98,7 @@ public void sendDocumentsToCafcass(final AdditionalApplicationsUploadedEvent eve AdditionalApplicationsBundle uploadedBundle = getUploadedBundle(caseData); if (!isConfidentialC2UploadedOnly(uploadedBundle) - || isConfidentialC2UploadedByChildSolicitor(uploadedBundle)) { + || uploadedBundle.isConfidentialC2UploadedByChildSolicitor()) { final CaseData caseDataBefore = event.getCaseDataBefore(); AdditionalApplicationsBundle oldBundle = Optional.ofNullable(caseDataBefore.getAdditionalApplicationsBundle()) @@ -338,15 +338,4 @@ private AdditionalApplicationsBundle getUploadedBundle(CaseData caseData) { private boolean isConfidentialC2UploadedOnly(AdditionalApplicationsBundle bundle) { return bundle.getC2DocumentBundle() == null && bundle.getOtherApplicationsBundle() == null; } - - private boolean isConfidentialC2UploadedByChildSolicitor(AdditionalApplicationsBundle bundle) { - return isNotEmpty(bundle.getC2DocumentBundleChild0()) || isNotEmpty(bundle.getC2DocumentBundleChild1()) - || isNotEmpty(bundle.getC2DocumentBundleChild2()) || isNotEmpty(bundle.getC2DocumentBundleChild3()) - || isNotEmpty(bundle.getC2DocumentBundleChild4()) || isNotEmpty(bundle.getC2DocumentBundleChild5()) - || isNotEmpty(bundle.getC2DocumentBundleChild6()) || isNotEmpty(bundle.getC2DocumentBundleChild7()) - || isNotEmpty(bundle.getC2DocumentBundleChild8()) || isNotEmpty(bundle.getC2DocumentBundleChild9()) - || isNotEmpty(bundle.getC2DocumentBundleChild10()) || isNotEmpty(bundle.getC2DocumentBundleChild11()) - || isNotEmpty(bundle.getC2DocumentBundleChild12()) || isNotEmpty(bundle.getC2DocumentBundleChild13()) - || isNotEmpty(bundle.getC2DocumentBundleChild14()); - } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/DraftOrdersApprovedEventHandler.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/DraftOrdersApprovedEventHandler.java index 24d8b9e5870..b6bd9e1857e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/DraftOrdersApprovedEventHandler.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/handlers/cmo/DraftOrdersApprovedEventHandler.java @@ -214,8 +214,7 @@ public void sendNotificationToCafcassViaSendGrid(final DraftOrdersApproved event approvedOrders.forEach(hearingOrder -> cafcassNotificationService.sendEmail(caseData, - Set.of(hearingOrder.isConfidentialOrder() ? hearingOrder.getOrderConfidential() - : hearingOrder.getOrder()), + Set.of(hearingOrder.getOrderOrOrderConfidential()), ORDER, OrderCafcassData.builder() .documentName(hearingOrder.getTitle()) @@ -367,7 +366,7 @@ public void notifyTranslationTeam(DraftOrdersApproved event) { approvedOrders.forEach( order -> translationRequestService.sendRequest(event.getCaseData(), Optional.ofNullable(order.getTranslationRequirements()), - (order.isConfidentialOrder()) ? order.getOrderConfidential() : order.getOrder(), + order.getOrderOrOrderConfidential(), String.format("%s - %s", defaultIfEmpty(order.getTitle(), "Blank order (C21)"), formatLocalDateTimeBaseUsingFormat(order.getDateIssued().atStartOfDay(), DATE) ) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/common/AdditionalApplicationsBundle.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/common/AdditionalApplicationsBundle.java index 05cc834540e..393756ef712 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/common/AdditionalApplicationsBundle.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/common/AdditionalApplicationsBundle.java @@ -103,4 +103,16 @@ && isNotEmpty(((C2DocumentBundle) field).getApplicantName())) { public YesNo getHasConfidentialC2() { return YesNo.from(isNotEmpty(c2DocumentBundleConfidential)); } + + @JsonIgnore + public boolean isConfidentialC2UploadedByChildSolicitor() { + return isNotEmpty(c2DocumentBundleChild0) || isNotEmpty(c2DocumentBundleChild1) + || isNotEmpty(c2DocumentBundleChild2) || isNotEmpty(c2DocumentBundleChild3) + || isNotEmpty(c2DocumentBundleChild4) || isNotEmpty(c2DocumentBundleChild5) + || isNotEmpty(c2DocumentBundleChild6) || isNotEmpty(c2DocumentBundleChild7) + || isNotEmpty(c2DocumentBundleChild8) || isNotEmpty(c2DocumentBundleChild9) + || isNotEmpty(c2DocumentBundleChild10) || isNotEmpty(c2DocumentBundleChild11) + || isNotEmpty(c2DocumentBundleChild12) || isNotEmpty(c2DocumentBundleChild13) + || isNotEmpty(c2DocumentBundleChild14); + } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/HearingOrder.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/HearingOrder.java index 3217ca65af0..35813750323 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/HearingOrder.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/HearingOrder.java @@ -205,4 +205,10 @@ public List getDocumentAcknowledge() { public boolean isConfidentialOrder() { return isNotEmpty(orderConfidential); } + + @JsonIgnore + public DocumentReference getOrderOrOrderConfidential() { + return (isConfidentialOrder()) ? orderConfidential : order; + } + } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/generated/GeneratedOrder.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/generated/GeneratedOrder.java index db2dbcd597b..359b43c4124 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/generated/GeneratedOrder.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/order/generated/GeneratedOrder.java @@ -192,4 +192,9 @@ public List> getSelectedOthers() { public boolean isConfidential() { return isNotEmpty(documentConfidential); } + + @JsonIgnore + public DocumentReference getDocumentOrDocumentConfidential() { + return (isConfidential()) ? documentConfidential : document; + } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index 2d8d9b93fd0..e4d042904e5 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -7,11 +7,21 @@ import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.PlacementConfidentialDocument; +import uk.gov.hmcts.reform.fpl.model.PlacementNoticeDocument; +import uk.gov.hmcts.reform.fpl.model.PlacementSupportingDocument; +import uk.gov.hmcts.reform.fpl.model.Supplement; +import uk.gov.hmcts.reform.fpl.model.SupportingEvidenceBundle; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; +import uk.gov.hmcts.reform.fpl.model.common.C2DocumentBundle; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.common.OtherApplicationsBundle; +import uk.gov.hmcts.reform.fpl.model.common.SubmittedC1WithSupplementBundle; +import uk.gov.hmcts.reform.fpl.model.group.C110A; import uk.gov.hmcts.reform.fpl.model.interfaces.WithDocument; +import uk.gov.hmcts.reform.fpl.model.order.DraftOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; import uk.gov.hmcts.reform.fpl.model.order.generated.GeneratedOrder; import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; @@ -20,9 +30,15 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.stream.Stream; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.AA_PARENT_ORDERS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.C1_APPLICATION_DOCUMENTS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.C2_APPLICATION_DOCUMENTS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.NOTICE_OF_ACTING_OR_ISSUE; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.PLACEMENT_RESPONSES; import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @@ -39,18 +55,10 @@ public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, C private List getCaseDocuments(CaseData caseData) { List resultList = new ArrayList<>(); - //draftOrderForReviewPriorToHearing - //applications - //originalApplications - // c1AndOtherApplications (main application form) - // c2Applications (main application form) - //orders - //draftOrders - //applicantsDocuments - //parent_expertReports - //documentsSentToParties - resultList.addAll(getOrders(caseData)); - resultList.addAll(getApplicationForm(caseData)); + resultList.addAll(getStandardAndUrgentDirectionOrder(caseData)); + resultList.addAll(getDraftOrders(caseData)); + resultList.addAll(getApprovedOrders(caseData)); + resultList.addAll(getOriginalApplications(caseData)); resultList.addAll(getPlacementApplications(caseData)); resultList.addAll(getAdditionalApplications(caseData)); resultList.addAll(getHearingNotice(caseData)); @@ -58,70 +66,158 @@ private List getCaseDocuments(CaseData caseData) { return ImmutableList.copyOf(resultList); } + private List getStandardAndUrgentDirectionOrder(CaseData caseData) { + return Stream.of(caseData.getUrgentDirectionsOrder(), caseData.getStandardDirectionOrder()) + .filter(Objects::nonNull) + .map(sdo -> + Stream.of(sdo.getOrderDoc(), sdo.getTranslatedOrderDoc()) + .filter(Objects::nonNull) + .map(docRef -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, docRef, false)) + .toList()) + .flatMap(List::stream) + .toList(); + } - private List getOrders(CaseData caseData) { - List resultList = new ArrayList<>(); - // TODO check ccd config, only add to the list if Cafcass can view it - - // TODO urgentDirectionsOrder - caseData.getUrgentDirectionsOrder(); - // TODO standardDirectionOrder - caseData.getStandardDirectionOrder(); - - // draft orders (hearingOrdersBundlesDrafts, hearingOrdersBundlesDraftReview) + private List getDraftOrders(CaseData caseData) { // Remarks: cafcass don't have permission to read draftUploadedCMOs and refusedHearingOrders - resultList.addAll(Stream.of(unwrapElements(caseData.getHearingOrdersBundlesDrafts()), + return Stream.of( + unwrapElements(caseData.getHearingOrdersBundlesDrafts()), unwrapElements(caseData.getHearingOrdersBundlesDraftReview())) .flatMap(List::stream) - // convert Stream to Stream .map(draftOrderBundles -> Stream.of(draftOrderBundles.getOrders(), draftOrderBundles.getAllChildConfidentialOrders()) .flatMap(List::stream) .map(Element::getValue) .toList()) .flatMap(List::stream) - .map(draftOrder -> (draftOrder.isConfidentialOrder()) - ? draftOrder.getOrderConfidential() : draftOrder.getOrder()) + .map(HearingOrder::getOrderOrOrderConfidential) .map(draftOrderDoc -> buildCafcassApiCaseDocument("draftOrders", draftOrderDoc, false)) - .toList()); + .toList(); + } - // approved CMOs - resultList.addAll(unwrapElements(caseData.getSealedCMOs()).stream() - .map(sealedCmo -> (sealedCmo.isConfidentialOrder()) - ? sealedCmo.getOrderConfidential() : sealedCmo.getOrder()) + private List getApprovedOrders(CaseData caseData) { + // Remarks: cafcass don't have permission to read refusedHearingOrders + return Stream.concat( + // approved CMOs + unwrapElements(caseData.getSealedCMOs()).stream().map(HearingOrder::getOrderOrOrderConfidential), + // approved orders (only those can be read by cafcass) + Stream.of(caseData.getOrderCollection(), + caseData.getConfidentialOrders().getAllChildConfidentialOrders()) + .flatMap(List::stream) + .map(Element::getValue) + .map(GeneratedOrder::getDocumentOrDocumentConfidential) + ) .map(sealedCmoDoc -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, sealedCmoDoc, false)) - .toList()); + .toList(); + } - // approved orders (only those can be read by cafcass) - resultList.addAll(Stream.of(caseData.getOrderCollection(), - caseData.getConfidentialOrders().getAllChildConfidentialOrders()) - .flatMap(List::stream) - .map(Element::getValue) - .map(order -> (order.isConfidential()) ? order.getDocumentConfidential() : order.getDocument()) - .map(orderDoc -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, orderDoc, false)) - .toList()); + private List getOriginalApplications(CaseData caseData) { + List documentReferences = new ArrayList<>(); - return resultList; - } + SubmittedC1WithSupplementBundle submittedC1 = caseData.getSubmittedC1WithSupplement(); + if (isNotEmpty(submittedC1)) { + documentReferences.add(submittedC1.getDocument()); + documentReferences.addAll(getAllDocumentsFromSupplements(submittedC1.getSupplementsBundle())); + documentReferences.addAll(getAllDocumentsFromSupportingEvidenceBundles(submittedC1.getSupportingEvidenceBundle())); + } + + C110A c110a = caseData.getC110A(); + if (isNotEmpty(c110a)) { + documentReferences.addAll(Stream.of(c110a.getDocument(), c110a.getTranslatedDocument(), + c110a.getSupplementDocument()) + .toList()); + } - private List getApplicationForm(CaseData caseData) { - //TODO - return List.of(); + return documentReferences.stream() + .map(docRef -> buildCafcassApiCaseDocument("originalApplications", docRef, false)) + .toList(); } private List getPlacementApplications(CaseData caseData) { - //TODO - return List.of(); + return unwrapElements(caseData.getPlacementEventData().getPlacements()).stream() + .map(placement -> { + List documentReferences = new ArrayList<>(); + + documentReferences.add(placement.getApplication()); + documentReferences.add(placement.getPlacementNotice()); + documentReferences.addAll(unwrapElements(placement.getConfidentialDocuments()).stream() + .map(PlacementConfidentialDocument::getDocument).toList()); + documentReferences.addAll(unwrapElements(placement.getSupportingDocuments()).stream() + .map(PlacementSupportingDocument::getDocument).toList()); + documentReferences.addAll(unwrapElements(placement.getNoticeDocuments()).stream() + .map(PlacementNoticeDocument::getDocument).toList()); + + return documentReferences; + }) + .flatMap(List::stream) + .map(docRef -> buildCafcassApiCaseDocument(PLACEMENT_RESPONSES, docRef, false)) + .toList(); } private List getAdditionalApplications(CaseData caseData) { - //TODO - return List.of(); + final List resultList = new ArrayList<>(); + + // additional application + unwrapElements(caseData.getAdditionalApplicationsBundle()).forEach(additionalApplicationsBundle -> { + + C2DocumentBundle c2Bundle = (additionalApplicationsBundle.isConfidentialC2UploadedByChildSolicitor()) + ? additionalApplicationsBundle.getC2DocumentBundleConfidential() + : additionalApplicationsBundle.getC2DocumentBundle(); + if (isNotEmpty(c2Bundle)) { + List c2DocRef = new ArrayList<>(); + c2DocRef.add(c2Bundle.getDocument()); + + c2DocRef.addAll(getAllDocumentsFromSupplements(c2Bundle.getSupplementsBundle())); + c2DocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( + c2Bundle.getSupportingEvidenceBundle())); + c2DocRef.addAll(unwrapElements(c2Bundle.getDraftOrdersBundle()).stream() + .map(DraftOrder::getDocument).toList()); + + resultList.addAll(c2DocRef.stream() + .map(docRef -> buildCafcassApiCaseDocument(C2_APPLICATION_DOCUMENTS, docRef, + false)) + .toList()); + } + + OtherApplicationsBundle otherBundle = additionalApplicationsBundle.getOtherApplicationsBundle(); + if (isNotEmpty(otherBundle)) { + List otherDocRef = new ArrayList<>(); + + otherDocRef.add(otherBundle.getDocument()); + otherDocRef.addAll(getAllDocumentsFromSupplements(otherBundle.getSupplementsBundle())); + otherDocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( + otherBundle.getSupportingEvidenceBundle())); + + resultList.addAll(otherDocRef.stream() + .map(docRef -> buildCafcassApiCaseDocument(C1_APPLICATION_DOCUMENTS, docRef, + false)) + .toList()); + } + }); + + + return resultList; + } + + private List getAllDocumentsFromSupportingEvidenceBundles(List> + bundles) { + return unwrapElements(bundles).stream() + .map(supportingEvidenceBundleElement -> List.of(supportingEvidenceBundleElement.getDocument(), + supportingEvidenceBundleElement.getTranslatedDocument())) + .flatMap(List::stream).toList(); + } + + private List getAllDocumentsFromSupplements(List> bundles) { + return unwrapElements(bundles).stream().map(Supplement::getDocument).toList(); } private List getHearingNotice(CaseData caseData) { - //TODO - return List.of(); + return unwrapElements(caseData.getHearingDetails()).stream() + .map(hearingBooking -> List.of(hearingBooking.getNoticeOfHearing(), + hearingBooking.getTranslatedNoticeOfHearing())) + .flatMap(List::stream) + .map(docRef -> buildCafcassApiCaseDocument(NOTICE_OF_ACTING_OR_ISSUE, docRef, false)) + .toList(); } private List getManageDocuments(CaseData caseData) { diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulator.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulator.java index 4fe3aab2bd4..fce35f7a26e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulator.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulator.java @@ -54,7 +54,7 @@ private DocumentReference getSelectedOrder(CaseData caseData) { if (foundOrder.isPresent()) { GeneratedOrder order = foundOrder.get().getValue(); - return (order.isConfidential()) ? order.getDocumentConfidential() : order.getDocument(); + return order.getDocumentOrDocumentConfidential(); } Optional> foundCMO = caseData.getSealedCMOs() From fee3ae250a6d6a6211ff715c1cdd7bb8a44a7bc5 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 24 Jul 2024 15:31:23 +0100 Subject: [PATCH 23/51] fix category --- .../java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java | 4 ++-- .../reform/fpl/model/cafcass/api/CafcassApiAddress.java | 3 ++- .../hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java | 5 +++-- .../reform/fpl/model/cafcass/api/CafcassApiSolicitor.java | 3 ++- .../java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java index 3e633c55cba..8e4a3576672 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/cfv/DocumentType.java @@ -160,11 +160,11 @@ public enum DocumentType { .markAsConfidential(YesNo.from(bundle.isConfidential()).getValue()) .translationRequirements(bundle.getTranslationRequirement()) .build(), - AA_PARENT_RESPONDENTS_STATEMENTS, 220, DEFAULT_NOTIFICATION_CONFIG, "respondentWitnessStatements"), + AA_PARENT_RESPONDENTS_STATEMENTS, 220, DEFAULT_NOTIFICATION_CONFIG, "parent_respondentsStatements"), RESPONDENTS_WITNESS_STATEMENTS("└─ Witness statements", standardResolver("respWitnessStmtList"), false, false, false, defaultWithDocumentBuilder(), - AA_PARENT_RESPONDENTS_STATEMENTS, 230, DEFAULT_NOTIFICATION_CONFIG, "applicantWitnessStatements"), + AA_PARENT_RESPONDENTS_STATEMENTS, 230, DEFAULT_NOTIFICATION_CONFIG, "respondentWitnessStatements"), GUARDIAN_EVIDENCE("Guardian's evidence", standardResolver("guardianEvidenceList"), false, false, false, defaultWithDocumentBuilder(), diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java index f54d792eace..5bdd6e243c0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java @@ -1,9 +1,10 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; +import lombok.Data; import lombok.Getter; -@Getter +@Data @Builder public class CafcassApiAddress { private final String addressLine1; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java index 996ca2d396d..d29ff0a681a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java @@ -1,12 +1,13 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; +import lombok.Data; import lombok.Getter; import java.time.LocalDateTime; -@Getter -@Builder +@Data +@Builder(toBuilder = true) public class CafcassApiCase { private Long caseId; private String jurisdiction; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java index 9bfbb9abb81..0b4263dae96 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java @@ -1,9 +1,10 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; +import lombok.Data; import lombok.Getter; -@Getter +@Data @Builder public class CafcassApiSolicitor { private String email; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java index b8387004b6c..7d1f86a90af 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java @@ -35,7 +35,7 @@ public static String getTelephoneNumber(Telephone telephone) { .orElse(null); } - public static CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { + public static CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder(); if (respondentSolicitor != null) { builder = builder.email(respondentSolicitor.getEmail()); From 6ad0f96f6e2eb5112b2ef8af48b5afd6daca9c7b Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 24 Jul 2024 15:31:32 +0100 Subject: [PATCH 24/51] CafcassApiHelperTest and CafcassApiCaseServiceTest --- .../api/CafcassApiCaseServiceTest.java | 123 ++++++++++++++++++ .../fpl/utils/CafcassApiHelperTest.java | 85 ++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java new file mode 100644 index 00000000000..d9f726acfd7 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java @@ -0,0 +1,123 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +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 uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.fpl.CaseDefinitionConstants; +import uk.gov.hmcts.reform.fpl.enums.State; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.service.CaseConverter; +import uk.gov.hmcts.reform.fpl.service.search.SearchService; +import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; + +import java.time.LocalDateTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class CafcassApiCaseServiceTest { + private static final LocalDateTime SEARCH_END_DATE = LocalDateTime.now(); + private static final LocalDateTime SEARCH_START_DATE = SEARCH_END_DATE.minusDays(1); + private static final RangeQuery SEARCH_RANGE = RangeQuery.builder().field("last_modified") + .greaterThanOrEqual(SEARCH_START_DATE).lessThanOrEqual(SEARCH_END_DATE).build(); + + private static final CaseData MOCK_CASE_DATA_1 = mock(CaseData.class); + private static final CaseDetails MOCK_CASE_DETAILS_1 = CaseDetails.builder() + .id(1L) + .jurisdiction(CaseDefinitionConstants.JURISDICTION) + .state(State.CASE_MANAGEMENT.getValue()) + .caseTypeId(CaseDefinitionConstants.CASE_TYPE) + .createdDate(LocalDateTime.MIN) + .lastModified(LocalDateTime.now().minusHours(1)) + .build(); + private static final CaseData MOCK_CASE_DATA_2 = mock(CaseData.class); + private static final CaseDetails MOCK_CASE_DETAILS_2 = MOCK_CASE_DETAILS_1.toBuilder().id(2L).build(); + + private static final CafcassApiCaseData MOCK_CONVERTED_CAFCASSAPICASEDATA = mock(CafcassApiCaseData.class); + + @Mock + private CaseConverter caseConverter; + @Mock + private SearchService searchService; + @Mock + private CafcassApiCaseDataConverter cafcassApiCaseDataConverter1; + @Mock + private CafcassApiCaseDataConverter cafcassApiCaseDataConverter2; + @Mock + private CafcassApiCaseDataConverter cafcassApiCaseDataConverter3; + + private CafcassApiCaseService underTest; + + @BeforeEach + void setUpWithMockConverters() { + underTest = new CafcassApiCaseService(caseConverter, searchService, + List.of(cafcassApiCaseDataConverter1, cafcassApiCaseDataConverter2, cafcassApiCaseDataConverter3)); + } + + @Test + void shouldReturnSearchResultAndBuildCafcassApiCaseByInvokingAllConverter() { + final CafcassApiCaseData.CafcassApiCaseDataBuilder mockBuilder = + mock(CafcassApiCaseData.CafcassApiCaseDataBuilder.class); + when(mockBuilder.build()).thenReturn(MOCK_CONVERTED_CAFCASSAPICASEDATA); + when(cafcassApiCaseDataConverter1.convert(any(), any())).thenReturn(mockBuilder); + when(cafcassApiCaseDataConverter2.convert(any(), any())).thenReturn(mockBuilder); + when(cafcassApiCaseDataConverter3.convert(any(), any())).thenReturn(mockBuilder); + + final List caseDetails = List.of(MOCK_CASE_DETAILS_1, MOCK_CASE_DETAILS_2); + when(searchService.search(eq(SEARCH_RANGE), anyInt(), anyInt())).thenReturn(caseDetails); + when(caseConverter.convert(MOCK_CASE_DETAILS_1)).thenReturn(MOCK_CASE_DATA_1); + when(caseConverter.convert(MOCK_CASE_DETAILS_2)).thenReturn(MOCK_CASE_DATA_2); + + + CafcassApiCase expectedCafcassApiCase1 = CafcassApiCase.builder() + .caseId(1L) + .jurisdiction(CaseDefinitionConstants.JURISDICTION) + .state(State.CASE_MANAGEMENT.getValue()) + .caseTypeId(CaseDefinitionConstants.CASE_TYPE) + .createdDate(MOCK_CASE_DETAILS_1.getCreatedDate()) + .lastModified(MOCK_CASE_DETAILS_1.getLastModified()) + .caseData(MOCK_CONVERTED_CAFCASSAPICASEDATA) + .build(); + CafcassApiCase expectedCafcassApiCase2 = expectedCafcassApiCase1.toBuilder() + .caseId(2L) + .caseData(MOCK_CONVERTED_CAFCASSAPICASEDATA) + .build(); + + List actual = underTest.searchCaseByDateRange(SEARCH_START_DATE, SEARCH_END_DATE); + List expected = List.of(expectedCafcassApiCase1, expectedCafcassApiCase2); + + assertEquals(expected, actual); + + // verify calling all converters to build CafcassApiCaseData + verify(cafcassApiCaseDataConverter1).convert(eq(MOCK_CASE_DATA_1), any()); + verify(cafcassApiCaseDataConverter2).convert(eq(MOCK_CASE_DATA_1), any()); + verify(cafcassApiCaseDataConverter3).convert(eq(MOCK_CASE_DATA_1), any()); + verify(cafcassApiCaseDataConverter1).convert(eq(MOCK_CASE_DATA_2), any()); + verify(cafcassApiCaseDataConverter2).convert(eq(MOCK_CASE_DATA_2), any()); + verify(cafcassApiCaseDataConverter3).convert(eq(MOCK_CASE_DATA_2), any()); + verifyNoMoreInteractions(cafcassApiCaseDataConverter1); + verifyNoMoreInteractions(cafcassApiCaseDataConverter2); + verifyNoMoreInteractions(cafcassApiCaseDataConverter3); + } + + @Test + void shouldReturnEmptyListIfNoCaseFound() { + when(searchService.search(eq(SEARCH_RANGE), anyInt(), anyInt())).thenReturn(List.of()); + List actual = underTest.searchCaseByDateRange(SEARCH_START_DATE, SEARCH_END_DATE); + + assertEquals(List.of(), actual); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java new file mode 100644 index 00000000000..9a4922c036c --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java @@ -0,0 +1,85 @@ +package uk.gov.hmcts.reform.fpl.utils; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.ccd.model.Organisation; +import uk.gov.hmcts.reform.fpl.model.Address; +import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiAddress; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.common.Telephone; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CafcassApiHelperTest { + @Test + public void testGetCafcassApiAddress() { + Address address = Address.builder() + .addressLine1("Address Line 1") + .addressLine2("Address Line 2") + .addressLine3("Address Line 3") + .postTown("Post Town") + .county("County") + .postcode("A123 B123") + .country("UK") + .build(); + + CafcassApiAddress expected = CafcassApiAddress.builder() + .addressLine1(address.getAddressLine1()) + .addressLine2(address.getAddressLine2()) + .addressLine3(address.getAddressLine3()) + .postTown(address.getPostTown()) + .county(address.getCounty()) + .postcode(address.getPostcode()) + .country(address.getCountry()) + .build(); + + CafcassApiAddress actual = CafcassApiHelper.getCafcassApiAddress(address); + assertEquals(expected, actual); + assertNull(CafcassApiHelper.getCafcassApiAddress(null)); + } + + @Test + public void testIsYes() { + assertTrue(CafcassApiHelper.isYes("yes")); + assertFalse(CafcassApiHelper.isYes("no")); + assertFalse(CafcassApiHelper.isYes(null)); + assertFalse(CafcassApiHelper.isYes("")); + } + + @Test + public void testGetTelephoneNumber() { + Telephone telephone = TestDataHelper.testTelephone(); + assertEquals(telephone.getTelephoneNumber(), CafcassApiHelper.getTelephoneNumber(telephone)); + assertNull(CafcassApiHelper.getTelephoneNumber(null)); + } + + @Test + public void testGetCafcassApiSolicitor() { + RespondentSolicitor solicitor = RespondentSolicitor.builder() + .email("solicitor@test.com") + .firstName("SolicitorFirstName") + .lastName("SolicitorLastName") + .organisation(Organisation.builder() + .organisationID("organisation ID") + .organisationName("organisation name") + .build()) + .build(); + + CafcassApiSolicitor expected = CafcassApiSolicitor.builder() + .email(solicitor.getEmail()) + .firstName(solicitor.getFirstName()) + .lastName(solicitor.getLastName()) + .organisationId(solicitor.getOrganisation().getOrganisationID()) + .organisationName(solicitor.getOrganisation().getOrganisationName()) + .build(); + + assertEquals(expected, CafcassApiHelper.getCafcassApiSolicitor(solicitor)); + assertEquals(CafcassApiSolicitor.builder().build(), + CafcassApiHelper.getCafcassApiSolicitor(null)); + } +} From bbe80e0d4c3785fb3fece81df8ad97a406aea99e Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 24 Jul 2024 18:18:48 +0100 Subject: [PATCH 25/51] applicantConverter test --- .../cafcass/api/CafcassApiApplicant.java | 4 +- .../model/cafcass/api/CafcassApiCaseData.java | 4 +- .../cafcass/api/CafcassApiCaseDocument.java | 4 +- .../api/CafcassApiCaseManagementLocation.java | 4 +- .../model/cafcass/api/CafcassApiChild.java | 4 +- .../cafcass/api/CafcassApiColleague.java | 4 +- .../api/CafcassApiFactorsParenting.java | 4 +- .../model/cafcass/api/CafcassApiHearing.java | 4 +- .../api/CafcassApiInternationalElement.java | 4 +- .../model/cafcass/api/CafcassApiOther.java | 4 +- .../cafcass/api/CafcassApiProceeding.java | 4 +- .../cafcass/api/CafcassApiRespondent.java | 4 +- .../fpl/model/cafcass/api/CafcassApiRisk.java | 4 +- .../CafcassApiApplicantsConverterTest.java | 116 ++++++++++++++++++ .../api/CafcassApiConverterTestBase.java | 21 ++++ 15 files changed, 163 insertions(+), 26 deletions(-) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java index d3d2a318ce4..edadc7ac491 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiApplicant.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import java.util.List; -@Getter +@Data @Builder public class CafcassApiApplicant { private String id; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java index 4c67beee3e9..04ddcd4e965 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseData.java @@ -1,13 +1,13 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import uk.gov.hmcts.reform.fpl.enums.OrderType; import java.time.LocalDate; import java.util.List; -@Getter +@Data @Builder public class CafcassApiCaseData { private String familyManCaseNumber; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java index d9c9891feb3..de1e0293386 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiCaseDocument { private String document_filename; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java index 558baa4f66f..3abb87002af 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseManagementLocation.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiCaseManagementLocation { private String region; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java index bedc52648c4..e4ac3090704 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiChild.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import java.time.LocalDate; -@Getter +@Data @Builder public class CafcassApiChild { private String firstName; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java index 36bde068e60..754614e6b58 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiColleague.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiColleague { private String role; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java index 6664e406c7d..b9450b3cd29 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiFactorsParenting.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiFactorsParenting { private boolean alcoholDrugAbuse; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java index 4060b54220b..ec1f8ad301c 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiHearing.java @@ -1,7 +1,7 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import uk.gov.hmcts.reform.fpl.enums.HearingStatus; import uk.gov.hmcts.reform.fpl.enums.HearingType; import uk.gov.hmcts.reform.fpl.enums.hearing.HearingAttendance; @@ -9,7 +9,7 @@ import java.time.LocalDateTime; import java.util.List; -@Getter +@Data @Builder public class CafcassApiHearing { private String id; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java index f745547e2f3..6e660997a73 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiInternationalElement.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiInternationalElement { private boolean possibleCarer; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java index 658675da87e..278e440de7a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiOther.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiOther { private String name; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java index d8dc2c3f1e0..73ae4c93971 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiProceeding.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; -@Getter +@Data @Builder public class CafcassApiProceeding { private String proceedingStatus; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java index 623b76d9844..da743a5f97a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import java.time.LocalDate; -@Getter +@Data @Builder public class CafcassApiRespondent { private String firstName; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java index b5192517c53..b2b057e10a7 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRisk.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import java.util.List; -@Getter +@Data @Builder public class CafcassApiRisk { private List neglectOccurrences; diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java new file mode 100644 index 00000000000..ec8eb497a5d --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java @@ -0,0 +1,116 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.ColleagueRole; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.Address; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Colleague; +import uk.gov.hmcts.reform.fpl.model.LocalAuthority; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; + +public class CafcassApiApplicantsConverterTest extends CafcassApiConverterTestBase{ + private static final LocalAuthority LA_1 = LocalAuthority.builder() + .name("Applicant 1 name") + .email("applicant1@test.com") + .phone("0123456789") + .address(Address.builder().addressLine1("applicant 1 address").build()) + .designated(YesNo.YES.getValue()) + .colleagues(wrapElements( + Colleague.builder() + .role(ColleagueRole.SOLICITOR) + .title("applicant 1 colleague") + .email("colleague1@test.com") + .fullName("colleague 1") + .mainContact(YesNo.YES.getValue()) + .notificationRecipient(YesNo.YES.getValue()) + .build())) + .build(); + private static final Element LA_1_ELEMENT = element(LA_1); + + private static final LocalAuthority LA_2 = LocalAuthority.builder() + .name("Applicant 2 name") + .email("applicant2@test.com") + .phone("0123456789") + .address(Address.builder().addressLine1("applicant 2 address").build()) + .designated(YesNo.NO.getValue()) + .colleagues(wrapElements( + Colleague.builder() + .role(ColleagueRole.OTHER) + .title("applicant 2 colleague") + .email("colleague2@test.com") + .fullName("colleague 2") + .mainContact(YesNo.NO.getValue()) + .notificationRecipient(YesNo.NO.getValue()) + .build())) + .build(); + private static final Element LA_2_ELEMENT = element(LA_2); + + CafcassApiApplicantsConverterTest() { + super(new CafcassApiApplicantsConverter()); + } + + @Test + void shouldConvertAllApplicant() { + CaseData caseData = CaseData.builder() + .localAuthorities(List.of(LA_1_ELEMENT, LA_2_ELEMENT)) + .build(); + + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .applicants(List.of( + CafcassApiApplicant.builder() + .id(LA_1_ELEMENT.getId().toString()) + .name("Applicant 1 name") + .email("applicant1@test.com") + .phone("0123456789") + .address(getCafcassApiAddress(LA_1.getAddress())) + .designated(true) + .colleagues(List.of( + CafcassApiColleague.builder() + .role(ColleagueRole.SOLICITOR.toString()) + .title("applicant 1 colleague") + .email("colleague1@test.com") + .fullName("colleague 1") + .mainContact(true) + .notificationRecipient(true) + .build())) + .build(), + CafcassApiApplicant.builder() + .id(LA_2_ELEMENT.getId().toString()) + .name("Applicant 2 name") + .email("applicant2@test.com") + .phone("0123456789") + .address(getCafcassApiAddress(LA_2.getAddress())) + .designated(false) + .colleagues(List.of( + CafcassApiColleague.builder() + .role(ColleagueRole.OTHER.toString()) + .title("applicant 2 colleague") + .email("colleague2@test.com") + .fullName("colleague 2") + .mainContact(false) + .notificationRecipient(false) + .build())) + .build())) + .build(); + + testConvert(caseData, expected); + } + + @Test + void shouldBuildEmptyListIfNoApplicant() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().applicants(List.of()).build(); + + testConvert(CaseData.builder().localAuthorities(null).build(), expected); + testConvert(CaseData.builder().localAuthorities(List.of()).build(), expected); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java new file mode 100644 index 00000000000..655f341037e --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public abstract class CafcassApiConverterTestBase { + CafcassApiCaseDataConverter underTest; + + private CafcassApiConverterTestBase() {} + CafcassApiConverterTestBase(CafcassApiCaseDataConverter converterUnderTest) { + underTest = converterUnderTest; + } + + public CafcassApiCaseData testConvert(CaseData caseData, CafcassApiCaseData expected) { + CafcassApiCaseData actual = underTest.convert(caseData, CafcassApiCaseData.builder()).build(); + assertEquals(actual, expected); + return actual; + } +} From bab3ad057bdf02a20db3530d054ef19822db4454 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 13:02:41 +0100 Subject: [PATCH 26/51] CafcassApiChildrenConverterTest --- .../CafcassApiApplicantsConverterTest.java | 92 +++++---------- ...piCaseManagementLocationConverterTest.java | 37 ++++++ .../api/CafcassApiChildrenConverterTest.java | 103 +++++++++++++++++ .../api/CafcassApiConverterTestBase.java | 109 ++++++++++++++++++ 4 files changed, 277 insertions(+), 64 deletions(-) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverterTest.java create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java index ec8eb497a5d..164f45521c3 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverterTest.java @@ -1,59 +1,19 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; import org.junit.jupiter.api.Test; -import uk.gov.hmcts.reform.fpl.enums.ColleagueRole; import uk.gov.hmcts.reform.fpl.enums.YesNo; -import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.CaseData; -import uk.gov.hmcts.reform.fpl.model.Colleague; import uk.gov.hmcts.reform.fpl.model.LocalAuthority; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; import uk.gov.hmcts.reform.fpl.model.common.Element; import java.util.List; -import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; -public class CafcassApiApplicantsConverterTest extends CafcassApiConverterTestBase{ - private static final LocalAuthority LA_1 = LocalAuthority.builder() - .name("Applicant 1 name") - .email("applicant1@test.com") - .phone("0123456789") - .address(Address.builder().addressLine1("applicant 1 address").build()) - .designated(YesNo.YES.getValue()) - .colleagues(wrapElements( - Colleague.builder() - .role(ColleagueRole.SOLICITOR) - .title("applicant 1 colleague") - .email("colleague1@test.com") - .fullName("colleague 1") - .mainContact(YesNo.YES.getValue()) - .notificationRecipient(YesNo.YES.getValue()) - .build())) - .build(); - private static final Element LA_1_ELEMENT = element(LA_1); - - private static final LocalAuthority LA_2 = LocalAuthority.builder() - .name("Applicant 2 name") - .email("applicant2@test.com") - .phone("0123456789") - .address(Address.builder().addressLine1("applicant 2 address").build()) - .designated(YesNo.NO.getValue()) - .colleagues(wrapElements( - Colleague.builder() - .role(ColleagueRole.OTHER) - .title("applicant 2 colleague") - .email("colleague2@test.com") - .fullName("colleague 2") - .mainContact(YesNo.NO.getValue()) - .notificationRecipient(YesNo.NO.getValue()) - .build())) - .build(); - private static final Element LA_2_ELEMENT = element(LA_2); +public class CafcassApiApplicantsConverterTest extends CafcassApiConverterTestBase { CafcassApiApplicantsConverterTest() { super(new CafcassApiApplicantsConverter()); @@ -61,45 +21,49 @@ public class CafcassApiApplicantsConverterTest extends CafcassApiConverterTestBa @Test void shouldConvertAllApplicant() { + LocalAuthority la1 = LocalAuthority.builder() + .name("Applicant 1 name") + .email("applicant1@test.com") + .phone("0123456789") + .address(getTestAddress("applicant 1 address")) + .designated(YesNo.YES.getValue()) + .colleagues(wrapElements(getTestColleague(1))) + .build(); + Element la1Element = element(la1); + + LocalAuthority la2 = LocalAuthority.builder() + .name("Applicant 2 name") + .email("applicant2@test.com") + .phone("0123456789") + .address(getTestAddress("applicant 2 address")) + .designated(YesNo.NO.getValue()) + .colleagues(wrapElements(getTestColleague(2))) + .build(); + Element la2Element = element(la2); + CaseData caseData = CaseData.builder() - .localAuthorities(List.of(LA_1_ELEMENT, LA_2_ELEMENT)) + .localAuthorities(List.of(la1Element, la2Element)) .build(); CafcassApiCaseData expected = CafcassApiCaseData.builder() .applicants(List.of( CafcassApiApplicant.builder() - .id(LA_1_ELEMENT.getId().toString()) + .id(la1Element.getId().toString()) .name("Applicant 1 name") .email("applicant1@test.com") .phone("0123456789") - .address(getCafcassApiAddress(LA_1.getAddress())) + .address(getExpectedAddress("applicant 1 address")) .designated(true) - .colleagues(List.of( - CafcassApiColleague.builder() - .role(ColleagueRole.SOLICITOR.toString()) - .title("applicant 1 colleague") - .email("colleague1@test.com") - .fullName("colleague 1") - .mainContact(true) - .notificationRecipient(true) - .build())) + .colleagues(List.of(getExpectedColleague(1))) .build(), CafcassApiApplicant.builder() - .id(LA_2_ELEMENT.getId().toString()) + .id(la2Element.getId().toString()) .name("Applicant 2 name") .email("applicant2@test.com") .phone("0123456789") - .address(getCafcassApiAddress(LA_2.getAddress())) + .address(getExpectedAddress("applicant 2 address")) .designated(false) - .colleagues(List.of( - CafcassApiColleague.builder() - .role(ColleagueRole.OTHER.toString()) - .title("applicant 2 colleague") - .email("colleague2@test.com") - .fullName("colleague 2") - .mainContact(false) - .notificationRecipient(false) - .build())) + .colleagues(List.of(getExpectedColleague(2))) .build())) .build(); diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverterTest.java new file mode 100644 index 00000000000..63da832f3da --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverterTest.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.ccd.model.CaseLocation; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseManagementLocation; + +public class CafcassApiCaseManagementLocationConverterTest extends CafcassApiConverterTestBase { + + CafcassApiCaseManagementLocationConverterTest() { + super(new CafcassApiCaseManagementLocationConverter()); + } + + @Test + void shouldConvertCaseManagementLocation() { + CaseData caseData = CaseData.builder() + .caseManagementLocation(CaseLocation.builder() + .region("region").baseLocation("baseLocation").build()) + .build(); + + testConvert(caseData, CafcassApiCaseData.builder() + .caseManagementLocation(CafcassApiCaseManagementLocation.builder() + .region("region").baseLocation("baseLocation").build()) + .build()); + } + + @Test + void shouldReturnEmptyObjectIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .caseManagementLocation(CafcassApiCaseManagementLocation.builder().build()) + .build(); + + testConvert(CaseData.builder().caseManagementLocation(null).build(), expected); + testConvert(CaseData.builder().caseManagementLocation(CaseLocation.builder().build()).build(), expected); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java new file mode 100644 index 00000000000..b735b3f8646 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java @@ -0,0 +1,103 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.ChildGender; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Child; +import uk.gov.hmcts.reform.fpl.model.ChildParty; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; + +import java.time.LocalDate; +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; + +public class CafcassApiChildrenConverterTest extends CafcassApiConverterTestBase { + + CafcassApiChildrenConverterTest() { + super(new CafcassApiChildrenConverter()); + } + + @Test + void shouldConvertAllChildren() { + Child childWithAllFields = Child.builder() + .party(ChildParty.builder() + .firstName("Child") + .lastName("One") + .dateOfBirth(LocalDate.of(2024, 1, 1)) + .gender(ChildGender.BOY) + .genderIdentification("genderIdentification") + .livingSituation("livingSituation") + .livingSituationDetails("livingSituationDetails") + .address(getTestAddress()) + .careAndContactPlan("careAndContactPlan") + .detailsHidden(YesNo.YES.toString()) + .detailsHiddenReason("detailsHiddenReason") + .socialWorkerName("socialWorkerName") + .socialWorkerTelephoneNumber(getTestTelephone()) + .additionalNeeds(YesNo.YES.toString()) + .additionalNeedsDetails("additionalNeedsDetails") + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .fathersResponsibility("fathersResponsibility") + .build()) + .solicitor(getTestRespondentSolicitor()) + .build(); + + Child childWithMandatoryFieldOnly = Child.builder() + .party(ChildParty.builder() + .firstName("Child") + .lastName("Two") + .dateOfBirth(LocalDate.of(2023, 1, 1)) + .gender(ChildGender.GIRL) + .build()) + .build(); + + CaseData caseData = CaseData.builder() + .children1(wrapElements(childWithAllFields, childWithMandatoryFieldOnly)) + .build(); + + testConvert(caseData, CafcassApiCaseData.builder() + .children(List.of( + CafcassApiChild.builder() + .firstName("Child") + .lastName("One") + .dateOfBirth(LocalDate.of(2024, 1, 1)) + .gender(ChildGender.BOY.toString()) + .genderIdentification("genderIdentification") + .livingSituation("livingSituation") + .livingSituationDetails("livingSituationDetails") + .address(getExpectedAddress()) + .careAndContactPlan("careAndContactPlan") + .detailsHidden(true) + .socialWorkerName("socialWorkerName") + .socialWorkerTelephoneNumber(getExpectedTelephone()) + .additionalNeeds(true) + .additionalNeedsDetails("additionalNeedsDetails") + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .fathersResponsibility("fathersResponsibility") + .solicitor(getExpectedSolicitor()) + .build(), + CafcassApiChild.builder() + .firstName("Child") + .lastName("Two") + .dateOfBirth(LocalDate.of(2023, 1, 1)) + .gender(ChildGender.GIRL.toString()) + .solicitor(CafcassApiSolicitor.builder().build()) + .build() + )).build()); + } + + + @Test + void shouldReturnEmptyLis() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().children(List.of()).build(); + + testConvert(CaseData.builder().children1(null).build(), expected); + testConvert(CaseData.builder().children1(List.of()).build(), expected); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java index 655f341037e..0af090ce662 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java @@ -1,9 +1,21 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; +import uk.gov.hmcts.reform.ccd.model.Organisation; +import uk.gov.hmcts.reform.fpl.enums.ColleagueRole; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Colleague; +import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiAddress; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.common.Telephone; +import uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper; import static org.junit.jupiter.api.Assertions.assertEquals; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; public abstract class CafcassApiConverterTestBase { CafcassApiCaseDataConverter underTest; @@ -18,4 +30,101 @@ public CafcassApiCaseData testConvert(CaseData caseData, CafcassApiCaseData expe assertEquals(actual, expected); return actual; } + + public static Address getTestAddress() { + return getTestAddress("address line 1"); + } + + public static Address getTestAddress(String line1) { + return Address.builder().addressLine1(line1).build(); + } + + public static CafcassApiAddress getExpectedAddress() { + return getExpectedAddress("address line 1"); + } + + public static CafcassApiAddress getExpectedAddress(String line1) { + return CafcassApiHelper.getCafcassApiAddress(getTestAddress(line1)); + } + + public static Colleague getTestColleague() { + return getTestColleague(1); + } + + public static Colleague getTestColleague(int colleagueNo) { + return Colleague.builder() + .role(ColleagueRole.SOLICITOR) + .title("Colleague" + colleagueNo + "'s title'") + .email("colleague@test.com") + .fullName("Colleague " + colleagueNo) + .mainContact(YesNo.YES.getValue()) + .notificationRecipient(YesNo.YES.getValue()) + .build(); + } + + public static CafcassApiColleague getExpectedColleague() { + return getExpectedColleague(1); + } + + public static CafcassApiColleague getExpectedColleague(int colleagueNo) { + return CafcassApiColleague.builder() + .role(ColleagueRole.SOLICITOR.toString()) + .title("Colleague" + colleagueNo + "'s title'") + .email("colleague@test.com") + .fullName("Colleague " + colleagueNo) + .mainContact(true) + .notificationRecipient(true) + .build(); + } + + public static Telephone getTestTelephone() { + return Telephone.builder() + .telephoneNumber("0123456789") + .contactDirection("contactDirection") + .telephoneUsageType("telephoneUsageType") + .build(); + } + + public static String getExpectedTelephone() { + return "0123456789"; + } + + public static Organisation getTestOrganisation() { + return Organisation.builder() + .organisationID("ORGID") + .organisationName("organisationName") + .build(); + } + + public static RespondentSolicitor getTestRespondentSolicitor() { + return getTestRespondentSolicitor(1); + } + + public static RespondentSolicitor getTestRespondentSolicitor(int solicitorNo) { + return RespondentSolicitor.builder() + .firstName("Solicitor" + solicitorNo + "FirstName") + .lastName("Solicitor" + solicitorNo + "LastName") + .email("respondentSolicitor" + solicitorNo + "@test.com") + .telephoneNumber(getTestTelephone()) + .regionalOfficeAddress(getTestAddress("Solicitor " + solicitorNo + "'s address")) + .organisation(getTestOrganisation()) + .colleaguesToBeNotified(wrapElements(getTestColleague(1), + getTestColleague(2))) + .build(); + } + + public static CafcassApiSolicitor getExpectedSolicitor() { + return getExpectedSolicitor(1); + } + + public static CafcassApiSolicitor getExpectedSolicitor(int solicitorNo) { + Organisation testOrg = getTestOrganisation(); + return CafcassApiSolicitor.builder() + .firstName("Solicitor" + solicitorNo + "FirstName") + .lastName("Solicitor" + solicitorNo + "LastName") + .email("respondentSolicitor" + solicitorNo + "@test.com") + .organisationId(testOrg.getOrganisationID()) + .organisationName(testOrg.getOrganisationName()) + .build(); + } } From b412da4f52028abe2e3531d515fe67ec9d48276d Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 16:33:14 +0100 Subject: [PATCH 27/51] refactor CafcassApiCaseDocumentsConverter to more FP style --- .../api/CafcassApiCaseDocumentsConverter.java | 181 +++++++++--------- 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index e4d042904e5..59d70e0a2e1 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -31,6 +31,7 @@ import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Stream; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; @@ -53,62 +54,58 @@ public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, C } private List getCaseDocuments(CaseData caseData) { - List resultList = new ArrayList<>(); - - resultList.addAll(getStandardAndUrgentDirectionOrder(caseData)); - resultList.addAll(getDraftOrders(caseData)); - resultList.addAll(getApprovedOrders(caseData)); - resultList.addAll(getOriginalApplications(caseData)); - resultList.addAll(getPlacementApplications(caseData)); - resultList.addAll(getAdditionalApplications(caseData)); - resultList.addAll(getHearingNotice(caseData)); - resultList.addAll(getManageDocuments(caseData)); - - return ImmutableList.copyOf(resultList); + return Stream.of( + getStandardAndUrgentDirectionOrder(caseData), + getDraftOrders(caseData), + getApprovedOrders(caseData), + getOriginalApplications(caseData), + getPlacementApplications(caseData), + getAdditionalApplications(caseData), + getHearingNotice(caseData), + getManageDocuments(caseData)) + .flatMap(List::stream) + //.parallel() + .toList(); } + private List getStandardAndUrgentDirectionOrder(CaseData caseData) { return Stream.of(caseData.getUrgentDirectionsOrder(), caseData.getStandardDirectionOrder()) .filter(Objects::nonNull) - .map(sdo -> - Stream.of(sdo.getOrderDoc(), sdo.getTranslatedOrderDoc()) - .filter(Objects::nonNull) - .map(docRef -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, docRef, false)) - .toList()) + .map(sdo -> buildCafcassApiCaseDocumentList(AA_PARENT_ORDERS, false, + Stream.of(sdo.getOrderDoc(), sdo.getTranslatedOrderDoc()))) .flatMap(List::stream) .toList(); } private List getDraftOrders(CaseData caseData) { // Remarks: cafcass don't have permission to read draftUploadedCMOs and refusedHearingOrders - return Stream.of( - unwrapElements(caseData.getHearingOrdersBundlesDrafts()), - unwrapElements(caseData.getHearingOrdersBundlesDraftReview())) - .flatMap(List::stream) - .map(draftOrderBundles -> - Stream.of(draftOrderBundles.getOrders(), draftOrderBundles.getAllChildConfidentialOrders()) - .flatMap(List::stream) - .map(Element::getValue) - .toList()) - .flatMap(List::stream) - .map(HearingOrder::getOrderOrOrderConfidential) - .map(draftOrderDoc -> buildCafcassApiCaseDocument("draftOrders", draftOrderDoc, false)) - .toList(); + return buildCafcassApiCaseDocumentList("draftOrders", false, + Stream.of( + caseData.getHearingOrdersBundlesDrafts(), + caseData.getHearingOrdersBundlesDraftReview()) + .filter(Objects::nonNull) + .flatMap(List::stream) + .map(Element::getValue) + .flatMap(draftOrderBundles -> + Stream.of(draftOrderBundles.getOrders(), draftOrderBundles.getAllChildConfidentialOrders()) + .flatMap(List::stream) + .map(Element::getValue)) + .map(HearingOrder::getOrderOrOrderConfidential)); } private List getApprovedOrders(CaseData caseData) { // Remarks: cafcass don't have permission to read refusedHearingOrders - return Stream.concat( + return buildCafcassApiCaseDocumentList(AA_PARENT_ORDERS, false, + Stream.concat( // approved CMOs unwrapElements(caseData.getSealedCMOs()).stream().map(HearingOrder::getOrderOrOrderConfidential), // approved orders (only those can be read by cafcass) Stream.of(caseData.getOrderCollection(), caseData.getConfidentialOrders().getAllChildConfidentialOrders()) + .filter(Objects::nonNull) .flatMap(List::stream) .map(Element::getValue) - .map(GeneratedOrder::getDocumentOrDocumentConfidential) - ) - .map(sealedCmoDoc -> buildCafcassApiCaseDocument(AA_PARENT_ORDERS, sealedCmoDoc, false)) - .toList(); + .map(GeneratedOrder::getDocumentOrDocumentConfidential))); } private List getOriginalApplications(CaseData caseData) { @@ -128,30 +125,27 @@ private List getOriginalApplications(CaseData caseData) .toList()); } - return documentReferences.stream() - .map(docRef -> buildCafcassApiCaseDocument("originalApplications", docRef, false)) - .toList(); + return buildCafcassApiCaseDocumentList("originalApplications", false, documentReferences); } private List getPlacementApplications(CaseData caseData) { - return unwrapElements(caseData.getPlacementEventData().getPlacements()).stream() - .map(placement -> { - List documentReferences = new ArrayList<>(); - - documentReferences.add(placement.getApplication()); - documentReferences.add(placement.getPlacementNotice()); - documentReferences.addAll(unwrapElements(placement.getConfidentialDocuments()).stream() - .map(PlacementConfidentialDocument::getDocument).toList()); - documentReferences.addAll(unwrapElements(placement.getSupportingDocuments()).stream() - .map(PlacementSupportingDocument::getDocument).toList()); - documentReferences.addAll(unwrapElements(placement.getNoticeDocuments()).stream() - .map(PlacementNoticeDocument::getDocument).toList()); - - return documentReferences; - }) - .flatMap(List::stream) - .map(docRef -> buildCafcassApiCaseDocument(PLACEMENT_RESPONSES, docRef, false)) - .toList(); + return buildCafcassApiCaseDocumentList(PLACEMENT_RESPONSES, false, + unwrapElements(caseData.getPlacementEventData().getPlacements()).stream() + .map(placement -> { + List documentReferences = new ArrayList<>(); + + documentReferences.add(placement.getApplication()); + documentReferences.add(placement.getPlacementNotice()); + documentReferences.addAll(unwrapElements(placement.getConfidentialDocuments()).stream() + .map(PlacementConfidentialDocument::getDocument).toList()); + documentReferences.addAll(unwrapElements(placement.getSupportingDocuments()).stream() + .map(PlacementSupportingDocument::getDocument).toList()); + documentReferences.addAll(unwrapElements(placement.getNoticeDocuments()).stream() + .map(PlacementNoticeDocument::getDocument).toList()); + + return documentReferences; + }) + .flatMap(List::stream)); } private List getAdditionalApplications(CaseData caseData) { @@ -159,7 +153,6 @@ private List getAdditionalApplications(CaseData caseData // additional application unwrapElements(caseData.getAdditionalApplicationsBundle()).forEach(additionalApplicationsBundle -> { - C2DocumentBundle c2Bundle = (additionalApplicationsBundle.isConfidentialC2UploadedByChildSolicitor()) ? additionalApplicationsBundle.getC2DocumentBundleConfidential() : additionalApplicationsBundle.getC2DocumentBundle(); @@ -173,10 +166,7 @@ private List getAdditionalApplications(CaseData caseData c2DocRef.addAll(unwrapElements(c2Bundle.getDraftOrdersBundle()).stream() .map(DraftOrder::getDocument).toList()); - resultList.addAll(c2DocRef.stream() - .map(docRef -> buildCafcassApiCaseDocument(C2_APPLICATION_DOCUMENTS, docRef, - false)) - .toList()); + resultList.addAll(buildCafcassApiCaseDocumentList(C2_APPLICATION_DOCUMENTS, false, c2DocRef)); } OtherApplicationsBundle otherBundle = additionalApplicationsBundle.getOtherApplicationsBundle(); @@ -188,23 +178,20 @@ private List getAdditionalApplications(CaseData caseData otherDocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( otherBundle.getSupportingEvidenceBundle())); - resultList.addAll(otherDocRef.stream() - .map(docRef -> buildCafcassApiCaseDocument(C1_APPLICATION_DOCUMENTS, docRef, - false)) - .toList()); + resultList.addAll(buildCafcassApiCaseDocumentList(C1_APPLICATION_DOCUMENTS, false, otherDocRef)); } }); - return resultList; } private List getAllDocumentsFromSupportingEvidenceBundles(List> bundles) { return unwrapElements(bundles).stream() - .map(supportingEvidenceBundleElement -> List.of(supportingEvidenceBundleElement.getDocument(), + .flatMap(supportingEvidenceBundleElement -> Stream.of( + supportingEvidenceBundleElement.getDocument(), supportingEvidenceBundleElement.getTranslatedDocument())) - .flatMap(List::stream).toList(); + .toList(); } private List getAllDocumentsFromSupplements(List> bundles) { @@ -212,35 +199,31 @@ private List getAllDocumentsFromSupplements(List getHearingNotice(CaseData caseData) { - return unwrapElements(caseData.getHearingDetails()).stream() - .map(hearingBooking -> List.of(hearingBooking.getNoticeOfHearing(), - hearingBooking.getTranslatedNoticeOfHearing())) - .flatMap(List::stream) - .map(docRef -> buildCafcassApiCaseDocument(NOTICE_OF_ACTING_OR_ISSUE, docRef, false)) - .toList(); + return buildCafcassApiCaseDocumentList(NOTICE_OF_ACTING_OR_ISSUE, false, + unwrapElements(caseData.getHearingDetails()).stream() + .flatMap(hearingBooking -> Stream.of( + hearingBooking.getNoticeOfHearing(), + hearingBooking.getTranslatedNoticeOfHearing()))); } private List getManageDocuments(CaseData caseData) { return Arrays.stream(DocumentType.values()) - .filter(documentType -> documentType.getBaseFieldNameResolver() != null) - .map(documentType -> - Stream.concat( - Stream.of(ConfidentialLevel.NON_CONFIDENTIAL, ConfidentialLevel.LA) - .map(confidentialLevel -> manageDocumentService - .toFieldNameToListOfElementMap(caseData, documentType, confidentialLevel).values()) - .flatMap(Collection::stream).flatMap(List::stream), - manageDocumentService.getListOfRemovedElement(caseData, documentType).stream()) + .filter(documentType -> isNotEmpty(documentType.getBaseFieldNameResolver())) + .map(documentType -> buildCafcassApiCaseDocumentList(documentType, false, + Stream.of(ConfidentialLevel.NON_CONFIDENTIAL, ConfidentialLevel.LA) + .map(confidentialLevel -> manageDocumentService + .toFieldNameToListOfElementMap(caseData, documentType, confidentialLevel).values()) + .flatMap(Collection::stream).flatMap(List::stream) .map(Element::getValue) -// .filter(object -> object instanceof WithDocument) + //.filter(object -> object instanceof WithDocument) .map(object -> (WithDocument) object) - .map(doc -> buildCafcassApiCaseDocument(documentType, doc.getDocument(), false)) - .toList()) + .map(WithDocument::getDocument))) .flatMap(List::stream) .toList(); } - private CafcassApiCaseDocument buildCafcassApiCaseDocument(String category, DocumentReference docRef, - boolean removed) { + private CafcassApiCaseDocument buildCafcassApiCaseDocument(String category, boolean removed, + DocumentReference docRef) { return CafcassApiCaseDocument.builder() .documentId(getDocumentIdFromUrl(docRef.getUrl()).toString()) .document_filename(docRef.getFilename()) @@ -249,8 +232,26 @@ private CafcassApiCaseDocument buildCafcassApiCaseDocument(String category, Docu .build(); } - private CafcassApiCaseDocument buildCafcassApiCaseDocument(DocumentType docType, DocumentReference docRef, - boolean removed) { - return buildCafcassApiCaseDocument(docType.getCategory(), docRef, removed); + private List buildCafcassApiCaseDocumentList(DocumentType docType, boolean removed, + List docRefList) { + return buildCafcassApiCaseDocumentList(docType.getCategory(), removed, docRefList); + } + + private List buildCafcassApiCaseDocumentList(String category, boolean removed, + List docRefList) { + return buildCafcassApiCaseDocumentList(category, removed, docRefList.stream()); + } + + private List buildCafcassApiCaseDocumentList(DocumentType category, boolean removed, + Stream docRefList) { + return buildCafcassApiCaseDocumentList(category.getCategory(), removed, docRefList); + } + + private List buildCafcassApiCaseDocumentList(String category, boolean removed, + Stream docRefList) { + return docRefList + .filter(Objects::nonNull) + .map(docRef -> buildCafcassApiCaseDocument(category, removed, docRef)) + .toList(); } } From dada3b202d88c023303a4558f22ec63d57a923fc Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 16:33:17 +0100 Subject: [PATCH 28/51] Create CafcassApiFactorsParentingConverterTest.java --- ...fcassApiFactorsParentingConverterTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverterTest.java new file mode 100644 index 00000000000..43f4ce668f2 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverterTest.java @@ -0,0 +1,48 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.FactorsParenting; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiFactorsParenting; + +public class CafcassApiFactorsParentingConverterTest extends CafcassApiConverterTestBase { + CafcassApiFactorsParentingConverterTest() { + super(new CafcassApiFactorsParentingConverter()); + } + + @Test + void shouldConvertFactorsParenting() { + CaseData caseData = CaseData.builder() + .factorsParenting(FactorsParenting.builder() + .alcoholDrugAbuse(YesNo.YES.getValue()) + .alcoholDrugAbuseReason("alcoholDrugAbuseReason") + .domesticViolence(YesNo.YES.getValue()) + .domesticViolenceReason("domesticViolenceReason") + .anythingElse(YesNo.YES.getValue()) + .anythingElseReason("anythingElseReason") + .build()) + .build(); + + testConvert(caseData, CafcassApiCaseData.builder() + .factorsParenting(CafcassApiFactorsParenting.builder() + .alcoholDrugAbuse(true) + .alcoholDrugAbuseReason("alcoholDrugAbuseReason") + .domesticViolence(true) + .domesticViolenceReason("domesticViolenceReason") + .anythingElse(true) + .anythingElseReason("anythingElseReason") + .build()) + .build()); + } + + @Test + void shouldReturnEmptyIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .factorsParenting(CafcassApiFactorsParenting.builder().build()) + .build(); + testConvert(CaseData.builder().factorsParenting(null).build(), expected); + testConvert(CaseData.builder().factorsParenting(FactorsParenting.builder().build()).build(), expected); + } +} From 555ddbfc421b0ffe7cc1c8be1e972ebf00722183 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 16:47:26 +0100 Subject: [PATCH 29/51] Create CafcassApiHearingDetailsConverterTest.java --- ...CafcassApiHearingDetailsConverterTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverterTest.java new file mode 100644 index 00000000000..88b3da3dd1c --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverterTest.java @@ -0,0 +1,92 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.HearingStatus; +import uk.gov.hmcts.reform.fpl.enums.HearingType; +import uk.gov.hmcts.reform.fpl.enums.hearing.HearingAttendance; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.HearingBooking; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiHearing; +import uk.gov.hmcts.reform.fpl.model.common.Element; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.service.ManageHearingsService.DEFAULT_PRE_ATTENDANCE; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; + +public class CafcassApiHearingDetailsConverterTest extends CafcassApiConverterTestBase { + CafcassApiHearingDetailsConverterTest() { + super(new CafcassApiHearingDetailsConverter()); + } + + @Test + void shouldConvertHearingDetails() { + HearingBooking vacatedHearing = HearingBooking.builder() + .type(HearingType.OTHER) + .typeDetails("typeDetails") + .venue("venue") + .status(HearingStatus.VACATED) + .startDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) + .endDate(LocalDateTime.of(2024, 1, 1, 15, 0, 0)) + .attendance(Arrays.asList(HearingAttendance.values())) + .cancellationReason("cancellationReason") + .preAttendanceDetails("preAttendanceDetails") + .attendanceDetails("attendanceDetails") + .build(); + Element vacatedHearingElement = element(vacatedHearing); + + HearingBooking caseManagementHearing = HearingBooking.builder() + .type(HearingType.CASE_MANAGEMENT) + .venue("venue") + .startDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) + .endDate(LocalDateTime.of(2024, 1, 1, 15, 0, 0)) + .attendance(Arrays.asList(HearingAttendance.values())) + .build(); + Element caseManagementHearingElement = element(caseManagementHearing); + + CaseData caseData = CaseData.builder() + .hearingDetails(List.of(vacatedHearingElement, caseManagementHearingElement)) + .build(); + + CafcassApiHearing expectedVacatedHearing = CafcassApiHearing.builder() + .id(vacatedHearingElement.getId().toString()) + .type(HearingType.OTHER) + .typeDetails("typeDetails") + .venue("venue") + .status(HearingStatus.VACATED) + .startDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) + .endDate(LocalDateTime.of(2024, 1, 1, 15, 0, 0)) + .attendance(Arrays.asList(HearingAttendance.values())) + .cancellationReason("cancellationReason") + .preAttendanceDetails("preAttendanceDetails") + .attendanceDetails("attendanceDetails") + .build(); + + CafcassApiHearing expectedCaseManagementHearing = CafcassApiHearing.builder() + .id(caseManagementHearingElement.getId().toString()) + .type(HearingType.CASE_MANAGEMENT) + .venue("venue") + .startDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) + .endDate(LocalDateTime.of(2024, 1, 1, 15, 0, 0)) + .preAttendanceDetails(DEFAULT_PRE_ATTENDANCE) + .attendance(Arrays.asList(HearingAttendance.values())) + .build(); + + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .hearingDetails(List.of(expectedVacatedHearing, expectedCaseManagementHearing)) + .build(); + + testConvert(caseData, expected); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().hearingDetails(List.of()).build(); + + testConvert(CaseData.builder().hearingDetails(null).build(), expected); + testConvert(CaseData.builder().hearingDetails(List.of()).build(), expected); + } +} From fb8cf502a4bb8dfeb630cafc19356f1d4751170d Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 16:54:48 +0100 Subject: [PATCH 30/51] add CafcassApiInternationalElementConverterTest --- ...fcassApiInternationalElementConverter.java | 1 - ...sApiInternationalElementConverterTest.java | 59 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverterTest.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java index ca48eb84e1f..6206f1fac51 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java @@ -5,7 +5,6 @@ import uk.gov.hmcts.reform.fpl.model.InternationalElement; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiInternationalElement; -import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseDataConverter; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverterTest.java new file mode 100644 index 00000000000..1c7ed110e34 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverterTest.java @@ -0,0 +1,59 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.InternationalElement; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiInternationalElement; + +public class CafcassApiInternationalElementConverterTest extends CafcassApiConverterTestBase { + CafcassApiInternationalElementConverterTest() { + super(new CafcassApiInternationalElementConverter()); + } + + @Test + void shouldConvertInternationalElement() { + CaseData caseData = CaseData.builder() + .internationalElement(InternationalElement.builder() + .possibleCarer(YesNo.YES.getValue()) + .possibleCarerReason("possibleCarerReason") + .significantEvents(YesNo.YES.getValue()) + .significantEventsReason("significantEventsReason") + .issues(YesNo.YES.getValue()) + .issuesReason("issuesReason") + .proceedings(YesNo.YES.getValue()) + .proceedingsReason("proceedingsReason") + .internationalAuthorityInvolvement(YesNo.YES.getValue()) + .internationalAuthorityInvolvementDetails("internationalAuthorityInvolvementDetails") + .build()) + .build(); + + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .internationalElement(CafcassApiInternationalElement.builder() + .possibleCarer(true) + .possibleCarerReason("possibleCarerReason") + .significantEvents(true) + .significantEventsReason("significantEventsReason") + .issues(true) + .issuesReason("issuesReason") + .proceedings(true) + .proceedingsReason("proceedingsReason") + .internationalAuthorityInvolvement(true) + .internationalAuthorityInvolvementDetails("internationalAuthorityInvolvementDetails") + .build()) + .build(); + + testConvert(caseData, expected); + } + + @Test + void shouldReturnEmptyObjectIfNull() { + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .internationalElement(CafcassApiInternationalElement.builder().build()) + .build(); + + testConvert(CaseData.builder().internationalElement(null).build(), expected); + testConvert(CaseData.builder().internationalElement(InternationalElement.builder().build()).build(), expected); + } +} From 1f5d3c6890ad9fdcb87f6734e89e75dbe9444096 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 17:06:02 +0100 Subject: [PATCH 31/51] Create CafcassApiMetaDataConverterTest.java --- .../api/CafcassApiMetaDataConverterTest.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverterTest.java new file mode 100644 index 00000000000..e83923885f2 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverterTest.java @@ -0,0 +1,73 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Orders; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; + +import java.time.LocalDate; +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.enums.OrderType.CARE_ORDER; +import static uk.gov.hmcts.reform.fpl.enums.OrderType.CONTACT_WITH_CHILD_IN_CARE; + +public class CafcassApiMetaDataConverterTest extends CafcassApiConverterTestBase { + CafcassApiMetaDataConverterTest() { + super(new CafcassApiMetaDataConverter()); + } + + @Test + void shouldConvertC1MetaData() { + CaseData caseData = CaseData.builder() + .familyManCaseNumber("familyManCaseNumber") + .dateSubmitted(LocalDate.of(2024, 1, 1)) + .orders(Orders.builder() + .orderType(List.of(CONTACT_WITH_CHILD_IN_CARE)) + .build()) + .dateOfIssue(LocalDate.of(2024, 2, 1)) + .isLocalAuthority(YesNo.NO) + .relatingLA("LA1") + .build(); + + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .familyManCaseNumber("familyManCaseNumber") + .dateSubmitted(LocalDate.of(2024, 1, 1)) + .applicationType("C1") + .ordersSought(List.of(CONTACT_WITH_CHILD_IN_CARE)) + .dateOfCourtIssue(LocalDate.of(2024, 2, 1)) + .citizenIsApplicant(true) + .applicantLA(null) + .respondentLA("LA1") + .build(); + + testConvert(caseData, expected); + } + + @Test + void shouldConvertC110aMetaData() { + CaseData caseData = CaseData.builder() + .familyManCaseNumber("familyManCaseNumber") + .dateSubmitted(LocalDate.of(2024, 1, 1)) + .orders(Orders.builder() + .orderType(List.of(CARE_ORDER)) + .build()) + .dateOfIssue(LocalDate.of(2024, 2, 1)) + .isLocalAuthority(YesNo.YES) + .caseLocalAuthority("LA1") + .build(); + + CafcassApiCaseData expected = CafcassApiCaseData.builder() + .familyManCaseNumber("familyManCaseNumber") + .dateSubmitted(LocalDate.of(2024, 1, 1)) + .applicationType("C110A") + .ordersSought(List.of(CARE_ORDER)) + .dateOfCourtIssue(LocalDate.of(2024, 2, 1)) + .citizenIsApplicant(false) + .applicantLA("LA1") + .respondentLA(null) + .build(); + + testConvert(caseData, expected); + } +} From a6b38ee5038042cb5c3fcafa898d30de51b439bb Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 17:21:33 +0100 Subject: [PATCH 32/51] Create CafcassApiOthersConverterTest.java --- .../api/CafcassApiOthersConverterTest.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverterTest.java new file mode 100644 index 00000000000..d0d378c31bb --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverterTest.java @@ -0,0 +1,97 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Other; +import uk.gov.hmcts.reform.fpl.model.Others; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiOther; +import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.robotics.Gender; + +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; + +public class CafcassApiOthersConverterTest extends CafcassApiConverterTestBase { + CafcassApiOthersConverterTest() { + super(new CafcassApiOthersConverter()); + } + + @Test + void shouldConvertOthers() { + Other firstOthers = Other.builder() + .name("First Other") + .dateOfBirth("2000-01-01") + .gender(Gender.OTHER.toString()) + .genderIdentification("genderIdentification") + .birthPlace("birthPlace") + .addressKnow(YesNo.YES.getValue()) + .address(getTestAddress()) + .telephone(getTestTelephone().getTelephoneNumber()) + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .detailsHidden(YesNo.YES.toString()) + .detailsHiddenReason("detailsHiddenReason") + .build(); + + Other secondOther = Other.builder() + .name("Second Other") + .dateOfBirth("2000-01-01") + .gender(Gender.MALE.toString()) + .birthPlace("birthPlace") + .addressKnow(YesNo.NO.getValue()) + .addressNotKnowReason("addressNotKnowReason") + .detailsHidden(YesNo.NO.toString()) + .build(); + Element secondOtherElement = element(secondOther); + + Other emptyOther = Other.builder().build(); + Element emptyOtherElement = element(emptyOther); + + CaseData caseData = CaseData.builder() + .others(Others.builder() + .firstOther(firstOthers) + .additionalOthers(List.of(secondOtherElement, emptyOtherElement)) + .build()) + .build(); + + List expectedOthers = List.of( + CafcassApiOther.builder() + .name("First Other") + .dateOfBirth("2000-01-01") + .gender(Gender.OTHER.toString()) + .genderIdentification("genderIdentification") + .birthPlace("birthPlace") + .addressKnown(true) + .address(getExpectedAddress()) + .telephone(getExpectedTelephone()) + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .detailsHidden(true) + .detailsHiddenReason("detailsHiddenReason") + .build(), + CafcassApiOther.builder() + .name("Second Other") + .dateOfBirth("2000-01-01") + .gender(Gender.MALE.toString()) + .birthPlace("birthPlace") + .addressKnown(false) + .addressUnknownReason("addressNotKnowReason") + .detailsHidden(false) + .build(), + CafcassApiOther.builder().build() + ); + + testConvert(caseData, CafcassApiCaseData.builder().others(expectedOthers).build()); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().others(List.of()).build(); + + testConvert(CaseData.builder().others(null).build(), expected); + testConvert(CaseData.builder().others(Others.builder().build()).build(), expected); + } +} From 10b59c45618d9de92a8be0f46a87ab844d23e2d3 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 17:38:27 +0100 Subject: [PATCH 33/51] add CafcassApiPreviousProceedingsConverterTest --- ...afcassApiPreviousProceedingsConverter.java | 2 +- ...ssApiPreviousProceedingsConverterTest.java | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverterTest.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java index d445e83aaef..ff3a727f174 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java @@ -24,7 +24,7 @@ private List getCafcassApiProceeding(CaseData caseData) { .map(proceeding -> CafcassApiProceeding.builder() .proceedingStatus(proceeding.getProceedingStatus()) .caseNumber(proceeding.getCaseNumber()) - .started(proceeding.getProceedingStatus()) + .started(proceeding.getStarted()) .ended(proceeding.getEnded()) .ordersMade(proceeding.getOrdersMade()) .judge(proceeding.getJudge()) diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverterTest.java new file mode 100644 index 00000000000..d9ef7218b0a --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverterTest.java @@ -0,0 +1,76 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Proceeding; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiProceeding; + +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; + +public class CafcassApiPreviousProceedingsConverterTest extends CafcassApiConverterTestBase { + CafcassApiPreviousProceedingsConverterTest() { + super(new CafcassApiPreviousProceedingsConverter()); + } + + @Test + void shouldConvertPreviousProceedings() { + Proceeding additionalProceeding = Proceeding.builder() + .proceedingStatus("Previous") + .caseNumber("123") + .sameGuardianNeeded(YesNo.NO.toString()) + .build(); + Proceeding additionalEmptyProceeding = Proceeding.builder().build(); + + Proceeding proceeding = Proceeding.builder() + .proceedingStatus("Ongoing") + .caseNumber("1234567898765432") + .started("2023-05-24") + .ended("2023-05-24") + .ordersMade("C20, C8, etc.") + .judge("District Judge Martin Brown") + .children("Joe Bloggs, Jane Bloggs") + .guardian("John Smith") + .sameGuardianNeeded(YesNo.YES.toString()) + .sameGuardianDetails("Do not need the same guardian for x and y reasons.") + .additionalProceedings(wrapElements(additionalProceeding, additionalEmptyProceeding)) + .build(); + + + CaseData caseData = CaseData.builder() + .proceeding(proceeding) + .build(); + + List expectedList = List.of( + CafcassApiProceeding.builder() + .proceedingStatus("Ongoing") + .caseNumber("1234567898765432") + .started("2023-05-24") + .ended("2023-05-24") + .ordersMade("C20, C8, etc.") + .judge("District Judge Martin Brown") + .children("Joe Bloggs, Jane Bloggs") + .guardian("John Smith") + .sameGuardianNeeded(true) + .sameGuardianDetails("Do not need the same guardian for x and y reasons.") + .build(), + CafcassApiProceeding.builder() + .proceedingStatus("Previous") + .caseNumber("123") + .sameGuardianNeeded(false) + .build(), + CafcassApiProceeding.builder().build() + ); + + testConvert(caseData, CafcassApiCaseData.builder().previousProceedings(expectedList).build()); + } + + @Test + void shouldReturnEmptyListIfNull() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().previousProceedings(List.of()).build(); + testConvert(CaseData.builder().proceeding(null).build(), expected); + } +} From f47773d1d03cbae7a9089cb550ebd5f351fe2fc7 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 18:10:56 +0100 Subject: [PATCH 34/51] refactor and add CafcassApiRespondentsConverterTest --- .../cafcass/api/CafcassApiRespondent.java | 2 +- .../api/CafcassApiChildrenConverter.java | 47 ++++----- .../api/CafcassApiRespondentsConverter.java | 39 ++++---- .../reform/fpl/utils/CafcassApiHelper.java | 27 +++--- .../api/CafcassApiChildrenConverterTest.java | 9 +- .../CafcassApiRespondentsConverterTest.java | 96 +++++++++++++++++++ .../fpl/utils/CafcassApiHelperTest.java | 3 +- 7 files changed, 163 insertions(+), 60 deletions(-) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java index da743a5f97a..78e91815741 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiRespondent.java @@ -19,7 +19,7 @@ public class CafcassApiRespondent { private String telephoneNumber; private String litigationIssues; private String litigationIssuesDetails; - private String contactDetailsHidden; + private boolean contactDetailsHidden; private String contactDetailsHiddenReason; private String relationshipToChild; private CafcassApiSolicitor solicitor; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java index 375db0daa87..3032f81beb8 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java @@ -10,10 +10,12 @@ import java.util.List; import java.util.Optional; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiSolicitor; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getTelephoneNumber; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Component public class CafcassApiChildrenConverter implements CafcassApiCaseDataConverter { @@ -24,30 +26,31 @@ public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, } private List getCafcassApiChild(CaseData caseData) { - return Optional.ofNullable(caseData.getChildren1()).orElse(List.of()).stream() - .map(Element::getValue) + return unwrapElements(caseData.getChildren1()).stream() .map(child -> { + CafcassApiChild.CafcassApiChildBuilder builder = CafcassApiChild.builder() + .solicitor(getCafcassApiSolicitor(child.getSolicitor())); ChildParty childParty = child.getParty(); - return CafcassApiChild.builder() - .firstName(childParty.getFirstName()) - .lastName(childParty.getLastName()) - .dateOfBirth(childParty.getDateOfBirth()) - .gender(childParty.getGender().toString()) - .genderIdentification(childParty.getGenderIdentification()) - .livingSituation(childParty.getLivingSituation()) - .livingSituationDetails(childParty.getLivingSituationDetails()) - .address(getCafcassApiAddress(childParty.getAddress())) - .careAndContactPlan(childParty.getCareAndContactPlan()) - .detailsHidden(isYes(childParty.getDetailsHidden())) - .socialWorkerName(childParty.getSocialWorkerName()) - .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) - .additionalNeeds(isYes(childParty.getAdditionalNeeds())) - .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) - .litigationIssues(childParty.getLitigationIssues()) - .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) - .solicitor(getCafcassApiSolicitor(child.getSolicitor())) - .fathersResponsibility(childParty.getFathersResponsibility()) - .build(); + if (isNotEmpty(childParty)) { + builder = builder.firstName(childParty.getFirstName()) + .lastName(childParty.getLastName()) + .dateOfBirth(childParty.getDateOfBirth()) + .gender(childParty.getGender().toString()) + .genderIdentification(childParty.getGenderIdentification()) + .livingSituation(childParty.getLivingSituation()) + .livingSituationDetails(childParty.getLivingSituationDetails()) + .address(getCafcassApiAddress(childParty.getAddress())) + .careAndContactPlan(childParty.getCareAndContactPlan()) + .detailsHidden(isYes(childParty.getDetailsHidden())) + .socialWorkerName(childParty.getSocialWorkerName()) + .socialWorkerTelephoneNumber(getTelephoneNumber(childParty.getSocialWorkerTelephoneNumber())) + .additionalNeeds(isYes(childParty.getAdditionalNeeds())) + .additionalNeedsDetails(childParty.getAdditionalNeedsDetails()) + .litigationIssues(childParty.getLitigationIssues()) + .litigationIssuesDetails(childParty.getLitigationIssuesDetails()) + .fathersResponsibility(childParty.getFathersResponsibility()); + } + return builder.build(); }) .toList(); } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java index 77e1c78ba03..a0259e1c7d3 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java @@ -10,10 +10,12 @@ import java.util.List; import java.util.Optional; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiSolicitor; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getTelephoneNumber; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Component public class CafcassApiRespondentsConverter implements CafcassApiCaseDataConverter { @@ -24,26 +26,27 @@ public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, } private List getCafcassApiRespondents(CaseData caseData) { - return Optional.ofNullable(caseData.getRespondents1()).orElse(List.of()).stream() - .map(Element::getValue) + return unwrapElements(caseData.getRespondents1()).stream() .map(respondent -> { + CafcassApiRespondent.CafcassApiRespondentBuilder builder = CafcassApiRespondent.builder() + .solicitor(getCafcassApiSolicitor(respondent.getSolicitor())); RespondentParty respondentParty = respondent.getParty(); - return CafcassApiRespondent.builder() - .firstName(respondentParty.getFirstName()) - .lastName(respondentParty.getLastName()) - .gender(respondentParty.getGender()) - .addressKnown(isYes(respondentParty.getAddressKnow())) - .addressUnknownReason(respondentParty.getAddressNotKnowReason()) - .address(getCafcassApiAddress(respondentParty.getAddress())) - .dateOfBirth(respondentParty.getDateOfBirth()) - .telephoneNumber(getTelephoneNumber(respondentParty.getTelephoneNumber())) - .litigationIssues(respondentParty.getLitigationIssues()) - .litigationIssuesDetails(respondentParty.getLitigationIssuesDetails()) - .contactDetailsHidden(respondentParty.getContactDetailsHidden()) - .contactDetailsHiddenReason(respondentParty.getContactDetailsHiddenReason()) - .relationshipToChild(respondentParty.getRelationshipToChild()) - .solicitor(getCafcassApiSolicitor(respondent.getSolicitor())) - .build(); + if (isNotEmpty(respondentParty)) { + builder = builder.firstName(respondentParty.getFirstName()) + .lastName(respondentParty.getLastName()) + .gender(respondentParty.getGender()) + .addressKnown(isYes(respondentParty.getAddressKnow())) + .addressUnknownReason(respondentParty.getAddressNotKnowReason()) + .address(getCafcassApiAddress(respondentParty.getAddress())) + .dateOfBirth(respondentParty.getDateOfBirth()) + .telephoneNumber(getTelephoneNumber(respondentParty.getTelephoneNumber())) + .litigationIssues(respondentParty.getLitigationIssues()) + .litigationIssuesDetails(respondentParty.getLitigationIssuesDetails()) + .contactDetailsHidden(isYes(respondentParty.getContactDetailsHidden())) + .contactDetailsHiddenReason(respondentParty.getContactDetailsHiddenReason()) + .relationshipToChild(respondentParty.getRelationshipToChild()); + } + return builder.build(); }) .toList(); } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java index 7d1f86a90af..61df4b1c448 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelper.java @@ -36,18 +36,19 @@ public static String getTelephoneNumber(Telephone telephone) { } public static CafcassApiSolicitor getCafcassApiSolicitor(RespondentSolicitor respondentSolicitor) { - CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder(); - if (respondentSolicitor != null) { - builder = builder.email(respondentSolicitor.getEmail()); - builder = builder.firstName(respondentSolicitor.getFirstName()); - builder = builder.lastName(respondentSolicitor.getLastName()); - - if (respondentSolicitor.getOrganisation() != null) { - builder = builder.organisationId(respondentSolicitor.getOrganisation().getOrganisationID()); - builder = builder.organisationName(respondentSolicitor.getOrganisation().getOrganisationName()); - } - } - - return builder.build(); + return Optional.ofNullable(respondentSolicitor) + .map(solicitor -> { + CafcassApiSolicitor.CafcassApiSolicitorBuilder builder = CafcassApiSolicitor.builder() + .email(solicitor.getEmail()) + .firstName(solicitor.getFirstName()) + .lastName(solicitor.getLastName()); + + if (solicitor.getOrganisation() != null) { + builder = builder.organisationId(solicitor.getOrganisation().getOrganisationID()) + .organisationName(solicitor.getOrganisation().getOrganisationName()); + } + return builder.build(); + }) + .orElse(null); } } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java index b735b3f8646..2cfa9396a7c 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverterTest.java @@ -8,7 +8,6 @@ import uk.gov.hmcts.reform.fpl.model.ChildParty; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; import java.time.LocalDate; import java.util.List; @@ -56,8 +55,10 @@ void shouldConvertAllChildren() { .build()) .build(); + Child emptyChild = Child.builder().build(); + CaseData caseData = CaseData.builder() - .children1(wrapElements(childWithAllFields, childWithMandatoryFieldOnly)) + .children1(wrapElements(childWithAllFields, childWithMandatoryFieldOnly, emptyChild)) .build(); testConvert(caseData, CafcassApiCaseData.builder() @@ -87,8 +88,8 @@ void shouldConvertAllChildren() { .lastName("Two") .dateOfBirth(LocalDate.of(2023, 1, 1)) .gender(ChildGender.GIRL.toString()) - .solicitor(CafcassApiSolicitor.builder().build()) - .build() + .build(), + CafcassApiChild.builder().build() )).build()); } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java new file mode 100644 index 00000000000..b1fdaa2945f --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java @@ -0,0 +1,96 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Respondent; +import uk.gov.hmcts.reform.fpl.model.RespondentParty; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRespondent; +import uk.gov.hmcts.reform.fpl.model.robotics.Gender; + +import java.time.LocalDate; +import java.util.List; + +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; + +public class CafcassApiRespondentsConverterTest extends CafcassApiConverterTestBase { + CafcassApiRespondentsConverterTest( ) { + super(new CafcassApiRespondentsConverter()); + } + + @Test + void shouldConvertAllRespondents() { + Respondent respondentWithAddressHidden = Respondent.builder() + .solicitor(getTestRespondentSolicitor()) + .party(RespondentParty.builder() + .firstName("Respondent1") + .lastName("LastName") + .gender(Gender.MALE.toString()) + .addressKnow(YesNo.YES.toString()) + .address(getTestAddress()) + .dateOfBirth(LocalDate.of(2000, 1, 1)) + .telephoneNumber(getTestTelephone()) + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .contactDetailsHidden(YesNo.YES.toString()) + .contactDetailsHiddenReason("contactDetailsHiddenReason") + .relationshipToChild("relationshipToChild") + .build()) + .build(); + + Respondent respondentWithMandatoryFieldOnly = Respondent.builder() + .party(RespondentParty.builder() + .firstName("Respondent2") + .lastName("LastName") + .gender(Gender.MALE.toString()) + .addressKnow(YesNo.NO.toString()) + .addressNotKnowReason("addressUnknownReason") + .relationshipToChild("relationshipToChild") + .build()) + .build(); + + Respondent emptyRespondent = Respondent.builder().build(); + + CaseData caseData = CaseData.builder() + .respondents1(wrapElements(respondentWithAddressHidden, respondentWithMandatoryFieldOnly, emptyRespondent)) + .build(); + + List expectedList = List.of( + CafcassApiRespondent.builder() + .firstName("Respondent1") + .lastName("LastName") + .gender(Gender.MALE.toString()) + .addressKnown(true) + .address(getExpectedAddress()) + .dateOfBirth(LocalDate.of(2000, 1, 1)) + .telephoneNumber(getExpectedTelephone()) + .litigationIssues("litigationIssues") + .litigationIssuesDetails("litigationIssuesDetails") + .contactDetailsHidden(true) + .contactDetailsHiddenReason("contactDetailsHiddenReason") + .relationshipToChild("relationshipToChild") + .solicitor(getExpectedSolicitor()) + .build(), + CafcassApiRespondent.builder() + .firstName("Respondent2") + .lastName("LastName") + .gender(Gender.MALE.toString()) + .addressKnown(false) + .addressUnknownReason("addressUnknownReason") + .relationshipToChild("relationshipToChild") + .build(), + CafcassApiRespondent.builder().build() + ); + + testConvert(caseData, CafcassApiCaseData.builder().respondents(expectedList).build()); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().respondents(List.of()).build(); + + testConvert(CaseData.builder().respondents1(null).build(), expected); + testConvert(CaseData.builder().respondents1(List.of()).build(), expected); + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java index 9a4922c036c..ede10eec0e9 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java @@ -79,7 +79,6 @@ public void testGetCafcassApiSolicitor() { .build(); assertEquals(expected, CafcassApiHelper.getCafcassApiSolicitor(solicitor)); - assertEquals(CafcassApiSolicitor.builder().build(), - CafcassApiHelper.getCafcassApiSolicitor(null)); + assertNull(CafcassApiHelper.getCafcassApiSolicitor(null)); } } From a6312ab55b647cc2d78194ab542432ed47fe00bc Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 18:17:40 +0100 Subject: [PATCH 35/51] Create CafcassApiRisksConverterTest.java --- .../api/CafcassApiRisksConverterTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverterTest.java new file mode 100644 index 00000000000..80b6c3e0cea --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverterTest.java @@ -0,0 +1,49 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.YesNo; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.Risks; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRisk; + +import java.util.List; + +public class CafcassApiRisksConverterTest extends CafcassApiConverterTestBase { + CafcassApiRisksConverterTest() { + super(new CafcassApiRisksConverter()); + } + + @Test + void shouldConvertRisk() { + CaseData caseData = CaseData.builder() + .risks(Risks.builder() + .neglect(YesNo.YES.toString()) + .neglectOccurrences(List.of("Future risk of harm")) + .sexualAbuse(YesNo.YES.toString()) + .sexualAbuseOccurrences(List.of("Past harm")) + .physicalHarm(YesNo.YES.toString()) + .physicalHarmOccurrences(List.of("Future risk of harm", "Past harm")) + .emotionalHarm(YesNo.YES.toString()) + .emotionalHarmOccurrences(List.of("Future risk of harm", "Past harm")) + .build()) + .build(); + + testConvert(caseData, CafcassApiCaseData.builder() + .risks(CafcassApiRisk.builder() + .neglectOccurrences(List.of("Future risk of harm")) + .sexualAbuseOccurrences(List.of("Past harm")) + .physicalHarmOccurrences(List.of("Future risk of harm", "Past harm")) + .emotionalHarmOccurrences(List.of("Future risk of harm", "Past harm")) + .build()) + .build()); + } + + @Test + void shouldReturnEmptyObjectIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().risks(CafcassApiRisk.builder().build()).build(); + + testConvert(CaseData.builder().risks(null).build(), expected); + testConvert(CaseData.builder().risks(Risks.builder().build()).build(), expected); + } +} From 9a564a2217d93817bdbf67f262461ee886c65deb Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 25 Jul 2024 18:49:48 +0100 Subject: [PATCH 36/51] add sdo and udo converter test --- .../CafcassApiCaseDocumentsConverterTest.java | 88 +++++++++++++++++++ .../api/CafcassApiConverterTestBase.java | 17 ++++ 2 files changed, 105 insertions(+) create mode 100644 service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java new file mode 100644 index 00000000000..bb021c417c3 --- /dev/null +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java @@ -0,0 +1,88 @@ +package uk.gov.hmcts.reform.fpl.service.cafcass.api; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; +import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.StandardDirectionOrder; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; +import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; +import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.AA_PARENT_ORDERS; +import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; + +public class CafcassApiCaseDocumentsConverterTest extends CafcassApiConverterTestBase { + private static final ManageDocumentService manageDocumentService = mock(ManageDocumentService.class); + + CafcassApiCaseDocumentsConverterTest() { + super(new CafcassApiCaseDocumentsConverter(manageDocumentService)); + } + + private List getExpectedCafcassApiCaseDocuments(String category, boolean removed, + List docRefs) { + return docRefs.stream().map(docRef -> CafcassApiCaseDocument.builder() + .documentId(getDocumentIdFromUrl(docRef.getUrl()).toString()) + .document_filename(docRef.getFilename()) + .documentCategory(category) + .removed(removed) + .build()) + .toList(); + } + + private void testCaseDocument(CaseData caseData, List documentReferences, + DocumentType documentType) { + testCaseDocument(caseData, documentReferences, documentType.getCategory()); + } + + private void testCaseDocument(CaseData caseData, List documentReferences, String category) { + CafcassApiCaseData actual = testConvert(caseData); + assertThat(actual.getCaseDocuments()) + .containsAll(getExpectedCafcassApiCaseDocuments(category, false, documentReferences)); + + } + + @Nested + class StandardAndUrgentDirectionOrder { + @Test + void shouldConvertStandardAndUrgentDirectionOrder() { + DocumentReference sdoOrder = getTestDocumentReference(); + DocumentReference sdoTranslatedOrder = getTestDocumentReference(); + DocumentReference udoOrder = getTestDocumentReference(); + DocumentReference udoTranslatedOrder = getTestDocumentReference(); + + CaseData caseData = CaseData.builder() + .standardDirectionOrder(StandardDirectionOrder.builder() + .orderDoc(sdoOrder) + .translatedOrderDoc(sdoTranslatedOrder) + .build()) + .urgentDirectionsOrder(StandardDirectionOrder.builder() + .orderDoc(udoOrder) + .translatedOrderDoc(udoTranslatedOrder) + .build()) + .build(); + + testCaseDocument(caseData, List.of(sdoOrder, sdoTranslatedOrder, udoOrder, udoTranslatedOrder), + AA_PARENT_ORDERS); + } + + @Test + void shouldReturnEmptyListIfDocumentNotExist() { + testConvert(CaseData.builder() + .standardDirectionOrder(StandardDirectionOrder.builder().build()) + .urgentDirectionsOrder(StandardDirectionOrder.builder().build()).build(), + CafcassApiCaseData.builder().caseDocuments(List.of()).build()); + } + + @Test + void shouldReturnEmptyListIfNull() { + testConvert(CaseData.builder().standardDirectionOrder(null).urgentDirectionsOrder(null).build(), + CafcassApiCaseData.builder().caseDocuments(List.of()).build()); + } + } +} diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java index 0af090ce662..b0dce55de53 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java @@ -11,9 +11,13 @@ import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; +import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; import uk.gov.hmcts.reform.fpl.model.common.Telephone; import uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper; +import java.util.UUID; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; import static org.junit.jupiter.api.Assertions.assertEquals; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; @@ -31,6 +35,10 @@ public CafcassApiCaseData testConvert(CaseData caseData, CafcassApiCaseData expe return actual; } + public CafcassApiCaseData testConvert(CaseData caseData) { + return underTest.convert(caseData, CafcassApiCaseData.builder()).build(); + } + public static Address getTestAddress() { return getTestAddress("address line 1"); } @@ -127,4 +135,13 @@ public static CafcassApiSolicitor getExpectedSolicitor(int solicitorNo) { .organisationName(testOrg.getOrganisationName()) .build(); } + + public static DocumentReference getTestDocumentReference() { + UUID docId = UUID.randomUUID(); + return DocumentReference.builder() + .filename(randomAlphanumeric(10)) + .url("test.link/" + docId) + .binaryUrl("test.link/" + docId + "/binary") + .build(); + } } From 09e26b81d1a91851d35bda869f7a737a00ebdd82 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Fri, 26 Jul 2024 15:41:45 +0100 Subject: [PATCH 37/51] add draft oder converting test --- .../CafcassApiCaseDocumentsConverterTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java index bb021c417c3..7f77a2c17ad 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java @@ -8,6 +8,9 @@ import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; +import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; +import uk.gov.hmcts.reform.fpl.model.order.HearingOrdersBundle; import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; import java.util.List; @@ -16,6 +19,7 @@ import static org.mockito.Mockito.mock; import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.AA_PARENT_ORDERS; import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; public class CafcassApiCaseDocumentsConverterTest extends CafcassApiConverterTestBase { private static final ManageDocumentService manageDocumentService = mock(ManageDocumentService.class); @@ -85,4 +89,50 @@ void shouldReturnEmptyListIfNull() { CafcassApiCaseData.builder().caseDocuments(List.of()).build()); } } + + @Nested + class DraftOrders { + private final static DocumentReference DRAFT_ORDER = getTestDocumentReference(); + private final static DocumentReference DRAFT_ORDER_CONFIDENTIAL = getTestDocumentReference(); + private final static DocumentReference DRAFT_ORDER_REVIEW = getTestDocumentReference(); + private final static DocumentReference DRAFT_ORDER_REVIEW_CONFIDENTIAL = getTestDocumentReference(); + + @Test + void shouldConvertDraftOrders() { + List> hearingOrdersBundlesDrafts = wrapElements( + HearingOrdersBundle.builder() + .orders(wrapElements(HearingOrder.builder().order(DRAFT_ORDER).build())) + .build(), + HearingOrdersBundle.builder() + .ordersChild0(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) + .build()); + List> hearingOrdersBundlesDraftReview = wrapElements( + HearingOrdersBundle.builder() + .orders(wrapElements(HearingOrder.builder().order(DRAFT_ORDER_REVIEW).build())) + .build(), + HearingOrdersBundle.builder() + .ordersResp0(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_REVIEW_CONFIDENTIAL).build())) + .build()); + + CaseData caseData = CaseData.builder() + .hearingOrdersBundlesDrafts(hearingOrdersBundlesDrafts) + .hearingOrdersBundlesDraftReview(hearingOrdersBundlesDraftReview) + .build(); + + testCaseDocument(caseData, List.of(DRAFT_ORDER, DRAFT_ORDER_CONFIDENTIAL, DRAFT_ORDER_REVIEW), + "draftOrders"); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + CafcassApiCaseData expected = CafcassApiCaseData.builder().caseDocuments(List.of()).build(); + testConvert(CaseData.builder().hearingOrdersBundlesDrafts(null) + .hearingOrdersBundlesDraftReview(null).build(), expected); + testConvert( + CaseData.builder().hearingOrdersBundlesDrafts(List.of()) + .hearingOrdersBundlesDraftReview(List.of()).build(), expected); + } + } } From 392a1b22ebeecd67519c9d9e651faab93a2756de Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Fri, 26 Jul 2024 16:17:01 +0100 Subject: [PATCH 38/51] refactor to service --- .../service/cafcass/api/CafcassApiApplicantsConverter.java | 4 ++-- .../cafcass/api/CafcassApiCaseDocumentsConverter.java | 3 ++- .../api/CafcassApiCaseManagementLocationConverter.java | 4 ++-- .../service/cafcass/api/CafcassApiChildrenConverter.java | 6 ++---- .../cafcass/api/CafcassApiFactorsParentingConverter.java | 4 ++-- .../cafcass/api/CafcassApiHearingDetailsConverter.java | 4 ++-- .../api/CafcassApiInternationalElementConverter.java | 4 ++-- .../service/cafcass/api/CafcassApiMetaDataConverter.java | 4 ++-- .../fpl/service/cafcass/api/CafcassApiOthersConverter.java | 6 +++--- .../cafcass/api/CafcassApiPreviousProceedingsConverter.java | 4 ++-- .../service/cafcass/api/CafcassApiRespondentsConverter.java | 6 ++---- .../fpl/service/cafcass/api/CafcassApiRisksConverter.java | 4 ++-- 12 files changed, 25 insertions(+), 28 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java index af7b12ffc14..fdf362083f0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiApplicantsConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.LocalAuthority; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; @@ -14,7 +14,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; -@Component +@Service public class CafcassApiApplicantsConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index 59d70e0a2e1..f9977cfa7e7 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; @@ -43,7 +44,7 @@ import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; -@Component +@Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassApiCaseDocumentsConverter implements CafcassApiCaseDataConverter { private final ManageDocumentService manageDocumentService; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java index 9784f4c6288..1ad1d21c3dd 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseManagementLocationConverter.java @@ -1,12 +1,12 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.model.CaseLocation; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseManagementLocation; -@Component +@Service public class CafcassApiCaseManagementLocationConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java index 3032f81beb8..7bef6661fbb 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiChildrenConverter.java @@ -1,14 +1,12 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.ChildParty; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; -import uk.gov.hmcts.reform.fpl.model.common.Element; import java.util.List; -import java.util.Optional; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; @@ -17,7 +15,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; -@Component +@Service public class CafcassApiChildrenConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java index 3f1e5d245da..54f522a38a8 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiFactorsParentingConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.FactorsParenting; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; @@ -8,7 +8,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; -@Component +@Service public class CafcassApiFactorsParentingConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java index 1a57499ed47..edc15aa85a8 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiHearingDetailsConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.HearingBooking; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; @@ -9,7 +9,7 @@ import java.util.List; import java.util.Optional; -@Component +@Service public class CafcassApiHearingDetailsConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java index 6206f1fac51..f546364bb1e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiInternationalElementConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.InternationalElement; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; @@ -8,7 +8,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; -@Component +@Service public class CafcassApiInternationalElementConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java index a919ee551ac..2c989b3979a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiMetaDataConverter.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.enums.YesNo; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; -@Component +@Service public class CafcassApiMetaDataConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java index 83c99b4f321..a20e4f8ac09 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiOther; @@ -10,11 +10,11 @@ import java.util.Optional; import java.util.stream.Stream; -import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; -@Component +@Service public class CafcassApiOthersConverter implements CafcassApiCaseDataConverter{ @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java index ff3a727f174..6004e171c94 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiPreviousProceedingsConverter.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiProceeding; @@ -10,7 +10,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; -@Component +@Service public class CafcassApiPreviousProceedingsConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java index a0259e1c7d3..9c2a5e5ea16 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverter.java @@ -1,14 +1,12 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.RespondentParty; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRespondent; -import uk.gov.hmcts.reform.fpl.model.common.Element; import java.util.List; -import java.util.Optional; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.getCafcassApiAddress; @@ -17,7 +15,7 @@ import static uk.gov.hmcts.reform.fpl.utils.CafcassApiHelper.isYes; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; -@Component +@Service public class CafcassApiRespondentsConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java index 0d320c7d7a8..90e49ae4c3e 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRisksConverter.java @@ -1,12 +1,12 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.Risks; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRisk; -@Component +@Service public class CafcassApiRisksConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, From d633668fee1779802d4fa5ea986ac3dbb5187eb7 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Fri, 26 Jul 2024 17:30:50 +0100 Subject: [PATCH 39/51] original application test --- .../CafcassApiCaseDocumentsConverterTest.java | 202 ++++++++++++++++-- 1 file changed, 184 insertions(+), 18 deletions(-) diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java index 7f77a2c17ad..d800602f69b 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java @@ -4,13 +4,19 @@ import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; +import uk.gov.hmcts.reform.fpl.model.ConfidentialGeneratedOrders; import uk.gov.hmcts.reform.fpl.model.StandardDirectionOrder; +import uk.gov.hmcts.reform.fpl.model.Supplement; +import uk.gov.hmcts.reform.fpl.model.SupportingEvidenceBundle; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.common.SubmittedC1WithSupplementBundle; +import uk.gov.hmcts.reform.fpl.model.group.C110A; import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrdersBundle; +import uk.gov.hmcts.reform.fpl.model.order.generated.GeneratedOrder; import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; import java.util.List; @@ -77,16 +83,18 @@ void shouldConvertStandardAndUrgentDirectionOrder() { @Test void shouldReturnEmptyListIfDocumentNotExist() { - testConvert(CaseData.builder() + testCaseDocument( + CaseData.builder() .standardDirectionOrder(StandardDirectionOrder.builder().build()) .urgentDirectionsOrder(StandardDirectionOrder.builder().build()).build(), - CafcassApiCaseData.builder().caseDocuments(List.of()).build()); + List.of(), "draftOrders"); } @Test void shouldReturnEmptyListIfNull() { - testConvert(CaseData.builder().standardDirectionOrder(null).urgentDirectionsOrder(null).build(), - CafcassApiCaseData.builder().caseDocuments(List.of()).build()); + testCaseDocument( + CaseData.builder().standardDirectionOrder(null).urgentDirectionsOrder(null).build(), + List.of(), "draftOrders"); } } @@ -94,11 +102,9 @@ void shouldReturnEmptyListIfNull() { class DraftOrders { private final static DocumentReference DRAFT_ORDER = getTestDocumentReference(); private final static DocumentReference DRAFT_ORDER_CONFIDENTIAL = getTestDocumentReference(); - private final static DocumentReference DRAFT_ORDER_REVIEW = getTestDocumentReference(); - private final static DocumentReference DRAFT_ORDER_REVIEW_CONFIDENTIAL = getTestDocumentReference(); @Test - void shouldConvertDraftOrders() { + void shouldConvertDraftOrdersAndConfidentialOrdersUploadedByChildSolicitor() { List> hearingOrdersBundlesDrafts = wrapElements( HearingOrdersBundle.builder() .orders(wrapElements(HearingOrder.builder().order(DRAFT_ORDER).build())) @@ -107,32 +113,192 @@ void shouldConvertDraftOrders() { .ordersChild0(wrapElements(HearingOrder.builder() .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) .build()); + + CaseData caseData = CaseData.builder() + .hearingOrdersBundlesDrafts(hearingOrdersBundlesDrafts) + .build(); + + testCaseDocument(caseData, List.of(DRAFT_ORDER, DRAFT_ORDER_CONFIDENTIAL), "draftOrders"); + } + + @Test + void shouldConvertDraftOrdersReviewAndConfidentialOrdersUploadedByChildSolicitor() { List> hearingOrdersBundlesDraftReview = wrapElements( HearingOrdersBundle.builder() - .orders(wrapElements(HearingOrder.builder().order(DRAFT_ORDER_REVIEW).build())) + .orders(wrapElements(HearingOrder.builder().order(DRAFT_ORDER).build())) .build(), HearingOrdersBundle.builder() - .ordersResp0(wrapElements(HearingOrder.builder() - .orderConfidential(DRAFT_ORDER_REVIEW_CONFIDENTIAL).build())) + .ordersChild0(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) + .build()); + CaseData caseData = CaseData.builder() + .hearingOrdersBundlesDraftReview(hearingOrdersBundlesDraftReview) + .build(); + testCaseDocument(caseData, List.of(DRAFT_ORDER, DRAFT_ORDER_CONFIDENTIAL), "draftOrders"); + } + + @Test + void shouldNotConvertConfidentialOrdersNotUploadedByChildSolicitor() { + List> hearingOrdersBundlesDrafts = wrapElements( + HearingOrdersBundle.builder() + .ordersCTSC(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) + .build(), + HearingOrdersBundle.builder() + .ordersLA(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) .build()); + List> hearingOrdersBundlesDraftReview = wrapElements( + HearingOrdersBundle.builder() + .ordersResp0(wrapElements(HearingOrder.builder() + .orderConfidential(DRAFT_ORDER_CONFIDENTIAL).build())) + .build()); CaseData caseData = CaseData.builder() .hearingOrdersBundlesDrafts(hearingOrdersBundlesDrafts) .hearingOrdersBundlesDraftReview(hearingOrdersBundlesDraftReview) .build(); - testCaseDocument(caseData, List.of(DRAFT_ORDER, DRAFT_ORDER_CONFIDENTIAL, DRAFT_ORDER_REVIEW), - "draftOrders"); + testCaseDocument(caseData, List.of(), "draftOrders"); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + testCaseDocument( + CaseData.builder().hearingOrdersBundlesDrafts(null).hearingOrdersBundlesDraftReview(null).build(), + List.of(), "draftOrders"); + testCaseDocument( + CaseData.builder() + .hearingOrdersBundlesDrafts(List.of()) + .hearingOrdersBundlesDraftReview(List.of()).build(), + List.of(), "draftOrders"); + } + } + + @Nested + class ApprovedOrder { + private static final DocumentReference SEALED_CMO = getTestDocumentReference(); + private static final DocumentReference SEALED_CMO_CONFIDENTIAL = getTestDocumentReference(); + private static final DocumentReference APPROVED_ORDER = getTestDocumentReference(); + private static final DocumentReference APPROVED_ORDER_CONFIDENTIAL = getTestDocumentReference(); + @Test + void shouldConvertSealedCmosAndOrders() { + CaseData caseData = CaseData.builder() + .sealedCMOs(wrapElements( + HearingOrder.builder() + .order(SEALED_CMO) + .build(), + HearingOrder.builder() + .orderConfidential(SEALED_CMO_CONFIDENTIAL) + .build() + )) + .orderCollection(wrapElements(GeneratedOrder.builder().document(APPROVED_ORDER).build())) + .confidentialOrders(ConfidentialGeneratedOrders.builder() + .orderCollectionChild0(wrapElements( + GeneratedOrder.builder().document(APPROVED_ORDER_CONFIDENTIAL).build())) + .build()) + .build(); + + testCaseDocument(caseData, + List.of(SEALED_CMO, SEALED_CMO_CONFIDENTIAL, APPROVED_ORDER, APPROVED_ORDER_CONFIDENTIAL), + AA_PARENT_ORDERS); + } + + @Test + void shouldNotConvertConfidentialOrderNotUploadedByChildSolicitor() { + CaseData caseData = CaseData.builder() + .confidentialOrders(ConfidentialGeneratedOrders.builder() + .orderCollectionCTSC(wrapElements( + GeneratedOrder.builder().document(APPROVED_ORDER_CONFIDENTIAL).build())) + .orderCollectionLA(wrapElements( + GeneratedOrder.builder().document(APPROVED_ORDER_CONFIDENTIAL).build())) + .orderCollectionResp0(wrapElements( + GeneratedOrder.builder().document(APPROVED_ORDER_CONFIDENTIAL).build())) + .build()) + .build(); + testCaseDocument(caseData, List.of(), AA_PARENT_ORDERS); + } + + @Test + void shouldReturnEmptyListIfNullOrEmpty() { + testCaseDocument(CaseData.builder().build(), List.of(), AA_PARENT_ORDERS); + + testCaseDocument( + CaseData.builder() + .sealedCMOs(List.of()).orderCollection(List.of()) + .confidentialOrders(ConfidentialGeneratedOrders.builder().build()) + .build(), + List.of(), AA_PARENT_ORDERS); + + testCaseDocument( + CaseData.builder() + .confidentialOrders(ConfidentialGeneratedOrders.builder() + .orderCollectionResp0(List.of()) + .orderCollectionChild0(List.of()) + .build()) + .build(), + List.of(), AA_PARENT_ORDERS); + } + } + + @Nested + class OriginalApplications { + DocumentReference APPLICATION_DOC = getTestDocumentReference(); + DocumentReference APPLICATION_TRANSLATED_DOC = getTestDocumentReference(); + DocumentReference SUPPLEMENT_DOC = getTestDocumentReference(); + Supplement SUPPLEMENT = Supplement.builder().document(SUPPLEMENT_DOC).build(); + DocumentReference SUPPORTING_EVIDENCE_DOC = getTestDocumentReference(); + DocumentReference SUPPORTING_EVIDENCE_TRANSLATEDDOC = getTestDocumentReference(); + SupportingEvidenceBundle supportingEvidence = SupportingEvidenceBundle.builder() + .document(SUPPORTING_EVIDENCE_DOC) + .translatedDocument(SUPPORTING_EVIDENCE_TRANSLATEDDOC) + .build(); + + @Test + void shouldConvertC1OriginalApplicationDocument() { + CaseData caseData = CaseData.builder() + .submittedC1WithSupplement(SubmittedC1WithSupplementBundle.builder() + .document(APPLICATION_DOC) + .supplementsBundle(wrapElements(SUPPLEMENT)) + .supportingEvidenceBundle(wrapElements(supportingEvidence)) + .build()) + .build(); + + testCaseDocument( + caseData, + List.of(APPLICATION_DOC, SUPPLEMENT_DOC, SUPPORTING_EVIDENCE_DOC, SUPPORTING_EVIDENCE_TRANSLATEDDOC), + "originalApplications"); + } + + @Test + void shouldConvertC110AOriginalApplicationDocument() { + CaseData caseData = CaseData.builder() + .c110A(C110A.builder() + .submittedForm(APPLICATION_DOC) + .translatedSubmittedForm(APPLICATION_TRANSLATED_DOC) + .supplementDocument(SUPPLEMENT_DOC) + .build()) + .build(); + + testCaseDocument( + caseData, + List.of(APPLICATION_DOC, APPLICATION_TRANSLATED_DOC, SUPPLEMENT_DOC), + "originalApplications"); } @Test void shouldReturnEmptyListIfNullOrEmpty() { - CafcassApiCaseData expected = CafcassApiCaseData.builder().caseDocuments(List.of()).build(); - testConvert(CaseData.builder().hearingOrdersBundlesDrafts(null) - .hearingOrdersBundlesDraftReview(null).build(), expected); - testConvert( - CaseData.builder().hearingOrdersBundlesDrafts(List.of()) - .hearingOrdersBundlesDraftReview(List.of()).build(), expected); + testCaseDocument( + CaseData.builder().c110A(null).submittedC1WithSupplement(null).build(), + List.of(), + "originalApplications"); + + testCaseDocument( + CaseData.builder().c110A( + C110A.builder().build()) + .submittedC1WithSupplement(SubmittedC1WithSupplementBundle.builder().build()).build(), + List.of(), + "originalApplications"); } } } From 465137319c8a0172b7ce33d97789819def79c0f5 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 17:24:08 +0100 Subject: [PATCH 40/51] add managed doc test --- .../api/CafcassApiCaseDocumentsConverter.java | 3 - .../CafcassApiCaseDocumentsConverterTest.java | 302 +++++++++++++++++- 2 files changed, 301 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index f9977cfa7e7..53d8c928ab4 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -1,9 +1,7 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import com.google.common.collect.ImmutableList; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; @@ -32,7 +30,6 @@ import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.stream.Stream; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java index d800602f69b..9505d1250c1 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java @@ -1,30 +1,65 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; +import com.google.common.collect.ImmutableMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.mockito.Mockito; +import org.springframework.test.annotation.DirtiesContext; +import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.ConfidentialGeneratedOrders; +import uk.gov.hmcts.reform.fpl.model.ManagedDocument; +import uk.gov.hmcts.reform.fpl.model.Placement; +import uk.gov.hmcts.reform.fpl.model.PlacementConfidentialDocument; +import uk.gov.hmcts.reform.fpl.model.PlacementNoticeDocument; +import uk.gov.hmcts.reform.fpl.model.PlacementSupportingDocument; import uk.gov.hmcts.reform.fpl.model.StandardDirectionOrder; import uk.gov.hmcts.reform.fpl.model.Supplement; import uk.gov.hmcts.reform.fpl.model.SupportingEvidenceBundle; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; +import uk.gov.hmcts.reform.fpl.model.common.AdditionalApplicationsBundle; +import uk.gov.hmcts.reform.fpl.model.common.C2DocumentBundle; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.model.common.OtherApplicationsBundle; import uk.gov.hmcts.reform.fpl.model.common.SubmittedC1WithSupplementBundle; +import uk.gov.hmcts.reform.fpl.model.event.PlacementEventData; import uk.gov.hmcts.reform.fpl.model.group.C110A; +import uk.gov.hmcts.reform.fpl.model.interfaces.WithDocument; +import uk.gov.hmcts.reform.fpl.model.order.DraftOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrdersBundle; import uk.gov.hmcts.reform.fpl.model.order.generated.GeneratedOrder; import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Stream; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel.CTSC; +import static uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel.LA; +import static uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel.NON_CONFIDENTIAL; import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.AA_PARENT_ORDERS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.C1_APPLICATION_DOCUMENTS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.C2_APPLICATION_DOCUMENTS; +import static uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType.PLACEMENT_RESPONSES; import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.getDocumentIdFromUrl; +import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; public class CafcassApiCaseDocumentsConverterTest extends CafcassApiConverterTestBase { @@ -53,7 +88,7 @@ private void testCaseDocument(CaseData caseData, List documen private void testCaseDocument(CaseData caseData, List documentReferences, String category) { CafcassApiCaseData actual = testConvert(caseData); assertThat(actual.getCaseDocuments()) - .containsAll(getExpectedCafcassApiCaseDocuments(category, false, documentReferences)); + .containsOnlyOnceElementsOf(getExpectedCafcassApiCaseDocuments(category, false, documentReferences)); } @@ -301,4 +336,269 @@ void shouldReturnEmptyListIfNullOrEmpty() { "originalApplications"); } } + + @Nested + class PlacementApplications { + private static final DocumentReference PLACEMENT_APPLICATION_1 = getTestDocumentReference(); + private static final DocumentReference PLACEMENT_APPLICATION_2 = getTestDocumentReference(); + private static final DocumentReference PLACEMENT_NOTICE_DOCUMENT_1 = getTestDocumentReference(); + private static final DocumentReference PLACEMENT_NOTICE_DOCUMENT_2 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOCUMENT_1 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOCUMENT_2 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOCUMENT_3 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOCUMENT_4 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_DOCUMENT_1 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_DOCUMENT_2 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_DOCUMENT_3 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_DOCUMENT_4 = getTestDocumentReference(); + private static final DocumentReference NOTICE_DOCUMENT_1 = getTestDocumentReference(); + private static final DocumentReference NOTICE_DOCUMENT_2 = getTestDocumentReference(); + private static final DocumentReference NOTICE_DOCUMENT_3 = getTestDocumentReference(); + private static final DocumentReference NOTICE_DOCUMENT_4 = getTestDocumentReference(); + + @Test + void shouldConvertAllPlacementApplications() { + final Placement placement1 = Placement.builder() + .application(PLACEMENT_APPLICATION_1) + .placementNotice(PLACEMENT_NOTICE_DOCUMENT_1) + .confidentialDocuments(wrapElements( + PlacementConfidentialDocument.builder().document(CONFIDENTIAL_DOCUMENT_1).build(), + PlacementConfidentialDocument.builder().document(CONFIDENTIAL_DOCUMENT_3).build() + )) + .supportingDocuments(wrapElements( + PlacementSupportingDocument.builder().document(SUPPORTING_DOCUMENT_1).build(), + PlacementSupportingDocument.builder().document(SUPPORTING_DOCUMENT_3).build() + )) + .noticeDocuments(wrapElements( + PlacementNoticeDocument.builder().response(NOTICE_DOCUMENT_1).build(), + PlacementNoticeDocument.builder().response(NOTICE_DOCUMENT_3).build() + )) + .build(); + + + final Placement placement2 = Placement.builder() + .application(PLACEMENT_APPLICATION_2) + .placementNotice(PLACEMENT_NOTICE_DOCUMENT_2) + .confidentialDocuments(wrapElements( + PlacementConfidentialDocument.builder().document(CONFIDENTIAL_DOCUMENT_2).build(), + PlacementConfidentialDocument.builder().document(CONFIDENTIAL_DOCUMENT_4).build() + )) + .supportingDocuments(wrapElements( + PlacementSupportingDocument.builder().document(SUPPORTING_DOCUMENT_2).build(), + PlacementSupportingDocument.builder().document(SUPPORTING_DOCUMENT_4).build() + )) + .noticeDocuments(wrapElements( + PlacementNoticeDocument.builder().response(NOTICE_DOCUMENT_2).build(), + PlacementNoticeDocument.builder().response(NOTICE_DOCUMENT_4).build() + )) + .build(); + + CaseData caseData = CaseData.builder() + .placementEventData(PlacementEventData.builder() + .placements(wrapElements(placement1, placement2)) + .build()) + .build(); + + testCaseDocument(caseData, List.of(PLACEMENT_APPLICATION_1, PLACEMENT_APPLICATION_2, + PLACEMENT_NOTICE_DOCUMENT_1, PLACEMENT_NOTICE_DOCUMENT_2, + CONFIDENTIAL_DOCUMENT_1, CONFIDENTIAL_DOCUMENT_3, CONFIDENTIAL_DOCUMENT_2, CONFIDENTIAL_DOCUMENT_4, + SUPPORTING_DOCUMENT_1, SUPPORTING_DOCUMENT_3, SUPPORTING_DOCUMENT_2, SUPPORTING_DOCUMENT_4, + NOTICE_DOCUMENT_1, NOTICE_DOCUMENT_3, NOTICE_DOCUMENT_2, NOTICE_DOCUMENT_4), PLACEMENT_RESPONSES); + } + + @Test + void shouldConvertPlacementApplicationIfOnlyApplicationDocumentExist() { + final Placement placement = Placement.builder().application(PLACEMENT_APPLICATION_1).build(); + + CaseData caseData = CaseData.builder() + .placementEventData(PlacementEventData.builder() + .placements(wrapElements(placement)) + .build()) + .build(); + + testCaseDocument(caseData, List.of(PLACEMENT_APPLICATION_1), PLACEMENT_RESPONSES); + } + + @Test + void shouldReturnEmptyListIfNoPlacementExist() { + testCaseDocument(CaseData.builder().build(), List.of(), PLACEMENT_RESPONSES); + testCaseDocument(CaseData.builder() + .placementEventData(PlacementEventData.builder() + .placements(wrapElements(Placement.builder().build())) + .build()).build(), List.of(), PLACEMENT_RESPONSES); + } + } + + @Nested + class AdditionalApplications { + private static final DocumentReference C2 = getTestDocumentReference(); + private static final DocumentReference C2_2 = getTestDocumentReference(); + private static final DocumentReference OTHER_APPLICATION = getTestDocumentReference(); + private static final DocumentReference OTHER_APPLICATION_2 = getTestDocumentReference(); + private static final DocumentReference SUPPLEMENT_1 = getTestDocumentReference(); + private static final DocumentReference SUPPLEMENT_2 = getTestDocumentReference(); + private static final DocumentReference SUPPLEMENT_3 = getTestDocumentReference(); + private static final DocumentReference SUPPLEMENT_4 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_EVIDENCE_1 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_EVIDENCE_2 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_EVIDENCE_3 = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_EVIDENCE_4 = getTestDocumentReference(); + private static final DocumentReference DRAFT_ORDER_1 = getTestDocumentReference(); + private static final DocumentReference DRAFT_ORDER_2 = getTestDocumentReference(); + + @Test + void shouldConvertBothC2AndOtherAdditionalApplications() { + AdditionalApplicationsBundle additionalApplicationsBundle = AdditionalApplicationsBundle.builder() + .c2DocumentBundle(C2DocumentBundle.builder() + .document(C2) + .supplementsBundle(wrapElements( + Supplement.builder().document(SUPPLEMENT_1).build(), + Supplement.builder().document(SUPPLEMENT_2).build() + )) + .supportingEvidenceBundle(wrapElements( + SupportingEvidenceBundle.builder().document(SUPPORTING_EVIDENCE_1).build(), + SupportingEvidenceBundle.builder().document(SUPPORTING_EVIDENCE_2).build())) + .draftOrdersBundle(wrapElements( + DraftOrder.builder().document(DRAFT_ORDER_1).build(), + DraftOrder.builder().document(DRAFT_ORDER_2).build())) + .build()) + .otherApplicationsBundle(OtherApplicationsBundle.builder() + .document(OTHER_APPLICATION) + .supplementsBundle(wrapElements( + Supplement.builder().document(SUPPLEMENT_3).build(), + Supplement.builder().document(SUPPLEMENT_4).build())) + .supportingEvidenceBundle(wrapElements( + SupportingEvidenceBundle.builder().document(SUPPORTING_EVIDENCE_3).build(), + SupportingEvidenceBundle.builder().document(SUPPORTING_EVIDENCE_4).build())) + .build()) + .build(); + + CaseData caseData = CaseData.builder() + .additionalApplicationsBundle(wrapElements(additionalApplicationsBundle)).build(); + + testAdditionalApplications(caseData, + List.of(C2, SUPPLEMENT_1, SUPPLEMENT_2, SUPPORTING_EVIDENCE_1, SUPPORTING_EVIDENCE_2, + DRAFT_ORDER_1, DRAFT_ORDER_2), + List.of( + OTHER_APPLICATION, SUPPLEMENT_3, SUPPLEMENT_4, SUPPORTING_EVIDENCE_3, SUPPORTING_EVIDENCE_4)); + } + + @Test + void shouldConvertAllAdditionalApplications() { + AdditionalApplicationsBundle additionalApplicationsBundle1 = AdditionalApplicationsBundle.builder() + .c2DocumentBundle(C2DocumentBundle.builder().document(C2).build()) + .otherApplicationsBundle(OtherApplicationsBundle.builder().document(OTHER_APPLICATION).build()) + .build(); + AdditionalApplicationsBundle additionalApplicationsBundle2 = AdditionalApplicationsBundle.builder() + .c2DocumentBundle(C2DocumentBundle.builder().document(C2_2).build()) + .otherApplicationsBundle(OtherApplicationsBundle.builder().document(OTHER_APPLICATION_2).build()) + .build(); + CaseData caseData = CaseData.builder() + .additionalApplicationsBundle(wrapElements( + additionalApplicationsBundle1, additionalApplicationsBundle2)) + .build(); + + testAdditionalApplications(caseData, + List.of(C2, C2_2), + List.of(OTHER_APPLICATION, OTHER_APPLICATION_2)); + } + + @Test + void shouldConvertConfidentialC2UploadedByChildSolicitorOnly() { + AdditionalApplicationsBundle c2ByChildSolicitor = AdditionalApplicationsBundle.builder() + .c2DocumentBundleConfidential(C2DocumentBundle.builder().document(C2).build()) + .c2DocumentBundleChild0(C2DocumentBundle.builder().document(C2).build()) + .build(); + AdditionalApplicationsBundle c2ByLa = AdditionalApplicationsBundle.builder() + .c2DocumentBundleConfidential(C2DocumentBundle.builder().document(C2_2).build()) + .c2DocumentBundleLA(C2DocumentBundle.builder().document(C2_2).build()) + .build(); + AdditionalApplicationsBundle c2ByRespondentSolicitor = AdditionalApplicationsBundle.builder() + .c2DocumentBundleConfidential(C2DocumentBundle.builder().document(C2_2).build()) + .c2DocumentBundleResp0(C2DocumentBundle.builder().document(C2_2).build()) + .build(); + testAdditionalApplications(CaseData.builder() + .additionalApplicationsBundle(wrapElements( + c2ByChildSolicitor, c2ByLa, c2ByRespondentSolicitor)).build(), + List.of(C2), List.of()); + } + + @Test + void shouldReturnEmptyListIfNoAdditionalApplication() { + testAdditionalApplications(CaseData.builder().build(), List.of(), List.of()); + testAdditionalApplications(CaseData.builder() + .additionalApplicationsBundle(wrapElements(AdditionalApplicationsBundle.builder().build())).build(), + List.of(), List.of()); + } + + private void testAdditionalApplications(CaseData caseData, List c2Docs, + List c1Docs) { + CafcassApiCaseData actual = testConvert(caseData); + List expectedDocs = new ArrayList<>(); + expectedDocs.addAll(getExpectedCafcassApiCaseDocuments(C2_APPLICATION_DOCUMENTS.getCategory(), + false, c2Docs)); + expectedDocs.addAll(getExpectedCafcassApiCaseDocuments(C1_APPLICATION_DOCUMENTS.getCategory(), + false, c1Docs)); + + assertThat(actual.getCaseDocuments()).containsOnlyOnceElementsOf(expectedDocs); + } + } + + @Nested + @DirtiesContext + class ManagedDocuments { + private static final DocumentReference NON_CONFIDENTIAL_DOC_1 = getTestDocumentReference(); + private static final DocumentReference NON_CONFIDENTIAL_DOC_2 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOC_LA_1 = getTestDocumentReference(); + private static final DocumentReference CONFIDENTIAL_DOC_LA_2 = getTestDocumentReference(); + + private static final List> NON_CONFIDENTIAL_DOCS = List.of( + element(ManagedDocument.builder().document(NON_CONFIDENTIAL_DOC_1).build()), + element(ManagedDocument.builder().document(NON_CONFIDENTIAL_DOC_2).build())); + private static final List> CONFIDENTIAL_DOC_LA = List.of( + element(ManagedDocument.builder().document(CONFIDENTIAL_DOC_LA_1).build()), + element(ManagedDocument.builder().document(CONFIDENTIAL_DOC_LA_2).build())); + private static final List> CONFIDENTIAL_DOC_CTSC = List.of( + element(ManagedDocument.builder().document(getTestDocumentReference()).build()), + element(ManagedDocument.builder().document(getTestDocumentReference()).build())); + + @ParameterizedTest + @EnumSource(DocumentType.class) + void shouldConvertAllManagedDocuments(DocumentType documentType) { + Mockito.reset(manageDocumentService); + if (isNotEmpty(documentType.getBaseFieldNameResolver())) { + when( + manageDocumentService.toFieldNameToListOfElementMap(any(), eq(documentType), eq(NON_CONFIDENTIAL)) + ).thenReturn( + Map.of(documentType.getBaseFieldNameResolver().apply(NON_CONFIDENTIAL), NON_CONFIDENTIAL_DOCS) + ); + + when( + manageDocumentService.toFieldNameToListOfElementMap(any(), eq(documentType), eq(LA)) + ).thenReturn(Map.of(documentType.getBaseFieldNameResolver().apply(LA), CONFIDENTIAL_DOC_LA)); + + when( + manageDocumentService.toFieldNameToListOfElementMap(any(), eq(documentType), eq(CTSC)) + ).thenReturn(Map.of(documentType.getBaseFieldNameResolver().apply(CTSC), CONFIDENTIAL_DOC_CTSC)); + + testCaseDocument(CaseData.builder().build(), + List.of(NON_CONFIDENTIAL_DOC_1, NON_CONFIDENTIAL_DOC_2, CONFIDENTIAL_DOC_LA_1, + CONFIDENTIAL_DOC_LA_2), + documentType); + } else { + testCaseDocument(CaseData.builder().build(), List.of(), documentType); + } + Mockito.reset(manageDocumentService); + } + + @Test + void shouldReturnEmptyListIfNoDocumentFound() { + when(manageDocumentService.toFieldNameToListOfElementMap(any(), any(), any())).thenReturn(Map.of()); + testCaseDocument(CaseData.builder().build(), List.of(), ""); + + when(manageDocumentService.toFieldNameToListOfElementMap(any(), any(), any())) + .thenReturn(Map.of("", List.of())); + testCaseDocument(CaseData.builder().build(), List.of(), ""); + } + } } From f214c55fb22b339ae39d00e63a01f8f6f243d1d8 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 18:36:13 +0100 Subject: [PATCH 41/51] update controller test --- .../cafcass/CafcassApiControllerBaseTest.java | 62 +++++++++++ .../CafcassApiSearchCaseControllerTest.java | 82 ++++++++++++++ .../cafcass/CafcassCasesControllerTest.java | 103 +----------------- .../api/CafcassApiSearchCasesResponse.java | 3 +- 4 files changed, 147 insertions(+), 103 deletions(-) create mode 100644 service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiControllerBaseTest.java create mode 100644 service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiControllerBaseTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiControllerBaseTest.java new file mode 100644 index 00000000000..036750aa1b0 --- /dev/null +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiControllerBaseTest.java @@ -0,0 +1,62 @@ +package uk.gov.hmcts.reform.fpl.controllers.cafcass; + +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; +import uk.gov.hmcts.reform.fpl.interceptors.CafcassApiInterceptor; +import uk.gov.hmcts.reform.idam.client.models.UserInfo; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; + +@WebMvcTest(CafcassCasesController.class) +@OverrideAutoConfiguration(enabled = true) +public abstract class CafcassApiControllerBaseTest extends AbstractTest { + private static final UserInfo CAFCASS_SYSTEM_UPDATE_USER_INFO = UserInfo.builder() + .roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName())) + .build(); + + @Autowired + protected MockMvc mockMvc; + + @MockBean + private CafcassApiInterceptor cafcassApiInterceptor; + + @BeforeEach + void setUp() throws Exception { + givenCurrentUser(CAFCASS_SYSTEM_UPDATE_USER_INFO); + when(cafcassApiInterceptor.preHandle(any(), any(), any())).thenReturn(true); + } + + protected MvcResult sendRequest(MockHttpServletRequestBuilder request, int expectedStatus) throws Exception { + MvcResult response = mockMvc.perform(request).andExpect(status().is(expectedStatus)).andReturn(); + assertEquals(response.getResponse().getStatus(), expectedStatus); + return response; + } + + protected T readResponseContent(MvcResult response, Class responseType) throws IOException { + return mapper.readValue(response.getResponse().getContentAsByteArray(), responseType); + } + + protected MockHttpServletRequestBuilder buildGetRequest(String url) { + return get(url).header("authorization", USER_AUTH_TOKEN); + } + + protected MockHttpServletRequestBuilder buildPostRequest(String url) { + return post(url).header("authorization", USER_AUTH_TOKEN); + } +} diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java new file mode 100644 index 00000000000..26f633bc183 --- /dev/null +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java @@ -0,0 +1,82 @@ +package uk.gov.hmcts.reform.fpl.controllers.cafcass; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MvcResult; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; +import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSearchCasesResponse; +import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseService; + +import java.time.LocalDateTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + +public class CafcassApiSearchCaseControllerTest extends CafcassApiControllerBaseTest { + @MockBean + private CafcassApiCaseService cafcassApiCaseService; + + @Test + void searchCases() throws Exception { + List responseCases = List.of( + CafcassApiCase.builder() + .caseId(1L).jurisdiction("jurisdiction").state("state").caseTypeId("caseTypeId") + .createdDate(LocalDateTime.of(2023, 1, 1, 10, 0, 0)) + .lastModified(LocalDateTime.of(2024, 3, 28, 12,32,0)) + .caseData(CafcassApiCaseData.builder().build()) + .build(), + CafcassApiCase.builder() + .caseId(2L).jurisdiction("jurisdiction").state("state").caseTypeId("caseTypeId") + .createdDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) + .lastModified(LocalDateTime.of(2024, 3, 28, 12,40,0)) + .caseData(CafcassApiCaseData.builder().build()) + .build()); + + when(cafcassApiCaseService.searchCaseByDateRange( + LocalDateTime.of(2024, 3, 28, 12,30,1,541000000), + LocalDateTime.of(2024, 3, 28, 12,45,1,540000000)) + ).thenReturn(responseCases); + + MvcResult response = sendRequest(buildGetRequest("/cases") + .queryParam("startDate", "2024-03-28T12:30:01.541") + .queryParam("endDate", "2024-03-28T12:45:01.540"), 200); + + assertEquals( + CafcassApiSearchCasesResponse.builder().total(2).cases(responseCases).build(), + readResponseContent(response, CafcassApiSearchCasesResponse.class)); + } + + @Test + void searchCasesInvalidFormat400() throws Exception { + sendRequest(buildGetRequest("/cases") + .queryParam("startDate", "123").queryParam("endDate", "321"), + 400); + } + + @Test + void shouldReturn400IfEmptyParam() throws Exception { + sendRequest(buildGetRequest("/cases"), 400); + + sendRequest(buildGetRequest("/cases") + .queryParam("startDate", "2023-03-28T12:32:54.541"), 400); + + sendRequest(buildGetRequest("/cases") + .queryParam("endDate", "2024-03-27T12:32:54.542"), 400); + } + + @Test + void searchCasesInvalidTimeRange() throws Exception { + sendRequest(buildGetRequest("/cases") + .queryParam("startDate", "2024-03-28T12:32:54.541") + .queryParam("endDate", "2023-03-27T12:32:54.542"), 400); + } + + @Test + void shouldReturn400IfSearchRangeMoreThan15Minutes() throws Exception { + sendRequest(buildGetRequest("/cases") + .queryParam("startDate", "2024-03-28T12:32:54.541") + .queryParam("endDate", "2024-03-28T12:47:54.542"), 400); + } +} diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java index 3f68d249c0b..1500f4c332a 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesControllerTest.java @@ -17,11 +17,11 @@ import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; +@Deprecated @WebMvcTest(CafcassCasesController.class) @OverrideAutoConfiguration(enabled = true) public class CafcassCasesControllerTest extends AbstractTest { @@ -41,107 +41,6 @@ void setUp() { givenCurrentUser(CAFCASS_SYSTEM_UPDATE_USER_INFO); } - @Test - void searchCases() throws Exception { - MvcResult response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN) - .queryParam("startDate", "2023-03-28T12:32:54.541") - .queryParam("endDate", "2024-03-27T12:32:54.542")) - .andExpect(status().is(200)) - .andReturn(); - - assertEquals("searchCases - Start date: [2023-03-28], End date: [2024-03-27]", - response.getResponse().getContentAsString()); - } - - @Test - void searchCasesInvalidFormat400() throws Exception { - MvcResult response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN) - .queryParam("startDate", "123") - .queryParam("endDate", "321")) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - } - - @Test - void searchCasesEmptyParam400() throws Exception { - MvcResult response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN)) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - - response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN) - .queryParam("startDate", "2023-03-28T12:32:54.541")) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - - response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN) - .queryParam("endDate", "2024-03-27T12:32:54.542")) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - } - - @Test - void searchCases500() throws Exception { - MvcResult response = mockMvc - .perform(get("/cases") - .header("authorization", USER_AUTH_TOKEN) - .queryParam("startDate", "2024-03-28T12:32:54.541") - .queryParam("endDate", "2023-03-27T12:32:54.542")) - .andExpect(status().is(500)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 500); - } - - @Test - void getDocumentBinary() throws Exception { - UUID docId = UUID.randomUUID(); - MvcResult response = mockMvc - .perform(get("/cases/documents/%s/binary".formatted(docId)) - .header("authorization", USER_AUTH_TOKEN)) - .andExpect(status().is(200)) - .andReturn(); - - assertEquals("getDocumentBinary - document id: [%s]".formatted(docId), - response.getResponse().getContentAsString()); - } - - @Test - void getDocumentBinary400() throws Exception { - MvcResult response = mockMvc - .perform(get("/cases/documents/123/binary") - .header("authorization", USER_AUTH_TOKEN)) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - - response = mockMvc - .perform(get("/cases/documents/ /binary") - .header("authorization", USER_AUTH_TOKEN)) - .andExpect(status().is(400)) - .andReturn(); - - assertEquals(response.getResponse().getStatus(), 400); - } - @Test void uploadDocument() throws Exception { diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java index 884b8d23dd7..6a6eac327a4 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java @@ -1,11 +1,12 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; import lombok.Builder; +import lombok.Data; import lombok.Getter; import java.util.List; -@Getter +@Data @Builder public class CafcassApiSearchCasesResponse { private int total; From f54889b3d12cfc263317b89da8a03a837d07ca1d Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 18:54:38 +0100 Subject: [PATCH 42/51] fix style check --- .../cafcass/CafcassApiConfiguration.java | 3 - .../model/cafcass/api/CafcassApiAddress.java | 1 - .../fpl/model/cafcass/api/CafcassApiCase.java | 1 - .../cafcass/api/CafcassApiCaseDocument.java | 4 +- .../api/CafcassApiSearchCasesResponse.java | 1 - .../cafcass/api/CafcassApiSolicitor.java | 1 - .../api/CafcassApiCaseDocumentsConverter.java | 62 ++++++++++--------- .../cafcass/api/CafcassApiCaseService.java | 35 ----------- .../api/CafcassApiOthersConverter.java | 2 +- .../CafcassApiInterceptorTest.java | 6 +- .../CafcassApiCaseDocumentsConverterTest.java | 35 +++++------ .../api/CafcassApiConverterTestBase.java | 4 +- .../CafcassApiRespondentsConverterTest.java | 2 +- .../fpl/utils/CafcassApiHelperTest.java | 2 - 14 files changed, 57 insertions(+), 102 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java index 3fcaa5892d3..03e192d7cb3 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/config/cafcass/CafcassApiConfiguration.java @@ -1,14 +1,11 @@ package uk.gov.hmcts.reform.fpl.config.cafcass; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; -import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import uk.gov.hmcts.reform.fpl.interceptors.CafcassApiInterceptor; -import uk.gov.hmcts.reform.fpl.service.UserService; @Configuration @RequiredArgsConstructor(onConstructor = @__(@Autowired)) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java index 5bdd6e243c0..d5e45a8d92f 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiAddress.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Data; -import lombok.Getter; @Data @Builder diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java index d29ff0a681a..9c2d8a7daf5 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCase.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Data; -import lombok.Getter; import java.time.LocalDateTime; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java index de1e0293386..c05b09680a3 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiCaseDocument.java @@ -1,12 +1,14 @@ package uk.gov.hmcts.reform.fpl.model.cafcass.api; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; @Data @Builder public class CafcassApiCaseDocument { - private String document_filename; + @JsonProperty("document_filename") + private String documentFileName; private boolean removed; private String documentCategory; private String documentId; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java index 6a6eac327a4..ce3596f864a 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSearchCasesResponse.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Data; -import lombok.Getter; import java.util.List; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java index 0b4263dae96..964c39be707 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/cafcass/api/CafcassApiSolicitor.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Data; -import lombok.Getter; @Data @Builder diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index 53d8c928ab4..294f7b5fece 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -47,7 +47,8 @@ public class CafcassApiCaseDocumentsConverter implements CafcassApiCaseDataConve private final ManageDocumentService manageDocumentService; @Override - public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { + public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, + CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { return builder.caseDocuments(getCaseDocuments(caseData)); } @@ -113,7 +114,8 @@ private List getOriginalApplications(CaseData caseData) if (isNotEmpty(submittedC1)) { documentReferences.add(submittedC1.getDocument()); documentReferences.addAll(getAllDocumentsFromSupplements(submittedC1.getSupplementsBundle())); - documentReferences.addAll(getAllDocumentsFromSupportingEvidenceBundles(submittedC1.getSupportingEvidenceBundle())); + documentReferences.addAll( + getAllDocumentsFromSupportingEvidenceBundles(submittedC1.getSupportingEvidenceBundle())); } C110A c110a = caseData.getC110A(); @@ -151,33 +153,33 @@ private List getAdditionalApplications(CaseData caseData // additional application unwrapElements(caseData.getAdditionalApplicationsBundle()).forEach(additionalApplicationsBundle -> { - C2DocumentBundle c2Bundle = (additionalApplicationsBundle.isConfidentialC2UploadedByChildSolicitor()) - ? additionalApplicationsBundle.getC2DocumentBundleConfidential() - : additionalApplicationsBundle.getC2DocumentBundle(); - if (isNotEmpty(c2Bundle)) { - List c2DocRef = new ArrayList<>(); - c2DocRef.add(c2Bundle.getDocument()); - - c2DocRef.addAll(getAllDocumentsFromSupplements(c2Bundle.getSupplementsBundle())); - c2DocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( - c2Bundle.getSupportingEvidenceBundle())); - c2DocRef.addAll(unwrapElements(c2Bundle.getDraftOrdersBundle()).stream() - .map(DraftOrder::getDocument).toList()); - - resultList.addAll(buildCafcassApiCaseDocumentList(C2_APPLICATION_DOCUMENTS, false, c2DocRef)); - } - - OtherApplicationsBundle otherBundle = additionalApplicationsBundle.getOtherApplicationsBundle(); - if (isNotEmpty(otherBundle)) { - List otherDocRef = new ArrayList<>(); - - otherDocRef.add(otherBundle.getDocument()); - otherDocRef.addAll(getAllDocumentsFromSupplements(otherBundle.getSupplementsBundle())); - otherDocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( - otherBundle.getSupportingEvidenceBundle())); - - resultList.addAll(buildCafcassApiCaseDocumentList(C1_APPLICATION_DOCUMENTS, false, otherDocRef)); - } + C2DocumentBundle c2Bundle = (additionalApplicationsBundle.isConfidentialC2UploadedByChildSolicitor()) + ? additionalApplicationsBundle.getC2DocumentBundleConfidential() + : additionalApplicationsBundle.getC2DocumentBundle(); + if (isNotEmpty(c2Bundle)) { + List c2DocRef = new ArrayList<>(); + c2DocRef.add(c2Bundle.getDocument()); + + c2DocRef.addAll(getAllDocumentsFromSupplements(c2Bundle.getSupplementsBundle())); + c2DocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( + c2Bundle.getSupportingEvidenceBundle())); + c2DocRef.addAll(unwrapElements(c2Bundle.getDraftOrdersBundle()).stream() + .map(DraftOrder::getDocument).toList()); + + resultList.addAll(buildCafcassApiCaseDocumentList(C2_APPLICATION_DOCUMENTS, false, c2DocRef)); + } + + OtherApplicationsBundle otherBundle = additionalApplicationsBundle.getOtherApplicationsBundle(); + if (isNotEmpty(otherBundle)) { + List otherDocRef = new ArrayList<>(); + + otherDocRef.add(otherBundle.getDocument()); + otherDocRef.addAll(getAllDocumentsFromSupplements(otherBundle.getSupplementsBundle())); + otherDocRef.addAll(getAllDocumentsFromSupportingEvidenceBundles( + otherBundle.getSupportingEvidenceBundle())); + + resultList.addAll(buildCafcassApiCaseDocumentList(C1_APPLICATION_DOCUMENTS, false, otherDocRef)); + } }); return resultList; @@ -224,7 +226,7 @@ private CafcassApiCaseDocument buildCafcassApiCaseDocument(String category, bool DocumentReference docRef) { return CafcassApiCaseDocument.builder() .documentId(getDocumentIdFromUrl(docRef.getUrl()).toString()) - .document_filename(docRef.getFilename()) + .documentFileName(docRef.getFilename()) .documentCategory(category) .removed(removed) .build(); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java index b09256457b8..536fc28701b 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java @@ -5,50 +5,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; -import uk.gov.hmcts.reform.ccd.model.CaseLocation; -import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.CaseData; -import uk.gov.hmcts.reform.fpl.model.ChildParty; -import uk.gov.hmcts.reform.fpl.model.FactorsParenting; -import uk.gov.hmcts.reform.fpl.model.HearingBooking; -import uk.gov.hmcts.reform.fpl.model.InternationalElement; -import uk.gov.hmcts.reform.fpl.model.LocalAuthority; -import uk.gov.hmcts.reform.fpl.model.RespondentParty; -import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; -import uk.gov.hmcts.reform.fpl.model.Risks; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiAddress; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiApplicant; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseDocument; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseManagementLocation; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiChild; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiColleague; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiFactorsParenting; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiHearing; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiInternationalElement; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiOther; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiProceeding; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRespondent; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiRisk; -import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSolicitor; -import uk.gov.hmcts.reform.fpl.model.common.Document; -import uk.gov.hmcts.reform.fpl.model.common.Element; -import uk.gov.hmcts.reform.fpl.model.common.Telephone; import uk.gov.hmcts.reform.fpl.service.CaseConverter; import uk.gov.hmcts.reform.fpl.service.search.SearchService; import uk.gov.hmcts.reform.fpl.utils.elasticsearch.RangeQuery; -import java.lang.reflect.Field; import java.time.LocalDateTime; import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; -import static uk.gov.hmcts.reform.fpl.enums.YesNo.YES; -import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Slf4j @Service diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java index a20e4f8ac09..4b9f9035b91 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiOthersConverter.java @@ -15,7 +15,7 @@ import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements; @Service -public class CafcassApiOthersConverter implements CafcassApiCaseDataConverter{ +public class CafcassApiOthersConverter implements CafcassApiCaseDataConverter { @Override public CafcassApiCaseData.CafcassApiCaseDataBuilder convert(CaseData caseData, CafcassApiCaseData.CafcassApiCaseDataBuilder builder) { diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java index f36ad98f3c4..287e7599cb3 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java @@ -21,10 +21,10 @@ @ExtendWith(MockitoExtension.class) public class CafcassApiInterceptorTest { - private final static String AUTH_TOKEN_TEST = "bearerToken"; - private final static UserInfo CAFCASS_SYSTEM_UPDATE_USER = + private static final String AUTH_TOKEN_TEST = "bearerToken"; + private static final UserInfo CAFCASS_SYSTEM_UPDATE_USER = UserInfo.builder().roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName())).build(); - private final static UserInfo LOCAL_AUTHORITY_UPDATE_USER = + private static final UserInfo LOCAL_AUTHORITY_UPDATE_USER = UserInfo.builder().roles(List.of(LOCAL_AUTHORITY.getRoleName())).build(); @Mock diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java index 9505d1250c1..235b5ad156b 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverterTest.java @@ -1,13 +1,11 @@ package uk.gov.hmcts.reform.fpl.service.cafcass.api; -import com.google.common.collect.ImmutableMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; import org.mockito.Mockito; import org.springframework.test.annotation.DirtiesContext; -import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel; import uk.gov.hmcts.reform.fpl.enums.cfv.DocumentType; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.ConfidentialGeneratedOrders; @@ -29,7 +27,6 @@ import uk.gov.hmcts.reform.fpl.model.common.SubmittedC1WithSupplementBundle; import uk.gov.hmcts.reform.fpl.model.event.PlacementEventData; import uk.gov.hmcts.reform.fpl.model.group.C110A; -import uk.gov.hmcts.reform.fpl.model.interfaces.WithDocument; import uk.gov.hmcts.reform.fpl.model.order.DraftOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrder; import uk.gov.hmcts.reform.fpl.model.order.HearingOrdersBundle; @@ -37,19 +34,14 @@ import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel.CTSC; import static uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel.LA; @@ -73,7 +65,7 @@ private List getExpectedCafcassApiCaseDocuments(String c List docRefs) { return docRefs.stream().map(docRef -> CafcassApiCaseDocument.builder() .documentId(getDocumentIdFromUrl(docRef.getUrl()).toString()) - .document_filename(docRef.getFilename()) + .documentFileName(docRef.getFilename()) .documentCategory(category) .removed(removed) .build()) @@ -135,8 +127,8 @@ void shouldReturnEmptyListIfNull() { @Nested class DraftOrders { - private final static DocumentReference DRAFT_ORDER = getTestDocumentReference(); - private final static DocumentReference DRAFT_ORDER_CONFIDENTIAL = getTestDocumentReference(); + private static final DocumentReference DRAFT_ORDER = getTestDocumentReference(); + private static final DocumentReference DRAFT_ORDER_CONFIDENTIAL = getTestDocumentReference(); @Test void shouldConvertDraftOrdersAndConfidentialOrdersUploadedByChildSolicitor() { @@ -216,6 +208,7 @@ class ApprovedOrder { private static final DocumentReference SEALED_CMO_CONFIDENTIAL = getTestDocumentReference(); private static final DocumentReference APPROVED_ORDER = getTestDocumentReference(); private static final DocumentReference APPROVED_ORDER_CONFIDENTIAL = getTestDocumentReference(); + @Test void shouldConvertSealedCmosAndOrders() { CaseData caseData = CaseData.builder() @@ -278,15 +271,15 @@ void shouldReturnEmptyListIfNullOrEmpty() { @Nested class OriginalApplications { - DocumentReference APPLICATION_DOC = getTestDocumentReference(); - DocumentReference APPLICATION_TRANSLATED_DOC = getTestDocumentReference(); - DocumentReference SUPPLEMENT_DOC = getTestDocumentReference(); - Supplement SUPPLEMENT = Supplement.builder().document(SUPPLEMENT_DOC).build(); - DocumentReference SUPPORTING_EVIDENCE_DOC = getTestDocumentReference(); - DocumentReference SUPPORTING_EVIDENCE_TRANSLATEDDOC = getTestDocumentReference(); - SupportingEvidenceBundle supportingEvidence = SupportingEvidenceBundle.builder() + private static final DocumentReference APPLICATION_DOC = getTestDocumentReference(); + private static final DocumentReference APPLICATION_TRANSLATED_DOC = getTestDocumentReference(); + private static final DocumentReference SUPPLEMENT_DOC = getTestDocumentReference(); + private static final Supplement SUPPLEMENT = Supplement.builder().document(SUPPLEMENT_DOC).build(); + private static final DocumentReference SUPPORTING_EVIDENCE_DOC = getTestDocumentReference(); + private static final DocumentReference SUPPORTING_EVIDENCE_TRANSLATED_DOC = getTestDocumentReference(); + private static final SupportingEvidenceBundle SUPPORTING_EVIDENCE_BUNDLE = SupportingEvidenceBundle.builder() .document(SUPPORTING_EVIDENCE_DOC) - .translatedDocument(SUPPORTING_EVIDENCE_TRANSLATEDDOC) + .translatedDocument(SUPPORTING_EVIDENCE_TRANSLATED_DOC) .build(); @Test @@ -295,13 +288,13 @@ void shouldConvertC1OriginalApplicationDocument() { .submittedC1WithSupplement(SubmittedC1WithSupplementBundle.builder() .document(APPLICATION_DOC) .supplementsBundle(wrapElements(SUPPLEMENT)) - .supportingEvidenceBundle(wrapElements(supportingEvidence)) + .supportingEvidenceBundle(wrapElements(SUPPORTING_EVIDENCE_BUNDLE)) .build()) .build(); testCaseDocument( caseData, - List.of(APPLICATION_DOC, SUPPLEMENT_DOC, SUPPORTING_EVIDENCE_DOC, SUPPORTING_EVIDENCE_TRANSLATEDDOC), + List.of(APPLICATION_DOC, SUPPLEMENT_DOC, SUPPORTING_EVIDENCE_DOC, SUPPORTING_EVIDENCE_TRANSLATED_DOC), "originalApplications"); } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java index b0dce55de53..08a6c198388 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiConverterTestBase.java @@ -24,7 +24,9 @@ public abstract class CafcassApiConverterTestBase { CafcassApiCaseDataConverter underTest; - private CafcassApiConverterTestBase() {} + private CafcassApiConverterTestBase() { + } + CafcassApiConverterTestBase(CafcassApiCaseDataConverter converterUnderTest) { underTest = converterUnderTest; } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java index b1fdaa2945f..b8c0f6fc965 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiRespondentsConverterTest.java @@ -15,7 +15,7 @@ import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements; public class CafcassApiRespondentsConverterTest extends CafcassApiConverterTestBase { - CafcassApiRespondentsConverterTest( ) { + CafcassApiRespondentsConverterTest() { super(new CafcassApiRespondentsConverter()); } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java index ede10eec0e9..0a6523a6634 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/utils/CafcassApiHelperTest.java @@ -1,8 +1,6 @@ package uk.gov.hmcts.reform.fpl.utils; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.model.Organisation; import uk.gov.hmcts.reform.fpl.model.Address; import uk.gov.hmcts.reform.fpl.model.RespondentSolicitor; From 9ea0fe8f0c0b7204ff5d39c1cb74563d7bd6a4da Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 20:50:39 +0100 Subject: [PATCH 43/51] fix unit test --- .../gov/hmcts/reform/fpl/controllers/RootControllerTest.java | 5 +++++ .../reform/fpl/controllers/TestingSupportControllerTest.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/RootControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/RootControllerTest.java index ad067b9bb7e..9eee83ab92d 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/RootControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/RootControllerTest.java @@ -4,9 +4,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; +import uk.gov.hmcts.reform.idam.client.IdamClient; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -20,6 +22,9 @@ class RootControllerTest { @Autowired private MockMvc mockMvc; + @MockBean + private IdamClient idamClient; + @Test void shouldWelcomeUponRootRequestWith200ResponseCode() throws Exception { MvcResult response = mockMvc diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/TestingSupportControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/TestingSupportControllerTest.java index 27204d97fff..636fda7cfdc 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/TestingSupportControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/TestingSupportControllerTest.java @@ -32,6 +32,7 @@ import uk.gov.hmcts.reform.fpl.service.ccd.CoreCaseDataService; import uk.gov.hmcts.reform.fpl.testingsupport.controllers.TestingSupportController; import uk.gov.hmcts.reform.fpl.utils.ResourceReader; +import uk.gov.hmcts.reform.idam.client.IdamClient; import java.util.List; import java.util.Map; @@ -93,6 +94,9 @@ class TestingSupportControllerTest { @MockBean private DocumentUploadClientApi uploadClient; + @MockBean + private IdamClient idamClient; + @BeforeEach void init() { when(requestData.authorisation()).thenReturn(USER_AUTH_TOKEN); From a9c0bf67782848f267d8538b5cd95947d39f10aa Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 21:26:21 +0100 Subject: [PATCH 44/51] fix code check --- .../reform/fpl/service/cafcass/api/CafcassApiCaseService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java index 536fc28701b..4cede418d08 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java @@ -30,7 +30,7 @@ public List searchCaseByDateRange(LocalDateTime startDate, Local .greaterThanOrEqual(startDate) .lessThanOrEqual(endDate).build(); - List caseDetails = searchService.search(searchRange, 10000 , 0); + List caseDetails = searchService.search(searchRange, 10000, 0); return caseDetails.stream() .map(this::convertToCafcassApiCase) From 971d01ef314a6e08c93493f5809fef3a697ffcf2 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 21:30:31 +0100 Subject: [PATCH 45/51] rename to CafcassApiSearchCaseService --- .../cafcass/CafcassApiSearchCaseControllerTest.java | 6 +++--- .../fpl/controllers/cafcass/CafcassCasesController.java | 6 +++--- ...ApiCaseService.java => CafcassApiSearchCaseService.java} | 2 +- ...erviceTest.java => CafcassApiSearchCaseServiceTest.java} | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) rename service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/{CafcassApiCaseService.java => CafcassApiSearchCaseService.java} (98%) rename service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/{CafcassApiCaseServiceTest.java => CafcassApiSearchCaseServiceTest.java} (97%) diff --git a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java index 26f633bc183..04d1a136d28 100644 --- a/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java +++ b/service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.java @@ -6,7 +6,7 @@ import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSearchCasesResponse; -import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseService; +import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiSearchCaseService; import java.time.LocalDateTime; import java.util.List; @@ -16,7 +16,7 @@ public class CafcassApiSearchCaseControllerTest extends CafcassApiControllerBaseTest { @MockBean - private CafcassApiCaseService cafcassApiCaseService; + private CafcassApiSearchCaseService cafcassApiSearchCaseService; @Test void searchCases() throws Exception { @@ -34,7 +34,7 @@ void searchCases() throws Exception { .caseData(CafcassApiCaseData.builder().build()) .build()); - when(cafcassApiCaseService.searchCaseByDateRange( + when(cafcassApiSearchCaseService.searchCaseByDateRange( LocalDateTime.of(2024, 3, 28, 12,30,1,541000000), LocalDateTime.of(2024, 3, 28, 12,45,1,540000000)) ).thenReturn(responseCases); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 23d4c8b8dd5..53a941ba7e0 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -16,7 +16,7 @@ import uk.gov.hmcts.reform.fpl.exceptions.api.BadInputException; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSearchCasesResponse; -import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiCaseService; +import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiSearchCaseService; import java.time.LocalDateTime; import java.util.List; @@ -33,7 +33,7 @@ public class CafcassCasesController { private static final String DATE_TIME_FORMAT_IN = "yyyy-MM-dd'T'hh:mm:ss.SSS"; private static final String DATE_TIME_FORMAT_OUT = "yyyy-MM-dd"; - private final CafcassApiCaseService cafcassApiCaseService; + private final CafcassApiSearchCaseService cafcassApiSearchCaseService; @GetMapping("") public CafcassApiSearchCasesResponse searchCases( @@ -47,7 +47,7 @@ public CafcassApiSearchCasesResponse searchCases( throw new BadInputException(); } - List caseDetails = cafcassApiCaseService.searchCaseByDateRange(startDate, endDate); + List caseDetails = cafcassApiSearchCaseService.searchCaseByDateRange(startDate, endDate); return CafcassApiSearchCasesResponse.builder() .total(caseDetails.size()) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseService.java similarity index 98% rename from service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java rename to service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseService.java index 4cede418d08..d6b05216323 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseService.java @@ -18,7 +18,7 @@ @Slf4j @Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) -public class CafcassApiCaseService { +public class CafcassApiSearchCaseService { private final CaseConverter caseConverter; private final SearchService searchService; private final List cafcassApiCaseDataConverters; diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseServiceTest.java similarity index 97% rename from service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java rename to service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseServiceTest.java index d9f726acfd7..24362ca5d52 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseServiceTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiSearchCaseServiceTest.java @@ -28,7 +28,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class CafcassApiCaseServiceTest { +public class CafcassApiSearchCaseServiceTest { private static final LocalDateTime SEARCH_END_DATE = LocalDateTime.now(); private static final LocalDateTime SEARCH_START_DATE = SEARCH_END_DATE.minusDays(1); private static final RangeQuery SEARCH_RANGE = RangeQuery.builder().field("last_modified") @@ -59,11 +59,11 @@ public class CafcassApiCaseServiceTest { @Mock private CafcassApiCaseDataConverter cafcassApiCaseDataConverter3; - private CafcassApiCaseService underTest; + private CafcassApiSearchCaseService underTest; @BeforeEach void setUpWithMockConverters() { - underTest = new CafcassApiCaseService(caseConverter, searchService, + underTest = new CafcassApiSearchCaseService(caseConverter, searchService, List.of(cafcassApiCaseDataConverter1, cafcassApiCaseDataConverter2, cafcassApiCaseDataConverter3)); } From ecaa7453c11387c8a065b0a3ef79e9ae678a2d0f Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Mon, 29 Jul 2024 21:48:22 +0100 Subject: [PATCH 46/51] Update AmendOrderToDownloadPrePopulatorTest.java --- .../question/AmendOrderToDownloadPrePopulatorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulatorTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulatorTest.java index 2f37ef58b3a..acf7d4d71d1 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulatorTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/orders/prepopulator/question/AmendOrderToDownloadPrePopulatorTest.java @@ -129,7 +129,7 @@ void getSelectedOrderForOrder() { .build(); when(amendedOrderList.getValueCodeAsUUID()).thenReturn(ORDER_ID); - when(order.getDocument()).thenReturn(orderDocument); + when(order.getDocumentOrDocumentConfidential()).thenReturn(orderDocument); assertThat(underTest.prePopulate(caseData)).isEqualTo(Map.of("manageOrdersOrderToAmend", orderDocument)); } From 83e399a35f1c676df8ec4d11e9760b92dd651723 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 31 Jul 2024 09:56:30 +0100 Subject: [PATCH 47/51] Update CafcassApiInterceptor.java --- .../hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java index 4e4612f08f9..c89a623f014 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.servlet.HandlerInterceptor; @@ -19,13 +20,13 @@ @Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassApiInterceptor implements HandlerInterceptor { - private final IdamClient idamClient; + private final ObjectProvider idamClient; public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String authToken = request.getHeader("Authorization"); if (isNotEmpty(authToken)) { - UserInfo userInfo = idamClient.getUserInfo(authToken); + UserInfo userInfo = idamClient.getIfAvailable().getUserInfo(authToken); if (userInfo != null && userInfo.getRoles().contains(CAFCASS_SYSTEM_UPDATE.getRoleName())) { return true; } From 8dbdea805712f2a13615d8c4b694e1f94cd14c63 Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 31 Jul 2024 11:28:35 +0100 Subject: [PATCH 48/51] use cafcass role until new role is set up --- .../main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java | 2 +- .../reform/fpl/interceptors/CafcassApiInterceptor.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java index 4da3be2e3b7..d93fc104bc8 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/enums/UserRole.java @@ -8,7 +8,7 @@ public enum UserRole { LOCAL_AUTHORITY("caseworker-publiclaw-solicitor"), HMCTS_ADMIN("caseworker-publiclaw-courtadmin"), CAFCASS("caseworker-publiclaw-cafcass"), - CAFCASS_SYSTEM_UPDATE("caseworker-publiclaw-cafcasssystemupdate"), + CAFCASS_SYSTEM_UPDATE("caseworker-publiclaw-cafcass"), // TODO set up new system-update role GATEKEEPER("caseworker-publiclaw-gatekeeper"), JUDICIARY("caseworker-publiclaw-judiciary"), HMCTS_SUPERUSER("caseworker-publiclaw-superuser"); diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java index c89a623f014..ebfd5d4cb62 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.web.servlet.HandlerInterceptor; import uk.gov.hmcts.reform.fpl.exceptions.api.AuthorizationException; @@ -20,13 +21,14 @@ @Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassApiInterceptor implements HandlerInterceptor { - private final ObjectProvider idamClient; + @Lazy + private final IdamClient idamClient; public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String authToken = request.getHeader("Authorization"); if (isNotEmpty(authToken)) { - UserInfo userInfo = idamClient.getIfAvailable().getUserInfo(authToken); + UserInfo userInfo = idamClient.getUserInfo(authToken); if (userInfo != null && userInfo.getRoles().contains(CAFCASS_SYSTEM_UPDATE.getRoleName())) { return true; } From 95f6faa4bcaca73f6760629f682256e9e1187ecb Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 31 Jul 2024 11:28:55 +0100 Subject: [PATCH 49/51] Update CafcassApiInterceptor.java --- .../gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java index ebfd5d4cb62..1d41217458b 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java @@ -2,7 +2,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; From 306b626f60bee639d28492526f791666db00cb7b Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 31 Jul 2024 12:50:34 +0100 Subject: [PATCH 50/51] use object provider --- .../reform/fpl/interceptors/CafcassApiInterceptor.java | 7 +++---- .../reform/fpl/interceptors/CafcassApiInterceptorTest.java | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java index 1d41217458b..c89a623f014 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptor.java @@ -2,8 +2,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.web.servlet.HandlerInterceptor; import uk.gov.hmcts.reform.fpl.exceptions.api.AuthorizationException; @@ -20,14 +20,13 @@ @Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class CafcassApiInterceptor implements HandlerInterceptor { - @Lazy - private final IdamClient idamClient; + private final ObjectProvider idamClient; public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String authToken = request.getHeader("Authorization"); if (isNotEmpty(authToken)) { - UserInfo userInfo = idamClient.getUserInfo(authToken); + UserInfo userInfo = idamClient.getIfAvailable().getUserInfo(authToken); if (userInfo != null && userInfo.getRoles().contains(CAFCASS_SYSTEM_UPDATE.getRoleName())) { return true; } diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java index 287e7599cb3..2b831c7e583 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/interceptors/CafcassApiInterceptorTest.java @@ -5,6 +5,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.ObjectProvider; import uk.gov.hmcts.reform.fpl.exceptions.api.AuthorizationException; import uk.gov.hmcts.reform.idam.client.IdamClient; import uk.gov.hmcts.reform.idam.client.models.UserInfo; @@ -29,6 +30,8 @@ public class CafcassApiInterceptorTest { @Mock private IdamClient idamClient; + @Mock + private ObjectProvider idamClientObjectProvider; @InjectMocks private CafcassApiInterceptor underTest; @@ -36,6 +39,7 @@ public class CafcassApiInterceptorTest { public void shouldReturnTrueIfCafcassSystemUpdateUser() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getHeader("Authorization")).thenReturn(AUTH_TOKEN_TEST); + when(idamClientObjectProvider.getIfAvailable()).thenReturn(idamClient); when(idamClient.getUserInfo(AUTH_TOKEN_TEST)).thenReturn(CAFCASS_SYSTEM_UPDATE_USER); assertTrue(underTest.preHandle(request, null, null)); @@ -45,6 +49,7 @@ public void shouldReturnTrueIfCafcassSystemUpdateUser() throws Exception { public void shouldThrowAuthExceptionIfNotCafcassSystemUpdateUser() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getHeader("Authorization")).thenReturn(AUTH_TOKEN_TEST); + when(idamClientObjectProvider.getIfAvailable()).thenReturn(idamClient); when(idamClient.getUserInfo(AUTH_TOKEN_TEST)).thenReturn(LOCAL_AUTHORITY_UPDATE_USER); assertThrows(AuthorizationException.class, From 4c7548b84de4f62f898c42041e42734e6becda4f Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Wed, 31 Jul 2024 17:00:47 +0100 Subject: [PATCH 51/51] remove comment --- .../reform/fpl/controllers/cafcass/CafcassCasesController.java | 2 -- .../service/cafcass/api/CafcassApiCaseDocumentsConverter.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java index 53a941ba7e0..6223c6aa3b2 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassCasesController.java @@ -41,8 +41,6 @@ public CafcassApiSearchCasesResponse searchCases( @RequestParam(name = "endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate) { log.info("searchCases, " + startDate + ", " + endDate); - // TODO a generice work flow for validation? - // TODO should put the 15 mins range to configuration instead? if (startDate.isAfter(endDate) || startDate.plusMinutes(15).isBefore(endDate)) { throw new BadInputException(); } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java index 294f7b5fece..989fcba967d 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/cafcass/api/CafcassApiCaseDocumentsConverter.java @@ -63,7 +63,6 @@ private List getCaseDocuments(CaseData caseData) { getHearingNotice(caseData), getManageDocuments(caseData)) .flatMap(List::stream) - //.parallel() .toList(); } @@ -215,7 +214,6 @@ private List getManageDocuments(CaseData caseData) { .toFieldNameToListOfElementMap(caseData, documentType, confidentialLevel).values()) .flatMap(Collection::stream).flatMap(List::stream) .map(Element::getValue) - //.filter(object -> object instanceof WithDocument) .map(object -> (WithDocument) object) .map(WithDocument::getDocument))) .flatMap(List::stream)