List of usage examples for org.hibernate.criterion ProjectionList add
public ProjectionList add(Projection projection, String alias)
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 {// w w w . j a v a 2s .com 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. /* w ww.j av a 2 s . c o 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
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.lims.model.dao.InventoryDao.java
License:Open Source License
public List<InvSite> searchInvSite(InvSite invSite, List<Study> studyList) throws ArkSystemException { List<InvSite> invSiteList = new ArrayList<InvSite>(0); if (studyList == null || studyList.isEmpty()) { return invSiteList; }/*from w w w .j a v a 2 s . c o m*/ Criteria criteria = getSession().createCriteria(StudyInvSite.class); /* * if (invSite.getId() != null) { criteria.add(Restrictions.eq("id", invSite.getId())); } * * if (invSite.getName() != null) { criteria.add(Restrictions.eq("name", invSite.getName())); } * * if (invSite.getContact() != null) { criteria.add(Restrictions.eq("contact", invSite.getContact())); } * * if (invSite.getAddress() != null) { criteria.add(Restrictions.eq("address", invSite.getAddress())); } * * if (invSite.getPhone() != null) { criteria.add(Restrictions.eq("phone", invSite.getPhone())); } */ /*if you have an empty grouping, hibernate will do this sort of this; * select this_.INV_SITE_ID as y0_ from lims.study_inv_site this_ where this_.STUDY_ID in ( ) group by this_.INV_SITE_ID ...therefore always null check before checking if something is in a group of nothing */ criteria.add(Restrictions.in("study", studyList)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("invSite"), "invSite"); criteria.setProjection(projectionList); // List<StudyInvSite> list = criteria.list(); invSiteList = criteria.list(); /* * for(StudyInvSite studyInvSite : list){ invSiteList.add(studyInvSite.getInvSite()); } */ return invSiteList; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
/** * The method checks if the given questionnaire's fields have data linked to it. * //from w w w . j a v a 2 s.c om * @param customFieldGroup */ public void isDataAvailableForQuestionnaire(CustomFieldGroup customFieldGroup) { Criteria criteria = getSession().createCriteria(CustomField.class, "cf"); criteria.createAlias("customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldDisplay criteria.createAlias("cfd.customFieldGroup", "cfg", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldGroup criteria.add(Restrictions.eq("cf.study", customFieldGroup.getStudy())); ArkFunction function = iArkCommonService .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_DATA_DICTIONARY); criteria.add(Restrictions.eq("cf.arkFunction", function)); criteria.add(Restrictions.eq("cfg.id", customFieldGroup.getId())); DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "pd"); // Join CustomFieldDisplay and PhenoData on ID FK fieldDataCriteria.add(Property.forName("cfd.id").eqProperty("pd." + "customFieldDisplay.id")); criteria.add( Subqueries.exists(fieldDataCriteria.setProjection(Projections.property("pd.customFieldDisplay")))); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("cfg.name"), "questionnaire"); projectionList.add(Projections.property("cf.name"), "fieldName"); projectionList.add(Projections.property("cf.description"), "description"); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public List<PhenoDataSetGroup> getPhenoDataSetGroupsByLinkSubjectStudy(LinkSubjectStudy linkSubjectStudy) { Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class); criteria.add(Restrictions.eq("linkSubjectStudy", linkSubjectStudy)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("questionnaire"), "questionnaire"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetCollection.class)); List<PhenoDataSetCollection> phenoDataSetCollections = (List<PhenoDataSetCollection>) criteria.list(); List<PhenoDataSetGroup> phenoDataSetGroups = new ArrayList<PhenoDataSetGroup>(); for (PhenoDataSetCollection phenoDataSetCollection : phenoDataSetCollections) { phenoDataSetGroups.add(phenoDataSetCollection.getQuestionnaire()); }//from w ww . ja v a2 s .c om return phenoDataSetGroups; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public List<PhenoDataSetFieldDisplay> getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroupOrderByPhenoDataSetCategory( PhenoDataSetGroup phenoDataSetGroup) { Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class); criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("phenoDataSetGroup"), "phenoDataSetGroup"); projectionList.add(Projections.groupProperty("phenoDataSetCategory"), "phenoDataSetCategory"); projectionList.add(Projections.groupProperty("parentPhenoDataSetCategory"), "parentPhenoDataSetCategory"); projectionList.add(Projections.groupProperty("phenoDataSetCategoryOrderNumber"), "phenoDataSetCategoryOrderNumber"); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber")); criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetFieldDisplay.class)); return (List<PhenoDataSetFieldDisplay>) criteria.list(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public List<Boolean> getPublishedSatusLst(Study study, ArkFunction arkFunction) { Criteria criteria = getSession().createCriteria(PhenoDataSetGroup.class); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkFunction", arkFunction)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("published"), "published"); criteria.setProjection(projectionList); criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetGroup.class)); List<PhenoDataSetGroup> phenoDataSetGroups = (List<PhenoDataSetGroup>) criteria.list(); List<Boolean> pubishStatusLst = new ArrayList<Boolean>(); for (PhenoDataSetGroup phenoDataSetGroup : phenoDataSetGroups) { pubishStatusLst.add(phenoDataSetGroup.getPublished()); }/*www .ja v a 2 s . c om*/ return pubishStatusLst; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public List<ConsentDetailsDataRow> getStudyLevelConsentDetailsDataRowList(ConsentDetailsReportVO cdrVO) { List<ConsentDetailsDataRow> resultList = new ArrayList<ConsentDetailsDataRow>(0); Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss"); // Add study in context to criteria first (linkSubjectStudy on the VO should never be null) criteria.add(/*from w ww . j av a 2s . c o m*/ Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy())); if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) { criteria.add(Restrictions.ilike("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTUID, cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS, cdrVO.getLinkSubjectStudy().getSubjectStatus())); } // we are dealing with study-level consent if (cdrVO.getConsentStatus() != null) { if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) { // Special-case: Treat the null FK for consentStatus as "Not Consented" criteria.add(Restrictions.or( Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus()), Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS))); } else { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus())); } } if (cdrVO.getConsentDate() != null) { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate())); } criteria.createAlias("lss.consentStatus", "cs", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.subjectStatus", "ss"); criteria.createAlias("lss.person", "p"); criteria.createAlias("lss.person.genderType", "genderType"); // Restrict any addresses to the preferred mailing address //Criteria addressCriteria = criteria.createAlias("lss.person.addresses", "a", JoinType.LEFT_OUTER_JOIN); // addressCriteria.setMaxResults(1); // addressCriteria.add(Restrictions.or(Restrictions.or(Restrictions.eq("a.preferredMailingAddress", true), Restrictions.isNull("a.preferredMailingAddress"),Restrictions.eq("a.preferredMailingAddress", false)))); criteria.createAlias("lss.person.addresses.country", "c", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.person.addresses.state", "state", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.person.phones", "phone", JoinType.LEFT_OUTER_JOIN); //TODO: Get work phone returned as well //Criteria phoneCriteria = criteria.createAlias("lss.person.phones.phoneType", "phoneType", JoinType.LEFT_OUTER_JOIN);/*.add( Restrictions.or(Restrictions.eq("phoneType.name", "Home"), ( Restrictions.or(Restrictions.or(Restrictions.eq("phoneType.name", "Home"), Restrictions.isNull("phoneType.name"),Restrictions.eq("phoneType.name", "Mobile"))) ) ) ));*/ //phoneCriteria.setMaxResults(1); criteria.createAlias("lss.person.titleType", "title"); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("lss.subjectUID"), "subjectUID"); projectionList.add(Projections.property("cs.name"), "consentStatus"); projectionList.add(Projections.property("ss.name"), "subjectStatus"); projectionList.add(Projections.property("title.name"), "title"); projectionList.add(Projections.property("p.firstName"), "firstName"); projectionList.add(Projections.property("p.lastName"), "lastName"); projectionList.add(Projections.property("a.streetAddress"), "streetAddress"); projectionList.add(Projections.property("a.city"), "suburb"); projectionList.add(Projections.property("a.postCode"), "postcode"); projectionList.add(Projections.property("state.name"), "state"); projectionList.add(Projections.property("c.name"), "country"); projectionList.add(Projections.property("phone.phoneNumber"), "homePhone"); projectionList.add(Projections.property("p.preferredEmail"), "email"); projectionList.add(Projections.property("genderType.name"), "sex"); projectionList.add(Projections.property("lss.consentDate"), "consentDate"); criteria.setProjection(projectionList); // only return fields required for report criteria.addOrder(Order.asc("lss.consentStatus")); // although MySQL causes NULLs to come first criteria.addOrder(Order.asc("lss.subjectUID")); criteria.setResultTransformer(Transformers.aliasToBean(ConsentDetailsDataRow.class)); resultList = (criteria.list()); return resultList; }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public List<ConsentDetailsDataRow> getStudyLevelConsentOtherIDDetailsDataRowList(ConsentDetailsReportVO cdrVO) { List<ConsentDetailsDataRow> resultList = new ArrayList<ConsentDetailsDataRow>(0); Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss"); // Add study in context to criteria first (linkSubjectStudy on the VO should never be null) criteria.add(/*from w w w. java 2 s. c om*/ Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy())); if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) { criteria.add(Restrictions.ilike("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTUID, cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS, cdrVO.getLinkSubjectStudy().getSubjectStatus())); } // we are dealing with study-level consent if (cdrVO.getConsentStatus() != null) { if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) { // Special-case: Treat the null FK for consentStatus as "Not Consented" criteria.add(Restrictions.or( Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus()), Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS))); } else { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus())); } } if (cdrVO.getConsentDate() != null) { criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate())); } criteria.createAlias("lss.consentStatus", "cs", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.subjectStatus", "ss"); criteria.createAlias("lss.person", "p"); criteria.createAlias("lss.person.genderType", "genderType"); // Restrict any addresses to the preferred mailing address //Criteria addressCriteria = criteria.createAlias("lss.person.addresses", "a", JoinType.LEFT_OUTER_JOIN); // addressCriteria.setMaxResults(1); // addressCriteria.add(Restrictions.or(Restrictions.or(Restrictions.eq("a.preferredMailingAddress", true), Restrictions.isNull("a.preferredMailingAddress"),Restrictions.eq("a.preferredMailingAddress", false)))); criteria.createAlias("lss.person.addresses.country", "c", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.person.addresses.state", "state", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("lss.person.phones", "phone", JoinType.LEFT_OUTER_JOIN); //TODO: Get work phone returned as well //Criteria phoneCriteria = criteria.createAlias("lss.person.phones.phoneType", "phoneType", JoinType.LEFT_OUTER_JOIN);/*.add( Restrictions.or(Restrictions.eq("phoneType.name", "Home"), ( Restrictions.or(Restrictions.or(Restrictions.eq("phoneType.name", "Home"), Restrictions.isNull("phoneType.name"),Restrictions.eq("phoneType.name", "Mobile"))) ) ) ));*/ //phoneCriteria.setMaxResults(1); criteria.createAlias("lss.person.titleType", "title"); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("lss.subjectUID"), "subjectUID"); projectionList.add(Projections.property("cs.name"), "consentStatus"); projectionList.add(Projections.property("ss.name"), "subjectStatus"); projectionList.add(Projections.property("title.name"), "title"); projectionList.add(Projections.property("p.firstName"), "firstName"); projectionList.add(Projections.property("p.lastName"), "lastName"); projectionList.add(Projections.property("a.streetAddress"), "streetAddress"); projectionList.add(Projections.property("a.city"), "suburb"); projectionList.add(Projections.property("a.postCode"), "postcode"); projectionList.add(Projections.property("state.name"), "state"); projectionList.add(Projections.property("c.name"), "country"); projectionList.add(Projections.property("phone.phoneNumber"), "homePhone"); projectionList.add(Projections.property("p.preferredEmail"), "email"); projectionList.add(Projections.property("genderType.name"), "sex"); projectionList.add(Projections.property("lss.consentDate"), "consentDate"); criteria.setProjection(projectionList); // only return fields required for report criteria.addOrder(Order.asc("lss.consentStatus")); // although MySQL causes NULLs to come first criteria.addOrder(Order.asc("lss.subjectUID")); criteria.setResultTransformer(Transformers.aliasToBean(ConsentDetailsDataRow.class)); resultList = (criteria.list()); //removing duplicate entries from resultList List<ConsentDetailsDataRow> uniqueResults = new ArrayList(); Iterator<ConsentDetailsDataRow> iterator = resultList.iterator(); while (iterator.hasNext()) { ConsentDetailsDataRow o = iterator.next(); if (!uniqueResults.contains(o)) uniqueResults.add(o); } resultList.clear(); resultList.addAll(uniqueResults); for (int j = 0; j < resultList.size(); j++) { ConsentDetailsDataRow c = resultList.get(j); if (c.getOtherID() == null && c.getOtherIDSource() == null) { List<OtherID> otherIDs = null; try { otherIDs = iArkCommonService.getOtherIDs(iArkCommonService .getSubjectByUID(c.getSubjectUID(), cdrVO.getLinkSubjectStudy().getStudy()) .getPerson()); if (otherIDs.size() >= 1) { c.setOtherID(otherIDs.get(0).getOtherID()); c.setOtherIDSource(otherIDs.get(0).getOtherID_Source()); } if (otherIDs.size() > 1) { for (int i = 1; i < otherIDs.size(); i++) { OtherID o = otherIDs.get(i); ConsentDetailsDataRow clone = new ConsentDetailsDataRow(c.getSubjectUID(), o.getOtherID_Source(), o.getOtherID(), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); resultList.add(clone); } } } catch (EntityNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return resultList; }