User's Manual

132 Chapter 11. Services Tutorials
System.out.println("object = " + object.getObject());
Iterator parents = object.getParentCategories().iterator();
while(parents.hasNext()) {
System.out.println("parent = " +
((Category) parents.next()).toString());
}
}
Example 11-6. Retrieving child objects of a given Category
11.3. Notification Tutorial
This section deals with several types of notification services you can create in WAF — simple notifi-
cation, notification with attachment, notification digest, and email alerts.
11.3.1. Creating a Simple Notification
A basic notification requires a sender, a receiver, a subject, and a body. All notifications require a
Message object to send, but in the case of a simple text message, an API allows you to provide the
relevant information and constructs a temporary Message object for you. By default, these notifica-
tions will be deleted after they are sent.
The following code fragment depicts the simplest case of sending a notification to a user:
User to = getRecipient();
User from = getSender();
Notification n = new Notification(to, from, "Subject", "Body");
n.save();
This notification will be sent to the user on the next run of SimpleQueueManager. to and from must
be persistent Parties in the database.
You can also create a notification and send it to a Group. When the notification is processed, it will
be sent to each individual User in the Group.
Group group = getTargetGroup();
User from = getSender();
Notification n = new Notification(group, from, "Subject", "Body");
n.setExpandGroup(Boolean.TRUE);
n.save();
Note that this option is turned on by default, so the call to setExpandGroup is not strictly necessary.
11.3.2. Creating a Simple Notification with an Attachment
For more complicated notifications, it is better to construct a separate Message object and then wrap
a notification around it for email delivery to a user. The following example shows how to construct
a multipart message with attachments, using both an HTML document fetched from a URL and a
simple text document constructed on the fly.
// Create a message for the body of the notification
User from = getSender();
Message msg = new Message(from, "subject", "See attachments");