Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

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

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void setPermissions(Session session, HttpServletRequest request) throws ServiceException {
    try {//w  ww.j  av  a 2 s .  c  o m
        String id = request.getParameter("roleid");
        String[] features = request.getParameterValues("features");
        String[] permissions = request.getParameterValues("permissions");
        String sql = "delete from UserPermission where role.ID=?";
        HibernateUtil.executeUpdate(session, sql, id);
        Role role = (Role) session.load(Role.class, id);
        for (int i = 0; i < features.length; i++) {
            if (permissions[i].equals("0")) {
                continue;
            }
            UserPermission permission = new UserPermission();
            permission.setRole(role);
            permission.setFeature((ProjectFeature) session.load(ProjectFeature.class, features[i]));
            permission.setPermissionCode(Long.parseLong(permissions[i]));
            session.save(permission);
        }
        // insertAuditLog(session, AuditAction.PERMISSIONS_MODIFIED, AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has changed the permissions of role " + role.getName(), request);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.setPermissions", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void updateLastLogin(Session session, HttpServletRequest request) throws ServiceException {
    try {/* w  w w  .j  a va  2  s  .co m*/
        UserLogin userLogin = (UserLogin) session.load(UserLogin.class, AuthHandler.getUserid(request));
        userLogin.setLastActivityDate(new Date());
        session.update(userLogin);
        //   insertAuditLog(session, AuditAction.LOG_IN_SUCCESS, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has logged in", request);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.updateLastLogin", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void updateCompany(Session session, HttpServletRequest request, HashMap hm)
        throws ServiceException {
    try {//from  w  w w .ja va2s  . co m
        CompanyPreferences cp = (CompanyPreferences) session.load(CompanyPreferences.class,
                AuthHandler.getCompanyid(request));
        Company company = cp.getCompany();
        company.setCompanyName((String) hm.get("companyname"));
        company.setAddress((String) hm.get("address"));
        company.setCity((String) hm.get("city"));
        company.setState((String) hm.get("state"));
        company.setZipCode((String) hm.get("zip"));
        company.setPhoneNumber((String) hm.get("phone"));
        company.setFaxNumber((String) hm.get("fax"));
        company.setWebsite((String) hm.get("website"));
        company.setEmailID((String) hm.get("mail"));
        company.setSubDomain((String) hm.get("domainname"));
        cp.setEmpidformat((String) hm.get("employeeidformat"));
        company.setCountry((Country) session.load(Country.class, (String) hm.get("country")));
        company.setCurrency((KWLCurrency) session.load(KWLCurrency.class, (String) hm.get("currency")));
        KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, (String) hm.get("timezone"));
        company.setTimeZone(timeZone);
        company.setModifiedOn(new Date());
        JSONArray jArr = new JSONArray((String) hm.get("holidays"));
        Set<CompanyHoliday> holidays = company.getHolidays();
        holidays.clear();
        DateFormat formatter = AuthHandler.getDateFormatter(request);
        for (int i = 0; i < jArr.length(); i++) {
            CompanyHoliday day = new CompanyHoliday();
            JSONObject obj = jArr.getJSONObject(i);
            day.setDescription(obj.getString("description"));
            day.setHolidayDate(formatter.parse(obj.getString("day")));
            day.setCompany(company);
            holidays.add(day);
        }
        String imageName = ((FileItem) (hm.get("logo"))).getName();
        if (StringUtil.isNullOrEmpty(imageName) == false) {
            String fileName = AuthHandler.getCompanyid(request) + FileUploadHandler.getCompanyImageExt();
            company.setCompanyLogo(ProfileImageServlet.ImgBasePath + fileName);
            new FileUploadHandler().uploadImage((FileItem) hm.get("logo"), fileName,
                    StorageHandler.GetProfileImgStorePath(), 130, 25, true, false);
        }
        session.update(company);
        SessionHandler.updatePreferences(request, (String) hm.get("currency"), null,
                (String) hm.get("timezone"), timeZone.getDifference());
        // insertAuditLog(session, AuditAction.COMPANY_UPDATION, "User " + AuthHandler.getUserName(request) + " changed company details", request);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.updateCompany", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void deletecompany(Session session, HttpServletRequest request) throws ServiceException {
    try {/*from   ww  w .j  a v  a2s  .  c o  m*/
        String[] ids = request.getParameterValues("cmpid");
        for (int i = 0; i < ids.length; i++) {
            Company c = (Company) session.load(Company.class, ids[i]);
            c.setDeleted(1);
            session.saveOrUpdate(c);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.deletecompanies", e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static JSONObject changePassword(String platformURL, Session session, HttpServletRequest request)
        throws ServiceException {
    JSONObject jobj = new JSONObject();
    String msg = "";
    try {/* ww  w  .j  ava2 s  .  c  o  m*/
        String password = request.getParameter("currentpassword");
        String pwd = request.getParameter("changepassword").toString();
        String uid = AuthHandler.getUserid(request);
        String companyid = AuthHandler.getCompanyid(request);

        if (password == null || password.length() <= 0) {
            msg = MessageSourceProxy.getMessage("hrms.common.InvalidPassword", null, "Invalid Password.",
                    RequestContextUtils.getLocale(request));
        } else {
            //String newpass=AuthHandler.getSHA1(password);
            if (StringUtil.isStandAlone()) {
                platformURL = "";
            }
            if (!StringUtil.isNullOrEmpty(platformURL)) {
                JSONObject userData = new JSONObject();
                userData.put("pwd", pwd);
                userData.put("oldpwd", password);
                userData.put("userid", uid);
                userData.put("remoteapikey", StorageHandler.GetRemoteAPIKey());
                String action = "3";
                JSONObject resObj = APICallHandler.callApp(platformURL, userData, companyid, action);
                if (!resObj.isNull("success") && resObj.getBoolean("success")) {
                    User user = (User) session.load(User.class, uid);
                    UserLogin userLogin = user.getUserLogin();
                    userLogin.setPassword(pwd);
                    session.saveOrUpdate(userLogin);
                    msg = MessageSourceProxy.getMessage("hrms.common.PasswordChangedsuccessfully", null,
                            "Invalid Password.", RequestContextUtils.getLocale(request));

                } else {
                    if (!resObj.isNull("errorcode") && resObj.getString("errorcode").equals("e10")) {
                        msg = MessageSourceProxy.getMessage("hrms.common.OldpasswordisincorrectPleasetryagain",
                                null, "Invalid Password.", RequestContextUtils.getLocale(request));
                    } else {
                        msg = MessageSourceProxy.getMessage("hrms.common.ErrorinchangingPassword", null,
                                "Invalid Password.", RequestContextUtils.getLocale(request));
                    }
                }
            } else {
                User user = (User) session.load(User.class, uid);
                UserLogin userLogin = user.getUserLogin();
                String currentpass = userLogin.getPassword();
                if (StringUtil.equal(password, currentpass)) {
                    userLogin.setPassword(pwd);
                    session.saveOrUpdate(userLogin);
                    msg = MessageSourceProxy.getMessage("hrms.common.PasswordChangedsuccessfully", null,
                            "Invalid Password.", RequestContextUtils.getLocale(request));
                } else {
                    msg = MessageSourceProxy.getMessage("hrms.common.OldpasswordisincorrectPleasetryagain",
                            null, "Invalid Password.", RequestContextUtils.getLocale(request));
                }
            }
        }
        jobj.put("msg", msg);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ProfileHandler.setPassword", e);
    }
    return jobj;
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void insertAuditLog(Session session, String actionid, String details, HttpServletRequest request,
        String recid) throws ServiceException {
    try {//from   w  w w.  j a va  2s.co m
        AuditAction action = (AuditAction) session.load(AuditAction.class, actionid);
        insertAuditLog(session, action, details, request, recid);
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void insertAuditLog(Session session, String actionid, String details, String ipAddress,
        String userid, String recid) throws ServiceException {
    try {/*from   w ww .ja v a2s  .  c  om*/
        AuditAction action = (AuditAction) session.load(AuditAction.class, actionid);
        User user = (User) session.load(User.class, userid);
        insertAuditLog(session, action, details, ipAddress, user, recid);
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

License:Open Source License

public static void insertAuditLog(Session session, AuditAction action, String details,
        HttpServletRequest request, String recid) throws ServiceException {
    try {//from w w  w  .ja  va 2 s. c om
        User user = (User) session.load(User.class, AuthHandler.getUserid(request));
        String ipaddr = null;
        if (StringUtil.isNullOrEmpty(request.getHeader("x-real-ip"))) {
            ipaddr = request.getRemoteAddr();
        } else {
            ipaddr = request.getHeader("x-real-ip");
        }

        insertAuditLog(session, action, details, ipaddr, user, recid);
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

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  a  va  2 s. co  m*/
        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  a  v a  2 s .  co m
        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);
    }
}