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-5872] feat: add userAggregatorContractMappings field in Product entity in onboarding-sdk #590

Merged
merged 2 commits into from
Nov 6, 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
6 changes: 3 additions & 3 deletions apps/onboarding-functions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-crypto</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-azure-storage</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
4 changes: 2 additions & 2 deletions apps/onboarding-ms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-azure-storage</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion libs/onboarding-sdk-azure-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-pom</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<relativePath>../onboarding-sdk-pom</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion libs/onboarding-sdk-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-pom</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<relativePath>../onboarding-sdk-pom</relativePath>
</parent>
<artifactId>onboarding-sdk-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion libs/onboarding-sdk-crypto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-pom</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<relativePath>../onboarding-sdk-pom</relativePath>
</parent>
<artifactId>onboarding-sdk-crypto</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion libs/onboarding-sdk-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>onboarding-sdk-pom</artifactId>
<packaging>pom</packaging>
<name>onboarding-sdk-pom</name>
<version>0.4.0</version>
<version>0.4.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
4 changes: 2 additions & 2 deletions libs/onboarding-sdk-product/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-pom</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<relativePath>../onboarding-sdk-pom</relativePath>
</parent>
<artifactId>onboarding-sdk-product</artifactId>
<name>onboarding-sdk-product</name>
<version>0.4.0</version>
<version>0.4.1</version>

<properties>
<jackson.version>2.15.2</jackson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public enum PHASE_ADDITION_ALLOWED {
DASHBOARD("dashboard"),

//Phase on dashboard "Aggiunta Utenti" when a sign contract is needed
DASHBOARD_ASYNC("dashboard-async");
DASHBOARD_ASYNC("dashboard-async"),

//Phase on dashboard "Aggiunta Utenti" for aggregators when a sign contract is needed
DASHBOARD_AGGREGATOR("dashboard-aggregator");

public final String value;

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

import it.pagopa.selfcare.onboarding.common.PartyRole;
import org.apache.commons.lang3.StringUtils;

import java.time.Instant;
import java.util.*;
import org.apache.commons.lang3.StringUtils;

public class Product {

Expand Down Expand Up @@ -36,6 +37,7 @@ public class Product {
private List<String> consumers;
private Map<String, ContractTemplate> institutionContractMappings;
private Map<String, ContractTemplate> userContractMappings;
private Map<String, ContractTemplate> userAggregatorContractMappings;

public String getId() {
return id;
Expand Down Expand Up @@ -300,6 +302,14 @@ public void setUserContractMappings(Map<String, ContractTemplate> userContractMa
this.userContractMappings = userContractMappings;
}

public Map<String, ContractTemplate> getUserAggregatorContractMappings() {
return userAggregatorContractMappings;
}

public void setUserAggregatorContractMappings(Map<String, ContractTemplate> userAggregatorContractMappings) {
this.userAggregatorContractMappings = userAggregatorContractMappings;
}

public String getAlias() {
return alias;
}
Expand Down Expand Up @@ -347,4 +357,24 @@ && getInstitutionContractMappings().containsKey(institutionType)) {
}
return contractTemplate;
}

/**
* This method returns ContractTemplate associate with a specific InstitutionType for UserAggregatorContract.
* In case none InstitutionType exists on contractMapping, it returns the default ContractTemplate.
*
* @param institutionType InstitutionType
* @return ContractTemplate
*/
public ContractTemplate getUserAggregatorContractTemplate(String institutionType) {
ContractTemplate userAggregatorContractTemplate = new ContractTemplate();
if (Objects.nonNull(getUserAggregatorContractMappings())) {
if (Objects.nonNull(institutionType)
&& getUserAggregatorContractMappings().containsKey(institutionType)) {
userAggregatorContractTemplate = getUserAggregatorContractMappings().get(institutionType);
} else if (getUserAggregatorContractMappings().containsKey(CONTRACT_TYPE_DEFAULT)) {
userAggregatorContractTemplate = getUserAggregatorContractMappings().get(CONTRACT_TYPE_DEFAULT);
}
}
return userAggregatorContractTemplate;
}
giulia-tremolada marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package it.pagopa.selfcare.product.entity;

import static org.junit.jupiter.api.Assertions.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;

public class ProductTest {

private static final Logger log = LoggerFactory.getLogger(ProductTest.class);
Expand Down Expand Up @@ -277,4 +278,58 @@ void productTest() {
.asText());
assertEquals(product.getStatus().toString(), jsonNode.get("status").asText());
}

@Test
void testGetUserAggregatorContractTemplate_WithValidInstitutionType() {
// Setup
Product product = new Product();
Map<String, ContractTemplate> mappings = new HashMap<>();
ContractTemplate contractTemplate = new ContractTemplate();
contractTemplate.setContractTemplatePath("path");
contractTemplate.setContractTemplatePath("version");
mappings.put("validType", contractTemplate);
product.setUserAggregatorContractMappings(mappings);

// Execute
ContractTemplate result = product.getUserAggregatorContractTemplate("validType");

// Verify
assertNotNull(result);
assertEquals(mappings.get("validType"), result);
}

@Test
void testGetUserAggregatorContractTemplate_WithDefault() {
// Setup
Product product = new Product();
Map<String, ContractTemplate> mappings = new HashMap<>();
ContractTemplate contractTemplate = new ContractTemplate();
contractTemplate.setContractTemplatePath("path");
contractTemplate.setContractTemplatePath("version");
mappings.put("default", contractTemplate);
product.setUserAggregatorContractMappings(mappings);

// Execute
ContractTemplate result = product.getUserAggregatorContractTemplate("unknownType");

// Verify
assertNotNull(result);
assertEquals(mappings.get("default"), result);
}

@Test
void testGetUserAggregatorContractTemplate_NoMappings() {
// Setup
Product product = new Product();
product.setUserAggregatorContractMappings(null);

// Execute
ContractTemplate result = product.getUserAggregatorContractTemplate("anyType");

// Verify
assertNotNull(result);
assertEquals(ContractTemplate.class, result.getClass());
assertNull(result.getContractTemplatePath());
assertNull(result.getContractTemplateVersion());
}
}
8 changes: 4 additions & 4 deletions test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-common</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-azure-storage</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-crypto</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
</dependencies>

Expand Down
Loading