| java.lang.Object org.ofbiz.content.email.NotificationServices
NotificationServices | public class NotificationServices (Code) | | Provides generic services related to preparing and
delivering notifications via email.
To use the NotificationService, a message specific service should be
defined for a particular
Freemarker Template mapping the required fields of the
template to the required attributes of the service.
This service definition should extend the sendNotificationInterface
or the prepareNotificationInterface service interface
and simply invoke the associated method defined in this class.
<service name="sendPoPickupNotification" engine="java"
location="org.ofbiz.content.email.NotificationServices" invoke="sendNotification">
<description>Sends notification based on a message template</description>
<implements service="sendNotificationInterface"/>
<attribute name="orderId" type="String" mode="IN" optional="false"/>
</service>
An optional parameter available to all message templates is baseUrl
which can either be specified when the service is invoked or let the
NotificationService attempt to resolve it as best it can,
see
NotificationServices.setBaseUrl(GenericDelegator,String,Map) setBaseUrl(Map) for details on how this is achieved.
The following example shows what a simple notification message template,
associated with the above service, might contain:
Please use the following link to schedule a delivery date:
<p>
${baseUrl}/ordermgr/control/schedulepo?order_id=${orderId}"
The template file must be found on the classpath at runtime and
match the "templateName" field passed to the service when it
is invoked.
For complex messages with a large number of dynamic fields, it may be wise
to implement a custom service that takes one or two parameters that can
be used to resolve the rest of the required fields and then pass them to
the
NotificationServices.prepareNotification(DispatchContext,Map) prepareNotification(DispatchContext, Map) or
NotificationServices.sendNotification(DispatchContext,Map) sendNotification(DispatchContext, Map)
methods directly to generate or generate and send the notification respectively.
author: Tristan Austin author: Andy Zeneski version: $Revision: 1.5 $ since: 2.2 |
Method Summary | |
public static Map | prepareNotification(DispatchContext ctx, Map context) This will process the associated notification template definition
with all the fields contained in the given context and generate
the message body of the notification.
The result returned will contain the appropriate response
messages indicating succes or failure and the OUT parameter,
"body" containing the generated message.
Parameters: ctx - The dispatching context of the service Parameters: context - The map containing all the fields associated withthe sevice A new Map indicating success or error containing thebody generated from the template and the input parameters. | public static Map | sendNotification(DispatchContext ctx, Map context) This will use the
NotificationServices.prepareNotification(DispatchContext,Map) prepareNotification(DispatchContext, Map) method to generate the body of the notification message to send
and then deliver it via the "sendMail" service.
If the "body" parameter is already specified, the message body generation
phase will be skipped and the notification will be sent with the
specified body instead. | public static void | setBaseUrl(GenericDelegator delegator, String webSiteId, Map context) The expectation is that a lot of notification messages will include
a link back to one or more pages in the system, which will require knowledge
of the base URL to extrapolate. |
prepareNotification | public static Map prepareNotification(DispatchContext ctx, Map context)(Code) | | This will process the associated notification template definition
with all the fields contained in the given context and generate
the message body of the notification.
The result returned will contain the appropriate response
messages indicating succes or failure and the OUT parameter,
"body" containing the generated message.
Parameters: ctx - The dispatching context of the service Parameters: context - The map containing all the fields associated withthe sevice A new Map indicating success or error containing thebody generated from the template and the input parameters. |
sendNotification | public static Map sendNotification(DispatchContext ctx, Map context)(Code) | | This will use the
NotificationServices.prepareNotification(DispatchContext,Map) prepareNotification(DispatchContext, Map) method to generate the body of the notification message to send
and then deliver it via the "sendMail" service.
If the "body" parameter is already specified, the message body generation
phase will be skipped and the notification will be sent with the
specified body instead. This can be used to combine both service
calls in a decoupled manner if other steps are required between
generating the message body and sending the notification.
Parameters: ctx - The dispatching context of the service Parameters: context - The map containing all the fields associated withthe sevice A Map with the service response messages in it |
setBaseUrl | public static void setBaseUrl(GenericDelegator delegator, String webSiteId, Map context)(Code) | | The expectation is that a lot of notification messages will include
a link back to one or more pages in the system, which will require knowledge
of the base URL to extrapolate. This method will ensure that the
baseUrl field is set in the given context.
If it has been specified a default baseUrl will be
set using a best effort approach. If it is specified in the
url.properties configuration files of the system, that will be
used, otherwise it will attempt resolve the fully qualified
local host name.
Note: I thought it might be useful to have some dynamic way
of extending the default properties provided by the NotificationService,
such as the baseUrl , perhaps using the standard
ResourceBundle java approach so that both classes
and static files may be invoked.
Parameters: context - The context to check and, if necessary, set thebaseUrl . |
|
|