diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 9dba85833..d12a3d117 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -770,113 +770,6 @@ } ] } }, - "/external/institutions/{externalId}/relationships" : { - "get" : { - "tags" : [ "External" ], - "summary" : "returns the relationships related to the institution", - "description" : "returns the relationships related to the institution", - "operationId" : "getUserInstitutionRelationshipsByExternalIdUsingGET", - "parameters" : [ { - "name" : "externalId", - "in" : "path", - "description" : "Institution's unique external identifier", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - }, { - "name" : "personId", - "in" : "query", - "description" : "personId", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "roles", - "in" : "query", - "description" : "roles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "DELEGATE", "MANAGER", "OPERATOR", "SUB_DELEGATE" ] - } - }, { - "name" : "states", - "in" : "query", - "description" : "states", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "ACTIVE", "DELETED", "PENDING", "REJECTED", "SUSPENDED", "TOBEVALIDATED" ] - } - }, { - "name" : "products", - "in" : "query", - "description" : "products", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "productRoles", - "in" : "query", - "description" : "productRoles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/RelationshipResult" - } - } - } - } - }, - "400" : { - "description" : "Bad Request", - "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" ] - } ] - } - }, "/institutions" : { "get" : { "tags" : [ "Institution", "external-v2", "support" ], @@ -1992,113 +1885,6 @@ } ] } }, - "/institutions/{id}/relationships" : { - "get" : { - "tags" : [ "Institution" ], - "summary" : "returns the relationships related to the institution", - "description" : "returns the relationships related to the institution", - "operationId" : "getUserInstitutionRelationshipsUsingGET", - "parameters" : [ { - "name" : "id", - "in" : "path", - "description" : "The internal identifier of the institution", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - }, { - "name" : "personId", - "in" : "query", - "description" : "personId", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "roles", - "in" : "query", - "description" : "roles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "DELEGATE", "MANAGER", "OPERATOR", "SUB_DELEGATE" ] - } - }, { - "name" : "states", - "in" : "query", - "description" : "states", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "ACTIVE", "DELETED", "PENDING", "REJECTED", "SUSPENDED", "TOBEVALIDATED" ] - } - }, { - "name" : "products", - "in" : "query", - "description" : "products", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "productRoles", - "in" : "query", - "description" : "productRoles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/RelationshipResult" - } - } - } - } - }, - "400" : { - "description" : "Bad Request", - "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" ] - } ] - } - }, "/institutions/{institutionId}/createdAt" : { "put" : { "tags" : [ "Institution" ], @@ -2410,111 +2196,6 @@ } ] } }, - "/relationships" : { - "get" : { - "tags" : [ "Management" ], - "summary" : "Return a list of relationships", - "description" : "Return a list of relationships", - "operationId" : "getInstitutionRelationshipsUsingGET", - "parameters" : [ { - "name" : "from", - "in" : "query", - "description" : "from", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "to", - "in" : "query", - "description" : "to", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "roles", - "in" : "query", - "description" : "roles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "DELEGATE", "MANAGER", "OPERATOR", "SUB_DELEGATE" ] - } - }, { - "name" : "states", - "in" : "query", - "description" : "states", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string", - "enum" : [ "ACTIVE", "DELETED", "PENDING", "REJECTED", "SUSPENDED", "TOBEVALIDATED" ] - } - }, { - "name" : "products", - "in" : "query", - "description" : "products", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "productRoles", - "in" : "query", - "description" : "productRoles", - "required" : false, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "204" : { - "description" : "No Content", - "content" : { - "*/*" : { - "schema" : { - "$ref" : "#/components/schemas/RelationshipsManagement" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "deprecated" : true, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, "/onboarding" : { "head" : { "tags" : [ "Onboarding" ], @@ -5998,18 +5679,6 @@ } } }, - "RelationshipsManagement" : { - "title" : "RelationshipsManagement", - "type" : "object", - "properties" : { - "items" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/RelationshipResult" - } - } - } - }, "RootParent" : { "title" : "RootParent", "type" : "object", diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalService.java index 1579553f7..f1467b25f 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalService.java @@ -1,12 +1,10 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.commons.base.security.PartyRole; -import it.pagopa.selfcare.mscore.model.institution.Onboarding; -import it.pagopa.selfcare.mscore.model.user.ProductManagerInfo; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.model.institution.GeographicTaxonomies; import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.institution.Onboarding; +import it.pagopa.selfcare.mscore.model.user.ProductManagerInfo; import java.util.List; @@ -20,12 +18,6 @@ public interface ExternalService { List retrieveInstitutionGeoTaxonomiesByExternalId(String externalId); - List getUserInstitutionRelationships(String externalId, String userId, String personId, - List roles, - List states, - List products, - List productRoles); - List retrieveInstitutionProductsByExternalId(String externalId, List states); List retrieveInstitutionByIds(List ids); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalServiceImpl.java index 7efc179fc..38eb15c91 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ExternalServiceImpl.java @@ -1,19 +1,18 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.commons.base.security.PartyRole; +import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; import it.pagopa.selfcare.mscore.model.institution.GeographicTaxonomies; import it.pagopa.selfcare.mscore.model.institution.Institution; import it.pagopa.selfcare.mscore.model.institution.Onboarding; import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.user.ProductManagerInfo; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; -import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.model.user.UserBinding; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; + import static it.pagopa.selfcare.mscore.constant.GenericError.INSTITUTION_MANAGER_ERROR; @Service @@ -74,16 +73,4 @@ public List retrieveInstitutionGeoTaxonomiesByExternalId(S Institution institution = institutionService.retrieveInstitutionByExternalId(externalId); return institutionService.retrieveInstitutionGeoTaxonomies(institution); } - - @Override - public List getUserInstitutionRelationships(String externalId, - String userId, - String personId, - List roles, - List states, - List products, - List productRoles) { - Institution institution = institutionService.retrieveInstitutionByExternalId(externalId); - return institutionService.retrieveUserInstitutionRelationships(institution, userId, personId, roles, states, products, productRoles); - } } diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionService.java index 265122c7d..5b6204713 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionService.java @@ -1,14 +1,11 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.commons.base.security.SelfCareUser; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.constant.SearchMode; import it.pagopa.selfcare.mscore.core.util.InstitutionPaSubunitType; import it.pagopa.selfcare.mscore.model.institution.*; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; -import it.pagopa.selfcare.mscore.model.user.UserBinding; import it.pagopa.selfcare.mscore.model.user.UserInfo; import java.time.OffsetDateTime; @@ -47,16 +44,6 @@ public interface InstitutionService { Institution retrieveInstitutionProduct(String externalId, String productId); - List retrieveUserRelationships(String userId, String institutionId, List roles, List states, List products, List productRoles); - - List retrieveUserInstitutionRelationships(Institution institution, - String userId, - String personId, - List roles, - List states, - List products, - List productRoles); - void retrieveInstitutionsWithFilter(String externalId, String productId, List validRelationshipStates); List retrieveInstitutionGeoTaxonomies(Institution institution); @@ -79,8 +66,6 @@ List retrieveUserInstitutionRelationships(Institution institut void updateCreatedAt(String institutionId, String productId, OffsetDateTime createdAt, OffsetDateTime activatedAt); - List retrieveAllProduct(String userId, UserBinding binding, Institution institution, List roles, List states, List products, List productRoles); - List getInstitutionsByProductId(String productId, Integer page, Integer size); List getInstitutionBrokers(String productId, InstitutionType type); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java index 4718f3b1e..b31956aa0 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java @@ -1,7 +1,6 @@ package it.pagopa.selfcare.mscore.core; import it.pagopa.selfcare.commons.base.logging.LogUtils; -import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.commons.base.security.SelfCareUser; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.mscore.api.*; @@ -12,15 +11,14 @@ import it.pagopa.selfcare.mscore.core.strategy.factory.CreateInstitutionStrategyFactory; import it.pagopa.selfcare.mscore.core.strategy.input.CreateInstitutionStrategyInput; import it.pagopa.selfcare.mscore.core.util.InstitutionPaSubunitType; -import it.pagopa.selfcare.mscore.exception.*; +import it.pagopa.selfcare.mscore.exception.InvalidRequestException; +import it.pagopa.selfcare.mscore.exception.MsCoreException; +import it.pagopa.selfcare.mscore.exception.ResourceConflictException; +import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.institution.*; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.onboarding.Token; import it.pagopa.selfcare.mscore.model.onboarding.TokenUser; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; -import it.pagopa.selfcare.mscore.model.user.UserBinding; import it.pagopa.selfcare.mscore.model.user.UserInfo; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -28,12 +26,13 @@ import org.springframework.util.StringUtils; import java.time.OffsetDateTime; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import static it.pagopa.selfcare.mscore.constant.GenericError.CREATE_INSTITUTION_ERROR; -import static it.pagopa.selfcare.mscore.core.util.UtilEnumList.ADMIN_PARTY_ROLE; -import static it.pagopa.selfcare.mscore.core.util.UtilEnumList.ONBOARDING_INFO_DEFAULT_RELATIONSHIP_STATES; @Slf4j @Service @@ -373,30 +372,6 @@ public List retrieveInstitutionByIds(List ids) { return institutionConnector.findAllByIds(ids); } - @Override - public List retrieveUserInstitutionRelationships(Institution institution, String userId, String personId, List roles, List states, List products, List productRoles) { - List adminRelationships = userService.retrieveUsers(institution.getId(), userId, ADMIN_PARTY_ROLE, ONBOARDING_INFO_DEFAULT_RELATIONSHIP_STATES, null, null); - String personToFilter = personId; - if (adminRelationships.isEmpty()) { - personToFilter = userId; - } - List institutionRelationships = userService.retrieveUsers(institution.getId(), personToFilter, roles, states, products, productRoles); - return toRelationshipInfo(institutionRelationships, institution, roles, states, products, productRoles); - } - - @Override - public List retrieveUserRelationships(String userId, String institutionId, List roles, List states, List products, List productRoles) { - Institution institution = null; - if (!StringUtils.hasText(userId) && !StringUtils.hasText(institutionId) - && (products == null || products.isEmpty())) { - throw new InvalidRequestException(CustomError.MISSING_QUERY_PARAMETER.getMessage(), CustomError.MISSING_QUERY_PARAMETER.getCode()); - } - if (StringUtils.hasText(institutionId)) { - institution = retrieveInstitutionById(institutionId); - } - return toRelationshipInfo(userService.retrieveUsers(institutionId, userId, roles, states, products, productRoles), institution, roles, states, products, productRoles); - } - @Override public void updateCreatedAt(String institutionId, String productId, OffsetDateTime createdAt, OffsetDateTime activatedAt) { log.trace("updateCreatedAt start"); @@ -428,47 +403,6 @@ public void checkIfAlreadyExists(String externalId) { } } - private List toRelationshipInfo(List institutionRelationships, Institution institution, List roles, List states, List products, List productRoles) { - List list = new ArrayList<>(); - for (OnboardedUser onboardedUser : institutionRelationships) { - for (UserBinding binding : onboardedUser.getBindings()) { - list.addAll(retrieveAllProduct(onboardedUser.getId(), binding, institution, roles, states, products, productRoles)); - } - } - return list; - } - - @Override - public List retrieveAllProduct(String userId, UserBinding binding, Institution institution, List roles, List states, List products, List productRoles) { - List relationshipInfoList = new ArrayList<>(); - if (institution != null) { - if (institution.getId().equalsIgnoreCase(binding.getInstitutionId())) { - relationshipInfoList = binding.getProducts().stream() - .filter(product -> filterProduct(product, roles, states, products, productRoles)) - .map(product -> { - RelationshipInfo relationshipInfo = new RelationshipInfo(); - relationshipInfo.setInstitution(institution); - relationshipInfo.setUserId(userId); - relationshipInfo.setOnboardedProduct(product); - return relationshipInfo; - }) - .collect(Collectors.toList()); - } - } else { - for (OnboardedProduct product : binding.getProducts()) { - if (Boolean.TRUE.equals(filterProduct(product, roles, states, products, productRoles))) { - Institution retrievedInstitution = retrieveInstitutionById(binding.getInstitutionId()); - RelationshipInfo relationshipInfo = new RelationshipInfo(); - relationshipInfo.setInstitution(retrievedInstitution); - relationshipInfo.setUserId(userId); - relationshipInfo.setOnboardedProduct(product); - relationshipInfoList.add(relationshipInfo); - } - } - } - return relationshipInfoList; - } - @Override public List getInstitutionBrokers(String productId, InstitutionType type) { return institutionConnector.findBrokers(productId, type); @@ -485,22 +419,4 @@ public List getInstitutionUsers(String institutionId) { log.trace("getInstitutionUsers end"); return userInfos; } - - protected Boolean filterProduct(OnboardedProduct product, List roles, List states, List products, List productRoles) { - - if (roles != null && !roles.isEmpty() && !roles.contains(product.getRole())) { - return false; - } - - if (states != null && !states.isEmpty() && !states.contains(product.getStatus())) { - return false; - } - - if (products != null && !products.isEmpty() && !products.contains(product.getProductId())) { - return false; - } - - return !(productRoles != null && !productRoles.isEmpty() && !productRoles.contains(product.getProductRole())); - - } } diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/UserService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/UserService.java index e209f03dc..cf122021d 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/UserService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/UserService.java @@ -25,8 +25,6 @@ public interface UserService { List retrieveBindings(String institutionId, String userId, String[] states, List products); - List retrieveUsers(String institutionId, String personId, List roles, List states, List products, List productRoles); - boolean checkIfInstitutionUser(String userId, String institutionId); User retrieveUserFromUserRegistry(String userId); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/UserServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/UserServiceImpl.java index 32d679bd4..c4fb574e6 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/UserServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/UserServiceImpl.java @@ -111,11 +111,6 @@ public List retrieveBindings(String institutionId, String userId, S .collect(Collectors.toList()); } - @Override - public List retrieveUsers(String institutionId, String personId, List roles, List states, List products, List productRoles) { - return userConnector.findWithFilter(institutionId, personId, roles, states, products, productRoles); - } - @Override public boolean checkIfInstitutionUser(String userId, String institutionId) { return !userConnector.findActiveInstitutionUser(userId, institutionId).isEmpty(); diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/ExternalServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/ExternalServiceImplTest.java index ca0db101e..8d87eceb3 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/ExternalServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/ExternalServiceImplTest.java @@ -1,13 +1,11 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; import it.pagopa.selfcare.mscore.model.institution.GeographicTaxonomies; import it.pagopa.selfcare.mscore.model.institution.Institution; import it.pagopa.selfcare.mscore.model.institution.Onboarding; import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.model.user.UserBinding; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -273,42 +271,4 @@ void testRetrieveInstitutionGeoTaxonomiesByExternalId() { verify(institutionService).retrieveInstitutionByExternalId(any()); verify(institutionService).retrieveInstitutionGeoTaxonomies(any()); } - - /** - * Method under test: {@link ExternalServiceImpl#getUserInstitutionRelationships(String, String, String, List, List, List, List)} - */ - @Test - void testGetUserInstitutionRelationships() { - when(institutionService.retrieveInstitutionByExternalId(any())).thenReturn(new Institution()); - ArrayList relationshipInfoList = new ArrayList<>(); - when(institutionService.retrieveUserInstitutionRelationships(any(), any(), any(), - any(), any(), any(), any())) - .thenReturn(relationshipInfoList); - ArrayList roles = new ArrayList<>(); - ArrayList states = new ArrayList<>(); - ArrayList products = new ArrayList<>(); - List actualUserInstitutionRelationships = externalServiceImpl - .getUserInstitutionRelationships("42", "42", "42", roles, states, products, new ArrayList<>()); - assertSame(relationshipInfoList, actualUserInstitutionRelationships); - assertTrue(actualUserInstitutionRelationships.isEmpty()); - verify(institutionService).retrieveInstitutionByExternalId(any()); - verify(institutionService).retrieveUserInstitutionRelationships(any(), any(), - any(), any(), any(), any(), - any()); - } - - /** - * Method under test: {@link ExternalServiceImpl#getUserInstitutionRelationships(String, String, String, List, List, List, List)} - */ - @Test - void testGetUserInstitutionRelationships2() { - when(institutionService.retrieveInstitutionByExternalId(any())) - .thenThrow(new InvalidRequestException("An error occurred", "Code")); - ArrayList roles = new ArrayList<>(); - ArrayList states = new ArrayList<>(); - ArrayList products = new ArrayList<>(); - ArrayList productRoles = new ArrayList<>(); - assertThrows(InvalidRequestException.class, () -> externalServiceImpl.getUserInstitutionRelationships("42", "42", - "42", roles, states, products, productRoles)); - } } diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java index 110c02671..76136f3b4 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java @@ -12,16 +12,15 @@ import it.pagopa.selfcare.mscore.core.strategy.CreateInstitutionStrategy; import it.pagopa.selfcare.mscore.core.strategy.factory.CreateInstitutionStrategyFactory; import it.pagopa.selfcare.mscore.core.util.InstitutionPaSubunitType; -import it.pagopa.selfcare.mscore.exception.*; +import it.pagopa.selfcare.mscore.exception.InvalidRequestException; +import it.pagopa.selfcare.mscore.exception.MsCoreException; +import it.pagopa.selfcare.mscore.exception.ResourceConflictException; +import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; import it.pagopa.selfcare.mscore.model.institution.*; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.onboarding.Token; import it.pagopa.selfcare.mscore.model.onboarding.TokenUser; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.model.user.User; -import it.pagopa.selfcare.mscore.model.user.UserBinding; import it.pagopa.selfcare.mscore.model.user.UserInfo; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -40,7 +39,6 @@ import java.util.Optional; import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; -import static it.pagopa.selfcare.mscore.core.util.TestUtils.dummyInstitutionPa; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -182,11 +180,8 @@ void testCreateInstitutionByExternalId2() { when(institutionConnector.save(any())).thenReturn(institution); when(institutionConnector.findByExternalId(any())).thenReturn(Optional.empty()); - InstitutionProxyInfo institutionProxyInfo = dummyInstitutionProxyInfo; - CategoryProxyInfo categoryProxyInfo = dummyCategoryProxyInfo; - - when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(categoryProxyInfo); - when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(institutionProxyInfo); + when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(dummyCategoryProxyInfo); + when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(dummyInstitutionProxyInfo); assertSame(institution, institutionServiceImpl.createInstitutionByExternalId("42")); verify(institutionConnector).save(any()); verify(institutionConnector).findByExternalId(any()); @@ -203,11 +198,8 @@ void shouldThrowExceptionOnCreationInstitutionByExternalIdWhenSaveAlreadyExists( .thenThrow(new ResourceConflictException("An error occurred", "START - check institution {} already exists")); when(institutionConnector.findByExternalId(any())).thenReturn(Optional.empty()); - InstitutionProxyInfo institutionProxyInfo = dummyInstitutionProxyInfo; - CategoryProxyInfo categoryProxyInfo = dummyCategoryProxyInfo; - - when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(categoryProxyInfo); - when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(institutionProxyInfo); + when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(dummyCategoryProxyInfo); + when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(dummyInstitutionProxyInfo); assertThrows(MsCoreException.class, () -> institutionServiceImpl.createInstitutionByExternalId("42")); verify(institutionConnector).save(any()); verify(institutionConnector).findByExternalId(any()); @@ -232,11 +224,9 @@ void shouldThrowExceptionOnCreationInstitutionByExternalIdIfAlreadyExists() { */ @Test void testCreateInstitutionByExternalId6() { - InstitutionProxyInfo institutionProxyInfo = dummyInstitutionProxyInfo; - CategoryProxyInfo categoryProxyInfo = dummyCategoryProxyInfo; - when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(categoryProxyInfo); - when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(institutionProxyInfo); + when(partyRegistryProxyConnector.getCategory(any(), any())).thenReturn(dummyCategoryProxyInfo); + when(partyRegistryProxyConnector.getInstitutionById(any())).thenReturn(dummyInstitutionProxyInfo); Institution institution = new Institution(); when(institutionConnector.save(any())).thenReturn(institution); when(institutionConnector.findByExternalId(any())).thenReturn(Optional.empty()); @@ -542,10 +532,6 @@ void testRetrieveInstitutionProduct2() { */ @Test void testRetrieveInstitutionGeoTaxonomies2() { - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - UserServiceImpl userService = new UserServiceImpl(null, null, null, null); - //InstitutionServiceImpl institutionServiceImpl = new InstitutionServiceImpl(partyRegistryProxyConnector, null, - // userService, new CoreConfig(), mock(TokenConnector.class), mock(UserConnector.class), contractService); Institution institution = new Institution(); institution.setGeographicTaxonomies(new ArrayList<>()); @@ -758,136 +744,6 @@ void testRetrieveInstitutionByIds2() { verify(institutionConnector).findAllByIds(any()); } - /** - * Method under test: {@link InstitutionServiceImpl#retrieveUserInstitutionRelationships(Institution, String, String, List, List, List, List)} - */ - @Test - void testRetrieveUserInstitutionRelationships3() { - - when(userService.retrieveUsers(any(), any(), any(), - any(), any(), any())).thenReturn(new ArrayList<>()); - - Institution institution = new Institution(); - ArrayList roles = new ArrayList<>(); - ArrayList states = new ArrayList<>(); - ArrayList products = new ArrayList<>(); - assertTrue(institutionServiceImpl - .retrieveUserInstitutionRelationships(institution, "42", "42", roles, states, products, new ArrayList<>()) - .isEmpty()); - verify(userService, atLeast(1)).retrieveUsers(any(), any(), any(), - any(), any(), any()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveUserInstitutionRelationships(Institution, String, String, List, List, List, List)} - */ - @Test - void testRetrieveUserInstitutionRelationships9() { - ArrayList userBindingList = new ArrayList<>(); - userBindingList.add(new UserBinding()); - - OnboardedUser onboardedUser = new OnboardedUser(); - onboardedUser.setBindings(userBindingList); - - ArrayList onboardedUserList = new ArrayList<>(); - onboardedUserList.add(onboardedUser); - - when(userService.retrieveUsers(any(), any(), any(), - any(), any(), any())).thenReturn(onboardedUserList); - - Billing billing = new Billing(); - ArrayList onboarding = new ArrayList<>(); - ArrayList geographicTaxonomies = new ArrayList<>(); - ArrayList attributes = new ArrayList<>(); - PaymentServiceProvider paymentServiceProvider = new PaymentServiceProvider("Abi Code", "42", - "Legal Register Name", "42", true); - - Institution institution = dummyInstitutionPa(); - - assertTrue(institutionServiceImpl - .retrieveUserInstitutionRelationships(institution, "42", "42", List.of(), List.of(), List.of(), List.of()) - .isEmpty()); - verify(userService, atLeast(1)).retrieveUsers(any(), any(), any(), - any(), any(), any()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveUserRelationships(String, String, List, List, List, List)} - */ - @Test - void testRetrieveUserRelationships2() { - - ArrayList roles = new ArrayList<>(); - ArrayList states = new ArrayList<>(); - ArrayList products = new ArrayList<>(); - List list = new ArrayList<>(); - assertThrows(InvalidRequestException.class, () -> institutionServiceImpl.retrieveUserRelationships(null, null, - roles, states, products, list)); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveUserRelationships(String, String, List, List, List, List)} - */ - @Test - void testRetrieveUserRelationships6() { - OnboardedUser onboardedUser = new OnboardedUser(); - onboardedUser.setBindings(new ArrayList<>()); - - ArrayList onboardedUserList = new ArrayList<>(); - onboardedUserList.add(onboardedUser); - - when(userService.retrieveUsers(any(), any(), any(), - any(), any(), any())).thenReturn(onboardedUserList); - - assertTrue( - institutionServiceImpl.retrieveUserRelationships("42", "42", List.of(), List.of(), List.of(), List.of()) - .isEmpty()); - verify(userService).retrieveUsers(any(), any(), any(), - any(), any(), any()); - } - - @Test - void testRetrieveUserRelationships9() { - UserBinding userBinding = new UserBinding(); - userBinding.setProducts(new ArrayList<>()); - - ArrayList userBindingList = new ArrayList<>(); - userBindingList.add(userBinding); - - OnboardedUser onboardedUser = new OnboardedUser(); - onboardedUser.setBindings(userBindingList); - - ArrayList onboardedUserList = new ArrayList<>(); - onboardedUserList.add(onboardedUser); - - when(userService.retrieveUsers(any(), any(), any(), - any(), any(), any())).thenReturn(onboardedUserList); - - assertTrue( - institutionServiceImpl.retrieveUserRelationships("42", "42", List.of(), List.of(), List.of(), List.of()) - .isEmpty()); - verify(userService).retrieveUsers(any(), any(), any(), any(), any(), any()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveUserRelationships(String, String, List, List, List, List)} - */ - @Test - void testRetrieveUserRelationships13() { - - when(institutionConnector.findById(any())).thenReturn(new Institution()); - when(userService.retrieveUsers(any(), any(), any(), - any(), any(), any())).thenReturn(new ArrayList<>()); - - - assertTrue( - institutionServiceImpl.retrieveUserRelationships(null, "42", List.of(), List.of(), List.of(), List.of()) - .isEmpty()); - verify(institutionConnector).findById(any()); - verify(userService).retrieveUsers(any(), any(), any(), - any(), any(), any()); - } - /** * Method under test: {@link InstitutionServiceImpl#retrieveInstitutionProduct(String, String)} */ @@ -910,276 +766,6 @@ void testGetInstitutionProduct2() { verify(institutionConnector).findByExternalIdAndProductId(any(), any()); } - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct6() { - - UserBinding binding = new UserBinding(); - binding.setInstitutionId("43"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - binding.setProducts(List.of(product)); - when(institutionConnector.findById(any())).thenReturn(new Institution()); - - Assertions.assertDoesNotThrow(() -> institutionServiceImpl.retrieveAllProduct("42", binding, null, null, null, null, null)); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_allEmpty() { - - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = Collections.emptyList(); - List states = Collections.emptyList(); - List products = Collections.emptyList(); - List productRoles = Collections.emptyList(); - - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - assertFalse(relationshipInfoList.isEmpty()); - assertEquals(relationshipInfoList.get(0).getOnboardedProduct().getProductId(), binding.getProducts().get(0).getProductId()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_noRoleFound() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - product.setRole(PartyRole.MANAGER); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.DELEGATE); - List states = Collections.emptyList(); - List products = Collections.emptyList(); - List productRoles = Collections.emptyList(); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertTrue(relationshipInfoList.isEmpty()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_noStatesFound() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - product.setRole(PartyRole.DELEGATE); - product.setStatus(RelationshipState.SUSPENDED); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.DELEGATE); - List states = new ArrayList<>(); - states.add(RelationshipState.ACTIVE); - List products = Collections.emptyList(); - List productRoles = Collections.emptyList(); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertTrue(relationshipInfoList.isEmpty()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_noProductsFound() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - product.setRole(PartyRole.DELEGATE); - product.setStatus(RelationshipState.ACTIVE); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.DELEGATE); - List states = new ArrayList<>(); - states.add(RelationshipState.ACTIVE); - List products = new ArrayList<>(); - products.add("productIdNotFound"); - List productRoles = Collections.emptyList(); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertTrue(relationshipInfoList.isEmpty()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_noProductRolesFound() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - product.setRole(PartyRole.DELEGATE); - product.setStatus(RelationshipState.ACTIVE); - product.setProductRole("Operator API"); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.DELEGATE); - List states = new ArrayList<>(); - states.add(RelationshipState.ACTIVE); - List products = new ArrayList<>(); - products.add("productId"); - List productRoles = new ArrayList<>(); - productRoles.add("Role not found"); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertTrue(relationshipInfoList.isEmpty()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_institutionNull_filterProduct_noProductsFound() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product = new OnboardedProduct(); - product.setProductId("productId"); - product.setRole(PartyRole.DELEGATE); - product.setStatus(RelationshipState.ACTIVE); - product.setProductRole("Operator API"); - binding.setProducts(List.of(product)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.DELEGATE); - List states = new ArrayList<>(); - states.add(RelationshipState.ACTIVE); - List products = new ArrayList<>(); - products.add("productId"); - List productRoles = new ArrayList<>(); - productRoles.add("Role not found"); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertTrue(relationshipInfoList.isEmpty()); - } - - /** - * Method under test: {@link InstitutionServiceImpl#retrieveAllProduct(String, UserBinding, Institution, List, List, List, List)} - */ - @Test - void testRetrieveAllProduct_filterProduct_found() { - // Given - List relationshipInfoList; - UserBinding binding = new UserBinding(); - binding.setInstitutionId("42"); - OnboardedProduct product1 = new OnboardedProduct(); - product1.setProductId("productId1"); - product1.setRole(PartyRole.DELEGATE); - product1.setStatus(RelationshipState.ACTIVE); - product1.setProductRole("Operator API"); - OnboardedProduct product2 = new OnboardedProduct(); - product2.setProductId("productId2"); - product2.setRole(PartyRole.OPERATOR); - product2.setStatus(RelationshipState.SUSPENDED); - product2.setProductRole("Operatore API"); - OnboardedProduct product3 = new OnboardedProduct(); - product3.setProductId("productId3"); - product3.setRole(PartyRole.DELEGATE); - product3.setStatus(RelationshipState.ACTIVE); - product3.setProductRole("Operator API"); - OnboardedProduct product4 = new OnboardedProduct(); - product4.setProductId("productId4"); - product4.setRole(PartyRole.DELEGATE); - product4.setStatus(RelationshipState.ACTIVE); - product4.setProductRole("Amministratore"); - binding.setProducts(List.of(product1, product2, product3, product4)); - - Institution institution = new Institution(); - institution.setId("42"); - - List roles = new ArrayList<>(); - roles.add(PartyRole.OPERATOR); - roles.add(PartyRole.DELEGATE); - List states = new ArrayList<>(); - states.add(RelationshipState.ACTIVE); - states.add(RelationshipState.SUSPENDED); - List products = new ArrayList<>(); - products.add("productId2"); - products.add("productId4"); - List productRoles = new ArrayList<>(); - productRoles.add("Operatore API"); - productRoles.add("Amministratore"); - - // When - relationshipInfoList = institutionServiceImpl.retrieveAllProduct("42", binding, institution, roles, states, products, productRoles); - - // Then - assertEquals(2, relationshipInfoList.size()); - assertEquals(binding.getProducts().get(1).getRole(), relationshipInfoList.get(0).getOnboardedProduct().getRole()); - assertEquals(binding.getProducts().get(1).getStatus(), relationshipInfoList.get(0).getOnboardedProduct().getStatus()); - assertEquals(binding.getProducts().get(1).getProductId(), relationshipInfoList.get(0).getOnboardedProduct().getProductId()); - assertEquals(binding.getProducts().get(1).getProductRole(), relationshipInfoList.get(0).getOnboardedProduct().getProductRole()); - assertEquals(binding.getProducts().get(3).getRole(), relationshipInfoList.get(1).getOnboardedProduct().getRole()); - assertEquals(binding.getProducts().get(3).getStatus(), relationshipInfoList.get(1).getOnboardedProduct().getStatus()); - assertEquals(binding.getProducts().get(3).getProductId(), relationshipInfoList.get(1).getOnboardedProduct().getProductId()); - assertEquals(binding.getProducts().get(3).getProductRole(), relationshipInfoList.get(1).getOnboardedProduct().getProductRole()); - } - /** * Method under test: {@link InstitutionServiceImpl#retrieveGeoTaxonomies(String)} */ diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/UserServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/UserServiceImplTest.java index a64799c21..c2d18c43c 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/UserServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/UserServiceImplTest.java @@ -180,18 +180,6 @@ void testFindAllByIds2() { verify(userConnector).findAllByIds(any()); } - @Test - void retrieveUsers() { - ArrayList onboardedUserList = new ArrayList<>(); - when(userConnector.findWithFilter(any(), any(), any(), - any(), any(), any())).thenReturn(onboardedUserList); - List actualRetrieveAdminUsersResult = userServiceImpl.retrieveUsers("42", "42", new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); - assertSame(onboardedUserList, actualRetrieveAdminUsersResult); - assertTrue(actualRetrieveAdminUsersResult.isEmpty()); - verify(userConnector).findWithFilter(any(), any(), any(), - any(), any(), any()); - } - @Test void retrieveBindings_shouldReturnEmpty() { ArrayList onboardedUserList = new ArrayList<>(); diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ExternalController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ExternalController.java index 8d2516ac1..f23126c87 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ExternalController.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ExternalController.java @@ -3,52 +3,28 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import it.pagopa.selfcare.commons.base.security.PartyRole; -import it.pagopa.selfcare.commons.base.security.SelfCareUser; -import it.pagopa.selfcare.mscore.core.ExternalService; -import it.pagopa.selfcare.mscore.model.institution.Onboarding; -import it.pagopa.selfcare.mscore.model.user.ProductManagerInfo; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.constant.RelationshipState; +import it.pagopa.selfcare.mscore.core.ExternalService; import it.pagopa.selfcare.mscore.model.institution.GeographicTaxonomies; import it.pagopa.selfcare.mscore.model.institution.Institution; -import it.pagopa.selfcare.mscore.web.model.institution.CreatePnPgInstitutionRequest; -import it.pagopa.selfcare.mscore.web.model.institution.InstitutionBillingResponse; -import it.pagopa.selfcare.mscore.web.model.institution.InstitutionManagerResponse; -import it.pagopa.selfcare.mscore.web.model.institution.InstitutionPnPgResponse; -import it.pagopa.selfcare.mscore.web.model.institution.InstitutionResponse; -import it.pagopa.selfcare.mscore.web.model.institution.RelationshipResult; +import it.pagopa.selfcare.mscore.model.institution.Onboarding; +import it.pagopa.selfcare.mscore.model.user.ProductManagerInfo; +import it.pagopa.selfcare.mscore.web.model.institution.*; import it.pagopa.selfcare.mscore.web.model.mapper.InstitutionMapperCustom; import it.pagopa.selfcare.mscore.web.model.mapper.InstitutionResourceMapper; -import it.pagopa.selfcare.mscore.web.model.mapper.RelationshipMapper; import it.pagopa.selfcare.mscore.web.model.onboarding.OnboardedProducts; import it.pagopa.selfcare.mscore.web.util.CustomExceptionMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.Authentication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; import java.util.stream.Collectors; -import static it.pagopa.selfcare.mscore.constant.GenericError.CREATE_INSTITUTION_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.GET_INSTITUTION_BY_EXTERNAL_ID_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.GET_INSTITUTION_BY_ID_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.GET_PRODUCTS_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.INSTITUTION_BILLING_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.INSTITUTION_MANAGER_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.RETRIEVE_GEO_TAXONOMIES_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.RETRIEVING_USER_RELATIONSHIP_ERROR; +import static it.pagopa.selfcare.mscore.constant.GenericError.*; @Slf4j @RestController @@ -174,36 +150,6 @@ public ResponseEntity> retrieveInstitutionGeoTaxonomi return ResponseEntity.ok(list); } - /** - * The function returns the relationships related to the institution - * - * @param externalId String - * @param personId String - * @param roles List - * @param states List - * @param products List - * @param productRoles List - * - * @return List - * * Code: 200, Message: successful operation, DataType: List - * * Code: 404, Message: GeographicTaxonomies or Institution not found, DataType: Problem - */ - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "${swagger.mscore.external.institution.relationships}", notes = "${swagger.mscore.external.institution.relationships}") - @GetMapping(value = "/{externalId}/relationships") - public ResponseEntity> getUserInstitutionRelationshipsByExternalId(@ApiParam("${swagger.mscore.institutions.model.externalId}") @PathVariable("externalId") String externalId, - @RequestParam(value = "personId", required = false) String personId, - @RequestParam(value = "roles", required = false) List roles, - @RequestParam(value = "states", required = false) List states, - @RequestParam(value = "products", required = false) List products, - @RequestParam(value = "productRoles", required = false) List productRoles, - Authentication authentication) { - CustomExceptionMessage.setCustomMessage(RETRIEVING_USER_RELATIONSHIP_ERROR); - SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); - List response = externalService.getUserInstitutionRelationships(externalId, selfCareUser.getId(), personId, roles, states, products, productRoles); - return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(response)); - } - /** * The function persist PG institution * diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/InstitutionController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/InstitutionController.java index 06a41da04..3ffc8cd98 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/InstitutionController.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/InstitutionController.java @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; -import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.commons.base.security.SelfCareUser; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.mscore.constant.GenericError; @@ -13,7 +12,6 @@ import it.pagopa.selfcare.mscore.core.InstitutionService; import it.pagopa.selfcare.mscore.core.OnboardingService; import it.pagopa.selfcare.mscore.model.institution.*; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.model.user.UserInfo; import it.pagopa.selfcare.mscore.model.user.UserToOnboard; import it.pagopa.selfcare.mscore.web.model.institution.*; @@ -403,37 +401,6 @@ public ResponseEntity retrieveInstitutionById(@ApiParam("${ return ResponseEntity.ok().body(institutionResourceMapper.toInstitutionResponse(institution)); } - /** - * The function return user institution relationships - * - * @param institutionId String - * @param personId String - * @param roles String[] - * @param states String[] - * @param products String[] - * @param productRoles String[] - * @return List - * * Code: 200, Message: successful operation, DataType: List - * * Code: 404, Message: GeographicTaxonomies or Institution not found, DataType: Problem - */ - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "${swagger.mscore.institution.relationships}", notes = "${swagger.mscore.institution.relationships}") - @GetMapping(value = "/{id}/relationships") - public ResponseEntity> getUserInstitutionRelationships(@ApiParam("${swagger.mscore.institutions.model.institutionId}") - @PathVariable("id") String institutionId, - @RequestParam(value = "personId", required = false) String personId, - @RequestParam(value = "roles", required = false) List roles, - @RequestParam(value = "states", required = false) List states, - @RequestParam(value = "products", required = false) List products, - @RequestParam(value = "productRoles", required = false) List productRoles, - Authentication authentication) { - CustomExceptionMessage.setCustomMessage(GenericError.GET_USER_INSTITUTION_RELATIONSHIP_ERROR); - SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); - Institution institution = institutionService.retrieveInstitutionById(institutionId); - List relationshipInfoList = institutionService.retrieveUserInstitutionRelationships(institution, selfCareUser.getId(), personId, roles, states, products, productRoles); - return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(relationshipInfoList)); - } - /** * Get list of onboarding for a certain productId diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ManagementController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ManagementController.java index 35eea8b99..d7c3f7081 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ManagementController.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/ManagementController.java @@ -3,29 +3,25 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import it.pagopa.selfcare.commons.base.security.PartyRole; -import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.core.InstitutionService; -import it.pagopa.selfcare.mscore.core.UserService; import it.pagopa.selfcare.mscore.model.institution.Institution; -import it.pagopa.selfcare.mscore.model.user.RelationshipInfo; import it.pagopa.selfcare.mscore.web.model.institution.BulkInstitutions; import it.pagopa.selfcare.mscore.web.model.institution.BulkPartiesSeed; -import it.pagopa.selfcare.mscore.web.model.institution.RelationshipsManagement; import it.pagopa.selfcare.mscore.web.model.mapper.InstitutionMapperCustom; -import it.pagopa.selfcare.mscore.web.model.mapper.RelationshipMapper; import it.pagopa.selfcare.mscore.web.util.CustomExceptionMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.util.ArrayList; import java.util.List; import static it.pagopa.selfcare.mscore.constant.GenericError.GET_INSTITUTION_BY_ID_ERROR; -import static it.pagopa.selfcare.mscore.constant.GenericError.GET_RELATIONSHIP_ERROR; @Slf4j @RestController @@ -48,22 +44,4 @@ public ResponseEntity retrieveInstitutionByIds(@ApiParam("${sw List institution = institutionService.retrieveInstitutionByIds(ids); return ResponseEntity.ok().body(InstitutionMapperCustom.toBulkInstitutions(institution, ids)); } - - /** - * @deprecated - */ - @Deprecated(since = "1.0-SNAPSHOT") - @ResponseStatus(HttpStatus.NO_CONTENT) - @ApiOperation(value = "${swagger.mscore.relationships.get}", notes = "${swagger.mscore.relationships.get}") - @GetMapping(value = "/relationships") - public ResponseEntity getInstitutionRelationships(@RequestParam(value = "from", required = false) String userId, - @RequestParam(value = "to", required = false) String institutionId, - @RequestParam(value = "roles", required = false) List roles, - @RequestParam(value = "states", required = false) List states, - @RequestParam(value = "products", required = false) List products, - @RequestParam(value = "productRoles", required = false) List productRoles) { - CustomExceptionMessage.setCustomMessage(GET_RELATIONSHIP_ERROR); - List response = institutionService.retrieveUserRelationships(userId, institutionId, roles, states, products, productRoles); - return ResponseEntity.ok().body(new RelationshipsManagement(RelationshipMapper.toRelationshipResultList(response))); - } } diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/ExternalControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/ExternalControllerTest.java index 1070db855..83edc86f5 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/ExternalControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/ExternalControllerTest.java @@ -1,7 +1,6 @@ package it.pagopa.selfcare.mscore.web.controller; import com.fasterxml.jackson.databind.ObjectMapper; -import it.pagopa.selfcare.commons.base.security.SelfCareUser; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.core.ExternalService; @@ -15,14 +14,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.http.MediaType; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -192,27 +186,6 @@ void testCreatePnPgInstitution() throws Exception { .andExpect(MockMvcResultMatchers.content().string("{}")); } - @Test - void getUserInstitutionRelationshipsByExternalId() throws Exception { - Authentication authentication = Mockito.mock(Authentication.class); - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("id").build()); - - when(externalService.getUserInstitutionRelationships(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders - .get("/external/institutions/{externalId}/relationships", "42") - .principal(authentication); - MockMvcBuilders.standaloneSetup(externalController) - .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } - /** * Method under test: {@link ExternalController#getBillingInstitutionByExternalId(String, String)} */ diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java index 58549862b..a361df1af 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java @@ -261,27 +261,6 @@ void shouldGetOnboardingsInstitutionByProductId() throws Exception { "{\"onboardings\":[{\"productId\":\"example\",\"tokenId\":\"tokenId\",\"status\":\"ACTIVE\",\"contract\":\"contract\",\"pricingPlan\":\"setPricingPlan\",\"billing\":{\"vatNumber\":\"example\",\"recipientCode\":\"example\",\"publicServices\":false},\"createdAt\":null,\"updatedAt\":null,\"closedAt\":null}]}")); } - @Test - void getUserInstitutionRelationships() throws Exception { - Authentication authentication = Mockito.mock(Authentication.class); - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("id").build()); - Institution institution = new Institution(); - institution.setId("id"); - when(institutionService.retrieveInstitutionById(any())).thenReturn(institution); - when(institutionService.retrieveUserInstitutionRelationships(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = get("/institutions/{id}/relationships", "42") - .principal(authentication); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(institutionController) - .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")); - } - @Test void retrieveInstitutionById() throws Exception { SecurityContext securityContext = Mockito.mock(SecurityContext.class);