Skip to content

Commit

Permalink
logging onboarding service
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Feb 23, 2024
1 parent 1602cf2 commit d9d22fd
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.onboarding.service;

import io.quarkus.logging.Log;
import io.quarkus.mongodb.panache.common.reactive.Panache;
import io.quarkus.mongodb.panache.reactive.ReactivePanacheQuery;
import io.smallrye.mutiny.Multi;
Expand Down Expand Up @@ -38,6 +39,7 @@
import org.bson.Document;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.openapi.quarkus.core_json.api.OnboardingApi;
import org.openapi.quarkus.onboarding_functions_json.api.OrchestrationApi;
Expand All @@ -62,6 +64,8 @@

@ApplicationScoped
public class OnboardingServiceDefault implements OnboardingService {

private static final Logger LOG = Logger.getLogger(OnboardingServiceDefault.class);
protected static final String ATLEAST_ONE_PRODUCT_ROLE_REQUIRED = "At least one Product role related to %s Party role is required";
protected static final String MORE_THAN_ONE_PRODUCT_ROLE_AVAILABLE = "More than one Product role related to %s Party role is available. Cannot automatically set the Product role";
private static final String ONBOARDING_NOT_ALLOWED_ERROR_MESSAGE_TEMPLATE = "Institution with external id '%s' is not allowed to onboard '%s' product";
Expand Down Expand Up @@ -201,6 +205,12 @@ private Uni<Onboarding> persistOnboarding(Onboarding onboarding, List<UserReques
}

private Uni<Onboarding> addParentDescriptionForAooOrUo(Onboarding onboarding) {

Log.infof("Adding parent description AOO/UOO for: taxCode %s, subunitCode %s, type %s",
onboarding.getInstitution().getTaxCode(),
onboarding.getInstitution().getSubunitCode(),
onboarding.getInstitution().getInstitutionType());

if (InstitutionType.PA == onboarding.getInstitution().getInstitutionType()) {
if (InstitutionPaSubunitType.AOO == onboarding.getInstitution().getSubunitType()) {
return addParentDescriptionForAOO(onboarding);
Expand All @@ -213,6 +223,7 @@ private Uni<Onboarding> addParentDescriptionForAooOrUo(Onboarding onboarding) {

private Uni<Onboarding> addParentDescriptionForUO(Onboarding onboarding) {
return uoApi.findByUnicodeUsingGET1(onboarding.getInstitution().getSubunitCode(), null)
.onItem().invoke(uoResource -> LOG.infof("Founded parent %s for UO institution with subunitCode %s", uoResource.getDenominazioneEnte(), onboarding.getInstitution().getSubunitCode()))
.onItem().invoke(uoResource -> onboarding.getInstitution().setParentDescription(uoResource.getDenominazioneEnte()))
.onFailure(WebApplicationException.class).recoverWithUni(ex -> ((WebApplicationException) ex).getResponse().getStatus() == 404
? Uni.createFrom().failure(new ResourceNotFoundException(String.format(UO_NOT_FOUND.getMessage(), onboarding.getInstitution().getSubunitCode())))
Expand All @@ -223,6 +234,7 @@ private Uni<Onboarding> addParentDescriptionForUO(Onboarding onboarding) {

private Uni<Onboarding> addParentDescriptionForAOO(Onboarding onboarding) {
return aooApi.findByUnicodeUsingGET(onboarding.getInstitution().getSubunitCode(), null)
.onItem().invoke(aooResource -> LOG.infof("Founded parent %s for AOO institution with subunitCode %s", aooResource.getDenominazioneEnte(), onboarding.getInstitution().getSubunitCode()))
.onItem().invoke(aooResource -> onboarding.getInstitution().setParentDescription(aooResource.getDenominazioneEnte()))
.onFailure(WebApplicationException.class).recoverWithUni(ex -> ((WebApplicationException) ex).getResponse().getStatus() == 404
? Uni.createFrom().failure(new ResourceNotFoundException(String.format(AOO_NOT_FOUND.getMessage(), onboarding.getInstitution().getSubunitCode())))
Expand All @@ -234,6 +246,12 @@ public Uni<Onboarding> persistAndStartOrchestrationOnboarding(Onboarding onboard
final List<Onboarding> onboardings = new ArrayList<>();
onboardings.add(onboarding);

Log.infof("Persist onboarding and start orchestration %b for: taxCode %s, subunitCode %s, type %s",
onboardingOrchestrationEnabled,
onboarding.getInstitution().getTaxCode(),
onboarding.getInstitution().getSubunitCode(),
onboarding.getInstitution().getInstitutionType());

if (Boolean.TRUE.equals(onboardingOrchestrationEnabled)) {
return Onboarding.persistOrUpdate(onboardings)
.onItem().transformToUni(saved -> orchestration)
Expand Down Expand Up @@ -308,6 +326,11 @@ private Uni<Boolean> verifyAlreadyOnboardingForProductAndProductParent(String in

private Uni<Boolean> checkIfAlreadyOnboardingAndValidateAllowedMap(String productId, String institutionTaxCode, String institutionSubuniCode) {

Log.infof("Validating allowed map and verify an onboarding is present for: taxCode %s, subunitCode %s, product %s",
institutionTaxCode,
institutionSubuniCode,
productId);

if (!onboardingValidationStrategy.validate(productId, institutionTaxCode)) {
return Uni.createFrom().failure(new OnboardingNotAllowedException(String.format(ONBOARDING_NOT_ALLOWED_ERROR_MESSAGE_TEMPLATE,
institutionTaxCode,
Expand Down Expand Up @@ -361,6 +384,8 @@ private Uni<List<UserRequest>> validationRole(List<UserRequest> users) {

private Uni<List<User>> retrieveUserResources(List<UserRequest> users, Product product) {

Log.infof("Retrieving user resources for: product %s, product parent %s", product.getId(), product.getParentId());

Map<PartyRole, ProductRoleInfo> roleMappings = Objects.nonNull(product.getParent())
? product.getParent().getRoleMappings()
: product.getRoleMappings();
Expand Down Expand Up @@ -566,7 +591,7 @@ private Uni<String> uploadSignedContractAndUpdateToken(String onboardingId, File
return retrieveToken(onboardingId)
.onItem().transformToUni(token -> Uni.createFrom().item(Unchecked.supplier(() -> {
final String path = String.format("%s%s", pathContracts, onboardingId);
final String filename = String.format("signed_%s", token.getContractFilename());
final String filename = String.format("signed_%s", Optional.ofNullable(token.getContractFilename()).orElse(onboardingId));

try {
return azureBlobClient.uploadFile(path, filename, Files.readAllBytes(contract.toPath()));
Expand Down

0 comments on commit d9d22fd

Please sign in to comment.