Example usage for org.hibernate Session saveOrUpdate

List of usage examples for org.hibernate Session saveOrUpdate

Introduction

In this page you can find the example usage for org.hibernate Session saveOrUpdate.

Prototype

void saveOrUpdate(Object object);

Source Link

Document

Either #save(Object) or #update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

Usage

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void extusrchngpass(Session session, HttpServletRequest request) throws ServiceException {

    try {//from  w  w w .j  a  va 2 s.c  o m
        if (StringUtil.isNullOrEmpty(request.getParameter("pass"))) {
        } else {
            Jobapplicant exapp = (Jobapplicant) session.load(Jobapplicant.class,
                    request.getParameter("userid"));
            exapp.setPassword(request.getParameter("pass"));
            session.saveOrUpdate(exapp);
        }

    } catch (Exception ex) {
        throw ServiceException.FAILURE("hrmsManager.changepassword", ex);
    }

}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static JSONObject saveempprofile(Session session, HttpServletRequest request)
        throws ServiceException, JSONException, SessionExpiredException, ParseException {
    //int approved = 0;
    String id;/*from w  w w.j  a  v a  2 s.  co  m*/
    JSONObject msg = new JSONObject();
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    List tabledata = null;
    try {
        String currentuser = AuthHandler.getUserid(request);
        String userid = request.getParameter("userid");
        String jsondata = request.getParameter("jsondatawk");
        String jsondata1 = request.getParameter("jsondatacad");
        //String jsondata2 = request.getParameter("jsondataprof");
        //String jsondata3 = request.getParameter("jsondataemp");
        Empexperience experi = null;
        Empprofile prof = null;
        UserLogin eapp = (UserLogin) session.load(UserLogin.class, request.getParameter("userid"));
        if (!StringUtil.isNullOrEmpty(request.getParameter("formname"))
                && request.getParameter("formname").equals("Personal")) {
            try {
                String query = "from Empprofile where userLogin.userID=?";
                tabledata = HibernateUtil.executeQuery(session, query, userid);
                if (tabledata.size() == 0) {
                    id = UUID.randomUUID().toString();
                    prof = new Empprofile();
                    prof.setUserLogin(eapp);
                } else {
                    prof = (Empprofile) session.load(Empprofile.class, userid);
                }
                prof.setMiddlename(request.getParameter("mname"));
                //                    prof.setBankacc(request.getParameter("bankacc"));
                prof.setBankbranch(request.getParameter("bankbranch"));
                prof.setBankname(request.getParameter("bankname"));
                prof.setBloodgrp(request.getParameter("bloodgrp"));
                if (StringUtil.isNullOrEmpty(request.getParameter("childDoB1")) == false) {
                    prof.setChild1DoB(fmt.parse(request.getParameter("childDoB1")));
                }
                prof.setChild1name(request.getParameter("child1name"));
                if (StringUtil.isNullOrEmpty(request.getParameter("childDoB2")) == false) {
                    prof.setChild2DoB(fmt.parse(request.getParameter("childDoB2")));
                }
                prof.setChild2name(request.getParameter("child2name"));
                if (StringUtil.isNullOrEmpty(request.getParameter("DoB")) == false) {
                    prof.setDoB(fmt.parse(request.getParameter("DoB")));
                }
                prof.setDrvlicense(request.getParameter("drvlicense"));
                if (StringUtil.isNullOrEmpty(request.getParameter("exppassport")) == false) {
                    prof.setExppassport(fmt.parse(request.getParameter("exppassport")));
                }
                if (StringUtil.isNullOrEmpty(request.getParameter("fatherDoB")) == false) {
                    prof.setFatherDoB(fmt.parse(request.getParameter("fatherDoB")));
                }
                prof.setFathername(request.getParameter("fathername"));
                prof.setGender(request.getParameter("gender"));
                prof.setMarriage(request.getParameter("marital"));
                if (StringUtil.isNullOrEmpty(request.getParameter("motherDoB")) == false) {
                    prof.setMotherDoB(fmt.parse(request.getParameter("motherDoB")));
                }
                prof.setMothername(request.getParameter("mothername"));
                prof.setPanno(request.getParameter("panno"));
                prof.setPassportno(request.getParameter("passportno"));
                prof.setPfno(request.getParameter("pfno"));
                if (StringUtil.isNullOrEmpty(request.getParameter("spouseDoB")) == false) {
                    prof.setSpouseDoB(fmt.parse(request.getParameter("spouseDoB")));
                }
                prof.setSpousename(request.getParameter("spousename"));
                prof.setKeyskills(request.getParameter("keyskills"));

                prof.setUpdated_by(currentuser);
                prof.setUpdated_on(new Date());
                if (StringUtil.equal(userid, currentuser)) {
                    prof.setStatus("Pending");
                } else {
                    prof.setStatus("Approved");
                }
                session.save(prof);
                User u = (User) session.load(User.class, userid);
                Useraccount ua = (Useraccount) session.load(Useraccount.class, userid);
                u.setFirstName(request.getParameter("fname"));
                u.setLastName(request.getParameter("lname"));
                ua.setSalary(request.getParameter("salarypermonth"));
                ua.setAccno(request.getParameter("bankacc"));
                insertConfigData(session, request, "Personal", userid);
                //@@ProfileHandler.insertAuditLog(session, AuditAction.PROFILE_EDITED, "User  " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has edited " + AuthHandler.getFullName(u) + "'s profile", request);
                session.saveOrUpdate(u);
                msg.put("msg", "Profile updated successfully.");
                msg.put("success", true);
            } catch (Exception e) {
                System.out.println("Error is" + e);
            }
        } else if (!StringUtil.isNullOrEmpty(request.getParameter("formname"))
                && request.getParameter("formname").equals("Contact")) {
            String query = "from Empprofile where userLogin.userID=?";
            tabledata = HibernateUtil.executeQuery(session, query, userid);
            if (tabledata.size() == 0) {
                id = UUID.randomUUID().toString();
                prof = new Empprofile();
                prof.setUserLogin(eapp);
            } else {
                prof = (Empprofile) session.load(Empprofile.class, userid);
            }
            prof.setEmgaddr(request.getParameter("emgaddr"));
            prof.setEmghome(request.getParameter("emghome"));
            prof.setEmgmob(request.getParameter("emgmob"));
            prof.setEmgname(request.getParameter("emgname"));
            prof.setEmgreln(request.getParameter("emgreln"));
            prof.setEmgwork(request.getParameter("emgwork"));
            prof.setLandno(request.getParameter("landno"));
            prof.setMailaddr(request.getParameter("mailaddr"));
            prof.setMobno(request.getParameter("mobno"));
            prof.setPermaddr(request.getParameter("permaddr"));
            prof.setPermcity(request.getParameter("permcity"));
            if (StringUtil.isNullOrEmpty(request.getParameter("permcountry")) == false) {
                prof.setPermcountry(
                        (MasterData) session.load(MasterData.class, request.getParameter("permcountry")));
            }
            prof.setPermstate(request.getParameter("permstate"));
            prof.setPresentaddr(request.getParameter("presentaddr"));
            prof.setPresentcity(request.getParameter("presentcity"));
            if (StringUtil.isNullOrEmpty(request.getParameter("presentcountry")) == false) {
                prof.setPresentcountry(
                        (MasterData) session.load(MasterData.class, request.getParameter("presentcountry")));
            }
            prof.setPresentstate(request.getParameter("presentstate"));
            prof.setWorkno(request.getParameter("workno"));
            prof.setWorkmail(request.getParameter("workmail"));
            prof.setOthermail(request.getParameter("othermail"));
            prof.setWeekoff(request.getParameter("weekoff"));
            prof.setWkstarttime(request.getParameter("starttime"));
            prof.setWkendtime(request.getParameter("endtime"));
            session.save(prof);
            insertConfigData(session, request, "Contact", userid);
            msg.put("msg", "Profile updated successfully.");
            msg.put("success", true);

        } else if (!StringUtil.isNullOrEmpty(request.getParameter("formname"))
                && request.getParameter("formname").equals("Organizational")) {
            String query = "from Empprofile where userLogin.userID=?";
            tabledata = HibernateUtil.executeQuery(session, query, userid);
            if (tabledata.size() == 0) {
                id = UUID.randomUUID().toString();
                prof = new Empprofile();
                prof.setUserLogin(eapp);
            } else {
                prof = (Empprofile) session.load(Empprofile.class, userid);
            }
            if (StringUtil.isNullOrEmpty(request.getParameter("reportto")) == false) {
                prof.setReportto((User) session.load(User.class, request.getParameter("reportto")));
            }
            prof.setEmptype(request.getParameter("emptype"));
            prof.setCommid(request.getParameter("commid"));
            prof.setBranchcode(request.getParameter("branchcode"));
            prof.setBranchaddr(request.getParameter("branchaddr"));
            prof.setBranchcity(request.getParameter("branchcity"));
            if (StringUtil.isNullOrEmpty(request.getParameter("relievedate")) == false) {
                prof.setRelievedate(fmt.parse(request.getParameter("relievedate")));
            }
            if (StringUtil.isNullOrEmpty(request.getParameter("branchcountry")) == false) {
                prof.setBranchcountry(
                        (MasterData) session.load(MasterData.class, request.getParameter("branchcountry")));
            }
            prof.setProbperiod(
                    request.getParameter("probationmon") + "," + request.getParameter("probationyr"));
            prof.setTrainperiod(request.getParameter("trainingmon") + "," + request.getParameter("trainingyr"));
            prof.setNoticeperiod(request.getParameter("noticemon") + "," + request.getParameter("noticeyr"));
            if (StringUtil.isNullOrEmpty(request.getParameter("confirmdate")) == false) {
                prof.setConfirmdate(fmt.parse(request.getParameter("confirmdate")));
            }
            if (StringUtil.isNullOrEmpty(request.getParameter("joindate")) == false) {
                prof.setJoindate(fmt.parse(request.getParameter("joindate")));
            }
            session.save(prof);
            User u = (User) session.load(User.class, userid);
            Useraccount ua = (Useraccount) session.load(Useraccount.class, userid);
            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 (StringUtil.isNullOrEmpty(request.getParameter("designationid")) == false) {
                if ((MasterData) session.load(MasterData.class,
                        (String) request.getParameter("designationid")) != ua.getDesignationid()) {
                    ehst.setDesignation(ua.getDesignationid());
                    histsave = 1;
                }
                ua.setDesignationid(
                        (MasterData) session.load(MasterData.class, request.getParameter("designationid")));
            }
            if (StringUtil.isNullOrEmpty(request.getParameter("department")) == false) {
                if ((MasterData) session.load(MasterData.class,
                        (String) request.getParameter("department")) != ua.getDepartment()) {
                    ehst.setDepartment(ua.getDepartment());
                    if (histsave == 0) {
                        ehst.setDesignation(ua.getDesignationid());
                    }
                    histsave = 2;
                }
                ua.setDepartment(
                        (MasterData) session.load(MasterData.class, request.getParameter("department")));

            }
            if (StringUtil.isNullOrEmpty(request.getParameter("empid")) == false) {
                String[] codeid = (request.getParameter("empid")).split("-");
                Integer codeid2 = null;
                for (int x = 0; x < codeid.length; x++) {
                    if (codeid[x].matches("[0-9]*") == true) {
                        codeid2 = Integer.parseInt(codeid[x]);
                    }
                }
                String q2 = "from User where employeeid=? and company.companyID=?";
                List emplst = HibernateUtil.executeQuery(session, q2,
                        new Object[] { codeid2, AuthHandler.getCompanyid(request) });
                if (emplst.size() > 0) {
                    int getid = ua.getEmployeeid();
                    if (getid != codeid2) {
                        msg.put("msg", "Employee ID is already assigned to another employee");
                    }
                } else {
                    ua.setEmployeeid(codeid2);
                }
                if (histsave == 1) {
                    ehst.setDepartment(ua.getDepartment());
                }
                if (histsave == 1 || histsave == 2) {
                    ehst.setUserid(u);
                    ehst.setEmpid(ua.getEmployeeid());
                    ehst.setUpdatedon(saveDate);
                    ehst.setUpdatedby(updatedby);
                    ehst.setCategory(Emphistory.Emp_Desg_change);
                    session.saveOrUpdate(ehst);
                }
                //@@ProfileHandler.insertAuditLog(session, AuditAction.PROFILE_EDITED, "User  " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has edited " + AuthHandler.getFullName(u) + "'s profile", request);
                session.saveOrUpdate(u);
            }
            insertConfigData(session, request, "Organizational", userid);
            msg.put("msg", "Profile updated successfully.");
            msg.put("success", true);

        } else {
            if (jsondata.length() > 0) {
                JSONArray jarr = new JSONArray("[" + jsondata + "]");
                for (int i = 0; i < jarr.length(); i++) {
                    JSONObject jobj = jarr.getJSONObject(i);
                    if (StringUtil.isNullOrEmpty(jobj.getString("id"))) {
                        id = UUID.randomUUID().toString();
                        experi = new Empexperience();
                        experi.setUserid(eapp);
                        experi.setType(jobj.getString("type"));
                    } else {
                        experi = (Empexperience) session.load(Empexperience.class, jobj.getString("id"));
                    }
                    experi.setOrganization(jobj.getString("organisation"));
                    experi.setPosition(jobj.getString("position"));
                    experi.setBeginyear(jobj.getString("beginyear"));
                    experi.setEndyear(jobj.getString("endyear"));
                    experi.setComment(jobj.getString("comment"));
                    session.save(experi);
                }
            }
            if (jsondata1.length() > 0) {
                JSONArray jarr1 = new JSONArray("[" + jsondata1 + "]");
                for (int j = 0; j < jarr1.length(); j++) {
                    JSONObject jobj = jarr1.getJSONObject(j);
                    if (StringUtil.isNullOrEmpty(jobj.getString("id"))) {
                        id = UUID.randomUUID().toString();
                        experi = new Empexperience();
                        experi.setUserid(eapp);
                        experi.setType(jobj.getString("type"));
                    } else {
                        experi = (Empexperience) session.load(Empexperience.class, jobj.getString("id"));
                    }
                    experi.setQualification(jobj.getString("qualification"));
                    experi.setInstitution(jobj.getString("institution"));
                    experi.setYearofgrad(jobj.getString("gradyear"));
                    experi.setMarks(jobj.getString("marks"));
                    experi.setFrmyear(jobj.getString("yeargrdfrm"));
                    experi.setQaulin(jobj.getString("qualificationin"));
                    session.save(experi);
                }
            }
            msg.put("msg", "Profile updated successfully.");
            msg.put("success", true);
        }

    } catch (JSONException ex) {
        throw ServiceException.FAILURE("hrmsHandler.EmpProfilesave", ex);
    } catch (SessionExpiredException ex) {
        throw ServiceException.FAILURE("hrmsHandler.EmpProfilesave", ex);
    } catch (ParseException ex) {
        throw ServiceException.FAILURE("hrmsHandler.EmpProfilesave", ex);
    }
    return msg;
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void deleteApplicants(Session session, HttpServletRequest request)
        throws ServiceException, HibernateException, SessionExpiredException {
    try {/*from  w w  w.  j  a va  2s. c  o  m*/
        String[] ids = request.getParameterValues("ids");
        for (int i = 0; i < ids.length; i++) {
            Jobapplicant exps = (Jobapplicant) session.load(Jobapplicant.class, ids[i]);
            exps.setUsername(exps.getUsername() + "_del");
            exps.setDeleted(true);
            //@@ProfileHandler.insertAuditLog(session, AuditAction.DELETE_APPLICANT, "User  " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has deleted applicant " + exps.getFirstname() + " " + exps.getLastname(),request);
            session.saveOrUpdate(exps);
        }
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.deleteApplicants", e);
    }
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void terminateEmp(Session session, HttpServletRequest request)
        throws ServiceException, HibernateException, SessionExpiredException, ParseException {
    String hql = "";
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    try {//  w w w. j  a  v  a2  s .  c om
        String ids[] = request.getParameterValues("ids");
        String masterid = request.getParameter("tercause");
        String desc = ((StringUtil.isNullOrEmpty(request.getParameter("terdesc"))) ? ""
                : request.getParameter("terdesc"));
        String reldate = request.getParameter("relievedate");
        Date rvdate = fmt.parse(reldate);
        Empprofile emp = null;
        UserLogin usl = null;
        User usr = null;
        User updatedby = (User) session.get(User.class, AuthHandler.getUserid(request));
        for (int i = 0; i < ids.length; i++) {
            hql = "from Empprofile where userLogin.userID=?";
            List lst = HibernateUtil.executeQuery(session, hql, new Object[] { ids[i] });
            usl = (UserLogin) session.get(UserLogin.class, ids[i]);
            usr = (User) session.get(User.class, ids[i]);
            if (lst.isEmpty()) {
                emp = new Empprofile();
                emp.setUserLogin(usl);
            } else {
                emp = (Empprofile) session.get(Empprofile.class, ids[i]);
            }
            Emphistory ehst = new Emphistory();
            Useraccount ua = (Useraccount) session.get(Useraccount.class, ids[i]);
            ehst.setUserid(usr);
            ehst.setDepartment(ua.getDepartment());
            ehst.setDesignation(ua.getDesignationid());
            ehst.setSalary(ua.getSalary());
            ehst.setEmpid(ua.getEmployeeid());
            ehst.setUpdatedon(rvdate);
            ehst.setJoindate(emp.getJoindate());
            ehst.setEnddate(rvdate);
            ehst.setUpdatedby(updatedby);
            ehst.setCategory(Emphistory.Emp_Desg_change);
            emp.setTerminatedby(updatedby);
            emp.setTercause((MasterData) session.get(MasterData.class, masterid));
            emp.setRelievedate(rvdate);
            emp.setTerReason(desc);
            emp.setTermnd(true);
            usr.setDeleteflag(1);
            session.saveOrUpdate(ehst);
            session.saveOrUpdate(emp);
            session.saveOrUpdate(usr);
            //@@ProfileHandler.insertAuditLog(session, AuditAction.EMPLOYEE_TERMINATED, "Employee " + AuthHandler.getFullName(usr) + " terminated by " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)),request);
        }
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.terminateEmp", e);
    } catch (SessionExpiredException e) {
        throw ServiceException.FAILURE("hrmsHandler.terminateEmp", e);
    } catch (ParseException e) {
        throw ServiceException.FAILURE("hrmsHandler.terminateEmp", e);
    }
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void rehireEmp(Session session, HttpServletRequest request)
        throws ServiceException, HibernateException, SessionExpiredException, ParseException {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    try {/*from  ww w.j ava 2s  .c o  m*/
        String ids[] = request.getParameterValues("ids");
        String deptid = request.getParameter("dept");
        String desgid = request.getParameter("desg");
        String salary = (request.getParameter("salary"));
        String reldate = request.getParameter("joindate");
        String tempid = request.getParameter("templateid");
        Date rvdate = fmt.parse(reldate);
        MasterData desg = (MasterData) session.get(MasterData.class, desgid);
        MasterData dept = (MasterData) session.get(MasterData.class, deptid);
        for (int i = 0; i < ids.length; i++) {
            User u = (User) session.get(User.class, ids[i]);
            Empprofile emp = (Empprofile) session.get(Empprofile.class, ids[i]);
            Useraccount ua = (Useraccount) session.get(Useraccount.class, u.getUserID());
            ua.setDepartment((dept));
            ua.setDesignationid(desg);
            ua.setSalary(salary);
            u.setDeleteflag(0);
            if (StringUtil.isNullOrEmpty(tempid) == false) {
                ua.setTemplateid(tempid);
            }
            emp.setJoindate(rvdate);
            emp.setTermnd(false);
            emp.setRelievedate(null);
            session.saveOrUpdate(emp);
            session.saveOrUpdate(u);
            session.saveOrUpdate(ua);
            //@@ProfileHandler.insertAuditLog(session, AuditAction.REHIRE_EMPLOYEE, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has rehired employee " + AuthHandler.getFullName(u) ,request);
        }
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.terminateEmp", e);
    } catch (ParseException e) {
        throw ServiceException.FAILURE("hrmsHandler.terminateEmp", e);
    }
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void deleteDocuments(Session session, HttpServletRequest request)
        throws ServiceException, HibernateException {
    try {/*ww  w  .  j av  a 2  s .  c o  m*/
        String[] ids = request.getParameterValues("ids");
        for (int i = 0; i < ids.length; i++) {
            HrmsDocs hdocs = (HrmsDocs) session.load(HrmsDocs.class, ids[i]);
            hdocs.setDeleted(true);
            session.saveOrUpdate(hdocs);
        }
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.deleteDocuments", e);
    }
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static String reviewanonymousAppraisalReport(Session session, HttpServletRequest request)
        throws ServiceException {
    JSONObject jobj = new JSONObject();
    try {// ww w. j  a  va2  s.  c  om
        String employeeid = request.getParameter("employeeid");
        String appcycleid = request.getParameter("appraisalcycleid");
        float salary;
        float salaryincrement = 0;
        String hql = "from Appraisalmanagement where employee.userID=? and appcycle.id=? and managerstatus=1";
        List list = HibernateUtil.executeQuery(session, hql, new Object[] { employeeid, appcycleid });
        Iterator ite = list.iterator();
        while (ite.hasNext()) {//Change status of all submitted request
            Appraisalmanagement app = (Appraisalmanagement) ite.next();
            if (Boolean.parseBoolean(request.getParameter("reviewstatus"))) {//To approve request
                if (app.getReviewstatus() != 2) {
                    User user = (User) session.load(User.class, employeeid);
                    Useraccount ua = (Useraccount) session.get(Useraccount.class, user.getUserID());
                    app.setOriginaldesignation(ua.getDesignationid());
                    app.setOriginaldepartment(ua.getDepartment());
                    app.setReviewstatus(2);
                    app.setAppraisalstatus("submitted");
                    if (!StringUtil.isNullOrEmpty(request.getParameter("reviewercomment"))) {
                        app.setReviewercomment(request.getParameter("reviewercomment"));
                    }
                    app.setEmployeestatus(1);
                    app.setManagerstatus(1);
                    app.setReviewersubmitdate(new Date());
                    if (!StringUtil.isNullOrEmpty(request.getParameter("department"))) {
                        app.setReviewdepartment((MasterData) session.load(MasterData.class,
                                request.getParameter("department")));
                    }
                    if (!StringUtil.isNullOrEmpty(request.getParameter("designation"))) {
                        app.setReviewdesignation((MasterData) session.load(MasterData.class,
                                request.getParameter("designation")));
                    }
                    if (!StringUtil.isNullOrEmpty(request.getParameter("salaryincrement"))) {
                        app.setReviewsalaryincrement(Float.parseFloat(request.getParameter("salaryincrement")));
                    } else {
                        app.setReviewsalaryincrement(0);
                    }
                    session.update(app);
                } else {
                    jobj.put("success", true);
                    jobj.put("msg",
                            MessageSourceProxy.getMessage("hrms.hrmshandler.msg.appraisalisalreadyapproved ",
                                    null, "Appraisal is already approved",
                                    LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0)));
                    return jobj.toString();
                }
            } else { //To unapprove the request
                if (app.getReviewstatus() != 2) {
                    app.setManagerstatus(0);
                    app.setReviewstatus(1);
                    if (!StringUtil.isNullOrEmpty(request.getParameter("reviewercomment"))) {
                        app.setReviewercomment(request.getParameter("reviewercomment"));
                    }
                    app.setAppraisalstatus("pending");
                } else {
                    jobj.put("success", true);
                    jobj.put("msg",
                            MessageSourceProxy.getMessage("hrms.hrmshandler.msg.appraisalisalreadyapproved ",
                                    null, "Appraisal has been already approved",
                                    LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0)));
                    return jobj.toString();
                }
            }
        }
        if (Boolean.parseBoolean(request.getParameter("reviewstatus"))) { //Update user information
            User user = (User) session.load(User.class, employeeid);
            Useraccount ua = (Useraccount) session.get(Useraccount.class, user.getUserID());
            if (StringUtil.isNullOrEmpty(ua.getSalary())) {
                salary = 0;
            } else {
                salary = Float.parseFloat(ua.getSalary());
            }
            if (!StringUtil.isNullOrEmpty(request.getParameter("salaryincrement"))) {
                salaryincrement = Float.parseFloat(request.getParameter("salaryincrement"));
            } else {
                salaryincrement = 0;
            }
            salary = salary + (salary * salaryincrement) / 100;
            //                user.setSalary("" + salary);
            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 (!StringUtil.isNullOrEmpty(request.getParameter("designation"))) {
                //                    if((MasterData) session.load(MasterData.class, (String) request.getParameter("designation"))!=user.getDesignationid()){
                //                        ehst.setDesignation(user.getDesignationid());
                //                        histsave=1;
                //                    }
                //                    user.setDesignationid((MasterData) session.load(MasterData.class, request.getParameter("designation")));
            }
            if (!StringUtil.isNullOrEmpty(request.getParameter("department"))) {
                //                    if((MasterData) session.load(MasterData.class, (String) request.getParameter("department"))!=user.getDepartment()){
                //                        ehst.setDepartment(user.getDepartment());
                //                        if(histsave==0) {
                //                            ehst.setDesignation(user.getDesignationid());
                //                        }
                //                        histsave=2;
                //                    }
                //                    user.setDepartment((MasterData) session.load(MasterData.class, request.getParameter("department")));
            }
            if (histsave == 1) {
                //                    ehst.setDepartment(user.getDepartment());
            }
            if (histsave == 1 || histsave == 2) {
                ehst.setUserid(user);
                //                    ehst.setEmpid(user.getEmployeeid());
                ehst.setUpdatedon(saveDate);
                //                    ehst.setUpdatedby(updatedby);
                ehst.setCategory(Emphistory.Emp_Desg_change);
                session.saveOrUpdate(ehst);
            }
            session.update(user);
        }
        jobj.put("success", true);
        jobj.put("msg",
                MessageSourceProxy.getMessage("hrms.hrmshandler.msg.appraisalstatuschangedsuccessfully", null,
                        "Appraisal status changed successfully",
                        LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0)));
        return jobj.toString();
    } catch (SessionExpiredException e) {
        throw ServiceException.FAILURE("hrmsHandler.reviewanonymousAppraisalReport", e);
    } catch (JSONException e) {
        throw ServiceException.FAILURE("hrmsHandler.reviewanonymousAppraisalReport", e);
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.reviewanonymousAppraisalReport", e);
    }
}

From source file:com.krawler.hrms.hrmsHandler.java

License:Open Source License

public static void approveAppraisalCycle(Session session, HttpServletRequest request)
        throws ServiceException, HibernateException {
    try {/* w ww  .  j  a  v a 2 s  .  c o m*/
        String[] ids = request.getParameterValues("ids");
        for (int i = 0; i < ids.length; i++) {
            Appraisalcycle appcl = (Appraisalcycle) session.load(Appraisalcycle.class, ids[i]);
            appcl.setCycleapproval(Boolean.parseBoolean(request.getParameter("status")));
            session.saveOrUpdate(appcl);
        }
    } catch (HibernateException e) {
        throw ServiceException.FAILURE("hrmsHandler.approveAppraisalCycle", e);
    }
}

From source file:com.krawler.hrms.hrmsManager.java

License:Open Source License

public static String assignManagerFunction(Session session, HttpServletRequest request)
        throws ServiceException, SessionExpiredException {
    String result = "";
    List tabledata = null;//w ww.j  a  va2  s  .c o  m
    String[] userids = request.getParameterValues("userid");
    String[] reviewerids = request.getParameterValues("reviewerid");
    String[] managerids = request.getParameterValues("managerid");
    String hql;
    Assignmanager assign;
    Assignreviewer reviewer;
    try {
        if (Boolean.parseBoolean(request.getParameter("isManager"))) {
            for (int i = 0; i < userids.length; i++) {
                hql = "from Assignmanager where assignemp.userID=? and managerstatus=1";
                tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { userids[i] });
                Iterator ite = tabledata.iterator();
                while (ite.hasNext()) {
                    Assignmanager log = (Assignmanager) ite.next();
                    log.setManagerstatus(0);
                    session.update(log);
                }
            }
            for (int i = 0; i < userids.length; i++) {
                for (int j = 0; j < managerids.length; j++) {
                    assign = new Assignmanager();
                    assign.setAssignemp((User) session.load(User.class, userids[i]));
                    assign.setAssignman((User) session.load(User.class, managerids[j]));
                    assign.setManagerstatus(1);
                    session.saveOrUpdate(assign);
                }
            }
        } else {
            for (int i = 0; i < userids.length; i++) {
                hql = "from Assignreviewer where employee.userID=? and reviewerstatus=1";
                tabledata = HibernateUtil.executeQuery(session, hql, new Object[] { userids[i] });
                Iterator ite = tabledata.iterator();
                while (ite.hasNext()) {
                    Assignreviewer log = (Assignreviewer) ite.next();
                    log.setReviewerstatus(0);
                    session.update(log);
                }
            }
            for (int i = 0; i < userids.length; i++) {
                for (int j = 0; j < managerids.length; j++) {
                    reviewer = new Assignreviewer();
                    reviewer.setEmployee((User) session.load(User.class, userids[i]));
                    reviewer.setReviewer((User) session.load(User.class, managerids[j]));
                    reviewer.setReviewerstatus(1);
                    session.saveOrUpdate(reviewer);
                }
            }
        }
    } catch (ServiceException ex) {
        throw ServiceException.FAILURE("assignManagerFunction", ex);
    }
    return result;
}

From source file:com.lakeside.data.sqldb.BaseDao.java

License:Apache License

/**
 * ?//from w w w  .  j a v a2  s . com
 * @param entity
 * @return
 */
public T merge(final T entity) {
    Assert.notNull(entity, "entity?");
    Session session = getSession();
    String idName = getIdName();
    PropertyDescriptor idp = BeanUtils.getPropertyDescriptor(entityClass, idName);
    PK idvalue = null;
    try {
        idvalue = (PK) idp.getReadMethod().invoke(entity);
    } catch (Exception e) {
        throw new FatalBeanException("Could not copy properties from source to target", e);
    }
    T dest = null;
    if (idvalue != null) {
        dest = (T) session.get(entityClass, idvalue);
    }
    if (dest != null) {
        // merge the properties
        PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(entityClass);
        for (PropertyDescriptor p : descriptors) {
            if (p.getWriteMethod() != null) {
                try {
                    Method readMethod = p.getReadMethod();
                    if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
                        readMethod.setAccessible(true);
                    }
                    Object value = readMethod.invoke(entity);
                    if (value == null) {
                        continue;
                    }
                    Method writeMethod = p.getWriteMethod();
                    if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
                        writeMethod.setAccessible(true);
                    }
                    writeMethod.invoke(dest, value);
                } catch (Throwable ex) {
                    throw new FatalBeanException("Could not copy properties from source to target", ex);
                }
            }
        }
    } else {
        // destination object is empty, save the entity object parameted
        dest = entity;
    }
    session.saveOrUpdate(dest);
    logger.debug("merge entity: {}", entity);
    return dest;
}