diff --git a/connector-api/pom.xml b/connector-api/pom.xml index 0ba184b5..3ff87fce 100644 --- a/connector-api/pom.xml +++ b/connector-api/pom.xml @@ -14,7 +14,7 @@ it.pagopa.selfcare onboarding-sdk-product - 0.2.0 + 0.4.1 diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImpl.java index b2feec40..2cd3eb43 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImpl.java @@ -28,11 +28,7 @@ public Product getProduct(String id, InstitutionType institutionType) { } Assert.hasText(id, "A productId is required"); Product product = productService.getProduct(id); - if (Objects.nonNull(product.getInstitutionContractMappings()) && product.getInstitutionContractMappings().containsKey(institutionType)) { - product.setContractTemplatePath(product.getInstitutionContractMappings().get(institutionType).getContractTemplatePath()); - product.setContractTemplateVersion(product.getInstitutionContractMappings().get(institutionType).getContractTemplateVersion()); - product.setContractTemplateUpdatedAt(product.getInstitutionContractMappings().get(institutionType).getContractTemplateUpdatedAt()); - } + log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProduct result = {}", product); return product; } diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImplTest.java index ed8a124a..9f1838dd 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/ProductsConnectorImplTest.java @@ -1,7 +1,7 @@ package it.pagopa.selfcare.onboarding.connector; import it.pagopa.selfcare.onboarding.common.InstitutionType; -import it.pagopa.selfcare.product.entity.ContractStorage; +import it.pagopa.selfcare.product.entity.ContractTemplate; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.entity.ProductStatus; import it.pagopa.selfcare.product.service.ProductService; @@ -12,6 +12,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import java.time.Instant; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,11 +32,10 @@ class ProductsConnectorImplTest { @Test void getProductByInstitutionType() { final Product product = dummyProduct(); - ContractStorage contractStorage = new ContractStorage(); - contractStorage.setContractTemplateUpdatedAt(Instant.now()); - contractStorage.setContractTemplatePath("contractTemplatePath"); - contractStorage.setContractTemplateVersion("contractTemplateVersion"); - final Map contractStorageMap = Map.of(InstitutionType.PA.name(),contractStorage); + ContractTemplate contractTemplate = new ContractTemplate(); + contractTemplate.setContractTemplatePath("contractTemplatePath"); + contractTemplate.setContractTemplateVersion("contractTemplateVersion"); + final Map contractStorageMap = Map.of(InstitutionType.PA.name(),contractTemplate); product.setInstitutionContractMappings(contractStorageMap); final String productId = "productId"; when(productService.getProduct(anyString())).thenReturn(product); @@ -51,11 +51,10 @@ void getProductByInstitutionType() { @Test void getProduct_institutionTypeNotPresent(){ final Product product = dummyProduct(); - ContractStorage contractStorage = new ContractStorage(); - contractStorage.setContractTemplateUpdatedAt(Instant.now()); - contractStorage.setContractTemplatePath("contractTemplatePath"); - contractStorage.setContractTemplateVersion("contractTemplateVersion"); - final Map contractStorageMap = Map.of(InstitutionType.PA.name(),contractStorage); + ContractTemplate contractTemplate = new ContractTemplate(); + contractTemplate.setContractTemplatePath("contractTemplatePath"); + contractTemplate.setContractTemplateVersion("contractTemplateVersion"); + final Map contractStorageMap = Map.of(InstitutionType.PA.name(),contractTemplate); product.setInstitutionContractMappings(contractStorageMap); final String productId = "productId"; when(productService.getProduct(anyString())).thenReturn(product); @@ -87,8 +86,13 @@ void getProducts() { private Product dummyProduct(){ Product product = new Product(); - product.setContractTemplatePath("Contract Template Path"); - product.setContractTemplateVersion("1.0.2"); + ContractTemplate contractTemplate = new ContractTemplate(); + contractTemplate.setContractTemplatePath("Contract Template Path"); + contractTemplate.setContractTemplateVersion("1.0.2"); + Map institutionContractMapping = new HashMap<>(); + institutionContractMapping.put(Product.CONTRACT_TYPE_DEFAULT, contractTemplate); + product.setInstitutionContractMappings(institutionContractMapping); + product.setId("42"); product.setParentId("42"); product.setRoleMappings(null); diff --git a/core/pom.xml b/core/pom.xml index 6227d855..f22b2af9 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -19,7 +19,7 @@ it.pagopa.selfcare onboarding-sdk-common - 0.2.0 + 0.2.2 compile diff --git a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java index d3ca2332..5e1a6a09 100644 --- a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java @@ -198,8 +198,8 @@ public void onboardingProduct(OnboardingData onboardingData) { product.getId())); } - onboardingData.setContractPath(product.getContractTemplatePath()); - onboardingData.setContractVersion(product.getContractTemplateVersion()); + onboardingData.setContractPath(product.getInstitutionContractTemplate(onboardingData.getInstitutionType().name()).getContractTemplatePath()); + onboardingData.setContractVersion(product.getInstitutionContractTemplate(onboardingData.getInstitutionType().name()).getContractTemplateVersion()); checkIfProductIsActiveAndSetUserProductRole(product, onboardingData); onboardingData.setProductName(product.getTitle()); @@ -286,10 +286,10 @@ private void checkIfProductIsActiveAndSetUserProductRole(Product product, Onboar product.getId(), baseProduct.getId())); } - roleMappings = baseProduct.getRoleMappings(); + roleMappings = baseProduct.getRoleMappings(onboardingData.getProductId()); } else { validateOnboarding(onboardingData.getTaxCode(), product.getId()); - roleMappings = product.getRoleMappings(); + roleMappings = product.getRoleMappings(onboardingData.getProductId()); } validateProductRole(onboardingData.getUsers(), roleMappings); diff --git a/web/pom.xml b/web/pom.xml index 34e1e774..0a5124b5 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -33,7 +33,7 @@ it.pagopa.selfcare onboarding-sdk-common - 0.2.0 + 0.2.2 diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/ProductController.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/ProductController.java index ae703bc4..2cf92062 100644 --- a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/ProductController.java +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/ProductController.java @@ -69,7 +69,7 @@ public List getProductsAdmin() { log.trace("getProductsAdmin start"); final List products = productService.getProducts(true); List resources = products.stream() - .filter(product -> Objects.nonNull(product.getUserContractTemplatePath())) + .filter(product -> Objects.nonNull(product.getUserContractTemplate(Product.CONTRACT_TYPE_DEFAULT).getContractTemplatePath())) .map(ProductMapper::toResource) .toList(); log.debug("getProductsAdmin result = {}", resources); diff --git a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/ProductControllerTest.java b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/ProductControllerTest.java index 7ca7e883..a4b113dd 100644 --- a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/ProductControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/ProductControllerTest.java @@ -5,6 +5,7 @@ import it.pagopa.selfcare.onboarding.core.ProductService; import it.pagopa.selfcare.onboarding.web.config.WebTestConfig; import it.pagopa.selfcare.onboarding.web.model.ProductResource; +import it.pagopa.selfcare.product.entity.ContractTemplate; import it.pagopa.selfcare.product.entity.Product; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -20,7 +21,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import static org.mockito.ArgumentMatchers.any; @@ -101,7 +104,13 @@ void getProducts() throws Exception { void getProductsAdmin() throws Exception { //given Product product = new Product(); - product.setUserContractTemplatePath("test"); + Map userContractMappings = new HashMap<>(); + ContractTemplate userContract = new ContractTemplate(); + userContract.setContractTemplatePath("test"); + userContract.setContractTemplateVersion("version"); + userContractMappings.put(Product.CONTRACT_TYPE_DEFAULT, userContract); + product.setUserContractMappings(userContractMappings); + Mockito.when(productServiceMock.getProducts(true)) .thenReturn(List.of(product)); //when