Class AbstractEmailNotificationMessageListener
java.lang.Object
com.broadleafcommerce.notification.service.messaging.AbstractEmailNotificationMessageListener
- Direct Known Subclasses:
AbstractNotificationFulfillmentStatusChangeMessageListener
,AbstractNotificationQuoteStatusChangedMessageListener
,AccountInviteAcceptanceMessageListener
,NotificationAccountInviteMessageListener
,NotificationAuthenticationMessageListener
,NotificationCartApprovalRequestListener
,NotificationCartAwaitingPaymentResultsListener
,NotificationCartPendingPaymentFailedListener
,NotificationCartRejectionMessageListener
,NotificationOrderConfirmationMessageListener
,PaymentGatewayCustomerNotificationListener
@DataRouteByKey("notification")
public abstract class AbstractEmailNotificationMessageListener
extends Object
Abstract message listener to help create notifications when events are received.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected final org.springframework.context.MessageSource
protected final NotificationService<Notification>
protected TenantProvider
protected final com.broadleafcommerce.common.extension.TypeFactory
protected UserResolver
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractEmailNotificationMessageListener
(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentConsumptionService, NotificationService<Notification> notificationService, org.springframework.context.MessageSource messages, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected Notification
buildNotification
(com.jayway.jsonpath.DocumentContext jsonContext) Build theNotification
for the current message.protected Notification
buildNotification
(String payload, com.jayway.jsonpath.DocumentContext jsonContext) Deprecated, for removal: This API element is subject to removal in a future version.protected abstract com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildNotificationContext
(com.jayway.jsonpath.DocumentContext jsonContext) Build theContextInfo
for the current messageprotected abstract String
Get the class name to identify this listener for handling message idempotency.protected com.jayway.jsonpath.DocumentContext
getDocumentContext
(@NonNull String payload) Parses the message payload into aDocumentContext
which allows for JsonPath parsing using Jackson providers.protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
protected org.springframework.context.MessageSource
protected abstract String
getMessageType
(com.jayway.jsonpath.DocumentContext jsonContext) Determine which message type should be sent.protected NotificationService<Notification>
protected abstract String
getNotificationSubject
(com.jayway.jsonpath.DocumentContext jsonContext) Determine the subject to use for the email notification.protected com.fasterxml.jackson.databind.ObjectMapper
protected String
getPayload
(org.springframework.messaging.Message<String> message) Get the message payload and customize it if needed.getRecipients
(com.jayway.jsonpath.DocumentContext jsonContext) Determine the recipients to use for the email notification.protected TenantProvider
protected com.broadleafcommerce.common.extension.TypeFactory
protected UserResolver
protected void
handleMessageInternal
(org.springframework.messaging.Message<String> message) Message listener entry point.protected void
modifyNotification
(Notification notification, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Deprecated, for removal: This API element is subject to removal in a future version.since 1.8.0.protected void
modifyNotification
(Notification notification, com.jayway.jsonpath.DocumentContext jsonContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Extension point to allow modifying the notification or context before sending to the notification serviceprotected void
processMessage
(org.springframework.messaging.Message<String> message) Processes the received message by extracting fields relevant to sending an email notification.protected Optional<com.broadleafcommerce.data.tracking.core.tenant.domain.Application>
resolveApplicationById
(@NonNull String applicationId) Resolves the application with the given application id.void
setTenantProvider
(TenantProvider tenantProvider) void
setUserResolver
(UserResolver userResolver) protected abstract boolean
validateShouldSendNotification
(com.jayway.jsonpath.DocumentContext jsonContext) Validate that the message state is valid to send the email.
-
Field Details
-
EMAIL_DELIVERY
- See Also:
-
notificationService
-
messages
protected final org.springframework.context.MessageSource messages -
userResolver
-
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory -
tenantProvider
-
-
Constructor Details
-
AbstractEmailNotificationMessageListener
public AbstractEmailNotificationMessageListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentConsumptionService, NotificationService<Notification> notificationService, org.springframework.context.MessageSource messages, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
handleMessageInternal
Message listener entry point. Checks if the message has already been received and, if not, begins processing it.- Parameters:
message
- the message payload
-
getClassName
Get the class name to identify this listener for handling message idempotency.- Returns:
- the listener's class name
-
processMessage
Processes the received message by extracting fields relevant to sending an email notification.- Parameters:
message
- the message payload
-
getPayload
Get the message payload and customize it if needed.- Parameters:
message
- the message payload- Returns:
- string version of the message payload
-
getDocumentContext
Parses the message payload into aDocumentContext
which allows for JsonPath parsing using Jackson providers.- Parameters:
payload
- the message payload- Returns:
- a
DocumentContext
` representation of the message payload
-
validateShouldSendNotification
protected abstract boolean validateShouldSendNotification(com.jayway.jsonpath.DocumentContext jsonContext) Validate that the message state is valid to send the email.- Parameters:
jsonContext
- the message payload- Returns:
- whether the email should be sent
-
buildNotification
@Deprecated(forRemoval=true, since="1.7.0") protected Notification buildNotification(String payload, com.jayway.jsonpath.DocumentContext jsonContext) Deprecated, for removal: This API element is subject to removal in a future version.Build theNotification
for the current message. This is deprecated in 1.7. Use buildNotification(DocumentContext jsonContext) instead. The payload String can be derived from the jsonContext with "jsonContext.jsonString()".- Parameters:
payload
- string version of the message payloadjsonContext
- the message payload- Returns:
- the Notification for the current message
- Since:
- 1.7. Use buildNotification(DocumentContext jsonContext) instead.
-
buildNotification
Build theNotification
for the current message.- Parameters:
jsonContext
- the message payload- Returns:
- the Notification for the current message
-
modifyNotification
@Deprecated(forRemoval=true, since="1.8.0") protected void modifyNotification(Notification notification, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Deprecated, for removal: This API element is subject to removal in a future version.since 1.8.0. UsemodifyNotification(Notification, DocumentContext, ContextInfo)
Extension point to allow modifying the notification or context before sending to the notification service- Parameters:
notification
- the Notification for the current messagecontext
- The context of the request
-
modifyNotification
protected void modifyNotification(Notification notification, com.jayway.jsonpath.DocumentContext jsonContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Extension point to allow modifying the notification or context before sending to the notification service- Parameters:
notification
- the Notification for the current messagejsonContext
- the message payloadcontext
- The context of the request
-
getMessageType
Determine which message type should be sent.- Parameters:
jsonContext
- the message payload- Returns:
- the message type to send
-
getNotificationSubject
Determine the subject to use for the email notification.- Parameters:
jsonContext
- the message payload- Returns:
- the subject to use for the email notification
-
getRecipients
Determine the recipients to use for the email notification.- Parameters:
jsonContext
- the message payload- Returns:
- the recipients to use for the email notification
-
buildNotificationContext
protected abstract com.broadleafcommerce.data.tracking.core.context.ContextInfo buildNotificationContext(com.jayway.jsonpath.DocumentContext jsonContext) Build theContextInfo
for the current message- Parameters:
jsonContext
- the payload of the message- Returns:
- the NotificationContext for the current message
-
resolveApplicationById
protected Optional<com.broadleafcommerce.data.tracking.core.tenant.domain.Application> resolveApplicationById(@NonNull @NonNull String applicationId) Resolves the application with the given application id.- Parameters:
applicationId
- the application id- Returns:
- an
Optional
ofApplication
-
getIdempotentConsumptionService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentConsumptionService() -
getNotificationService
-
getMessages
protected org.springframework.context.MessageSource getMessages() -
getUserResolver
-
setUserResolver
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getTenantProvider
-
setTenantProvider
-