Class NotificationSenderService
java.lang.Object
es.kukenan.smartfi.microservice.communication.service.NotificationSenderService
Service class that holds all the notification sending bussiness logic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class is designed to hold all the required information to send a set of messages. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AuditServiceBackoffice endpoints implementation.private es.kukenan.smartfi.common.context.RequestContextManagerKukenbank request context manager.static final StringStatus description for a notification skipped due to user notifications disabled.private MessageChannelPriorityRepositoryMessage channel priority repository.Sms to slack flag.private NotificationProviderManagerNotification provider manager, used to find the implementation for message providers.private NotificationRequestBuilderNotification request factory, used to create notification requests for messages.private NotificationsRepositoryNotifications repository.private es.kukenan.smartfi.common.utils.CustomObjectMapperCustom object mapper to serialize/deserialize JSON.static final StringStatus description for a notification skipped due to destination not in white list.static final StringStatus description for a notification skipped due to user notifications disabled.private booleanSms to slack flag.private TemplatesRepositoryTemplates repository.private DestinationWhiteListComponentComponent used to filter destination using a white list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendUserVariables(Map<String, Object> variables, User user) Append template variables that are extracted from the user data.Check channel and typeId to apply conversion in message to standar GSM 7.private NotificationRequestcreateNotificationRequestWithWhiteListFilter(NotificationSenderService.MessageContext messageContext) CreateNotificationRequestto send applying the white list filter for the message.private voidhandleNotificationException(NotificationRequest notificationRequest, es.kukenan.smartfi.common.service.exceptions.KukenanWalletException ex, NotificationSenderService.MessageContext messageContext) Handle an error condition during a single notification request sending.private voidhandleNotificationException(NotificationRequest notificationRequest, es.kukenan.smartfi.common.service.exceptions.UnexpectedException ex, NotificationSenderService.MessageContext messageContext) Handle an error condition during a single notification request sending.private NotificationhandleNotificationResponse(NotificationResponse notificationResponse, Template template, NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext) Handles a notification response (after sending a notification).private Notificationprivate NotificationhandleNotificationSkippedDueWhiteList(NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext) private NotificationsendMessage(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event) Send a single message wrapped in the given context.private NotificationsendMessageByChannel(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event) Process the message for defined receiver by channel.private NotificationsendMessageForReceiver(NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event) Process the message by receivers.voidsendMessages(MessagesRequest messagesRequest, es.kukenan.smartfi.events.common.AbstractEvent<?> event) Send a set of messages for a single user, normally corresponding to the same context.private NotificationsendNotification(NotificationRequest notificationRequest, NotificationSenderService.MessageContext messageContext, es.kukenan.smartfi.events.common.AbstractEvent<?> event) Mail method to send a single notification to its destination.sendSingleMessage(MessagesRequest messagesRequest) Send a single message for a single user.private voidstoreNotificationError(NotificationRequest notificationRequest, es.kukenan.smartfi.common.api.dtos.error.ErrorSummaryDto errorSummary, NotificationSenderService.MessageContext messageContext) Handle an error condition during a single notification request sending.private StringtoStatusDescription(Object object) Extract an error description from the given kukenbank exception.
-
Field Details
-
STATUSDESC_USERNOTIFDISABLED
Status description for a notification skipped due to user notifications disabled.- See Also:
-
STATUSDESC_NOTINWHITELIST
Status description for a notification skipped due to destination not in white list.- See Also:
-
INVALIDINFORMATION_USERNOTIFDISABLED
Status description for a notification skipped due to user notifications disabled.- See Also:
-
switchSmsToSlack
@Value("${notifications.sms.switch.slack}") private boolean switchSmsToSlackSms to slack flag. -
messagesOnlyEmailByFlag
Sms to slack flag. -
notificationRequestFactory
Notification request factory, used to create notification requests for messages. -
notificationProviderManager
Notification provider manager, used to find the implementation for message providers. -
notificationsRepository
Notifications repository. -
templatesRepository
Templates repository. -
objectMapper
@Autowired private es.kukenan.smartfi.common.utils.CustomObjectMapper objectMapperCustom object mapper to serialize/deserialize JSON. -
whiteListComponent
Component used to filter destination using a white list. -
messageChannelPriorityRepository
Message channel priority repository. -
auditService
Backoffice endpoints implementation. -
contextManager
@Autowired private es.kukenan.smartfi.common.context.RequestContextManager contextManagerKukenbank 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 thatUnexpectedExceptionmay be thrown in case of error although some messages may be sent.- Parameters:
messagesRequest-MessagesRequest.event- abstract event object for extract audit info.
-
sendSingleMessage
Send a single message for a single user.UnexpectedExceptionwill 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 contextevent- 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 contextevent- 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) CreateNotificationRequestto 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
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
Extract an error description from the given kukenbank exception.- Parameters:
object- the object to convert in an status description.- Returns:
- a descriptive error.
-