Skip to content

Commit

Permalink
Update registry managers for ADE and INFOCAMERE
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Dec 4, 2024
1 parent e943167 commit 16ef2b6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package it.pagopa.selfcare.onboarding.entity.registry;


import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.User;

public abstract class BaseRegistryManager<T> implements RegistryManager<T> {

Expand All @@ -11,6 +13,7 @@ public abstract class BaseRegistryManager<T> implements RegistryManager<T> {
protected static final String ONBOARDING_NOT_ALLOWED_ERROR_MESSAGE_NOT_DELEGABLE = "Institution with external id '%s' is not allowed to onboard '%s' product because it is not delegable";
protected static final String PARENT_TAX_CODE_IS_INVALID = "The tax code of the parent entity of the request does not match the tax code of the parent entity retrieved by IPA";
protected static final String TAX_CODE_INVOICING_IS_INVALID = "The tax code invoicing of the request does not match any tax code of institutions' hierarchy";
protected static final String PNPG_INSTITUTION_REGISTRY_NOT_FOUND = "Institution with taxCode %s is not into registry";
protected static final int DURATION_TIMEOUT = 5;
protected static final int MAX_NUMBER_ATTEMPTS = 2;

Expand All @@ -33,4 +36,12 @@ public RegistryManager<T> setResource(T registryResource) {
this.registryResource = registryResource;
return this;
}

protected String getManagerIdFromOnboarding() {
return onboarding.getUsers().stream()
.filter(user -> user.getRole().equals(PartyRole.MANAGER))
.map(User::getId)
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.registry.client.ClientRegistryADE;
import it.pagopa.selfcare.onboarding.exception.InvalidRequestException;
import it.pagopa.selfcare.product.entity.Product;
import org.openapi.quarkus.party_registry_proxy_json.api.NationalRegistriesApi;
import org.openapi.quarkus.user_registry_json.api.UserApi;

import java.util.Objects;

public class RegistryManagerADE extends ClientRegistryADE {

public RegistryManagerADE(Onboarding onboarding, NationalRegistriesApi nationalRegistriesApi, UserApi userApi) {
public RegistryManagerADE(
Onboarding onboarding, NationalRegistriesApi nationalRegistriesApi, UserApi userApi) {
super(onboarding, nationalRegistriesApi, userApi);
}

Expand All @@ -20,7 +24,15 @@ public Uni<Onboarding> customValidation(Product product) {

@Override
public Uni<Boolean> isValid() {
Boolean result = super.registryResource;
if (Objects.isNull(result) || !result) {
return Uni.createFrom()
.failure(
new InvalidRequestException(
String.format(
PNPG_INSTITUTION_REGISTRY_NOT_FOUND,
onboarding.getInstitution().getTaxCode())));
}
return Uni.createFrom().item(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.registry.client.ClientRegistryInfocamere;
import it.pagopa.selfcare.onboarding.exception.InvalidRequestException;
import it.pagopa.selfcare.product.entity.Product;
import org.openapi.quarkus.party_registry_proxy_json.api.InfocamereApi;
import org.openapi.quarkus.party_registry_proxy_json.model.BusinessResource;
import org.openapi.quarkus.user_registry_json.api.UserApi;

import java.util.List;
import java.util.Objects;

public class RegistryManagerInfocamere extends ClientRegistryInfocamere {

public RegistryManagerInfocamere(Onboarding onboarding, InfocamereApi infocamereApi) {
super(onboarding, infocamereApi);
public RegistryManagerInfocamere(
Onboarding onboarding, InfocamereApi infocamereApi, UserApi userApi) {
super(onboarding, infocamereApi, userApi);
}

@Override
Expand All @@ -19,7 +26,26 @@ public Uni<Onboarding> customValidation(Product product) {

@Override
public Uni<Boolean> isValid() {
List<BusinessResource> institutions = super.registryResource.getBusinesses();
if (institutions.isEmpty() || Objects.isNull(findByTaxCode(institutions))) {
return Uni.createFrom()
.failure(
new InvalidRequestException(
String.format(
PNPG_INSTITUTION_REGISTRY_NOT_FOUND,
onboarding.getInstitution().getTaxCode())));
}
return Uni.createFrom().item(true);
}


private BusinessResource findByTaxCode(List<BusinessResource> businessResources) {
return businessResources.stream()
.filter(
businessResource ->
businessResource
.getBusinessTaxId()
.equals(onboarding.getInstitution().getTaxCode()))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RegistryManager<?> create(Onboarding onboarding) {
case PDND_INFOCAMERE -> new RegistryManagerPDNDInfocamere(onboarding, infocamerePdndApi);
case ANAC -> new RegistryManagerANAC(onboarding, stationsApi);
case IVASS -> new RegistryManagerIVASS(onboarding, insuranceCompaniesApi);
case INFOCAMERE -> new RegistryManagerInfocamere(onboarding, infocamereApi);
case INFOCAMERE -> new RegistryManagerInfocamere(onboarding, infocamereApi, userApi);
case ADE -> new RegistryManagerADE(onboarding, nationalRegistriesApi, userApi);
case IPA -> getResourceFromIPA(onboarding);
default -> getRegistryManagerSELC(onboarding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import static it.pagopa.selfcare.onboarding.service.OnboardingServiceDefault.USERS_FIELD_LIST;

import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.User;
import it.pagopa.selfcare.onboarding.entity.registry.BaseRegistryManager;
import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException;
import jakarta.ws.rs.WebApplicationException;
Expand Down Expand Up @@ -48,14 +46,8 @@ public Boolean retrieveInstitution() {
}

private String getManagerTaxCode() {
final String managerId =
onboarding.getUsers().stream()
.filter(user -> user.getRole().equals(PartyRole.MANAGER))
.map(User::getId)
.findFirst()
.orElse(null);
return userApi
.findByIdUsingGET(USERS_FIELD_LIST, managerId)
.findByIdUsingGET(USERS_FIELD_LIST, getManagerIdFromOnboarding())
.await()
.atMost(Duration.of(DURATION_TIMEOUT, ChronoUnit.SECONDS))
.getFiscalCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.onboarding.entity.registry.client;

import static it.pagopa.selfcare.onboarding.service.OnboardingServiceDefault.USERS_FIELD_LIST;

import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
Expand All @@ -12,14 +13,17 @@
import org.openapi.quarkus.party_registry_proxy_json.model.BusinessesResource;
import org.openapi.quarkus.party_registry_proxy_json.model.GetInstitutionsByLegalDto;
import org.openapi.quarkus.party_registry_proxy_json.model.GetInstitutionsByLegalFilterDto;
import org.openapi.quarkus.user_registry_json.api.UserApi;

public abstract class ClientRegistryInfocamere extends BaseRegistryManager<BusinessesResource> {

private final InfocamereApi client;
private final UserApi userApi;

protected ClientRegistryInfocamere(Onboarding onboarding, InfocamereApi client) {
protected ClientRegistryInfocamere(Onboarding onboarding, InfocamereApi client, UserApi userApi) {
super(onboarding);
this.client = client;
this.userApi = userApi;
}

public BusinessesResource retrieveInstitution() {
Expand All @@ -28,7 +32,7 @@ public BusinessesResource retrieveInstitution() {
GetInstitutionsByLegalDto.builder()
.filter(
GetInstitutionsByLegalFilterDto.builder()
.legalTaxId(onboarding.getInstitution().getTaxCode())
.legalTaxId(getManagerTaxCode())
.build())
.build())
.onFailure()
Expand All @@ -42,10 +46,18 @@ public BusinessesResource retrieveInstitution() {
.failure(
new ResourceNotFoundException(
String.format(
"Institution with taxCode %s not found",
"Institutions' list for user with taxCode %s not found",
onboarding.getInstitution().getTaxCode())))
: Uni.createFrom().failure(ex))
.await()
.atMost(Duration.of(DURATION_TIMEOUT, ChronoUnit.SECONDS));
}

private String getManagerTaxCode() {
return userApi
.findByIdUsingGET(USERS_FIELD_LIST, getManagerIdFromOnboarding())
.await()
.atMost(Duration.of(DURATION_TIMEOUT, ChronoUnit.SECONDS))
.getFiscalCode();
}
}

0 comments on commit 16ef2b6

Please sign in to comment.