List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.krawler.esp.handlers.ProfileHandler.java
License:Open Source License
public static void update_profile_status(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException { try {/*w ww.j av a 2s . c om*/ String[] ids = request.getParameterValues("emp_ids"); for (int i = 0; i < ids.length; i++) { Empprofile prof = (Empprofile) session.load(Empprofile.class, ids[i]); prof.setStatus("Approved"); prof.setUpdated_by(AuthHandler.getUserid(request)); prof.setUpdated_on(new Date()); session.saveOrUpdate(prof); //ProfileHandler.insertAuditLog(session, AuditAction.PROFILE_APPROVED, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has approved " + AuthHandler.getFullName(session, prof.getUserID()),request); } } catch (HibernateException ex) { throw ServiceException.FAILURE("ProfileHandler.EmpProfilestatus", ex); } catch (SessionExpiredException ex) { throw ServiceException.FAILURE("ProfileHandler.EmpProfilestatus", ex); } }
From source file:com.krawler.esp.handlers.ProfileHandler.java
License:Open Source License
public static void setEmpIdFormat(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException, NullPointerException { try {/*from w w w. j ava 2 s . c om*/ String cmpid = AuthHandler.getCompanyid(request); CompanyPreferences cmpPref = null; Company company = (Company) session.load(Company.class, cmpid); // company.setSubscriptionCode(Long.parseLong(request.getParameter("subcription"))); session.saveOrUpdate(company); String query = "from CompanyPreferences where company.companyID=?"; List tabledata = HibernateUtil.executeQuery(session, query, cmpid); if (tabledata.size() == 0) { cmpPref = new CompanyPreferences(); cmpPref.setCompany(company); } else { cmpPref = (CompanyPreferences) session.get(CompanyPreferences.class, cmpid); } cmpPref.setEmpidformat(request.getParameter("employeeidformat")); cmpPref.setJobidformat(request.getParameter("jobidformat")); if (StringUtil.isNullOrEmpty(request.getParameter("selfappraisal"))) { cmpPref.setSelfappraisal(false); } else { cmpPref.setSelfappraisal(true); } if (StringUtil.isNullOrEmpty(request.getParameter("competencies"))) { cmpPref.setCompetency(false); } else { cmpPref.setCompetency(true); } if (StringUtil.isNullOrEmpty(request.getParameter("goals"))) { cmpPref.setGoal(false); } else { cmpPref.setGoal(true); } if (StringUtil.isNullOrEmpty(request.getParameter("annmng"))) { cmpPref.setAnnmanager(false); } else { cmpPref.setAnnmanager(true); } if (StringUtil.isNullOrEmpty(request.getParameter("approveappr"))) { cmpPref.setApproveappraisal(false); } else { cmpPref.setApproveappraisal(true); } if (StringUtil.isNullOrEmpty(request.getParameter("promotionrec"))) { cmpPref.setPromotion(false); } else { cmpPref.setPromotion(true); } if (StringUtil.isNullOrEmpty(request.getParameter("weightage"))) { cmpPref.setWeightage(false); } else { cmpPref.setWeightage(true); } if (StringUtil.isNullOrEmpty(request.getParameter("reviewappraisal"))) { cmpPref.setReviewappraisal(false); } else { cmpPref.setReviewappraisal(true); } if (StringUtil.isNullOrEmpty(request.getParameter("partial"))) { cmpPref.setPartial(false); } else { cmpPref.setPartial(true); } if (StringUtil.isNullOrEmpty(request.getParameter("fullupdates"))) { cmpPref.setFullupdates(false); } else { cmpPref.setFullupdates(true); } if (StringUtil.isNullOrEmpty(request.getParameter("modaverage"))) { cmpPref.setModaverage(false); } else { cmpPref.setModaverage(true); } session.saveOrUpdate(cmpPref); } catch (SessionExpiredException e) { throw ServiceException.FAILURE("ProfileHandler.setEmpIdFormat", e); } catch (NullPointerException e) { throw ServiceException.FAILURE("ProfileHandler.setEmpIdFormat", e); } }
From source file:com.krawler.esp.servlets.remoteapi.java
License:Open Source License
public static String DeleteGoal(Session session, HttpServletRequest request) throws ServiceException { String result = ""; try {/*from w ww .j av a 2 s.c om*/ String jsondata = request.getParameter("data"); JSONArray jarr = new JSONArray("[" + jsondata + "]"); for (int i = 0; i < jarr.length(); i++) { JSONObject jobj = jarr.getJSONObject(i); String id = jobj.getString("gid"); Finalgoalmanagement fgmt = (Finalgoalmanagement) session.load(Finalgoalmanagement.class, id); if (fgmt != null) { fgmt.setDeleted(true); User usr = (User) session.load(User.class, jobj.getString("userid")); User empusr = (User) session.load(User.class, jobj.getString("empid")); if (usr != null && empusr != null) { String Fullname = null, empFullname = null; try { Fullname = getFullName(usr); empFullname = getFullName(empusr); } catch (Exception ex) { result = getMessage(2, 4); // user not exist break; } String logtext = "User " + Fullname + " has deleted " + empFullname + "'s goal " + fgmt.getGoalname(); session.saveOrUpdate(fgmt); insertAuditLog(session, AuditAction.GOAL_DELETED, logtext, request, usr); result = getMessage(1, 13); // goal delete success } else { result = getMessage(2, 4); // user not exist } } else { result = getMessage(2, 14); // Goal with id not exist } } } catch (Exception ex) { result = getMessage(2, 13); } return result; }
From source file:com.krawler.esp.servlets.remoteapi.java
License:Open Source License
private static String createUser(Session session, HttpServletRequest request) throws SQLException, ServiceException { String retStr = ""; try {//from w ww . j a v a 2 s.c o m JSONObject jobj = new JSONObject(request.getParameter("data")); String id = ""; String pwdText = ""; String companyid = jobj.isNull("companyid") ? "" : jobj.getString("companyid"); String username = jobj.isNull("username") ? "" : jobj.getString("username"); String pwd = jobj.isNull("password") ? "" : jobj.getString("password"); String fname = jobj.isNull("fname") ? "" : jobj.getString("fname"); String lname = jobj.isNull("lname") ? "" : jobj.getString("lname"); String emailid = jobj.isNull("emailid") ? "" : jobj.getString("emailid"); String userid = jobj.isNull("userid") ? "" : jobj.getString("userid"); String subdomain = jobj.isNull("subdomain") ? "" : jobj.getString("subdomain"); if (StringUtil.isNullOrEmpty(companyid) || StringUtil.isNullOrEmpty(username) || StringUtil.isNullOrEmpty(fname) || StringUtil.isNullOrEmpty(lname) || StringUtil.isNullOrEmpty(emailid) || StringUtil.isNullOrEmpty(userid)) { return getMessage(2, 1); } String hql = "from Company where companyID=?"; List ls = HibernateUtil.executeQuery(session, hql, new Object[] { companyid }); if (ls.size() == 0) { return getMessage(2, 8); } UserLogin userLogin; User user; Useraccount ua; Empprofile empProfile = new Empprofile(); if (StringUtil.isNullOrEmpty(id) == false) { user = (User) session.load(User.class, id); ua = (Useraccount) session.load(Useraccount.class, id); userLogin = user.getUserLogin(); String pass = jobj.getString("password"); String oldpass = jobj.getString("oldpassword"); if (StringUtil.isNullOrEmpty(oldpass) == false) { if (AuthHandler.getSHA1(oldpass).equals(userLogin.getPassword())) { if (StringUtil.isNullOrEmpty(pass) == false) userLogin.setPassword(AuthHandler.getSHA1(pass)); } else throw new Exception("Old Password does not match"); } } else { hql = "from UserLogin u where u.userID=?"; ls = null; ls = HibernateUtil.executeQuery(session, hql, new Object[] { userid }); if (ls.size() > 0) { return getMessage(2, 7); } else { user = new User(); ua = new Useraccount(); userLogin = new UserLogin(); userLogin.setUserID(userid); ua.setUserID(userid); // user.setUserID(userid); user.setUserLogin(userLogin); //userLogin.setUser(user); String q = "from User where userLogin.userName=? and company.companyID=?";// and company.companyID=?"; ls = null; ls = HibernateUtil.executeQuery(session, q, new Object[] { username, companyid }); if (ls.size() > 0 && username.equals(userLogin.getUserName()) == false) { return getMessage(2, 3); } userLogin.setUserName(username); if (jobj.isNull("password")) { pwdText = AuthHandler.generateNewPassword(); pwd = AuthHandler.getSHA1(pwdText); } userLogin.setPassword(pwd); user.setCompany((Company) session.load(Company.class, companyid)); empProfile = setEmployeeProfileDefault(userid, empProfile, userLogin); } } user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, "18")); user.setFirstName(fname); user.setLastName(lname); user.setEmailID(emailid); ua.setUser(user); ua.setSalary("0"); String role = jobj.isNull("role") ? "h3" : jobj.getString("role"); if (StringUtil.equal(role, "h1") || StringUtil.equal(role, "h0")) { role = "1"; } else if (StringUtil.equal(role, "h2")) { role = "2"; } else if (StringUtil.equal(role, "h3")) { role = "3"; } ua.setRole((Role) session.load(Role.class, role)); if (jobj.has("accno") && StringUtil.isNullOrEmpty(jobj.getString("accno")) == false) { if ((jobj.getString("accno")).length() > 0) { ua.setAccno(jobj.getString("accno")); } else { ua.setAccno("0"); } } ua.setTemplateid("0"); int empid = getMaxCountEmpid(session, companyid); ua.setEmployeeid(empid); if (jobj.has("formatid") && StringUtil.isNullOrEmpty(jobj.getString("formatid")) == false) { user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, jobj.getString("formatid"))); } String diff = null; if (jobj.has("tzid") && StringUtil.isNullOrEmpty(jobj.getString("tzid")) == false) { KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, jobj.getString("tzid")); diff = timeZone.getDifference(); user.setTimeZone(timeZone); } if (jobj.has("aboutuser") && StringUtil.isNullOrEmpty(jobj.getString("aboutuser")) == false) { user.setAboutUser(jobj.getString("aboutuser")); } session.saveOrUpdate(userLogin); session.saveOrUpdate(user); session.save(ua); session.save(empProfile); updatePreferences(request, null, (jobj.has("formatid") ? jobj.getString("formatid") : null), (jobj.has("tzid") ? jobj.getString("tzid") : null), diff); retStr = getMessage(1, 5); } catch (Exception e) { e.printStackTrace(); throw ServiceException.FAILURE(e.getMessage(), e); } return retStr; }
From source file:com.krawler.esp.servlets.remoteapi.java
License:Open Source License
/** * Create company with passed company name and company created user * @param session A current transaction session * @param request A HttpServletRequest/*from w ww . j a v a2s.co m*/ * @param id Unique username * @param password User password * @param emailid User emailid * @param fname User's name * @return JSON with success/failure response. * @throws ServiceException */ private static String signupCompany(Session session, HttpServletRequest request, String id, String password, String emailid, String companyname, String fname, JSONObject jobj, String companyid, String creatorid, String subdomain, String lname) throws ServiceException { String result = "failure"; int modules = 0; try { Company company = null; String query1 = "from Company c where c.subDomain= ?"; List list1 = HibernateUtil.executeQuery(session, query1, subdomain); Iterator itr1 = list1.iterator(); if (itr1.hasNext()) { // rename company's invalid subdomain Company oldcompany = (Company) itr1.next(); oldcompany.setSubDomain("old_" + oldcompany.getSubDomain()); session.saveOrUpdate(oldcompany); // return getMessage(2, 8);//result="e11"; } else { query1 = "from UserLogin u where u.userID=?"; list1 = HibernateUtil.executeQuery(session, query1, creatorid); itr1 = list1.iterator(); if (itr1.hasNext()) { return getMessage(2, 7); } query1 = "from Company c where c.companyID= ?"; list1 = HibernateUtil.executeQuery(session, query1, companyid); itr1 = list1.iterator(); if (itr1.hasNext()) { return getMessage(2, 8);//result="e11"; } company = new Company(); company.setCompanyID(companyid); company.setSubDomain(subdomain); company.setAddress(""); company.setCompanyName(companyname); company.setCountry((Country) session.get(Country.class, "244")); company.setTimeZone((KWLTimeZone) session.get(KWLTimeZone.class, "23")); company.setEmailID(emailid); company.setCurrency((KWLCurrency) session.get(KWLCurrency.class, "1")); company.setDeleted(0); company.setCreatedOn(new Date()); company.setModifiedOn(new Date()); session.save(company); UserLogin userLogin = new UserLogin(); User user = new User(); Useraccount ua = new Useraccount(); Empprofile empProfile = new Empprofile(); ua.setUserID(creatorid); userLogin.setUserID(creatorid); user.setUserLogin(userLogin); user.setDateFormat((KWLDateFormat) session.load(KWLDateFormat.class, "18")); userLogin.setUserName(id); userLogin.setPassword(password); user.setFirstName(fname); user.setLastName(lname); user.setEmailID(emailid); ua.setUser(user); ua.setEmployeeid(0001); user.setCompany(company); ua.setRole((Role) session.load(Role.class, Role.COMPANY_ADMIN)); ua.setSalary("10000"); ua.setAccno(""); user.setDesignation("admin"); ua.setTemplateid("0"); empProfile = setEmployeeProfileDefault(creatorid, empProfile, userLogin); session.save(userLogin); session.save(user); session.save(ua); session.save(empProfile); company.setCreator(user); session.save(company); CompanyPreferences cmpPref = new CompanyPreferences(); cmpPref.setCompany(company); cmpPref.setAnnmanager(true); cmpPref.setTimesheetjob(true); modules = getmodules(session); cmpPref.setSubscriptionCode(modules); cmpPref.setSelfappraisal(true); cmpPref.setCompetency(true); cmpPref.setGoal(true); cmpPref.setApproveappraisal(true); cmpPref.setReviewappraisal(true); cmpPref.setFullupdates(true); cmpPref.setWeightage(true); session.save(cmpPref); createRecruitmentFormFields(session, request, company); createPayrollFields(session, company); result = "success"; } } catch (Exception e) { throw ServiceException.FAILURE("CompanyHandler.Signup Company", e); } return result; }
From source file:com.krawler.esp.servlets.remoteapi.java
License:Open Source License
private static String UserDelete(Session session, HttpServletRequest request) throws SQLException, ServiceException { String result = "{\"success\":false}"; try {//w ww . j a v a 2 s . c o m JSONObject jobj = new JSONObject(request.getParameter("data")); String userid = ""; boolean flag = false; if (jobj.has("userid")) { userid = jobj.getString("userid"); String[] ids = userid.split(","); for (int i = 0; i < ids.length; i++) { User u = (User) session.get(User.class, ids[i]); UserLogin ul = (UserLogin) session.get(UserLogin.class, ids[i]); if (u != null) { ul.setUserName(ul.getUserName() + "_del"); u.setDeleteflag(1); session.saveOrUpdate(ul); session.save(u); result = getMessage(1, 7); } AssignParentToChildOfDeletedUser(ids[i], session); } } else { return getMessage(2, 1); } } catch (Exception e) { result = "{\"success\":false, 'errormsg': 'Following error occured while deleting user : '" + e.getMessage() + "}"; throw ServiceException.FAILURE("comapanyServlet.CompanyUserDelete:" + e.getMessage(), e); } return result; }
From source file:com.krawler.esp.servlets.remoteapi.java
License:Open Source License
private static String updateCompany(Session session, HttpServletRequest request) throws ServiceException, JSONException, SessionExpiredException { String result = ""; JSONObject jobj = new JSONObject(request.getParameter("data")); String address = jobj.isNull("address") ? "" : jobj.getString("address"); String city = jobj.isNull("city") ? "" : jobj.getString("city"); String state = jobj.isNull("state") ? "" : jobj.getString("state"); String companyname = jobj.isNull("companyname") ? "" : jobj.getString("companyname"); String companyid = jobj.isNull("companyid") ? "" : jobj.getString("companyid"); String phone = jobj.isNull("phone") ? "" : jobj.getString("phone"); String subdomain = jobj.isNull("subdomain") ? "" : jobj.getString("subdomain"); String fax = jobj.isNull("fax") ? "" : jobj.getString("fax"); String zip = jobj.isNull("zip") ? "" : jobj.getString("zip"); String website = jobj.isNull("website") ? "" : jobj.getString("website"); String emailid = jobj.isNull("emailid") ? "" : jobj.getString("emailid"); String currency = jobj.isNull("currency") ? "" : jobj.getString("currency"); String country = jobj.isNull("country") ? "" : jobj.getString("country"); String timezone = jobj.isNull("timezone") ? "" : jobj.getString("timezone"); String imgPath = jobj.isNull("image") ? "" : jobj.getString("image"); if (StringUtil.isNullOrEmpty(companyid) || StringUtil.isNullOrEmpty(subdomain) || StringUtil.isNullOrEmpty(companyname) || StringUtil.isNullOrEmpty(currency) || StringUtil.isNullOrEmpty(country) || StringUtil.isNullOrEmpty(timezone)) { return getMessage(2, 1); }//from ww w . j a v a2 s . c o m try { Company company = null; String query1 = "from Company c where c.companyID= ?"; List list1 = HibernateUtil.executeQuery(session, query1, companyid); Iterator itr1 = list1.iterator(); if (!(itr1.hasNext())) { return getMessage(2, 4); } else { query1 = "from Company c where c.subDomain= ? and c.companyID <> ?"; list1 = HibernateUtil.executeQuery(session, query1, new Object[] { subdomain, companyid }); itr1 = list1.iterator(); if (itr1.hasNext()) { return getMessage(2, 10); } company = (Company) session.load(Company.class, companyid); company.setSubDomain(subdomain); company.setCompanyName(companyname); company.setAddress(address); company.setCity(city); company.setState(state); company.setPhoneNumber(phone); company.setFaxNumber(fax); company.setZipCode(zip); company.setWebsite(website); company.setEmailID(emailid); company.setCompanyLogo(imgPath); company.setCountry((Country) session.load(Country.class, country)); company.setCurrency((KWLCurrency) session.load(KWLCurrency.class, currency)); KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, timezone); company.setTimeZone(timeZone); company.setModifiedOn(new Date()); session.saveOrUpdate(company); result = getMessage(1, 11); } } catch (NullPointerException e) { throw ServiceException.FAILURE("CompanyHandler.updateCompany", e); } return result; }
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static JSONObject AppraisalAssign(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException, ParseException, JSONException { JSONObject jobj = new JSONObject(); try {/*from ww w. ja va 2s . co m*/ Appraisalmanagement appm = null; boolean flag = true; String query = ""; String manager = ""; String hql = ""; Iterator ite = null; List tabledata = null; List list = null; String ids[] = request.getParameterValues("empids"); Date userdate = com.krawler.common.util.Timezone.toUserSystemTimezoneDate(session, request, dateFmt.format(new Date()), AuthHandler.getUserid(request)); hql = "select id from Appraisalcycle where id=? and submitenddate>=?"; tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { request.getParameter("apptype"), userdate }); if (tabledata.isEmpty()) { jobj.put("message", "Appraisal cycle submission has already ended"); } else { for (int i = 0; i < ids.length; i++) { hql = "from Appraisalmanagement where employee.userID=? and appcycle.id=? "; tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { ids[i], request.getParameter("apptype") }); if (tabledata.isEmpty()) {//check for appraisal cycle already initiated query = "select count(assignman.userID) from Assignmanager where assignemp.userID=? and managerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); long man = (Long) list.get(0); query = "select count(reviewer.userID) from Assignreviewer where employee.userID=? and reviewerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); long rv = (Long) list.get(0); if (man > 0 && rv > 0) { //at least 1 manager and reviewer are assigned query = "from Assignmanager where assignemp.userID=? and managerstatus=1"; list = HibernateUtil.executeQuery(session, query, ids[i]); ite = list.iterator(); while (ite.hasNext()) { Assignmanager assignman = (Assignmanager) ite.next(); if (assignman.getAssignman() != null) { manager = assignman.getAssignman().getUserID(); appm = new Appraisalmanagement(); User usr = (User) session.load(User.class, ids[i]); appm.setAppcycle((Appraisalcycle) session.load(Appraisalcycle.class, request.getParameter("apptype"))); appm.setEmployee(usr); appm.setManager((User) session.load(User.class, manager)); appm.setEmployeestatus(0); appm.setManagerstatus(0); appm.setEmployeedraft(0); appm.setManagerdraft(0); appm.setAppraisalstatus(request.getParameter("status")); appm.setReviewstatus(0); session.saveOrUpdate(appm); } } } else { if (rv == 0 && man == 0) { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noappraiserandreviewerassignedforselectedappraisalcycle", null, "No appraiser and reviewer assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } else if (rv == 0) { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noreviewerassignedforselectedappraisalcycle", null, "No reviewer assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } else { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.noappraiserassignedforselectedappraisalcycle", null, "No appraiser assigned for selected appraisal cycle", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } } } else { jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.appraisalcycleisalreadyinitiatedfortheselectedemployee", null, "Appraisal Cycle is already initiated for the selected employee", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); return jobj; } //@@ProfileHandler.insertAuditLog(session, AuditAction.INITIATE_APPRAISAL, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has initiated appraisal of " + AuthHandler.getFullName(appm.getEmployee()) + " for the appraisal cycle " + appm.getAppcycle().getCyclename(), request); jobj.put("message", MessageSourceProxy.getMessage( "hrms.hrmshandler.msg.appraisalsuccessfullyintiatedforselectedemployee", null, "Appraisal successfully intiated for selected employee(s)", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); } } } catch (HibernateException ex) { throw new HibernateException("AppraisalAssign"); } finally { } return jobj; }
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static JSONObject transferappdataFunction(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException, UnsupportedEncodingException, NoSuchAlgorithmException, JSONException, JSONException { String pass = "1234"; JSONObject jobj = new JSONObject(); String hql = ""; List tabledata = null;/*w w w . j a v a2 s .c om*/ Integer codeid2 = null; User user; Useraccount ua; boolean flag1 = false; boolean flag2 = false; try { if (request.getParameter("employeetype").equalsIgnoreCase("External")) { if (StringUtil.isNullOrEmpty(request.getParameter("employeeid")) == false) { String[] codeid = (request.getParameter("employeeid")).split("-"); for (int x = 0; x < codeid.length; x++) { if (codeid[x].matches("[0-9]*") == true) { codeid2 = Integer.parseInt(codeid[x]); } } } String hql1 = "from Useraccount where employeeid=? and user.company.companyID=?"; if (HibernateUtil .executeQuery(session, hql1, new Object[] { codeid2, AuthHandler.getCompanyid(request) }) .isEmpty() == true) { flag1 = true; } String hql2 = "from UserLogin where userName=?"; if (HibernateUtil.executeQuery(session, hql2, request.getParameter("appusername")) .isEmpty() == true) { flag2 = true; } //tabledata = HibernateUtil.executeQuery(session, hql, request.getParameter("appusername")); if (flag1 && flag2) { hql = "from ConfigRecruitmentData where id=?"; tabledata = HibernateUtil.executeQuery(session, hql, request.getParameter("applicantid")); Iterator ite = tabledata.iterator(); while (ite.hasNext()) { ConfigRecruitmentData jobapp = (ConfigRecruitmentData) ite.next(); user = new User(); ua = new Useraccount(); Allapplications app = (Allapplications) session.load(Allapplications.class, request.getParameter("applicationid")); String userid = UUID.randomUUID().toString(); UserLogin userLogin = new UserLogin(); userLogin.setUserID(userid); userLogin.setUserName(request.getParameter("appusername")); userLogin.setPassword(AuthHandler.getSHA1(pass)); user.setFirstName(jobapp.getCol1()); user.setLastName(jobapp.getCol2()); user.setEmailID(jobapp.getCol3()); ua.setUserID(userid); ua.setEmployeeid(codeid2); ua.setSalary("0"); user.setCompany((Company) session.load(Company.class, AuthHandler.getCompanyid(request))); ua.setDesignationid( (MasterData) session.load(MasterData.class, request.getParameter("designationid"))); ua.setDepartment( (MasterData) session.load(MasterData.class, request.getParameter("departmentid"))); ua.setRole((Role) session.load(Role.class, "3")); User cre = user.getCompany().getCreator(); user.setTimeZone(cre.getTimeZone()); user.setDateFormat(cre.getDateFormat()); user.setUserLogin(userLogin); jobapp.setDeleted(true); deleteuserappFunction(0, false, request.getParameter("applicantid"), request.getParameter("applicantid"), session, request); session.saveOrUpdate(userLogin); session.saveOrUpdate(user); session.saveOrUpdate(ua); session.update(jobapp); jobj.put("message", true); } } else { jobj.put("message", false); } } else { user = (User) session.load(User.class, request.getParameter("applicantid")); ua = (Useraccount) session.get(Useraccount.class, user.getUserID()); if (user != null) { deleteuserappFunction(1, false, request.getParameter("applicantid"), request.getParameter("applicantid"), session, request); int histsave = 0; Date saveDate = new Date(); SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy/MM/dd"); saveDate = new Date(fmt1.format(saveDate)); Emphistory ehst = new Emphistory(); User updatedby = (User) session.get(User.class, AuthHandler.getUserid(request)); if ((MasterData) session.load(MasterData.class, request.getParameter("designationid")) != ua .getDesignationid()) { ehst.setDesignation(ua.getDesignationid()); histsave = 1; } ua.setDesignationid( (MasterData) session.load(MasterData.class, request.getParameter("designationid"))); if ((MasterData) session.load(MasterData.class, request.getParameter("departmentid")) != ua .getDepartment()) { ehst.setDepartment(ua.getDepartment()); if (histsave == 0) { ehst.setDesignation(ua.getDesignationid()); } histsave = 2; } ua.setDepartment( (MasterData) session.load(MasterData.class, request.getParameter("departmentid"))); if (histsave == 1) { ehst.setDepartment(ua.getDepartment()); } if (histsave == 1 || histsave == 2) { ehst.setUserid(user); ehst.setEmpid(ua.getEmployeeid()); ehst.setUpdatedon(saveDate); ehst.setUpdatedby(updatedby); ehst.setCategory(Emphistory.Emp_Desg_change); session.saveOrUpdate(ehst); } session.update(user); jobj.put("message", true); } } } catch (ServiceException ex) { throw ServiceException.FAILURE("addnewuserFunction", ex); } catch (UnsupportedEncodingException e) { throw ServiceException.FAILURE("Auth.getSHA1", e); } catch (NoSuchAlgorithmException e) { throw ServiceException.FAILURE("Auth.getSHA1", e); } catch (JSONException e) { throw ServiceException.FAILURE("hrmsHandler.addnewuserFunction", e); } return jobj; }
From source file:com.krawler.hrms.hrmsHandler.java
License:Open Source License
public static void assignedgoalsdelete(Session session, HttpServletRequest request) throws ServiceException { try {//from ww w . ja va 2s. c o m String[] ids = request.getParameterValues("ids"); for (int i = 0; i < ids.length; i++) { Finalgoalmanagement fgmt = (Finalgoalmanagement) session.load(Finalgoalmanagement.class, ids[i]); fgmt.setDeleted(true); String logtext = "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has deleted " + AuthHandler.getFullName(fgmt.getUserID()) + "'s goal " + fgmt.getGoalname(); session.saveOrUpdate(fgmt); //@@ProfileHandler.insertAuditLog(session, AuditAction.GOAL_DELETED, logtext ,request); } } catch (Exception ex) { throw ServiceException.FAILURE("hrmsManager.deleteGoals", ex); } }