From c28400777d76330a29ffa3f5854e8640e08e91f2 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Mon, 25 Nov 2024 11:09:05 +0100 Subject: [PATCH 1/8] Added unit tests for new workflow executor --- .../functions/OnboardingFunctions.java | 1 + .../WorkflowExecutorForApproveGpu.java | 45 +++++++++++++++++++ .../functions/OnboardingFunctionsTest.java | 43 +++++++++++++++++- .../onboarding/common/WorkflowType.java | 1 + 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index 4d2dc86e3..115b68e48 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -157,6 +157,7 @@ public void onboardingsOrchestrator( workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); case FOR_APPROVE_PT -> workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry); + case FOR_APPROVE_GPU -> workflowExecutor = new WorkflowExecutorForApproveGpu(objectMapper, optionsRetry); case CONFIRMATION -> workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry); case CONFIRMATION_AGGREGATE -> workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry); diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java new file mode 100644 index 000000000..1a14632f1 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java @@ -0,0 +1,45 @@ +package it.pagopa.selfcare.onboarding.workflow; + +import static it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowType.INSTITUTION; +import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.*; +import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY; +import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingString; +import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingWorkflowString; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.microsoft.durabletask.TaskOptions; +import com.microsoft.durabletask.TaskOrchestrationContext; +import it.pagopa.selfcare.onboarding.common.OnboardingStatus; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow; +import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowInstitution; +import java.util.Optional; + +public record WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions optionsRetry) implements WorkflowExecutor { + + @Override + public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { + String onboardingString = getOnboardingString(objectMapper, onboardingWorkflow.getOnboarding()); + ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); + return Optional.of(OnboardingStatus.TOBEVALIDATED); + } + + @Override + public Optional executeToBeValidatedState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { + String onboardingWorkflowString = getOnboardingWorkflowString(objectMapper, onboardingWorkflow); + ctx.callActivity(BUILD_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await(); + ctx.callActivity(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await(); + ctx.callActivity(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, onboardingWorkflowString, optionsRetry, String.class).await(); + return Optional.of(OnboardingStatus.PENDING); + } + + @Override + public Optional executePendingState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { + return onboardingCompletionActivity(ctx, onboardingWorkflow); + } + + @Override + public OnboardingWorkflow createOnboardingWorkflow(Onboarding onboarding) { + return new OnboardingWorkflowInstitution(onboarding, INSTITUTION.name()); + } +} diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index 18c8b9c61..cee377ff0 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -298,6 +298,26 @@ void onboardingsOrchestratorForApprove() { .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED); } + @Test + void onboardingsOrchestratorForApproveGpu() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.REQUEST); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(1)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(0)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED); + } + @Test void onboardingsOrchestratorForApproveWhenToBeValidated() { Onboarding onboarding = new Onboarding(); @@ -307,7 +327,6 @@ void onboardingsOrchestratorForApproveWhenToBeValidated() { TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); - function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); @@ -574,6 +593,28 @@ void onboardingsOrchestratorForApprovePtWhenToBeValidated() { .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED); } + @Test + void onboardingsOrchestratorForApproveGpuWhenToBeValidated() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.TOBEVALIDATED); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(3)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(0)); + assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); + assertEquals(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, captorActivity.getAllValues().get(2)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.PENDING); + } + TaskOrchestrationContext mockTaskOrchestrationContext(Onboarding onboarding) { TaskOrchestrationContext orchestrationContext = mock(TaskOrchestrationContext.class); when(orchestrationContext.getInput(String.class)).thenReturn(onboarding.getId()); diff --git a/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/WorkflowType.java b/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/WorkflowType.java index 7caf95509..80369b59f 100644 --- a/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/WorkflowType.java +++ b/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/WorkflowType.java @@ -5,6 +5,7 @@ public enum WorkflowType { CONTRACT_REGISTRATION,//INSTITUTION FOR_APPROVE,//INSTITUTION FOR_APPROVE_PT,//INSTITUTION + FOR_APPROVE_GPU,//INSTITUTION CONFIRMATION,//INSTITUTION USERS,//USER USERS_IMPORT,//USER From 6b6ab6ce174968d1ce18da7b61182293bdaa8250 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Mon, 25 Nov 2024 11:40:39 +0100 Subject: [PATCH 2/8] Updated references for onboarding-sdk to 0.5.1 --- apps/onboarding-functions/pom.xml | 2 +- apps/onboarding-ms/pom.xml | 2 +- apps/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/onboarding-functions/pom.xml b/apps/onboarding-functions/pom.xml index c641a17f5..77535ed3a 100644 --- a/apps/onboarding-functions/pom.xml +++ b/apps/onboarding-functions/pom.xml @@ -22,7 +22,7 @@ true 3.1.2 1.5.5.Final - 0.5.0 + 0.5.1 diff --git a/apps/onboarding-ms/pom.xml b/apps/onboarding-ms/pom.xml index 85f379c3f..b56e8b669 100644 --- a/apps/onboarding-ms/pom.xml +++ b/apps/onboarding-ms/pom.xml @@ -24,7 +24,7 @@ true 3.1.2 2.4.1 - 0.5.0 + 0.5.1 diff --git a/apps/pom.xml b/apps/pom.xml index a9228779a..f89743172 100644 --- a/apps/pom.xml +++ b/apps/pom.xml @@ -13,7 +13,7 @@ pom - 0.5.0 + 0.5.1 From 1f7af98cf70e0c8559bd85e7b9cd9cf957950278 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Wed, 27 Nov 2024 11:08:45 +0100 Subject: [PATCH 3/8] Updated unit tests --- .../functions/OnboardingFunctionsTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index cee377ff0..1d5301aa1 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -318,6 +318,31 @@ void onboardingsOrchestratorForApproveGpu() { .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED); } + @Test + void onboardingsOrchestratorForApproveGpuWhenIsPending() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.PENDING); + onboarding.setInstitution(new Institution()); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(5)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); + assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); + assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); + assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(3)); + assertEquals(SEND_MAIL_COMPLETION_ACTIVITY, captorActivity.getAllValues().get(4)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED); + } + @Test void onboardingsOrchestratorForApproveWhenToBeValidated() { Onboarding onboarding = new Onboarding(); From dbe94d554827df3e498f1e59f3ed0c6987d84452 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Wed, 27 Nov 2024 12:48:08 +0100 Subject: [PATCH 4/8] Updated workflow executor --- .../functions/OnboardingFunctions.java | 2 + .../WorkflowExecutorForApproveGpu.java | 1 + .../functions/OnboardingFunctionsTest.java | 68 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index b354904ed..f4bbe2bdf 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -201,6 +201,8 @@ public void onboardingsOrchestrator( workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); case FOR_APPROVE_PT -> workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry); + case FOR_APPROVE_GPU -> + workflowExecutor = new WorkflowExecutorForApproveGpu(objectMapper, optionsRetry); case CONFIRMATION -> workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry); case CONFIRMATION_AGGREGATE -> diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java index 1a14632f1..f3a4f8906 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java @@ -20,6 +20,7 @@ public record WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptio @Override public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { String onboardingString = getOnboardingString(objectMapper, onboardingWorkflow.getOnboarding()); + ctx.callActivity("BuildAttachmentsAndSaveTokens", onboardingString, optionsRetry, String.class).await(); ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); return Optional.of(OnboardingStatus.TOBEVALIDATED); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index c80f1806d..feab27d18 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -1142,6 +1142,74 @@ void onboardingOrchestratorUsersEaPending() { function.onboardingsOrchestrator(orchestrationContext, executionContext); } + @Test + void onboardingsOrchestratorForApproveGpu() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.REQUEST); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(2)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals("BuildAttachmentsAndSaveTokens", captorActivity.getAllValues().get(0)); + assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(1)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED); + } + + @Test + void onboardingsOrchestratorForApproveGpuWhenIsPending() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.PENDING); + onboarding.setInstitution(new Institution()); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(5)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); + assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); + assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2)); + assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(3)); + assertEquals(SEND_MAIL_COMPLETION_ACTIVITY, captorActivity.getAllValues().get(4)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED); + } + + @Test + void onboardingsOrchestratorForApproveGpuWhenToBeValidated() { + Onboarding onboarding = new Onboarding(); + onboarding.setId("onboardingId"); + onboarding.setStatus(OnboardingStatus.TOBEVALIDATED); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext, executionContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + verify(orchestrationContext, times(3)) + .callActivity(captorActivity.capture(), any(), any(), any()); + assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(0)); + assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); + assertEquals(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, captorActivity.getAllValues().get(2)); + + verify(service, times(1)) + .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.PENDING); + } + private Product createDummyProduct() { Product product = new Product(); product.setTitle("Title"); From 305567e10dd886a2cc9258f77fe921b595086d68 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Wed, 27 Nov 2024 14:46:19 +0100 Subject: [PATCH 5/8] Updated workflow executor gpu --- .../workflow/WorkflowExecutorForApprove.java | 20 ++++++++++- .../WorkflowExecutorForApproveGpu.java | 35 +++++-------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApprove.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApprove.java index 6c53420ac..db2093995 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApprove.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApprove.java @@ -15,7 +15,15 @@ import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingString; import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingWorkflowString; -public record WorkflowExecutorForApprove(ObjectMapper objectMapper, TaskOptions optionsRetry) implements WorkflowExecutor { +public class WorkflowExecutorForApprove implements WorkflowExecutor { + + private final ObjectMapper objectMapper; + private final TaskOptions optionsRetry; + + public WorkflowExecutorForApprove(ObjectMapper objectMapper, TaskOptions optionsRetry) { + this.objectMapper = objectMapper; + this.optionsRetry = optionsRetry; + } @Override public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { @@ -42,4 +50,14 @@ public Optional executePendingState(TaskOrchestrationContext c public OnboardingWorkflow createOnboardingWorkflow(Onboarding onboarding) { return new OnboardingWorkflowInstitution(onboarding, INSTITUTION.name()); } + + @Override + public ObjectMapper objectMapper() { + return objectMapper; + } + + @Override + public TaskOptions optionsRetry() { + return optionsRetry; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java index f3a4f8906..76d48cf79 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java @@ -1,46 +1,27 @@ package it.pagopa.selfcare.onboarding.workflow; -import static it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowType.INSTITUTION; import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.*; -import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY; import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingString; -import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingWorkflowString; import com.fasterxml.jackson.databind.ObjectMapper; import com.microsoft.durabletask.TaskOptions; import com.microsoft.durabletask.TaskOrchestrationContext; import it.pagopa.selfcare.onboarding.common.OnboardingStatus; -import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow; -import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowInstitution; import java.util.Optional; -public record WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions optionsRetry) implements WorkflowExecutor { +public class WorkflowExecutorForApproveGpu extends WorkflowExecutorForApprove { - @Override - public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { - String onboardingString = getOnboardingString(objectMapper, onboardingWorkflow.getOnboarding()); - ctx.callActivity("BuildAttachmentsAndSaveTokens", onboardingString, optionsRetry, String.class).await(); - ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); - return Optional.of(OnboardingStatus.TOBEVALIDATED); - } - - @Override - public Optional executeToBeValidatedState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { - String onboardingWorkflowString = getOnboardingWorkflowString(objectMapper, onboardingWorkflow); - ctx.callActivity(BUILD_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await(); - ctx.callActivity(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await(); - ctx.callActivity(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, onboardingWorkflowString, optionsRetry, String.class).await(); - return Optional.of(OnboardingStatus.PENDING); + public WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions optionsRetry) { + super(objectMapper, optionsRetry); } @Override - public Optional executePendingState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { - return onboardingCompletionActivity(ctx, onboardingWorkflow); + public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { + String onboardingString = getOnboardingString(super.objectMapper(), onboardingWorkflow.getOnboarding()); + ctx.callActivity("BuildAttachmentsAndSaveTokens", onboardingString, super.optionsRetry(), String.class).await(); + ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, super.optionsRetry(), String.class).await(); + return Optional.of(OnboardingStatus.TOBEVALIDATED); } - @Override - public OnboardingWorkflow createOnboardingWorkflow(Onboarding onboarding) { - return new OnboardingWorkflowInstitution(onboarding, INSTITUTION.name()); - } } From 4637b7bdb4a32c061e405dbd4bd81bfce150b236 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Wed, 27 Nov 2024 14:54:31 +0100 Subject: [PATCH 6/8] Removed unused method --- .../onboarding/functions/OnboardingFunctionsTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index feab27d18..1fc5c22ab 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -1241,12 +1241,4 @@ private static Map createDummyContractTemplateInstitut return institutionTemplate; } - private static Map createDummyContractTemplateUser() { - Map institutionTemplate = new HashMap<>(); - ContractTemplate conctractTemplate = new ContractTemplate(); - conctractTemplate.setContractTemplatePath("example"); - conctractTemplate.setContractTemplateVersion("version"); - institutionTemplate.put("default", conctractTemplate); - return institutionTemplate; - } } From 89c7d7967cc03d62a60ba5ead683552b610d0d69 Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Thu, 28 Nov 2024 12:50:53 +0100 Subject: [PATCH 7/8] Updated unit tests --- .../onboarding/functions/OnboardingFunctions.java | 4 ++-- .../onboarding/functions/utils/ActivityName.java | 1 + .../workflow/WorkflowExecutorForApproveGpu.java | 2 +- .../onboarding/functions/OnboardingFunctionsTest.java | 9 ++++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index f4bbe2bdf..ae30636da 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -256,7 +256,7 @@ public void buildContract( } /** This HTTP-triggered function invokes an orchestration to build attachments and save tokens */ - @FunctionName("BuildAttachmentsAndSaveTokens") + @FunctionName("TriggerBuildAttachmentsAndSaveTokens") public HttpResponseMessage buildAttachmentsAndSaveTokens( @HttpTrigger( name = "req", @@ -295,7 +295,7 @@ public HttpResponseMessage buildAttachmentsAndSaveTokens( * for invoking the activity function "BuildAttachment" and "saveTokenAttachment" until there are * no more attachment to process. */ - @FunctionName("BuildAttachmentAndSaveToken") + @FunctionName(BUILD_ATTACHMENTS_SAVE_TOKENS) public void buildAttachmentAndSaveToken( @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx, ExecutionContext functionContext) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java index bf8291a52..25a4502cd 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java @@ -3,6 +3,7 @@ public class ActivityName { public static final String SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME = "SaveTokenWithContract"; + public static final String BUILD_ATTACHMENTS_SAVE_TOKENS = "BuildAttachmentAndSaveTokens"; public static final String SAVE_TOKEN_WITH_ATTACHMENT_ACTIVITY_NAME = "SaveTokenWithAttachment"; public static final String BUILD_CONTRACT_ACTIVITY_NAME = "BuildContract"; public static final String BUILD_ATTACHMENT_ACTIVITY_NAME = "BuildAttachment"; diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java index 76d48cf79..e1474e0b5 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java @@ -19,7 +19,7 @@ public WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions opti @Override public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { String onboardingString = getOnboardingString(super.objectMapper(), onboardingWorkflow.getOnboarding()); - ctx.callActivity("BuildAttachmentsAndSaveTokens", onboardingString, super.optionsRetry(), String.class).await(); + ctx.callSubOrchestrator(BUILD_ATTACHMENTS_SAVE_TOKENS, onboardingString, String.class); ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, super.optionsRetry(), String.class).await(); return Optional.of(OnboardingStatus.TOBEVALIDATED); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index 1fc5c22ab..ae77bb038 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -1154,10 +1154,13 @@ void onboardingsOrchestratorForApproveGpu() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(2)) + verify(orchestrationContext, times(1)) .callActivity(captorActivity.capture(), any(), any(), any()); - assertEquals("BuildAttachmentsAndSaveTokens", captorActivity.getAllValues().get(0)); - assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(1)); + + assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(0)); + + Mockito.verify(orchestrationContext, times(1)) + .callSubOrchestrator(eq(BUILD_ATTACHMENTS_SAVE_TOKENS), any(), any()); verify(service, times(1)) .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED); From 564e2f69898bbc27689fb9d32674ace8fc4744ff Mon Sep 17 00:00:00 2001 From: "pierpaolo.didato@emeal.nttdata.com" Date: Thu, 28 Nov 2024 13:01:24 +0100 Subject: [PATCH 8/8] Updated variable name --- .../selfcare/onboarding/functions/OnboardingFunctions.java | 2 +- .../selfcare/onboarding/functions/utils/ActivityName.java | 2 +- .../onboarding/workflow/WorkflowExecutorForApproveGpu.java | 2 +- .../selfcare/onboarding/functions/OnboardingFunctionsTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index ae30636da..ecb395889 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -295,7 +295,7 @@ public HttpResponseMessage buildAttachmentsAndSaveTokens( * for invoking the activity function "BuildAttachment" and "saveTokenAttachment" until there are * no more attachment to process. */ - @FunctionName(BUILD_ATTACHMENTS_SAVE_TOKENS) + @FunctionName(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY) public void buildAttachmentAndSaveToken( @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx, ExecutionContext functionContext) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java index 25a4502cd..8b03f1358 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java @@ -3,7 +3,6 @@ public class ActivityName { public static final String SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME = "SaveTokenWithContract"; - public static final String BUILD_ATTACHMENTS_SAVE_TOKENS = "BuildAttachmentAndSaveTokens"; public static final String SAVE_TOKEN_WITH_ATTACHMENT_ACTIVITY_NAME = "SaveTokenWithAttachment"; public static final String BUILD_CONTRACT_ACTIVITY_NAME = "BuildContract"; public static final String BUILD_ATTACHMENT_ACTIVITY_NAME = "BuildAttachment"; @@ -33,6 +32,7 @@ public class ActivityName { public static final String EXISTS_DELEGATION_ACTIVITY = "ExistsDelegationActivity"; public static final String DELETE_MANAGERS_BY_IC_AND_ADE = "DeleteManagersByIcAndAde"; public static final String RETRIEVE_AGGREGATES_ACTIVITY = "RetrieveAggregates"; + public static final String BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY = "BuildAttachmentAndSaveTokens"; private ActivityName() {} } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java index e1474e0b5..fc6eccd20 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForApproveGpu.java @@ -19,7 +19,7 @@ public WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions opti @Override public Optional executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { String onboardingString = getOnboardingString(super.objectMapper(), onboardingWorkflow.getOnboarding()); - ctx.callSubOrchestrator(BUILD_ATTACHMENTS_SAVE_TOKENS, onboardingString, String.class); + ctx.callSubOrchestrator(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY, onboardingString, String.class); ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, super.optionsRetry(), String.class).await(); return Optional.of(OnboardingStatus.TOBEVALIDATED); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index ae77bb038..0e22cdb7b 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -1160,7 +1160,7 @@ void onboardingsOrchestratorForApproveGpu() { assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(0)); Mockito.verify(orchestrationContext, times(1)) - .callSubOrchestrator(eq(BUILD_ATTACHMENTS_SAVE_TOKENS), any(), any()); + .callSubOrchestrator(eq(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY), any(), any()); verify(service, times(1)) .updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED);