@GlobalDBOpenCloseAndUserPrivilages public Map getUserTypeSize( Session session, HttpServletRequest request, HttpServletResponse response, String LoggedInRegion, String LoggedInUser) { Map resultMap = new HashMap(); String isAccountModule = "No"; Map financialYearMap = new LinkedHashMap(); financialYearMap.put("0", "--Select--"); UserViewModel userObj = (UserViewModel) request.getSession(false).getAttribute("userDetails"); Criteria rcCriteria = session.createCriteria(Useroperatingrights.class); rcCriteria.add(Restrictions.sqlRestriction("userid = '" + userObj.getUserid() + "'")); rcCriteria.add(Restrictions.sqlRestriction("accessright is true")); rcCriteria.addOrder(Order.asc("usertypeid")); List rcList = rcCriteria.list(); resultMap.put("typesize", rcList.size()); Criteria fyearsCriteria = session.createCriteria(Accountingyear.class); List fyearsList = fyearsCriteria.list(); if (fyearsList.size() > 0) { for (int i = 0; i < fyearsList.size(); i++) { Accountingyear accountingyearObj = (Accountingyear) fyearsList.get(i); financialYearMap.put( accountingyearObj.getId(), (accountingyearObj.getStartyear() + "-" + accountingyearObj.getEndyear())); } } resultMap.put("financialYearMap", financialYearMap); if (rcList.size() == 1) { Useroperatingrights useroperatingrightsObj = (Useroperatingrights) rcList.get(0); Criteria privileageCriteria = session.createCriteria(Menuprivilages.class); privileageCriteria.add( Restrictions.sqlRestriction("usertype = " + useroperatingrightsObj.getUsertypeid())); privileageCriteria.add(Restrictions.sqlRestriction("accessright is true")); List privileageList = privileageCriteria.list(); if (privileageList.size() > 0) { for (int j = 0; j < privileageList.size(); j++) { Menuprivilages menuprivilagesObj = (Menuprivilages) privileageList.get(j); // // System.out.println("menuprivilagesObj.getMenumaster().getGrouptype()==" + // menuprivilagesObj.getMenumaster().getGrouptype()); if (menuprivilagesObj.getMenumaster().getGrouptype() == null) { } else if (menuprivilagesObj.getMenumaster().getGrouptype() == 'A') { isAccountModule = "Yes"; break; } } } } resultMap.put("isAccountModule", isAccountModule); return resultMap; }
public int getSequenceNumber(Session session) { int maxSequenceNumber = 1; try { StringBuffer sb = new StringBuffer(); sb.append("select max(cast(id as INTEGER)) as maxsequencenumber from menuprivilages"); List imlist = session.createSQLQuery(sb.toString()).list(); if (imlist.size() > 0) { if (imlist.get(0) != null) { maxSequenceNumber = (Integer) imlist.get(0); maxSequenceNumber = maxSequenceNumber + 1; } else { maxSequenceNumber = 1; } } else { maxSequenceNumber = 1; } } catch (Exception ex) { ex.printStackTrace(); } return maxSequenceNumber; }
@GlobalDBOpenCloseAndUserPrivilages public Map getAssignedMenus( Session session, HttpServletRequest request, HttpServletResponse response, String LoggedInRegion, String LoggedInUser, String usertypes) { Map resultMap = new HashMap(); Map menuMap = new LinkedHashMap(); try { Criteria menuCrit = session.createCriteria(Menuprivilages.class); menuCrit.add(Restrictions.sqlRestriction("usertype=" + Integer.parseInt(usertypes))); menuCrit.add(Restrictions.sqlRestriction("accessright is true")); List menuList = menuCrit.list(); if (menuList.size() > 0) { for (int i = 0; i < menuList.size(); i++) { Menuprivilages menuObj = (Menuprivilages) menuList.get(i); Criteria criteria = session.createCriteria(Menumaster.class); criteria.add(Restrictions.ne("parentcode", 0)); criteria.add(Restrictions.eq("code", menuObj.getMenumaster().getCode())); criteria.add(Restrictions.ne("methodname", "")); // criteria.add(Restrictions.sqlRestriction("code=" + // menuObj.getMenumaster().getCode()+" and parentcode!=0")); List menulist = criteria.list(); if (menulist.size() > 0) { menuMap.put( "accessright" + menuObj.getMenumaster().getCode(), "accessright" + menuObj.getMenumaster().getCode()); } } resultMap.put("menuMap", menuMap); } else { resultMap.put("ERROR", "Not Assigned"); } } catch (Exception e) { } return resultMap; }
public void insertParent(Session session, int menuId, int usertypes) { Transaction transaction = null; try { Criteria menuCrit = session.createCriteria(Menumaster.class); menuCrit.add(Restrictions.sqlRestriction("code=" + menuId)); List menuList = menuCrit.list(); if (menuList.size() > 0) { Menumaster menuObj = (Menumaster) menuList.get(0); Criteria menuCrit1 = session.createCriteria(Menuprivilages.class); menuCrit1.add(Restrictions.sqlRestriction("usertype=" + usertypes)); menuCrit1.add(Restrictions.sqlRestriction("menumaster=" + menuObj.getParentcode())); List menuList1 = menuCrit1.list(); if (menuList1.size() <= 0) { transaction = session.beginTransaction(); Usertype typeobj = new Usertype(); typeobj.setId(usertypes); Menumaster menuMasterObj = new Menumaster(); menuMasterObj.setCode(menuObj.getParentcode()); Menuprivilages menuObj2 = new Menuprivilages(); menuObj2.setId(String.valueOf(getSequenceNumber(session))); menuObj2.setUsertype(typeobj); menuObj2.setMenumaster(menuMasterObj); menuObj2.setAccessright(Boolean.TRUE); session.save(menuObj2); transaction.commit(); this.insertParent(session, menuObj.getParentcode(), usertypes); } } } catch (Exception e) { if (transaction != null) { transaction.rollback(); } e.printStackTrace(); } }
public void updateParent(Session session, int menuId, int usertypes) { Transaction transaction = null; try { Criteria menuCrit3 = session.createCriteria(Menuprivilages.class); menuCrit3.add(Restrictions.sqlRestriction("usertype=" + usertypes)); menuCrit3.add(Restrictions.sqlRestriction("menumaster=" + menuId)); List menuList3 = menuCrit3.list(); if (menuList3.size() > 0) { transaction = session.beginTransaction(); Menuprivilages menuObj3 = (Menuprivilages) menuList3.get(0); menuObj3.setAccessright(Boolean.TRUE); session.update(menuObj3); transaction.commit(); this.updateParent(session, menuObj3.getMenumaster().getParentcode(), usertypes); } } catch (Exception e) { if (transaction != null) { transaction.rollback(); } e.printStackTrace(); } }
@GlobalDBOpenCloseAndUserPrivilages public Map saveMenuAssign( Session session, HttpServletRequest request, HttpServletResponse response, String LoggedInRegion, String LoggedInUser, String usertypes, String menucodes) { Map resultMap = new HashMap(); String[] strArray = null; String delimiter = "-"; Transaction transaction = null; try { Criteria menuCrit = session.createCriteria(Menuprivilages.class); menuCrit.add(Restrictions.sqlRestriction("usertype=" + Integer.parseInt(usertypes))); List menuList = menuCrit.list(); if (menuList.size() > 0) { for (int i = 0; i < menuList.size(); i++) { Menuprivilages menuObj = (Menuprivilages) menuList.get(i); transaction = session.beginTransaction(); menuObj.setAccessright(Boolean.FALSE); session.update(menuObj); transaction.commit(); } if (!menucodes.equalsIgnoreCase("") && menucodes != null) { strArray = menucodes.split(java.util.regex.Pattern.quote(delimiter)); for (String menuId : strArray) { Criteria menuCrit1 = session.createCriteria(Menuprivilages.class); menuCrit1.add(Restrictions.sqlRestriction("usertype=" + Integer.parseInt(usertypes))); menuCrit1.add(Restrictions.sqlRestriction("menumaster=" + Integer.parseInt(menuId))); List menuList1 = menuCrit1.list(); if (menuList1.size() > 0) { transaction = session.beginTransaction(); Menuprivilages menuObj = (Menuprivilages) menuList1.get(0); menuObj.setAccessright(Boolean.TRUE); session.update(menuObj); transaction.commit(); this.updateParent( session, menuObj.getMenumaster().getParentcode(), menuObj.getUsertype().getId()); } else { transaction = session.beginTransaction(); Usertype typeobj = new Usertype(); typeobj.setId(Integer.parseInt(usertypes)); Menumaster menuMasterObj = new Menumaster(); menuMasterObj.setCode(Integer.parseInt(menuId)); Menuprivilages menuObj = new Menuprivilages(); menuObj.setId(String.valueOf(getSequenceNumber(session))); menuObj.setUsertype(typeobj); menuObj.setMenumaster(menuMasterObj); menuObj.setAccessright(Boolean.TRUE); session.saveOrUpdate(menuObj); transaction.commit(); this.insertParent(session, Integer.parseInt(menuId), Integer.parseInt(usertypes)); } } } } else { Criteria criteria = session.createCriteria(Menumaster.class); // criteria.add(Restrictions.ne("parentcode", 0)); criteria.addOrder(Order.asc("menuorder")); List menumasterlist = criteria.list(); if (menumasterlist.size() > 0) { for (int i = 0; i < menumasterlist.size(); i++) { Menumaster menuMasterObj = (Menumaster) menumasterlist.get(i); transaction = session.beginTransaction(); Usertype typeobj = new Usertype(); typeobj.setId(Integer.parseInt(usertypes)); Menuprivilages menuObj = new Menuprivilages(); menuObj.setId(String.valueOf(getSequenceNumber(session))); menuObj.setUsertype(typeobj); menuObj.setMenumaster(menuMasterObj); menuObj.setAccessright(Boolean.FALSE); session.save(menuObj); transaction.commit(); } } if (!menucodes.equalsIgnoreCase("") && menucodes != null) { strArray = menucodes.split(java.util.regex.Pattern.quote(delimiter)); for (String menuId : strArray) { Criteria menuCrit1 = session.createCriteria(Menuprivilages.class); menuCrit1.add(Restrictions.sqlRestriction("usertype=" + Integer.parseInt(usertypes))); menuCrit1.add(Restrictions.sqlRestriction("menumaster=" + Integer.parseInt(menuId))); List menuList1 = menuCrit1.list(); if (menuList1.size() > 0) { transaction = session.beginTransaction(); Menuprivilages menuObj = (Menuprivilages) menuList1.get(0); menuObj.setAccessright(Boolean.TRUE); session.update(menuObj); transaction.commit(); this.updateParent( session, menuObj.getMenumaster().getParentcode(), menuObj.getUsertype().getId()); } else { transaction = session.beginTransaction(); Usertype typeobj = new Usertype(); typeobj.setId(Integer.parseInt(usertypes)); Menumaster menuMasterObj = new Menumaster(); menuMasterObj.setCode(Integer.parseInt(menuId)); Menuprivilages menuObj = new Menuprivilages(); menuObj.setId(String.valueOf(getSequenceNumber(session))); menuObj.setUsertype(typeobj); menuObj.setMenumaster(menuMasterObj); menuObj.setAccessright(Boolean.TRUE); session.save(menuObj); transaction.commit(); this.insertParent(session, Integer.parseInt(menuId), Integer.parseInt(usertypes)); } } } } resultMap.put("success", "Successfully Menus Assigned"); } catch (Exception e) { e.printStackTrace(); if (transaction != null) { transaction.rollback(); } resultMap.put("ERROR", "Menus Assigning Faild"); } return resultMap; }