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.
feat: move validRoles to new ProductUtils class
- Loading branch information
Showing
4 changed files
with
42 additions
and
13 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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
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 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 | ||
* @return List<PartyRole> | ||
*/ | ||
public static List<PartyRole> validRoles(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)) | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toList()); | ||
|
||
} | ||
} |