diff --git a/apps/user-group-ms/app/src/main/docs/openapi.json b/apps/user-group-ms/app/src/main/docs/openapi.json index 3e2d933d..57768303 100644 --- a/apps/user-group-ms/app/src/main/docs/openapi.json +++ b/apps/user-group-ms/app/src/main/docs/openapi.json @@ -24,9 +24,9 @@ "description" : "User group endpoint CRUD operations" } ], "paths" : { - "/user-groups/v1/" : { + "/v1/user-groups" : { "get" : { - "tags" : [ "UserGroup" ], + "tags" : [ "UserGroup", "external-v2", "support", "support-pnpg" ], "summary" : "getUserGroups", "description" : "Service that allows to get a list of UserGroup entities", "operationId" : "getUserGroupsUsingGET", @@ -157,7 +157,6 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] @@ -228,13 +227,12 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] } }, - "/user-groups/v1/members/{memberId}" : { + "/v1/user-groups/members/{memberId}" : { "delete" : { "tags" : [ "UserGroup" ], "summary" : "deleteMemberFromUserGroups", @@ -304,13 +302,12 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] } }, - "/user-groups/v1/{id}" : { + "/v1/user-groups/{id}" : { "get" : { "tags" : [ "UserGroup" ], "summary" : "getUserGroup", @@ -378,7 +375,6 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] @@ -459,7 +455,6 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] @@ -514,13 +509,12 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] } }, - "/user-groups/v1/{id}/activate" : { + "/v1/user-groups/{id}/activate" : { "post" : { "tags" : [ "UserGroup" ], "summary" : "activateGroup", @@ -571,13 +565,12 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] } }, - "/user-groups/v1/{id}/members/{memberId}" : { + "/v1/user-groups/{id}/members/{memberId}" : { "put" : { "tags" : [ "UserGroup" ], "summary" : "addMemberToUserGroup", @@ -638,7 +631,6 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] @@ -703,13 +695,12 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] } }, - "/user-groups/v1/{id}/suspend" : { + "/v1/user-groups/{id}/suspend" : { "post" : { "tags" : [ "UserGroup" ], "summary" : "suspendGroup", @@ -760,739 +751,6 @@ } } }, - "deprecated" : true, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups" : { - "get" : { - "tags" : [ "UserGroup", "external-v2", "support", "support-pnpg" ], - "summary" : "getUserGroups", - "description" : "Service that allows to get a list of UserGroup entities", - "operationId" : "getUserGroupsUsingGET_1", - "parameters" : [ { - "name" : "institutionId", - "in" : "query", - "description" : "Users group's institutionId", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "page", - "in" : "query", - "description" : "The page number to access (0 indexed, defaults to 0)", - "required" : false, - "style" : "form", - "allowReserved" : true, - "schema" : { - "type" : "integer", - "format" : "int32" - } - }, { - "name" : "size", - "in" : "query", - "description" : "Number of records per page (defaults to 20, max 2000)", - "required" : false, - "style" : "form", - "allowReserved" : true, - "schema" : { - "type" : "integer", - "format" : "int32" - } - }, { - "name" : "sort", - "in" : "query", - "description" : "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.", - "required" : false, - "style" : "form", - "allowReserved" : true, - "schema" : { - "type" : "array", - "items" : { - "type" : "string" - } - } - }, { - "name" : "productId", - "in" : "query", - "description" : "Users group's productId", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "userId", - "in" : "query", - "description" : "Member's unique identifier", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string", - "format" : "uuid" - } - }, { - "name" : "status", - "in" : "query", - "description" : "If filter on status is present, it must be used with at least one of the other filters", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "ACTIVE", "DELETED", "SUSPENDED" ] - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/PageOfUserGroupResource" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - }, - "post" : { - "tags" : [ "UserGroup" ], - "summary" : "createGroup", - "description" : "Service that allows the insert of a new occurrence for the UserGroup entity", - "operationId" : "createGroupUsingPOST_1", - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/CreateUserGroupDto" - } - } - } - }, - "responses" : { - "201" : { - "description" : "Created", - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/UserGroupResource" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "409" : { - "description" : "Conflict", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups/members/{memberId}" : { - "delete" : { - "tags" : [ "UserGroup" ], - "summary" : "deleteMemberFromUserGroups", - "description" : "Service to delete a member from a specific UserGroup entity", - "operationId" : "deleteMemberFromUserGroupsUsingDELETE_1", - "parameters" : [ { - "name" : "memberId", - "in" : "path", - "description" : "Member's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string", - "format" : "uuid" - } - }, { - "name" : "institutionId", - "in" : "query", - "description" : "institutionId", - "required" : true, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "productId", - "in" : "query", - "description" : "productId", - "required" : true, - "style" : "form", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups/{id}" : { - "get" : { - "tags" : [ "UserGroup" ], - "summary" : "getUserGroup", - "description" : "Service to get a specific UserGroup entity", - "operationId" : "getUserGroupUsingGET_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/UserGroupResource" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - }, - "put" : { - "tags" : [ "UserGroup" ], - "summary" : "updateUserGroup", - "description" : "Service that allows the modification of a specific occurrence for the UserGroup entity by an Admin user", - "operationId" : "updateUserGroupUsingPUT_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/UpdateUserGroupDto" - } - } - } - }, - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/UserGroupResource" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "409" : { - "description" : "Conflict", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - }, - "delete" : { - "tags" : [ "UserGroup" ], - "summary" : "deleteGroup", - "description" : "Service that allows the deletion of a specific occurrence for the UserGroup entity by an Admin user", - "operationId" : "deleteGroupUsingDELETE_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups/{id}/activate" : { - "post" : { - "tags" : [ "UserGroup" ], - "summary" : "activateGroup", - "description" : "Service that allows the activation of a specific occurrence for the UserGroup entity by an Admin user", - "operationId" : "activateGroupUsingPOST_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups/{id}/members/{memberId}" : { - "put" : { - "tags" : [ "UserGroup" ], - "summary" : "addMemberToUserGroup", - "description" : "Service to add a member to a specific UserGroup entity", - "operationId" : "addMemberToUserGroupUsingPUT_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - }, { - "name" : "memberId", - "in" : "path", - "description" : "Member's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string", - "format" : "uuid" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - }, - "delete" : { - "tags" : [ "UserGroup" ], - "summary" : "deleteMemberFromUserGroup", - "description" : "Service to delete a member from a specific UserGroup entity", - "operationId" : "deleteMemberFromUserGroupUsingDELETE_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - }, { - "name" : "memberId", - "in" : "path", - "description" : "Member's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string", - "format" : "uuid" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/user-groups/{id}/suspend" : { - "post" : { - "tags" : [ "UserGroup" ], - "summary" : "suspendGroup", - "description" : "Service that allows the suspension of a specific occurrence for the UserGroup entity by an Admin user", - "operationId" : "suspendGroupUsingPOST_1", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "Users group's unique identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "204" : { - "description" : "No Content" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, "security" : [ { "bearerAuth" : [ "global" ] } ] diff --git a/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/controller/UserGroupController.java b/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/controller/UserGroupController.java deleted file mode 100644 index aecae7b2..00000000 --- a/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/controller/UserGroupController.java +++ /dev/null @@ -1,225 +0,0 @@ -package it.pagopa.selfcare.user_group.web.controller; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.tags.Tags; -import it.pagopa.selfcare.commons.web.model.Page; -import it.pagopa.selfcare.commons.web.model.Problem; -import it.pagopa.selfcare.commons.web.model.mapper.PageMapper; -import it.pagopa.selfcare.user_group.connector.api.UserGroupOperations; -import it.pagopa.selfcare.user_group.connector.model.UserGroupFilter; -import it.pagopa.selfcare.user_group.connector.model.UserGroupStatus; -import it.pagopa.selfcare.user_group.core.UserGroupService; -import it.pagopa.selfcare.user_group.web.model.CreateUserGroupDto; -import it.pagopa.selfcare.user_group.web.model.UpdateUserGroupDto; -import it.pagopa.selfcare.user_group.web.model.UserGroupResource; -import it.pagopa.selfcare.user_group.web.model.mapper.UserGroupMapper; -import lombok.extern.slf4j.Slf4j; -import org.owasp.encoder.Encode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; -import java.util.UUID; - -@Slf4j -@RestController -@RequestMapping(value = "/user-groups/v1", produces = MediaType.APPLICATION_JSON_VALUE) -@Api(tags = "UserGroup") -@Deprecated -public class UserGroupController { - - private final UserGroupService groupService; - private final UserGroupMapper userGroupMapper; - - @Autowired - public UserGroupController(UserGroupService groupService, - UserGroupMapper userGroupMapper) { - this.groupService = groupService; - this.userGroupMapper = userGroupMapper; - } - - @PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.CREATED) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.createUserGroup}") - @ApiResponse(responseCode = "409", - description = "Conflict", - content = { - @Content(mediaType = MediaType.APPLICATION_PROBLEM_JSON_VALUE, - schema = @Schema(implementation = Problem.class)) - }) - public UserGroupResource createGroup(@RequestBody - @Valid - CreateUserGroupDto group) { - log.trace("createGroup start"); - log.debug("createGroup group = {}", group); - UserGroupOperations groupOperations = groupService.createGroup(userGroupMapper.fromDto(group)); - UserGroupResource result = userGroupMapper.toResource(groupOperations); - log.debug("createGroup result = {}", result); - log.trace("createGroup end"); - return result; - } - - - @DeleteMapping("/{id}") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.deleteUserGroup}") - public void deleteGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id) { - log.trace("deteleGroup start"); - log.debug("deleteGroup id = {}", Encode.forJava(id)); - groupService.deleteGroup(id); - log.trace("deteleGroup end"); - - } - - - @PostMapping("/{id}/activate") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.activateUserGroup}") - public void activateGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id) { - log.trace("activateGroup start"); - log.debug("activateGroup id = {}", Encode.forJava(id)); - groupService.activateGroup(id); - log.trace("activateGroup end"); - } - - - @PostMapping("/{id}/suspend") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.suspendUserGroup}") - public void suspendGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id) { - log.trace("suspendGroup start"); - log.debug("suspendGroup id = {}", Encode.forJava(id)); - groupService.suspendGroup(id); - log.trace("suspendGroup end"); - } - - - @PutMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.updateUserGroup}") - @ApiResponse(responseCode = "409", - description = "Conflict", - content = { - @Content(mediaType = MediaType.APPLICATION_PROBLEM_JSON_VALUE, - schema = @Schema(implementation = Problem.class)) - }) - public UserGroupResource updateUserGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id, - @RequestBody - @Valid - UpdateUserGroupDto groupDto) { - log.trace("updateUserGroup start"); - log.debug("updateUserGroup id = {}", Encode.forJava(id)); - UserGroupOperations updatedGroup = groupService.updateGroup(id, userGroupMapper.toUserGroupOperations(groupDto)); - UserGroupResource result = userGroupMapper.toResource(updatedGroup); - log.debug("updateUserGroup result = {}", result); - log.trace("updateUserGroup end"); - return result; - } - - - @PutMapping(value = "/{id}/members/{memberId}") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.addMember}") - public void addMemberToUserGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id, - @ApiParam("${swagger.user-group.model.memberId}") - @PathVariable("memberId") - UUID userId) { - log.trace("addMemberToUserGroup start"); - log.debug("addMemberToUserGroup id = {}", Encode.forJava(id)); - groupService.addMember(id, userId); - log.trace("addMemberToUserGroup end"); - } - - - @GetMapping(value = "/{id}") - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.getUserGroup}") - public UserGroupResource getUserGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String id) { - log.trace("getUserGroup start"); - log.debug("getUserGroup id = {}", Encode.forJava(id)); - UserGroupOperations group = groupService.getUserGroup(id); - UserGroupResource groupResource = userGroupMapper.toResource(group); - log.debug("getUserGroup result = {}", groupResource); - log.trace("getUserGroup end"); - return groupResource; - } - - @GetMapping(value = "/") - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.getUserGroups}") - public Page getUserGroups(@ApiParam("${swagger.user-group.model.institutionId}") - @RequestParam(value = "institutionId", required = false) - String institutionId, - @ApiParam("${swagger.user-group.model.productId}") - @RequestParam(value = "productId", required = false) - String productId, - @ApiParam("${swagger.user-group.model.memberId}") - @RequestParam(value = "userId", required = false) - UUID memberId, - @ApiParam("${swagger.user-group.model.statusFilter}") - @RequestParam(value = "status", required = false) - List status, - Pageable pageable) { - log.trace("getUserGroups start"); - log.debug("getUserGroups institutionId = {}, productId = {}, pageable = {}, status = {}", Encode.forJava(institutionId), Encode.forJava(productId), pageable, status); - UserGroupFilter filter = new UserGroupFilter(institutionId, productId, memberId, status); - Page result = PageMapper.map(groupService.getUserGroups(filter, pageable) - .map(userGroupMapper::toResource)); - log.debug("getUserGroups result = {}", result); - log.trace("getUserGroups end"); - return result; - } - - @DeleteMapping(value = "/{id}/members/{memberId}") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.deleteMember}") - public void deleteMemberFromUserGroup(@ApiParam("${swagger.user-group.model.id}") - @PathVariable("id") - String userGroupId, - @ApiParam("${swagger.user-group.model.memberId}") - @PathVariable("memberId") - UUID memberId) { - log.trace("deleteMemberFromUserGroup start"); - log.debug("deleteMemberFromUserGroup userGroupId = {}, memberId = {}", Encode.forJava(userGroupId), memberId); - groupService.deleteMember(userGroupId, memberId.toString()); - log.trace("deleteMemberFromUserGroup end"); - } - - - @DeleteMapping(value = "/members/{memberId}") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "", notes = "${swagger.user-group.groups.api.deleteMember}") - public void deleteMemberFromUserGroups(@ApiParam("${swagger.user-group.model.memberId}") - @PathVariable("memberId") - UUID memberId, - @RequestParam(value = "institutionId") String institutionId, - @RequestParam(value = "productId") String productId) { - log.trace("deleteMemberFromUserGroups start"); - log.debug("deleteMemberFromUserGroups memberId = {}, institutionId = {}, productId = {}", memberId, Encode.forJava(institutionId), Encode.forJava(productId)); - groupService.deleteMembers(memberId.toString(), institutionId, productId); - log.trace("deleteMemberFromUserGroups end"); - } - -} diff --git a/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/handler/UserGroupExceptionHandler.java b/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/handler/UserGroupExceptionHandler.java index 83dbdefe..23ca627b 100644 --- a/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/handler/UserGroupExceptionHandler.java +++ b/apps/user-group-ms/web/src/main/java/it/pagopa/selfcare/user_group/web/handler/UserGroupExceptionHandler.java @@ -5,7 +5,6 @@ import it.pagopa.selfcare.user_group.connector.exception.ResourceAlreadyExistsException; import it.pagopa.selfcare.user_group.connector.exception.ResourceNotFoundException; import it.pagopa.selfcare.user_group.connector.exception.ResourceUpdateException; -import it.pagopa.selfcare.user_group.web.controller.UserGroupController; import it.pagopa.selfcare.user_group.web.controller.UserGroupV1Controller; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -14,7 +13,7 @@ import static org.springframework.http.HttpStatus.*; -@ControllerAdvice(assignableTypes = {UserGroupController.class, UserGroupV1Controller.class}) +@ControllerAdvice(assignableTypes = {UserGroupV1Controller.class}) @Slf4j public class UserGroupExceptionHandler { diff --git a/apps/user-group-ms/web/src/test/java/it/pagopa/selfcare/user_group/web/controller/UserGroupControllerTest.java b/apps/user-group-ms/web/src/test/java/it/pagopa/selfcare/user_group/web/controller/UserGroupControllerTest.java deleted file mode 100644 index a982ab2b..00000000 --- a/apps/user-group-ms/web/src/test/java/it/pagopa/selfcare/user_group/web/controller/UserGroupControllerTest.java +++ /dev/null @@ -1,371 +0,0 @@ -package it.pagopa.selfcare.user_group.web.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import it.pagopa.selfcare.user_group.connector.api.UserGroupOperations; -import it.pagopa.selfcare.user_group.connector.exception.ResourceNotFoundException; -import it.pagopa.selfcare.user_group.connector.model.UserGroupFilter; -import it.pagopa.selfcare.user_group.connector.model.UserGroupStatus; -import it.pagopa.selfcare.user_group.core.UserGroupService; -import it.pagopa.selfcare.user_group.web.config.WebTestConfig; -import it.pagopa.selfcare.user_group.web.handler.UserGroupExceptionHandler; -import it.pagopa.selfcare.user_group.web.model.*; -import it.pagopa.selfcare.user_group.web.model.mapper.UserGroupMapperImpl; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.Pageable; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; -import static java.util.UUID.randomUUID; -import static org.hamcrest.Matchers.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.springframework.data.support.PageableExecutionUtils.getPage; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.http.MediaType.APPLICATION_PROBLEM_JSON; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - - -@WebMvcTest(value = {UserGroupController.class}, excludeAutoConfiguration = SecurityAutoConfiguration.class) -@ContextConfiguration(classes = { - UserGroupController.class, - UserGroupExceptionHandler.class, - WebTestConfig.class, - UserGroupMapperImpl.class -}) -class UserGroupControllerTest { - - private static final DummyCreateUserGroupDto CREATE_USER_GROUP_DTO = mockInstance(new DummyCreateUserGroupDto()); - private static final DummyUpdateUserGroupDto UPDATE_USER_GROUP_DTO = mockInstance(new DummyUpdateUserGroupDto()); - private static final String BASE_URL = "/user-groups/v1"; - - @MockBean - private UserGroupService groupServiceMock; - - @Autowired - protected MockMvc mvc; - - @Autowired - protected ObjectMapper mapper; - - @Captor - private ArgumentCaptor pageableCaptor; - - @Test - void createGroup() throws Exception { - //given - when(groupServiceMock.createGroup(any(UserGroupOperations.class))) - .thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0, UserGroupOperations.class)); - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/") - .content(mapper.writeValueAsString(CREATE_USER_GROUP_DTO)) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isCreated()) - .andReturn(); - //then - UserGroupResource group = mapper.readValue(result.getResponse().getContentAsString(), UserGroupResource.class); - assertNotNull(group); - assertEquals(CREATE_USER_GROUP_DTO.getDescription(), group.getDescription()); - assertEquals(CREATE_USER_GROUP_DTO.getName(), group.getName()); - assertEquals(CREATE_USER_GROUP_DTO.getInstitutionId(), group.getInstitutionId()); - assertEquals(CREATE_USER_GROUP_DTO.getProductId(), group.getProductId()); - assertEquals(CREATE_USER_GROUP_DTO.getStatus(), group.getStatus()); - assertEquals(CREATE_USER_GROUP_DTO.getMembers(), group.getMembers()); - } - - @Test - void deleteGroup_doesNotExists() throws Exception { - //given - Mockito.doThrow(ResourceNotFoundException.class) - .when(groupServiceMock).deleteGroup(Mockito.anyString()); - //when - mvc.perform(MockMvcRequestBuilders - .delete(BASE_URL + "/id") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNotFound()) - .andExpect(content().contentType(APPLICATION_PROBLEM_JSON)) - .andExpect(content().string(not(emptyString()))); - //then - } - - @Test - void deleteGroup() throws Exception { - Mockito.doNothing() - .when(groupServiceMock).deleteGroup(Mockito.anyString()); - // when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .delete(BASE_URL + "/id") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().is2xxSuccessful()) - .andReturn(); - // then - assertEquals("", result.getResponse().getContentAsString()); - verify(groupServiceMock, times(1)) - .deleteGroup(Mockito.anyString()); - Mockito.verifyNoMoreInteractions(groupServiceMock); - - } - - @Test - void activateGroup_doesNotExists() throws Exception { - //given - String groupId = "groupId"; - Mockito.doThrow(ResourceNotFoundException.class) - .when(groupServiceMock).activateGroup(Mockito.anyString()); - //when - mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/{id}/activate", groupId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNotFound()) - .andExpect(content().contentType(APPLICATION_PROBLEM_JSON)) - .andExpect(content().string(not(emptyString()))); - //then - } - - @Test - void activateGroup() throws Exception { - //given - String groupId = "groupId"; - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/{id}/activate", groupId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNoContent()) - .andReturn(); - //then - assertEquals(0, result.getResponse().getContentLength()); - verify(groupServiceMock, times(1)) - .activateGroup(groupId); - Mockito.verifyNoMoreInteractions(groupServiceMock); - } - - @Test - void suspendGroup_doesNotExists() throws Exception { - //given - String groupId = "groupId"; - Mockito.doThrow(ResourceNotFoundException.class) - .when(groupServiceMock).suspendGroup(Mockito.anyString()); - //when - mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/{id}/suspend", groupId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNotFound()) - .andExpect(content().contentType(APPLICATION_PROBLEM_JSON)) - .andExpect(content().string(not(emptyString()))); - //then - } - - @Test - void suspendGroup() throws Exception { - //given - String groupId = "groupId"; - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/{id}/suspend", groupId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNoContent()) - .andReturn(); - //then - assertEquals(0, result.getResponse().getContentLength()); - verify(groupServiceMock, times(1)) - .suspendGroup(groupId); - Mockito.verifyNoMoreInteractions(groupServiceMock); - } - - @Test - void updateGroup_exists() throws Exception { - //given - when(groupServiceMock.updateGroup(Mockito.anyString(), any(UserGroupOperations.class))) - .thenAnswer(invocationOnMock -> { - String id = invocationOnMock.getArgument(0, String.class); - UserGroupOperations group = invocationOnMock.getArgument(1, UserGroupOperations.class); - group.setId(id); - group.setMembers(Set.of(randomUUID().toString(), randomUUID().toString())); - return group; - }); - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .put(BASE_URL + "/id") - .content(mapper.writeValueAsString(UPDATE_USER_GROUP_DTO)) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().is2xxSuccessful()) - .andReturn(); - //then - UserGroupResource group = mapper.readValue(result.getResponse().getContentAsString(), UserGroupResource.class); - - assertNotNull(group); - assertEquals(UPDATE_USER_GROUP_DTO.getDescription(), group.getDescription()); - assertEquals(UPDATE_USER_GROUP_DTO.getName(), group.getName()); - assertNotEquals(UPDATE_USER_GROUP_DTO.getMembers().size(), group.getMembers().size()); - } - - @Test - void addMember() throws Exception { - //given - String groupId = "groupId"; - MemberUUID member = new MemberUUID(); - member.setMember(randomUUID()); - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .put(BASE_URL + "/groupId/members/" + member.getMember()) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().is2xxSuccessful()) - .andReturn(); - //then - assertEquals(0, result.getResponse().getContentLength()); - verify(groupServiceMock, times(1)) - .addMember(groupId, member.getMember()); - Mockito.verifyNoMoreInteractions(groupServiceMock); - } - - @Test - void deleteMember() throws Exception { - //given - String groupId = "groupId"; - UUID memberId = randomUUID(); - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .delete(BASE_URL + "/groupId/members/" + memberId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNoContent()) - .andReturn(); - //then - assertEquals(0, result.getResponse().getContentLength()); - verify(groupServiceMock, times(1)) - .deleteMember(groupId, memberId.toString()); - Mockito.verifyNoMoreInteractions(groupServiceMock); - } - - @Test - void getUserGroup() throws Exception { - //given - String InstitutionId = "institutionId"; - String productId = "productId"; - when(groupServiceMock.getUserGroup(Mockito.anyString())) - .thenAnswer(invocationOnMock -> { - String id = invocationOnMock.getArgument(0, String.class); - UserGroupOperations group = mockInstance(new GroupDto(), "setId"); - group.setId(id); - group.setMembers(Set.of(randomUUID().toString(), randomUUID().toString())); - return group; - }); - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .get(BASE_URL + "/groupId") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().is2xxSuccessful()) - .andReturn(); - //then - UserGroupResource group = mapper.readValue(result.getResponse().getContentAsString(), UserGroupResource.class); - assertNotNull(group); - } - - @Test - void getUserGroups() throws Exception { - //given - String institutionId = "institutionId"; - String productId = "productId"; - String userId = randomUUID().toString(); - UserGroupStatus allowedStatus = UserGroupStatus.ACTIVE; - final int page = 1; - final int size = 3; - UserGroupOperations groupOperations = mockInstance(new GroupDto()); - groupOperations.setMembers(Set.of(randomUUID().toString())); - when(groupServiceMock.getUserGroups(any(), any())) - .thenAnswer(invocation -> { - final Pageable pageable = invocation.getArgument(1, Pageable.class); - return getPage(List.of(groupOperations), pageable, () -> pageable.isPaged() - ? (long) pageable.getPageSize() * pageable.getPageNumber() + 1 - : 1); - }); - //when - mvc.perform(MockMvcRequestBuilders - .get(BASE_URL + "/") - .param("institutionId", institutionId) - .param("productId", productId) - .param("userId", userId) - .param("status", String.valueOf(allowedStatus)) - .param("page", String.valueOf(page)) - .param("size", String.valueOf(size)) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.number", notNullValue())) - .andExpect(jsonPath("$.size", notNullValue())) - .andExpect(jsonPath("$.totalElements", notNullValue())) - .andExpect(jsonPath("$.totalPages", notNullValue())) - .andExpect(jsonPath("$.content", notNullValue())) - .andExpect(jsonPath("$.content[0].id", notNullValue())) - .andExpect(jsonPath("$.content[0].institutionId", notNullValue())) - .andExpect(jsonPath("$.content[0].productId", notNullValue())) - .andExpect(jsonPath("$.content[0].name", notNullValue())) - .andExpect(jsonPath("$.content[0].description", notNullValue())) - .andExpect(jsonPath("$.content[0].status", notNullValue())) - .andExpect(jsonPath("$.content[0].members", not(emptyArray()))) - .andExpect(jsonPath("$.content[0].createdAt", notNullValue())) - .andExpect(jsonPath("$.content[0].createdBy", notNullValue())) - .andExpect(jsonPath("$.content[0].modifiedAt", notNullValue())) - .andExpect(jsonPath("$.content[0].modifiedBy", notNullValue())); - //then - ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserGroupFilter.class); - verify(groupServiceMock, times(1)) - .getUserGroups(filterCaptor.capture(), pageableCaptor.capture()); - UserGroupFilter capturedFilter = filterCaptor.getValue(); - assertEquals(capturedFilter.getProductId(), productId); - assertEquals(capturedFilter.getInstitutionId(), institutionId); - assertEquals(capturedFilter.getUserId(), userId); - Pageable capturedPageable = pageableCaptor.getValue(); - assertTrue(capturedPageable.getSort().isUnsorted()); - assertEquals(page, capturedPageable.getPageNumber()); - assertEquals(size, capturedPageable.getPageSize()); - } - - @Test - void deleteMembers() throws Exception { - //given - UUID memberId = randomUUID(); - String institutionId = "institutionId"; - String productId = "productId"; - //when - MvcResult result = mvc.perform(MockMvcRequestBuilders - .delete(BASE_URL + "/members/" + memberId) - .param("institutionId", institutionId) - .param("productId", productId) - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isNoContent()) - .andReturn(); - //then - assertEquals(0, result.getResponse().getContentLength()); - verify(groupServiceMock, times(1)) - .deleteMembers(memberId.toString(), institutionId, productId); - Mockito.verifyNoMoreInteractions(groupServiceMock); - } - -} \ No newline at end of file