Commit 2cdf6b7c by Nilu

schedule message after job status change

parent f4fc03d9
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
<column name="object_id" type="Long" nullable="false" length="11"/> <column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/> <column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/> <column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="true" length="200"/> <column name="subject" type="String" nullable="false" length="200"/>
<column name="application_status" type="String" nullable="true" length="200"/> <column name="application_status" type="String" nullable="false" length="200"/>
<column name="delay" type="Double" nullable="true"/> <column name="delay_hrs" type="Long" nullable="true"/>
<column name="delay_min" type="Long" nullable="true"/>
<column name="variance" type="Long" nullable="true"/> <column name="variance" type="Long" nullable="true"/>
<column name="business_hours_only" type="Boolean" nullable="true"/> <column name="business_hours_only" type="Boolean" nullable="true"/>
<column name="message_content" type="CLOB" nullable="true"/> <column name="message_content" type="CLOB" nullable="false"/>
</NODE> </NODE>
</NODE></OBJECTS> </NODE></OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_scheduled_email</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="false" length="200"/>
<column name="scheduled_date" type="Date" nullable="false"/>
<column name="application_status" type="String" nullable="false" length="200"/>
<column name="message_content" type="CLOB" nullable="false"/>
<column name="job_application_id" type="Long" length="11" nullable="false"/>
<column name="message_template_id" type="Long" length="11" nullable="true"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_scheduled_email" indexName="idx_tl_scheduled_email_job_application_id" isUnique="false"><column name="job_application_id"/></NODE>
</NODE></OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_sent_email</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="false" length="200"/>
<column name="sent_date" type="Date" nullable="false"/>
<column name="application_status" type="String" nullable="false" length="200"/>
<column name="message_content" type="CLOB" nullable="false"/>
<column name="email_to" type="CLOB" nullable="false"/>
<column name="job_application_id" type="Long" length="11" nullable="false"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_sent_email" indexName="idx_tl_sent_email_job_application_id" isUnique="false"><column name="job_application_id"/></NODE>
</NODE></OBJECTS>
\ No newline at end of file
...@@ -8,12 +8,13 @@ CREATE TABLE tl_message_template ( ...@@ -8,12 +8,13 @@ CREATE TABLE tl_message_template (
object_last_updated_date datetime DEFAULT getdate() NOT NULL , object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL object_created_date datetime DEFAULT getdate() NOT NULL
, ,
subject varchar(200) NULL, subject varchar(200) NOT NULL,
application_status varchar(200) NULL, application_status varchar(200) NOT NULL,
delay numeric(20,5) NULL, delay_hrs numeric(12) NULL,
delay_min numeric(12) NULL,
variance numeric(12) NULL, variance numeric(12) NULL,
business_hours_only char(1) NULL, business_hours_only char(1) NULL,
message_content text NULL message_content text NOT NULL
); );
......
-- DROP TABLE tl_scheduled_email;
CREATE TABLE tl_scheduled_email (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
subject varchar(200) NOT NULL,
scheduled_date datetime NOT NULL,
application_status varchar(200) NOT NULL,
message_content text NOT NULL,
job_application_id numeric(12) NOT NULL,
message_template_id numeric(12) NULL
);
ALTER TABLE tl_scheduled_email ADD
CONSTRAINT PK_tl_scheduled_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_scheduled_email_job_application_id
ON tl_scheduled_email (job_application_id);
-- DROP TABLE tl_sent_email;
CREATE TABLE tl_sent_email (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
subject varchar(200) NOT NULL,
sent_date datetime NOT NULL,
application_status varchar(200) NOT NULL,
message_content text NOT NULL,
email_to text NOT NULL,
job_application_id numeric(12) NOT NULL
);
ALTER TABLE tl_sent_email ADD
CONSTRAINT PK_tl_sent_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_sent_email_job_application_id
ON tl_sent_email (job_application_id);
...@@ -9,12 +9,13 @@ CREATE TABLE tl_message_template ( ...@@ -9,12 +9,13 @@ CREATE TABLE tl_message_template (
object_last_updated_date date DEFAULT SYSDATE NOT NULL , object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL object_created_date date DEFAULT SYSDATE NOT NULL
, ,
subject varchar2(200) NULL, subject varchar2(200) NOT NULL,
application_status varchar2(200) NULL, application_status varchar2(200) NOT NULL,
delay number(20,5) NULL, delay_hrs number(12) NULL,
delay_min number(12) NULL,
variance number(12) NULL, variance number(12) NULL,
business_hours_only char(1) NULL, business_hours_only char(1) NULL,
message_content clob NULL message_content clob NOT NULL
); );
......
-- DROP TABLE tl_scheduled_email;
CREATE TABLE tl_scheduled_email (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
subject varchar2(200) NOT NULL,
scheduled_date date NOT NULL,
application_status varchar2(200) NOT NULL,
message_content clob NOT NULL,
job_application_id number(12) NOT NULL,
message_template_id number(12) NULL
);
ALTER TABLE tl_scheduled_email ADD
CONSTRAINT PK_tl_scheduled_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_scheduled_email_job_application_id
ON tl_scheduled_email (job_application_id);
-- DROP TABLE tl_sent_email;
CREATE TABLE tl_sent_email (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
subject varchar2(200) NOT NULL,
sent_date date NOT NULL,
application_status varchar2(200) NOT NULL,
message_content clob NOT NULL,
email_to clob NOT NULL,
job_application_id number(12) NOT NULL
);
ALTER TABLE tl_sent_email ADD
CONSTRAINT PK_tl_sent_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_sent_email_job_application_id
ON tl_sent_email (job_application_id);
...@@ -9,12 +9,13 @@ CREATE TABLE tl_message_template ( ...@@ -9,12 +9,13 @@ CREATE TABLE tl_message_template (
object_last_updated_date timestamp DEFAULT NOW() NOT NULL , object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL object_created_date timestamp DEFAULT NOW() NOT NULL
, ,
subject varchar(200) NULL, subject varchar(200) NOT NULL,
application_status varchar(200) NULL, application_status varchar(200) NOT NULL,
delay numeric(20,5) NULL, delay_hrs numeric(12) NULL,
delay_min numeric(12) NULL,
variance numeric(12) NULL, variance numeric(12) NULL,
business_hours_only char(1) NULL, business_hours_only char(1) NULL,
message_content text NULL message_content text NOT NULL
); );
......
-- @AutoRun
-- drop table tl_scheduled_email;
CREATE TABLE tl_scheduled_email (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
subject varchar(200) NOT NULL,
scheduled_date timestamp NOT NULL,
application_status varchar(200) NOT NULL,
message_content text NOT NULL,
job_application_id numeric(12) NOT NULL,
message_template_id numeric(12) NULL
);
ALTER TABLE tl_scheduled_email ADD
CONSTRAINT pk_tl_scheduled_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_scheduled_email_job_application_id
ON tl_scheduled_email (job_application_id);
-- @AutoRun
-- drop table tl_sent_email;
CREATE TABLE tl_sent_email (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
subject varchar(200) NOT NULL,
sent_date timestamp NOT NULL,
application_status varchar(200) NOT NULL,
message_content text NOT NULL,
email_to text NOT NULL,
job_application_id numeric(12) NOT NULL
);
ALTER TABLE tl_sent_email ADD
CONSTRAINT pk_tl_sent_email PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_tl_sent_email_job_application_id
ON tl_sent_email (job_application_id);
package performa.batch;
import java.util.Date;
import oneit.appservices.batch.ORMBatch;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.LessThanEqualFilter;
import oneit.utils.parsers.FieldException;
import performa.orm.ScheduledEmail;
public class MessagingEngineBatch extends ORMBatch
{
public static LoggingArea MESSAGING_ENGINE_BATCH = LoggingArea.createLoggingArea("MessagingEngineBatch");
@Override
public void run(ObjectTransaction ot) throws StorageException, FieldException
{
LogMgr.log (MESSAGING_ENGINE_BATCH, LogLevel.PROCESSING1, "RUNNING Messaging Engine Batch");
ScheduledEmail[] scheduledEmails = ScheduledEmail.SearchByAll().andScheduledDate(new LessThanEqualFilter<>(new Date())).search(ot);
for (ScheduledEmail scheduledEmail : scheduledEmails)
{
scheduledEmail.delete();
}
}
}
package performa.orm; package performa.orm;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import oneit.logging.LoggingArea; import oneit.logging.LoggingArea;
import oneit.objstore.rdbms.filters.EqualsFilter; import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.rdbms.filters.IsNotNullFilter; import oneit.objstore.rdbms.filters.IsNotNullFilter;
import oneit.objstore.rdbms.filters.NotEqualsFilter;
import oneit.security.SecUser;
import oneit.utils.BusinessException; import oneit.utils.BusinessException;
import oneit.utils.CollectionUtils; import oneit.utils.CollectionUtils;
import oneit.utils.StringUtils; import oneit.utils.StringUtils;
import oneit.utils.filter.Filter; import oneit.utils.filter.Filter;
import oneit.utils.math.NullArith; import oneit.utils.math.NullArith;
import oneit.utils.parsers.FieldException;
import performa.orm.types.JobStatus; import performa.orm.types.JobStatus;
import performa.orm.types.TimeZone;
import performa.utils.Utils; import performa.utils.Utils;
...@@ -178,4 +175,9 @@ public class Company extends BaseCompany ...@@ -178,4 +175,9 @@ public class Company extends BaseCompany
return pipelineCompany().toHiringTeams(filter).uniqueVals(); return pipelineCompany().toHiringTeams(filter).uniqueVals();
} }
public TimeZone getDefaultTimeZone()
{
return pipelineCompany().toHiringTeams().toTimeZone().val();
}
} }
\ No newline at end of file
...@@ -17,6 +17,7 @@ import oneit.utils.math.Rounding; ...@@ -17,6 +17,7 @@ import oneit.utils.math.Rounding;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.chart.RingChart; import performa.chart.RingChart;
import performa.orm.types.*; import performa.orm.types.*;
import performa.orm.types.TimeZone;
import performa.utils.*; import performa.utils.*;
...@@ -31,6 +32,57 @@ public class JobApplication extends BaseJobApplication ...@@ -31,6 +32,57 @@ public class JobApplication extends BaseJobApplication
// Do not add any code to this, always put it in initialiseNewObject // Do not add any code to this, always put it in initialiseNewObject
} }
@Override
public void preCommit(boolean willBeStored) throws Exception
{
super.preCommit(willBeStored);
if(willBeStored)
{
JobApplication old = (JobApplication) getEarliestBackup();
// when application status changed
if(!CollectionUtils.equals(old.getApplicationStatus(), getApplicationStatus()))
{
// delete previously scheduled emails for previous application status
Filter<ScheduledEmail> filter = ScheduledEmail.SearchByAll().andApplicationStatus(new EqualsFilter<>(old.getApplicationStatus()));
pipelineJobApplication().toScheduledEmails(filter).uniqueVals().stream().forEach((scheduledEmail) -> {
scheduledEmail.delete();
});
// create scheduled emails for new application status
MessageTemplate[] templates = MessageTemplate.SearchByAll().andApplicationStatus(new EqualsFilter<>(getApplicationStatus())).search(getTransaction());
for(MessageTemplate template : templates)
{
ScheduledEmail scheduledEmail = ScheduledEmail.createScheduledEmail(getTransaction());
Date now = new Date();
int variance = MessagingUtils.randInt(0, template.getVariance());
Date scheduledDate = DateDiff.add(now, Calendar.MINUTE, template.getDelayInMin() + variance);
if(template.getBusinessHoursOnly())
{
TimeZone jobTimeZone = getJob().getHiringTeam().getCompany().getDefaultTimeZone();
Calendar cal = new GregorianCalendar();
cal.setTime(now);
scheduledDate = MessagingUtils.getWithinBusinessHours(cal, jobTimeZone != null ? java.util.TimeZone.getTimeZone(jobTimeZone.getTimeZoneCode()) : cal.getTimeZone());
}
scheduledEmail.setScheduledDate(scheduledDate);
scheduledEmail.setSubject(template.getSubject());
scheduledEmail.setMessageContent(template.getMessageContent());
scheduledEmail.setApplicationStatus(getApplicationStatus());
scheduledEmail.setMessageTemplate(template);
addToScheduledEmails(scheduledEmail);
}
}
}
}
public static JobApplication createNewApplication(Candidate candidate, Job job) throws StorageException, FieldException public static JobApplication createNewApplication(Candidate candidate, Job job) throws StorageException, FieldException
{ {
......
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'> <ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="JobApplication" package="performa.orm"> <BUSINESSCLASS name="JobApplication" package="performa.orm">
<IMPORT value="performa.orm.types.*"/> <IMPORT value="performa.orm.types.*"/>
<MULTIPLEREFERENCE name="AssessmentCriteriaAnswers" type="AssessmentCriteriaAnswer" backreferenceName="JobApplication" /> <MULTIPLEREFERENCE name="AssessmentCriteriaAnswers" type="AssessmentCriteriaAnswer" backreferenceName="JobApplication" />
<MULTIPLEREFERENCE name="Notes" type="Note" backreferenceName="JobApplication" /> <MULTIPLEREFERENCE name="Notes" type="Note" backreferenceName="JobApplication" />
<MULTIPLEREFERENCE name="ScheduledEmails" type="ScheduledEmail" backreferenceName="JobApplication" />
<MULTIPLEREFERENCE name="SentEmails" type="SentEmail" backreferenceName="JobApplication" />
<TRANSIENT name="AppProcessOption" type="AppProcessOption" attribHelper="EnumeratedAttributeHelper"/> <TRANSIENT name="AppProcessOption" type="AppProcessOption" attribHelper="EnumeratedAttributeHelper"/>
<TRANSIENT name="OverallRank" type="Integer" /> <TRANSIENT name="OverallRank" type="Integer" />
......
package performa.orm; package performa.orm;
import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.utils.*;
import performa.orm.types.*;
import performa.orm.*;
public class MessageTemplate extends BaseMessageTemplate public class MessageTemplate extends BaseMessageTemplate
{ {
...@@ -25,5 +10,9 @@ public class MessageTemplate extends BaseMessageTemplate ...@@ -25,5 +10,9 @@ public class MessageTemplate extends BaseMessageTemplate
{ {
// Do not add any code to this, always put it in initialiseNewObject // Do not add any code to this, always put it in initialiseNewObject
} }
}
public int getDelayInMin()
{
return (getDelayHrs() * 60) + getDelayMin();
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ROOT> <ROOT>
<BUSINESSCLASS name="MessageTemplate" package="performa.orm"> <BUSINESSCLASS name="MessageTemplate" package="performa.orm">
<IMPORT value="performa.orm.types.*"/> <IMPORT value="performa.orm.types.*"/>
<IMPORT value="performa.orm.*"/> <IMPORT value="performa.orm.*"/>
<TABLE name="tl_message_template" tablePrefix="object" polymorphic="FALSE"> <TABLE name="tl_message_template" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="Subject" type="String" dbcol="subject" mandatory="false" length="200" /> <ATTRIB name="Subject" type="String" dbcol="subject" mandatory="true" length="200" />
<ATTRIB name="ApplicationStatus" type="ApplicationStatus" dbcol="application_status" attribHelper="EnumeratedAttributeHelper" defaultValue="ApplicationStatus.DRAFT" mandatory="false"/> <ATTRIB name="ApplicationStatus" type="ApplicationStatus" dbcol="application_status" mandatory="true" defaultValue="ApplicationStatus.DRAFT" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="Delay" type="Double" dbcol="delay" mandatory="false" /> <ATTRIB name="DelayHrs" type="Integer" dbcol="delay_hrs" mandatory="false" defaultValue="0" />
<ATTRIB name="Variance" type="Integer" dbcol="variance" mandatory="false" /> <ATTRIB name="DelayMin" type="Integer" dbcol="delay_min" mandatory="false" defaultValue="0" />
<ATTRIB name="BusinessHoursOnly" type="Boolean" dbcol="business_hours_only" mandatory="false" /> <ATTRIB name="Variance" type="Integer" dbcol="variance" mandatory="false" defaultValue="0" />
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="false" /> <ATTRIB name="BusinessHoursOnly" type="Boolean" dbcol="business_hours_only" mandatory="false" defaultValue="Boolean.FALSE"/>
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="true" />
</TABLE> </TABLE>
......
package performa.orm;
public class ScheduledEmail extends BaseScheduledEmail
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public ScheduledEmail ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="ScheduledEmail" package="performa.orm">
<IMPORT value="performa.orm.types.*"/>
<TABLE name="tl_scheduled_email" tablePrefix="object">
<ATTRIB name="Subject" type="String" dbcol="subject" mandatory="true" length="200" />
<ATTRIB name="ScheduledDate" type="Date" dbcol="scheduled_date" mandatory="true" />
<ATTRIB name="ApplicationStatus" type="ApplicationStatus" dbcol="application_status" mandatory="true" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="true" />
<SINGLEREFERENCE name="JobApplication" type="JobApplication" dbcol="job_application_id" backreferenceName="ScheduledEmails" mandatory="true"/>
<SINGLEREFERENCE name="MessageTemplate" type="MessageTemplate" dbcol="message_template_id" />
</TABLE>
<SEARCH type="All" paramFilter="tl_scheduled_email.object_id is not null" orderBy="tl_scheduled_email.object_id">
</SEARCH>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
package performa.orm;
public class SentEmail extends BaseSentEmail
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public SentEmail ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="SentEmail" package="performa.orm">
<IMPORT value="performa.orm.types.*"/>
<TABLE name="tl_sent_email" tablePrefix="object">
<ATTRIB name="Subject" type="String" dbcol="subject" mandatory="true" length="200" />
<ATTRIB name="SentDate" type="Date" dbcol="sent_date" mandatory="true" />
<ATTRIB name="ApplicationStatus" type="ApplicationStatus" dbcol="application_status" mandatory="true" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="true" />
<ATTRIB name="EmailTo" type="String" dbcol="email_to" mandatory="true" />
<SINGLEREFERENCE name="JobApplication" type="JobApplication" dbcol="job_application_id" backreferenceName="SentEmails" mandatory="true"/>
</TABLE>
<SEARCH type="All" paramFilter="tl_scheduled_email.object_id is not null" orderBy="tl_scheduled_email.object_id">
</SEARCH>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
package performa.utils;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
public class MessagingUtils
{
private static final Random rand = new Random();
public static int WORK_START_HOUR = 9;
public static int WORK_STOP_HOUR = 17;
public static int randInt(int min, int max)
{
return rand.nextInt((max - min) + 1) + min;
}
public static Date getWithinBusinessHours(Calendar cal, TimeZone timeZone)
{
while (!isWorkingDay(cal))
{
cal.add(Calendar.DAY_OF_MONTH, 1);
}
Calendar calDayStart = new GregorianCalendar();
Calendar calDayEnd = new GregorianCalendar();
calDayStart.setTime(cal.getTime());
calDayEnd.setTime(cal.getTime());
startOfWorkingDay(calDayStart, timeZone);
endOfWorkingDay(calDayEnd, timeZone);
if(cal.before(calDayStart))
{
cal.setTimeZone(timeZone);
cal.set(GregorianCalendar.HOUR_OF_DAY, WORK_START_HOUR);
}
else if(cal.after(calDayEnd))
{
cal.setTimeZone(timeZone);
cal.add(Calendar.DAY_OF_MONTH, 1);
cal.set(GregorianCalendar.HOUR_OF_DAY, WORK_START_HOUR);
while (!isWorkingDay(cal))
{
cal.add(Calendar.DAY_OF_MONTH, 1);
}
}
return cal.getTime();
}
public static void startOfWorkingDay(Calendar cal, TimeZone timeZone)
{
cal.setTimeZone(timeZone);
cal.set(GregorianCalendar.MILLISECOND, 0);
cal.set(GregorianCalendar.SECOND, 0);
cal.set(GregorianCalendar.MINUTE, 0);
cal.set(GregorianCalendar.HOUR_OF_DAY, WORK_START_HOUR);
}
public static void endOfWorkingDay(Calendar cal, TimeZone timeZone)
{
cal.setTimeZone(timeZone);
cal.set(GregorianCalendar.MILLISECOND, 0);
cal.set(GregorianCalendar.SECOND, 0);
cal.set(GregorianCalendar.MINUTE, 0);
cal.set(GregorianCalendar.HOUR_OF_DAY, WORK_STOP_HOUR);
}
public static boolean isWorkingDay(Calendar day)
{
int dayOfWeek = day.get(Calendar.DAY_OF_WEEK);
return !(dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
}
}
\ No newline at end of file
...@@ -66,10 +66,10 @@ ...@@ -66,10 +66,10 @@
<oneit:skin tagName="layout_row"> <oneit:skin tagName="layout_row">
<oneit:layout_label width="1"> <oneit:layout_label width="1">
<oneit:ormlabel obj="<%= messageTemplate %>" field="Delay"/> <oneit:ormlabel obj="<%= messageTemplate %>" field="DelayHrs"/>
</oneit:layout_label> </oneit:layout_label>
<oneit:layout_field width="1"> <oneit:layout_field width="1">
<oneit:ormInput obj="<%= messageTemplate %>" attributeName="Delay" style="width:30%" /><span>Hours</span> <oneit:ormInput obj="<%= messageTemplate %>" attributeName="DelayHrs" style="width:30%" /><span>Hours</span>
</oneit:layout_field> </oneit:layout_field>
</oneit:skin> </oneit:skin>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun --> <!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector"> <OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation"> <NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_message_template</tableName> <tableName factory="String">tl_message_template</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/> <column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/> <column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/> <column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="true" length="200"/> <column name="subject" type="String" nullable="false" length="200"/>
<column name="application_status" type="String" nullable="true" length="200"/> <column name="application_status" type="String" nullable="false" length="200"/>
<column name="delay" type="Double" nullable="true"/> <column name="delay_hrs" type="Long" nullable="true"/>
<column name="delay_min" type="Long" nullable="true"/>
<column name="variance" type="Long" nullable="true"/> <column name="variance" type="Long" nullable="true"/>
<column name="business_hours_only" type="Boolean" nullable="true"/> <column name="business_hours_only" type="Boolean" nullable="true"/>
<column name="message_content" type="CLOB" nullable="true"/> <column name="message_content" type="CLOB" nullable="false"/>
</NODE> </NODE>
</NODE></OBJECTS> </NODE>
\ No newline at end of file </OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_scheduled_email</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="false" length="200"/>
<column name="scheduled_date" type="Date" nullable="false"/>
<column name="application_status" type="String" nullable="false" length="200"/>
<column name="message_content" type="CLOB" nullable="false"/>
<column name="job_application_id" type="Long" length="11" nullable="false"/>
<column name="message_template_id" type="Long" length="11" nullable="true"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_scheduled_email" indexName="idx_tl_scheduled_email_job_application_id" isUnique="false">
<column name="job_application_id"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_sent_email</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="subject" type="String" nullable="false" length="200"/>
<column name="sent_date" type="Date" nullable="false"/>
<column name="application_status" type="String" nullable="false" length="200"/>
<column name="message_content" type="CLOB" nullable="false"/>
<column name="email_to" type="CLOB" nullable="false"/>
<column name="job_application_id" type="Long" length="11" nullable="false"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_sent_email" indexName="idx_tl_sent_email_job_application_id" isUnique="false">
<column name="job_application_id"/>
</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