Skip to content

Commit

Permalink
feat: added validRolesByProductRole on ProductUtiles
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Oct 1, 2024
1 parent 92323ba commit db467f3
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -15,10 +16,35 @@ public class ProductUtils {
/**
* Returns list of product's PartyRole associates with that PHASE_ADDITION_ALLOWED
* @param product Product
* @param phase phase
* @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!");
}
Expand All @@ -27,7 +53,6 @@ public static List<PartyRole> validRoles(Product product, PHASE_ADDITION_ALLOWED
.entrySet().stream()
.filter(entry -> Objects.nonNull(entry.getValue().getPhasesAdditionAllowed()) &&
entry.getValue().getPhasesAdditionAllowed().contains(phase.value))
.map(Map.Entry::getKey)
.collect(Collectors.toList());

}
Expand Down

0 comments on commit db467f3

Please sign in to comment.