Skip to content

Commit

Permalink
feat: move check in RegistryManagerIPAUo
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcoplutino committed Jan 16, 2025
1 parent 63b3365 commit 23c2aa0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.exception.InvalidRequestException;
import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException;
import it.pagopa.selfcare.product.entity.Product;
import jakarta.ws.rs.WebApplicationException;
import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi;
import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi;
Expand All @@ -19,15 +18,12 @@
import java.time.temporal.ChronoUnit;
import java.util.Objects;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO_PREMIUM;
import static it.pagopa.selfcare.onboarding.service.OnboardingServiceDefault.GSP_CATEGORY_INSTITUTION_TYPE;

public class RegistryManagerIPA extends RegistryManagerIPAUo {

private static final String DESCRIPTION_TO_REPLACE_REGEX = " - COMUNE";

private static final String ALLOWED_PRICING_PLAN = "C0";

public RegistryManagerIPA(Onboarding onboarding, UoApi uoApi, InstitutionApi institutionApi, GeographicTaxonomiesApi geographicTaxonomiesApi) {
super(onboarding, uoApi, institutionApi, geographicTaxonomiesApi);
}
Expand All @@ -52,14 +48,6 @@ public Uni<Boolean> isValid() {
return Uni.createFrom().item(true);
}

@Override
public Uni<Onboarding> customValidation(Product product) {
if (PROD_IO_PREMIUM.getValue().equals(onboarding.getProductId()) &&
!ALLOWED_PRICING_PLAN.equals(onboarding.getPricingPlan())) {
return Uni.createFrom().failure(new InvalidRequestException(BaseRegistryManager.NOT_ALLOWED_PRICING_PLAN));
}
return Uni.createFrom().item(onboarding);
}

private boolean originIPA(Onboarding onboarding, InstitutionResource institutionResource) {
return onboarding.getInstitution().getDigitalAddress().equals(institutionResource.getDigitalAddress()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

import static it.pagopa.selfcare.onboarding.common.InstitutionPaSubunitType.UO;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_INTEROP;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO_PREMIUM;
import static it.pagopa.selfcare.onboarding.constants.CustomError.*;

public class RegistryManagerIPAUo extends ClientRegistryIPA {

private static final String ALLOWED_PRICING_PLAN = "C0";

public RegistryManagerIPAUo(Onboarding onboarding, UoApi uoApi, AooApi aooApi) {
super(onboarding, uoApi, aooApi);
}
Expand All @@ -41,6 +44,9 @@ public Uni<Onboarding> customValidation(Product product) {
if (!PROD_INTEROP.getValue().equals(onboarding.getProductId())
&& (Objects.isNull(onboarding.getBilling()) || Objects.isNull(onboarding.getBilling().getRecipientCode()))) {
return Uni.createFrom().failure(new InvalidRequestException(BILLING_OR_RECIPIENT_CODE_REQUIRED));
} else if (PROD_IO_PREMIUM.getValue().equals(onboarding.getProductId()) &&
!ALLOWED_PRICING_PLAN.equals(onboarding.getPricingPlan())) {
return Uni.createFrom().failure(new InvalidRequestException(BaseRegistryManager.NOT_ALLOWED_PRICING_PLAN));
}
return Uni.createFrom().item(onboarding);
}).onItem().transformToUni(unused -> billingChecks());
Expand Down Expand Up @@ -78,13 +84,13 @@ protected Uni<Void> checkRecipientCode() {
}

protected Uni<CustomError> validateRecipientCode(UOResource uoResource) {
if (Objects.nonNull(originIdEC) && !originIdEC.equals(uoResource.getCodiceIpa())) {
return Uni.createFrom().item(DENIED_NO_ASSOCIATION);
}
if (Objects.isNull(uoResource.getCodiceFiscaleSfe())) {
return Uni.createFrom().item(DENIED_NO_BILLING);
}
return Uni.createFrom().nullItem();
if (Objects.nonNull(originIdEC) && !originIdEC.equals(uoResource.getCodiceIpa())) {
return Uni.createFrom().item(DENIED_NO_ASSOCIATION);
}
if (Objects.isNull(uoResource.getCodiceFiscaleSfe())) {
return Uni.createFrom().item(DENIED_NO_BILLING);
}
return Uni.createFrom().nullItem();
}

protected boolean isInvoiceablePA(Onboarding onboarding) {
Expand Down Expand Up @@ -116,8 +122,7 @@ private Uni<Onboarding> checkTaxCodeInvoicing(Onboarding onboarding) {
.flatMap(uosResource -> {
/* if parent tax code is not into hierarchy, throw an exception */
if (Objects.nonNull(uosResource) && Objects.nonNull(uosResource.getItems())
&& uosResource.getItems().stream().anyMatch(uoResource -> !uoResource.getCodiceFiscaleEnte().equals(onboarding.getInstitution().getTaxCode())))
{
&& uosResource.getItems().stream().anyMatch(uoResource -> !uoResource.getCodiceFiscaleEnte().equals(onboarding.getInstitution().getTaxCode()))) {
return Uni.createFrom().failure(new InvalidRequestException(TAX_CODE_INVOICING_IS_INVALID));
}
return Uni.createFrom().item(onboarding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ void onboardingPa_allowedPricingPlan(UniAsserter asserter) {
institutionBaseRequest.setOrigin(Origin.IPA);
request.setInstitution(institutionBaseRequest);
request.setPricingPlan("C0");
Billing billing = new Billing();
billing.setRecipientCode("recCode");
request.setBilling(billing);

mockPersistOnboarding(asserter);
mockVerifyAllowedMap(request.getInstitution().getTaxCode(), request.getProductId(), asserter);
Expand All @@ -731,6 +734,11 @@ void onboardingPa_allowedPricingPlan(UniAsserter asserter) {
mockSimpleProductValidAssert(request.getProductId(), false, asserter);
mockVerifyOnboardingNotFound();

UOResource uoResource = new UOResource();
uoResource.setCodiceFiscaleSfe("codSfe");
uoResource.setCodiceIpa("originId");
when(uoApi.findByUnicodeUsingGET1("recCode", null)).thenReturn(Uni.createFrom().item(uoResource));

InstitutionResource institutionResource = new InstitutionResource();
institutionResource.setDescription("TEST");
institutionResource.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
Expand Down

0 comments on commit 23c2aa0

Please sign in to comment.