Skip to content

Commit

Permalink
Update onboarding product lib (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu authored Nov 8, 2024
1 parent 862b8d3 commit 8784c6a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.2.0</version>
<version>0.4.1</version>
</dependency>
</dependencies>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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<String, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA.name(),contractStorage);
ContractTemplate contractTemplate = new ContractTemplate();
contractTemplate.setContractTemplatePath("contractTemplatePath");
contractTemplate.setContractTemplateVersion("contractTemplateVersion");
final Map<String, ContractTemplate> contractStorageMap = Map.of(InstitutionType.PA.name(),contractTemplate);
product.setInstitutionContractMappings(contractStorageMap);
final String productId = "productId";
when(productService.getProduct(anyString())).thenReturn(product);
Expand All @@ -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<String, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA.name(),contractStorage);
ContractTemplate contractTemplate = new ContractTemplate();
contractTemplate.setContractTemplatePath("contractTemplatePath");
contractTemplate.setContractTemplateVersion("contractTemplateVersion");
final Map<String, ContractTemplate> contractStorageMap = Map.of(InstitutionType.PA.name(),contractTemplate);
product.setInstitutionContractMappings(contractStorageMap);
final String productId = "productId";
when(productService.getProduct(anyString())).thenReturn(product);
Expand Down Expand Up @@ -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<String, ContractTemplate> institutionContractMapping = new HashMap<>();
institutionContractMapping.put(Product.CONTRACT_TYPE_DEFAULT, contractTemplate);
product.setInstitutionContractMappings(institutionContractMapping);

product.setId("42");
product.setParentId("42");
product.setRoleMappings(null);
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>0.2.0</version>
<version>0.2.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>0.2.0</version>
<version>0.2.2</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<ProductResource> getProductsAdmin() {
log.trace("getProductsAdmin start");
final List<Product> products = productService.getProducts(true);
List<ProductResource> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -101,7 +104,13 @@ void getProducts() throws Exception {
void getProductsAdmin() throws Exception {
//given
Product product = new Product();
product.setUserContractTemplatePath("test");
Map<String, ContractTemplate> 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
Expand Down

0 comments on commit 8784c6a

Please sign in to comment.