From 4c778f09675516099332bee066479e9a1b8cb54d Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Fri, 15 Nov 2024 09:06:58 +0000 Subject: [PATCH 01/15] Add model for MI reporting --- .../account/management/dto/MiReportData.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java new file mode 100644 index 00000000..860a272c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java @@ -0,0 +1,25 @@ +package uk.gov.hmcts.reform.pip.account.management.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import uk.gov.hmcts.reform.pip.model.account.Roles; +import uk.gov.hmcts.reform.pip.model.account.UserProvenances; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@Setter +@AllArgsConstructor +public class MiReportData { + private UUID userId; + private String provenanceUserId; + private UserProvenances userProvenance; + private Roles roles; + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") + private LocalDateTime createdDate; + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") + private LocalDateTime lastSignedInDate; +} From 6035893cac8e0ba676f834a1fa332e8f08c8ef71 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Fri, 15 Nov 2024 09:09:34 +0000 Subject: [PATCH 02/15] Update MI endpoint to use model not string --- .../AccountFilteringController.java | 19 ++++--------------- .../management/database/UserRepository.java | 9 +++++---- .../service/AccountFilteringService.java | 15 ++++++++------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java index faceb0c4..bcc1b2b9 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java @@ -1,9 +1,6 @@ package uk.gov.hmcts.reform.pip.account.management.controllers; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.ExampleObject; -import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -12,7 +9,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -21,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.account.management.service.AccountFilteringService; import uk.gov.hmcts.reform.pip.model.account.Roles; @@ -50,18 +47,10 @@ public AccountFilteringController(AccountFilteringService accountFilteringServic this.accountFilteringService = accountFilteringService; } - @ApiResponse(responseCode = OK_CODE, description = "A CSV like structure which contains the data. " - + "See example for headers ", content = { - @Content(examples = {@ExampleObject("user_id,provenance_user_id,user_provenance,roles," - + "created_date,last_signed_in_date")}, - mediaType = MediaType.TEXT_PLAIN_VALUE, - schema = @Schema(implementation = String.class)) - } - ) - @Operation(summary = "Returns a list of (anonymized) account data for MI reporting. This endpoint will be " - + "deprecated in the future, in favour of returning a JSON model") + @ApiResponse(responseCode = OK_CODE, description = "A JSON model which contains the data. ") + @Operation(summary = "Returns (anonymized) account data for MI reporting") @GetMapping("/mi-data") - public ResponseEntity getMiData() { + public ResponseEntity> getMiData() { return ResponseEntity.status(HttpStatus.OK).body(accountFilteringService.getAccManDataForMiReporting()); } diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java index 22e3705b..e9790149 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; @@ -24,10 +25,10 @@ List findExistingByProvenanceId(@Param("provUserId") String provenanceUs Optional findByUserId(UUID userId); - @Query(value = "SELECT cast(user_id as text), provenance_user_id, user_provenance, roles, created_date, " - + "last_signed_in_date FROM pi_user", - nativeQuery = true) - List getAccManDataForMI(); + @Query("SELECT new uk.gov.hmcts.reform.pip.account.management.dto.MiReportData(" + + "u.userId, u.provenanceUserId, u.userProvenance, u.roles, u.createdDate, u.lastSignedInDate) " + + "FROM PiUser u") + List getAccManDataForMI(); @Query(value = "SELECT * FROM pi_user WHERE CAST(last_verified_date AS DATE) = CURRENT_DATE - (interval '1' day)" + " * :daysAgo AND user_provenance = 'PI_AAD' AND roles = 'VERIFIED'", nativeQuery = true) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java index 8b1dac0e..9f53677c 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java @@ -5,6 +5,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.pip.account.management.database.UserRepository; +import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.errorhandling.exceptions.NotFoundException; import uk.gov.hmcts.reform.pip.account.management.helpers.EmailHelper; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; @@ -26,13 +27,13 @@ public AccountFilteringService(UserRepository userRepository) { this.userRepository = userRepository; } - public String getAccManDataForMiReporting() { - StringBuilder builder = new StringBuilder(85); - builder.append("user_id,provenance_user_id,user_provenance,roles,created_date,last_signed_in_date") - .append(System.lineSeparator()); - userRepository.getAccManDataForMI() - .forEach(line -> builder.append(line).append(System.lineSeparator())); - return builder.toString(); + /** + * Method which will retrieve MI reporting data for all accounts. + * + * @return A list of MI Data objects for all accounts. + */ + public List getAccManDataForMiReporting() { + return userRepository.getAccManDataForMI(); } /** From 6460f7a49b82c53b423acd53512ce6ca5d1b03cb Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Fri, 15 Nov 2024 09:09:49 +0000 Subject: [PATCH 03/15] Update tests --- .../service/AccountFilteringServiceTest.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java index 842f4bf8..694b0cc8 100644 --- a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java @@ -11,17 +11,18 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import uk.gov.hmcts.reform.pip.account.management.database.UserRepository; +import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.errorhandling.exceptions.NotFoundException; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -31,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.pip.model.account.Roles.ALL_NON_RESTRICTED_ADMIN_ROLES; +import static uk.gov.hmcts.reform.pip.model.account.Roles.INTERNAL_ADMIN_CTSC; import static uk.gov.hmcts.reform.pip.model.account.UserProvenances.PI_AAD; import static uk.gov.hmcts.reform.pip.model.account.UserProvenances.SSO; @@ -38,11 +40,10 @@ class AccountFilteringServiceTest { private static final String EMAIL = "test@hmcts.net"; private static final String ID = "1234"; - private static final List EXAMPLE_CSV = List.of( - "2fe899ff-96ed-435a-bcad-1411bbe96d2a,string,CFT_IDAM,INTERNAL_ADMIN_CTSC,2022-01-19 13:45:50.873778," - + "2023-01-25 14:22:56.434343"); + private static final UUID USER_ID = UUID.randomUUID(); + private static final LocalDateTime CREATED_DATE = LocalDateTime.of(2022,1, 19, 13, 45, 50); + private static final LocalDateTime LAST_SIGNED_IN = LocalDateTime.of(2023,1, 25, 14, 22, 43); private static final PiUser PI_USER = new PiUser(); - private static final String USER_NOT_FOUND_EXCEPTION_MESSAGE = "The exception when a user has not been found has been thrown"; private static final String RETURN_USER_ERROR = "Returned user does not match expected user"; @@ -63,26 +64,14 @@ static void setup() { @Test void testMiService() { - when(userRepository.getAccManDataForMI()).thenReturn(EXAMPLE_CSV); - String testString = accountFilteringService.getAccManDataForMiReporting(); - - assertThat(testString) - .as("Json parsing has probably failed") - .contains("CTSC") - .hasLineCount(2); - - String[] splitLineString = testString.split("(\r\n|\r|\n)"); - long countLine1 = splitLineString[0].chars().filter(character -> character == ',').count(); - - assertThat(splitLineString[0]) - .as("Header row does not match") - .isEqualTo("user_id,provenance_user_id,user_provenance,roles,created_date,last_signed_in_date"); - - assertThat(splitLineString) - .as("Data must be missing, are only headers printing? or Wrong data") - .hasSizeGreaterThanOrEqualTo(2) - .allSatisfy( - e -> assertThat(e.chars().filter(character -> character == ',').count()).isEqualTo(countLine1)); + MiReportData miRecord = new MiReportData(USER_ID, ID, PI_AAD, INTERNAL_ADMIN_CTSC, + CREATED_DATE, LAST_SIGNED_IN); + List miData = List.of(miRecord, miRecord); + + when(userRepository.getAccManDataForMI()).thenReturn(miData); + List miReportData = accountFilteringService.getAccManDataForMiReporting(); + + assertEquals(miData, miReportData, "Returned data does not match expected data"); } @Test From 3badf757571b3ab90ce132398267579bf53f90a0 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Tue, 19 Nov 2024 16:24:01 +0000 Subject: [PATCH 04/15] Update tests --- .../CustomAccountRetrievalTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index 519cb421..ef730533 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -19,16 +19,19 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import uk.gov.hmcts.reform.pip.account.management.Application; import uk.gov.hmcts.reform.pip.account.management.config.AzureConfigurationClientTestConfiguration; +import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.CreationEnum; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -59,11 +62,10 @@ class CustomAccountRetrievalTest { private static final String NOT_FOUND_STATUS_CODE_MESSAGE = "Status code does not match not found"; private static final String USER_SHOULD_MATCH = "Users should match"; private static final String FORBIDDEN_STATUS_CODE = "Status code does not match forbidden"; + private static final String VALIDATION_MI_REPORT = "Should successfully retrieve MI data"; private static final String UNAUTHORIZED_ROLE = "APPROLE_unknown.authorized"; private static final String UNAUTHORIZED_USERNAME = "unauthorized_isAuthorized"; - private static final String EXPECTED_HEADERS = "user_id,provenance_user_id,user_provenance,roles," - + "created_date,last_signed_in_date"; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final PiUser VALID_USER = createUser(true, UUID.randomUUID().toString()); @@ -111,17 +113,15 @@ void testMiAccountDataRequestSuccess() throws Exception { MockHttpServletRequestBuilder request = MockMvcRequestBuilders .get(MI_REPORTING_ACCOUNT_DATA_URL); - String responseMiData = mockMvc.perform(request).andExpect(status().isOk()).andReturn() - .getResponse().getContentAsString(); + MvcResult responseMiData = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); - assertEquals(EXPECTED_HEADERS, responseMiData.split("\n")[0], - "Should successfully retrieve MI data headers" - ); + assertNotNull(responseMiData.getResponse(), VALIDATION_MI_REPORT); - assertTrue( - responseMiData.contains(createdUserId), - "Should successfully retrieve MI data" - ); + List miData = + Arrays.asList(OBJECT_MAPPER.readValue(responseMiData.getResponse().getContentAsString(), MiReportData[].class)); + + assertEquals(6, miData.size(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(0).getUserId().toString(), VALIDATION_MI_REPORT); } @Test From 5ef120b27580788356bcb0f4b6e40cc59c8a606b Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Tue, 19 Nov 2024 17:07:38 +0000 Subject: [PATCH 05/15] Update tests --- .../management/controllers/CustomAccountRetrievalTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index ef730533..b993e707 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -108,7 +108,7 @@ void testMiAccountDataRequestSuccess() throws Exception { } ); - String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).get(0).toString(); +// String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).get(0).toString(); MockHttpServletRequestBuilder request = MockMvcRequestBuilders .get(MI_REPORTING_ACCOUNT_DATA_URL); @@ -121,7 +121,7 @@ void testMiAccountDataRequestSuccess() throws Exception { Arrays.asList(OBJECT_MAPPER.readValue(responseMiData.getResponse().getContentAsString(), MiReportData[].class)); assertEquals(6, miData.size(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(0).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(VALID_USER.getUserId(), miData.get(0).getUserId(), VALIDATION_MI_REPORT); } @Test From 3cc53ddd3246b960c829ee3af68c25e64179267e Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Tue, 19 Nov 2024 17:16:11 +0000 Subject: [PATCH 06/15] Update tests --- .../controllers/CustomAccountRetrievalTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index b993e707..ede8d9dc 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -108,7 +108,7 @@ void testMiAccountDataRequestSuccess() throws Exception { } ); -// String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).get(0).toString(); + String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).get(0).toString(); MockHttpServletRequestBuilder request = MockMvcRequestBuilders .get(MI_REPORTING_ACCOUNT_DATA_URL); @@ -121,7 +121,13 @@ void testMiAccountDataRequestSuccess() throws Exception { Arrays.asList(OBJECT_MAPPER.readValue(responseMiData.getResponse().getContentAsString(), MiReportData[].class)); assertEquals(6, miData.size(), VALIDATION_MI_REPORT); - assertEquals(VALID_USER.getUserId(), miData.get(0).getUserId(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(0).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(1).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(2).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(3).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(4).getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.get(5).getUserId().toString(), VALIDATION_MI_REPORT); + } @Test From ab7fc8ca5b2d5f1973ea3c7b560f0d2edb8e7801 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Wed, 20 Nov 2024 14:45:20 +0000 Subject: [PATCH 07/15] Update tests --- .../CustomAccountRetrievalTest.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index ede8d9dc..b8291b84 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -108,7 +108,7 @@ void testMiAccountDataRequestSuccess() throws Exception { } ); - String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).get(0).toString(); + String createdUserId = mappedResponse.get(CreationEnum.CREATED_ACCOUNTS).getFirst().toString(); MockHttpServletRequestBuilder request = MockMvcRequestBuilders .get(MI_REPORTING_ACCOUNT_DATA_URL); @@ -117,17 +117,15 @@ void testMiAccountDataRequestSuccess() throws Exception { assertNotNull(responseMiData.getResponse(), VALIDATION_MI_REPORT); - List miData = - Arrays.asList(OBJECT_MAPPER.readValue(responseMiData.getResponse().getContentAsString(), MiReportData[].class)); - - assertEquals(6, miData.size(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(0).getUserId().toString(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(1).getUserId().toString(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(2).getUserId().toString(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(3).getUserId().toString(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(4).getUserId().toString(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.get(5).getUserId().toString(), VALIDATION_MI_REPORT); + List miData = Arrays.asList( + OBJECT_MAPPER.readValue( + responseMiData.getResponse().getContentAsString(), + MiReportData[].class + ) + ); + assertEquals(1, miData.size(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.getFirst().getUserId().toString(), VALIDATION_MI_REPORT); } @Test From 8d6a90050b31debdb3f3e464f43c4e16e6e832b2 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Wed, 20 Nov 2024 14:57:35 +0000 Subject: [PATCH 08/15] Update tests --- .../management/controllers/CustomAccountRetrievalTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index b8291b84..3c826674 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -176,7 +176,7 @@ void testGetAllThirdPartyAccounts() throws Exception { PiUser[].class ); - assertEquals(1, users.length, "Correct number of users should return"); + assertEquals(6, users.length, "Correct number of users should return"); assertEquals(createdUserId, users[0].getUserId().toString(), USER_SHOULD_MATCH); } From fe69f0cad3fa6a3166bcc8ea966e3cc5513ffa9e Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Wed, 20 Nov 2024 15:08:05 +0000 Subject: [PATCH 09/15] Update tests --- .../management/controllers/CustomAccountRetrievalTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index 3c826674..c75cf42b 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -124,7 +124,7 @@ void testMiAccountDataRequestSuccess() throws Exception { ) ); - assertEquals(1, miData.size(), VALIDATION_MI_REPORT); + assertEquals(6, miData.size(), VALIDATION_MI_REPORT); assertEquals(createdUserId, miData.getFirst().getUserId().toString(), VALIDATION_MI_REPORT); } @@ -176,7 +176,7 @@ void testGetAllThirdPartyAccounts() throws Exception { PiUser[].class ); - assertEquals(6, users.length, "Correct number of users should return"); + assertEquals(1, users.length, "Correct number of users should return"); assertEquals(createdUserId, users[0].getUserId().toString(), USER_SHOULD_MATCH); } From f577e6a38b390862308604ec271921f8f83806ac Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Wed, 20 Nov 2024 15:15:40 +0000 Subject: [PATCH 10/15] Update tests --- .../management/controllers/CustomAccountRetrievalTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index c75cf42b..1dfab571 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -125,7 +125,7 @@ void testMiAccountDataRequestSuccess() throws Exception { ); assertEquals(6, miData.size(), VALIDATION_MI_REPORT); - assertEquals(createdUserId, miData.getFirst().getUserId().toString(), VALIDATION_MI_REPORT); + assertEquals(createdUserId, miData.getLast().getUserId().toString(), VALIDATION_MI_REPORT); } @Test From 15d6d73486b5677e0d563326c039f1752697a814 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Thu, 21 Nov 2024 09:21:52 +0000 Subject: [PATCH 11/15] Move MI reporting model to Data Models repo --- build.gradle | 2 +- .../AccountFilteringController.java | 4 +-- .../management/database/UserRepository.java | 4 +-- .../account/management/dto/MiReportData.java | 25 ------------------- .../service/AccountFilteringService.java | 4 +-- .../service/AccountFilteringServiceTest.java | 8 +++--- 6 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java diff --git a/build.gradle b/build.gradle index fb9ba4b0..1e6bc582 100644 --- a/build.gradle +++ b/build.gradle @@ -221,7 +221,7 @@ dependencies { implementation group: 'com.opencsv', name: 'opencsv', version: '5.9' implementation group: 'commons-validator', name: 'commons-validator', version: '1.9.0' - implementation group: 'com.github.hmcts', name: 'pip-data-models', version: '2.1.32', { + implementation group: 'com.github.hmcts', name: 'pip-data-models', version: '2.1.33', { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-data-jpa' } implementation group: 'io.hypersistence', name: 'hypersistence-utils-hibernate-63', version: '3.8.3' diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java index bcc1b2b9..13e7a3a2 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java @@ -17,12 +17,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.account.management.service.AccountFilteringService; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; import uk.gov.hmcts.reform.pip.model.authentication.roles.IsAdmin; +import uk.gov.hmcts.reform.pip.model.report.AccountMiData; import java.util.List; @@ -50,7 +50,7 @@ public AccountFilteringController(AccountFilteringService accountFilteringServic @ApiResponse(responseCode = OK_CODE, description = "A JSON model which contains the data. ") @Operation(summary = "Returns (anonymized) account data for MI reporting") @GetMapping("/mi-data") - public ResponseEntity> getMiData() { + public ResponseEntity> getMiData() { return ResponseEntity.status(HttpStatus.OK).body(accountFilteringService.getAccManDataForMiReporting()); } diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java index e9790149..b0f34aff 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java @@ -7,10 +7,10 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import uk.gov.hmcts.reform.pip.model.report.AccountMiData; import java.util.List; import java.util.Optional; @@ -28,7 +28,7 @@ List findExistingByProvenanceId(@Param("provUserId") String provenanceUs @Query("SELECT new uk.gov.hmcts.reform.pip.account.management.dto.MiReportData(" + "u.userId, u.provenanceUserId, u.userProvenance, u.roles, u.createdDate, u.lastSignedInDate) " + "FROM PiUser u") - List getAccManDataForMI(); + List getAccManDataForMI(); @Query(value = "SELECT * FROM pi_user WHERE CAST(last_verified_date AS DATE) = CURRENT_DATE - (interval '1' day)" + " * :daysAgo AND user_provenance = 'PI_AAD' AND roles = 'VERIFIED'", nativeQuery = true) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java deleted file mode 100644 index 860a272c..00000000 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/dto/MiReportData.java +++ /dev/null @@ -1,25 +0,0 @@ -package uk.gov.hmcts.reform.pip.account.management.dto; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import uk.gov.hmcts.reform.pip.model.account.Roles; -import uk.gov.hmcts.reform.pip.model.account.UserProvenances; - -import java.time.LocalDateTime; -import java.util.UUID; - -@Getter -@Setter -@AllArgsConstructor -public class MiReportData { - private UUID userId; - private String provenanceUserId; - private UserProvenances userProvenance; - private Roles roles; - @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") - private LocalDateTime createdDate; - @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") - private LocalDateTime lastSignedInDate; -} diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java index 9f53677c..891190a8 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java @@ -5,12 +5,12 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.pip.account.management.database.UserRepository; -import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.errorhandling.exceptions.NotFoundException; import uk.gov.hmcts.reform.pip.account.management.helpers.EmailHelper; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import uk.gov.hmcts.reform.pip.model.report.AccountMiData; import java.util.List; @@ -32,7 +32,7 @@ public AccountFilteringService(UserRepository userRepository) { * * @return A list of MI Data objects for all accounts. */ - public List getAccManDataForMiReporting() { + public List getAccManDataForMiReporting() { return userRepository.getAccManDataForMI(); } diff --git a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java index 694b0cc8..04ef1026 100644 --- a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java @@ -11,11 +11,11 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import uk.gov.hmcts.reform.pip.account.management.database.UserRepository; -import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.errorhandling.exceptions.NotFoundException; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import uk.gov.hmcts.reform.pip.model.report.AccountMiData; import java.time.LocalDateTime; import java.util.ArrayList; @@ -64,12 +64,12 @@ static void setup() { @Test void testMiService() { - MiReportData miRecord = new MiReportData(USER_ID, ID, PI_AAD, INTERNAL_ADMIN_CTSC, + AccountMiData miRecord = new AccountMiData(USER_ID, ID, PI_AAD, INTERNAL_ADMIN_CTSC, CREATED_DATE, LAST_SIGNED_IN); - List miData = List.of(miRecord, miRecord); + List miData = List.of(miRecord, miRecord); when(userRepository.getAccManDataForMI()).thenReturn(miData); - List miReportData = accountFilteringService.getAccManDataForMiReporting(); + List miReportData = accountFilteringService.getAccManDataForMiReporting(); assertEquals(miData, miReportData, "Returned data does not match expected data"); } From feb10fca887315c0a60e932560794e88ad74b194 Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Mon, 25 Nov 2024 17:25:55 +0000 Subject: [PATCH 12/15] Update Query to use model from Data Models --- .../reform/pip/account/management/database/UserRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java index b0f34aff..28836621 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java @@ -25,7 +25,7 @@ List findExistingByProvenanceId(@Param("provUserId") String provenanceUs Optional findByUserId(UUID userId); - @Query("SELECT new uk.gov.hmcts.reform.pip.account.management.dto.MiReportData(" + @Query("SELECT new uk.gov.hmcts.reform.pip.model.report.AccountMiData(" + "u.userId, u.provenanceUserId, u.userProvenance, u.roles, u.createdDate, u.lastSignedInDate) " + "FROM PiUser u") List getAccManDataForMI(); From 2647626f368db4318514820e4e5ae90940c8c67e Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Mon, 25 Nov 2024 17:38:34 +0000 Subject: [PATCH 13/15] Update test to use MI model in Data Models --- .../management/controllers/CustomAccountRetrievalTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index 1dfab571..36ba619b 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -19,11 +19,11 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import uk.gov.hmcts.reform.pip.account.management.Application; import uk.gov.hmcts.reform.pip.account.management.config.AzureConfigurationClientTestConfiguration; -import uk.gov.hmcts.reform.pip.account.management.dto.MiReportData; import uk.gov.hmcts.reform.pip.account.management.model.CreationEnum; import uk.gov.hmcts.reform.pip.account.management.model.PiUser; import uk.gov.hmcts.reform.pip.model.account.Roles; import uk.gov.hmcts.reform.pip.model.account.UserProvenances; +import uk.gov.hmcts.reform.pip.model.report.AccountMiData; import java.util.Arrays; import java.util.List; @@ -117,10 +117,10 @@ void testMiAccountDataRequestSuccess() throws Exception { assertNotNull(responseMiData.getResponse(), VALIDATION_MI_REPORT); - List miData = Arrays.asList( + List miData = Arrays.asList( OBJECT_MAPPER.readValue( responseMiData.getResponse().getContentAsString(), - MiReportData[].class + AccountMiData[].class ) ); From eb8a5317cd3a4f676e438fae89680f120f95599d Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Tue, 26 Nov 2024 14:15:38 +0000 Subject: [PATCH 14/15] Rename MI data method --- .../management/controllers/AccountFilteringController.java | 2 +- .../pip/account/management/database/UserRepository.java | 2 +- .../account/management/service/AccountFilteringService.java | 4 ++-- .../management/service/AccountFilteringServiceTest.java | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java index 13e7a3a2..9c55d7f6 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/controllers/AccountFilteringController.java @@ -51,7 +51,7 @@ public AccountFilteringController(AccountFilteringService accountFilteringServic @Operation(summary = "Returns (anonymized) account data for MI reporting") @GetMapping("/mi-data") public ResponseEntity> getMiData() { - return ResponseEntity.status(HttpStatus.OK).body(accountFilteringService.getAccManDataForMiReporting()); + return ResponseEntity.status(HttpStatus.OK).body(accountFilteringService.getAccountDataForMi()); } @ApiResponse(responseCode = OK_CODE, description = "List of third party accounts") diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java index 28836621..f78e7977 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/database/UserRepository.java @@ -28,7 +28,7 @@ List findExistingByProvenanceId(@Param("provUserId") String provenanceUs @Query("SELECT new uk.gov.hmcts.reform.pip.model.report.AccountMiData(" + "u.userId, u.provenanceUserId, u.userProvenance, u.roles, u.createdDate, u.lastSignedInDate) " + "FROM PiUser u") - List getAccManDataForMI(); + List getAccountDataForMi(); @Query(value = "SELECT * FROM pi_user WHERE CAST(last_verified_date AS DATE) = CURRENT_DATE - (interval '1' day)" + " * :daysAgo AND user_provenance = 'PI_AAD' AND roles = 'VERIFIED'", nativeQuery = true) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java index 891190a8..246f8ebc 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringService.java @@ -32,8 +32,8 @@ public AccountFilteringService(UserRepository userRepository) { * * @return A list of MI Data objects for all accounts. */ - public List getAccManDataForMiReporting() { - return userRepository.getAccManDataForMI(); + public List getAccountDataForMi() { + return userRepository.getAccountDataForMi(); } /** diff --git a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java index 04ef1026..2a354f3d 100644 --- a/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pip/account/management/service/AccountFilteringServiceTest.java @@ -68,8 +68,8 @@ void testMiService() { CREATED_DATE, LAST_SIGNED_IN); List miData = List.of(miRecord, miRecord); - when(userRepository.getAccManDataForMI()).thenReturn(miData); - List miReportData = accountFilteringService.getAccManDataForMiReporting(); + when(userRepository.getAccountDataForMi()).thenReturn(miData); + List miReportData = accountFilteringService.getAccountDataForMi(); assertEquals(miData, miReportData, "Returned data does not match expected data"); } From f1fb5a715492c1f11572ce1c1dd44879c063d74c Mon Sep 17 00:00:00 2001 From: Natasha Alker Date: Tue, 26 Nov 2024 15:23:19 +0000 Subject: [PATCH 15/15] Remove test debugging --- .../management/controllers/CustomAccountRetrievalTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java index 36ba619b..3db09916 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/pip/account/management/controllers/CustomAccountRetrievalTest.java @@ -124,7 +124,6 @@ void testMiAccountDataRequestSuccess() throws Exception { ) ); - assertEquals(6, miData.size(), VALIDATION_MI_REPORT); assertEquals(createdUserId, miData.getLast().getUserId().toString(), VALIDATION_MI_REPORT); }