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 Stringprotected final org.springframework.context.MessageSourceprotected final NotificationService<Notification>protected TenantProviderprotected final com.broadleafcommerce.common.extension.TypeFactoryprotected 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 NotificationbuildNotification(com.jayway.jsonpath.DocumentContext jsonContext) Build theNotificationfor the current message.protected NotificationbuildNotification(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.ContextInfobuildNotificationContext(com.jayway.jsonpath.DocumentContext jsonContext) Build theContextInfofor the current messageprotected abstract StringGet the class name to identify this listener for handling message idempotency.protected com.jayway.jsonpath.DocumentContextgetDocumentContext(@NonNull String payload) Parses the message payload into aDocumentContextwhich allows for JsonPath parsing using Jackson providers.protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionServiceprotected org.springframework.context.MessageSourceprotected abstract StringgetMessageType(com.jayway.jsonpath.DocumentContext jsonContext) Determine which message type should be sent.protected NotificationService<Notification>protected abstract StringgetNotificationSubject(com.jayway.jsonpath.DocumentContext jsonContext) Determine the subject to use for the email notification.protected com.fasterxml.jackson.databind.ObjectMapperprotected StringgetPayload(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 TenantProviderprotected com.broadleafcommerce.common.extension.TypeFactoryprotected UserResolverprotected voidhandleMessageInternal(org.springframework.messaging.Message<String> message) Message listener entry point.protected voidmodifyNotification(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 voidmodifyNotification(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 voidprocessMessage(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.voidsetTenantProvider(TenantProvider tenantProvider) voidsetUserResolver(UserResolver userResolver) protected abstract booleanvalidateShouldSendNotification(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 aDocumentContextwhich 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 theNotificationfor 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 theNotificationfor 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 theContextInfofor 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
OptionalofApplication
-
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
-