From 06a9557e1b513a2c11c9069379eb093746163a84 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Fri, 9 Feb 2024 11:08:49 +0100 Subject: [PATCH 1/3] Added API to retrieve all User from userIds --- app/src/main/resources/swagger/api-docs.json | 95 +++++++++++++++++++ .../mscore/web/controller/UserController.java | 30 +++++- .../mscore/web/model/mapper/UserMapper.java | 1 + .../web/model/user/OnboardedUserResponse.java | 14 +++ .../model/user/OnboardedUsersResponse.java | 12 +++ .../resources/swagger/swagger_en.properties | 2 + .../web/controller/UserControllerTest.java | 18 +++- 7 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java create mode 100644 web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index d8afdea3f..a5d9ed4c8 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -4876,6 +4876,70 @@ } ] } }, + "/onboarded-users" : { + "put" : { + "tags" : [ "Persons" ], + "summary" : "Retrieve onboarded users according to identifiers in input", + "description" : "Retrieve onboarded users according to identifiers in input", + "operationId" : "getOnboardedUsersUsingPUT", + "parameters" : [ { + "name" : "ids", + "in" : "query", + "description" : "${swagger.mscore.users.userIds}", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "204" : { + "description" : "No Content", + "content" : { + "*/*" : { + "schema" : { + "$ref" : "#/components/schemas/OnboardedUsersResponse" + } + } + } + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "403" : { + "description" : "Forbidden", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "404" : { + "description" : "Not Found", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, "/relationships/{relationshipId}" : { "get" : { "tags" : [ "Persons" ], @@ -7583,6 +7647,37 @@ } } }, + "OnboardedUserResponse" : { + "title" : "OnboardedUserResponse", + "type" : "object", + "properties" : { + "bindings" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/UserBinding" + } + }, + "createdAt" : { + "type" : "string", + "format" : "date-time" + }, + "id" : { + "type" : "string" + } + } + }, + "OnboardedUsersResponse" : { + "title" : "OnboardedUsersResponse", + "type" : "object", + "properties" : { + "users" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/OnboardedUserResponse" + } + } + } + }, "Onboarding" : { "title" : "Onboarding", "type" : "object", diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/UserController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/UserController.java index 1549ea826..6aed3636d 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/UserController.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/UserController.java @@ -14,6 +14,7 @@ import it.pagopa.selfcare.mscore.core.UserService; import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.UserNotificationToSend; +import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.onboarding.OnboardingInfo; import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.model.user.User; @@ -315,8 +316,8 @@ public ResponseEntity getUsers(@RequestParam(name = " } userNotificationResponse.setUsers(userNotificationMap.values().stream() - .map(UserNotificationBindingsResponse::new) - .toList()); + .map(UserNotificationBindingsResponse::new) + .toList()); return ResponseEntity.ok(userNotificationResponse); } @@ -350,4 +351,29 @@ public ResponseEntity updateUserStatus(@ApiParam(value = "${swagger.mscore userService.updateUserStatus(userId, institutionId, productId, role, productRole, status); return ResponseEntity.noContent().build(); } + + /** + * Get onboarded users from identifiers in input. + * + * @param userIds Users identifiers. + * @return ResponseEntity + *

+ * * Code: 204, Message: Update successful, DataType: No Content + * * Code: 400, Message: Bad Request, DataType: Problem + * * Code: 404, Message: Not Found, DataType: Problem + */ + @ResponseStatus(HttpStatus.NO_CONTENT) + @ApiOperation(value = "${swagger.mscore.api.users.getOnboardedUsers}", notes = "${swagger.mscore.api.users.getOnboardedUsers}") + @GetMapping(value = "/onboarded-users") + public ResponseEntity getOnboardedUsers(@ApiParam(value = "${swagger.mscore.users.userIds}", required = true) + @RequestParam(value = "ids") List userIds) { + log.debug("getOnboardedUsers - userIds: {}", userIds); + final List onboardedUsers = userService.findAllByIds(userIds); + OnboardedUsersResponse response = OnboardedUsersResponse.builder() + .users(onboardedUsers.stream() + .map(userMapper::toOnboardedUserResponse) + .toList()) + .build(); + return ResponseEntity.ok(response); + } } diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java index 98164c825..73260a487 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java @@ -42,6 +42,7 @@ public interface UserMapper { InstitutionUpdate toInstitutionUpdate(InstitutionUpdateRequest request); UserNotificationResponse toUserNotification(UserNotificationToSend user); + OnboardedUserResponse toOnboardedUserResponse(OnboardedUser onboardedUser); @Named("retrieveMailFromWorkContacts") default String retrieveMailFromWorkContacts(Map map, String institutionId){ diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java new file mode 100644 index 000000000..2ed1a2791 --- /dev/null +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java @@ -0,0 +1,14 @@ +package it.pagopa.selfcare.mscore.web.model.user; + +import it.pagopa.selfcare.mscore.model.user.UserBinding; +import lombok.Data; + +import java.time.OffsetDateTime; +import java.util.List; + +@Data +public class OnboardedUserResponse { + private String id; + private List bindings; + private OffsetDateTime createdAt; +} diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java new file mode 100644 index 000000000..3369961e0 --- /dev/null +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java @@ -0,0 +1,12 @@ +package it.pagopa.selfcare.mscore.web.model.user; + +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +@Data +@Builder +public class OnboardedUsersResponse { + private List users; +} diff --git a/web/src/main/resources/swagger/swagger_en.properties b/web/src/main/resources/swagger/swagger_en.properties index 19576f719..dda23aa95 100644 --- a/web/src/main/resources/swagger/swagger_en.properties +++ b/web/src/main/resources/swagger/swagger_en.properties @@ -79,10 +79,12 @@ swagger.mscore.users.products=Retrieves products info and role which the user is swagger.mscore.users=Retrieves user given userId and optional ProductId swagger.mscore.users.delete.products=Delete logically the association institution and product swagger.mscore.api.users.updateUserStatus=Update user status with optional filter for institution, product, role and productRole +swagger.mscore.api.users.getOnboardedUsers=Retrieve onboarded users according to identifiers in input swagger.mscore.institutions.delegations=Retrieve institution's delegations swagger.mscore.institutions.delegations.mode=Mode (full or normal) to retreieve institution's delegations swagger.mscore.institutions.brokers=Retrieve institution brokers swagger.mscore.users.userId=User's unique identifier +swagger.mscore.users.userIds=Users unique identifiers swagger.mscore.api.users.updateUser=Service to send notification when user data get's updated swagger.mscore.institutions.api.getInstitutionUsers=Retrieve institution's users swagger.mscore.api.users.findAll=Retrieve all users according to optional params in input diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java index 23e227169..13de5a49e 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java @@ -9,7 +9,6 @@ import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.core.UserRelationshipService; import it.pagopa.selfcare.mscore.core.UserService; -import it.pagopa.selfcare.mscore.core.UserServiceImpl; import it.pagopa.selfcare.mscore.core.util.UserNotificationMapper; import it.pagopa.selfcare.mscore.core.util.UserNotificationMapperImpl; import it.pagopa.selfcare.mscore.model.CertifiedField; @@ -649,5 +648,22 @@ void updateUserStatus() throws Exception { .andExpect(MockMvcResultMatchers.status().isNoContent()); } + @Test + void onboardedUsers() throws Exception { + final OnboardedUser onboardedUser = new OnboardedUser(); + onboardedUser.setId("userId"); + when(userService.findAllByIds(any())).thenReturn(List.of(onboardedUser)); + + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders + .put("/onboarded-users", "userId") + .queryParam("ids","DELETED") + .contentType(MediaType.APPLICATION_JSON); + + MockMvcBuilders.standaloneSetup(userController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + } From f5ddd6447525281cd470e70ee81be36ea9c5d7d7 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Fri, 9 Feb 2024 11:42:34 +0100 Subject: [PATCH 2/3] Fixed unit test about onboarded-users --- app/src/main/resources/swagger/api-docs.json | 16 +++------------- .../web/controller/UserControllerTest.java | 4 ++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index a5d9ed4c8..0bd78d74f 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -4877,15 +4877,15 @@ } }, "/onboarded-users" : { - "put" : { + "get" : { "tags" : [ "Persons" ], "summary" : "Retrieve onboarded users according to identifiers in input", "description" : "Retrieve onboarded users according to identifiers in input", - "operationId" : "getOnboardedUsersUsingPUT", + "operationId" : "getOnboardedUsersUsingGET", "parameters" : [ { "name" : "ids", "in" : "query", - "description" : "${swagger.mscore.users.userIds}", + "description" : "Users unique identifiers", "required" : true, "style" : "form", "explode" : true, @@ -4914,16 +4914,6 @@ } } }, - "403" : { - "description" : "Forbidden", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, "404" : { "description" : "Not Found", "content" : { diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java index 13de5a49e..fe737337a 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/UserControllerTest.java @@ -655,8 +655,8 @@ void onboardedUsers() throws Exception { when(userService.findAllByIds(any())).thenReturn(List.of(onboardedUser)); MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders - .put("/onboarded-users", "userId") - .queryParam("ids","DELETED") + .get("/onboarded-users") + .queryParam("ids","userId") .contentType(MediaType.APPLICATION_JSON); MockMvcBuilders.standaloneSetup(userController) From 9cd6957e2f06c68c70cc03463350028c7b29267b Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Fri, 9 Feb 2024 12:35:33 +0100 Subject: [PATCH 3/3] Removed redundant object OnboardedUserResponse --- app/src/main/resources/swagger/api-docs.json | 21 +------------------ .../mscore/web/model/mapper/UserMapper.java | 2 +- .../web/model/user/OnboardedUserResponse.java | 14 ------------- .../model/user/OnboardedUsersResponse.java | 2 +- 4 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 0bd78d74f..84b136709 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -7637,25 +7637,6 @@ } } }, - "OnboardedUserResponse" : { - "title" : "OnboardedUserResponse", - "type" : "object", - "properties" : { - "bindings" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/UserBinding" - } - }, - "createdAt" : { - "type" : "string", - "format" : "date-time" - }, - "id" : { - "type" : "string" - } - } - }, "OnboardedUsersResponse" : { "title" : "OnboardedUsersResponse", "type" : "object", @@ -7663,7 +7644,7 @@ "users" : { "type" : "array", "items" : { - "$ref" : "#/components/schemas/OnboardedUserResponse" + "$ref" : "#/components/schemas/UserProductsResponse" } } } diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java index 73260a487..85ebed564 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/mapper/UserMapper.java @@ -42,7 +42,7 @@ public interface UserMapper { InstitutionUpdate toInstitutionUpdate(InstitutionUpdateRequest request); UserNotificationResponse toUserNotification(UserNotificationToSend user); - OnboardedUserResponse toOnboardedUserResponse(OnboardedUser onboardedUser); + UserProductsResponse toOnboardedUserResponse(OnboardedUser onboardedUser); @Named("retrieveMailFromWorkContacts") default String retrieveMailFromWorkContacts(Map map, String institutionId){ diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java deleted file mode 100644 index 2ed1a2791..000000000 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUserResponse.java +++ /dev/null @@ -1,14 +0,0 @@ -package it.pagopa.selfcare.mscore.web.model.user; - -import it.pagopa.selfcare.mscore.model.user.UserBinding; -import lombok.Data; - -import java.time.OffsetDateTime; -import java.util.List; - -@Data -public class OnboardedUserResponse { - private String id; - private List bindings; - private OffsetDateTime createdAt; -} diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java index 3369961e0..b98f48c2b 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/model/user/OnboardedUsersResponse.java @@ -8,5 +8,5 @@ @Data @Builder public class OnboardedUsersResponse { - private List users; + private List users; }