Commit 4e7c2989 by Chamath

Sending chat mails and SMS.

parent 182efaa9
......@@ -199,6 +199,7 @@ public abstract class BaseMessage extends BaseBusinessClass
metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
metaInfo.put ("dbcol", "sent_via");
metaInfo.put ("defaultValue", "SentVia.ON_APP");
metaInfo.put ("mandatory", "false");
metaInfo.put ("name", "SentVia");
metaInfo.put ("type", "SentVia");
......@@ -271,7 +272,7 @@ public abstract class BaseMessage extends BaseBusinessClass
super._initialiseNewObjAttributes (transaction);
_SentVia = (SentVia)(HELPER_SentVia.initialise (_SentVia));
_SentVia = (SentVia)(SentVia.ON_APP);
_MessageContent = (String)(HELPER_MessageContent.initialise (_MessageContent));
_IsRead = (Boolean)(HELPER_IsRead.initialise (_IsRead));
}
......
......@@ -3,7 +3,7 @@ package performa.orm;
public class Message extends BaseMessage
{
private static final long serialVersionUID = 0L;
private static final long serialVersionUID = 0L;
// This constructor should not be called
public Message ()
......
......@@ -10,7 +10,7 @@
<TABLE name="tl_message" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="SentVia" type="SentVia" dbcol="sent_via" attribHelper="EnumeratedAttributeHelper" mandatory="false"/>
<ATTRIB name="SentVia" type="SentVia" dbcol="sent_via" attribHelper="EnumeratedAttributeHelper" defaultValue="SentVia.ON_APP" mandatory="false"/>
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="false"/>
<ATTRIB name="IsRead" type="Boolean" dbcol="is_read" mandatory="false"/>
......
package performa.utils;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
import java.util.*;
import oneit.business.content.Article;
import oneit.business.content.jsp.ShortcutFilter;
import oneit.logging.*;
import oneit.objstore.ObjectTransaction;
public class MessagingUtils
{
private static final Random rand = new Random();
public static final LoggingArea LOG = LoggingArea.createLoggingArea("MessagingUtilsLog");
public static int WORK_START_HOUR = 9;
public static int WORK_STOP_HOUR = 17;
......@@ -80,4 +81,17 @@ public class MessagingUtils
return !(dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
}
public static String getArticleContent(ObjectTransaction objectTransaction, String shortcut)
{
Article article = ShortcutFilter.doShortcutSearch(objectTransaction, shortcut);
if (article == null)
{
LogMgr.log(LOG, LogLevel.PROCESSING2, "Article not found with shortcut: " + shortcut);
return null;
}
return article.getArticleContent(Article.CONTENT_BODY).getContentForEditor();
}
}
\ No newline at end of file
package performa.utils;
import au.com.m4u.smsapi.*;
import java.io.IOException;
import java.util.Set;
import oneit.appservices.config.ConfigMgr;
import oneit.components.*;
import oneit.logging.*;
import oneit.utils.*;
/**
*
* @author chamathkalhara
*/
public class SMSUtils implements InitialisationParticipant
{
public static final LoggingArea LOG = LoggingArea.createLoggingArea("SMSUtilsLog");
private static final String SIMULATE_EXEMPTIONS = ConfigMgr.getKeyfileString ("sms.simulate.exemptions", null);
private static final Set<String> SIMULATE_EXEMPTION_SET = CollectionUtils.createSet(StringUtils.split(SIMULATE_EXEMPTIONS, ';'));
private String userName;
private String password;
private boolean doNotSend = true;
private int messageFormat = 2;
public boolean isSendingForReal ()
{
return ! doNotSend;
}
private SmsInterface openConnection (boolean secureMode, boolean debug) throws IOException
{
SmsInterface si = new SmsInterface(messageFormat);
si.useSecureMode(secureMode);
si.setDebug(debug);
LogMgr.log(LOG, LogLevel.DEBUG2, "Connecting to SMS SmsInterface with ", userName);
if (! si.connect (userName, password, false))
{
LogMgr.log(LOG, LogLevel.DEBUG2, "Failed in Connecting to SMS Interface");
throw new IOException("SMS: Cannot connect");
}
else
{
LogMgr.log(LOG, LogLevel.DEBUG2, "Connected to SMS SmsInterface");
}
return si;
}
public void sendSMS (String message, String number, Short validityPeriod) throws IOException
{
sendSMS(message, number, validityPeriod, LOG);
}
public void sendSMS (String message, String number, Short validityPeriod, LoggingArea log) throws IOException
{
if (doNotSend && (SIMULATE_EXEMPTION_SET == null || !SIMULATE_EXEMPTION_SET.contains(number)))
{
LogMgr.log(log, LogLevel.BUSINESS1, "PRETEND Sending SMS [", message, "] ", number);
}
else
{
SmsInterface sms = openConnection(true, true);
sms.addMessage(number, message, 0, 0, validityPeriod == null ? ValidityPeriod.DEFAULT : validityPeriod.shortValue(), false);
LogMgr.log(log, LogLevel.BUSINESS1, "Sending SMS ", number);
if (sms.sendMessages ())
{
LogMgr.log(log, LogLevel.PROCESSING2, "SMS Sent [", message, "] response code ", sms.getResponseCode());
}
else
{
LogMgr.log(log, LogLevel.BUSINESS2, "SMS Failed [", message, "] response code ", sms.getResponseCode(), " ResponseMessage:", sms.getResponseMessage());
throw new IOException("SMS Failed [" + message + "] response code " + sms.getResponseCode());
}
}
}
@Override
public void init(ParticipantInitialisationContext context) throws InitialisationException
{
userName = context.getSingleChild("userName", userName).toString();
password = context.getSingleChild("password", password).toString();
doNotSend = (Boolean)context.getSingleChild("simulate", Boolean.TRUE);
}
}
package performa.ws;
import java.io.IOException;
import java.util.*;
import oneit.appservices.config.ConfigMgr;
import oneit.appservices.ws.*;
import oneit.appservices.ws.services.ORMUpdateJSONService;
import oneit.email.*;
import oneit.logging.*;
import oneit.net.LoopbackHTTP;
import oneit.objstore.*;
import oneit.servlets.jsp.ui.DefaultUICustomiser;
import oneit.utils.*;
import oneit.utils.transform.MapTransform;
import oneit.utils.transform.param.*;
import org.json.*;
import performa.orm.*;
import performa.orm.types.SentVia;
import performa.utils.*;
/**
*
* @author chamathkalhara
*/
public class SendMessage extends ORMUpdateJSONService
{
public static final LoggingArea LOG = LoggingArea.createLoggingArea("SendMessageLog");
protected ConfigurableEmailer APP_MESSAGE_EMAILER = (ConfigurableEmailer) ConfigMgr.getConfigObject(ConfigMgr.GLOBAL_CONFIG_SYSTEM, "AppMessageEmailer");
protected ConfigurableEmailer APP_EMAIL_EMAILER = (ConfigurableEmailer) ConfigMgr.getConfigObject(ConfigMgr.GLOBAL_CONFIG_SYSTEM, "AppEmailEmailer");
PrefixCompoundTransform prefixTransform = new PrefixCompoundTransform();
@Override
public void processForm(JSONServiceRequest request, ObjectTransaction objTran, JSONObject result, MultiException exceptions, Set<BaseBusinessClass> createdBBCs, Set<BaseBusinessClass> updatedBBCs) throws BusinessException, JSONException
{
List<Message> createdMessages = WSUtils.filterBBCs(Message.REFERENCE_Message, createdBBCs);
List<Message> updatedMessages = WSUtils.filterBBCs(Message.REFERENCE_Message, updatedBBCs);
List<Message> allMessages = new ArrayList(createdMessages);
allMessages.addAll(updatedMessages);
for (Message message : allMessages)
{
if (message.getStatus() != ObjectStatus.NEW)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Message should be a new one");
break;
}
ConfigurableEmailer EMAILER = null;
if (message.getSentVia() == SentVia.EMAIL)
{
EMAILER = APP_EMAIL_EMAILER;
}
if (message.getSentVia() == SentVia.ON_APP)
{
EMAILER = APP_MESSAGE_EMAILER;
}
JobApplication jobApplication = message.getJobApplication();
String appUrl = getShortantURL(jobApplication.getID().longValue());
Candidate candidate = jobApplication.getCandidate();
HiringTeam hiringTeam = jobApplication.getJob().getHiringTeam();
ObjectTransform defaultTransform = new MapTransform(CollectionUtils.mapEntry("link", appUrl).toMap());
prefixTransform.add(message.getClass().getSimpleName(), new ORMPipelineTransform(message));
prefixTransform.add(candidate.getUser().getClass().getSimpleName(), new ORMPipelineTransform(candidate.getUser()));
prefixTransform.add(hiringTeam.getClass().getSimpleName(), new ORMPipelineTransform(hiringTeam));
prefixTransform.setDefault(defaultTransform);
if (message.getSentVia() == SentVia.EMAIL || message.getSentVia() == SentVia.ON_APP)
{
try
{
EMAILER.sendTransactionalEmail(objTran,
new Date(),
prefixTransform,
new String[]{candidate.getUser().getEmail()},
null,
null,
null,
null,
null,
null,
null,
null,
candidate.getID().longValue());
}
catch (ConfigurableEmailerException ex)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Error when sending the mail to " + candidate.getUser().getEmail() , ex);
}
}
else
{
SMSUtils smsUtils = (SMSUtils) ConfigMgr.getConfigObject("CONFIG.CUSTOM", "SMS");
String smsContent = MessagingUtils.getArticleContent(objTran, "AppSMSMessageTemplate");
if (smsContent == null)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Ignore sending SMS. smsContent is null ", this);
return;
}
smsContent = StringUtils.replaceParams (StringUtils.fromHTML(smsContent), prefixTransform);
try
{
smsUtils.sendSMS(smsContent, candidate.getPhone(), null, LOG);
LogMgr.log(LOG, LogLevel.PROCESSING1, "SMS sent to ", candidate.getPhone(), this);
}
catch (IOException ex)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, ex, "Error while sending AppSMSMessageTemplate");
throw new BusinessException("Error while sending SMS");
}
}
}
super.processForm(request, objTran, result, exceptions, createdBBCs, updatedBBCs);
}
private String getShortantURL(Long jobAppID)
{
String url = LoopbackHTTP.getRemoteAccessURL(DefaultUICustomiser.ANGULAR_BASE_PATH + "/message-engine/" + jobAppID);
return url;
}
}
\ No newline at end of file
......@@ -24,11 +24,24 @@
<MAP code="Client" class="performa.orm.Client" />
<MAP code="Company" class="performa.orm.Company" />
<MAP code="HiringTeam" class="performa.orm.HiringTeam" />
<MAP code="ChatAttachment" class="performa.orm.ChatAttachment" />
</NODE>
<NODE name="CONFIG.GLOBAL::Performa">
<PARAM name="HasWebsite" factory="Boolean" value="true"/>
<PARAM name="AutoUpgradeBatch_AutoDDL" factory="Boolean" value="true"/>
<PARAM name="AppMessageEmailer" factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="AppMessageMail"/>
<PARAM name="AppEmailEmailer" factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="AppEmailTemplate"/>
</NODE>
<NODE name="CONFIG.CUSTOM" factory="SystemConfiguration">
<PARENT factory="Named" nodename="CONFIG.GLOBAL"/>
<PARAM name="SMS" factory="Participant" class="performa.utils.SMSUtils">
<userName factory="MetaComponent" component="Secure.String" TextID="sms.username" Default=""/>
<password factory="MetaComponent" component="Secure.String" TextID="sms.password" Default=""/>
<simulate factory="Boolean"><eval factory="MetaComponent" component="Secure.String" TextID="sms.simulate" Default="true"/></simulate>
</PARAM>
</NODE>
<NODE name="DashboardTypes::Performa">
......@@ -101,6 +114,10 @@
<QueryType factory="String" name="All" value="performa.search.SearchJobApplication"/>
</NODE>
<NODE name="Send" factory="Participant" class="performa.ws.SendMessage" privilege="*">
<INHERITS nodename="SaveWebService::.*" mandatory="false"/>
</NODE>
<!-- Enum services -->
<NODE name="ResponseAction" factory="Participant" class="oneit.appservices.ws.services.EnumJSONService" enumClass="performa.orm.types.ResponseAction" privilege="*"/>
<NODE name="StageType" factory="Participant" class="oneit.appservices.ws.services.EnumJSONService" enumClass="performa.orm.types.StageType" privilege="*"/>
......
<?xml version="1.0" encoding="UTF-8"?>
<OBJECTS xmlns:oneit="http://www.1iT.com.au" name="">
<NODE factory="Vector" name="Script"><NODE class="oneit.appservices.upgrade.cms.CMSArticleUpdateOperation" factory="Participant" name="App Email Template">
<createSpecificIdentifier factory='String' value='T5BUKP4YC4DJ2GEFYHG4TTIAEZHI1C'/>
<articleIdentifiers factory="Array" class="java.lang.String">
<NODE factory="String" value="T5BUKP4YC4DJ2GEFYHG4TTIAEZHI1C"/>
</articleIdentifiers>
<createdLabel factory="String" value="T5BUKP4YC4DJ2GEFYHG4TTIAEZHI1C"/>
<newParentCategory factory="String" value="RESOURCE_LIBRARY"/>
<articleAttributeChanges factory="Map">
<NODE name="EmailTo" factory="Null"/>
<NODE name="EmailFrom" factory="String" value="matchd@info.com.au"/>
<NODE name="EmailSubject" factory="String" value="Message"/>
<NODE name="Shortcuts" factory="String" value="AppEmailTemplate"/>
<NODE name="EmailCC" factory="Null"/>
<NODE name="EmailBCC" factory="Null"/>
</articleAttributeChanges>
<ormAttributeChanges factory="Map">
<NODE name="PublishDate" factory="Date" value="2019-09-20 10:00:00"/>
<NODE name="WithdrawDate" factory="Date" value="2069-09-20 10:00:00"/>
<NODE name="Title" factory="String" value="App Email Template"/>
<NODE name="ShortTitle" factory="String" value="App Email Template"/>
<NODE name="SortOrder" factory="Integer" value="-38035449"/>
<NODE name="Type" factory="Enumerated" class="oneit.business.content.ArticleType" value="ARTICLE"/>
<NODE name="Template" factory="Enumerated" class="oneit.business.content.ArticleTemplate" value="EMAIL_TEMPLATE"/>
</ormAttributeChanges>
<content factory="Map"> <NODE name="Body" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<p></p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
<NODE name="Synopsis" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<p></p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
<NODE name="EmailBody" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="HTML Tidy, see www.w3.org" name="generator">
<title></title>
</head>
<body>
<p>Hi ${SecUser:FirstName} ${SecUser:LastName},</p>
<p>${Message:MessageContent}</p>
<p>Thanks,</p>
<p>${HiringTeam:HiringTeamName}</p>
</body>
</html>]]></NODE>
<NODE name="TransformedContent" factory="String"><![CDATA[<p>HI ${user.Name],</p><p>${message.MessageContent}</p><p>Thanks,</p><p>${hiringTeam.HiringTeamName}</p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
</content>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<OBJECTS xmlns:oneit="http://www.1iT.com.au" name="">
<NODE factory="Vector" name="Script"><NODE class="oneit.appservices.upgrade.cms.CMSArticleUpdateOperation" factory="Participant" name="App Message Mail">
<createSpecificIdentifier factory='String' value='Q9K1TA3IJODPNHU25FPLXRZT5SL3DH'/>
<articleIdentifiers factory="Array" class="java.lang.String">
<NODE factory="String" value="Q9K1TA3IJODPNHU25FPLXRZT5SL3DH"/>
</articleIdentifiers>
<createdLabel factory="String" value="Q9K1TA3IJODPNHU25FPLXRZT5SL3DH"/>
<newParentCategory factory="String" value="RESOURCE_LIBRARY"/>
<articleAttributeChanges factory="Map">
<NODE name="EmailTo" factory="Null"/>
<NODE name="EmailFrom" factory="String" value="matchd@info.com.au"/>
<NODE name="EmailSubject" factory="String" value="Message Alert"/>
<NODE name="Shortcuts" factory="String" value="AppMessageMail"/>
<NODE name="EmailCC" factory="Null"/>
<NODE name="EmailBCC" factory="Null"/>
</articleAttributeChanges>
<ormAttributeChanges factory="Map">
<NODE name="PublishDate" factory="Date" value="2019-09-20 00:00:00"/>
<NODE name="WithdrawDate" factory="Date" value="2069-09-20 00:00:00"/>
<NODE name="Title" factory="String" value="App Message Mail"/>
<NODE name="ShortTitle" factory="String" value="App Message Mail"/>
<NODE name="SortOrder" factory="Integer" value="-38035376"/>
<NODE name="Type" factory="Enumerated" class="oneit.business.content.ArticleType" value="ARTICLE"/>
<NODE name="Template" factory="Enumerated" class="oneit.business.content.ArticleTemplate" value="EMAIL_TEMPLATE"/>
</ormAttributeChanges>
<content factory="Map"> <NODE name="Body" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<p></p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
<NODE name="Synopsis" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<p></p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
<NODE name="EmailBody" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="HTML Tidy, see www.w3.org" name="generator">
<title></title>
</head>
<body>
<p>Hi ${SecUser:FirstName} ${SecUser:LastName},</p>
<p>You have received a new message. Click <a href="${link}">here</a> to see the message.</p>
<p>Thanks,</p>
<p>${HiringTeam:HiringTeamName}</p>
</body>
</html>]]></NODE>
<NODE name="TransformedContent" factory="String"><![CDATA[<p>Hi, ${user.Name},</p><p>You have received a new message. Click <a href="${link}">here</a> to see the message.</p><p>Thanks.</p><p>${hiringTeam.HiringTeamName}</p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
</content>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Please add following key file entries
sms.simulate=true
sms.username=OneIT004
sms.password=uGYk7fYZ3
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<OBJECTS xmlns:oneit="http://www.1iT.com.au" name="">
<NODE factory="Vector" name="Script"><NODE class="oneit.appservices.upgrade.cms.CMSArticleUpdateOperation" factory="Participant" name="App SMS Message Template">
<createSpecificIdentifier factory='String' value='4SQN7E9L8TCLZQ50WZXPX9V7X1PZOJ'/>
<articleIdentifiers factory="Array" class="java.lang.String">
<NODE factory="String" value="4SQN7E9L8TCLZQ50WZXPX9V7X1PZOJ"/>
</articleIdentifiers>
<createdLabel factory="String" value="4SQN7E9L8TCLZQ50WZXPX9V7X1PZOJ"/>
<newParentCategory factory="String" value="RESOURCE_LIBRARY"/>
<articleAttributeChanges factory="Map">
<NODE name="Exclude From Search" factory="Boolean" value="false"/>
<NODE name="Additional CSS Class" factory="Null"/>
<NODE name="Exclude From Sitemap" factory="Boolean" value="false"/>
<NODE name="Exclude from SEO Indexing" factory="Boolean" value="false"/>
<NODE name="Allow Disable" factory="Boolean" value="false"/>
<NODE name="Menu Icon CSS" factory="Null"/>
<NODE name="Add Brackline Separator" factory="Boolean" value="false"/>
<NODE name="Shortcuts" factory="String" value="AppSMSMessageTemplate"/>
<NODE name="Menu Title" factory="Null"/>
<NODE name="Exclude From Navigation" factory="Boolean" value="false"/>
</articleAttributeChanges>
<ormAttributeChanges factory="Map">
<NODE name="PublishDate" factory="Date" value="2019-09-20 10:00:00"/>
<NODE name="WithdrawDate" factory="Date" value="2069-09-20 10:00:00"/>
<NODE name="Title" factory="String" value="App SMS Message Template"/>
<NODE name="ShortTitle" factory="String" value="App SMS Message Template"/>
<NODE name="SortOrder" factory="Integer" value="-38035456"/>
<NODE name="Type" factory="Enumerated" class="oneit.business.content.ArticleType" value="ARTICLE"/>
<NODE name="Template" factory="Enumerated" class="oneit.business.content.ArticleTemplate" value="STANDARD"/>
</ormAttributeChanges>
<content factory="Map"> <NODE name="Body" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="HTML Tidy, see www.w3.org" name="generator">
<title></title>
</head>
<body>
<p>Hi ${SecUser:FirstName} ${SecUser:LastName},</p>
<p>You have received a new message. Click following link to see the message.</p>
<p><a href="${link}">${link}</a></p>
<p>Thanks,</p>
<p>${HiringTeam:HiringTeamName}</p>
</body>
</html>]]></NODE>
<NODE name="TransformedContent" factory="String"><![CDATA[<p>Hi ${user.Name},</p><p>You have received a new message. Click following link to see the message.</p><p>&lt;a href="${link}"&gt;here&lt;/a&gt;</p><p>Thanks,</p><p>${hiringTeam.HiringTeamName}</p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
<NODE name="Synopsis" factory="Map">
<NODE name="Content" factory="String"><![CDATA[<p></p>]]></NODE>
<NODE name="IncludeContent" factory="Boolean" value="true"/>
</NODE>
</content>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment