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

replace selfcare-commons with onboarding-sdk-commons #28

Merged
merged 3 commits into from
Oct 30, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.selfcare.onboarding.entity;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionPaSubunitType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.Origin;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.selfcare.onboarding.entity;

import it.pagopa.selfcare.commons.base.security.PartyRole;

import it.pagopa.selfcare.onboarding.common.PartyRole;

public class User {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package it.pagopa.selfcare.onboarding.service;

import com.openhtmltopdf.extend.FSStream;
import com.openhtmltopdf.extend.FSStreamFactory;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import com.openhtmltopdf.svgsupport.BatikSVGDrawer;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.config.AzureStorageConfig;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import eu.europa.esig.dss.enumerations.DigestAlgorithm;
import eu.europa.esig.dss.model.DSSDocument;
import eu.europa.esig.dss.model.FileDocument;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.Token;
import it.pagopa.selfcare.onboarding.entity.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package it.pagopa.selfcare.onboarding.utils;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.common.PricingPlan;
import it.pagopa.selfcare.onboarding.entity.Billing;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.springframework.util.StringUtils;

import java.util.*;

Expand Down Expand Up @@ -119,7 +118,7 @@ public static void setupProdPNData(Map<String, Object> map, Institution institut


private static void addPricingPlan(String pricingPlan, Map<String, Object> map) {
if (StringUtils.hasText(pricingPlan) && Arrays.stream(PLAN_LIST).anyMatch(s -> s.equalsIgnoreCase(pricingPlan))) {
if (Objects.nonNull(pricingPlan) && Arrays.stream(PLAN_LIST).anyMatch(s -> s.equalsIgnoreCase(pricingPlan))) {
map.put("pricingPlanPremium", pricingPlan.replace("C", ""));
map.put("pricingPlanPremiumCheckbox", "X");
} else {
Expand All @@ -129,7 +128,7 @@ private static void addPricingPlan(String pricingPlan, Map<String, Object> map)

map.put("pricingPlanPremiumBase", Optional.ofNullable(pricingPlan).orElse(""));

if (StringUtils.hasText(pricingPlan) && "C0".equalsIgnoreCase(pricingPlan)) {
if (Objects.nonNull(pricingPlan) && "C0".equalsIgnoreCase(pricingPlan)) {
map.put("pricingPlanPremiumBaseCheckbox", "X");
} else {
map.put("pricingPlanPremiumBaseCheckbox", "");
Expand All @@ -138,7 +137,7 @@ private static void addPricingPlan(String pricingPlan, Map<String, Object> map)

private static void addInstitutionRegisterLabelValue(Institution institution, Map<String, Object> map) {
if (institution.getPaymentServiceProvider() != null
&& StringUtils.hasText(institution.getPaymentServiceProvider().getBusinessRegisterNumber())) {
&& Objects.nonNull(institution.getPaymentServiceProvider().getBusinessRegisterNumber())) {
map.put("number", institution.getPaymentServiceProvider().getBusinessRegisterNumber());
map.put("institutionRegisterLabelValue", "<li class=\"c19 c39 li-bullet-0\"><span class=\"c1\">codice di iscrizione all&rsquo;Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) <span class=\"c3\">${number}</span> </span><span class=\"c1\"></span></li>\n");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import jakarta.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import eu.europa.esig.dss.model.FileDocument;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.Token;
import it.pagopa.selfcare.onboarding.entity.User;
Expand Down
7 changes: 7 additions & 0 deletions onboarding-ms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<quarkus.platform.version>3.4.2</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<onboarding-sdk.version>0.0.4</onboarding-sdk.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -111,6 +112,7 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-context-propagation</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-mock</artifactId>
Expand All @@ -127,6 +129,11 @@
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>${onboarding-sdk.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.controller.request;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.util.InstitutionPaSubunitType;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.selfcare.onboarding.controller.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.controller.response;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.controller.request.DataProtectionOfficerRequest;
import it.pagopa.selfcare.onboarding.controller.request.PaymentServiceProviderRequest;
import it.pagopa.selfcare.onboarding.util.InstitutionPaSubunitType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.controller.response;

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

@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.entity;

import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.util.InstitutionPaSubunitType;
import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.selfcare.onboarding.entity;

import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io.quarkus.mongodb.panache.common.reactive.Panache;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.constants.CustomError;
import it.pagopa.selfcare.onboarding.controller.request.*;
import it.pagopa.selfcare.onboarding.controller.response.OnboardingResponse;
Expand All @@ -29,7 +29,6 @@
import org.openapi.quarkus.product_json.model.ProductRoleInfoRes;
import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.*;
import org.springframework.util.Assert;

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -163,14 +162,15 @@ private Uni<Boolean> checkIfAlreadyOnboardingAndValidateAllowedMap(String produc

private void validateProductRole(List<User> users, Map<String, ProductRoleInfoOperations> roleMappings) {
try {
Assert.notNull(roleMappings, "Role mappings is required");
if(Objects.isNull(roleMappings) || roleMappings.isEmpty())
throw new IllegalArgumentException("Role mappings is required");
users.forEach(userInfo -> {
Assert.notNull(roleMappings.get(userInfo.getRole().name()),
String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
Assert.notEmpty(roleMappings.get(userInfo.getRole().name()).getRoles(),
String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
Assert.state(roleMappings.get(userInfo.getRole().name()).getRoles().size() == 1,
String.format(MORE_THAN_ONE_PRODUCT_ROLE_AVAILABLE, userInfo.getRole()));
if(Objects.isNull(roleMappings.get(userInfo.getRole().name())))
throw new IllegalArgumentException(String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
if(Objects.isNull((roleMappings.get(userInfo.getRole().name()).getRoles())))
throw new IllegalArgumentException(String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
if(roleMappings.get(userInfo.getRole().name()).getRoles().size() == 1)
throw new IllegalArgumentException(String.format(MORE_THAN_ONE_PRODUCT_ROLE_AVAILABLE, userInfo.getRole()));
userInfo.setProductRole(roleMappings.get(userInfo.getRole().name()).getRoles().get(0).getCode());
});
} catch (IllegalArgumentException e){
Expand All @@ -180,14 +180,15 @@ private void validateProductRole(List<User> users, Map<String, ProductRoleInfoOp

private void validateProductRoleRes(List<User> users, Map<String, ProductRoleInfoRes> roleMappings) {
try {
Assert.notNull(roleMappings, "Role mappings is required");
if(Objects.isNull(roleMappings) || roleMappings.isEmpty())
throw new IllegalArgumentException("Role mappings is required");
users.forEach(userInfo -> {
Assert.notNull(roleMappings.get(userInfo.getRole().name()),
String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
Assert.notEmpty(roleMappings.get(userInfo.getRole().name()).getRoles(),
String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
Assert.state(roleMappings.get(userInfo.getRole().name()).getRoles().size() == 1,
String.format(MORE_THAN_ONE_PRODUCT_ROLE_AVAILABLE, userInfo.getRole()));
if(Objects.isNull(roleMappings.get(userInfo.getRole().name())))
throw new IllegalArgumentException(String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
if(Objects.isNull((roleMappings.get(userInfo.getRole().name()).getRoles())))
throw new IllegalArgumentException(String.format(ATLEAST_ONE_PRODUCT_ROLE_REQUIRED, userInfo.getRole()));
if(roleMappings.get(userInfo.getRole().name()).getRoles().size() == 1)
throw new IllegalArgumentException(String.format(MORE_THAN_ONE_PRODUCT_ROLE_AVAILABLE, userInfo.getRole()));
userInfo.setProductRole(roleMappings.get(userInfo.getRole().name()).getRoles().get(0).getCode());
});
} catch (IllegalArgumentException e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import io.quarkus.test.security.TestSecurity;
import io.restassured.http.ContentType;
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.controller.OnboardingController;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.controller.request.*;
import it.pagopa.selfcare.onboarding.controller.response.OnboardingResponse;
import it.pagopa.selfcare.onboarding.service.OnboardingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.quarkus.test.vertx.UniAsserter;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.controller.request.*;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.exception.InvalidRequestException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.pagopa.selfcare.onboarding.common;

public enum InstitutionType {
PA,
PG,
GSP,
SA,
PT,
SCP,
PSP,
AS
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package it.pagopa.selfcare.onboarding.common;

import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Objects;

public enum Origin {
MOCK("MOCK"),
Expand Down Expand Up @@ -30,7 +29,7 @@ public String toString() {


public static Origin fromValue(String value) {
if(StringUtils.hasText(value)) {
if(Objects.nonNull(value)) {
return Arrays.stream(values())
.filter(origin -> origin.toString().equals(value))
.findAny()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.pagopa.selfcare.onboarding.common;

public enum PartyRole {
MANAGER,
DELEGATE,
SUB_DELEGATE,
OPERATOR;

}
7 changes: 7 additions & 0 deletions onboarding-sdk/onboarding-sdk-product/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
<version>${jackson.version}</version>
</dependency>


<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>0.0.1</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package it.pagopa.selfcare.product.entity;


import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.PartyRole;

import java.time.Instant;
import java.util.EnumMap;
import java.util.Map;

public class Product {
Expand All @@ -22,7 +20,7 @@ public class Product {
private String createdBy;
private Instant modifiedAt;
private String modifiedBy;
private EnumMap<PartyRole, ProductRoleInfo> roleMappings;
private Map<PartyRole, ProductRoleInfo> roleMappings;
private String roleManagementURL;
private Instant contractTemplateUpdatedAt;
private String contractTemplatePath;
Expand Down Expand Up @@ -132,11 +130,11 @@ public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}

public EnumMap<PartyRole, ProductRoleInfo> getRoleMappings() {
public Map<PartyRole, ProductRoleInfo> getRoleMappings() {
return roleMappings;
}

public void setRoleMappings(EnumMap<PartyRole, ProductRoleInfo> roleMappings) {
public void setRoleMappings(Map<PartyRole, ProductRoleInfo> roleMappings) {
this.roleMappings = roleMappings;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package it.pagopa.selfcare.product.service;


import it.pagopa.selfcare.commons.base.security.PartyRole;
import it.pagopa.selfcare.commons.base.utils.InstitutionType;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;

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

public interface ProductService {
List<Product> getProducts(boolean rootOnly);

void validateRoleMappings(EnumMap<PartyRole, ? extends ProductRoleInfo> roleMappings);
void validateRoleMappings(Map<PartyRole, ? extends ProductRoleInfo> roleMappings);

Product getProduct(String id, InstitutionType institutionType);

Expand Down
Loading
Loading