List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static void saveRole(Session session, HttpServletRequest request) throws ServiceException { try {/*from ww w .j a v a 2 s. c om*/ String id = request.getParameter("roleid"); Role role; if (StringUtil.isNullOrEmpty(id)) { role = new Role(); } else { role = (Role) session.load(Role.class, id); } role.setCompany((Company) session.load(Company.class, AuthHandler.getCompanyid(request))); role.setName(request.getParameter("rolename")); session.saveOrUpdate(role); } catch (Exception e) { throw ServiceException.FAILURE(e.getMessage(), e); } }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static void deleteRole(Session session, HttpServletRequest request) throws ServiceException { try {/*from www . j a v a2s .c o m*/ String id = request.getParameter("roleid"); if (id.equals(Role.SUPER_ADMIN) || id.equals(Role.COMPANY_ADMIN) || id.equals(Role.COMPANY_USER) || id.equals(Role.COMPANY_MANAGER)) { throw new Exception(MessageSourceProxy.getMessage("hrms.jsp.msg.cannotdeletepredefinedrole", null, "Can not delete Predefined Roles", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); } if (checkUserExistanceInRole(session, id)) { throw new Exception(MessageSourceProxy.getMessage( "hrms.jsp.msg.usersexistsforthisrolepleaseassignanotherroletotheseusers", null, "Users exists for this role, please assign another role to these users.", LocaleUtil.getCompanyLocale(AuthHandler.getCompanyid(request), 0))); } Role role = (Role) session.load(Role.class, id); session.delete(role); } catch (Exception e) { throw ServiceException.FAILURE(e.getMessage(), e); } }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static boolean isEmployee(Session session, HttpServletRequest request) throws ServiceException { boolean emp = false; try {//from w ww . j a v a 2s . com String userid = AuthHandler.getUserid(request); String companyid = AuthHandler.getCompanyid(request); Useraccount u = (Useraccount) session.load(Useraccount.class, userid); if (StringUtil.equal(u.getRole().getID(), Role.COMPANY_USER)) { // // request.getSession().getAttribute(keyName); // String jsondata = (String) request.getSession().getAttribute("permission"); // JSONArray jarr = new JSONArray("[" + jsondata + "]"); // JSONObject jobj=jarr.getJSONObject(0); // //JSONObject jobj1=jarr.getJSONObject(1); // if(jobj.getJSONObject("UPerm").optInt("user",-1)>0) // { // emp=true; // } emp = true; } } catch (Exception e) { e.printStackTrace(); throw ServiceException.FAILURE("PermissionHandler.isEmployee", e); } return emp; }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static boolean isManager(Session session, HttpServletRequest request) throws ServiceException { boolean man = false; try {//w w w .jav a 2 s . co m String userid = AuthHandler.getUserid(request); String companyid = AuthHandler.getCompanyid(request); Useraccount u = (Useraccount) session.load(Useraccount.class, userid); if (StringUtil.equal(u.getRole().getID(), Role.COMPANY_MANAGER)) { man = true; } } catch (Exception e) { e.printStackTrace(); throw ServiceException.FAILURE("PermissionHandler.isManager", e); } return man; }
From source file:com.krawler.esp.handlers.PermissionHandlercrm.java
License:Open Source License
public static void saveActivity(Session session, HttpServletRequest request) throws ServiceException { try {//from w ww.ja v a 2 s . com String id = request.getParameter("activityid"); ProjectActivity activity; ProjectFeature feature = null; if (id != null && id.length() > 0) { activity = (ProjectActivity) session.load(ProjectActivity.class, id); } else { activity = new ProjectActivity(); feature = (ProjectFeature) session.load(ProjectFeature.class, request.getParameter("featureid")); activity.setFeature(feature); } activity.setActivityName(request.getParameter("activityname")); activity.setDisplayActivityName(request.getParameter("displayactivityname")); session.saveOrUpdate(activity); if (id != null && id.length() > 0) { updatePermissionsForActivity(session, activity, feature, true); } } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.saveActivity", e); } }
From source file:com.krawler.esp.handlers.PermissionHandlercrm.java
License:Open Source License
public static void saveFeature(Session session, HttpServletRequest request) throws ServiceException { try {// w w w. j a v a2 s.c om String id = request.getParameter("featureid"); ProjectFeature feature; if (id != null && id.length() > 0) { feature = (ProjectFeature) session.load(ProjectFeature.class, id); } else { feature = new ProjectFeature(); } feature.setFeatureName(request.getParameter("featurename")); feature.setDisplayFeatureName(request.getParameter("displayfeaturename")); session.saveOrUpdate(feature); } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.saveFeature", e); } }
From source file:com.krawler.esp.handlers.PermissionHandlercrm.java
License:Open Source License
public static void saveRole(Session session, HttpServletRequest request) throws ServiceException { try {/*from w ww . ja va 2s . c om*/ String id = request.getParameter("roleid"); Rolelist role; if (id != null && id.length() > 0) { role = (Rolelist) session.load(Rolelist.class, id); } else { role = new Rolelist(); } role.setRolename(request.getParameter("rolename")); role.setDisplayrolename(request.getParameter("displayrolename")); session.saveOrUpdate(role); } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.saveRole", e); } }
From source file:com.krawler.esp.handlers.PermissionHandlercrm.java
License:Open Source License
public static void deleteRole(Session session, HttpServletRequest request) throws ServiceException { try {//from w w w . ja va 2s . c o m String id = request.getParameter("roleid"); Rolelist role; role = (Rolelist) session.load(Rolelist.class, id); session.delete(role); } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.deleteRole", e); } }
From source file:com.krawler.esp.handlers.ProfileHandler.java
License:Open Source License
public static void deleteUser(Session session, HttpServletRequest request) throws ServiceException { try {/* www .j ava 2s . c om*/ JSONObject jobj = new JSONObject(); JSONArray jArr = new JSONArray(); String[] ids = request.getParameterValues("userids"); for (int i = 0; i < ids.length; i++) { User u = (User) session.load(User.class, ids[i]); if (u.getRoleID() == 1) { throw new Exception("Cannot delete Administrator"); } //UserLogin userLogin = (UserLogin) session.load(UserLogin.class, ids[i]); u.setDeleteflag(1); session.saveOrUpdate(u); //session.delete(userLogin); } } 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 setPassword(Session session, HttpServletRequest request) throws ServiceException { try {/*from www .ja va2 s.c o m*/ String password = request.getParameter("password"); if (password == null || password.length() <= 0) { password = AuthHandler.generateNewPassword(); } String newpass = AuthHandler.getSHA1(password); User user = (User) session.load(User.class, request.getParameter("userid")); UserLogin userLogin = user.getUserLogin(); userLogin.setPassword(newpass); session.saveOrUpdate(userLogin); String uri = URLUtil.getPageURL(request, Links.loginpageFull); String fname = user.getFirstName(); if (StringUtil.isNullOrEmpty(fname)) { fname = user.getUserLogin().getUserName(); } String pmsg = String.format(KWLErrorMsgs.msgTempPassword, fname, password, uri); String htmlmsg = String.format(KWLErrorMsgs.msgMailPassword, fname, password, uri, uri); try { String adminEmailId = request.getSession().getAttribute("sysemailid").toString(); SendMailHandler.postMail(new String[] { user.getEmailID() }, KWLErrorMsgs.msgMailSubjectPassword, htmlmsg, pmsg, adminEmailId); } catch (MessagingException e) { e.printStackTrace(); } } catch (Exception e) { throw ServiceException.FAILURE("ProfileHandler.setPassword", e); } }