List of usage examples for org.hibernate.criterion Projections property
public static PropertyProjection property(String propertyName)
From source file:alpha.portal.dao.hibernate.AlphaCardDaoHibernate.java
License:Apache License
/** * List alpha cards by criterion.//from w ww . j a v a 2 s.c om * * @param caseId * the case id * @param criteriaArray * the criteria array * @return the list * @see alpha.portal.dao.AlphaCardDao#listAlphaCardsByCriterion(org.hibernate.criterion.Criterion) */ public List<AlphaCard> listAlphaCardsByCriterion(final String caseId, final Criterion... criteriaArray) { Session session; boolean sessionOwn = false; try { session = this.getSessionFactory().getCurrentSession(); } catch (final Exception e) { session = this.getSessionFactory().openSession(); sessionOwn = true; } // get newest sequenceNumber for each cardId final DetachedCriteria version = DetachedCriteria.forClass(AlphaCard.class, "cardVersion") .add(Property.forName("card.alphaCardIdentifier.cardId") .eqProperty("cardVersion.alphaCardIdentifier.cardId")) .setProjection( Projections.projectionList().add(Projections.max("alphaCardIdentifier.sequenceNumber"))); final Criteria crit = session.createCriteria(AlphaCard.class, "card"); for (final Criterion c : criteriaArray) { // Create the subquery (somehow we need to use the Descriptor or // else the subquery-JOIN is not done) final DetachedCriteria subcrit = DetachedCriteria.forClass(AlphaCardDescriptor.class, "crit"); // Join the adornments subcrit.createAlias("crit.adornmentList", "ad"); // Add adornment condition subcrit.add(c); // Map the subquery back to the outer query subcrit.add(Restrictions.eqProperty("card.alphaCardIdentifier", "crit.alphaCardIdentifier")); // Narrow down subquery or else we get a NullPointer-Exception subcrit.setProjection(Projections.property("crit.alphaCardIdentifier.cardId")); // Add this subquery to the outer query. crit.add(Subqueries.exists(subcrit)); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .add(Property.forName("alphaCardIdentifier.sequenceNumber").eq(version)) .createAlias("alphaCase", "case").add(Restrictions.eq("case.caseId", caseId)); List<AlphaCard> list = crit.list(); if (list.size() > 1) { final List<AlphaCard> order = (list.get(0)).getAlphaCase().getAlphaCards(); final List<AlphaCard> orderedList = new LinkedList<AlphaCard>(); for (final AlphaCard cc : order) { for (final AlphaCard c : list) { if (c.getAlphaCardIdentifier().equals(cc.getAlphaCardIdentifier())) { orderedList.add(c); break; } } } list = orderedList; } if (sessionOwn) { session.close(); } return list; }
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 www . j a v a2 s. com*/ 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> getStudiesForUser(ArkUser arkUser, Study study) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.createAlias("arkStudy", "arkStudy"); criteria.add(Restrictions.eq("arkUser", arkUser));// Represents the user // either who is // logged in or one // that is provided if (study.getId() != null) { criteria.add(Restrictions.eq("arkStudy.id", study.getId())); }//from ww w . j a va 2s . co m if (study.getName() != null) { criteria.add(Restrictions.ilike("arkStudy.name", study.getName(), MatchMode.ANYWHERE)); } criteria.setProjection(Projections.distinct(Projections.property("study"))); List<Study> studies = (List<Study>) criteria.list(); return studies; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public String getDelimiterTypeNameByDelimiterChar(char delimiterCharacter) { String delimiterTypeName = null; Criteria criteria = getSession().createCriteria(DelimiterType.class); criteria.add(Restrictions.eq("delimiterCharacter", delimiterCharacter)); criteria.setProjection(Projections.property("name")); delimiterTypeName = (String) criteria.uniqueResult(); return delimiterTypeName; }
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 av a2s . com 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; } }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Long> getSubjectIdsforSearch(Search search) { Criteria criteria = getSession().createCriteria(SearchSubject.class); criteria.add(Restrictions.eq("search", search)); criteria.setProjection(Projections.property("linkSubjectStudy.id")); return criteria.list(); }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc"); criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId())); sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close();//from ww w . j a v a 2 s . c o m return result; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBiospecimens(BioCollection bioCollection) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BioCollection.class, "bc"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Biospecimen.class, "b"); criteria.add(Restrictions.eq("bc.id", bioCollection.getId())); sizeCriteria.add(Property.forName("bc.id").eqProperty("b.bioCollection.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("b.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close();// w ww . ja v a 2s . c om return result; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public List<CustomField> getCustomFieldsLinkedToCustomFieldGroup(CustomFieldGroup customFieldCriteria) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.add(Restrictions.eq("customFieldGroup", customFieldCriteria)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("customField")); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("sequence")); List<CustomField> fieldsList = criteria.list(); //log.warn("______________customFieldsList = " + fieldsList.size()); return fieldsList; }
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. * // w w w .j a v a2 s .com * @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"); }