Created
June 22, 2016 08:09
-
-
Save abhididdigi/ea571e1db1eaa27c251d96bd902d492d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
//var blob = new JSON().decode(this.blob); | |
var email = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"email"); | |
var firstName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"firstName"); | |
var lastName = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"lastName"); | |
var hiringManager = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"job.managers"); | |
gs.log("THe hiring_hiring Manager" + hiringManager); | |
var hrManager = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"rc"); | |
gs.log("THe HR Manager" + hrManager); | |
var businessUnitID = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"job.department"); | |
var locationID = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob, "job.location.name"); // work location ID. | |
var levelID = x_4591_jobvite_can.OB_JobviteConstants.getPattern(blob,"job.customFields[name=Job Level].value"); | |
//get all the information via API | |
var controller = this.controller; | |
//businessUnitID = controller.dimension.findBusinessUnitByName(businessUnitID); | |
locationID = controller.dimension.findLocationByName(locationID); | |
if(JSUtil.nil(locationID)){ | |
locationID = ''; | |
} | |
//levelID = controller.dimension.findLevelByName(levelID); | |
var regionID = controller.dimension.findRegionByName("North America") // hardcoding country for now. | |
var milestoneID = controller.dimension.findMilestoneByName("Offer Extended"); | |
var startDate = WD_Constants.getPattern(this.blob,'startDate'); | |
startDate = startDate.split(" ")[0]; | |
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 creation of a new employee with the email ID " + this.personal_email_id); | |
} | |
if(tz_start_date == -1){ | |
tz_start_date = ''; | |
} | |
//var nho_date = WD_Constants.getPattern(this.blob,'nho_date').split(" ")[0]; | |
var nho_date = WD_Constants.getPattern(this.blob, "customFields[name=NHO Date].value"); | |
var tz_nho_date = OB_Email_Constants.convertStartDate(nho_date, 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. There has been no creation of a new employee with the email ID " + this.personal_email_id); | |
} | |
if(tz_nho_date == -1){ | |
tz_nho_date = ''; | |
} | |
hiringManager = hiringManager[0].userName; | |
gs.log("hiringManager email found" + hiringManager); | |
hiringManager = controller.user.getUserByEmail(hiringManager); | |
hiringManager = hiringManager.id; | |
gs.log("HRmanager found" + hrManager) | |
hrManager = controller.user.getUserByEmail(hrManager); | |
hrManager = hrManager.id; | |
var nho_location = WD_Constants.getPattern(this.blob, "job.customFields[name=Location on First Day/NHO Location].value"); | |
if(JSUtil.nil(nho_location)){ | |
// OBSN - 177 | |
nho_location = locationID; | |
}else{ | |
nho_location = controller.dimension.findLocationByName(nho_location); | |
} | |
// password | |
var configFactory = OB_AppConfigDTO.create(); | |
var cfg = configFactory.getAppCOnfigByName("onboard_user_default_password"); | |
var password = cfg.value; | |
//var tz_start_date = startDate; | |
gs.log("creating user with email : " + email + " firstName : " + firstName + " Lastname: " + lastName + " hiringManager : " + hiringManager + " hrManager : " + hrManager + " levelID " + levelID + " locatonID " + locationID.id + " milestoneID " + milestoneID.id + " regionID " + regionID.id + " start date : " + tz_start_date + " NHO date " + tz_nho_date + " business id = " + businessUnitID + "NHO location = " + nho_location); | |
var hireType = controller.dimension.findHireTypeByName("US-FTE"); | |
var user = controller.user.createNewHire( | |
email, | |
firstName, | |
lastName, | |
hiringManager, | |
hrManager, | |
levelID,//levelID | |
nho_location.id,//NHO location | |
milestoneID.id,//milestoneID | |
businessUnitID,//businessUnitID | |
regionID.id,//regionID | |
"", //title | |
tz_start_date, | |
password, | |
tz_nho_date, | |
locationID.id,// work location. | |
hireType.id | |
); | |
}catch(e){ | |
gs.log("the line number issue" + e.LineNumber); | |
} | |
}, | |
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; | |
var controller = this.controller; | |
if(subjectText.indexOf("change start date") != -1){ | |
//API method needed. | |
var startDate = WD_Constants.getPattern(this.blob,'startDate'); | |
startDate = startDate.split(" ")[0]; | |
gs.log("THE START DATE0 = " + startDate); | |
var tz_start_date = OB_Email_Constants.convertStartDate(startDate,WD_Constants.getPattern(this.blob,'job.location.name')); | |
gs.log("THE START DATE = " + tz_start_date); | |
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'); | |
// Call to Eric's API. Check with Eric to provide one. | |
} | |
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); | |
return; | |
} | |
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. | |
} | |
} | |
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 if(subjectText.indexOf("offer accepted") != -1){ | |
// call Eric's API. : W | |
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); | |
return; | |
} | |
this.controller.newHire.updateOrientationDate(this.personal_email_id,tz_nho_date); | |
var startDate = WD_Constants.getPattern(this.blob,'startDate'); | |
startDate = startDate.split(" ")[0]; | |
gs.log("THE START DATE0 = " + startDate); | |
var tz_start_date = OB_Email_Constants.convertStartDate(startDate,WD_Constants.getPattern(this.blob,'job.location.name')); | |
gs.log("THE START DATE = " + tz_start_date); | |
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); | |
this.controller.newHire.checkUserForTransition(this.personal_email_id); | |
} | |
else if(subjectText.indexOf("background check passed")){ | |
this.controller.user.updateBackgroundCheckStatus(this.personal_email_id,"C"); | |
} | |
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