Skip to content

Commit e410f1d

Browse files
authored
[SELC-4386] feat: Added dependency and configuration of product libs (#245)
1 parent bec02ed commit e410f1d

File tree

44 files changed

+337
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+337
-366
lines changed

.github/workflows/release_open_api.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
swagger_conflict_update:
1313
runs-on: ubuntu-20.04
1414
permissions: write-all
15+
secrets: inherit
1516
name: Swagger Detect Conflict and Update
1617
steps:
1718
- id: swagger-conflict-update

Dockerfile.new

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@ FROM maven:3-eclipse-temurin-17@sha256:0d328fa6843bb26b60cf44d69833f241ffe96218f
22

33
COPY . .
44

5-
RUN mvn clean package -DskipTests=true
5+
RUN echo "<settings>\n" \
6+
"<servers>\n" \
7+
"<server>\n" \
8+
"<id>\${repositoryOnboarding}</id>\n" \
9+
"<username>\${repoLogin}</username>\n" \
10+
"<password>\${repoPwd}</password>\n" \
11+
"</server>\n" \
12+
"</servers>\n" \
13+
"</settings>\n" > settings.xml
14+
15+
ARG REPO_ONBOARDING
16+
ARG REPO_USERNAME
17+
ARG REPO_PASSWORD
18+
19+
RUN mvn --global-settings settings.xml -DrepositoryOnboarding=${REPO_ONBOARDING} -DrepoLogin=${REPO_USERNAME} -DrepoPwd=${REPO_PASSWORD} clean package -DskipTests=true
620

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

app/src/main/resources/swagger/api-docs.json

+4-12
Original file line numberDiff line numberDiff line change
@@ -2275,36 +2275,28 @@
22752275
},
22762276
"ProductRole" : {
22772277
"title" : "ProductRole",
2278-
"required" : [ "code", "description", "label" ],
22792278
"type" : "object",
22802279
"properties" : {
22812280
"code" : {
2282-
"type" : "string",
2283-
"description" : "Product role internal code"
2281+
"type" : "string"
22842282
},
22852283
"description" : {
2286-
"type" : "string",
2287-
"description" : "Product role description"
2284+
"type" : "string"
22882285
},
22892286
"label" : {
2290-
"type" : "string",
2291-
"description" : "Product role label"
2287+
"type" : "string"
22922288
}
22932289
}
22942290
},
22952291
"ProductRoleInfo" : {
22962292
"title" : "ProductRoleInfo",
2297-
"required" : [ "multiroleAllowed", "roles" ],
22982293
"type" : "object",
22992294
"properties" : {
23002295
"multiroleAllowed" : {
2301-
"type" : "boolean",
2302-
"description" : "Flag indicating if a User can have more than one product role",
2303-
"example" : false
2296+
"type" : "boolean"
23042297
},
23052298
"roles" : {
23062299
"type" : "array",
2307-
"description" : "Available product roles",
23082300
"items" : {
23092301
"$ref" : "#/components/schemas/ProductRole"
23102302
}

connector-api/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
<groupId>org.springframework.data</groupId>
1919
<artifactId>spring-data-commons</artifactId>
2020
</dependency>
21+
<dependency>
22+
<groupId>it.pagopa.selfcare</groupId>
23+
<artifactId>onboarding-sdk-product</artifactId>
24+
<version>0.1.10</version>
25+
</dependency>
2126
</dependencies>
27+
28+
<repositories>
29+
<repository>
30+
<id>selfcare-onboarding</id>
31+
<name>Selfcare Onboarding SDK</name>
32+
<url>https://maven.pkg.github.com/pagopa/selfcare-onboarding</url>
33+
</repository>
34+
</repositories>
2235
<!--<build>
2336
<plugins>
2437
<plugin>

connector-api/src/main/java/it/pagopa/selfcare/external_api/api/ProductsConnector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package it.pagopa.selfcare.external_api.api;
22

3-
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
4-
import it.pagopa.selfcare.external_api.model.product.Product;
3+
import it.pagopa.selfcare.onboarding.common.InstitutionType;
4+
import it.pagopa.selfcare.product.entity.Product;
55

66
import java.util.List;
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package it.pagopa.selfcare.external_api.connector.rest;
2+
3+
import it.pagopa.selfcare.external_api.api.ProductsConnector;
4+
import it.pagopa.selfcare.onboarding.common.InstitutionType;
5+
import it.pagopa.selfcare.product.entity.Product;
6+
import it.pagopa.selfcare.product.service.ProductService;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.List;
11+
12+
@Service
13+
@Slf4j
14+
public class ProductConnectorImpl implements ProductsConnector {
15+
16+
private final ProductService productService;
17+
18+
public ProductConnectorImpl(ProductService productService) {
19+
this.productService = productService;
20+
}
21+
22+
@Override
23+
public List<Product> getProducts() {
24+
return productService.getProducts(true, true);
25+
}
26+
27+
@Override
28+
public Product getProduct(String productId) {
29+
return productService.getProduct(productId);
30+
}
31+
32+
@Override
33+
public Product getProduct(String id, InstitutionType institutionType) {
34+
Product product = productService.getProduct(id);
35+
if (product.getInstitutionContractMappings().containsKey(institutionType)) {
36+
product.setContractTemplatePath(product.getInstitutionContractMappings().get(institutionType).getContractTemplatePath());
37+
product.setContractTemplateVersion(product.getInstitutionContractMappings().get(institutionType).getContractTemplateVersion());
38+
product.setContractTemplateUpdatedAt(product.getInstitutionContractMappings().get(institutionType).getContractTemplateUpdatedAt());
39+
}
40+
return product;
41+
}
42+
43+
44+
}

connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/client/ProductsRestClient.java

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package it.pagopa.selfcare.external_api.connector.rest.config;
2+
3+
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
4+
import it.pagopa.selfcare.azurestorage.AzureBlobClientDefault;
5+
import it.pagopa.selfcare.product.service.ProductService;
6+
import it.pagopa.selfcare.product.service.ProductServiceCacheable;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
11+
12+
@Configuration
13+
@PropertySource("classpath:config/products-sdk.properties")
14+
public class ProductServiceConfig {
15+
@Value("${external-api.blob-storage.container-product}")
16+
private String containerProduct;
17+
@Value("${external-api.blob-storage.filepath-product}")
18+
private String filepathProduct;
19+
@Value("${external-api.blob-storage.connection-string-product}")
20+
private String connectionStringProduct;
21+
22+
@Bean
23+
public ProductService productService(){
24+
AzureBlobClient azureBlobClient = new AzureBlobClientDefault(connectionStringProduct, containerProduct);
25+
try{
26+
return new ProductServiceCacheable(azureBlobClient, filepathProduct);
27+
} catch(IllegalArgumentException e){
28+
throw new IllegalArgumentException("Found an issue when trying to serialize product json string!!");
29+
}
30+
}
31+
}
32+

connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/config/ProductsRestClientConfig.java

-15
This file was deleted.

connector/rest/src/main/resources/config/products-rest-client.properties

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
external-api.blob-storage.container-product=${PRODUCT_STORAGE_CONTAINER:selc-d-product}
2+
external-api.blob-storage.filepath-product = products.json
3+
external-api.blob-storage.connection-string-product = ${BLOB_STORAGE_PRODUCT_CONNECTION_STRING:UseDevelopmentStorage=true;}

connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImplTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import it.pagopa.selfcare.external_api.model.pnpg.CreatePnPgInstitution;
2222
import it.pagopa.selfcare.user.generated.openapi.v1.dto.UserDataResponse;
2323
import org.junit.jupiter.api.Assertions;
24-
import org.junit.jupiter.api.BeforeEach;
2524
import org.junit.jupiter.api.Test;
2625
import org.junit.jupiter.api.extension.ExtendWith;
2726
import org.mockito.ArgumentCaptor;

connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsPartyRegistryProxyConnectorImplTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import it.pagopa.selfcare.external_api.connector.rest.client.MsPartyRegistryProxyRestClient;
55
import it.pagopa.selfcare.external_api.connector.rest.config.BaseConnectorTest;
66
import it.pagopa.selfcare.external_api.model.institutions.InstitutionResource;
7-
import org.junit.jupiter.api.BeforeEach;
87
import org.junit.jupiter.api.Test;
98
import org.junit.jupiter.api.extension.ExtendWith;
109
import org.mockito.InjectMocks;

connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/OnboardingMsConnectorImplTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import it.pagopa.selfcare.external_api.model.token.TokenOnboardedUsers;
1717
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.*;
1818
import org.junit.jupiter.api.Assertions;
19-
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.Test;
2120
import org.junit.jupiter.api.extension.ExtendWith;
2221
import org.mockito.ArgumentCaptor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package it.pagopa.selfcare.external_api.connector.rest;
2+
3+
import it.pagopa.selfcare.onboarding.common.InstitutionType;
4+
import it.pagopa.selfcare.product.entity.ContractStorage;
5+
import it.pagopa.selfcare.product.entity.Product;
6+
import it.pagopa.selfcare.product.entity.ProductStatus;
7+
import it.pagopa.selfcare.product.service.ProductService;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.mockito.InjectMocks;
11+
import org.mockito.Mock;
12+
import org.mockito.junit.jupiter.MockitoExtension;
13+
14+
import java.time.Instant;
15+
import java.util.List;
16+
import java.util.Map;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.mockito.ArgumentMatchers.anyString;
21+
import static org.mockito.Mockito.*;
22+
23+
@ExtendWith(MockitoExtension.class)
24+
class ProductConnectorImplTest {
25+
26+
@InjectMocks
27+
private ProductConnectorImpl productConnector;
28+
29+
@Mock
30+
private ProductService productService;
31+
32+
33+
@Test
34+
void getProductById(){
35+
final Product product = dummyProduct();
36+
final String productId = "productId";
37+
when(productService.getProduct(anyString())).thenReturn(product);
38+
39+
Product result = productConnector.getProduct(productId);
40+
41+
assertEquals(product, result);
42+
43+
verify(productService, times(1)).getProduct(productId);
44+
}
45+
46+
@Test
47+
void getProducts(){
48+
final Product product = dummyProduct();
49+
50+
when(productService.getProducts(anyBoolean(), anyBoolean())).thenReturn(List.of(product));
51+
52+
List<Product> products = productConnector.getProducts();
53+
54+
assertFalse(products.isEmpty());
55+
assertEquals(product, products.get(0));
56+
57+
verify(productService, times(1)).getProducts(true, true);
58+
}
59+
60+
@Test
61+
void getProductByInstitutionType() {
62+
final Product product = dummyProduct();
63+
ContractStorage contractStorage = new ContractStorage();
64+
contractStorage.setContractTemplateUpdatedAt(Instant.now());
65+
contractStorage.setContractTemplatePath("contractTemplatePath");
66+
contractStorage.setContractTemplateVersion("contractTemplateVersion");
67+
final Map<InstitutionType, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA,contractStorage);
68+
product.setInstitutionContractMappings(contractStorageMap);
69+
final String productId = "productId";
70+
when(productService.getProduct(anyString())).thenReturn(product);
71+
72+
Product result = productConnector.getProduct(productId, InstitutionType.PA);
73+
74+
assertEquals(product, result);
75+
76+
verify(productService, times(1)).getProduct(productId);
77+
78+
}
79+
80+
@Test
81+
void getProduct_institutionTypeNotPresent(){
82+
final Product product = dummyProduct();
83+
ContractStorage contractStorage = new ContractStorage();
84+
contractStorage.setContractTemplateUpdatedAt(Instant.now());
85+
contractStorage.setContractTemplatePath("contractTemplatePath");
86+
contractStorage.setContractTemplateVersion("contractTemplateVersion");
87+
final Map<InstitutionType, ContractStorage> contractStorageMap = Map.of(InstitutionType.PA,contractStorage);
88+
product.setInstitutionContractMappings(contractStorageMap);
89+
final String productId = "productId";
90+
when(productService.getProduct(anyString())).thenReturn(product);
91+
92+
Product result = productConnector.getProduct(productId, InstitutionType.SA);
93+
94+
assertEquals(product, result);
95+
96+
verify(productService, times(1)).getProduct(productId);
97+
98+
}
99+
100+
101+
102+
private Product dummyProduct(){
103+
Product product = new Product();
104+
product.setContractTemplatePath("Contract Template Path");
105+
product.setContractTemplateVersion("1.0.2");
106+
product.setId("42");
107+
product.setParentId("42");
108+
product.setRoleMappings(null);
109+
product.setStatus(ProductStatus.ACTIVE);
110+
product.setTitle("Dr");
111+
return product;
112+
}
113+
}

connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/UserMsConnectorImplTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import it.pagopa.selfcare.external_api.model.user.UserInstitution;
1111
import it.pagopa.selfcare.external_api.model.user.UserToOnboard;
1212
import it.pagopa.selfcare.user.generated.openapi.v1.dto.*;
13-
import org.junit.jupiter.api.BeforeEach;
1413
import org.junit.jupiter.api.Test;
1514
import org.junit.jupiter.api.extension.ExtendWith;
1615
import org.mockito.InjectMocks;

connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/UserRegistryConnectorImplTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import it.pagopa.selfcare.external_api.connector.rest.config.BaseConnectorTest;
77
import it.pagopa.selfcare.external_api.connector.rest.model.user_registry.EmbeddedExternalId;
88
import it.pagopa.selfcare.external_api.model.user.*;
9-
import org.junit.jupiter.api.BeforeEach;
109
import org.junit.jupiter.api.Test;
1110
import org.junit.jupiter.api.extension.ExtendWith;
1211
import org.junit.jupiter.api.function.Executable;

0 commit comments

Comments
 (0)