Skip to content

Commit

Permalink
[SELC-4386] feat: Added dependency and configuration of product libs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSi96 authored May 24, 2024
1 parent bec02ed commit e410f1d
Show file tree
Hide file tree
Showing 44 changed files with 337 additions and 366 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release_open_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
swagger_conflict_update:
runs-on: ubuntu-20.04
permissions: write-all
secrets: inherit
name: Swagger Detect Conflict and Update
steps:
- id: swagger-conflict-update
Expand Down
16 changes: 15 additions & 1 deletion Dockerfile.new
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@ FROM maven:3-eclipse-temurin-17@sha256:0d328fa6843bb26b60cf44d69833f241ffe96218f

COPY . .

RUN mvn clean package -DskipTests=true
RUN echo "<settings>\n" \
"<servers>\n" \
"<server>\n" \
"<id>\${repositoryOnboarding}</id>\n" \
"<username>\${repoLogin}</username>\n" \
"<password>\${repoPwd}</password>\n" \
"</server>\n" \
"</servers>\n" \
"</settings>\n" > settings.xml

ARG REPO_ONBOARDING
ARG REPO_USERNAME
ARG REPO_PASSWORD

RUN mvn --global-settings settings.xml -DrepositoryOnboarding=${REPO_ONBOARDING} -DrepoLogin=${REPO_USERNAME} -DrepoPwd=${REPO_PASSWORD} clean package -DskipTests=true

FROM openjdk:17-jdk@sha256:528707081fdb9562eb819128a9f85ae7fe000e2fbaeaf9f87662e7b3f38cb7d8 AS runtime

Expand Down
16 changes: 4 additions & 12 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2275,36 +2275,28 @@
},
"ProductRole" : {
"title" : "ProductRole",
"required" : [ "code", "description", "label" ],
"type" : "object",
"properties" : {
"code" : {
"type" : "string",
"description" : "Product role internal code"
"type" : "string"
},
"description" : {
"type" : "string",
"description" : "Product role description"
"type" : "string"
},
"label" : {
"type" : "string",
"description" : "Product role label"
"type" : "string"
}
}
},
"ProductRoleInfo" : {
"title" : "ProductRoleInfo",
"required" : [ "multiroleAllowed", "roles" ],
"type" : "object",
"properties" : {
"multiroleAllowed" : {
"type" : "boolean",
"description" : "Flag indicating if a User can have more than one product role",
"example" : false
"type" : "boolean"
},
"roles" : {
"type" : "array",
"description" : "Available product roles",
"items" : {
"$ref" : "#/components/schemas/ProductRole"
}
Expand Down
13 changes: 13 additions & 0 deletions connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.1.10</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>selfcare-onboarding</id>
<name>Selfcare Onboarding SDK</name>
<url>https://maven.pkg.github.com/pagopa/selfcare-onboarding</url>
</repository>
</repositories>
<!--<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.selfcare.external_api.api;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.external_api.model.product.Product;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.product.entity.Product;

import java.util.List;

Expand Down
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;
}


}

This file was deleted.

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!!");
}
}
}

This file was deleted.

This file was deleted.

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;}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import it.pagopa.selfcare.external_api.model.pnpg.CreatePnPgInstitution;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.UserDataResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.pagopa.selfcare.external_api.connector.rest.client.MsPartyRegistryProxyRestClient;
import it.pagopa.selfcare.external_api.connector.rest.config.BaseConnectorTest;
import it.pagopa.selfcare.external_api.model.institutions.InstitutionResource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import it.pagopa.selfcare.external_api.model.token.TokenOnboardedUsers;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import it.pagopa.selfcare.external_api.model.user.UserInstitution;
import it.pagopa.selfcare.external_api.model.user.UserToOnboard;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import it.pagopa.selfcare.external_api.connector.rest.config.BaseConnectorTest;
import it.pagopa.selfcare.external_api.connector.rest.model.user_registry.EmbeddedExternalId;
import it.pagopa.selfcare.external_api.model.user.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
Expand Down
Loading

0 comments on commit e410f1d

Please sign in to comment.