Class NotificationSenderService

java.lang.Object
es.kukenan.smartfi.microservice.communication.service.NotificationSenderService

@Service public class NotificationSenderService extends Object
Service class that holds all the notification sending bussiness logic.
  • Field Details

    • STATUSDESC_USERNOTIFDISABLED

      public static final String STATUSDESC_USERNOTIFDISABLED
      Status description for a notification skipped due to user notifications disabled.
      See Also:
    • STATUSDESC_NOTINWHITELIST

      public static final String STATUSDESC_NOTINWHITELIST
      Status description for a notification skipped due to destination not in white list.
      See Also:
    • INVALIDINFORMATION_USERNOTIFDISABLED

      public static final String INVALIDINFORMATION_USERNOTIFDISABLED
      Status description for a notification skipped due to user notifications disabled.
      See Also:
    • switchSmsToSlack

      @Value("${notifications.sms.switch.slack}") private boolean switchSmsToSlack
      Sms to slack flag.
    • messagesOnlyEmailByFlag

      @Value("${messages.only.email.flag.smsforemail}") private List<Integer> messagesOnlyEmailByFlag
      Sms to slack flag.
    • notificationRequestFactory

      @Autowired private NotificationRequestBuilder notificationRequestFactory
      Notification request factory, used to create notification requests for messages.
    • notificationProviderManager

      @Autowired private NotificationProviderManager notificationProviderManager
      Notification provider manager, used to find the implementation for message providers.
    • notificationsRepository

      @Autowired private NotificationsRepository notificationsRepository
      Notifications repository.
    • templatesRepository

      @Autowired private TemplatesRepository templatesRepository
      Templates repository.
    • objectMapper

      @Autowired private es.kukenan.smartfi.common.utils.CustomObjectMapper objectMapper
      Custom object mapper to serialize/deserialize JSON.
    • whiteListComponent

      @Autowired private DestinationWhiteListComponent whiteListComponent
      Component used to filter destination using a white list.
    • messageChannelPriorityRepository

      @Autowired private MessageChannelPriorityRepository messageChannelPriorityRepository
      Message channel priority repository.
    • auditService

      @Autowired private AuditService auditService
      Backoffice endpoints implementation.
    • contextManager

      @Autowired private es.kukenan.smartfi.common.context.RequestContextManager contextManager
      Kukenbank request context manager.
  • Constructor Details

    • NotificationSenderService

      public NotificationSenderService()
  • Method Details

    • sendMessages

      public void sendMessages(MessagesRequest messagesRequest, es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Send a set of messages for a single user, normally corresponding to the same context. Remember that UnexpectedException may be thrown in case of error although some messages may be sent.
      Parameters:
      messagesRequest - MessagesRequest.
      event - abstract event object for extract audit info.
    • sendSingleMessage

      public Notification sendSingleMessage(MessagesRequest messagesRequest)
      Send a single message for a single user. UnexpectedException will be thrown in case of error and no notification sent. This methods always creates a new transaction, suspending the previous one (if any) until completed.
      Parameters:
      messagesRequest - MessagesRequest.
      Returns:
      notification sent. May be null if user notifications are disabled (or white list is enabled and user address is not present in it).
    • sendMessage

      private Notification sendMessage(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Send a single message wrapped in the given context.
      Parameters:
      messageContext - the message to sending context. At this point, it does not contain the templates.
      event - abstract event object for extract audit info.
      Returns:
      the notification if one has been sent. Otherwise, something went wrong.
    • sendMessageForReceiver

      private Notification sendMessageForReceiver(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Process the message by receivers.
      Parameters:
      messageContext - the message context
      event - abstract event object for extract audit info.
      Returns:
      the notification if one has been sent. Otherwise, something went wrong.
    • applyGsm7FormatForNotificationCreatedEvent

      private NotificationSenderService.MessageContext applyGsm7FormatForNotificationCreatedEvent(NotificationSenderService.MessageContext messageContext)
      Check channel and typeId to apply conversion in message to standar GSM 7.
      Parameters:
      messageContext - the message context.
      Returns:
      transform message context.
    • sendMessageByChannel

      private Notification sendMessageByChannel(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Process the message for defined receiver by channel.
      Parameters:
      messageContext - the message context
      event - abstract event object for extract audit info.
      Returns:
      the notification if one has been sent. Otherwise, something went wrong.
    • createNotificationRequestWithWhiteListFilter

      private NotificationRequest createNotificationRequestWithWhiteListFilter(NotificationSenderService.MessageContext messageContext)
      Create NotificationRequest to send applying the white list filter for the message.
      Parameters:
      messageContext - the full message to sending context (including templates).
      Returns:
      the notification request.
    • sendNotification

      private Notification sendNotification(NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event)
      Mail method to send a single notification to its destination.
      Parameters:
      notificationRequest - the notification to send.
      messageContext - the full message to sending context (including templates).
      event - abstract event object for extract audit info.
      Returns:
      the notification sent, if any. If no notification was sent, something went wrong.
    • handleNotificationResponse

      private Notification handleNotificationResponse(NotificationResponse notificationResponse, Template template, NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext)
      Handles a notification response (after sending a notification).
      Parameters:
      notificationResponse - the notification response.
      template - the template used to send the notification.
      notificationRequest - the notification request that was sent.
      messageContext - the full message to sending context (including templates).
      Returns:
      the notification sent, if any. If no notification was sent, something went wrong.
    • handleNotificationSkippedDueUserDisabled

      private Notification handleNotificationSkippedDueUserDisabled(NotificationSenderService.MessageContext messageContext)
    • handleNotificationSkippedDueWhiteList

      private Notification handleNotificationSkippedDueWhiteList(NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext)
    • appendUserVariables

      private void appendUserVariables(Map<String,Object> variables, User user)
      Append template variables that are extracted from the user data. Previous values wont be overwritten if the user object contains null values.
      Parameters:
      variables - existing variable map, it is updated with the variables extracted from the user data.
      user - the user data.
    • handleNotificationException

      private void handleNotificationException(NotificationRequest notificationRequest, es.kukenan.smartfi.common.service.exceptions.KukenanWalletException ex, NotificationSenderService.MessageContext messageContext)
      Handle an error condition during a single notification request sending.
      Parameters:
      notificationRequest - the notification request that caused the exception.
      ex - the exception thrown.
      messageContext - the full message to sending context (including templates).
    • handleNotificationException

      private void handleNotificationException(NotificationRequest notificationRequest, es.kukenan.smartfi.common.service.exceptions.UnexpectedException ex, NotificationSenderService.MessageContext messageContext)
      Handle an error condition during a single notification request sending.
      Parameters:
      notificationRequest - the notification request that caused the exception.
      ex - the exception thrown.
      messageContext - the full message to sending context (including templates).
    • storeNotificationError

      private void storeNotificationError(NotificationRequest notificationRequest, es.kukenan.smartfi.common.api.dtos.error.ErrorSummaryDto errorSummary, NotificationSenderService.MessageContext messageContext)
      Handle an error condition during a single notification request sending.
      Parameters:
      notificationRequest - the notification request that caused the exception.
      errorSummary - the error summary.
      messageContext - the full message to sending context (including templates).
    • toStatusDescription

      private String toStatusDescription(Object object)
      Extract an error description from the given kukenbank exception.
      Parameters:
      object - the object to convert in an status description.
      Returns:
      a descriptive error.