Skip to content

Instantly share code, notes, and snippets.

@abhididdigi
Last active June 10, 2016 19:15
Show Gist options
  • Save abhididdigi/42b67564f96f9638b6735a358a79b7c1 to your computer and use it in GitHub Desktop.
Save abhididdigi/42b67564f96f9638b6735a358a79b7c1 to your computer and use it in GitHub Desktop.
var OB_JV_UserCreationUtil = Class.create();
OB_JV_UserCreationUtil.prototype = {
initialize: function(blob,subject) {
this.blob = blob;
this.controller = new OB_IntegrationController();
this.subject = subject;
this.personal_email_id = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"email");
this.controller = new OB_IntegrationController();
},
insertUser : function() {
try {
var blob = this.blob;
if(JSUtil.type_of(blob) == 'string') {
blob = new JSON().decode(this.blob);
}
// email
var email = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "email");
// firstName
var firstName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "firstName");
// lastName
var lastName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "lastName");
// hiringManagerObUserId
var hiringManager = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "job.managers");
hiringManager = hiringManager[0].userName;
hiringManager = this.controller.user.getUserByEmail(hiringManager);
// hrManagerObUserId
var hrManager = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "rc");
hrManager = this.controller.user.getUserByEmail(hrManager);
// levelName
var levelName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"job.customFields[name=Job Level].value");
// dayoneLocationId
var dayoneLocationName = WD_Constants.getPattern(this.blob, "job.customFields[name=Location on First Day/NHO Location].value");
if(JSUtil.nil(dayoneLocationName)) dayoneLocationName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "job.location.name");
var dayoneLocation = this.controller.dimension.findLocationByName(dayoneLocationName);
// milestoneId
var milestone = this.controller.dimension.findMilestoneByName("Offer Extended"); // Should this be hard-coded?
// businessUnitName
var businessUnitName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "job.department");
// regionId
var region = this.controller.dimension.findRegionByName("North America"); // Should this be hard-coded?
// title
var title = "";
// startDate
var startDate = WD_Constants.getPattern(this.blob,'startDate');
startDate = startDate.split(" ")[0];
startDate = OB_Email_Constants.convertStartDate(startDate, WD_Constants.getPattern(this.blob,'job.location.name'));
if(JSUtil.nil(startDate) || startDate == 'undefined'|| startDate == -1){
startDate = '';
}
gs.log(startDate);
// password
var configFactory = OB_AppConfigDTO.create();
var cfg = configFactory.getAppCOnfigByName("onboard_user_default_password");
var password = cfg.value;
// orientationDate
var orientationDate = WD_Constants.getPattern(this.blob, "customFields[name=NHO Date].value");
orientationDate = OB_Email_Constants.convertStartDate(orientationDate, WD_Constants.getPattern(this.blob, 'job.location.name'));
gs.log(orientationDate);
if(JSUtil.nil(orientationDate)|| orientationDate == 'undefined' || orientationDate == -1){
orientationDate = '';
}
// workLocationId
var workLocationName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "job.location.name");
var workLocation = this.controller.dimension.findLocationByName(workLocationName);
// hireTypeId
var hireTypeId = "";
// recruiterObUserId
var recruiterObUserId = "";
// Create the new hire.
var user = this.controller.user.createNewHire(
email,
firstName,
lastName,
hiringManager.id,
hrManager.id,
levelName,
dayoneLocation.id,
milestone.id,
businessUnitName,
region.id,
title,
startDate,
password,
orientationDate,
workLocation.id,
hireTypeId,
recruiterObUserId
);
} catch(e) {
gs.log("the line number issue" + e.LineNumber);
gs.log("OB_JV_UserCreationUtil: " + e.message);
}
},
updateUser:function(){
var blob = this.blob;
//var subject = "ob_email_subject";
if(JSUtil.type_of("blob") == "string"){
blob = new JSON().decode(blob);
}
//var subjectText = blob[subject];
var subjectText = this.subject;
if(subjectText.indexOf("change start date") != -1){
//API method needed.
var startDate = WD_Constants.getPattern(this.blob,'startdate');
var tz_start_date = OB_Email_Constants.convertStartDate(startDate,WD_Constants.getPattern(this.blob,'job.location.name'));
if(global.JSUtil.nil(tz_start_date) || tz_start_date == -1){
OB_Email_Constants.logError(this.blob,"start date is not right. Hence returning, and there has been no update to the start date of the user with email ID " + this.personal_email_id);
}
this.controller.newHire.updateStartDate(this.personal_email_id, tz_start_date);
}
else if(subjectText.indexOf("location change") != -1){
var location = WD_Constants.getPattern(this.blob,'location');
gs.log('New Location is '+location);
}
else if(subjectText.indexOf("change nho date") != -1){
var nhoDate = WD_Constants.getPattern(this.blob,'nho_date');
var tz_nho_date = OB_Email_Constants.convertStartDate(nhoDate,WD_Constants.getPattern(this.blob,'job.location.name'));
if(global.JSUtil.nil(tz_nho_date) || tz_nho_date == -1){
OB_Email_Constants.logError(this.blob,"NHO date is not right. Hence returning, and there has been no update to the NHO date of the user with email ID " + this.personal_email_id);
this.controller.newHire.updateOrientationDate(this.personal_email_id,tz_nho_date);
}
gs.log('New NHO Date is '+nhoDate);
}
else if(subjectText.indexOf("status change") != -1){
var status = WD_Constants.getPattern(this.blob,'status');
status = status + '';
if(status.toLowerCase.indexOf("offer rejected") != -1){
// call Eric's code to close out the user.
gs.log('@@test inside offer rejected');
}
}
else if(subjectText.indexOf("hiring manager change") != -1){
var hiringManager = WD_Constants.getPattern(this.blob,'hiring_manager');
gs.log('New Hiring Manager is '+hiringManager+'-'+this.personal_email_id);
gs.log("updating the hiring manager" + hiringManager);
this.controller.newHire.updateHiringManager(this.personal_email_id,hiringManager);
}
else if(subjectText.indexOf("recruiting coordinator change") != -1){
var rc = WD_Constants.getPattern(this.blob,'rc');
gs.log('New Recruiting Coordinator is; and updating it with '+rc);
this.controller.newHire.updateHRManager(this.personal_email_id,rc);
}
else
{
OB_Email_Constants.logError(this.blob,"Subject is not valid to update the user");
}
},
type: 'OB_JV_UserCreationUtil'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment