Commit 2dad92bb by Nilu

Messaging engine email sending and replacing placeholder tags

parent e5f514bb
...@@ -14,9 +14,12 @@ import oneit.objstore.ObjectTransaction; ...@@ -14,9 +14,12 @@ import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException; import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.LessThanEqualFilter; import oneit.objstore.rdbms.filters.LessThanEqualFilter;
import oneit.utils.InitialisationException; import oneit.utils.InitialisationException;
import oneit.utils.StringUtils;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.orm.JobApplication;
import performa.orm.ScheduledEmail; import performa.orm.ScheduledEmail;
import performa.orm.SentEmail; import performa.orm.SentEmail;
import performa.orm.types.PlaceholderOptions;
public class MessagingEngineBatch extends ORMBatch implements InitialisationParticipant public class MessagingEngineBatch extends ORMBatch implements InitialisationParticipant
...@@ -34,25 +37,48 @@ public class MessagingEngineBatch extends ORMBatch implements InitialisationPart ...@@ -34,25 +37,48 @@ public class MessagingEngineBatch extends ORMBatch implements InitialisationPart
for (ScheduledEmail scheduledEmail : scheduledEmails) for (ScheduledEmail scheduledEmail : scheduledEmails)
{ {
String messageContent = scheduledEmail.getMessageContent(); LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "Starting to create email for scheduled email : " , scheduledEmail);
JobApplication jobApplication = scheduledEmail.getJobApplication();
// replace tags // replace tags
String messageContent = StringUtils.replace(scheduledEmail.getMessageContent(),
new String[] {PlaceholderOptions.FIRST_NAME.getPlaceholder(),
PlaceholderOptions.SURNAME.getPlaceholder(),
PlaceholderOptions.EMAIL_ADDRESS.getPlaceholder(),
PlaceholderOptions.LOCATION.getPlaceholder(),
PlaceholderOptions.JOB_TITLE.getPlaceholder(),
PlaceholderOptions.JOB_REFERENCE.getPlaceholder()},
new String[] {jobApplication.getCandidate().getFirstName(),
jobApplication.getCandidate().getUser().getLastName(),
jobApplication.getCandidate().getUser().getEmail(),
jobApplication.getJob().getGoogleAddressText(),
jobApplication.getJob().getJobTitle(),
jobApplication.getJob().getReferenceNumber()});
LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "Replaced tags of message content : " , messageContent);
TextDataSource mesgBodyDataSource = new TextDataSource(messageContent); TextDataSource mesgBodyDataSource = new TextDataSource(StringUtils.fromHTML(messageContent));
String toEmail = scheduledEmail.getJobApplication().getCandidate().getUser().getEmail(); String toEmail = jobApplication.getCandidate().getUser().getEmail();
String fromEmail = scheduledEmail.getJobApplication().getJob().getCreatedBy().getUser().getEmail(); String fromEmail = jobApplication.getJob().getCreatedBy().getUser().getEmail();
SentEmail sentEmail = SentEmail.createSentEmail(ot); SentEmail sentEmail = SentEmail.createSentEmail(ot);
emailEngine.sendEmail(new String[] {toEmail}, fromEmail, scheduledEmail.getSubject() , new DataSource[]{mesgBodyDataSource}); emailEngine.sendEmail(new String[] {toEmail}, fromEmail, scheduledEmail.getSubject() , new DataSource[]{mesgBodyDataSource});
LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "Email sent to : " , toEmail, " from : ", fromEmail);
sentEmail.setSubject(scheduledEmail.getSubject()); sentEmail.setSubject(scheduledEmail.getSubject());
sentEmail.setSentDate(new Date()); sentEmail.setSentDate(new Date());
sentEmail.setApplicationStatus(scheduledEmail.getApplicationStatus()); sentEmail.setApplicationStatus(scheduledEmail.getApplicationStatus());
sentEmail.setMessageContent(messageContent); sentEmail.setMessageContent(messageContent);
sentEmail.setEmailTo(toEmail); sentEmail.setEmailTo(toEmail);
sentEmail.setJobApplication(scheduledEmail.getJobApplication()); sentEmail.setJobApplication(jobApplication);
LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "SentEmail object created to store sent email details : " , sentEmail);
scheduledEmail.delete(); scheduledEmail.delete();
} }
LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "End of Messaging Engine Batch");
} }
@Override @Override
......
...@@ -67,7 +67,7 @@ public class JobApplication extends BaseJobApplication ...@@ -67,7 +67,7 @@ public class JobApplication extends BaseJobApplication
TimeZone jobTimeZone = getJob().getHiringTeam().getCompany().getDefaultTimeZone(); TimeZone jobTimeZone = getJob().getHiringTeam().getCompany().getDefaultTimeZone();
Calendar cal = new GregorianCalendar(); Calendar cal = new GregorianCalendar();
cal.setTime(now); cal.setTime(scheduledDate);
scheduledDate = MessagingUtils.getWithinBusinessHours(cal, jobTimeZone != null ? java.util.TimeZone.getTimeZone(jobTimeZone.getTimeZoneCode()) : cal.getTimeZone()); scheduledDate = MessagingUtils.getWithinBusinessHours(cal, jobTimeZone != null ? java.util.TimeZone.getTimeZone(jobTimeZone.getTimeZoneCode()) : cal.getTimeZone());
} }
......
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