Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: replace business logic for retrieving product with onboarding-sdk-product #36

Merged
merged 21 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .container_apps/onboarding-ms/env/dev/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ app_settings = [
{
name = "ONBOARDING_ALLOWED_INSTITUTIONS_PRODUCTS"
value = "{'prod-interop': ['*'], 'prod-pn': ['*'], 'prod-io': ['*'], 'prod-io-premium': ['*'], 'prod-pagopa': ['*'], 'prod-fd': ['*'], 'prod-fd-garantito': ['*']}"
},
{
name = "STORAGE_CONTAINER_PRODUCT"
value = "product"
}
]

Expand All @@ -39,6 +43,7 @@ key_vault = {
"jwt-public-key",
"mongodb-connection-string",
"user-registry-api-key",
"onboarding-functions-api-key"
"onboarding-functions-api-key",
"blob-storage-product-connection-string"
]
}
52 changes: 0 additions & 52 deletions .github/workflows/code_review.yml

This file was deleted.

55 changes: 44 additions & 11 deletions .github/workflows/code_review_functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,51 @@ on:
- reopened
paths:
- 'onboarding-functions/**'

workflow_dispatch:

permissions:
id-token: write
contents: read
deployments: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

code-review:
name: Code review onboarding-ms
# The type of runner that the job will run on
uses: pagopa/selfcare-onboarding/.github/workflows/code_review.yml@develop
with:
module: onboarding-functions
runs-on: ubuntu-latest
permissions:
packages: read
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar-project.properties/cache
key: ${{ runner.os }}-sonar-project.properties
restore-keys: ${{ runner.os }}-sonar-project.properties

- name: Build and analyze on Pull Requests
shell: bash
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-Dsonar.organization=pagopa
-Dsonar.projectKey=pagopa_selfcare-onboarding
-Dsonar.coverage.jacoco.xmlReportPaths=./target/jacoco-report/jacoco.xml
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.coverage.exclusions='**/exception/**, **/response/**, **/request/**, **/entity/**, **/utils/**, **/*Constant*, **/*Config.java, **/src/test/**'
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}
--file onboarding-functions/pom.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
47 changes: 35 additions & 12 deletions .github/workflows/code_review_ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,42 @@ on:
- synchronize
- reopened
paths:
- 'onboarding-ms/**'
- 'apps/onboarding-ms/**'

workflow_dispatch:

permissions:
id-token: write
contents: read
deployments: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

code-review:
name: Code review onboarding-ms
# The type of runner that the job will run on
uses: pagopa/selfcare-onboarding/.github/workflows/code_review.yml@develop
with:
module: onboarding-ms
runs-on: ubuntu-latest
permissions:
packages: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
apps/onboarding-ms
libs/

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'

- name: Build and analyze on Pull Requests
shell: bash
run: mvn --projects :onboarding-ms --also-make verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-Dsonar.organization=pagopa
-Dsonar.projectKey=pagopa_selfcare-onboarding
-Dsonar.coverage.jacoco.xmlReportPaths=./target/jacoco-report/jacoco.xml
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.coverage.exclusions='**/exception/**, **/response/**, **/request/**, **/entity/**, **/utils/**, **/*Constant*, **/*Config.java, **/src/test/**'
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6 changes: 6 additions & 0 deletions .github/workflows/release_onboarding_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
sparse-checkout: |
libs/onboarding-sdk

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand All @@ -21,6 +23,10 @@ jobs:
java-version: '17'
cache: maven

- uses: s4u/[email protected]
with:
servers: '[{"id": "selfcare-github", "username": "${{ github.actor }}", "password": "${{ secrets.GITHUB_TOKEN }}"}]'

- name: Build with Maven
run: mvn --projects :onboarding-sdk --also-make-dependents clean package -DskipTests
shell: bash
Expand Down
32 changes: 24 additions & 8 deletions apps/onboarding-ms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ Repository that contains backend services synch for selfcare onboarding.

It implements CRUD operations for the 'onboarding' object and the business logic for the onboarding phase. During the onboarding process, the following activities are executed:

