-
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-6181] feat: added implementation of new API to find manager dat…
…a given onboardingId
- Loading branch information
Showing
8 changed files
with
512 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
core/src/main/java/it/pagopa/selfcare/onboarding/core/utils/PgManagerVerifier.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,52 @@ | ||
package it.pagopa.selfcare.onboarding.core.utils; | ||
|
||
import it.pagopa.selfcare.commons.base.logging.LogUtils; | ||
import it.pagopa.selfcare.commons.base.utils.Origin; | ||
import it.pagopa.selfcare.onboarding.connector.api.PartyRegistryProxyConnector; | ||
import it.pagopa.selfcare.onboarding.connector.exceptions.InvalidRequestException; | ||
import it.pagopa.selfcare.onboarding.connector.model.institutions.ManagerVerification; | ||
import it.pagopa.selfcare.onboarding.connector.model.institutions.MatchInfoResult; | ||
import it.pagopa.selfcare.onboarding.connector.model.institutions.infocamere.BusinessInfoIC; | ||
import it.pagopa.selfcare.onboarding.connector.model.institutions.infocamere.InstitutionInfoIC; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.owasp.encoder.Encode; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@Service | ||
@AllArgsConstructor | ||
public class PgManagerVerifier { | ||
private final PartyRegistryProxyConnector partyRegistryProxyConnector; | ||
|
||
public ManagerVerification doVerify(String userTaxCode, String institutionTaxCode) { | ||
log.debug(LogUtils.CONFIDENTIAL_MARKER, "Checking if user with taxCode {} is manager of institution with taxCode {} on INFOCAMERE", Encode.forJava(userTaxCode), Encode.forJava(institutionTaxCode)); | ||
InstitutionInfoIC institutionInfoIC = partyRegistryProxyConnector.getInstitutionsByUserFiscalCode(userTaxCode); | ||
if (Objects.nonNull(institutionInfoIC) && Objects.nonNull(institutionInfoIC.getBusinesses())){ | ||
for (BusinessInfoIC business : institutionInfoIC.getBusinesses()) { | ||
if (institutionTaxCode.equals(business.getBusinessTaxId())) { | ||
log.debug("User found as manager in INFOCAMERE for business with name = {}", business.getBusinessName()); | ||
return new ManagerVerification(Origin.INFOCAMERE.getValue(), business.getBusinessName(), true); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
log.debug(LogUtils.CONFIDENTIAL_MARKER, "Checking if user with taxCode {} is manager of institution with taxCode {} on ADE", Encode.forJava(userTaxCode), Encode.forJava(institutionTaxCode)); | ||
MatchInfoResult matchInfoResult = partyRegistryProxyConnector.matchInstitutionAndUser(institutionTaxCode, userTaxCode); | ||
if (Objects.nonNull(matchInfoResult) && matchInfoResult.isVerificationResult()) { | ||
log.debug("User found as manager in ADE, response = {}", matchInfoResult); | ||
return new ManagerVerification(Origin.ADE.getValue(), null, true); | ||
} | ||
} catch (InvalidRequestException e) { | ||
log.debug("User not found as manager in ADE"); | ||
return new ManagerVerification(false); | ||
} | ||
|
||
log.debug("User not found as manager in INFOCAMERE or ADE"); | ||
return new ManagerVerification(false); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
core/src/main/java/it/pagopa/selfcare/onboarding/core/utils/Utils.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,27 @@ | ||
package it.pagopa.selfcare.onboarding.core.utils; | ||
|
||
import it.pagopa.selfcare.onboarding.common.PartyRole; | ||
import it.pagopa.selfcare.onboarding.connector.model.onboarding.User; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class Utils { | ||
private Utils() { | ||
} | ||
|
||
public static boolean isUserAdmin(String userTaxCode, List<User> users) { | ||
return users.stream() | ||
.anyMatch(user -> user.getTaxCode().equals(userTaxCode) && | ||
(user.getRole() == PartyRole.MANAGER | ||
|| user.getRole() == PartyRole.DELEGATE | ||
|| user.getRole() == PartyRole.SUB_DELEGATE) | ||
); | ||
} | ||
|
||
public static Optional<User> getManager(List<User> users) { | ||
return users.stream() | ||
.filter(user -> user.getRole() == PartyRole.MANAGER) | ||
.findFirst(); | ||
} | ||
} |
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
Oops, something went wrong.