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

[SELC-4385] feat: Added dependency and configuration of product libs #426

Merged
merged 12 commits into from
May 7, 2024
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
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
3 changes: 3 additions & 0 deletions app/src/main/resources/config/dashboard-config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dashboard.blob-storage.container-product=${PRODUCT_STORAGE_CONTAINER:selc-d-product}
dashboard.blob-storage.filepath-product = products.json
dashboard.blob-storage.connection-string-product = ${BLOB_STORAGE_PRODUCT_CONNECTION_STRING:UseDevelopmentStorage=true;}
19 changes: 0 additions & 19 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6180,16 +6180,6 @@
"title" : "ProductsResource",
"type" : "object",
"properties" : {
"activatedAt" : {
"type" : "string",
"description" : "Date the products was activated",
"format" : "date-time"
},
"authorized" : {
"type" : "boolean",
"description" : "flag indicating whether the logged user has the authorization to manage the product",
"example" : false
},
"backOfficeEnvironmentConfigurations" : {
"type" : "array",
"description" : "Environment-specific configurations for back-office redirection with Token Exchange",
Expand Down Expand Up @@ -6234,11 +6224,6 @@
"type" : "string",
"description" : "Product logo's background color"
},
"productOnBoardingStatus" : {
"type" : "string",
"description" : "Product's onBoarding status",
"enum" : [ "ACTIVE", "INACTIVE", "PENDING" ]
},
"status" : {
"type" : "string",
"description" : "Product's status",
Expand All @@ -6255,10 +6240,6 @@
"urlPublic" : {
"type" : "string",
"description" : "URL that redirects to the public information webpage of the product"
},
"userRole" : {
"type" : "string",
"description" : "Logged user's role"
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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>
<scope>compile</scope>
</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>

</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package it.pagopa.selfcare.dashboard.connector.api;

import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.dashboard.connector.model.product.Product;
import it.pagopa.selfcare.dashboard.connector.model.product.ProductRoleInfo;
import it.pagopa.selfcare.dashboard.connector.model.product.ProductTree;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package it.pagopa.selfcare.dashboard.connector.config;

import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("classpath:config/dashboard-config.properties")
@ConfigurationProperties(prefix = "dashboard")
@Data
@ToString
public class DashboardConfig {

private BlobStorage blobStorage;

@Data
public static class BlobStorage {
private String containerProduct;
private String filepathProduct;
private String connectionStringProduct;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.dashboard.connector.model.product;

import it.pagopa.selfcare.product.entity.Product;
import lombok.Data;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package it.pagopa.selfcare.dashboard.connector.model.product.mapper;

import it.pagopa.selfcare.dashboard.connector.model.product.ProductTree;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRole;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;
import org.springframework.stereotype.Component;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
public class ProductMapper {

public List<ProductTree> toTreeResource(List<Product> model) {
List<ProductTree> resources = null;
if (model != null) {
Map<String, List<Product>> collect = model.stream()
.filter(productOperations -> productOperations.getParentId() != null)
.collect(Collectors.groupingBy(Product::getParentId, Collectors.toList()));
resources = model.stream()
.filter(productOperations -> productOperations.getParentId() == null)
.map(productOperations -> {
ProductTree productTreeResource = new ProductTree();
productTreeResource.setNode(productOperations);
if (collect.get(productOperations.getId()) != null) {
productTreeResource.setChildren(collect.get(productOperations.getId()));
}
return productTreeResource;
}).toList();
}
return resources;
}

public static Optional<String> getLabel(String productRoleCode, Map<PartyRole, ProductRoleInfo> roleMappings) {
return roleMappings.values().stream()
.flatMap(productRoleInfo -> productRoleInfo.getRoles().stream())
.filter(prodRole -> prodRole.getCode().equals(productRoleCode))
.findAny()
.map(ProductRole::getLabel);
}

public static Optional<PartyRole> getPartyRole(String productRoleCode, Map<PartyRole, ProductRoleInfo> roleMappings) {
return getPartyRole(productRoleCode, roleMappings, EnumSet.allOf(PartyRole.class));
}

public static Optional<it.pagopa.selfcare.onboarding.common.PartyRole> getPartyRole(String productRoleCode, Map<PartyRole, ProductRoleInfo> roleMappings, EnumSet<PartyRole> partyRoleWhiteList) {
return roleMappings.entrySet().stream()
.filter(entry -> partyRoleWhiteList.contains(entry.getKey()))
.filter(entry -> entry.getValue().getRoles().stream().anyMatch(productRole -> productRole.getCode().equals(productRoleCode)))
.map(Map.Entry::getKey)
.findAny();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.dashboard.connector.model.user;

import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import lombok.Data;

import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package it.pagopa.selfcare.dashboard.connector.rest;

import it.pagopa.selfcare.commons.base.logging.LogUtils;
import it.pagopa.selfcare.dashboard.connector.api.ProductsConnector;
import it.pagopa.selfcare.dashboard.connector.model.product.ProductTree;
import it.pagopa.selfcare.dashboard.connector.model.product.mapper.ProductMapper;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;
import it.pagopa.selfcare.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ProductConnectorImpl implements ProductsConnector {

private final ProductService productService;

private final ProductMapper productMapper;

public ProductConnectorImpl(ProductService productService, ProductMapper productMapper) {
this.productService = productService;
this.productMapper = productMapper;
}

@Override
public List<Product> getProducts() {
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProducts");
return productService.getProducts(false,true);
}

@Override
public Map<PartyRole, ProductRoleInfo> getProductRoleMappings(String productId) {
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProduct productId = {}", productId);
Assert.hasText(productId, "A productId is required");
Product product = productService.getProduct(productId);
Map<PartyRole, ProductRoleInfo> result = product != null ? product.getRoleMappings() : null;
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProduct result = {}", result);
return result;
}

@Override
public Product getProduct(String productId) {
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProduct productId = {}", productId);
Assert.hasText(productId, "A productId is required");
Product result = productService.getProduct(productId);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProduct result = {}", result);
return result;
}

@Override
public List<ProductTree> getProductsTree() {
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getProductsTree");
List<Product> products = productService.getProducts(false, true);
return productMapper.toTreeResource(products);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.commons.base.security.SelfCareAuthority;
import it.pagopa.selfcare.core.generated.openapi.v1.dto.*;
import it.pagopa.selfcare.dashboard.connector.model.auth.AuthInfo;
Expand All @@ -27,6 +26,7 @@
import it.pagopa.selfcare.dashboard.connector.rest.model.mapper.BrokerMapper;
import it.pagopa.selfcare.dashboard.connector.rest.model.mapper.DelegationRestClientMapperImpl;
import it.pagopa.selfcare.dashboard.connector.rest.model.mapper.InstitutionMapperImpl;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
Expand Down Expand Up @@ -105,7 +105,7 @@ public CoreConnectorImplTest() {
mapper.setTimeZone(TimeZone.getDefault());
}

private static final Function<PartyRole, SelfCareAuthority> PARTY_2_SELC_ROLE = partyRole -> switch (partyRole) {
private static final Function<it.pagopa.selfcare.commons.base.security.PartyRole, SelfCareAuthority> PARTY_2_SELC_ROLE = partyRole -> switch (partyRole) {
case MANAGER, DELEGATE, SUB_DELEGATE -> ADMIN;
default -> LIMITED;
};
Expand Down Expand Up @@ -737,8 +737,8 @@ void getAuthInfo() {
}

@ParameterizedTest
@EnumSource(value = PartyRole.class)
void party2SelcRoleMapping(PartyRole partyRole) {
@EnumSource(value = it.pagopa.selfcare.commons.base.security.PartyRole.class)
void party2SelcRoleMapping(it.pagopa.selfcare.commons.base.security.PartyRole partyRole) {
// when
SelfCareAuthority authority = partyRole.getSelfCareAuthority();
// then
Expand Down Expand Up @@ -843,7 +843,7 @@ void getUsers_notEmptyRole(SelfCareAuthority selfCareAuthority) {
userInfoFilter.setRole(selfCareAuthority);
userInfoFilter.setAllowedStates(List.of(ACTIVE, SUSPENDED));
List<String> partyRoles = new ArrayList<>();
for (PartyRole partyRole : PartyRole.values()) {
for (it.pagopa.selfcare.commons.base.security.PartyRole partyRole : it.pagopa.selfcare.commons.base.security.PartyRole.values()) {
if (userInfoFilter.getRole().equals(PARTY_2_SELC_ROLE.apply(partyRole))) {
partyRoles.add(partyRole.name());
}
Expand Down
Loading
Loading