Skip to content

Commit

Permalink
[SELC-3883] refactor: replace start orchestrator complete when approv…
Browse files Browse the repository at this point in the history
…e or complete onboarding (#100)

* remove orchestrator complete

* fix issue cast
  • Loading branch information
manuraf authored Jan 22, 2024
1 parent 44d8bee commit 2bc1700
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.jboss.resteasy.reactive.ClientWebApplicationException;
import org.openapi.quarkus.core_json.api.OnboardingApi;
import org.openapi.quarkus.onboarding_functions_json.api.OrchestrationApi;
import org.openapi.quarkus.onboarding_functions_json.model.OrchestrationResponse;
import org.openapi.quarkus.party_registry_proxy_json.api.AooApi;
import org.openapi.quarkus.party_registry_proxy_json.api.UoApi;
import org.openapi.quarkus.user_registry_json.api.UserApi;
Expand All @@ -59,7 +58,6 @@
import java.time.OffsetDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_INTEROP;
Expand Down Expand Up @@ -422,21 +420,15 @@ private static boolean isFieldToUpdate(CertifiableFieldResourceOfstring certifie
@Override
public Uni<OnboardingGet> approve(String onboardingId) {

// If approve if for PT it must complete onboarding, otherwise continue to onboarding process
Function<WorkflowType, Supplier<Uni<OrchestrationResponse>>> approveFunction =
workflowType -> WorkflowType.FOR_APPROVE_PT.equals(workflowType)
? () -> orchestrationApi.apiStartOnboardingCompletionOrchestrationGet(onboardingId)
: () -> orchestrationApi.apiStartOnboardingOrchestrationGet(onboardingId);

return retrieveOnboardingAndCheckIfExpired(onboardingId)
.onItem().transformToUni(this::checkIfToBeValidated)
//Fail if onboarding exists for a product
.onItem().transformToUni(onboarding -> product(onboarding.getProductId())
.onItem().transformToUni(product -> verifyAlreadyOnboardingForProductAndProductParent(onboarding, product))
)
.onItem().transformToUni(onboarding -> onboardingOrchestrationEnabled
? approveFunction.apply(onboarding.getWorkflowType())
.get().map(ignore -> onboarding)
? orchestrationApi.apiStartOnboardingOrchestrationGet(onboardingId)
.map(ignore -> onboarding)
: Uni.createFrom().item(onboarding))
.map(onboardingMapper::toGetResponse);
}
Expand Down Expand Up @@ -482,7 +474,7 @@ private Uni<Onboarding> complete(String onboardingId, File contract, Function<On
.map(ignore -> onboarding))
// Start async activity if onboardingOrchestrationEnabled is true
.onItem().transformToUni(onboarding -> onboardingOrchestrationEnabled
? orchestrationApi.apiStartOnboardingCompletionOrchestrationGet(onboarding.getId().toHexString())
? orchestrationApi.apiStartOnboardingOrchestrationGet(onboarding.getId().toHexString())
.map(ignore -> onboarding)
: Uni.createFrom().item(onboarding));
}
Expand Down Expand Up @@ -513,7 +505,7 @@ private Uni<Onboarding> retrieveOnboardingAndCheckIfExpired(String onboardingId)
return Onboarding.findByIdOptional(new ObjectId(onboardingId))
.onItem().transformToUni(opt -> opt
//I must cast to Onboarding because findByIdOptional return a generic ReactiveEntity
.map(onboarding -> (Onboarding) onboarding)
.map(Onboarding.class::cast)
//Check if onboarding is expired
.filter(onboarding -> !isOnboardingExpired(onboarding.getExpiringDate()))
.map(onboarding -> Uni.createFrom().item(onboarding))
Expand Down Expand Up @@ -591,7 +583,7 @@ private List<OnboardingGet> convertOnboardingListToResponse(List<Onboarding> ite
public Uni<Long> rejectOnboarding(String onboardingId) {
return checkOnboardingIdFormat(onboardingId)
.onItem().transformToUni(ignore -> Onboarding.findById(new ObjectId(onboardingId))
.onItem().transform(onboarding -> (Onboarding) onboarding))
.onItem().transform(Onboarding.class::cast))
.onItem().transformToUni(onboardingGet -> OnboardingStatus.COMPLETED.equals(onboardingGet.getStatus())
? Uni.createFrom().failure(new InvalidRequestException(String.format("Onboarding with id %s is COMPLETED!", onboardingId)))
: Uni.createFrom().item(onboardingGet))
Expand Down Expand Up @@ -619,7 +611,7 @@ public Uni<OnboardingGet> onboardingGet(String onboardingId) {
return Onboarding.findByIdOptional(new ObjectId(onboardingId))
.onItem().transformToUni(opt -> opt
//I must cast to Onboarding because findByIdOptional return a generic ReactiveEntity
.map(onboarding -> (Onboarding) onboarding)
.map(Onboarding.class::cast)
.map(onboardingMapper::toGetResponse)
.map(onboardingGet -> Uni.createFrom().item(onboardingGet))
.orElse(Uni.createFrom().failure(new ResourceNotFoundException(String.format("Onboarding with id %s not found!",onboardingId)))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,6 @@ void approveCompletion() {
onboarding.getInstitution().getSubunitCode()))
.thenReturn(Uni.createFrom().failure(new ClientWebApplicationException(404)));

when(orchestrationApi.apiStartOnboardingCompletionOrchestrationGet(onboarding.getId().toHexString()))
.thenReturn(Uni.createFrom().item(new OrchestrationResponse()));

UniAssertSubscriber<OnboardingGet> subscriber = onboardingService
.approve(onboarding.getId().toHexString())
.subscribe()
Expand All @@ -1231,5 +1228,8 @@ void approveCompletion() {
OnboardingGet actual = subscriber.awaitItem().getItem();
Assertions.assertNotNull(actual);
Assertions.assertEquals(onboarding.getId().toHexString(), actual.getId());

verify(orchestrationApi, times(1))
.apiStartOnboardingOrchestrationGet(onboarding.getId().toHexString());
}
}

0 comments on commit 2bc1700

Please sign in to comment.