List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static JSONObject verifyLogin(Session session, String username, String passwd, String subdomain) throws ServiceException { JSONObject jobj = new JSONObject(); try {/*from w ww . ja va 2 s . c om*/ String SELECT_USER_INFO = "select u, u.userLogin, u.company from User as u where u.userLogin.userName = ? and u.userLogin.password = ? and u.company.deleted=0 and u.deleteflag = 0 and u.company.subDomain=?"; List list = HibernateUtil.executeQuery(session, SELECT_USER_INFO, new Object[] { username, passwd, subdomain }); Iterator ite = list.iterator(); if (ite.hasNext()) { Object[] row = (Object[]) ite.next(); User user = (User) row[0]; UserLogin userLogin = (UserLogin) row[1]; Company company = (Company) row[2]; jobj.put("success", true); jobj.put("lid", userLogin.getUserID()); jobj.put("username", userLogin.getUserName()); jobj.put("companyid", company.getCompanyID()); jobj.put("company", company.getCompanyName()); jobj.put("roleid", user.getRoleID()); jobj.put("callwith", user.getCallwith()); jobj.put("timeformat", user.getTimeformat()); KWLTimeZone timeZone = user.getTimeZone(); if (timeZone == null) timeZone = company.getTimeZone(); if (timeZone == null) timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, "1"); jobj.put("timezoneid", timeZone.getTimeZoneID()); jobj.put("tzdiff", timeZone.getDifference()); jobj.put("tzid", timeZone.getTzID()); //@@hrms KWLDateFormat dateFormat = user.getDateFormat(); if (dateFormat == null) dateFormat = (KWLDateFormat) session.load(KWLDateFormat.class, "1"); jobj.put("dateformatid", dateFormat.getFormatID()); // jobj.put("dateformat", dateFormat.getJavaForm()); KWLCurrency currency = company.getCurrency(); if (currency == null) currency = (KWLCurrency) session.load(KWLCurrency.class, "1"); jobj.put("currencyid", currency.getCurrencyID()); // jobj.put("subscription",company.getSubscriptionCode()); //@@ for hrms String query = "select feature.featureName, permissionCode from UserPermission up where userLogin.userID=?"; list = HibernateUtil.executeQuery(session, query, userLogin.getUserID()); Iterator ite2 = list.iterator(); JSONArray jarr = new JSONArray(); while (ite2.hasNext()) { JSONObject jo = new JSONObject(); Object[] roww = (Object[]) ite2.next(); jo.put(roww[0].toString(), roww[1]); jarr.put(jo); } jobj.put("perms", jarr); } else { jobj.put("failure", true); } } catch (Exception e) { throw ServiceException.FAILURE("Auth.verifyLogin", e); } return jobj; }
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static JSONObject verifyLogin(Session session, String username, String subdomain) throws ServiceException { JSONObject jobj = new JSONObject(); try {//from w w w .jav a 2 s .co m String SELECT_USER_INFO = "select u, u.userLogin, u.company from User as u where u.userLogin.userName = ? and u.company.deleted=0 and u.deleteflag = 0 and u.company.subDomain=?"; List list = HibernateUtil.executeQuery(session, SELECT_USER_INFO, new Object[] { username, subdomain }); Iterator ite = list.iterator(); if (ite.hasNext()) { Object[] row = (Object[]) ite.next(); User user = (User) row[0]; UserLogin userLogin = (UserLogin) row[1]; Company company = (Company) row[2]; jobj.put("success", true); jobj.put("lid", userLogin.getUserID()); jobj.put("username", userLogin.getUserName()); jobj.put("companyid", company.getCompanyID()); jobj.put("company", company.getCompanyName()); jobj.put("callwith", user.getCallwith()); jobj.put("timeformat", user.getTimeformat()); jobj.put("roleid", user.getRoleID()); KWLTimeZone timeZone = user.getTimeZone(); if (timeZone == null) timeZone = company.getTimeZone(); if (timeZone == null) timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, "1"); jobj.put("timezoneid", timeZone.getTimeZoneID()); jobj.put("tzdiff", timeZone.getDifference()); KWLDateFormat dateFormat = user.getDateFormat(); if (dateFormat == null) dateFormat = (KWLDateFormat) session.load(KWLDateFormat.class, "1"); jobj.put("dateformatid", dateFormat.getFormatID()); // jobj.put("dateformat", dateFormat.getJavaForm()); KWLCurrency currency = company.getCurrency(); if (currency == null) currency = (KWLCurrency) session.load(KWLCurrency.class, "1"); jobj.put("currencyid", currency.getCurrencyID()); String query = "select feature.featureName, permissionCode from UserPermission up where userLogin.userID=?"; list = HibernateUtil.executeQuery(session, query, userLogin.getUserID()); Iterator ite2 = list.iterator(); JSONArray jarr = new JSONArray(); while (ite2.hasNext()) { JSONObject jo = new JSONObject(); Object[] roww = (Object[]) ite2.next(); jo.put(roww[0].toString(), roww[1]); jarr.put(jo); } jobj.put("perms", jarr); } else { jobj.put("failure", true); } } catch (Exception e) { throw ServiceException.FAILURE("Auth.verifyLogin", e); } return jobj; }
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static String getUser_hash(Session session, String userid) throws ServiceException { String res = ""; try {// w w w . j av a 2s . c om JSONObject resObj = new JSONObject(); User userObj = (User) session.load(User.class, userid); resObj.put("userhash", userObj.getUser_hash()); resObj.put("subdomain", userObj.getCompany().getSubDomain()); res = resObj.toString(); } catch (JSONException e) { throw ServiceException.FAILURE("AuthHandler.getUser_hash", e); } return res; }
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static DateFormat getUserDateFormatter(HttpServletRequest request, Session session) throws SessionExpiredException { KWLDateFormat df = (KWLDateFormat) session.load(KWLDateFormat.class, getDateFormatID(request)); String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); if (timeformat.equals("1")) { dateformat = df.getJavaForm().replace('H', 'h'); if (!dateformat.equals(df.getJavaForm())) dateformat += " a"; } else// w w w . j a v a2s. co m dateformat = df.getJavaForm(); SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf; }
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static JSONArray getPreferences(Session session, HttpServletRequest request) throws ServiceException { JSONArray preferences = new JSONArray(); try {//w w w. j a v a 2 s . c o m JSONObject j = new JSONObject(); String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, getTimeZoneID(request)); KWLDateFormat dateFormat = (KWLDateFormat) session.load(KWLDateFormat.class, getDateFormatID(request)); KWLCurrency currency = (KWLCurrency) session.load(KWLCurrency.class, getCurrencyID(request)); j.put("Timezone", timeZone.getName()); j.put("Timezoneid", timeZone.getTimeZoneID()); j.put("Timezonediff", timeZone.getDifference()); if (timeformat.equals("1")) { dateformat = dateFormat.getScriptForm().replace('H', 'h'); if (!dateformat.equals(dateFormat.getScriptForm())) dateformat += " T"; } else dateformat = dateFormat.getScriptForm(); j.put("DateFormat", dateformat); j.put("DateFormatid", dateFormat.getFormatID()); j.put("seperatorpos", dateFormat.getScriptSeperatorPosition()); j.put("Currency", currency.getHtmlcode()); j.put("CurrencyName", currency.getName()); j.put("CurrencySymbol", currency.getSymbol()); j.put("Currencyid", currency.getCurrencyID()); preferences.put(j); } catch (Exception e) { throw ServiceException.FAILURE("Auth.getPreferences", e); } return preferences; }
From source file:com.krawler.esp.handlers.AuthHandler.java
License:Open Source License
public static String getFullName(Session session, String userid) throws SessionExpiredException { return getFullName((User) session.load(User.class, userid)); }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static void saveActivity(Session session, HttpServletRequest request) throws ServiceException { try {/*w ww . j av a 2 s . c om*/ String id = request.getParameter("activityid"); ProjectActivity activity; if (StringUtil.isNullOrEmpty(id) == false) { activity = (ProjectActivity) session.load(ProjectActivity.class, id); } else { activity = new ProjectActivity(); ProjectFeature 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 (StringUtil.isNullOrEmpty(id) == false) { updatePermissionsForActivity(session, activity, activity.getFeature(), true); } } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.saveActivity", e); } }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static void saveFeature(Session session, HttpServletRequest request) throws ServiceException { try {/*from w ww. j ava2 s . c o m*/ String id = request.getParameter("featureid"); ProjectFeature feature; if (StringUtil.isNullOrEmpty(id) == false) { 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.PermissionHandler.java
License:Open Source License
public static void deleteFeature(Session session, HttpServletRequest request) throws ServiceException { try {//from www . ja v a 2 s . c o m String id = request.getParameter("featureid"); ProjectFeature feature; feature = (ProjectFeature) session.load(ProjectFeature.class, id); session.delete(feature); } catch (Exception e) { throw ServiceException.FAILURE("PermissionHandler.deleteFeature", e); } }
From source file:com.krawler.esp.handlers.PermissionHandler.java
License:Open Source License
public static void deleteActivity(Session session, HttpServletRequest request) throws ServiceException { try {//from w w w . j a v a2 s . c om String id = request.getParameter("activityid"); ProjectActivity activity; activity = (ProjectActivity) session.load(ProjectActivity.class, id); updatePermissionsForActivity(session, activity, activity.getFeature(), false); session.delete(activity); } catch (Exception e) { e.printStackTrace(); throw ServiceException.FAILURE("PermissionHandler.deleteActivity", e); } }