Sample JPO Code for Notification Attributes

When defining notification objects for subscription events, you can provide a JPO:method for many of the attributes.

This java program provides a sample JPO. Use the MQL insert program command to store code in the database.

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import matrix.db.Context;
import matrix.db.JPO;
import matrix.util.StringList;
// NotificationSample_mxJPO.java
//
// Created on May 23, 2006
//
// Copyright (c) 2005 MatrixOne Inc.
// All Rights Reserved
// This program contains proprietary and trade secret information of
// MatrixOne, Inc.  Copyright notice is precautionary only and does
// not evidence any actual or intended publication of such program.
//
/**
 * @author bucknam
 *
 * The <code>NotificationSample_mxJPO</code> class contains sample methods
 * which can be used as attributes of a Notification object.
 *
 * @version AEF 10.7.0.0 - Copyright (c) 2005, MatrixOne, Inc.
 */
public class NotificationSample_mxJPO {
/**
     * Default JPO constructor
     * @param context the eMatrix <code>Context</code> object
     * @param args a String array containing input arguments
     * 
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public NotificationSample_mxJPO(Context context, String[] args)
    throws Exception {
    }
    /**
     * This method is executed if a specific method is not specified.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds no arguments
     * @return an int 0, status code.
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public int mxMain(Context context, String[] args) throws Exception {
        if (true) {
            throw new Exception(
                    "must specify method on NotificationSample invocation");
        }
        return 0;
    }
/**
     * This method represents a filter.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return an int with 0 meaning let through
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static int evaluateFilter(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        
        //int results = 1; //to block
        int results = 0; // to pass
        
        return results;
    }
/**
     * This method generates a "from" user.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return a String of the user agent
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static String generateFromAgent(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        
        // String results = "User Agent";
        // Better to use symbolic notation...
        String results = "$<person_UserAgent>";
        
        return results;
    }
    /**
     * This method generates a StringList of recipients.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return a Stringlist of the given list of items
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static StringList generateRecipients(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        
        StringList results = new StringList(3);
        results.addElement("$<person_UserAgent>");
        results.addElement("$<person_TestEverything>");
        results.addElement("$<person_AdministrationUser>");
        
        return results;
    }
    /**
     * This method generates subject text.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return a String of the subject
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static String generateSubjectText(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        String fromAgent = (String) map.get("from");
        StringList replyTo = (StringList) map.get("replyTo");
        StringList objectIdList = (StringList) map.get("objectIdList");
        String basePropFile = (String) map.get("bundleName");
        String baseURL = (String) map.get("baseURL");
        String urlSuffix = (String) map.get("urlSuffix");
        Locale locale = (Locale) map.get("locale");
        String status = (String) map.get("status");
        StringList toList = (StringList) map.get("toList");
        StringList ccList = (StringList) map.get("ccList");
        StringList bccList = (StringList) map.get("bccList");
        
        String results = "This is a subject";
        
        return results;
    }
    /**
     * This method generates body text.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return a String of the message body
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static String generateBodyText(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        String fromAgent = (String) map.get("from");
        StringList replyTo = (StringList) map.get("replyTo");
        StringList objectIdList = (StringList) map.get("objectIdList");
        String basePropFile = (String) map.get("bundleName");
        String baseURL = (String) map.get("baseURL");
        String urlSuffix = (String) map.get("urlSuffix");
        Locale locale = (Locale) map.get("locale");
        String status = (String) map.get("status");
        StringList toList = (StringList) map.get("toList");
        StringList ccList = (StringList) map.get("ccList");
        StringList bccList = (StringList) map.get("bccList");
        
        String results = "This is a message \n Yes, it really is.";
        
        return results;
    }
    /**
     * This method generates body HTML text.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return a String of the message body in HTML format
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static String generateBodyHTML(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        String fromAgent = (String) map.get("from");
        StringList replyTo = (StringList) map.get("replyTo");
        StringList objectIdList = (StringList) map.get("objectIdList");
        String basePropFile = (String) map.get("bundleName");
        String baseURL = (String) map.get("baseURL");
        String urlSuffix = (String) map.get("urlSuffix");
        Locale locale = (Locale) map.get("locale");
        String status = (String) map.get("status");
        StringList toList = (StringList) map.get("toList");
        StringList ccList = (StringList) map.get("ccList");
        StringList bccList = (StringList) map.get("bccList");
        
        StringBuffer sb = new StringBuffer();
        sb.append("<HTML>\n");
        sb.append("<HEAD>\n");
        sb.append("<TITLE>\n");
        sb.append("Title Text\n");
        sb.append("</TITLE>\n");
        sb.append("</HEAD>\n");
        sb.append("<BODY>\n");
        sb.append("<H1>" + "Header Text" + "</H1>" + "\n");
        sb.append("This is an HTML message");
        sb.append("</BODY>\n");
        sb.append("</HTML>\n");
        String results = sb.toString();
        
        return results;
    }
    /**
     * This method modifies the given map.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args contains a Map with the following entries:
     *        id - a String holding the id of an object or relationship to be used for
     *          evaluating selects embedded in the subject and message strings
     *        idType - a String set to either "object" or "relationship"
     *        notificationName - a String holding the name of the Notification object
     *        payload - a Map containing information to pass on to helper JPO methods
     * @return an int with 0 meaning continue with sending mail
     * @throws Exception if the operation fails
     * @since AEF 10.7.0.0
     */
    public static Map preprocess(Context context, String[] args)
            throws Exception {
        if (args == null || args.length < 1) {
            throw (new IllegalArgumentException());
        }
        Map map = (Map) JPO.unpackArgs(args);
        String id = (String) map.get("id");
        String idType = (String) map.get("idType");
        String notificationName = (String) map.get("notificationName");
        Map payload = (Map) map.get("payload");
        String fromAgent = (String) map.get("from");
        StringList replyTo = (StringList) map.get("replyTo");
        StringList objectIdList = (StringList) map.get("objectIdList");
        String basePropFile = (String) map.get("bundleName");
        String baseURL = (String) map.get("baseURL");
        String urlSuffix = (String) map.get("urlSuffix");
        Locale locale = (Locale) map.get("locale");
        String status = (String) map.get("status");
        StringList toList = (StringList) map.get("toList");
        StringList ccList = (StringList) map.get("ccList");
        StringList bccList = (StringList) map.get("bccList");
        String subject = (String) map.get("subject");
        String messageText = (String) map.get("messageText");
        String messageHTML = (String) map.get("messageHTML");
        
        Map results = new HashMap();
        // Need only pass back those items used to formulate the email message
        results.put("from", fromAgent);
        results.put("replyTo", replyTo);
        results.put("toList", toList);
        results.put("ccList", ccList);
        results.put("bccList", bccList);
        results.put("subject", subject + " modified");
        results.put("messageText", messageText + " modified");
        results.put("messageHTML", messageHTML);
        
        //results.put("status", "Do Not Send"); //to block
        results.put("status", ""); // to pass
        
        return results;
    }
}