public class NotificationMessage extends MappedAttributesObject
Modifier and Type | Field and Description |
---|---|
private static java.util.Base64.Encoder |
cvEncoder
The base 64 encoder used for converting byte arrays to strings.
|
private static long |
serialVersionUID
The class' serialization version id.
|
ivHashCode, ivHashFlds, ivObjAttrs
Modifier | Constructor and Description |
---|---|
protected |
NotificationMessage()
Constructs a
NotificationMessage object. |
|
NotificationMessage(java.lang.String type)
Constructs a
NotificationMessage object. |
Modifier and Type | Method and Description |
---|---|
void |
addFileAttachment(java.io.File value)
Adds to the collection of file attachment file objects.
|
protected void |
addRecipentsAdmin(JDBCConnectionInfo cninf,
java.lang.String typesfx)
Adds to the collection of message recipient objects for admin users when
the current message type is for an admin message.
|
protected void |
addRecipientAddr(javax.mail.internet.InternetAddress value)
Adds to the collection of message recipient internet addresses.
|
void |
addRecipients(java.lang.Object value)
Adds to the collection of message recipient objects (Customer, User,
ArrayList, etc.).
|
protected void |
addRecipientUser(User value)
Adds to the collection of message recipient users.
|
protected void |
cullRecipientUsers(JDBCConnectionInfo cninf,
java.lang.String typesfx)
Discards message recipient users who don't have an interest in receiving
notifications for the current message type.
|
boolean |
equals(java.lang.Object obj)
Compares the given object to this object and determines if the two are
equal.
|
protected void |
formatMessage(JDBCConnectionInfo cninf,
java.lang.String typesfx)
Formats a message and then sends the formatted message to the Notification
Framework for processing.
|
protected void |
formatMessageMassMail(JDBCConnectionInfo cninf,
java.lang.String typesfx)
Formats a mass mail message and then sends the formatted message to the
Notification Framework for processing.
|
protected void |
formatMessageSample(java.lang.String typesfx)
Formats a sample message and then sends the formatted message to the
Notification Framework for processing.
|
protected void |
formatMessageString(java.lang.String typesfx)
Formats a message and then sends the formatted message to the Notification
Framework for processing.
|
protected void |
formatMessageVelocity(java.lang.String typesfx)
Formats a message and then sends the formatted message to the Notification
Framework for processing.
|
java.lang.Object |
getContent()
Returns the message content object.
|
java.util.ArrayList<java.io.File> |
getFileAttachments()
Returns the collection of file attachment file objects.
|
protected org.json.JSONArray |
getFileAttachmentsAsJSON()
Returns the collection of file attachment files as a JSON array of base
64 encoded JSON objects.
|
java.lang.Object |
getFrom()
Returns the message from address object.
|
protected org.json.JSONObject |
getFromAsJSON()
Returns the message from address as a JSON object.
|
protected java.util.ArrayList<javax.mail.internet.InternetAddress> |
getRecipientAddrs()
Returns the collection of message recipient internet addresses.
|
protected org.json.JSONArray |
getRecipientAddrsAsJSON()
Returns the collection of message recipient internet addresses as a
JSON array.
|
java.util.ArrayList<java.lang.Object> |
getRecipients()
Returns the collection of message recipient objects.
|
protected java.util.ArrayList<User> |
getRecipientUsers()
Returns the collection of message recipient users.
|
protected org.json.JSONArray |
getRecipientUsersAsJSON()
Returns the collection of message recipient users as a JSON array of
contact ids.
|
java.lang.String |
getSampleMethod()
Returns the sample delivery method (email, sms, push).
|
boolean |
getSampleMode()
Returns the sample mode on/off state.
|
java.lang.String |
getSampleVersion()
Returns the sample version number.
|
java.lang.String |
getSubject()
Returns the message subject.
|
protected org.json.JSONArray |
getSubstitutionsAsJSON()
Returns the collection of message API substitution parameters as a JSON
array.
|
java.lang.String |
getTemplate()
Returns the message template file path.
|
java.lang.String |
getType()
Returns the message type code.
|
java.lang.String |
getTypeSuffix()
Returns the message type code's suffix, which is the actual message type
used by the Notification Framework (sans the "MailMessage." prefix).
|
protected boolean |
isUserInterested(JDBCConnectionInfo cninf,
User user,
java.lang.String typesfx)
Answers if a user is interested in receiving notifications for the given
message type.
|
protected void |
logSendFailure()
Logs an error to the MAIN log for a send message failure.
|
protected javax.mail.internet.InternetAddress |
makeInternetAddress(java.lang.String name,
java.lang.String address)
Creates an
InternetAddress object from the given name and
email address. |
protected void |
parseContent(JDBCConnectionInfo cninf)
Parses the message content when it is a Velocity Context.
|
protected org.apache.velocity.VelocityContext |
parseContentAlert()
Parses the message content when it is a string for an alert message.
|
static org.apache.velocity.VelocityContext |
parseContentAlert(java.lang.String content)
Parses the message content when it is a string for an alert message.
|
protected void |
parseRecipients(JDBCConnectionInfo cninf)
Parses the collection of message recipients into either
User
objects or InternetAddress objects and adds to the respective
collection. |
protected void |
parseRecipients(JDBCConnectionInfo cninf,
java.lang.Object recipient)
Parses the given message recipient object into either a
User
object or an InternetAddress object and adds to the respective
collection. |
protected void |
parseRecipientsLowstockRestock(JDBCConnectionInfo cninf,
RestockNotification restock)
Parses the given lowstock/restock object into either a
User
recipient object or an InternetAddress recipient object and
then resets this message's recipient accordingly. |
void |
send()
Sends the message.
|
protected boolean |
sendMessage(java.lang.String api,
org.json.JSONObject data)
Sends a formatted message to the Notification Framework for processing.
|
void |
setContent(java.lang.Object value)
Sets the message content object.
|
protected void |
setContentAsHTML()
Converts plain text message content to HTML content by enclosing the
content within an HTML <pre> tag.
|
void |
setFrom(java.lang.Object value)
Sets the message from address object.
|
void |
setSampleMethod(java.lang.String value)
Sets the sample delivery method (email, sms, push).
|
void |
setSampleMode(boolean value)
Sets the sample mode on/off state.
|
void |
setSampleVersion(java.lang.String value)
Sets the sample version number.
|
void |
setSubject(java.lang.String value)
Sets the message subject.
|
protected void |
setSubstitutionsAsJSON(org.json.JSONArray value)
Sets the collection of message API substitution parameters as a JSON array.
|
void |
setTemplate(java.lang.String value)
Sets the message template file path.
|
void |
setType(java.lang.String value)
Sets the message type code.
|
protected void |
throwNoRecipients()
Throws a no recipients exception.
|
cloneMapAttributes, formatValue, formatValue, getHashFields, getMapArrayList, getMapAttributes, getMapBigDecimal, getMapBoolean, getMapDate, getMapDouble, getMapInteger, getMapLong, getMapMapped, getMapObject, getMapShort, getMapString, getMapString, getMapStringBuffer, getMapStringBuilder, getMapTime, getMapTimestamp, getMapVector, hashCode, setHashFields, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMapAttributes, setMapObject, setMapTime, setMapTimestamp, toStringArray
private static final long serialVersionUID
private static java.util.Base64.Encoder cvEncoder
protected NotificationMessage() throws java.lang.Exception
NotificationMessage
object.java.lang.Exception
- - if an error occurs while constructing
the NotificationMessage
object.public NotificationMessage(java.lang.String type) throws java.lang.Exception
NotificationMessage
object.type
- (String) The type code for the message. Must be one
of the predefined FlashMailMessage.MSG_* type constants or
the base class MailMessage.MSG_* type constants.java.lang.Exception
- - if an error occurs while constructing
the NotificationMessage
object.public boolean equals(java.lang.Object obj)
false
.equals
in class MappedAttributesObject
obj
- (Object) The object to compare with this object.true
if the specified object is equal to
this object, otherwise false
.public void send() throws java.lang.Exception
java.lang.Exception
- - if an error occurs while sending the
message.public java.lang.Object getContent()
public void setContent(java.lang.Object value)
String
, a message file name String
, or a
VelocityContext
of template tags and values.value
- (Object) The object that contains the message content.protected void setContentAsHTML()
public java.lang.Object getFrom()
protected org.json.JSONObject getFromAsJSON()
public void setFrom(java.lang.Object value)
value
- (Object) The object that contains the message from address.public void addRecipients(java.lang.Object value)
value
- (Object) The object that contains the recipient info.protected void addRecipentsAdmin(JDBCConnectionInfo cninf, java.lang.String typesfx)
cninf
- (JDBCConnectionInfo) A JDBC connection information object.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).public java.util.ArrayList<java.lang.Object> getRecipients()
public void addFileAttachment(java.io.File value)
value
- (File) The object for the file to attach.public java.util.ArrayList<java.io.File> getFileAttachments()
protected org.json.JSONArray getFileAttachmentsAsJSON()
public java.lang.String getSampleMethod()
public void setSampleMethod(java.lang.String value)
value
- (String) The sample delivery method.public boolean getSampleMode()
public void setSampleMode(boolean value)
value
- (boolean) true
if sample mode is to be turned
on, otherwise false
(default).public java.lang.String getSampleVersion()
public void setSampleVersion(java.lang.String value)
value
- (String) The sample version number.public java.lang.String getSubject()
public void setSubject(java.lang.String value)
value
- (String) The message subject.public java.lang.String getTemplate()
public void setTemplate(java.lang.String value)
value
- (String) The full path to the template file.public java.lang.String getType()
public java.lang.String getTypeSuffix()
public void setType(java.lang.String value)
value
- (String) The message type code.protected void parseContent(JDBCConnectionInfo cninf) throws java.lang.Exception
cninf
- (JDBCConnectionInfo) A JDBC connection information object.java.lang.Exception
- - if an error occurs during parsing.protected org.apache.velocity.VelocityContext parseContentAlert()
public static org.apache.velocity.VelocityContext parseContentAlert(java.lang.String content)
content
- (String) The content to parse.protected void parseRecipients(JDBCConnectionInfo cninf) throws java.lang.Exception
User
objects or InternetAddress
objects and adds to the respective
collection.cninf
- (JDBCConnectionInfo) A JDBC connection information object.java.lang.Exception
- - if an error occurs during parsing.protected void parseRecipients(JDBCConnectionInfo cninf, java.lang.Object recipient) throws java.lang.Exception
User
object or an InternetAddress
object and adds to the respective
collection.cninf
- (JDBCConnectionInfo) A JDBC connection information object.recipient
- (Object) An individual message recipient object.java.lang.Exception
- - if an error occurs during parsing.protected void parseRecipientsLowstockRestock(JDBCConnectionInfo cninf, RestockNotification restock) throws java.lang.Exception
User
recipient object or an InternetAddress
recipient object and
then resets this message's recipient accordingly.
If the lowstock/restock object's email address matches the email address of the object's user, then use the object's user as the recipient so that email/sms/push can be sent.
cninf
- (JDBCConnectionInfo) A JDBC connection information object.restock
- (RestockNotification) The lowstock/restock to parse.java.lang.Exception
- - if an error occurs during parsing.protected javax.mail.internet.InternetAddress makeInternetAddress(java.lang.String name, java.lang.String address)
InternetAddress
object from the given name and
email address.name
- (String) The name associated with the email address.address
- (String) The email address.InternetAddress
object for
the specified name and address, or null
if the
specified address does not conform to RFC822 syntax.protected void addRecipientAddr(javax.mail.internet.InternetAddress value)
value
- (InternetAddress) The internet addresses that contains
the recipient info.protected java.util.ArrayList<javax.mail.internet.InternetAddress> getRecipientAddrs()
protected org.json.JSONArray getRecipientAddrsAsJSON()
protected void addRecipientUser(User value)
value
- (User) The user that contains the recipient info.protected java.util.ArrayList<User> getRecipientUsers()
protected org.json.JSONArray getRecipientUsersAsJSON()
protected void cullRecipientUsers(JDBCConnectionInfo cninf, java.lang.String typesfx) throws java.lang.Exception
cninf
- (JDBCConnectionInfo) A JDBC connection information object.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during culling.protected org.json.JSONArray getSubstitutionsAsJSON()
protected void setSubstitutionsAsJSON(org.json.JSONArray value)
value
- (JSONArray) The substitution parameters.protected boolean isUserInterested(JDBCConnectionInfo cninf, User user, java.lang.String typesfx) throws java.lang.Exception
cninf
- (JDBCConnectionInfo) A JDBC connection information object.user
- (User) The user to check.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).true
if the user is interested,
otherwise false
.java.lang.Exception
- - if an error occurs during checking.protected void formatMessage(JDBCConnectionInfo cninf, java.lang.String typesfx) throws java.lang.Exception
cninf
- (JDBCConnectionInfo) A JDBC connection information object.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during formatting.protected void formatMessageMassMail(JDBCConnectionInfo cninf, java.lang.String typesfx) throws java.lang.Exception
cninf
- (JDBCConnectionInfo) A JDBC connection information object.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during formatting.protected void formatMessageSample(java.lang.String typesfx) throws java.lang.Exception
typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during formatting.protected void formatMessageString(java.lang.String typesfx) throws java.lang.Exception
formatMessage
when the
message content is a String
.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during formatting.protected void formatMessageVelocity(java.lang.String typesfx) throws java.lang.Exception
formatMessage
when the
message content is a Velocity Context
.typesfx
- (String) The message type suffix for the current
message type (sans the "MailMessage." prefix).java.lang.Exception
- - if an error occurs during formatting.protected boolean sendMessage(java.lang.String api, org.json.JSONObject data) throws java.lang.Exception
api
- (String) The name of the API to call.data
- (JSONObject) The data to be sent to the API.true
if the processing was successful,
otherwise false
.java.lang.Exception
- - if an error occurs during sending.protected void logSendFailure()
protected void throwNoRecipients() throws java.lang.Exception
java.lang.Exception
- - the no recipients exception.