- Check for the presence of users associated with the onboarding and potentially add them to the point of sale (pdv).
- Validate the requested product's suitability and verify eligible roles.
- Verify if there is an existing onboarding record for that institution and product.
1. Check for the presence of users associated with the onboarding and potentially add them to the point of sale (pdv).
2. Validate the requested product's suitability and verify eligible roles.
3. Verify if there is an existing onboarding record for that institution and product.

After the data is saved, it invokes the function implemented by onboarding-functions to trigger asynchronous onboarding activities."
After the data is saved, it invokes the function implemented by onboarding-functions to trigger asynchronous onboarding activities.

### Disable starting async onboarding workflow

````properties
env ONBOARDING_ORCHESTRATION_ENABLED=false.
````
### Allowed onboarding product with status TESTING

ONBOARDING_ALLOWED_INSTITUTIONS_PRODUCTS property permits onboarding for product with status TESTING. It can contain a map of entry with product as key and a list of taxcode as value.

````properties
ONBOARDING_ALLOWED_INSTITUTIONS_PRODUCTS={'prod-interop': ['0123456789']}.
````

## Configuration Properties

Expand All @@ -17,15 +30,18 @@ Before running you must set these properties as environment variables.

| **Property** | **Environment Variable** | **Default** | **Required** |
|--------------------------------------------------------|------------------------------------------|-------------|:------------:|
| quarkus.mongodb.connection-string<br/> | MONGODB_CONNECTION_URI | | yes |
| mp.jwt.verify.publickey<br/> | JWT_TOKEN_PUBLIC_KEY | | yes |
| quarkus.rest-client."**.UserApi".api-key<br/> | USER_REGISTRY_API_KEY | | yes |
| quarkus.mongodb.connection-string<br/> | MONGODB-CONNECTION-STRING | | yes |
| mp.jwt.verify.publickey<br/> | JWT-PUBLIC-KEY | | yes |
| quarkus.rest-client."**.UserApi".api-key<br/> | USER-REGISTRY-API-KEY | | yes |
| quarkus.rest-client."**.UserApi".url<br/> | USER_REGISTRY_URL | | yes |
| quarkus.rest-client."**.ProductApi".url<br/> | MS_PRODUCT_URL | | yes |
| quarkus.rest-client."**.OrchestrationApi".url<br/> | ONBOARDING_FUNCTIONS_URL | | yes |
| quarkus.rest-client."**.OrchestrationApi".api-key<br/> | ONBOARDING_FUNCTIONS_API_KEY | | yes |
| quarkus.rest-client."**.OrchestrationApi".api-key<br/> | ONBOARDING-FUNCTIONS-API-KEY | | yes |
| onboarding.institutions-allowed-list<br/> | ONBOARDING_ALLOWED_INSTITUTIONS_PRODUCTS | | no |

> **_NOTE:_** properties that contains secret must have the same name of its secret as uppercase.


## Running the application in dev mode

You can run your application in dev mode that enables live coding using:
Expand Down
11 changes: 11 additions & 0 deletions apps/onboarding-ms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@
<artifactId>onboarding-sdk-common</artifactId>
<version>${onboarding-sdk.version}</version>
</dependency>

<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-azure-storage</artifactId>
<version>${onboarding-sdk.version}</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>${onboarding-sdk.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package it.pagopa.selfcare.onboarding.conf;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
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.ProductServiceDefault;
import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
public class OnboardingMsConfig {

@ConfigProperty(name = "onboarding-ms.blob-storage.container-product")
String containerProduct;

@ConfigProperty(name = "onboarding-ms.blob-storage.filepath-product")
String filepathProduct;

@ConfigProperty(name = "onboarding-ms.blob-storage.connection-string-product")
String connectionStringProduct;

@ApplicationScoped
public ProductService productService(ObjectMapper objectMapper){
AzureBlobClient azureBlobClient = new AzureBlobClientDefault(connectionStringProduct, containerProduct);
String productJsonString = azureBlobClient.getFileAsText(filepathProduct);
try {
return new ProductServiceDefault(productJsonString, objectMapper);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Found an issue when trying to serialize product json string!!");
}
}
}
Loading
Loading