Академический Документы
Профессиональный Документы
Культура Документы
** emxNotificationUtilBase
**
** Copyright (c) 1992-2012 Dassault Systemes.
** 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
**
*/
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Collections;
import com.matrixone.apps.domain.DomainConstants;
import com.matrixone.apps.domain.DomainObject;
import com.matrixone.apps.domain.util.FrameworkProperties;
import com.matrixone.apps.domain.util.MapList;
import com.matrixone.apps.domain.util.MessageUtil;
import com.matrixone.apps.domain.util.MqlUtil;
import com.matrixone.apps.domain.util.ContextUtil;
import com.matrixone.apps.domain.util.PersonUtil;
import com.matrixone.apps.domain.util.PropertyUtil;
import com.matrixone.apps.domain.util.i18nNow;
import com.matrixone.apps.domain.util.FrameworkException;
import com.matrixone.util.MxMessage;
import matrix.db.Attribute;
import matrix.db.AttributeList;
import matrix.db.AttributeType;
import matrix.db.BusinessObject;
import matrix.db.BusinessObjectList;
import matrix.db.BusinessObjectWithSelect;
import matrix.db.BusinessObjectWithSelectList;
import matrix.db.Context;
import matrix.db.IconMail;
import matrix.db.JPO;
import matrix.db.MatrixClassLoader;
import matrix.db.Query;
import matrix.db.Relationship;
import matrix.db.RelationshipType;
import matrix.db.RelationshipWithSelect;
import matrix.db.RelationshipWithSelectItr;
import matrix.db.RelationshipWithSelectList;
import matrix.util.MatrixException;
import matrix.util.StringItr;
import matrix.util.StringList;
import com.matrixone.apps.domain.util.FrameworkUtil;
import com.matrixone.apps.framework.ui.UIUtil;
import com.matrixone.jsystem.util.ExceptionUtils;
import com.matrixone.jsystem.util.StringUtils;
import matrix.db.QueryIterator;
/**
* The <code>emxNotificationUtilBase</code> class contains static methods for
sending email.
*
* @version AEF 10.0.0.0 - Copyright (c) 2005, MatrixOne, Inc.
*/
/** Create a static mapping from token type to end delimiter string.*/
private static final Map delimiters;
static {
Map m = new HashMap(2);
m.put(SELECT, END_SELECT);
m.put(MACRO, END_MACRO);
delimiters = Collections.unmodifiableMap(m);
}
/**
* Constructor.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds no arguments
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
synchronized(_lock)
{
if (_sl == null)
{
// Get admin names that are used in this program from
property names.
String[] s = new String[18];
s[0] = "type_Notification";
s[1] = "attribute_Filter";
s[2] = "attribute_FromAgent";
s[3] = "attribute_StaticToList";
s[4] = "attribute_StaticCcList";
s[5] = "attribute_StaticBccList";
s[6] = "attribute_DynamicToList";
s[7] = "attribute_DynamicCcList";
s[8] = "attribute_DynamicBccList";
s[9] = "attribute_SubjectText";
s[10] = "attribute_BodyText";
s[11] = "attribute_BodyHTML";
s[12] = "attribute_RegisteredSuite";
s[13] = "attribute_Attachments";
s[14] = "attribute_URLSuffix";
s[15] = "attribute_ReplyTo";
s[16] = "attribute_PreprocessJPO";
s[17] = "vault_eServiceAdministration";
_notificationType = (String)adminNames.get(0);
_adminVault = (String)adminNames.get(17);
// Get all the information about trigger objects found.
StringList sl = new StringList(17);
sl.addElement("current");
sl.addElement("attribute[" + (String)adminNames.get(1) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(2) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(3) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(4) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(5) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(6) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(7) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(8) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(9) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(10) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(11) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(12) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(13) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(14) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(15) +
"].value");
sl.addElement("attribute[" + (String)adminNames.get(16) +
"].value");
_sl = sl.unmodifiableCopy();
_vaultPattern = _adminVault;
if (_vaultPattern == null || _vaultPattern.length() == 0)
_vaultPattern = "*";
/**
* 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.0.0.0
*/
/**
* This method creates a mail notification based on an object id.
* Only use this method if invoking from beans.
*
* @param context the eMatrix <code>Context</code> object
* @param args contains a Map with the following entries:
* objectId - a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings
* 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 0 status code
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
objectNotification(context,
(String) map.get("objectId"),
(String) map.get("notificationName"),
(Map) map.get("payload"));
return 0;
}
/**
* This method creates a mail notification based on an object id.
* Only use this method if calling from triggers or tcl.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds the following input arguments:
* objectId - a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings
* notificationName - a String holding the name of the Notification
object
* @return an int 0 status code
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
/**
* This method creates a mail notification based on an object id.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
}
catch(Exception e)
{
throw e;
}
}
}
returnValue = Boolean.parseBoolean((String)
objectInformation.get(DomainConstants.SELECT_EXISTS));
}
catch(Exception e){}
return returnValue;
}
/**
* This method creates a mail notification based on a relationship id.
* Only use this method if invoking from beans.
*
* @param context the eMatrix <code>Context</code> object
* @param args contains a Map with the following entries:
* relId - a String holding the id of a relationship to be used for
* evaluating selects embedded in the subject and message strings
* 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 0 status code
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
public static int relationshipNotificationFromMap(Context context, String[]
args)
throws Exception {
relationshipNotification(context,
(String) map.get("relId"),
(String) map.get("notificationName"),
(Map) map.get("payload"));
return 0;
}
/**
* This method creates a mail notification based on a relationship id.
* Only use this method if calling from triggers or tcl.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds the following input arguments:
* relId - a String holding the id of a relationship to be used for
* evaluating selects embedded in the subject and message strings
* notificationName - a String holding the name of the Notification
object
* @return an int 0 status code
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
return 0;
}
/**
* This method creates a mail notification based on a relationship id.
*
* @param context the eMatrix <code>Context</code> object
* @param relId a String holding the id of a relationship to be used for
* evaluating selects embedded in the subject and message strings
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
public static void relationshipNotification(Context context,
String relId, String notificationName, Map payload)
throws Exception {
/**
* This method creates a mail notification based on a either an object or
relationship id.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be used
for
* evaluating selects embedded in the subject and message strings
* @param idType a String set to either "object" or "relationship"
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
notificationWithSelectList.addElement(qItr.next());
} finally {
qItr.close();
}
ContextUtil.commitTransaction(context);
}
catch(Exception ex)
{
ContextUtil.abortTransaction(context);
throw new Exception(ex.toString());
}
programMap.put(notificationName,
notificationWithSelectList);
ageMap.put(notificationName, new Long(time +
_componentAge));
}
}
value = bows.getSelectData((String)_sl.elementAt(2));
String fromAgent = inputOrJPOToString(context, id, idType,
notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(3));
StringList toList = inputListOrJPOToStringList(context, id,
idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(4));
StringList ccList = inputListOrJPOToStringList(context, id,
idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(5));
StringList bccList = inputListOrJPOToStringList(context,
id, idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(6));
StringList toSelectList =
inputListOrJPOToStringList(context, id, idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(7));
StringList ccSelectList =
inputListOrJPOToStringList(context, id, idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(8));
StringList bccSelectList =
inputListOrJPOToStringList(context, id, idType, notificationName, payload, value);
String subjectKey =
bows.getSelectData((String)_sl.elementAt(9));
String messageKey =
bows.getSelectData((String)_sl.elementAt(10));
String messageHTMLKey =
bows.getSelectData((String)_sl.elementAt(11));
String basePropFile =
bows.getSelectData((String)_sl.elementAt(12));
if (basePropFile != null && basePropFile.length() > 0) {
StringBuffer temp = new StringBuffer(_bundlePrefix);
temp.append(StringUtils.replaceAll(bows.getSelectData((String)_sl.elementAt(12)),
"\\\\s", ""));
temp.append(_bundleSuffix);
basePropFile = temp.toString();
}
value = bows.getSelectData((String)_sl.elementAt(13));
StringList idSelectList =
inputListOrJPOToStringList(context, id, idType, notificationName, payload, value);
value = bows.getSelectData((String)_sl.elementAt(14));
String urlSuffix = inputOrJPOToString(context, id, idType,
notificationName, payload, value);
StringList finalIdList =
combineStaticAndDynamicLists(context, id, idType, null, idSelectList, false);
finalToEmailList.addAll(finalToBothList);
finalToIconMailList.addAll(finalToBothList);
finalCcEmailList.addAll(finalCcBothList);
finalCcIconMailList.addAll(finalCcBothList);
finalBccEmailList.addAll(finalBccBothList);
finalBccIconMailList.addAll(finalBccBothList);
}
}
}
/**
* This method creates one or more mail notification based on an object id.
* The object id passed in will be expanded to get parent id's.
* The parent ids will be used to create mail notifications.
* Only use this method if calling from triggers or tcl.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds the following input arguments:
* objectId - id of an object that we want to expand. From this we
will
* check the ids from the expand to be used for
* evaluating selects embedded in the subject and message strings
* notificationName - a String holding the name of the Notification
object
* relationshipPattern - relationship to expand on
* typePattern - type to expand to
* toDirection - expand to direction
* fromDirection - expand from direction
* @return an int 0 status code
* @throws Exception if the operation fails
* @since AEF R211
*/
/**
* This method creates a mail notification for the specified users.
*
* @param context the eMatrix <code>Context</code> object
* @param args contains a Map with the following entries:
* objectId - a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings,
* and also to send with the notification
* toList - a StringList containing the list of users to notify
* ccList - a StringList containing the list of users to cc
* subjectKey - a String that contains the notification subject key
* messageKey - a String that contains the notification message key
* objectIdList - a StringList containing select clauses evaluated to
send objects with the notification
* basePropFileName - a String holding the property file to search for
keys
* toSelectList - a StringList containing select clauses evaluated to
expand the list of users to notify
* ccSelectList - a StringList containing select clauses evaluated to
expand the list of users to cc
* filter - a String holding an expression used to determine if the
notification should be sent
* urlSuffix - a String holding a suffix to be appended to the
embedded URL
* fromAgent - a String holding the from user appearing in the mail
* messageJPOMethod - a String holding the JPO name and method name
(colon delimited) used to append to the message
* filterJPOMethod - a String holding the JPO name and method name
(colon delimited) used to filter
* @return an int 0 status code
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
createNotification(context,
(String) map.get("objectId"),
(StringList) map.get("toList"),
(StringList) map.get("ccList"),
(String) map.get("subjectKey"),
(String) map.get("messageKey"),
(StringList) map.get("objectIdList"),
(String) map.get("basePropFileName"),
(StringList) map.get("toSelectList"),
(StringList) map.get("ccSelectList"),
(String) map.get("filter"),
(String) map.get("urlSuffix"),
(String) map.get("fromAgent"),
(String) map.get("messageJPOMethod"),
(String) map.get("filterJPOMethod"));
return 0;
}
/**
* This method creates a mail notification for the specified users.
* Only use this method if calling from triggers or tcl,
* otherwise use the method createNotificationFromMap().
*
* @param context the eMatrix <code>Context</code> object
* @param args holds the following input arguments:
* objectId - a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings,
* and also to send with the notification if no idSelectList given
* toList - a semicolon separated list of users to notify
* ccList - a semicolon separated list of users to cc
* subjectKey - a String that contains the notification subject key
* messageKey - a String that contains the notification message key
* basePropName - a String the property file to search for keys
* toSelectList - a semicolon separated list containing select clauses
evaluated to expand the list of users to notify
* ccSelectList - a semicolon separated list containing select clauses
evaluated to expand the list of users to cc
* filter - a String holding an expression used to determine if the
notification should be sent
* urlSuffix - a String holding a suffix to be appended to the
embedded URL
* fromAgent - a String holding the from user appearing in the mail
* idSelectList - a semicolon separated list containing select clauses
evaluated to send objects with the notification
* messageJPOMethod - a String holding the JPO name and method name
(colon delimited) used to append to the message
* filterJPOMethod - a String holding the JPO name and method name
(colon delimited) used to filter
* @return an int 0 status code
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
/**
* This method creates a mail notification for the specified users.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId a String holding the id of an object to be used for
* evaluating selects embedded in the subject and message strings,
* and also to send with the notification if no idSelectList given
* @param toList a StringList that contains the list of users to notify
* @param ccList a StringList that contains the list of users to cc
* @param subjectKey a String that contains the notification subject key
* @param messageKey a String that contains the notification message key
* @param idSelectList a StringList containing select clauses evaluated to
send objects with the notification
* @param basePropFile String that is used for the name of property files to
search for keys.
* @param toSelectList a StringList containing select clauses evaluated to
expand the list of users to notify
* @param ccSelectList a StringList containing select clauses evaluated to
expand the list of users to cc
* @param filter a String holding an expression used to determine if the
notification should be sent
* @param urlSuffix a String holding a suffix to be appended to the embedded
URL
* @param fromAgent a String holding the from user appearing in the mail
* @param messageJPOMethod a String holding the JPO name and method name
(colon delimited) used to append to the message
* @param filterJPOMethod a String holding the JPO name and method name
(colon delimited) used to filter
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
try {
} catch (Throwable e) {
System.out
.println("exception trying to invoke filter JPO method: "
+ e.toString());
}
if (status != 0) {
return;
}
}
return className;
}
/**
* This method sends a mail notification to the specified users.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId String contains id of the object used to evaluate embedded
select clauses
* in the subject and message
* @param toList StringList that contains the list of users to notify
* @param ccList StringList that contains the list of users to cc
* @param bccList StringList that contains the list of users to bcc
* @param subjectKey String that contains the notification subject key
* @param messageKey String that contains the notification message key
* @param objectIdList StringList that contains the ids of objects to send
with the notification
* @param basePropFile String that is used for the name of property files to
search for keys
* @param urlSuffix String that contains additional info to append to
embedded URLs
* @param fromAgent a String holding the from user appearing in the mail
* @param messageJPOMethod - a String holding the JPO name and method name
(colon delimited) used to append to the message
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context, names,
languages, toList);
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context, names,
languages, ccList);
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context, names,
languages, bccList);
if (language.length() > 0) {
locale = MessageUtil.getLocale(language);
}
message.append(urls);
if (messageJPOMethod != null
&& !"".equals(messageJPOMethod.trim())) {
String msg = "";
int index = messageJPOMethod.indexOf(":");
String methodName = "";
String name = "";
if (index >= 0) {
methodName = messageJPOMethod.substring(index+1);
name = messageJPOMethod.substring(0, index);
}
} catch (Exception e) {
System.out.println("exception trying to invoke
message JPO method: " + e.toString());
}
if (msg.trim().length()>0) {
message.append("\n");
message.append(msg);
}
}
/**
* This method sends a mail notification to the specified users.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be
* used for evaluating selects embedded in the subject and
* message strings
* @param idType a String set to either "object" or "relationship"
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @param toList StringList that contains the list of users to notify
* @param ccList StringList that contains the list of users to cc
* @param bccList StringList that contains the list of users to bcc
* @param subjectKey String that contains the notification subject key
* @param messageKey String that contains the notification message key
* @param messageHTMLKey a String that contains the notification HTML message
key
* @param objectIdList StringList that contains the ids of objects to send
with the notification
* @param basePropFile String that is used for the name of property files to
search for keys
* @param urlSuffix String that contains additional info to append to
embedded URLs
* @param fromAgent a String holding the from user appearing in the mail
* @param replyTo a StringList containing select clauses evaluated to fill
out
* the replyTo user and personal information
* @param preprocessJPOMethod a String holding the JPO name and method name
(colon delimited) used to append to the message
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
urlsBuffer.append("\n");
}
//Ended
}
// Added for bug 356405
else
{
urlsBuffer.append("\n");
if(!idType.equals("object"))
{
urlsBuffer.append("relationshipID=");
urlsBuffer.append(id);
}
urlsBuffer.append("\n");
}
//Ended
String urls = urlsBuffer.toString();
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context,
nameAndLanguage, languages, toList);
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context,
nameAndLanguage, languages, ccList);
${CLASS:emxMailUtil}.getNamesAndLanguagePreferences(context,
nameAndLanguage, languages, bccList);
if (language.length() > 0) {
locale = MessageUtil.getLocale(language);
}
info.put("locale", locale);
info.put("status", "");
info.put("toList", to);
info.put("ccList", cc);
info.put("bccList", bcc);
try
{
// Pack arguments into string array
String[] args = JPO.packArgs(info);
try {
to = (StringList) resultsMap.get("toList");
cc = (StringList) resultsMap.get("ccList");
bcc = (StringList) resultsMap.get("bccList");
subject = (String) resultsMap.get("subject");
messageText = (String)
resultsMap.get("messageText");
messageHTML = (String)
resultsMap.get("messageHTML");
objectIdList = (StringList)
resultsMap.get("objectIdList");
fromAgent = (String) resultsMap.get("from");
replyTo = (StringList)
resultsMap.get("replyTo");
} catch (Throwable e) {
System.out.println("Exception trying to invoke
method " + methodName +
" of JPO " + name + " ERROR: " +
e.toString());
}
} catch (Exception e) {
System.out.println("Exception trying to print program
" + name + " ERROR: " + e.toString());
}
/**
* This method returns all of the spools that the given notification object is
connected to.
*
* @param context the eMatrix <code>Context</code> object
* @param notificationName a String holding the name of the Notification object
* @return a MapList of spool object ids
* @throws Exception if the operation fails
* @since x+2
*/
return (spool);
}
/**
* This method spools a mail notification to the specified users. Sometime
later the
* spooled messages can be consolidated and sent.
*
* @param context the eMatrix <code>Context</code> object
* @param to StringList that contains the list of users to notify
* @param cc StringList that contains the list of users to cc
* @param bcc StringList that contains the list of users to bcc
* @param subject String that contains the notification subject
* @param messageText String that contains the notification message
* @param messageHTML a String that contains the notification HTML message
* @param fromAgent a String holding the from user appearing in the mail
* @param replyTo a StringList containing the replyTo user and personal
information
* @param objectIdList StringList that contains the ids of objects to send with
the notification
* @param notifyType Notification Type selected by user (email, iconmail, or
both)
* @param notificationName a String holding the name of the Notification object
* @throws Exception if the operation fails
* @since x+2
*/
}
return;
}
/**
* This method sends mail using the Java Mail API.
*
* @param context the eMatrix <code>Context</code> object
* @param toList StringList that contains the list of users to notify
* @param ccList StringList that contains the list of users to cc
* @param bccList StringList that contains the list of users to bcc
* @param subject String that contains the subject
* @param messageText String that contains the message in plain text
* @param messageHTML String that contains the message in HTML format
* @param fromAgent a String holding the from user appearing in the mail
* @param replyTo a StringList holding the replyTo user and personal info
appearing in the mail
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
/**
* This method sends mail using the Java Mail API.
*
* @param context the eMatrix <code>Context</code> object
* @param toList StringList that contains the list of users to notify
* @param ccList StringList that contains the list of users to cc
* @param bccList StringList that contains the list of users to bcc
* @param subject String that contains the subject
* @param messageText String that contains the message in plain text
* @param messageHTML String that contains the message in HTML format
* @param fromAgent a String holding the from user appearing in the mail
* @param replyTo a StringList holding the replyTo user and personal info
appearing in the mail
* @param notifyType Notification Type selected by user (email, iconmail, or
both)
* @throws Exception if the operation fails
* @since x+2
*/
msg.setSubject(subject);
if (messageText != null) {
msg.setMessage(messageText);
}
if (messageHTML != null) {
msg.setHtmlMessage(messageHTML);
}
if (toList != null) {
ArrayList to = new ArrayList();
to.addAll(toList);
msg.setToList(to);
}
if (ccList != null) {
ArrayList cc = new ArrayList();
cc.addAll(ccList);
msg.setCcList(cc);
}
if (bccList != null) {
ArrayList bcc = new ArrayList();
bcc.addAll(bccList);
msg.setBccList(bcc);
}
// IR-058366V6R2011x Commented here and declared at the begining
before try block -starts
// boolean isContextPushed = false;
// ${CLASS:emxContextUtil} utilityClass = new $
{CLASS:emxContextUtil}(context, null);
// IR-058366V6R2011x Commented here and declared at the begining
before try block -Ends
// Test if spoofing should be performed on the "from" field.
String agentName = fromAgent;
if (agentName == null || "".equals(agentName)) {
agentName = ${CLASS:emxMailUtil}.getAgentName(context,
null);
}
if (agentName != null && !"".equals(agentName)) {
try {
// Push Notification Agent
String[] pushArgs = { agentName };
utilityClass.pushContext(context, pushArgs);
isContextPushed = true;
try
{
//Send mail only using email
if(email.equalsIgnoreCase(notifyType) ||
both.equalsIgnoreCase(notifyType))
{
int emailStatus = msg.sendJavaMail(context, false);
}
}
catch(Exception ex)
{
System.out.println("Message: Please check SMTP settings for
sending an Email");
throw new FrameworkException(ex);
}
Iterator i = objectIdList.iterator();
while (i.hasNext()) {
String id = (String) i.next();
BusinessObject bo = new BusinessObject(id);
// Added the condition to check if the mail is
sending for relationship then not attaching the
// connection id
if(messageText.indexOf("relationshipID=") ==
-1)
{
bo.open(context);
bol.addElement(bo);
}
bo.open(context);
bol.addElement(bo);
}
iconMail.setObjects(bol);
}
iconMail.send(context, subject, false);
}
// IR-058366V6R2011x Modification - Starts
// if (isContextPushed == true) {
// Pop Notification Agent
// utilityClass.popContext(context, null);
// }
// IR-058366V6R2011x Modification - Ends
}catch(Exception e)
{
e.printStackTrace();
}
finally // IR-058366V6R2011x Added finally block - Starts
{
if (isContextPushed == true) {
// Pop Notification Agent
utilityClass.popContext(context, null);
}
} // IR-058366V6R2011x Added finally block - Ends
}
/**
* This method sends an icon mail notification to the specified users.
*
* @param context the eMatrix <code>Context</code> object
* @param toList StringList that contains the list of users to notify
* @param ccList StringList that contains the list of users to cc
* @param bccList StringList that contains the list of users to bcc
* @param subject String that contains the notification subject
* @param message String that contains the notification message
* @param objectIdList StringList that contains the ids of objects to send
with the notification
* @param fromAgent a String holding the from user appearing in the mail
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
// viewing Icon mail in application '<' and '>' are read as tags by
html
// These char's need to be eliminated before sending the mail message.
subject = subject.replace('<', ' ');
subject = subject.replace('>', ' ');
message = message.replace('<', ' ');
message = message.replace('>', ' ');
Iterator i = objectIdList.iterator();
while (i.hasNext()) {
String id = (String) i.next();
BusinessObject bo = new BusinessObject(id);
bo.open(context);
bol.addElement(bo);
}
mail.setObjects(bol);
}
if (isContextPushed == true) {
// Pop Notification Agent
utilityClass.popContext(context, null);
}
}
/**
* Returns a processed and translated message for a given key.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId a String contains id of the object
* @param messageKey the notification message key
* @param locale the locale used to determine language
* @param basePropFileName used to identify property file.
* @return a String containing the message
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
/**
* Returns a processed and translated message for a given key or string.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId a String contains id of the object
* @param messageKey the notification message key or string
* @param formatArgs an array of message place holder values
* @param locale the locale used to determine language
* @param basePropFileName used to identify property file if key given
* @return a String containing the message
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
/**
* Returns a processed and translated message for a given key.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be
* used for evaluating selects embedded in the subject and
* message strings
* @param idType a String set to either "object" or "relationship"
* @param messageKey the notification message key
* @param locale the locale used to determine language
* @param basePropFileName used to identify property file.
* @return a String containing the message
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
/**
* Returns a processed and translated message for a given key or string.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be
* used for evaluating selects embedded in the subject and
* message strings
* @param idType a String set to either "object" or "relationship"
* @param messageKey the notification message key or string
* @param formatArgs an array of message place holder values
* @param locale the locale used to determine language
* @param basePropFileName used to identify property file if key given
* @return a String containing the message
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
if (message != null) {
// Do the normal macro substitution (i.e. $<type>, ${OBJECTID},
etc.)
message = substituteValues(context, message, id, idType,
locale.getLanguage());
return (message);
}
/**
* Get locale for given context.
*
* @param context the eMatrix <code>Context</code> object
* @return locale object
* @since AEF 10.0.0.0
*/
/**
* Replace symbolic names embedded in a string with true names.
*
* @param context the eMatrix <code>Context</code> object
* @param expression the string containing embedded selectables
* @return the evaluated result
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
protected static String substituteValues(Context context, String expression)
throws Exception {
return (substituteValues(context, expression, null, null));
}
/**
* Replace object selectables embedded in a string with their
* values based on the given object.
*
* @param context the eMatrix <code>Context</code> object
* @param expression the string containing embedded selectables
* @param objectId the id of the object used to evaluate the selectables
* @param language the string containing a language for i18n of type and
vault
* @return the evaluated result
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
/**
* Replace selectables embedded in a string with their
* values based on the given object or relationship.
*
* @param context the eMatrix <code>Context</code> object
* @param expression the string containing embedded selectables
* @param id a String holding the id of an object or relationship to be
* used for evaluating selects embedded in the subject and
* message strings
* @param idType a String set to either "object" or "relationship"
* @param language the string containing a language for i18n of type and
vault
* @return the evaluated result
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
try {
// get everything up to the first delimiter
token = st.nextToken(DELIMITER_START);
if (type.equals(SELECT) &&
token.indexOf("_") > -1) {
token =
replaceSymbolicTokens(context, token);
}
tokens.add(token);
types.add(type);
} catch (NoSuchElementException e) {
break;
}
}
//
// Get the selectable information from the object.
//
while (itr.hasNext()) {
selects.add((String) itr.next());
}
if (language != null) {
Hashtable selectMap = new Hashtable((Map)
values.get(SELECT));
values.put(SELECT, selectMap);
}
//
// Put the string back together while replacing tokens with
values.
//
while (tokenItr.hasNext()) {
String token = (String) tokenItr.next();
String type = (String) typeItr.next();
list.append(OUTPUT_LIST_DELIMITER);
list.append((String)
setItr.next());
}
value = list.toString();
}
}
} else {
value = (String) valueMap.get(token);
}
if (id != null) {
if (value == null) {
message.append(OUTPUT_NO_VALUE);
} else if (value == "") {
message.append(OUTPUT_EMPTY_VALUE);
} else {
message.append(value);
}
} else {
// if there is no value, just place the token
message.append(value == null ? token : value);
}
}
}
return (message.toString());
} catch (Exception e) {
throw (e);
}
}
/**
* Given an expression, replace all of the symbolic references
* with their real values.
*
* @param context the eMatrix <code>Context</code> object
* @param expression the expression containing the symbolic references
* @return the evaluated result
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
while (true) {
try {
String token = st.nextToken();
newExpression = buffer.toString();
}
return (newExpression);
}
/**
* Lookup a symbolic token and return the real value. If
* the token can't be found, return the original token.
*
* @param context the eMatrix <code>Context</code> object
* @param symbolicToken the token to lookup
* @return the result of the property lookup
* @since AEF 10.0.0.0
*/
protected static String lookupSymbolicToken(Context context,
String symbolicToken) {
String token = null;
try {
token = PropertyUtil.getSchemaProperty(context, symbolicToken);
} catch (Exception e) {
}
return (token);
}
/**
* Returns a formatted message.
*
* @param context the eMatrix <code>Context</code> object
* @param message the message containing format information
* @param formatArgs array of replacement values for the message
* @param locale the locale used to determine language
* @return a String containing the formatted message
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
return (formatter.format(formatArgs));
}
/**
* Get information regarding a given business object.
* The map that is returned contains all StringList entries. This ensures
that
* multiple values are handled. This also means for a single value you need
to
* extract the first element on the StringList.
*
* @param context the eMatrix <code>Context</code> object
* @param objectId the id of the given object
* @param objectSelects the eMatrix <code>StringList</code> object that holds
the list of object selectables
* @return Map containing information about the object based on selectables
* @throws Exception if the operation fails
* @since AEF 10.0.0.0
*/
protected static Map getInfo(Context context,
String objectId,
StringList objectSelects) throws Exception {
return getInfo(context, objectId, OBJECT, objectSelects);
}
/**
* Get information regarding a given business object or relationship.
* The map that is returned contains all StringList entries. This ensures
that
* multiple values are handled. This also means for a single value you need
to
* extract the first element on the StringList.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be
* used for evaluating selects embedded in the subject and
* message strings
* @param idType a String set to either "object" or "relationship"
* @param selects the eMatrix <code>StringList</code> object that holds the
list of selectables
* @return Map containing information about the object or relationship based
on selectables
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
relWSelItr.next();
RelationshipWithSelect relWSel = relWSelItr.obj();
Vector keys = relWSel.getSelectKeys();
int size = keys.size();
hashMap = new HashMap(size);
for (int i=0; i < size; i++) {
String name = (String) keys.elementAt(i);
hashMap.put(name, relWSel.getSelectDataList(name));
}
}
return (hashMap);
}
/*
* Converts encoded \uxxxx to unicode chars
* and changes special saved chars to their original forms
*/
protected static String loadConvert(String theString) {
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len);
/**
* Gets additional message that needs to be appended with the Message body of
Inbox Task Notification.
* @param context the eMatrix <code>Context</code> object
* @param objectIdList the idList for which the message needs to be returned
* @param locale the Locale object
* @param basePropFile the name of the property file in which the
notification keys are defined
* @param baseURL the URL link to the corresponding inbox task
* @param urlSuffix the Suffix that needs to be appended with the url
* @return String containing message to be appended
* @throws Exception if the operation fails
* @since AEF 10.6.SP1
*/
doTempObj.setId(sTempObjId);
if( (doTempObj.getInfo(context,DomainConstants.SELECT_TYPE)).equals(DomainConstants
.TYPE_INBOX_TASK)){
inBoxTaskId = sTempObjId;
break;
}
}catch(Exception ex){
throw (ex);
}
}
}
}
// If it is inbox task the message has to be modified accordingly.
if( (inBoxTaskId != null) && (!inBoxTaskId.equals("")) ){
if(locale !=null){
msg = $
{CLASS:emxMailUtil}.getInboxTaskMailMessage(context,inBoxTaskId,locale,basePropFile
,baseURL,urlSuffix);
}else{
msg = $
{CLASS:emxMailUtil}.getInboxTaskMailMessage(context,inBoxTaskId,getLocale(context),
basePropFile,baseURL,urlSuffix);
}
}
return msg;
}
/**
* Evaluate given filter expression (or JPO method).
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be used
for
* evaluating selects embedded in the subject and message strings
* @param idType a String set to either "object" or "relationship"
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @param filter a String holding the filter expression or "JPO
<jponame>:<methodname>"
* @return int containing status (0 pass, filter out)
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
try
{
// Create the arguments for the JPO method
Map note = new HashMap();
note.put("id", id);
note.put("idType", idType);
note.put("notificationName", notificationName);
note.put("payload", payload);
} catch (Throwable e) {
System.out.println("Exception trying to invoke
method " + methodName +
" of JPO " + name + " ERROR: " +
e.toString());
}
} catch (Exception e) {
System.out.println("Exception trying to print program
" + name + " ERROR: " + e.toString());
}
} else {
if (id != null && !id.equals("")) {
String expression = substituteValues(context,
filter);
StringBuffer command = new StringBuffer();
command.append("evaluate expression '");
command.append(expression);
if (idType.equalsIgnoreCase(OBJECT)) {
command.append("' on bus ");
} else {
command.append("' on relationship ");
}
command.append(id);
String filterResult = MqlUtil.mqlCommand(context,
command
.toString());
if (filterResult.startsWith("FALSE")) {
status = 1;
}
}
}
}
return status;
}
/**
* Parse list of items and return as a StringList.
*
* @param value a String holding the delimited list of items
* @return list a StringList holding the items
* @since AEF 11.0.0.0
*/
/**
* Parse list of items (or execute JPO method) and return as a StringList.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be used
for
* evaluating selects embedded in the subject and message strings
* @param idType a String set to either "object" or "relationship"
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @param value a String holding the delimited list of items
* @return list a StringList holding the items
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
try {
// Create the arguments for the JPO method
Map note = new HashMap();
note.put("id", id);
note.put("idType", idType);
note.put("notificationName", notificationName);
note.put("payload", payload);
} catch (Throwable e) {
System.out.println("Exception trying to invoke
method " + methodName +
" of JPO " + name + " ERROR: " +
e.toString());
throw new
FrameworkException(ExceptionUtils.getStackTrace(e));
}
} catch (Exception e) {
System.out.println("Exception trying to print program
" + name + " ERROR: " + e.toString());
throw new FrameworkException(e);
}
} else {
list = inputListToStringList(value);
}
}
return list;
}
/**
* Take given value (or execute JPO method) and return as a String.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be used
for
* evaluating selects embedded in the subject and message strings
* @param idType a String set to either "object" or "relationship"
* @param notificationName a String holding the name of the Notification
object
* @param payload a Map containing information to pass on to helper JPO
methods
* @param value a String holding the given value
* @return item a String holding the resulting item
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
try
{
// Create the arguments for the JPO method
Map note = new HashMap();
note.put("id", id);
note.put("idType", idType);
note.put("notificationName", notificationName);
note.put("payload", payload);
} catch (Throwable e) {
System.out.println("Exception trying to invoke
method " + methodName +
" of JPO " + name + " ERROR: " +
e.toString());
}
} catch (Exception e) {
System.out.println("Exception trying to print program
" + name + " ERROR: " + e.toString());
}
} else {
item = value;
}
}
return item;
}
/**
* Take given key value (or execute JPO method) and return localized String.
*
* @param context the eMatrix <code>Context</code> object
* @param value a String holding the given value
* @param info a Map containing information to pass on to helper JPO methods
* @param urls a String of urls to append to the results
* @return results a String holding the localized results
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
try {
} catch (Throwable e) {
System.out.println("Exception trying to invoke
method " + methodName +
" of JPO " + name + " ERROR: " +
e.toString());
}
} catch (Exception e) {
System.out.println("Exception trying to print program
" + name + " ERROR: " + e.toString());
}
} else {
results.append(getMessage(context,
(String) info.get("id"),
(String) info.get("idType"),
value,
(Locale) info.get("locale"),
(String) info.get("bundleName")));
if (!UIUtil.isNullOrEmpty(urls)) {
results.append("\n").append(urls);
}
}
}
return results.toString();
}
/**
* Combine a static list and the results of a dynamic list.
*
* @param context the eMatrix <code>Context</code> object
* @param id a String holding the id of an object or relationship to be used
for
* evaluating selects embedded in the subject and message strings
* @param idType a String set to either "object" or "relationship"
* @param list a StringList holding the static values
* @param selects a StringList holding the dynamic values
* @param userListMode a boolean set to true if evaluated selects generate
lists of users
* @return finalList a StringList holding the combined lists (fully
evaluates)
* @throws Exception if the operation fails
* @since AEF 11.0.0.0
*/
finalList.addElement(tokens.nextToken()
.trim());
}
}else {
finalList.add((String)
itr2.next());
}
}
}
}
// move values into set to eliminate duplicates
Set set = new HashSet();
set.addAll(finalList);
Iterator setItr = set.iterator();
finalList = new StringList(set.size());
while (setItr.hasNext()) {
finalList.add((String) setItr.next());
}
}
}
return finalList;
}
/**
* Parse userList and groups email persons List, IconMail persons List, and
Both persons list
*
* @param context the eMatrix <code>Context</code> object
* @param userList contains the list of the users along with notification
type in <person>|<notification type>
* @return HashMap a containing 'Email', 'IconMail' and 'Both' keys that
represent Notification Type and has list of persons
* as their values
* @throws Exception if the operation fails
* @since X+2
*/
private static HashMap getRefineList(Context context, StringList userList)
throws Exception
{
HashMap finalMap = new HashMap();
StringList EmailToList = new StringList();
StringList IconMailToList = new StringList();
StringList BothToList = new StringList();
StringTokenizer strTokenizer = null;
finalMap.put(email,EmailToList);
finalMap.put(iconMail,IconMailToList);
finalMap.put(both,BothToList);
if(userList!=null && userList.size()>0)
{
//Parse the toList to get the email persons List IconMail
persons List and Both persons list .
for(int i =0;i<userList.size();i++)
{
String personNotify = userList.get(i).toString();
strTokenizer = new StringTokenizer(personNotify, "|");
if(strTokenizer.hasMoreTokens())
{
String toPerson = strTokenizer.nextToken();
if(strTokenizer.hasMoreTokens())
{
String notifyType =strTokenizer.nextToken();
if(email.equalsIgnoreCase(notifyType))
{
EmailToList.add(toPerson);
}
else if(iconMail.equalsIgnoreCase(notifyType))
{
IconMailToList.add(toPerson);
}
else if(both.equalsIgnoreCase(notifyType) ||
"".equalsIgnoreCase(notifyType.trim()))
{
BothToList.add(toPerson);
}
}
else
{
BothToList.add(toPerson);
}
}
}
}
return finalMap;
}
/**
* resetCache.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds no arguments
* @return an int 0 for success and non-zero for failure
*/
/**
* Specifies the component age value.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds the following input arguments:
* 0 - Contains Long value
* @return an int 0 for success and non-zero for failure
* @throws Exception if the operation fails
*/
/**
* This method gets the names and notification frequency preferences from the
list.
*
* @param context the eMatrix <code>Context</code> object
* @param names from the list along with notification frequency preference will
be added to this map
* @param frequencies notification frequency preferences will be added to this
map
* @param list the list of recipients
* @since AEF R213
*/
/**
* This method gets names from the list with given notification frequency
preference.
*
* @param list the list of recipients
* @param nameAndFrequency map of key names and value frequency
* @param frequency String holds the frequency we are filtering on
* @return a StringList contains list of recipients expecting a notification in
the given time frame
* @since R213
*/
if (list != null) {
names = new StringList(list.size());
return (names);
}
/**
* Called when showing preference choices. Used in
AEFEmailNotificationPreference
* command, "Access Program" and "Access Function" properties.
*
* @param context the eMatrix <code>Context</code> object
* @param args holds no arguments
* @throws Exception if the operation fails
* @return always return "true" to allow preference.
* @since BPS 2012x
*/
public boolean hasEmailNotificationAccess(Context context,String args[]) throws
Exception {
return (true);
}
return (link);
}
return (link);
}
}