List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
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 ww . ja v a 2 s .c o m*/ * @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 w w . j av 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<ArkModule> getArkModuleListByArkUser(ArkUser arkUser) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); ArkModule arkModule = null;//from w ww . j a v a2 s .com try { // Restrict by user if NOT Super Administrator if (!isUserAdminHelper(arkUser.getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { criteria.add(Restrictions.eq("arkUser", arkUser)); } } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } catch (NullPointerException e) { log.error(e.getMessage(), e); } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("arkModule"), "arkModule"); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("arkModule.id")); criteria.createAlias("arkModule", "am"); criteria.add(Restrictions.eq("am.enabled", true)); return criteria.list(); }
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;//w w w. j a v a 2 s . c o 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.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getAssignedChildStudyListForUser(ArkUserVO arkUserVo) { List<Study> studyList = new ArrayList<Study>(0); try {//from w ww. ja v a 2s. co m ArkUser arkUser = getArkUser(arkUserVo.getArkUserEntity().getLdapUserName()); /* Get only the studies the ArkUser is linked to via the ArkUserRole */ Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUser)); // Restrict to child studies (without parent) Criteria studyCriteria = criteria.createCriteria("study"); studyCriteria.add(Restrictions.eq("parentStudy", arkUserVo.getStudy())); studyCriteria.add(Restrictions.neProperty("id", "parentStudy.id")); studyCriteria.addOrder(Order.asc("name")); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); studyList = criteria.list(); } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } return studyList; }
From source file:au.org.theark.core.dao.AuditDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<LssConsentHistory> getLssConsentHistoryList(LinkSubjectStudy linkSubjectStudy) { Criteria criteria = getSession().createCriteria(LssConsentHistory.class); criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy)); criteria.addOrder(Order.desc("id")); return criteria.list(); }
From source file:au.org.theark.core.dao.AuditDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ConsentHistory> getConsentHistoryList(Consent consent) { Criteria criteria = getSession().createCriteria(ConsentHistory.class); criteria.add(Restrictions.eq("linkSubjectStudy", consent.getLinkSubjectStudy())); if (consent.getStudyComp() != null) { criteria.add(Restrictions.eq("studyComp", consent.getStudyComp())); } else {//from w w w.java 2 s. c o m criteria.add(Restrictions.isNull("studyComp")); } criteria.addOrder(Order.desc("id")); return criteria.list(); }
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 .java2 s . co m 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; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
/** * Look up the Link Subject Study for subjects linked to a study * /* w w w .jav a2 s.c o m*/ * @param subjectVO * @return */ @SuppressWarnings("unchecked") public Collection<SubjectVO> getSubject(SubjectVO subjectVO) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("person", "p"); criteria.add(Restrictions.eq("study.id", subjectVO.getLinkSubjectStudy().getStudy().getId())); 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) { criteria.add(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE)); } 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().getSubjectUID() != null && subjectVO.getLinkSubjectStudy().getSubjectUID().length() > 0) { criteria.add(Restrictions.eq("subjectUID", subjectVO.getLinkSubjectStudy().getSubjectUID())); } 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)); } } criteria.addOrder(Order.asc("subjectUID")); List<LinkSubjectStudy> list = criteria.list(); Collection<SubjectVO> subjectVOList = new ArrayList<SubjectVO>(); for (Iterator iterator = list.iterator(); iterator.hasNext();) { LinkSubjectStudy linkSubjectStudy = (LinkSubjectStudy) iterator.next(); // Place the LinkSubjectStudy instance into a SubjectVO and add the // SubjectVO into a List SubjectVO subject = new SubjectVO(); subject.setLinkSubjectStudy(linkSubjectStudy); Person person = subject.getLinkSubjectStudy().getPerson(); subject.setSubjectPreviousLastname(getPreviousLastname(person)); subjectVOList.add(subject); } return subjectVOList; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
/** * Returns a list of Countries/* w w w . j a v a 2 s . c om*/ */ @SuppressWarnings("unchecked") public List<Country> getCountries() { Criteria criteria = getSession().createCriteria(Country.class); criteria.addOrder(Order.asc("name")); return criteria.list(); }