From d4c3668dffe915b517b2ea3021ae908ca067bd19 Mon Sep 17 00:00:00 2001 From: andrea-putzu <106688558+andrea-putzu@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:16:21 +0200 Subject: [PATCH] Merge back from hotfix send user fd notification (#559) Co-authored-by: empassaro --- .../dto/NotificationUserToSend.java | 120 +++++++++++++ .../onboarding/dto/NotificationUserType.java | 25 +++ .../onboarding/dto/QueueUserEvent.java | 9 + .../selfcare/onboarding/dto/UserToNotify.java | 38 ++++ .../functions/OnboardingFunctions.java | 23 ++- .../NotificationEventServiceDefault.java | 97 +++++++++- .../onboarding/utils/CustomMetricsConst.java | 1 + .../utils/FdNotificationBuilder.java | 38 +++- .../utils/NotificationUserBuilder.java | 19 ++ .../utils/NotificationUserBuilderFactory.java | 54 ++++++ .../utils/SapNotificationBuilder.java | 16 +- .../utils/StandardNotificationBuilder.java | 12 +- .../src/main/openapi/user.json | 1 - .../functions/OnboardingFunctionsTest.java | 70 ++++---- ...cationEventResenderServiceDefaultTest.java | 28 ++- .../NotificationEventServiceDefaultTest.java | 168 ++++++++++++++---- .../utils/FdNotificationBuilderTest.java | 112 +++++++++++- 17 files changed, 732 insertions(+), 99 deletions(-) create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java create mode 100644 apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java new file mode 100644 index 000000000..173ab2dbd --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserToSend.java @@ -0,0 +1,120 @@ +package it.pagopa.selfcare.onboarding.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import it.pagopa.selfcare.onboarding.utils.CustomOffsetDateTimeSerializer; + +import java.nio.file.Paths; +import java.time.OffsetDateTime; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class NotificationUserToSend { + + private String id; + private String institutionId; + private String product; + + private String onboardingTokenId; + + private String createdAt; + @JsonSerialize(using = CustomOffsetDateTimeSerializer.class) + private OffsetDateTime closedAt; + + private String updatedAt; + + private NotificationUserType type; + private UserToNotify user; + + + public String getInstitutionId() { + return institutionId; + } + + public void setInstitutionId(String institutionId) { + this.institutionId = institutionId; + } + + + public NotificationUserType getType() { + return type; + } + + public void setType(NotificationUserType type) { + this.type = type; + } + + + public String getOnboardingTokenId() { + return onboardingTokenId; + } + + public void setOnboardingTokenId(String onboardingTokenId) { + this.onboardingTokenId = onboardingTokenId; + } + + public OffsetDateTime getClosedAt() { + return closedAt; + } + + public void setClosedAt(OffsetDateTime closedAt) { + this.closedAt = closedAt; + } + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + public String getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + public UserToNotify getUser() { + return user; + } + + public void setUser(UserToNotify user) { + this.user = user; + } + + @Override + public String toString() { + return "NotificationToSend{" + + "id='" + id + '\'' + + ", institutionId='" + institutionId + '\'' + + ", product='" + product + '\'' + + ", onboardingTokenId='" + onboardingTokenId + '\'' + + ", createdAt=" + createdAt + + ", closedAt=" + closedAt + + ", updatedAt=" + updatedAt + + ", userId=" + user.getUserId() + + '}'; + } + +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java new file mode 100644 index 000000000..6d7c90212 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/NotificationUserType.java @@ -0,0 +1,25 @@ +package it.pagopa.selfcare.onboarding.dto; + +public enum NotificationUserType { + ADD_INSTITUTE(QueueUserEvent.ADD_INSTITUTE), + UPDATE_INSTITUTION(QueueUserEvent.UPDATE_INSTITUTION), + ACTIVE_USER(QueueUserEvent.ACTIVE_USER), + SUSPEND_USER(QueueUserEvent.SUSPEND_USER), + DELETE_USER(QueueUserEvent.DELETE_USER); + + + private final QueueUserEvent queueUserEvent; + + NotificationUserType(QueueUserEvent queueUserEvent) { + this.queueUserEvent = queueUserEvent; + } + + public static NotificationUserType getNotificationTypeFromQueueEvent(QueueUserEvent queueEvent) { + for (NotificationUserType notificationType : NotificationUserType.values()) { + if (notificationType.queueUserEvent == queueEvent) { + return notificationType; + } + } + return null; // Return null if no matching NotificationType is found + } +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java new file mode 100644 index 000000000..a9cea7683 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/QueueUserEvent.java @@ -0,0 +1,9 @@ +package it.pagopa.selfcare.onboarding.dto; + +public enum QueueUserEvent { + ADD_INSTITUTE, + UPDATE_INSTITUTION, + ACTIVE_USER, + SUSPEND_USER, + DELETE_USER +} \ No newline at end of file diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java new file mode 100644 index 000000000..cea745b85 --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/dto/UserToNotify.java @@ -0,0 +1,38 @@ +package it.pagopa.selfcare.onboarding.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import it.pagopa.selfcare.onboarding.common.PartyRole; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserToNotify { + + private String userId; + private String role; + private List roles; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } +} 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 9bc17708d..55a6ffe98 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 @@ -83,7 +83,7 @@ public HttpResponseMessage startOrchestration( try { /* if timeout is null, caller wants response asynchronously */ - if(Objects.isNull(timeoutString)) { + if (Objects.isNull(timeoutString)) { return durableContext.createCheckStatusResponse(request, instanceId); } @@ -94,11 +94,11 @@ public HttpResponseMessage startOrchestration( true); boolean isFailed = Optional.ofNullable(metadata) - .map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus()) ) + .map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus())) .orElse(true); return isFailed - ? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + ? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) .build() : request.createResponseBuilder(HttpStatus.OK) .build(); @@ -107,6 +107,7 @@ public HttpResponseMessage startOrchestration( return durableContext.createCheckStatusResponse(request, instanceId); } } + @FunctionName(ONBOARDINGS_AGGREGATE_ORCHESTRATOR) public void onboardingsAggregateOrchestrator( @DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx, @@ -115,7 +116,7 @@ public void onboardingsAggregateOrchestrator( try { String onboardingAggregate = ctx.getInput(String.class); boolean existsDelegation = Boolean.parseBoolean(ctx.callActivity(EXISTS_DELEGATION_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await()); - if(!existsDelegation) { + if (!existsDelegation) { onboardingId = ctx.callActivity(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await(); ctx.callSubOrchestrator("Onboardings", onboardingId, String.class).await(); } @@ -148,15 +149,19 @@ public void onboardingsOrchestrator( .orElseThrow(() -> new ResourceNotFoundException(String.format("Onboarding with id %s not found!", onboardingId))); switch (onboarding.getWorkflowType()) { - case CONTRACT_REGISTRATION -> workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry); - case CONTRACT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); - case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); + case CONTRACT_REGISTRATION -> + workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry); + case CONTRACT_REGISTRATION_AGGREGATOR -> + workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); + case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry); case FOR_APPROVE_PT -> workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry); case CONFIRMATION -> workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry); - case CONFIRMATION_AGGREGATE -> workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry); + case CONFIRMATION_AGGREGATE -> + workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry); case IMPORT -> workflowExecutor = new WorkflowExecutorImport(objectMapper, optionsRetry); case USERS -> workflowExecutor = new WorkflowExecutorForUsers(objectMapper, optionsRetry); - case INCREMENT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); + case INCREMENT_REGISTRATION_AGGREGATOR -> + workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper); case USERS_PG -> workflowExecutor = new WorkflowExecutorForUsersPg(objectMapper, optionsRetry); default -> throw new IllegalArgumentException("Workflow options not found!"); } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java index e6727ae16..108219f2a 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefault.java @@ -10,15 +10,14 @@ import it.pagopa.selfcare.onboarding.client.eventhub.EventHubRestClient; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.NotificationToSend; +import it.pagopa.selfcare.onboarding.dto.NotificationUserToSend; import it.pagopa.selfcare.onboarding.dto.NotificationsResources; import it.pagopa.selfcare.onboarding.dto.QueueEvent; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.Token; import it.pagopa.selfcare.onboarding.exception.NotificationException; import it.pagopa.selfcare.onboarding.repository.TokenRepository; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilder; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilderFactory; -import it.pagopa.selfcare.onboarding.utils.QueueEventExaminer; +import it.pagopa.selfcare.onboarding.utils.*; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.service.ProductService; import jakarta.enterprise.context.ApplicationScoped; @@ -28,6 +27,8 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; +import org.openapi.quarkus.user_json.model.OnboardedProductResponse; +import org.openapi.quarkus.user_json.model.UserDataResponse; import java.util.*; @@ -46,9 +47,14 @@ public class NotificationEventServiceDefault implements NotificationEventService @Inject InstitutionApi institutionApi; + @RestClient + @Inject + org.openapi.quarkus.user_json.api.UserApi userApi; + private final ProductService productService; private final NotificationConfig notificationConfig; private final NotificationBuilderFactory notificationBuilderFactory; + private final NotificationUserBuilderFactory notificationUserBuilderFactory; private final TokenRepository tokenRepository; private final ObjectMapper mapper; private final QueueEventExaminer queueEventExaminer; @@ -56,12 +62,14 @@ public class NotificationEventServiceDefault implements NotificationEventService public NotificationEventServiceDefault(ProductService productService, NotificationConfig notificationConfig, NotificationBuilderFactory notificationBuilderFactory, + NotificationUserBuilderFactory notificationUserBuilderFactory, TokenRepository tokenRepository, QueueEventExaminer queueEventExaminer, @Context @ConfigProperty(name = "onboarding-functions.appinsights.connection-string") String appInsightsConnectionString) { this.productService = productService; this.notificationConfig = notificationConfig; this.notificationBuilderFactory = notificationBuilderFactory; + this.notificationUserBuilderFactory = notificationUserBuilderFactory; this.tokenRepository = tokenRepository; this.queueEventExaminer = queueEventExaminer; TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.createDefault(); @@ -79,7 +87,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que @Override public void send(ExecutionContext context, Onboarding onboarding, QueueEvent queueEvent, String notificationEventTraceId) { context.getLogger().info(() -> String.format("Starting send method for onboarding with ID %s", onboarding.getId())); - if(isNotInstitutionOnboarding(onboarding)) { + if (isNotInstitutionOnboarding(onboarding)) { context.getLogger().info(() -> String.format("Onboarding with ID %s doesn't refer to an institution onboarding, skipping send notification", onboarding.getId())); return; } @@ -91,7 +99,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que return; } - if(Objects.isNull(queueEvent)) { + if (Objects.isNull(queueEvent)) { queueEvent = queueEventExaminer.determineEventType(onboarding); } @@ -103,6 +111,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que for (String consumer : product.getConsumers()) { NotificationConfig.Consumer consumerConfig = notificationConfig.consumers().get(consumer.toLowerCase()); prepareAndSendNotification(context, product, consumerConfig, notificationsResources, notificationEventTraceId); + prepareAndSendUserNotification(context, product, consumerConfig, notificationsResources, notificationEventTraceId); } } @@ -117,6 +126,50 @@ private void prepareAndSendNotification(ExecutionContext context, Product produc } } + private void prepareAndSendUserNotification(ExecutionContext context, Product product, NotificationConfig.Consumer consumer, NotificationsResources notificationsResources, String notificationEventTraceId) { + /*NotificationUserBuilder notificationUserBuilder = notificationUserBuilderFactory.create(consumer); + if (notificationUserBuilder.shouldSendUserNotification(notificationsResources.getOnboarding(), notificationsResources.getInstitution())) { + context.getLogger().info(() -> String.format("[APZ] prepareAndSendUserNotification %s [%s]", notificationsResources.getInstitution().getDescription(), consumer.topic())); + + notificationsResources.getOnboarding().getUsers().forEach(onboardingUser -> { + context.getLogger().info(() -> String.format("[APZ] onboardingUser %s [%s]", onboardingUser.getId(), consumer.topic())); + List users = userApi.usersUserIdInstitutionInstitutionIdGet(notificationsResources.getOnboarding().getInstitution().getId(), onboardingUser.getId(), onboardingUser.getId(), null, List.of(product.getId()), null, null); + users.forEach(userDataResponse -> { + context.getLogger().info(() -> String.format("[APZ] userDataResponse %s [%s]", userDataResponse.toString(), consumer.topic())); + userDataResponse.getProducts().forEach(onboardedProductResponse -> { + context.getLogger().info(() -> String.format("[APZ] onboardedProductResponse %s [%s]", onboardedProductResponse.toString(), consumer.topic())); + if (onboardedProductResponse.getProductId().equals(product.getId())) { + context.getLogger().info(() -> String.format("[APZ] getNotificationUserToSend %s [%s]", userDataResponse.getUserId(), consumer.topic())); + NotificationUserToSend notificationUserToSend = getNotificationUserToSend(notificationsResources, userDataResponse, onboardedProductResponse, notificationUserBuilder); + context.getLogger().info(() -> String.format("Sending user notification %s", notificationUserToSend.toString())); + sendUserNotification(context, consumer.topic(), notificationUserToSend, notificationEventTraceId); + } + }); + }); + }); + + + } else { + context.getLogger().info(() -> String.format("It was not necessary to send a notification on the topic %s because the onboarding with ID %s did not pass filter verification", notificationsResources.getOnboarding().getId(), consumer.topic())); + }*/ + } + + public static NotificationUserToSend getNotificationUserToSend(NotificationsResources notificationsResources, + UserDataResponse userDataResponse, + OnboardedProductResponse onboardedProductResponse, + NotificationUserBuilder notificationUserBuilder) { + return notificationUserBuilder.buildUserNotificationToSend( + notificationsResources.getOnboarding(), + notificationsResources.getToken(), + notificationsResources.getInstitution(), + onboardedProductResponse.getCreatedAt(), + onboardedProductResponse.getUpdatedAt(), + onboardedProductResponse.getStatus().toString(), + userDataResponse.getUserId(), + onboardedProductResponse.getRole(), + onboardedProductResponse.getProductRole()); + } + private void sendNotification(ExecutionContext context, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { String message = null; try { @@ -129,9 +182,24 @@ private void sendNotification(ExecutionContext context, String topic, Notificati } eventHubRestClient.sendMessage(topic, message); - telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); + telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationEventMap(notificationToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); } + /*private void sendUserNotification(ExecutionContext context, String topic, NotificationUserToSend notificationUserToSend, String notificationEventTraceId) { + String message = null; + try { + message = mapper.writeValueAsString(notificationUserToSend); + } catch (JsonProcessingException e) { + throw new NotificationException("Notification User cannot be serialized"); + } finally { + String finalMessage = message; + context.getLogger().info(() -> String.format("Sending notification user on topic: %s with message: %s", topic, finalMessage)); + } + + eventHubRestClient.sendMessage(topic, message); + telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, notificationUserEventMap(notificationUserToSend, topic, notificationEventTraceId), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS, 1D)); + }*/ + private void sendTestEnvProductsNotification(ExecutionContext context, Product product, String topic, NotificationToSend notificationToSend, String notificationEventTraceId) { context.getLogger().info(() -> String.format("Starting sendTestEnvProductsNotification with testEnv %s", product.getTestEnvProductIds())); if (product.getTestEnvProductIds() != null) { @@ -207,4 +275,21 @@ public static Map notificationEventMap(NotificationToSend notifi return propertiesMap; } + + public static Map notificationUserEventMap(NotificationUserToSend notificationUserToSend, String topic, String notificationEventTraceId) { + Map propertiesMap = new HashMap<>(); + Optional.ofNullable(topic).ifPresent(value -> propertiesMap.put("topic", value)); + Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put("notificationEventTraceId", value)); + Optional.ofNullable(notificationUserToSend.getId()).ifPresent(value -> propertiesMap.put("id", value)); + Optional.ofNullable(notificationUserToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value)); + Optional.ofNullable(notificationUserToSend.getProduct()).ifPresent(value -> propertiesMap.put("product", value)); + Optional.ofNullable(notificationUserToSend.getOnboardingTokenId()).ifPresent(value -> propertiesMap.put("onboardingTokenId", value)); + + if (Optional.ofNullable(notificationUserToSend.getUser()).isPresent()) { + Optional.ofNullable(notificationUserToSend.getUser().getUserId()).ifPresent(value -> propertiesMap.put("userId", value)); + Optional.ofNullable(notificationUserToSend.getUser().getRole()).ifPresent(value -> propertiesMap.put("role", value)); + //Optional.ofNullable(notificationUserToSend.getUser().getRoles()).ifPresent(value -> propertiesMap.put("roles", value.toString())); + } + return propertiesMap; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java index 270082f3a..3b7448263 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/CustomMetricsConst.java @@ -7,5 +7,6 @@ private CustomMetricsConst() { public static final String EVENT_ONBOARDING_FN_NAME = "ONBOARDING-FN"; public static final String EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE = "EventsOnboardingInstitution_failures"; public static final String EVENT_ONBOARDING_INSTTITUTION_FN_SUCCESS = "EventsOnboardingInstitution_success"; + public static final String EVENT_ONBOARDING_USER_FN_SUCCESS = "EventsOnboardingUser_success"; } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java index 0714a7ae2..a94bc8cb8 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -8,10 +9,12 @@ import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import java.time.OffsetDateTime; +import java.util.List; import java.util.Objects; import java.util.UUID; -public class FdNotificationBuilder extends BaseNotificationBuilder { +public class FdNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { public FdNotificationBuilder( String alternativeEmail, NotificationConfig.Consumer consumer, @@ -44,7 +47,7 @@ public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -52,4 +55,35 @@ public BillingToSend retrieveBilling(Onboarding onboarding) { billing.setPublicService(onboarding.getBilling().isPublicServices()); return billing; } + + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, + String createdAt, String updatedAt, String status, + String userId, String partyRole, String productRole) { + NotificationToSend notification = buildNotificationToSend(onboarding, token, institution, QueueEvent.UPDATE); + NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); + notificationUserToSend.setId(notification.getId()); + notificationUserToSend.setInstitutionId(notification.getInstitutionId()); + notificationUserToSend.setProduct(notification.getProduct()); + notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId()); + notificationUserToSend.setCreatedAt(createdAt.endsWith("Z") ? createdAt : createdAt + "Z"); + notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? createdAt : createdAt + "Z"); + QueueUserEvent queueUserEvent = switch (status) { + case "DELETE" -> QueueUserEvent.DELETE_USER; + case "SUSPEND" -> QueueUserEvent.SUSPEND_USER; + default -> QueueUserEvent.ACTIVE_USER; + }; + notificationUserToSend.setType(NotificationUserType.getNotificationTypeFromQueueEvent(queueUserEvent)); + UserToNotify user = new UserToNotify(); + user.setUserId(userId); + user.setRole(partyRole); + user.setRoles(List.of(productRole)); + notificationUserToSend.setUser(user); + return notificationUserToSend; + } + + @Override + public boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) { + return true; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java new file mode 100644 index 000000000..a3d1f7c8a --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilder.java @@ -0,0 +1,19 @@ +package it.pagopa.selfcare.onboarding.utils; + +import it.pagopa.selfcare.onboarding.common.PartyRole; +import it.pagopa.selfcare.onboarding.dto.NotificationUserToSend; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.entity.Token; +import org.openapi.quarkus.core_json.model.InstitutionResponse; + +import java.time.OffsetDateTime; + +public interface NotificationUserBuilder { + NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, + String createdAt, String updatedAt, String status, + String userId, String partyRole, String productRole); + + default boolean shouldSendUserNotification(Onboarding onboarding, InstitutionResponse institution) { + return false; + } +} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java new file mode 100644 index 000000000..b8a77a88e --- /dev/null +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/NotificationUserBuilderFactory.java @@ -0,0 +1,54 @@ +package it.pagopa.selfcare.onboarding.utils; + +import it.pagopa.selfcare.onboarding.config.NotificationConfig; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.openapi.quarkus.party_registry_proxy_json.api.AooApi; +import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; +import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import org.openapi.quarkus.party_registry_proxy_json.api.UoApi; + +import static it.pagopa.selfcare.onboarding.entity.Topic.*; + +@ApplicationScoped +public class NotificationUserBuilderFactory { + @Inject + @RestClient + InstitutionApi proxyRegistryInstitutionApi; + @Inject + @RestClient + GeographicTaxonomiesApi geographicTaxonomiesApi; + @Inject + @RestClient + org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; + private final String alternativeEmail; + @Inject + @RestClient + UoApi proxyRegistryUoApi; + @Inject + @RestClient + AooApi proxyRegistryAooApi; + + public NotificationUserBuilderFactory(@ConfigProperty(name = "onboarding-functions.sender-mail") String alternativeEmail) { + this.alternativeEmail = alternativeEmail; + } + + public NotificationUserBuilder create(NotificationConfig.Consumer consumer) { + + NotificationUserBuilder notificationUserBuilder; + if (SC_CONTRACTS_FD.getValue().equalsIgnoreCase(consumer.topic())) { + notificationUserBuilder = new FdNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + } else if (SC_CONTRACTS_SAP.getValue().equalsIgnoreCase(consumer.topic())) { + notificationUserBuilder = new SapNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi, proxyRegistryUoApi, proxyRegistryAooApi); + } else if (SC_CONTRACTS.getValue().equalsIgnoreCase(consumer.topic())) { + notificationUserBuilder = new StandardNotificationBuilder(this.alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); + } else { + throw new IllegalArgumentException("Topic not supported"); + } + + return notificationUserBuilder; + } + +} diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java index e73d36383..f7da85d81 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/SapNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.common.PricingPlan; import it.pagopa.selfcare.onboarding.common.ProductId; import it.pagopa.selfcare.onboarding.config.NotificationConfig; @@ -16,11 +17,12 @@ import org.openapi.quarkus.party_registry_proxy_json.model.InstitutionResource; import org.openapi.quarkus.party_registry_proxy_json.model.UOResource; +import java.time.OffsetDateTime; import java.util.Objects; import java.util.Set; import java.util.UUID; -public class SapNotificationBuilder extends BaseNotificationBuilder { +public class SapNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { private final UoApi proxyRegistryUoApi; private final AooApi proxyRegistryAooApi; @@ -37,6 +39,7 @@ public SapNotificationBuilder( this.proxyRegistryUoApi = proxyRegistryUoApi; this.proxyRegistryAooApi = proxyRegistryAooApi; } + @Override public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) { NotificationToSend notificationToSend = super.buildNotificationToSend(onboarding, token, institution, queueEvent); @@ -60,9 +63,10 @@ private static void setNotificationToSendInstitutionDescription(NotificationToSe + " - " + notificationToSend.getInstitution().getDescription()); } } + @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -70,6 +74,7 @@ public BillingToSend retrieveBilling(Onboarding onboarding) { billing.setPublicService(onboarding.getBilling().isPublicServices()); return billing; } + @Override public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) { InstitutionToNotify institutionToNotify = super.retrieveInstitution(institution); @@ -78,6 +83,7 @@ public InstitutionToNotify retrieveInstitution(InstitutionResponse institution) institutionToNotify.setCategory(null); return institutionToNotify; } + @Override public void retrieveAndSetGeographicData(InstitutionToNotify institutionToNotify) { GeographicTaxonomyResource geographicTaxonomies; @@ -111,6 +117,7 @@ public void retrieveAndSetGeographicData(InstitutionToNotify institutionToNotify institutionToNotify.setCity(geographicTaxonomies.getDesc().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); } } + @Override public boolean shouldSendNotification(Onboarding onboarding, InstitutionResponse institution) { return isProductAllowed(onboarding) && isAllowedInstitutionType(institution) && isAllowedOrigin(institution.getOrigin()); @@ -133,4 +140,9 @@ private boolean isAllowedOrigin(String origin) { private boolean isNullOrEmpty(Set set) { return Objects.isNull(set) || set.isEmpty(); } + + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole) { + return null; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java index 40d20c37a..f839fd05f 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/StandardNotificationBuilder.java @@ -1,5 +1,6 @@ package it.pagopa.selfcare.onboarding.utils; +import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.onboarding.config.NotificationConfig; import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -8,9 +9,10 @@ import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import java.time.OffsetDateTime; import java.util.Objects; -public class StandardNotificationBuilder extends BaseNotificationBuilder { +public class StandardNotificationBuilder extends BaseNotificationBuilder implements NotificationUserBuilder { public StandardNotificationBuilder( String alternativeEmail, NotificationConfig.Consumer consumer, @@ -20,6 +22,7 @@ public StandardNotificationBuilder( ) { super(alternativeEmail, consumer, proxyRegistryInstitutionApi, geographicTaxonomiesApi, coreInstitutionApi); } + @Override public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, QueueEvent queueEvent) { NotificationToSend notificationToSend = super.buildNotificationToSend(onboarding, token, institution, queueEvent); @@ -31,7 +34,7 @@ public NotificationToSend buildNotificationToSend(Onboarding onboarding, Token t @Override public BillingToSend retrieveBilling(Onboarding onboarding) { - if(Objects.isNull(onboarding.getBilling())) { + if (Objects.isNull(onboarding.getBilling())) { return null; } @@ -61,5 +64,8 @@ private void retrieveAndSetAggregatorInfo(Onboarding onboarding, NotificationToS } } - + @Override + public NotificationUserToSend buildUserNotificationToSend(Onboarding onboarding, Token token, InstitutionResponse institution, String createdAt, String updatedAt, String status, String userId, String partyRole, String productRole) { + return null; + } } diff --git a/apps/onboarding-functions/src/main/openapi/user.json b/apps/onboarding-functions/src/main/openapi/user.json index 4644cbf9a..53db2ad15 100644 --- a/apps/onboarding-functions/src/main/openapi/user.json +++ b/apps/onboarding-functions/src/main/openapi/user.json @@ -1388,7 +1388,6 @@ "type": "string" }, "LocalDateTime": { - "format": "date-time", "type": "string", "example": "2022-03-10T12:15:50" }, 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 8185220d0..aeda14cbd 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 @@ -69,8 +69,7 @@ class OnboardingFunctionsTest { @Test void startAndWaitOrchestration_failedOrchestration() throws Exception { // Setup - @SuppressWarnings("unchecked") - final HttpRequestMessage> req = mock(HttpRequestMessage.class); + @SuppressWarnings("unchecked") final HttpRequestMessage> req = mock(HttpRequestMessage.class); final Map queryParams = new HashMap<>(); final String onboardingId = "onboardingId"; @@ -152,7 +151,7 @@ void onboardingOrchestratorContractRegistrationAggregator() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_AGGREGATES_CSV_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(2)); @@ -186,7 +185,7 @@ void onboardingOrchestratorContractRegistrationAggregator_Pending() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); Mockito.verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .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)); @@ -204,7 +203,7 @@ void onboardingOrchestratorContractRegistrationAggregator_Pending() { } @Test - void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlreadyExists(){ + void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlreadyExists() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -226,7 +225,7 @@ void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationAlre } @Test - void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotExists(){ + void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotExists() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -251,9 +250,6 @@ void onboardingOrchestratorIncrementRegistrationAggregator_Pending_delgationNotE } - - - @Test void onboardingsOrchestratorNewAdminRequest() { Onboarding onboarding = new Onboarding(); @@ -311,7 +307,7 @@ void onboardingsOrchestratorForApproveWhenToBeValidated() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(3)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .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)); @@ -334,7 +330,7 @@ void onboardingsOrchestratorConfirmation() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .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)); @@ -361,7 +357,7 @@ void onboardingsOrchestratorConfirmationWithTestProductIds() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(8)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .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)); @@ -376,7 +372,7 @@ void onboardingsOrchestratorConfirmationWithTestProductIds() { } @Test - void onboardingOrchestratorConfirmAggregate(){ + void onboardingOrchestratorConfirmAggregate() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -390,7 +386,7 @@ void onboardingOrchestratorConfirmAggregate(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); Mockito.verify(orchestrationContext, times(6)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(CREATE_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -405,7 +401,7 @@ void onboardingOrchestratorConfirmAggregate(){ } @Test - void onboardingsAggregateOrchestrator(){ + void onboardingsAggregateOrchestrator() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -421,16 +417,17 @@ void onboardingsAggregateOrchestrator(){ function.onboardingsAggregateOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(2)) + .callActivity(captorActivity.capture(), any(), any(), any()); verify(orchestrationContext, times(1)) .callSubOrchestrator(eq("Onboardings"), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, captorActivity.getAllValues().get(1)); } + @Test - void onboardingsAggregateOrchestrator_resourceNotFound(){ + void onboardingsAggregateOrchestrator_resourceNotFound() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -448,14 +445,14 @@ void onboardingsAggregateOrchestrator_resourceNotFound(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); verify(service, times(1)).updateOnboardingStatusAndInstanceId(null, OnboardingStatus.FAILED, orchestrationContext.getInstanceId()); } @Test - void onboardingsAggregateOrchestrator_taskFailed(){ + void onboardingsAggregateOrchestrator_taskFailed() { Onboarding onboarding = new Onboarding(); onboarding.setId("onboardingId"); onboarding.setStatus(OnboardingStatus.PENDING); @@ -473,7 +470,7 @@ void onboardingsAggregateOrchestrator_taskFailed(){ ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(EXISTS_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(0)); verify(service, times(1)).updateOnboardingStatusAndInstanceId(null, OnboardingStatus.FAILED, orchestrationContext.getInstanceId()); @@ -495,7 +492,7 @@ void onboardingsOrchestratorImport() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .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)); @@ -520,7 +517,7 @@ void onboardingsOrchestratorNewAdmin() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(3)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(1)); assertEquals(SEND_MAIL_COMPLETION_ACTIVITY, captorActivity.getAllValues().get(2)); @@ -543,7 +540,7 @@ void onboardingsOrchestratorRegistrationRequestApprove() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(2)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(SEND_MAIL_REGISTRATION_REQUEST_ACTIVITY, captorActivity.getAllValues().get(0)); assertEquals(SEND_MAIL_REGISTRATION_APPROVE_ACTIVITY, captorActivity.getAllValues().get(1)); @@ -564,8 +561,8 @@ void onboardingsOrchestratorForApprovePtWhenToBeValidated() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(5)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(6)) + .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)); @@ -584,8 +581,8 @@ TaskOrchestrationContext mockTaskOrchestrationContext(Onboarding onboarding) { when(completionService.existsDelegation(any())).thenReturn("false"); Task task = mock(Task.class); - when(orchestrationContext.callActivity(any(),any(),any(),any())).thenReturn(task); - when(orchestrationContext.callSubOrchestrator(any(),any())).thenReturn(task); + when(orchestrationContext.callActivity(any(), any(), any(), any())).thenReturn(task); + when(orchestrationContext.callSubOrchestrator(any(), any())).thenReturn(task); when(task.await()).thenReturn("false"); when(orchestrationContext.allOf(anyList())).thenReturn(task); return orchestrationContext; @@ -598,8 +595,8 @@ TaskOrchestrationContext mockTaskOrchestrationContextForIncrementAggregator(Onbo when(completionService.existsDelegation(any())).thenReturn("true"); Task task = mock(Task.class); - when(orchestrationContext.callActivity(any(),any(),any(),any())).thenReturn(task); - when(orchestrationContext.callSubOrchestrator(any(),any())).thenReturn(task); + when(orchestrationContext.callActivity(any(), any(), any(), any())).thenReturn(task); + when(orchestrationContext.callSubOrchestrator(any(), any())).thenReturn(task); when(task.await()).thenReturn(returnValue); when(orchestrationContext.allOf(anyList())).thenReturn(task); return orchestrationContext; @@ -701,8 +698,8 @@ void onboardingCompletionOrchestrator() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(5)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(6)) + .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)); @@ -729,7 +726,7 @@ void onboardingRejectedOrchestrator() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(1)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(SEND_MAIL_REJECTION_ACTIVITY, captorActivity.getAllValues().get(0)); } @@ -747,8 +744,8 @@ void usersPgOrchestrator_whenStatusPending() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(4)) - .callActivity(captorActivity.capture(), any(), any(),any()); + verify(orchestrationContext, times(3)) + .callActivity(captorActivity.capture(), any(), any(), any()); assertEquals(DELETE_MANAGERS_BY_IC_AND_ADE, captorActivity.getAllValues().get(0)); assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(1)); assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(2)); @@ -769,7 +766,7 @@ void usersPgOrchestrator_whenStatusRequest() { ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); verify(orchestrationContext, times(0)) - .callActivity(captorActivity.capture(), any(), any(),any()); + .callActivity(captorActivity.capture(), any(), any(), any()); } @Test @@ -874,6 +871,7 @@ void createAggregateOnboardingRequest() { Mockito.verify(completionService, times(1)) .createAggregateOnboardingRequest(any()); } + @Test void createDelegationForAggregation() { final String onboardingString = "{\"onboardingId\":\"onboardingId\"}"; diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java index bdb5fe1a8..73047ddef 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventResenderServiceDefaultTest.java @@ -186,7 +186,7 @@ void resendNotificationsEndsWithMoreElementsToRetrieve() { private List getMockedList(int i) { List onboardings = new ArrayList<>(); - for(int j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { Onboarding onboarding = new Onboarding(); onboarding.setId("id" + j); onboarding.setStatus(OnboardingStatus.COMPLETED); @@ -196,4 +196,30 @@ private List getMockedList(int i) { return onboardings; } + + @Test + void resendNotifications_withUserNotification() { + /* Test that the resendNotifications method works correctly when there are two onboardings 1 COMPLETED (which should produce one notification) and 1 DELETED (which should produce two notifications) and no range is specified */ + // Arrange + ResendNotificationsFilters filters = ResendNotificationsFilters.builder().onboardingId("test").build(); + ExecutionContext context = getMockedContext(); + + Onboarding onboarding = new Onboarding(); + onboarding.setId("id1"); + onboarding.setStatus(OnboardingStatus.COMPLETED); + onboarding.setProductId("prod-fd"); + onboarding.setActivatedAt(LocalDateTime.of(2023, 2, 1, 0, 0)); + + + when(onboardingService.getOnboardingsToResend(filters, 0, 100)).thenReturn(List.of(onboarding)); + doNothing().when(notificationEventService).send(any(), any(), any(), any()); + + // Act + ResendNotificationsFilters resendNotificationsFilters = notificationEventResenderServiceDefault.resendNotifications(filters, context); + + // Assert + verify(notificationEventService, times(1)).send(any(), any(), any(), any()); + verify(onboardingService).getOnboardingsToResend(filters, 0, 100); + assertNull(resendNotificationsFilters); + } } \ No newline at end of file diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java index 6e70f01ea..12b1b1368 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationEventServiceDefaultTest.java @@ -8,15 +8,15 @@ import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.common.WorkflowType; import it.pagopa.selfcare.onboarding.dto.*; +import it.pagopa.selfcare.onboarding.dto.QueueEvent; +import it.pagopa.selfcare.onboarding.dto.UserToNotify; import it.pagopa.selfcare.onboarding.entity.Billing; import it.pagopa.selfcare.onboarding.entity.Institution; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.Token; import it.pagopa.selfcare.onboarding.exception.NotificationException; import it.pagopa.selfcare.onboarding.repository.TokenRepository; -import it.pagopa.selfcare.onboarding.utils.BaseNotificationBuilder; -import it.pagopa.selfcare.onboarding.utils.NotificationBuilderFactory; -import it.pagopa.selfcare.onboarding.utils.QueueEventExaminer; +import it.pagopa.selfcare.onboarding.utils.*; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.service.ProductService; import jakarta.inject.Inject; @@ -24,10 +24,9 @@ import org.junit.jupiter.api.Test; import org.openapi.quarkus.core_json.api.InstitutionApi; import org.openapi.quarkus.core_json.model.InstitutionResponse; +import org.openapi.quarkus.user_json.model.*; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.*; @@ -49,9 +48,16 @@ public class NotificationEventServiceDefaultTest { @InjectMock NotificationBuilderFactory notificationBuilderFactory; + @InjectMock + NotificationUserBuilderFactory notificationUserBuilderFactory; + @InjectMock TokenRepository tokenRepository; + @RestClient + @InjectMock + org.openapi.quarkus.user_json.api.UserApi userApi; + @RestClient @InjectMock InstitutionApi institutionApi; @@ -68,6 +74,9 @@ void sendMessage() { mockNotificationMapper(true); when(tokenRepository.findByOnboardingId(any())).thenReturn(Optional.of(new Token())); when(institutionApi.retrieveInstitutionByIdUsingGET(any())).thenReturn(new InstitutionResponse()); + List users = new ArrayList<>(); + when(userApi.usersUserIdInstitutionInstitutionIdGet(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(users); ExecutionContext context = mock(ExecutionContext.class); doReturn(Logger.getGlobal()).when(context).getLogger(); doNothing().when(eventHubRestClient).sendMessage(anyString(), anyString()); @@ -193,21 +202,27 @@ void sendMessageWontProceedsWhenOnboardingIsNotReferredToInstitution() { verifyNoInteractions(eventHubRestClient); } + @Test + void onboardingEventMapTest() { + final Onboarding onboarding = createOnboarding(); + onboarding.setId("ID"); + Map properties = NotificationEventServiceDefault.onboardingEventMap(onboarding); + assertNotNull(properties); + assertEquals("ID", properties.get("id")); + } + + @Test + void onboardingEventFailureMapTest() { + final Onboarding onboarding = createOnboarding(); + Map properties = NotificationEventServiceDefault.onboardingEventFailureMap(onboarding, new Exception()); + assertNotNull(properties); + } + @Test void notificationEventMapTest() { - NotificationToSend notificationToSend = new NotificationToSend(); - notificationToSend.setId("id"); - notificationToSend.setInternalIstitutionID("internal"); - notificationToSend.setProduct("prod"); - notificationToSend.setState("state"); - notificationToSend.setFileName("fileName"); - notificationToSend.setFilePath("filePath"); - notificationToSend.setContentType("contentType"); + NotificationToSend notificationToSend = getNotificationBaseToSend(); - InstitutionToNotify institution = new InstitutionToNotify(); - institution.setDescription("description"); - institution.setInstitutionType(InstitutionType.SA); - institution.setDigitalAddress("mail"); + InstitutionToNotify institution = getInstitutionToNotify(); notificationToSend.setInstitution(institution); BillingToSend billing = new BillingToSend(); @@ -236,19 +251,9 @@ void notificationEventMapTest() { @Test void notificationEventMapRootParentTest() { - NotificationToSend notificationToSend = new NotificationToSend(); - notificationToSend.setId("id"); - notificationToSend.setInternalIstitutionID("internal"); - notificationToSend.setProduct("prod"); - notificationToSend.setState("state"); - notificationToSend.setFileName("fileName"); - notificationToSend.setFilePath("filePath"); - notificationToSend.setContentType("contentType"); + NotificationToSend notificationToSend = getNotificationBaseToSend(); - InstitutionToNotify institution = new InstitutionToNotify(); - institution.setDescription("description"); - institution.setInstitutionType(InstitutionType.SA); - institution.setDigitalAddress("mail"); + InstitutionToNotify institution = getInstitutionToNotify(); RootParent rootParent = new RootParent(); rootParent.setDescription("RootDescription"); rootParent.setId("RootId"); @@ -339,4 +344,107 @@ private Product createProduct() { return product; } + + @Test + void notificationEventUserMapTest() { + NotificationUserToSend notificationUserToSend = getNotificationUserBaseToSend(); + UserToNotify user = new UserToNotify(); + user.setUserId("userId"); + user.setRole("OPERATOR"); + notificationUserToSend.setUser(user); + + Map properties = NotificationEventServiceDefault.notificationUserEventMap(notificationUserToSend, "topic", "traceId"); + assertNotNull(properties); + assertEquals("traceId", properties.get("notificationEventTraceId")); + assertEquals("id", properties.get("id")); + assertEquals("internal", properties.get("institutionId")); + assertEquals("prod", properties.get("product")); + + assertEquals("userId", properties.get("userId")); + assertEquals("OPERATOR", properties.get("role")); + } + + @Test + void getNotificationUserToSendTest() { + Onboarding onboarding = createOnboarding(); + InstitutionResponse institutionResponse = new InstitutionResponse(); + Token token = new Token(); + NotificationsResources notificationsResources = new NotificationsResources(onboarding, + institutionResponse, token, QueueEvent.ADD); + + OnboardedProductResponse onboardedProductResponse = new OnboardedProductResponse(); + onboardedProductResponse.productId("prod-fd-garantito"); + onboardedProductResponse.setEnv(Env.ROOT); + onboardedProductResponse.setStatus(OnboardedProductState.ACTIVE); + + + UserResponse userResponse = new UserResponse(); + userResponse.setId("userId"); + userResponse.setTaxCode("taxcode"); + userResponse.setName("Name"); + userResponse.setSurname("Surname"); + userResponse.setEmail("prv@email"); + HashMap workContacts = new HashMap(); + workContacts.put("email", "work@email"); + userResponse.setWorkContacts(workContacts); + + UserDataResponse userDataResponse = new UserDataResponse(); + userDataResponse.setId("userId"); + userDataResponse.institutionId("institutionId"); + userDataResponse.setInstitutionDescription("Institution Name"); + userDataResponse.setUserMailUuid("userMailId"); + userDataResponse.role("MANAGER"); + userDataResponse.setStatus("ADD"); + userDataResponse.setProducts(List.of(onboardedProductResponse)); + userDataResponse.setUserResponse(userResponse); + + NotificationUserToSend notificationUserToSendMock = new NotificationUserToSend(); + notificationUserToSendMock.setId("eventId"); + notificationUserToSendMock.setInstitutionId("institutionId"); + notificationUserToSendMock.setProduct("prod-fd-garantito"); + notificationUserToSendMock.setOnboardingTokenId("onboardingId"); + + FdNotificationBuilder fdNotificationBuilder = mock(FdNotificationBuilder.class); + when(notificationUserBuilderFactory.create(any())).thenReturn(fdNotificationBuilder); + when(fdNotificationBuilder.buildUserNotificationToSend(any(), any(), any(), any(), any(), any(), any(), + any(), any())).thenReturn(notificationUserToSendMock); + when(fdNotificationBuilder.shouldSendUserNotification(any(), any())).thenReturn(true); + doNothing().when(eventHubRestClient).sendMessage(anyString(), anyString()); + + + NotificationUserToSend notificationUserToSend = NotificationEventServiceDefault.getNotificationUserToSend(notificationsResources, userDataResponse, + onboardedProductResponse, fdNotificationBuilder); + + assertNotNull(notificationUserToSend); + } + + + private static InstitutionToNotify getInstitutionToNotify() { + InstitutionToNotify institution = new InstitutionToNotify(); + institution.setDescription("description"); + institution.setInstitutionType(InstitutionType.SA); + institution.setDigitalAddress("mail"); + return institution; + } + + private static NotificationToSend getNotificationBaseToSend() { + NotificationToSend notificationToSend = new NotificationToSend(); + notificationToSend.setId("id"); + notificationToSend.setInternalIstitutionID("internal"); + notificationToSend.setProduct("prod"); + notificationToSend.setState("state"); + notificationToSend.setFileName("fileName"); + notificationToSend.setFilePath("filePath"); + notificationToSend.setContentType("contentType"); + return notificationToSend; + } + + private static NotificationUserToSend getNotificationUserBaseToSend() { + NotificationUserToSend notificationUserToSend = new NotificationUserToSend(); + notificationUserToSend.setId("id"); + notificationUserToSend.setInstitutionId("internal"); + notificationUserToSend.setProduct("prod"); + return notificationUserToSend; + } + } \ No newline at end of file diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java index 9e51d7ce7..e50eaac23 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/FdNotificationBuilderTest.java @@ -4,8 +4,7 @@ import io.quarkus.test.junit.QuarkusTest; import it.pagopa.selfcare.onboarding.common.OnboardingStatus; import it.pagopa.selfcare.onboarding.config.NotificationConfig; -import it.pagopa.selfcare.onboarding.dto.NotificationToSend; -import it.pagopa.selfcare.onboarding.dto.NotificationType; +import it.pagopa.selfcare.onboarding.dto.*; import it.pagopa.selfcare.onboarding.dto.QueueEvent; import it.pagopa.selfcare.onboarding.entity.Billing; import it.pagopa.selfcare.onboarding.entity.Onboarding; @@ -16,8 +15,11 @@ import org.openapi.quarkus.core_json.model.InstitutionResponse; import org.openapi.quarkus.party_registry_proxy_json.api.GeographicTaxonomiesApi; import org.openapi.quarkus.party_registry_proxy_json.api.InstitutionApi; +import org.openapi.quarkus.user_json.model.*; import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; import static it.pagopa.selfcare.onboarding.entity.Topic.SC_CONTRACTS_FD; import static it.pagopa.selfcare.onboarding.utils.NotificationBuilderTestUtil.*; @@ -37,6 +39,9 @@ class FdNotificationBuilderTest { @InjectMock @RestClient org.openapi.quarkus.core_json.api.InstitutionApi coreInstitutionApi; + @RestClient + @InjectMock + org.openapi.quarkus.user_json.api.UserApi userApi; FdNotificationBuilder fdNotificationBuilder; @@ -51,13 +56,7 @@ public void setup() { void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventAdd() { // Create Onboarding - Onboarding onboarding = createOnboarding( - OnboardingStatus.COMPLETED, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt - OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt - null // deletedAt - ); + Onboarding onboarding = getOnboardingTest(); Billing billing = new Billing(); billing.setTaxCodeInvoicing("taxCodeInvoicing"); onboarding.setBilling(billing); @@ -88,4 +87,99 @@ void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventAdd() { assertEquals(onboarding.getBilling().isPublicServices(), notification.getBilling().isPublicService()); assertNull(notification.getFilePath()); } + + @Test + void toNotificationToSendWhenOnboardingHasActivatedAtAndQueueEventUserActive() { + + // Create Onboarding + Onboarding onboarding = getOnboardingTest(); + + Billing billing = new Billing(); + billing.setTaxCodeInvoicing("taxCodeInvoicing"); + onboarding.setBilling(billing); + + // Create Institution + InstitutionResponse institution = createInstitution(); + // Create Token + Token token = createToken(); + + InstitutionResponse institutionParentResource = new InstitutionResponse(); + institutionParentResource.setOriginId("parentOriginId"); + when(coreInstitutionApi.retrieveInstitutionByIdUsingGET(any())) + .thenReturn(institutionParentResource); + + OnboardedProductResponse productResponse = getOnboardedProductResponse(); + + UserResponse userResponse = new UserResponse(); + userResponse.id("userId1"); + + + UserDataResponse userDataResponse = getUserDataResponse(institution, productResponse, userResponse); + + List users = new ArrayList<>(); + users.add(userDataResponse); + + + when(userApi.usersUserIdInstitutionInstitutionIdGet(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(users); + + NotificationUserToSend notification = fdNotificationBuilder.buildUserNotificationToSend( + onboarding, + token, + institution, + productResponse.getCreatedAt(), + productResponse.getUpdatedAt(), + "ACTIVE", + userDataResponse.getUserId(), + productResponse.getRole(), + productResponse.getProductRole()); + + assertNotNull(notification); + assertNotEquals(onboarding.getId(), notification.getId()); + assertEquals(tokenId, notification.getOnboardingTokenId()); + assertEquals(productResponse.getCreatedAt(), notification.getCreatedAt()); + assertEquals(productResponse.getUpdatedAt(), notification.getUpdatedAt()); + assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); + assertEquals(productResponse.getRole(), notification.getUser().getRole()); + + assertTrue(notification.toString().contains("institutionId='" + notification.getInstitutionId() + "'")); + + } + + private static UserDataResponse getUserDataResponse(InstitutionResponse institution, OnboardedProductResponse productResponse, UserResponse userResponse) { + UserDataResponse userDataResponse = new UserDataResponse(); + userDataResponse.setId("userDataId1"); + userDataResponse.setUserId("userId1"); + userDataResponse.setInstitutionId(institution.getId()); + userDataResponse.setInstitutionDescription(institution.getDescription()); + userDataResponse.setUserMailUuid("usermail1"); + userDataResponse.setRole("OPERATOR"); + userDataResponse.setStatus("ACTIVE"); + userDataResponse.setProducts(List.of(productResponse)); + userDataResponse.setUserResponse(userResponse); + return userDataResponse; + } + + private static OnboardedProductResponse getOnboardedProductResponse() { + OnboardedProductResponse productResponse = new OnboardedProductResponse(); + productResponse.setProductId(productId); + productResponse.setStatus(OnboardedProductState.ACTIVE); + productResponse.setProductRole("security"); + productResponse.setRole("OPERATOR"); + productResponse.setEnv(Env.PROD); + productResponse.setCreatedAt("2024-10-10T10:35:42.144Z"); + productResponse.setUpdatedAt("2024-10-10T10:35:42.144Z"); + return productResponse; + } + + private static Onboarding getOnboardingTest() { + Onboarding onboarding = createOnboarding( + OnboardingStatus.COMPLETED, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + OffsetDateTime.parse("2020-11-02T10:02:00Z"), // activatedAt + OffsetDateTime.parse("2020-11-02T10:05:00Z"), // updatedAt + null // deletedAt + ); + return onboarding; + } } \ No newline at end of file