Skip to content

Commit

Permalink
[SELC-5299] Trace with onboarding on catching exception (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu authored Jul 18, 2024
1 parent 99662b9 commit 523ed92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void send(ExecutionContext context, Onboarding onboarding, QueueEvent que
prepareAndSendNotification(context, product, consumerConfig, onboarding, token.orElse(null), institution, queueEvent);
}
} catch (Exception e) {
telemetryClient.trackEvent(EVENT_ONBOARDING_FN_NAME, onboardingEventMap(onboarding), Map.of(EVENT_ONBOARDING_INSTTITUTION_FN_FAILURE, 1D));
throw new NotificationException(String.format("Impossible to send notification for onboarding with ID %s", onboarding.getId()), e);
}
}
Expand Down Expand Up @@ -137,6 +138,12 @@ private void sendTestEnvProductsNotification(ExecutionContext context, Product p
}
}

public static Map<String, String> onboardingEventMap(Onboarding onboarding) {
Map<String, String> propertiesMap = new HashMap<>();
Optional.ofNullable(onboarding.getId()).ifPresent(value -> propertiesMap.put("id", value));
return propertiesMap;
}

public static Map<String, String> notificationEventMap(NotificationToSend notificationToSend) {
Map<String, String> propertiesMap = new HashMap<>();
Optional.ofNullable(notificationToSend.getId()).ifPresent(value -> propertiesMap.put("id", value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ public List<NotificationCountResult> countNotifications(String productId, String
}


public NotificationCountResult countNotificationsByFilters(String productId, String from, String to, ExecutionContext context) {
Document queryAddEvent = createQuery(productId, List.of(OnboardingStatus.COMPLETED, OnboardingStatus.DELETED), from, to, ACTIVATED_AT_FIELD);
Document queryUpdateEvent = createQuery(productId, List.of(OnboardingStatus.DELETED), from, to, DELETED_AT_FIELD);
public NotificationCountResult countNotificationsByFilters(String productId, String from, String to, ExecutionContext context) {Document queryAddEvent = getQueryNotificationAdd(productId, from, to);
Document queryUpdateEvent = getQueryNotificationDelete(productId, from, to);

long countAddEvents = repository.find(queryAddEvent).count();
long countUpdateEvents= repository.find(queryUpdateEvent).count();
Expand All @@ -277,6 +276,14 @@ public NotificationCountResult countNotificationsByFilters(String productId, Str
return new NotificationCountResult(productId, total);
}

private Document getQueryNotificationDelete(String productId, String from, String to) {
return createQuery(productId, List.of(OnboardingStatus.DELETED), from, to, DELETED_AT_FIELD);
}

private Document getQueryNotificationAdd(String productId, String from, String to) {
return createQuery(productId, List.of(OnboardingStatus.COMPLETED, OnboardingStatus.DELETED), from, to, ACTIVATED_AT_FIELD);
}

private Document createQuery(String productId, List<OnboardingStatus> status, String from, String to, String dateField, boolean workflowTypeExist) {
Document query = new Document();
query.append("productId", productId);
Expand Down

0 comments on commit 523ed92

Please sign in to comment.