List of usage examples for org.hibernate.criterion Projections projectionList
public static ProjectionList projectionList()
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getStudyListForUser(ArkUserVO arkUserVo) { List<Study> studyList = new ArrayList<Study>(0); Study searchStudy = arkUserVo.getStudy(); try {//from w w w . j a v a 2 s.co m if (isUserAdminHelper(arkUserVo.getArkUserEntity().getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { studyList = getAllStudiesForSuperAdmin(arkUserVo.getStudy());// Get all Studies } else { /* Get only the studies the ArkUser is linked to via the ArkUserRole */ Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUserVo.getArkUserEntity())); Criteria studyCriteria = criteria.createCriteria("study"); applyStudySearchCriteria(searchStudy, studyCriteria); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); studyList = criteria.list(); } } catch (EntityNotFoundException e1) { log.error("The specified Ark User does not exist " + arkUserVo.getArkUserEntity().getLdapUserName()); e1.printStackTrace(); } return studyList; }
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 {/*from ww w .jav a 2 s . 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;/*ww w .j av a 2s. c o m*/ 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<ArkUser> getArkUserListByStudy(ArkUser arkUser, Study study) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); // Restrict by user if NOT Super Administrator try {/*from www . ja v a2 s .c o m*/ if (!isUserAdminHelper(arkUser.getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { criteria.add(Restrictions.eq("study", study)); } } catch (EntityNotFoundException e) { log.info("User Name doen not exsists"); } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("arkUser"), "arkUser"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(ArkUserRole.class)); List<ArkUserRole> arkUserRoles = (List<ArkUserRole>) criteria.list(); List<ArkUser> arkUserLst = new ArrayList<ArkUser>(); for (ArkUserRole arkRolePol : arkUserRoles) { arkUserLst.add(arkRolePol.getArkUser()); } //Added on 2015-12-10 filter study wise users. //changed on 2016-04-28. return arkUserLst; }
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 {// ww w .j av a 2 s. c o 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.ArkAuthorisationDao.java
License:Open Source License
/** * List of Permission for function. //from w w w . j a va 2 s .co m * * Just I need the list of permission list for a particular function I manage to use the hibernate projectionList property. * Group by Permission. * But still used setResultTransformer to transform the list which include the permission list. * @return */ public List<ArkPermission> getArkPremissionListForRoleAndModule(ArkRolePolicyTemplate arkRolePolicyTemplate) { Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class); criteria.add(Restrictions.eq("arkRole", arkRolePolicyTemplate.getArkRole())); criteria.add(Restrictions.eq("arkModule", arkRolePolicyTemplate.getArkModule())); criteria.add(Restrictions.eq("arkFunction", arkRolePolicyTemplate.getArkFunction())); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("arkPermission"), "arkPermission"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(ArkRolePolicyTemplate.class)); List<ArkRolePolicyTemplate> arkRolePolicyTemplatesLst = (List<ArkRolePolicyTemplate>) criteria.list(); List<ArkPermission> arkPermissionLst = new ArrayList<ArkPermission>(); for (ArkRolePolicyTemplate arkRolePol : arkRolePolicyTemplatesLst) { arkPermissionLst.add(arkRolePol.getArkPermission()); } return arkPermissionLst; }
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 {/* w w w .ja va 2 s. co 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<Study> getStudyListAssignedToBiospecimenUidTemplate() { Criteria criteria = getSession().createCriteria(BiospecimenUidTemplate.class); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("study"))); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getAssignedChildStudyListForPerson(Study study, Person person) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("study", "s"); criteria.add(Restrictions.eq("person", person)); criteria.add(Restrictions.eq("s.parentStudy", study)); criteria.add(Restrictions.ne("s.id", study.getId())); criteria.add(Restrictions.ne("subjectStatus", getSubjectStatus("Archive"))); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
private List<Long> applyConsentStatusFilters(DataExtractionVO allTheData, Search search, List<Long> idsToInclude) { //for(Long l : idsToInclude) { // log.info("including: " + l); //}// w w w. j a v a 2s. c om boolean hasConsentFilters = false; if (search.getQueryFilters().isEmpty()) { return idsToInclude; } else { for (QueryFilter filter : search.getQueryFilters()) { if (filter.getConsentStatusField() != null) { hasConsentFilters = true; } } } Criteria filter = getSession().createCriteria(Consent.class, "c"); filter.add(Restrictions.eq("c.study.id", search.getStudy().getId())); filter.createAlias("c.linkSubjectStudy", "lss"); if (!idsToInclude.isEmpty()) { filter.add(Restrictions.in("lss.id", idsToInclude)); } filter.createAlias("c.studyComponentStatus", "cscs"); filter.createAlias("c.studyComp", "csc"); if (!hasConsentFilters) { for (QueryFilter qf : search.getQueryFilters()) { if (qf.getConsentStatusField() != null) { switch (qf.getOperator()) { case EQUAL: filter.add(Restrictions.eq(getConsentFilterFieldName(qf), qf.getValue())); break; case BETWEEN: filter.add(Restrictions.between(getConsentFilterFieldName(qf), qf.getValue(), qf.getSecondValue())); break; case GREATER_THAN: filter.add(Restrictions.gt(getConsentFilterFieldName(qf), qf.getValue())); break; case GREATER_THAN_OR_EQUAL: filter.add(Restrictions.ge(getConsentFilterFieldName(qf), qf.getValue())); break; case IS_EMPTY: filter.add(Restrictions.isEmpty(getConsentFilterFieldName(qf))); break; case IS_NOT_EMPTY: filter.add(Restrictions.isNotEmpty(getConsentFilterFieldName(qf))); break; case LESS_THAN: filter.add(Restrictions.lt(getConsentFilterFieldName(qf), qf.getValue())); break; case LESS_THAN_OR_EQUAL: filter.add(Restrictions.le(getConsentFilterFieldName(qf), qf.getValue())); break; case LIKE: filter.add(Restrictions.like(getConsentFilterFieldName(qf), qf.getValue(), MatchMode.ANYWHERE)); break; case NOT_EQUAL: filter.add(Restrictions.ne(getConsentFilterFieldName(qf), qf.getValue())); break; default: break; } } } } filter.setProjection( Projections.distinct(Projections.projectionList().add(Projections.property("lss.id")))); List<Long> consentStatusIDs = filter.list(); Collection<Consent> csData = Collections.EMPTY_LIST; if (!consentStatusIDs.isEmpty()) { Criteria consentData = getSession().createCriteria(Consent.class, "c"); consentData.add(Restrictions.eq("c.study.id", search.getStudy().getId())); consentData.createAlias("c.linkSubjectStudy", "lss"); consentData.add(Restrictions.in("lss.id", consentStatusIDs)); csData = consentData.list(); } HashMap<String, ExtractionVO> hashOfConsentStatusData = allTheData.getConsentStatusData(); ExtractionVO valuesForThisLss = new ExtractionVO(); HashMap<String, String> map = null; LinkSubjectStudy previousLss = null; int count = 0; //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO for (Consent data : csData) { if (previousLss == null) { map = new HashMap<String, String>(); previousLss = data.getLinkSubjectStudy(); count = 0; } else if (data.getLinkSubjectStudy().getId().equals(previousLss.getId())) { //then just put the data in count++; } else { //if its a new LSS finalize previous map, etc valuesForThisLss.setKeyValues(map); valuesForThisLss.setSubjectUid(previousLss.getSubjectUID()); hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss); previousLss = data.getLinkSubjectStudy(); map = new HashMap<String, String>();//reset valuesForThisLss = new ExtractionVO(); count = 0; } if (data.getStudyComp().getName() != null) { map.put(count + "_Study Component Name", data.getStudyComp().getName()); } if (data.getStudyComponentStatus() != null) { map.put(count + "_Study Component Status", data.getStudyComponentStatus().getName()); } if (data.getConsentDate() != null) { map.put(count + "_Consent Date", data.getConsentDate().toString()); } if (data.getConsentedBy() != null) { map.put(count + "_Consented By", data.getConsentedBy()); } } //finalize the last entered key value sets/extraction VOs if (map != null && previousLss != null) { valuesForThisLss.setKeyValues(map); valuesForThisLss.setSubjectUid(previousLss.getSubjectUID()); hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss); } //can probably now go ahead and add these to the dataVO...even though inevitable further filters may further axe this list or parts of it. allTheData.setConsentStatusData(hashOfConsentStatusData); if (hasConsentFilters) { return consentStatusIDs; } else { return idsToInclude; } }