List of usage examples for org.hibernate.criterion Restrictions not
public static Criterion not(Criterion expression)
From source file:alpha.portal.service.impl.AlphaCardManagerImpl.java
License:Apache License
/** * Returns a {@link Criterion} to get all Adornments where the * contributorrole is not in roles.// w ww. ja v a 2s . c om * * @param roles * the roles * @return a {@link Criterion} */ public static Criterion getContributorRoleCriterionOthers(final String... roles) { return Restrictions.and(AlphaCardManagerImpl._CONTRIBUTORROLE, Restrictions.not(Restrictions.in("ad.value", roles))); }
From source file:alpha.portal.service.impl.AlphaCardManagerImplTest.java
License:Apache License
/** * Test criterion./*from w w w. j a v a2s .co 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:ar.com.zauber.commons.repository.query.visitor.CriteriaFilterVisitor.java
License:Apache License
/** * Niega la condicion si es necesario./* ww w.j ava 2s . c om*/ * * @param baseFilterObject */ private void negateIfNeeded(final BaseFilter baseFilterObject) { if (baseFilterObject.getNegated()) { criterion = Restrictions.not(criterion); } }
From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.impl.slotsengine.DayBookings.java
License:Open Source License
/** * Loads all the bookings for the day into memory. * /* ww w.j ava 2 s .c o m*/ * @return ses database session */ @SuppressWarnings("unchecked") public void fullLoad(Session ses) { if (this.hasFullLoad) return; int num = 0; /* Load all the rigs that have bookings today. */ for (Rig rig : (List<Rig>) ses.createCriteria(Rig.class).list()) { if (this.rigBookings.containsKey(rig.getName())) continue; if ((num = (Integer) ses.createCriteria(Bookings.class).add(Restrictions.eq("active", Boolean.TRUE)) .add(this.addDayRange()).add(Restrictions.eq("resourceType", ResourcePermission.RIG_PERMISSION)) .add(Restrictions.eq("rig", rig)).setProjection(Projections.rowCount()).uniqueResult()) == 0) continue; this.logger.debug( "Rig " + rig.getName() + " has " + num + " bookings, so loading it up for full day load."); this.getRigBookings(rig, ses); } /* Load all the rig types that have bookings today. */ Criteria qu = ses.createCriteria(RigType.class); if (this.typeTargets.size() > 0) qu.add(Restrictions.not(Restrictions.in("name", this.typeTargets.keySet()))); for (RigType type : (List<RigType>) qu.list()) { if (this.typeTargets.containsKey(type.getName())) continue; if ((num = (Integer) ses.createCriteria(Bookings.class).add(Restrictions.eq("active", Boolean.TRUE)) .add(this.addDayRange()) .add(Restrictions.eq("resourceType", ResourcePermission.TYPE_PERMISSION)) .add(Restrictions.eq("rigType", type)).setProjection(Projections.rowCount()) .uniqueResult()) == 0) continue; this.logger.debug("Rig type " + type.getName() + " has " + num + " bookings, so loading it up for" + " full day load."); Set<Rig> rigs = type.getRigs(); if (rigs.size() == 0) { this.logger.warn("Rig type " + type.getName() + " has " + num + " bookings but not rigs so they all" + " will be cancelled."); for (Bookings bk : (List<Bookings>) ses.createCriteria(Bookings.class) .add(Restrictions.eq("active", Boolean.TRUE)).add(this.addDayRange()) .add(Restrictions.eq("resourceType", ResourcePermission.TYPE_PERMISSION)) .add(Restrictions.eq("rigType", type)).list()) { this.logger.warn("Cancelling booking for " + bk.getUser().qName() + " because booking rig type " + type.getName() + " has no rigs."); bk.setActive(false); bk.setCancelReason("Booked rig type has no rigs."); new BookingNotification(bk).notifyCancel(); } ses.beginTransaction(); ses.flush(); ses.getTransaction().commit(); continue; } this.getRigBookings(rigs.iterator().next(), ses); } /* Load all the request capabilities that have bookings today. */ qu = ses.createCriteria(RequestCapabilities.class); if (this.capsTargets.size() > 0) qu.add(Restrictions.not(Restrictions.in("capabilities", this.capsTargets.keySet()))); for (RequestCapabilities caps : (List<RequestCapabilities>) qu.list()) { if (this.capsTargets.containsKey(caps.getCapabilities())) continue; if ((num = (Integer) ses.createCriteria(Bookings.class).add(Restrictions.eq("active", Boolean.TRUE)) .add(this.addDayRange()) .add(Restrictions.eq("resourceType", ResourcePermission.CAPS_PERMISSION)) .add(Restrictions.eq("requestCapabilities", caps)).setProjection(Projections.rowCount()) .uniqueResult()) == 0) continue; this.logger.debug("Request capabilities " + caps.getCapabilities() + " has " + num + " bookings, so " + "loading it up for full day load."); List<RequestCapabilities> capsList = new ArrayList<RequestCapabilities>(); capsList.add(caps); this.loadRequestCapabilities(capsList, ses, true); if (!this.capsTargets.containsKey(caps.getCapabilities())) { this.logger.warn("Request capabilities " + caps.getCapabilities() + " has " + num + " bookings but " + "not any matching rigs so they all will be cancelled."); for (Bookings bk : (List<Bookings>) ses.createCriteria(Bookings.class) .add(Restrictions.eq("active", Boolean.TRUE)).add(this.addDayRange()) .add(Restrictions.eq("resourceType", ResourcePermission.CAPS_PERMISSION)) .add(Restrictions.eq("requestCapabilities", caps)).list()) { this.logger.warn("Cancelling booking for " + bk.getUser().qName() + " because booking request " + "capabilities " + caps.getCapabilities() + " has no matching rigs."); bk.setActive(false); bk.setCancelReason("Booked request capabilities has no rigs."); new BookingNotification(bk).notifyCancel(); } ses.beginTransaction(); ses.flush(); ses.getTransaction().commit(); } } }
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.pages.UsersPage.java
License:Open Source License
/** * Gets a list of users with a specific search term. The users may be * excluded from a specific class. //from w w w .j a v a2s . co m * * @param request * @return response * @throws Exception */ @SuppressWarnings("unchecked") public JSONArray list(HttpServletRequest request) throws JSONException { JSONArray arr = new JSONArray(); Criteria qu = this.db.createCriteria(User.class); String search = request.getParameter("search"); if (search != null) { /* Search filter. */ qu.add(Restrictions.disjunction().add(Restrictions.like("name", search, MatchMode.ANYWHERE)) .add(Restrictions.like("firstName", search, MatchMode.ANYWHERE)) .add(Restrictions.like("lastName", search, MatchMode.ANYWHERE))); } if (request.getParameter("max") != null) { /* Max results. */ qu.setMaxResults(Integer.parseInt(request.getParameter("max"))); } if (request.getParameter("in") != null) { /* Users in class. */ UserClass inClass = new UserClassDao(this.db).findByName(request.getParameter("in")); if (inClass == null) { this.logger.warn("Not going to add in class as a user list restriction because the class '" + request.getParameter("in") + "' was not found."); } else { qu.createCriteria("userAssociations").add(Restrictions.eq("userClass", inClass)); } } if (request.getParameter("notIn") != null) { /* Users not in class. */ UserClass notInClass = new UserClassDao(this.db).findByName(request.getParameter("notIn")); if (notInClass == null) { this.logger.warn("Not going to add not in class as a user list restriction because the class '" + request.getParameter("notIn") + "' was not found."); } else { DetachedCriteria subQu = DetachedCriteria.forClass(User.class) .setProjection(Property.forName("name")).createCriteria("userAssociations") .add(Restrictions.eq("userClass", notInClass)); List<String> names = subQu.getExecutableCriteria(this.db).list(); if (names.size() > 0) { qu.add(Restrictions.not(Restrictions.in("name", names))); } } } qu.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); qu.addOrder(Order.asc("lastName")); qu.addOrder(Order.asc("name")); for (User user : (List<User>) qu.list()) { JSONObject uo = new JSONObject(); uo.put("name", user.getNamespace() + "-_-" + user.getName()); if (user.getFirstName() == null || user.getLastName() == null) { uo.put("display", user.getName()); } else { uo.put("display", user.getLastName() + ", " + user.getFirstName()); } arr.put(uo); } return arr; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
private Criteria buildGeneralSubjectCriteria(SubjectVO subjectVO) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("person", "p"); if (subjectVO.getLinkSubjectStudy().getStudy() != null) { criteria.add(Restrictions.eq("study.id", subjectVO.getLinkSubjectStudy().getStudy().getId())); } else {/*from ww w. j av a 2s. c o m*/ criteria.add(Restrictions.in("study", subjectVO.getStudyList())); criteria.createAlias("study", "st"); criteria.addOrder(Order.asc("st.name")); } if (subjectVO.getLinkSubjectStudy().getPerson() != null) { if (subjectVO.getLinkSubjectStudy().getPerson().getId() != null) { criteria.add(Restrictions.eq("p.id", subjectVO.getLinkSubjectStudy().getPerson().getId())); } if (subjectVO.getLinkSubjectStudy().getPerson().getFirstName() != null) { criteria.add(Restrictions.ilike("p.firstName", subjectVO.getLinkSubjectStudy().getPerson().getFirstName(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getPerson().getMiddleName() != null) { criteria.add(Restrictions.ilike("p.middleName", subjectVO.getLinkSubjectStudy().getPerson().getMiddleName(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getPerson().getLastName() != null) { /* old code pre George adding personlastname lookup criteria.add(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE));*/ //log.info("Lastname: " + subjectVO.getLinkSubjectStudy().getPerson().getLastName()); DetachedCriteria previousLastNames = DetachedCriteria.forClass(PersonLastnameHistory.class, "l") .setProjection(Projections.property("l.lastName")) .add(Restrictions.ilike("l.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE)) .add(Restrictions.eqProperty("p.id", "l.person.id")); criteria.add(Restrictions.or(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE), Subqueries.exists(previousLastNames))); } if (subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth() != null) { criteria.add(Restrictions.eq("p.dateOfBirth", subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth())); } if (subjectVO.getLinkSubjectStudy().getPerson().getGenderType() != null) { criteria.add(Restrictions.eq("p.genderType.id", subjectVO.getLinkSubjectStudy().getPerson().getGenderType().getId())); } if (subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus() != null) { criteria.add(Restrictions.eq("p.vitalStatus.id", subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus().getId())); } if (!subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().isEmpty()) { OtherID o = (OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]; if (o != null && o.getOtherID() != null && !o.getOtherID().isEmpty()) { log.info("OtherID search"); // DetachedCriteria otherID = DetachedCriteria.forClass(OtherID.class, "O") // .setProjection(Projections.projectionList().add(Projections.property("O.otherID"))) // .add(Restrictions.ilike("O.otherID", ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]).getOtherID(), MatchMode.EXACT)) // .add(Restrictions.eqProperty("p.id", "O.person.id")); // criteria.add(Subqueries.exists(otherID)); criteria.createAlias("p.otherIDs", "o"); criteria.add(Restrictions.ilike("o.otherID", ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]) .getOtherID(), MatchMode.ANYWHERE)); criteria.setProjection(Projections.distinct( Projections.projectionList().add(Projections.property("o.personid"), "lss.person.id"))); } } } if (subjectVO.getLinkSubjectStudy().getSubjectUID() != null && subjectVO.getLinkSubjectStudy().getSubjectUID().length() > 0) { criteria.add(Restrictions.ilike("subjectUID", subjectVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } if (subjectVO.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq("subjectStatus", subjectVO.getLinkSubjectStudy().getSubjectStatus())); SubjectStatus subjectStatus = getSubjectStatus("Archive"); if (subjectStatus != null) { criteria.add(Restrictions.ne("subjectStatus", subjectStatus)); } } else { SubjectStatus subjectStatus = getSubjectStatus("Archive"); if (subjectStatus != null) { criteria.add(Restrictions.ne("subjectStatus", subjectStatus)); } } if (subjectVO.getRelativeUIDs().size() > 0) { criteria.add(Restrictions.not(Restrictions.in("subjectUID", subjectVO.getRelativeUIDs().toArray()))); } criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.id()))); criteria.addOrder(Order.asc("subjectUID")); return criteria; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<ConsentStatus> getRecordableConsentStatus() { Criteria criteria = getSession().createCriteria(ConsentStatus.class); criteria.add(Restrictions.not(Restrictions.ilike("name", "Not Consented", MatchMode.ANYWHERE))); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public Collection<UploadType> getUploadTypesForSubject(Study study) { Criteria criteria = getSession().createCriteria(UploadType.class); criteria.add(Restrictions.eq("arkModule", getArkModuleForSubject())); if (study != null && study.getParentStudy() != null) { //i.e. study is a child study criteria.add(Restrictions.not(Restrictions.eq("name", "Subject Demographic Data"))); }// ww w .j a va2 s .com return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
@Override public List<StudyComp> getStudyComponentsNeverUsedInThisSubject(Study study, LinkSubjectStudy linkSubjectStudy) { List<StudyComp> consentStudyCompLst = getDifferentStudyComponentsInConsentForSubject(study, linkSubjectStudy);/* ww w. j a va 2 s .c om*/ List<Long> consentStudyCompIdLst = new ArrayList<Long>(); for (StudyComp studyComp : consentStudyCompLst) { consentStudyCompIdLst.add(studyComp.getId()); } Criteria criteria = getSession().createCriteria(StudyComp.class); criteria.add(Restrictions.eq("study", study)); if (!consentStudyCompIdLst.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in("id", consentStudyCompIdLst))); } return criteria.list(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public List<PhenoDataSetCategory> getAvailablePhenoCategoryListNotPicked(Study study, ArkFunction arkFunctionPhenoCat, ArkFunction arkFunctionPhenoCollection, ArkUser arkUser) throws ArkSystemException { List<PickedPhenoDataSetCategory> pickedPhenoSetCatLst = getPickedPhenoDataSetCategories(study, arkFunctionPhenoCollection, arkUser); List<Long> pickedPhenoDataIdLst = new ArrayList<Long>(); for (PickedPhenoDataSetCategory pickedPhenoDataSetCategory : pickedPhenoSetCatLst) { pickedPhenoDataIdLst.add(pickedPhenoDataSetCategory.getPhenoDataSetCategory().getId()); }/* w w w .j a va 2 s . c o m*/ Criteria criteria = getSession().createCriteria(PhenoDataSetCategory.class); criteria.add(Restrictions.eq("arkFunction", arkFunctionPhenoCat)); criteria.add(Restrictions.eq("study", study)); if (!pickedPhenoDataIdLst.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in("id", pickedPhenoDataIdLst))); } return criteria.list(); }