List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:getuser_bycity.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . ja v a 2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); String city = ""; HttpSession hs = request.getSession(); Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUName() + "is a " + ln.getURole()); switch (ln.getURole()) { case "agent": Criteria cr = ss.createCriteria(AgentDetail.class); cr.add(Restrictions.eq("uId", ln)); // / cr.add(Restrictions.ne(city, ln)) ArrayList<AgentDetail> ad = (ArrayList<AgentDetail>) cr.list(); city = ad.get(0).getACity(); break; case "customer": Criteria cr1 = ss.createCriteria(CustomerDetail.class); cr1.add(Restrictions.eq("uId", ln)); ArrayList<CustomerDetail> cd = (ArrayList<CustomerDetail>) cr1.list(); city = cd.get(0).getCCity(); break; default: System.out.println("No city"); } System.out.println(city + " is the city"); Criteria cr = ss.createCriteria(AgentDetail.class); cr.add(Restrictions.eq("aCity", city)); cr.add(Restrictions.ne("uId", ln)); ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr.list(); System.out.println("the size of agent aray is " + adl.size()); Criteria cr1 = ss.createCriteria(CustomerDetail.class); cr1.add(Restrictions.ne("uId", ln)); cr1.add(Restrictions.eq("cCity", city)); ArrayList<CustomerDetail> cdl = (ArrayList<CustomerDetail>) cr1.list(); System.out.println("the size of cust aray is " + cdl.size()); if (!adl.isEmpty() && !cdl.isEmpty()) { request.setAttribute("adl", adl); request.setAttribute("cdl", cdl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else if (!adl.isEmpty()) { request.setAttribute("adl", adl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else if (!cdl.isEmpty()) { request.setAttribute("cdl", cdl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else { String msg = "Sorry, there are no users from your city."; request.setAttribute("msg", msg); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:alpha.portal.service.impl.AlphaCardManagerImpl.java
License:Apache License
/** * Returns a {@link Criterion} to get all Adornments where the given userId * is not the contributor./*w w w .j a v a2s . c om*/ * * @param userId * the users id * @return a {@link Criterion} */ public static Criterion getContributorCriterionOthers(final String userId) { return Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.ne("ad.value", userId)); }
From source file:alpha.portal.service.impl.AlphaCardManagerImplTest.java
License:Apache License
/** * Test criterion./* w ww . j ava 2 s.c o m*/ */ @Test public void testCriterion() { Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.ne("ad.value", "123")).toString(), AlphaCardManagerImpl.getContributorCriterionOthers("123").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTOR, Restrictions.eq("ad.value", "123")).toString(), AlphaCardManagerImpl.getContributorCriterionOwn("123").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTORROLE, Restrictions.not(Restrictions.in("ad.value", new String[] { "role1" }))).toString(), AlphaCardManagerImpl.getContributorRoleCriterionOthers("role1").toString()); Assert.assertEquals( Restrictions.and(AlphaCardManagerImpl._CONTRIBUTORROLE, Restrictions.in("ad.value", new String[] { "role1" })).toString(), AlphaCardManagerImpl.getContributorRoleCriterionOwn("role1").toString()); }
From source file:apm.modules.sys.service.UserService.java
License:Open Source License
public Page<User> findUser(Page<User> page, User user) { DetachedCriteria dc = dao.createDetachedCriteria(); User currentUser = Users.currentUser(); dc.createAlias("company", "company"); if (user.getCompany() != null && StringUtils.isNotEmpty(user.getCompany().getId())) { dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()), //? Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%") //?? ));//from w w w. j a v a 2 s . co m } else { dc.add(Restrictions.or(Restrictions.eq("company.id", currentUser.getCompany().getId()), //? Restrictions.like("company.parentIds", "%," + currentUser.getCompany().getId() + ",%") //?? )); } /*dc.createAlias("office", "office"); if (user.getOffice()!=null && StringUtils.isNotEmpty(user.getOffice().getId())){ dc.add(Restrictions.or( Restrictions.eq("office.id", user.getOffice().getId()), // Restrictions.like("office.parentIds", "%,"+user.getOffice().getId()+",%") //? )); }else{ dc.add(Restrictions.or( Restrictions.eq("office.id", currentUser.getOffice().getId()), // Restrictions.like("office.parentIds", "%,"+currentUser.getOffice().getId()+",%") //? )); }*/ // ???? if (!currentUser.isAdmin()) { dc.add(Restrictions.ne("id", "1")); } /*if(user.getOffice() != null && StringUtils.isNotBlank(user.getOffice().getId())){ dc.add(dataScopeFilter(currentUser, "office", "")); }*/ /*dc.add(dataScopeFilter(currentUser, "office", ""));*/ //System.out.println(dataScopeFilterString(currentUser, "office", "")); if (StringUtils.isNotEmpty(user.getLoginName())) { dc.add(Restrictions.like("loginName", "%" + user.getLoginName() + "%")); } if (StringUtils.isNotEmpty(user.getName())) { dc.add(Restrictions.like("name", "%" + user.getName() + "%")); } dc.add(Restrictions.eq(User.DEL_FLAG, User.DEL_FLAG_NORMAL)); if (!StringUtils.isNotEmpty(page.getOrderBy())) { /*dc.addOrder(Order.asc("company.code")).addOrder(Order.asc("office.code")).addOrder(Order.desc("id"));*/ dc.addOrder(Order.asc("company.code")).addOrder(Order.desc("id")); } return dao.find(page, dc); }
From source file:au.org.theark.admin.model.dao.AdminDao.java
License:Open Source License
public List<ArkRoleModuleFunctionVO> searchPageableArkRoleModuleFunctionVO( ArkRoleModuleFunctionVO arkRoleModuleFunctionVo, int first, int count) { Criteria criteria = buildArkRoleModuleFunctionVoCriteria(arkRoleModuleFunctionVo); criteria.setFirstResult(first);//from w ww.j a va 2 s. c o m criteria.setMaxResults(count); // Restrict to NOT show Super Administrator (safety) // NOTE arpt alias set in buildarkRoleModuleFunctionVoCriteria criteria.add((Restrictions.ne("arpt.arkRole", getArkRoleByName(au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)))); List<ArkRoleModuleFunctionVO> list = criteria.list(); return list; }
From source file:au.org.theark.admin.model.dao.AdminDao.java
License:Open Source License
public List<ArkRole> getArkRoleListByArkModule(ArkModule arkModule) { Criteria criteria = getSession().createCriteria(ArkModuleRole.class); if (arkModule.getId() != null) { criteria.add(Restrictions.eq("arkModule", arkModule)); }/*from w ww .jav a 2 s . c om*/ // Restrict searching/selecting of Super Administrator criteria.add(Restrictions.ne("arkModule", getArkRoleByName(au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR))); criteria.createAlias("arkRole", "role"); criteria.addOrder(Order.asc("role.name")); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("arkRole"), "arkRole"); criteria.setProjection(projectionList); return criteria.list(); }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * A common method that can be used to apply a search filter on Study entity via a Criteria that is passed from the caller. The Criteria's entity * can be determined by the caller ( i.e can be Study.class or ArkUserRole.class), this is useful when the ArkUser is a SuperAdministrator when we * want all the studies to be displayed.In such a case the Criteria object must be the Study entity to include all studies. * //from w w w.j a v a2 s. com * @param searchStudy * @param studyCriteria */ private void applyStudySearchCriteria(Study searchStudy, Criteria studyCriteria, boolean isSuperUser) { if (searchStudy.getId() != null) { studyCriteria.add(Restrictions.eq(Constants.STUDY_KEY, searchStudy.getId())); } if (searchStudy.getName() != null) { studyCriteria.add(Restrictions.ilike(Constants.STUDY_NAME, searchStudy.getName(), MatchMode.ANYWHERE)); } if (searchStudy.getDateOfApplication() != null) { studyCriteria.add(Restrictions.eq(Constants.DATE_OF_APPLICATION, searchStudy.getDateOfApplication())); } if (searchStudy.getEstimatedYearOfCompletion() != null) { studyCriteria.add( Restrictions.eq(Constants.EST_YEAR_OF_COMPLETION, searchStudy.getEstimatedYearOfCompletion())); } if (searchStudy.getChiefInvestigator() != null) { studyCriteria.add(Restrictions.ilike(Constants.CHIEF_INVESTIGATOR, searchStudy.getChiefInvestigator(), MatchMode.ANYWHERE)); } if (searchStudy.getContactPerson() != null) { studyCriteria.add(Restrictions.ilike(Constants.CONTACT_PERSON, searchStudy.getContactPerson(), MatchMode.ANYWHERE)); } if (searchStudy.getStudyStatus() != null) { // In future, Super Administrators may be able to search for Archived studies studyCriteria.add(Restrictions.eq("studyStatus", searchStudy.getStudyStatus())); if (!isSuperUser) { // If not a Super Admin always remove Archived studies try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne("studyStatus", status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } } else { // If no status is selected, then default to return all except Archived try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne("studyStatus", status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } studyCriteria.addOrder(Order.asc("parentStudy")); studyCriteria.addOrder(Order.asc("id")); studyCriteria.addOrder(Order.asc("name")); }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getStudyListForUserAndModule(ArkUserVO arkUserVo, ArkModule arkModule) { List<Study> studyList = new ArrayList<Study>(0); Study searchStudy = arkUserVo.getStudy(); Criteria criteria = getSession().createCriteria(ArkUserRole.class); try {// w ww . j a v a2s.c o m // Restrict by user if NOT Super Administrator if (isUserAdminHelper(arkUserVo.getArkUserEntity().getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { // Fix another bug where the Super Administrator will never be able to INNER JOIN between ArkUserRole and Study on studyId // (since a Super Admin should always have null in the arkUserRole's study column) studyList = getAllStudiesForSuperAdmin(arkUserVo.getStudy()); // Get all Studies return studyList; } else { // Not Super Administrator, so continue with building the query criteria.add(Restrictions.eq("arkUser", arkUserVo.getArkUserEntity())); } } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } if (arkModule != null) { criteria.add(Restrictions.eq("arkModule", arkModule)); } else { // If no arkModule supplied, return empty list log.error("No arkModule supplied, returning empty study list"); return studyList; } // Restrict on study criteria (by default, NOT 'Archive' status) Criteria studyCriteria = criteria.createCriteria("study"); if (searchStudy.getId() != null) { studyCriteria.add(Restrictions.eq(Constants.STUDY_KEY, searchStudy.getId())); } if (searchStudy.getName() != null) { studyCriteria.add(Restrictions.ilike(Constants.STUDY_NAME, searchStudy.getName(), MatchMode.ANYWHERE)); } if (searchStudy.getDateOfApplication() != null) { studyCriteria.add(Restrictions.eq(Constants.DATE_OF_APPLICATION, searchStudy.getDateOfApplication())); } if (searchStudy.getEstimatedYearOfCompletion() != null) { studyCriteria.add( Restrictions.eq(Constants.EST_YEAR_OF_COMPLETION, searchStudy.getEstimatedYearOfCompletion())); } if (searchStudy.getChiefInvestigator() != null) { studyCriteria.add(Restrictions.ilike(Constants.CHIEF_INVESTIGATOR, searchStudy.getChiefInvestigator(), MatchMode.ANYWHERE)); } if (searchStudy.getContactPerson() != null) { studyCriteria.add(Restrictions.ilike(Constants.CONTACT_PERSON, searchStudy.getContactPerson(), MatchMode.ANYWHERE)); } if (searchStudy.getStudyStatus() != null) { studyCriteria.add(Restrictions.eq("studyStatus", searchStudy.getStudyStatus())); try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne("studyStatus", status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } else { try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne("studyStatus", status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); studyCriteria.addOrder(Order.asc("parentStudy")); criteria.setProjection(projectionList); studyList = criteria.list(); return studyList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getParentStudyList() { List<Study> studyList = new ArrayList<Study>(0); // Restrict on study criteria (by default, NOT 'Archive' status) Criteria studyCriteria = getSession().createCriteria(Study.class); StudyStatus status;//www . j av a 2 s .co m try { status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne("studyStatus", status)); } catch (StatusNotAvailableException e) { log.error(e.getMessage(), e); } // Can only select studies with null parent, or where the study is a parent studyCriteria.add(Restrictions.disjunction().add(Restrictions.isNull("parentStudy")) .add(Restrictions.eqProperty("parentStudy.id", "id"))); studyCriteria.addOrder(Order.asc("name")); studyList = studyCriteria.list(); return studyList; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getStudy(Study study) { Criteria studyCriteria = getSession().createCriteria(Study.class); if (study.getId() != null) { studyCriteria.add(Restrictions.eq(Constants.STUDY_KEY, study.getId())); }//from www. j a v a2 s . c om if (study.getName() != null) { studyCriteria.add(Restrictions.ilike(Constants.STUDY_NAME, study.getName(), MatchMode.ANYWHERE)); } if (study.getDateOfApplication() != null) { studyCriteria.add(Restrictions.eq(Constants.DATE_OF_APPLICATION, study.getDateOfApplication())); } if (study.getEstimatedYearOfCompletion() != null) { studyCriteria .add(Restrictions.eq(Constants.EST_YEAR_OF_COMPLETION, study.getEstimatedYearOfCompletion())); } if (study.getChiefInvestigator() != null) { studyCriteria.add(Restrictions.ilike(Constants.CHIEF_INVESTIGATOR, study.getChiefInvestigator(), MatchMode.ANYWHERE)); } if (study.getContactPerson() != null) { studyCriteria.add( Restrictions.ilike(Constants.CONTACT_PERSON, study.getContactPerson(), MatchMode.ANYWHERE)); } if (study.getStudyStatus() != null) { studyCriteria.add(Restrictions.eq(Constants.STUDY_STATUS, study.getStudyStatus())); try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne(Constants.STUDY_STATUS, status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } else { try { StudyStatus status = getStudyStatus("Archive"); studyCriteria.add(Restrictions.ne(Constants.STUDY_STATUS, status)); } catch (StatusNotAvailableException notAvailable) { log.error("Cannot look up and filter on archive status. Reference data could be missing"); } } studyCriteria.addOrder(Order.asc(Constants.STUDY_NAME)); List<Study> studyList = studyCriteria.list(); return studyList; }