-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-4386] feat: Added dependency and configuration of product libs (#…
…245)
- Loading branch information
Showing
44 changed files
with
337 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
connector-api/src/main/java/it/pagopa/selfcare/external_api/api/ProductsConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...st/src/main/java/it/pagopa/selfcare/external_api/connector/rest/ProductConnectorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package it.pagopa.selfcare.external_api.connector.rest; | ||
|
||
import it.pagopa.selfcare.external_api.api.ProductsConnector; | ||
import it.pagopa.selfcare.onboarding.common.InstitutionType; | ||
import it.pagopa.selfcare.product.entity.Product; | ||
import it.pagopa.selfcare.product.service.ProductService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Slf4j | ||
public class ProductConnectorImpl implements ProductsConnector { | ||
|
||
private final ProductService productService; | ||
|
||
public ProductConnectorImpl(ProductService productService) { | ||
this.productService = productService; | ||
} | ||
|
||
@Override | ||
public List<Product> getProducts() { | ||
return productService.getProducts(true, true); | ||
} | ||
|
||
@Override | ||
public Product getProduct(String productId) { | ||
return productService.getProduct(productId); | ||
} | ||
|
||
@Override | ||
public Product getProduct(String id, InstitutionType institutionType) { | ||
Product product = productService.getProduct(id); | ||
if (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()); | ||
} | ||
return product; | ||
} | ||
|
||
|
||
} |
31 changes: 0 additions & 31 deletions
31
...c/main/java/it/pagopa/selfcare/external_api/connector/rest/client/ProductsRestClient.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...main/java/it/pagopa/selfcare/external_api/connector/rest/config/ProductServiceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package it.pagopa.selfcare.external_api.connector.rest.config; | ||
|
||
import it.pagopa.selfcare.azurestorage.AzureBlobClient; | ||
import it.pagopa.selfcare.azurestorage.AzureBlobClientDefault; | ||
import it.pagopa.selfcare.product.service.ProductService; | ||
import it.pagopa.selfcare.product.service.ProductServiceCacheable; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
@Configuration | ||
@PropertySource("classpath:config/products-sdk.properties") | ||
public class ProductServiceConfig { | ||
@Value("${external-api.blob-storage.container-product}") | ||
private String containerProduct; | ||
@Value("${external-api.blob-storage.filepath-product}") | ||
private String filepathProduct; | ||
@Value("${external-api.blob-storage.connection-string-product}") | ||
private String connectionStringProduct; | ||
|
||
@Bean | ||
public ProductService productService(){ | ||
AzureBlobClient azureBlobClient = new AzureBlobClientDefault(connectionStringProduct, containerProduct); | ||
try{ | ||
return new ProductServiceCacheable(azureBlobClient, filepathProduct); | ||
} catch(IllegalArgumentException e){ | ||
throw new IllegalArgumentException("Found an issue when trying to serialize product json string!!"); | ||
} | ||
} | ||
} | ||
|
15 changes: 0 additions & 15 deletions
15
.../java/it/pagopa/selfcare/external_api/connector/rest/config/ProductsRestClientConfig.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
connector/rest/src/main/resources/config/products-rest-client.properties
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
connector/rest/src/main/resources/config/products-sdk.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
external-api.blob-storage.container-product=${PRODUCT_STORAGE_CONTAINER:selc-d-product} | ||
external-api.blob-storage.filepath-product = products.json | ||
external-api.blob-storage.connection-string-product = ${BLOB_STORAGE_PRODUCT_CONNECTION_STRING:UseDevelopmentStorage=true;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...rc/test/java/it/pagopa/selfcare/external_api/connector/rest/ProductConnectorImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package it.pagopa.selfcare.external_api.connector.rest; | ||
|
||
import it.pagopa.selfcare.onboarding.common.InstitutionType; | ||
import it.pagopa.selfcare.product.entity.ContractStorage; | ||
import it.pagopa.selfcare.product.entity.Product; | ||
import it.pagopa.selfcare.product.entity.ProductStatus; | ||
import it.pagopa.selfcare.product.service.ProductService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ProductConnectorImplTest { | ||
|
||
@InjectMocks | ||
private ProductConnectorImpl productConnector; | ||
|
||
@Mock | ||
private ProductService productService; | ||
|
||
|
||
@Test | ||
void getProductById(){ | ||
final Product product = dummyProduct(); | ||
final String productId = "productId"; | ||
when(productService.getProduct(anyString())).thenReturn(product); | ||
|
||
Product result = productConnector.getProduct(productId); | ||
|
||
assertEquals(product, result); | ||
|
||
verify(productService, times(1)).getProduct(productId); | ||
} | ||
|
||
@Test | ||
void getProducts(){ | ||
final Product product = dummyProduct(); | ||
|
||
when(productService.getProducts(anyBoolean(), anyBoolean())).thenReturn(List.of(product)); | ||
|
||
List<Product> products = productConnector.getProducts(); | ||
|
||
assertFalse(products.isEmpty()); | ||
assertEquals(product, products.get(0)); | ||
|
||
verify(productService, times(1)).getProducts(true, true); | ||
} | ||
|
||
@Test | ||
void getProductByInstitutionType() { | ||
final Product product = dummyProduct(); | ||
ContractStorage contractStorage = new ContractStorage(); | ||
contractStorage.setContractTemplateUpdatedAt(Instant.now()); | ||
contractStorage.setContractTemplatePath("contractTemplatePath"); | ||
contractStorage.setContractTemplateVersion("contractTemplateVersion"); | ||
final Map<InstitutionType, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA,contractStorage); | ||
product.setInstitutionContractMappings(contractStorageMap); | ||
final String productId = "productId"; | ||
when(productService.getProduct(anyString())).thenReturn(product); | ||
|
||
Product result = productConnector.getProduct(productId, InstitutionType.PA); | ||
|
||
assertEquals(product, result); | ||
|
||
verify(productService, times(1)).getProduct(productId); | ||
|
||
} | ||
|
||
@Test | ||
void getProduct_institutionTypeNotPresent(){ | ||
final Product product = dummyProduct(); | ||
ContractStorage contractStorage = new ContractStorage(); | ||
contractStorage.setContractTemplateUpdatedAt(Instant.now()); | ||
contractStorage.setContractTemplatePath("contractTemplatePath"); | ||
contractStorage.setContractTemplateVersion("contractTemplateVersion"); | ||
final Map<InstitutionType, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA,contractStorage); | ||
product.setInstitutionContractMappings(contractStorageMap); | ||
final String productId = "productId"; | ||
when(productService.getProduct(anyString())).thenReturn(product); | ||
|
||
Product result = productConnector.getProduct(productId, InstitutionType.SA); | ||
|
||
assertEquals(product, result); | ||
|
||
verify(productService, times(1)).getProduct(productId); | ||
|
||
} | ||
|
||
|
||
|
||
private Product dummyProduct(){ | ||
Product product = new Product(); | ||
product.setContractTemplatePath("Contract Template Path"); | ||
product.setContractTemplateVersion("1.0.2"); | ||
product.setId("42"); | ||
product.setParentId("42"); | ||
product.setRoleMappings(null); | ||
product.setStatus(ProductStatus.ACTIVE); | ||
product.setTitle("Dr"); | ||
return product; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.