Commit 319e57c2 by nilu

data migration to support new workflow ORM changes

parent d0bc44ea
......@@ -19,6 +19,7 @@
<column name="message_content" type="CLOB" nullable="false"/>
<column name="template_type" type="String" nullable="true" length="200"/>
<column name="is_global_template" type="Boolean" nullable="true"/>
<column name="is_system_generated" type="Boolean" nullable="true"/>
<column name="hiring_team_id" type="Long" length="11" nullable="true"/>
</NODE>
......
......@@ -21,6 +21,7 @@
<column name="thank_you_secondary_text" type="CLOB" nullable="true"/>
<column name="job_outline_button_text" type="CLOB" nullable="true"/>
<column name="is_global_template" type="Boolean" nullable="true"/>
<column name="is_system_generated" type="Boolean" nullable="true"/>
<column name="withdrawal_message_id" type="Long" length="11" nullable="true"/>
<column name="hiring_team_id" type="Long" length="11" nullable="true"/>
</NODE>
......
......@@ -19,6 +19,7 @@ CREATE TABLE tl_message_template (
message_content text NOT NULL,
template_type varchar(200) NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
hiring_team_id numeric(12) NULL
);
......
......@@ -21,6 +21,7 @@ CREATE TABLE tl_work_flow_template (
thank_you_secondary_text text NULL,
job_outline_button_text text NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
withdrawal_message_id numeric(12) NULL,
hiring_team_id numeric(12) NULL
);
......
......@@ -20,6 +20,7 @@ CREATE TABLE tl_message_template (
message_content clob NOT NULL,
template_type varchar2(200) NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
hiring_team_id number(12) NULL
);
......
......@@ -22,6 +22,7 @@ CREATE TABLE tl_work_flow_template (
thank_you_secondary_text clob NULL,
job_outline_button_text clob NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
withdrawal_message_id number(12) NULL,
hiring_team_id number(12) NULL
);
......
......@@ -20,6 +20,7 @@ CREATE TABLE tl_message_template (
message_content text NOT NULL,
template_type varchar(200) NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
hiring_team_id numeric(12) NULL
);
......
......@@ -22,6 +22,7 @@ CREATE TABLE tl_work_flow_template (
thank_you_secondary_text text NULL,
job_outline_button_text text NULL,
is_global_template char(1) NULL,
is_system_generated char(1) NULL,
withdrawal_message_id numeric(12) NULL,
hiring_team_id numeric(12) NULL
);
......
......@@ -202,6 +202,7 @@ public abstract class BaseWorkFlowMessage extends BaseBusinessClass
Map metaInfo = new HashMap ();
metaInfo.put ("dbcol", "business_hours_only");
metaInfo.put ("defaultValue", "Boolean.FALSE");
metaInfo.put ("mandatory", "false");
metaInfo.put ("name", "BusinessHoursOnly");
metaInfo.put ("type", "Boolean");
......@@ -258,7 +259,7 @@ public abstract class BaseWorkFlowMessage extends BaseBusinessClass
_Delay = (String)(HELPER_Delay.initialise (_Delay));
_Variance = (String)(HELPER_Variance.initialise (_Variance));
_BusinessHoursOnly = (Boolean)(HELPER_BusinessHoursOnly.initialise (_BusinessHoursOnly));
_BusinessHoursOnly = (Boolean)(Boolean.FALSE);
_IsWithdrawalMessage = (Boolean)(HELPER_IsWithdrawalMessage.initialise (_IsWithdrawalMessage));
}
......
......@@ -17,6 +17,7 @@
<ATTRIB name="MessageContent" type="String" dbcol="message_content" mandatory="true" />
<ATTRIB name="TemplateType" type="TemplateType" dbcol="template_type" attribHelper="EnumeratedAttributeHelper" mandatory="false"/>
<ATTRIB name="IsGlobalTemplate" type="Boolean" dbcol="is_global_template" mandatory="false"/>
<ATTRIB name="IsSystemGenerated" type="Boolean" dbcol="is_system_generated" mandatory="false" defaultValue="Boolean.FALSE"/>
<SINGLEREFERENCE name="HiringTeam" type="HiringTeam" dbcol="hiring_team_id" backreferenceName="MessageTemplates" mandatory="false"/>
......
......@@ -9,7 +9,7 @@
<ATTRIB name="Delay" type="String" dbcol="delay" mandatory="false"/>
<ATTRIB name="Variance" type="String" dbcol="variance" mandatory="false"/>
<ATTRIB name="BusinessHoursOnly" type="Boolean" dbcol="business_hours_only" mandatory="false"/>
<ATTRIB name="BusinessHoursOnly" type="Boolean" dbcol="business_hours_only" mandatory="false" defaultValue="Boolean.FALSE"/>
<ATTRIB name="IsWithdrawalMessage" type="Boolean" dbcol="is_withdrawal_message" mandatory="false"/>
<SINGLEREFERENCE name="MessageTemplate" type="MessageTemplate" dbcol="message_template_id" />
......
......@@ -23,6 +23,7 @@
<ATTRIB name="ThankYouSecondaryText" type="String" dbcol="thank_you_secondary_text" mandatory="false" defaultValue='"We will get in touch with you soon"'/>
<ATTRIB name="JobOutlineButtonText" type="String" dbcol="job_outline_button_text" mandatory="false" defaultValue='"Continue"'/>
<ATTRIB name="IsGlobalTemplate" type="Boolean" dbcol="is_global_template" mandatory="false"/>
<ATTRIB name="IsSystemGenerated" type="Boolean" dbcol="is_system_generated" mandatory="false" defaultValue="Boolean.FALSE"/>
<SINGLEREFERENCE name="WithdrawalMessage" type="WorkFlowMessage" dbcol="withdrawal_message_id" />
<SINGLEREFERENCE name="HiringTeam" type="HiringTeam" dbcol="hiring_team_id" backreferenceName="WorkFlowTemplates" mandatory="false"/>
......
......@@ -41,14 +41,14 @@ public class StageType extends AbstractEnumerated
public static final StageType DIVERSITY = new StageType ("DIVERSITY", "DIVERSITY", "Diversity", false);
public static final StageType SUCCESSFULL = new StageType ("SUCCESSFULL", "SUCCESSFULL", "Successfull", false);
public static final StageType SUCCESSFUL = new StageType ("SUCCESSFUL", "SUCCESSFUL", "Successful", false);
public static final StageType UNSUITABLE = new StageType ("UNSUITABLE", "UNSUITABLE", "Unsuitable", false);
public static final StageType WITHDREW = new StageType ("WITHDREW", "WITHDREW", "Withdrew", false);
private static final StageType[] allStageTypes =
new StageType[] { POST_INGEST,INCOMPLETE,REFERENCE_CHECK,SCREENING_CHECK,VIDEO_INTERVIEW,INTERVIEW,REQUIREMENT_FIT,CULTURE_FIT,ROLE_FIT,DIVERSITY,SUCCESSFULL,UNSUITABLE,WITHDREW};
new StageType[] { POST_INGEST,INCOMPLETE,REFERENCE_CHECK,SCREENING_CHECK,VIDEO_INTERVIEW,INTERVIEW,REQUIREMENT_FIT,CULTURE_FIT,ROLE_FIT,DIVERSITY,SUCCESSFUL,UNSUITABLE,WITHDREW};
private static StageType[] getAllStageTypes ()
......@@ -162,8 +162,8 @@ public class StageType extends AbstractEnumerated
ROLE_FIT.IsPostStage = Boolean.FALSE;
DIVERSITY.IsPreStage = Boolean.FALSE;
DIVERSITY.IsPostStage = Boolean.FALSE;
SUCCESSFULL.IsPreStage = Boolean.FALSE;
SUCCESSFULL.IsPostStage = Boolean.TRUE;
SUCCESSFUL.IsPreStage = Boolean.FALSE;
SUCCESSFUL.IsPostStage = Boolean.TRUE;
UNSUITABLE.IsPreStage = Boolean.FALSE;
UNSUITABLE.IsPostStage = Boolean.TRUE;
WITHDREW.IsPreStage = Boolean.FALSE;
......
......@@ -16,7 +16,7 @@
<VALUE name="CULTURE_FIT" description="Culture Fit" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.FALSE"/>
<VALUE name="ROLE_FIT" description="Role Fit" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.FALSE"/>
<VALUE name="DIVERSITY" description="Diversity" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.FALSE"/>
<VALUE name="SUCCESSFULL" description="Successfull" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.TRUE"/>
<VALUE name="SUCCESSFUL" description="Successful" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.TRUE"/>
<VALUE name="UNSUITABLE" description="Unsuitable" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.TRUE"/>
<VALUE name="WITHDREW" description="Withdrew" IsPreStage="Boolean.FALSE" IsPostStage="Boolean.TRUE"/>
......
package performa.utils;
import java.util.Arrays;
import java.util.Collection;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.services.TransactionServices;
import oneit.objstore.services.TransactionTask;
import oneit.utils.NestedException;
import oneit.utils.filter.CollectionFilter;
import oneit.utils.parsers.FieldException;
import performa.orm.Job;
import performa.orm.JobApplication;
import performa.orm.MessageTemplate;
import performa.orm.WorkFlow;
import performa.orm.WorkFlowMessage;
import performa.orm.WorkFlowStage;
import performa.orm.WorkFlowTemplate;
import performa.orm.types.ApplicationStatus;
import performa.orm.types.StageType;
public class WorkflowDataMigration
{
public static void main (final String[] args) throws Exception
{
TransactionServices.run(new TransactionTask() {
@Override
public void run(ObjectTransaction objTran) throws FieldException, StorageException
{
try
{
Job[] jobs = Job.searchAll(objTran);
MessageTemplate[] incomplete = MessageTemplate.SearchByAll().andApplicationStatus(new EqualsFilter<>(ApplicationStatus.DRAFT)).andIsSystemGenerated(new EqualsFilter<>(Boolean.TRUE)).search(objTran);
MessageTemplate[] postIngest = MessageTemplate.SearchByAll().andApplicationStatus(new EqualsFilter<>(ApplicationStatus.POST_INGEST)).andIsSystemGenerated(new EqualsFilter<>(Boolean.TRUE)).search(objTran);
for(Job job : jobs)
{
WorkFlowTemplate wfTemplate = WorkFlowTemplate.createWorkFlowTemplate(objTran);
wfTemplate.setTemplateName(job.getJobTitle());
wfTemplate.setIsSystemGenerated(Boolean.TRUE);
wfTemplate.setHiringTeam(job.getHiringTeam());
wfTemplate.addToJobs(job);
int sortOrder = 0;
WorkFlowStage postIngestStage = createWorkFlowStage(objTran, wfTemplate, "Post Ingest", StageType.POST_INGEST, sortOrder++);
for(MessageTemplate mTemplate : (Collection<MessageTemplate>)CollectionFilter.filter(Arrays.asList(postIngest), MessageTemplate.SearchByAll().andMessageID(new EqualsFilter<>(job.getHiringTeam().getMessageID()))))
{
createWorkFlowMessage(objTran, postIngestStage, mTemplate);
}
WorkFlowStage incompleteStage = createWorkFlowStage(objTran, wfTemplate, "Incomplete", StageType.INCOMPLETE, sortOrder++);
for(MessageTemplate mTemplate : (Collection<MessageTemplate>)CollectionFilter.filter(Arrays.asList(incomplete), MessageTemplate.SearchByAll().andMessageID(new EqualsFilter<>(job.getHiringTeam().getMessageID()))))
{
createWorkFlowMessage(objTran, incompleteStage, mTemplate);
}
if(job.getDiversityIncluded())
{
createWorkFlowStage(objTran, wfTemplate, "Diversity", StageType.DIVERSITY, sortOrder++);
}
if(job.getIncludeAssessmentCriteria())
{
createWorkFlowStage(objTran, wfTemplate, "Requirements", StageType.REQUIREMENT_FIT, sortOrder++);
}
if(job.getIncludeCulture())
{
createWorkFlowStage(objTran, wfTemplate, "Culture Fit", StageType.CULTURE_FIT, sortOrder++);
}
createWorkFlowStage(objTran, wfTemplate, "Role Fit", StageType.ROLE_FIT, sortOrder++);
for(WorkFlow workFlow : job.getWorkFlowsSet())
{
if(workFlow.getApplicationStatus() == ApplicationStatus.DRAFT || workFlow.getApplicationStatus() == ApplicationStatus.UNSUITABLE)
{
continue;
}
createWorkFlowStage(objTran, wfTemplate, workFlow.getName(), getStageTypeByStatus(workFlow.getApplicationStatus()), sortOrder++);
}
createWorkFlowStage(objTran, wfTemplate, "Successful", StageType.SUCCESSFUL, sortOrder++);
createWorkFlowStage(objTran, wfTemplate, "Withdrew", StageType.WITHDREW, sortOrder++);
createWorkFlowStage(objTran, wfTemplate, "Unsuitable", StageType.UNSUITABLE, sortOrder++);
// TODO: might have to move to another transaction
for(JobApplication jobApplication : job.getJobApplicationsSet())
{
jobApplication.setWorkFlowStage(getWFStageByStatus(wfTemplate, jobApplication.getApplicationStatus()));
}
}
}
catch (Exception e)
{
throw new NestedException(e);
}
}
private void createWorkFlowMessage(ObjectTransaction objTran, WorkFlowStage stage, MessageTemplate mTemplate) throws StorageException, FieldException
{
WorkFlowMessage wfMessage = WorkFlowMessage.createWorkFlowMessage(objTran);
wfMessage.setWorkFlowStage(stage);
wfMessage.setBusinessHoursOnly(mTemplate.getBusinessHoursOnly());
wfMessage.setMessageTemplate(mTemplate);
wfMessage.setDelay(getDelay(mTemplate));
wfMessage.setVariance(mTemplate.getVariance().toString() + "m");
}
private WorkFlowStage createWorkFlowStage(ObjectTransaction objTran, WorkFlowTemplate wfTemplate, String name, StageType stageType, int sortOrder) throws FieldException, StorageException
{
WorkFlowStage wfStage = WorkFlowStage.createWorkFlowStage(objTran);
wfStage.setWorkFlowTemplate(wfTemplate);
wfStage.setName(name);
wfStage.setStageType(stageType);
return wfStage;
}
});
}
private static String getDelay(MessageTemplate mTemplate)
{
StringBuilder sb = new StringBuilder();
sb.append((int)(mTemplate.getDelayHrs()/24)).append("d:");
sb.append(mTemplate.getDelayHrs()%24).append("h:");
sb.append(mTemplate.getDelayMin()).append("m");
return sb.toString();
}
public static StageType getStageTypeByStatus(ApplicationStatus status)
{
if(status == ApplicationStatus.POST_INGEST)
{
return StageType.POST_INGEST;
}
else if(status == ApplicationStatus.DRAFT)
{
return StageType.INCOMPLETE;
}
else if(status == ApplicationStatus.UNSUITABLE)
{
return StageType.UNSUITABLE;
}
// TODO: map other statuses
return null;
}
public static WorkFlowStage getWFStageByStatus(WorkFlowTemplate template , ApplicationStatus status)
{
if(status == ApplicationStatus.POST_INGEST)
{
return getWFStage(template, StageType.POST_INGEST);
}
else if(status == ApplicationStatus.DRAFT)
{
return getWFStage(template, StageType.INCOMPLETE);
}
else if(status == ApplicationStatus.UNSUITABLE)
{
return getWFStage(template, StageType.UNSUITABLE);
}
// TODO: map other statuses
return null;
}
private static WorkFlowStage getWFStage(WorkFlowTemplate template, StageType stageType)
{
return template.pipelineWorkFlowTemplate().toWorkFlowStages(WorkFlowStage.SearchByAll().andStageType(new EqualsFilter<>(stageType))).val();
}
}
\ No newline at end of file
UPDATE tl_message_template SET is_system_generated = 'Y' WHERE is_system_generated IS NULL;
\ 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