diff --git a/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/UserInstitutionCdcService.java b/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/UserInstitutionCdcService.java index 12b05ee2..39f4b4ae 100644 --- a/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/UserInstitutionCdcService.java +++ b/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/UserInstitutionCdcService.java @@ -46,6 +46,7 @@ import static it.pagopa.selfcare.user.model.TrackEventInput.toTrackEventInput; import static it.pagopa.selfcare.user.model.constants.EventsMetric.*; import static it.pagopa.selfcare.user.model.constants.EventsName.EVENT_USER_CDC_NAME; +import static it.pagopa.selfcare.user.model.constants.EventsName.FD_EVENT_USER_CDC_NAME; import static java.util.Arrays.asList; @Startup @@ -256,18 +257,18 @@ public void consumerToSendUserEventForFD(ChangeStreamDocument d log.info("Sending message to EventHubFdRestClient ... "); return eventHubFdRestClient.sendMessage(fdUserNotificationToSend) .onFailure().retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofSeconds(retryMaxBackOff)).atMost(maxRetry) - .onItem().invoke(() -> telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInput(fdUserNotificationToSend)), Map.of(EVENTS_USER_INSTITUTION_PRODUCT_SUCCESS, 1D))) - .onFailure().invoke(() -> telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInput(fdUserNotificationToSend)), Map.of(EVENTS_USER_INSTITUTION_PRODUCT_FAILURE, 1D))); + .onItem().invoke(() -> telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInput(fdUserNotificationToSend)), Map.of(FD_EVENTS_USER_INSTITUTION_PRODUCT_SUCCESS, 1D))) + .onFailure().invoke(() -> telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInput(fdUserNotificationToSend)), Map.of(FD_EVENTS_USER_INSTITUTION_PRODUCT_FAILURE, 1D))); } )) .subscribe().with( result -> { log.info("SendFdEvents successfully performed from UserInstitution document having id: {}", document.getDocumentKey().toJson()); - telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInputByUserInstitution(userInstitutionChanged)), Map.of(EVENTS_USER_INSTITUTION_SUCCESS, 1D)); + telemetryClient.trackEvent(FD_EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInputByUserInstitution(userInstitutionChanged)), Map.of(FD_EVENTS_USER_INSTITUTION_SUCCESS, 1D)); }, failure -> { log.error("Error during SendFdEvents from UserInstitution document having id: {} , message: {}", document.getDocumentKey().toJson(), failure.getMessage()); - telemetryClient.trackEvent(EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInputByUserInstitution(userInstitutionChanged)), Map.of(EVENTS_USER_INSTITUTION_FAILURE, 1D)); + telemetryClient.trackEvent(FD_EVENT_USER_CDC_NAME, mapPropsForTrackEvent(toTrackEventInputByUserInstitution(userInstitutionChanged)), Map.of(FD_EVENTS_USER_INSTITUTION_FAILURE, 1D)); }); } } diff --git a/libs/user-sdk-event/src/test/java/it/pagopa/selfcare/user/FdUserNotificationToSendTest.java b/libs/user-sdk-event/src/test/java/it/pagopa/selfcare/user/FdUserNotificationToSendTest.java new file mode 100644 index 00000000..2937e266 --- /dev/null +++ b/libs/user-sdk-event/src/test/java/it/pagopa/selfcare/user/FdUserNotificationToSendTest.java @@ -0,0 +1,110 @@ +package it.pagopa.selfcare.user; + +import it.pagopa.selfcare.user.model.FdUserNotificationToSend; +import it.pagopa.selfcare.user.model.NotificationUserType; +import it.pagopa.selfcare.user.model.UserToNotify; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.time.OffsetDateTime; + +class FdUserNotificationToSendTest { + + @Test + void fdUserNotificationToSend_ACTIVE() { + FdUserNotificationToSend notification = new FdUserNotificationToSend(); + notification.setId("123"); + notification.setInstitutionId("inst-456"); + notification.setProduct("product-789"); + notification.setCreatedAt(OffsetDateTime.now().minusDays(1)); + notification.setUpdatedAt(OffsetDateTime.now()); + notification.setOnboardingTokenId("token-101112"); + notification.setType(NotificationUserType.ACTIVE_USER); + UserToNotify user = new UserToNotify(); + notification.setUser(user); + + assertEquals("123", notification.getId()); + assertEquals("inst-456", notification.getInstitutionId()); + assertEquals("product-789", notification.getProduct()); + assertNotNull(notification.getCreatedAt()); + assertNotNull(notification.getUpdatedAt()); + assertEquals("token-101112", notification.getOnboardingTokenId()); + assertEquals(NotificationUserType.ACTIVE_USER, notification.getType()); + assertEquals(user, notification.getUser()); + } + + @Test + void fdUserNotificationToSend_DELETE() { + FdUserNotificationToSend notification = new FdUserNotificationToSend(); + notification.setId("123"); + notification.setInstitutionId("inst-456"); + notification.setProduct("product-789"); + notification.setCreatedAt(OffsetDateTime.now().minusDays(1)); + notification.setUpdatedAt(OffsetDateTime.now()); + notification.setOnboardingTokenId("token-101112"); + notification.setType(NotificationUserType.DELETE_USER); + UserToNotify user = new UserToNotify(); + notification.setUser(user); + + assertEquals("123", notification.getId()); + assertEquals("inst-456", notification.getInstitutionId()); + assertEquals("product-789", notification.getProduct()); + assertNotNull(notification.getCreatedAt()); + assertNotNull(notification.getUpdatedAt()); + assertEquals("token-101112", notification.getOnboardingTokenId()); + assertEquals(NotificationUserType.DELETE_USER, notification.getType()); + assertEquals(user, notification.getUser()); + } + + @Test + void fdUserNotificationToSend_SUSPEND() { + FdUserNotificationToSend notification = new FdUserNotificationToSend(); + notification.setId("123"); + notification.setInstitutionId("inst-456"); + notification.setProduct("product-789"); + notification.setCreatedAt(OffsetDateTime.now().minusDays(1)); + notification.setUpdatedAt(OffsetDateTime.now()); + notification.setOnboardingTokenId("token-101112"); + notification.setType(NotificationUserType.SUSPEND_USER); + UserToNotify user = new UserToNotify(); + notification.setUser(user); + + assertEquals("123", notification.getId()); + assertEquals("inst-456", notification.getInstitutionId()); + assertEquals("product-789", notification.getProduct()); + assertNotNull(notification.getCreatedAt()); + assertNotNull(notification.getUpdatedAt()); + assertEquals("token-101112", notification.getOnboardingTokenId()); + assertEquals(NotificationUserType.SUSPEND_USER, notification.getType()); + assertEquals(user, notification.getUser()); + } + + @Test + void fdUserNotificationToSend_withNullFields_shouldHandleNullValues() { + FdUserNotificationToSend notification = new FdUserNotificationToSend(); + + assertNull(notification.getId()); + assertNull(notification.getInstitutionId()); + assertNull(notification.getProduct()); + assertNull(notification.getCreatedAt()); + assertNull(notification.getUpdatedAt()); + assertNull(notification.getOnboardingTokenId()); + assertNull(notification.getType()); + assertNull(notification.getUser()); + } + + @Test + void fdUserNotificationToSend_withPartialData_shouldSetFieldsCorrectly() { + FdUserNotificationToSend notification = new FdUserNotificationToSend(); + notification.setId("123"); + notification.setProduct("product-789"); + + assertEquals("123", notification.getId()); + assertNull(notification.getInstitutionId()); + assertEquals("product-789", notification.getProduct()); + assertNull(notification.getCreatedAt()); + assertNull(notification.getUpdatedAt()); + assertNull(notification.getOnboardingTokenId()); + assertNull(notification.getType()); + assertNull(notification.getUser()); + } +} diff --git a/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsMetric.java b/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsMetric.java index 01194e55..913ba15a 100644 --- a/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsMetric.java +++ b/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsMetric.java @@ -8,6 +8,11 @@ public class EventsMetric { public static final String EVENTS_USER_INSTITUTION_PRODUCT_FAILURE = "EventsUserInstitutionProduct_failures"; public static final String EVENTS_USER_INSTITUTION_PRODUCT_SUCCESS = "EventsUserInstitutionProduct_success"; + public static final String FD_EVENTS_USER_INSTITUTION_FAILURE = "EventsUserInstitution_failures"; + public static final String FD_EVENTS_USER_INSTITUTION_SUCCESS = "EventsUserInstitution_success"; + public static final String FD_EVENTS_USER_INSTITUTION_PRODUCT_FAILURE = "EventsUserInstitutionProduct_failures"; + public static final String FD_EVENTS_USER_INSTITUTION_PRODUCT_SUCCESS = "EventsUserInstitutionProduct_success"; + public static final String EVENTS_USER_GROUP_FAILURE = "EventsUserGroup_failures"; public static final String EVENTS_USER_GROUP_SUCCESS = "EventsUserGroup_success"; public static final String EVENTS_USER_GROUP_PRODUCT_FAILURE = "EventsUserGroupProduct_failures"; diff --git a/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsName.java b/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsName.java index 37a0a53f..820ae2aa 100644 --- a/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsName.java +++ b/libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/constants/EventsName.java @@ -4,5 +4,7 @@ public class EventsName { public static final String EVENT_USER_MS_NAME = "USER_MS"; public static final String EVENT_USER_CDC_NAME = "USER_CDC"; + + public static final String FD_EVENT_USER_CDC_NAME = "FD_USER_CDC"; public static final String EVENT_USER_GROUP_CDC_NAME = "USER_GROUP_CDC"; }