generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5665] feat: enable addition Roles using phasesAdditionAllowed (#…
…510)
- Loading branch information
Showing
17 changed files
with
179 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...g-sdk-product/src/main/java/it/pagopa/selfcare/product/entity/PHASE_ADDITION_ALLOWED.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.pagopa.selfcare.product.entity; | ||
|
||
public enum PHASE_ADDITION_ALLOWED { | ||
|
||
//Phase on onboarding process | ||
ONBOARDING("onboarding"), | ||
|
||
//Phase on dashboard "Aggiunta Utenti" with any constraints | ||
DASHBOARD("dashboard"), | ||
|
||
//Phase on dashboard "Aggiunta Utenti" when a sign contract is needed | ||
DASHBOARD_ASYNC("dashboard-async"); | ||
|
||
public final String value; | ||
|
||
PHASE_ADDITION_ALLOWED(String value){ | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
libs/onboarding-sdk-product/src/main/java/it/pagopa/selfcare/product/utils/ProductUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package it.pagopa.selfcare.product.utils; | ||
|
||
import it.pagopa.selfcare.onboarding.common.PartyRole; | ||
import it.pagopa.selfcare.product.entity.PHASE_ADDITION_ALLOWED; | ||
import it.pagopa.selfcare.product.entity.Product; | ||
import it.pagopa.selfcare.product.entity.ProductRoleInfo; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class ProductUtils { | ||
|
||
/** | ||
* Returns list of product's PartyRole associates with that PHASE_ADDITION_ALLOWED | ||
* @param product Product | ||
* @param phase PHASE_ADDITION_ALLOWED | ||
* @return List<PartyRole> | ||
*/ | ||
public static List<PartyRole> validRoles(Product product, PHASE_ADDITION_ALLOWED phase) { | ||
return validEntryRoles(product, phase) | ||
.stream() | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Returns list of product's PartyRole associates with that PHASE_ADDITION_ALLOWED and filtering for productRole | ||
* @param product Product | ||
* @param phase PHASE_ADDITION_ALLOWED | ||
* @param productRole String | ||
* @return List<PartyRole> | ||
*/ | ||
public static List<PartyRole> validRolesByProductRole(Product product, PHASE_ADDITION_ALLOWED phase, String productRole) { | ||
if(Objects.isNull(product)) return List.of(); | ||
return validEntryRoles(product, phase) | ||
.stream() | ||
.filter(entry -> Objects.nonNull(entry.getValue().getRoles()) && | ||
entry.getValue().getRoles().stream() | ||
.anyMatch(item -> productRole.equals(item.getCode()))) | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static List<Map.Entry<PartyRole, ProductRoleInfo>> validEntryRoles(Product product, PHASE_ADDITION_ALLOWED phase) { | ||
if (Objects.isNull(product)) { | ||
throw new IllegalArgumentException("Product must not be null!"); | ||
} | ||
return Optional.ofNullable(product.getRoleMappings()) | ||
.orElse(Map.of()) | ||
.entrySet().stream() | ||
.filter(entry -> Objects.nonNull(entry.getValue().getPhasesAdditionAllowed()) && | ||
entry.getValue().getPhasesAdditionAllowed().contains(phase.value)) | ||
.collect(Collectors.toList()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...boarding-sdk-product/src/test/java/it/pagopa/selfcare/product/utils/ProductUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package it.pagopa.selfcare.product.utils; | ||
|
||
import it.pagopa.selfcare.onboarding.common.PartyRole; | ||
import it.pagopa.selfcare.product.entity.PHASE_ADDITION_ALLOWED; | ||
import it.pagopa.selfcare.product.entity.Product; | ||
import it.pagopa.selfcare.product.entity.ProductRole; | ||
import it.pagopa.selfcare.product.entity.ProductRoleInfo; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ProductUtilsTest { | ||
|
||
private final static String productRoleManager = "admin"; | ||
|
||
@Test | ||
void validRoles() { | ||
Product product = dummyProduct(); | ||
List<PartyRole> partyRoles = ProductUtils.validRoles(product, PHASE_ADDITION_ALLOWED.ONBOARDING); | ||
assertEquals(1, partyRoles.size()); | ||
assertEquals(PartyRole.MANAGER, partyRoles.get(0)); | ||
} | ||
|
||
@Test | ||
void validRolesByProductRole() { | ||
Product product = dummyProduct(); | ||
List<PartyRole> partyRoles = ProductUtils.validRolesByProductRole(product, PHASE_ADDITION_ALLOWED.ONBOARDING, productRoleManager); | ||
assertEquals(1, partyRoles.size()); | ||
assertEquals(PartyRole.MANAGER, partyRoles.get(0)); | ||
} | ||
|
||
Product dummyProduct() { | ||
|
||
ProductRole productRole = new ProductRole(); | ||
productRole.setCode(productRoleManager); | ||
ProductRoleInfo productRoleInfo = new ProductRoleInfo(); | ||
productRoleInfo.setRoles(List.of(productRole)); | ||
productRoleInfo.setPhasesAdditionAllowed(List.of(PHASE_ADDITION_ALLOWED.ONBOARDING.value)); | ||
|
||
ProductRole productRoleOperator = new ProductRole(); | ||
productRoleOperator.setCode("operator"); | ||
ProductRoleInfo productRoleInfoOperator = new ProductRoleInfo(); | ||
productRoleInfoOperator.setRoles(List.of(productRoleOperator)); | ||
productRoleInfoOperator.setPhasesAdditionAllowed(List.of(PHASE_ADDITION_ALLOWED.DASHBOARD.value)); | ||
|
||
Map<PartyRole, ProductRoleInfo> roleMapping = new HashMap<>(); | ||
roleMapping.put(PartyRole.MANAGER, productRoleInfo); | ||
roleMapping.put(PartyRole.OPERATOR, productRoleInfoOperator); | ||
|
||
Product productResource = new Product(); | ||
productResource.setId("productId"); | ||
productResource.setRoleMappings(roleMapping); | ||
return productResource; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters