List of usage examples for org.hibernate.criterion Restrictions or
public static LogicalExpression or(Criterion lhs, Criterion rhs)
From source file:apm.modules.sys.service.UserService.java
License:Open Source License
public Page<User> findUser(Page<User> page, User user) { DetachedCriteria dc = dao.createDetachedCriteria(); User currentUser = Users.currentUser(); dc.createAlias("company", "company"); if (user.getCompany() != null && StringUtils.isNotEmpty(user.getCompany().getId())) { dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()), //? Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%") //?? ));//from w ww.ja v a 2 s . c o m } else { dc.add(Restrictions.or(Restrictions.eq("company.id", currentUser.getCompany().getId()), //? Restrictions.like("company.parentIds", "%," + currentUser.getCompany().getId() + ",%") //?? )); } /*dc.createAlias("office", "office"); if (user.getOffice()!=null && StringUtils.isNotEmpty(user.getOffice().getId())){ dc.add(Restrictions.or( Restrictions.eq("office.id", user.getOffice().getId()), // Restrictions.like("office.parentIds", "%,"+user.getOffice().getId()+",%") //? )); }else{ dc.add(Restrictions.or( Restrictions.eq("office.id", currentUser.getOffice().getId()), // Restrictions.like("office.parentIds", "%,"+currentUser.getOffice().getId()+",%") //? )); }*/ // ???? if (!currentUser.isAdmin()) { dc.add(Restrictions.ne("id", "1")); } /*if(user.getOffice() != null && StringUtils.isNotBlank(user.getOffice().getId())){ dc.add(dataScopeFilter(currentUser, "office", "")); }*/ /*dc.add(dataScopeFilter(currentUser, "office", ""));*/ //System.out.println(dataScopeFilterString(currentUser, "office", "")); if (StringUtils.isNotEmpty(user.getLoginName())) { dc.add(Restrictions.like("loginName", "%" + user.getLoginName() + "%")); } if (StringUtils.isNotEmpty(user.getName())) { dc.add(Restrictions.like("name", "%" + user.getName() + "%")); } dc.add(Restrictions.eq(User.DEL_FLAG, User.DEL_FLAG_NORMAL)); if (!StringUtils.isNotEmpty(page.getOrderBy())) { /*dc.addOrder(Order.asc("company.code")).addOrder(Order.asc("office.code")).addOrder(Order.desc("id"));*/ dc.addOrder(Order.asc("company.code")).addOrder(Order.desc("id")); } return dao.find(page, dc); }
From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.BookingsService.java
License:Open Source License
@Override public GetBookingsResponse getBookings(GetBookings getBookings) { BookingsRequestType request = getBookings.getGetBookings(); String debug = "Received " + this.getClass().getSimpleName() + "#getBookings with params:"; if (request.getUserID() != null) debug += " user ID=" + request.getUserID().getUserID() + ", user name=" + request.getUserID().getUserName() + ", user namespace=" + request.getUserID().getUserNamespace() + " user QName=" + request.getUserID().getUserQName(); if (request.getPermissionID() != null) debug += " permission ID=" + request.getPermissionID().getPermissionID(); if (request.getResourceID() != null) debug += "resource type=" + request.getResourceID().getType() + ", resource ID=" + request.getResourceID().getResourceID() + ", resource name=" + request.getResourceID().getResourceName(); debug += " show cancelled=" + request.showCancelled() + " show finished=" + request.showFinished(); this.logger.debug(debug); GetBookingsResponse response = new GetBookingsResponse(); BookingListType bookings = new BookingListType(); response.setGetBookingsResponse(bookings); BookingsDao dao = new BookingsDao(); try {/*w w w . j a v a2 s.c o m*/ Session ses = dao.getSession(); Criteria cri = ses.createCriteria(Bookings.class); /* If user specificed, add that to query. */ User user = null; if (request.getUserID() != null && (user = this.getUserFromUserID(request.getUserID(), ses)) != null) { cri.add(Restrictions.eq("user", user)); } /* If permission was specified, add that to query. */ if (request.getPermissionID() != null) { cri.add(Restrictions.eq("resourcePermission.id", Long.valueOf(request.getPermissionID().getPermissionID()))); } /* If resource was specified, add that to query. */ ResourceIDType rid = request.getResourceID(); if (rid != null) { if (ResourcePermission.RIG_PERMISSION.equals(rid.getType())) { cri.add(Restrictions.eq("resourceType", ResourcePermission.RIG_PERMISSION)); if (rid.getResourceID() > 0) cri.add(Restrictions.eq("rig.id", Long.valueOf(rid.getResourceID()))); if (rid.getResourceName() != null) { cri.createCriteria("rig").add(Restrictions.eq("name", rid.getResourceName())); } } else if (ResourcePermission.TYPE_PERMISSION.equals(rid.getType())) { cri.add(Restrictions.eq("resourceType", ResourcePermission.TYPE_PERMISSION)); if (rid.getResourceID() > 0) cri.add(Restrictions.eq("rigType.id", Long.valueOf(rid.getResourceID()))); if (rid.getResourceName() != null) { cri.createCriteria("rigType").add(Restrictions.eq("name", rid.getResourceName())); } } else if (ResourcePermission.CAPS_PERMISSION.equals(rid.getType())) { cri.add(Restrictions.eq("resourceType", ResourcePermission.CAPS_PERMISSION)); if (rid.getResourceID() > 0) { cri.add(Restrictions.eq("requestCapabilities.id", Long.valueOf(rid.getResourceID()))); } if (rid.getResourceName() != null) { cri.createCriteria("requestCapabilities") .add(Restrictions.eq("capabilities", rid.getResourceName())); } } else { this.logger.warn("Not added a resource restriction to existing booking search because the " + "resourece type '" + rid.getType() + "' is not one of '" + ResourcePermission.RIG_PERMISSION + "' '" + ResourcePermission.TYPE_PERMISSION + "' '" + ResourcePermission.CAPS_PERMISSION + "'."); } } /* Other constraints specified. */ if (!request.showCancelled() && !request.showFinished()) { cri.add(Restrictions.eq("active", Boolean.TRUE)); } else if (!request.showFinished()) { cri.add(Restrictions.or(Restrictions.isNotNull("cancelReason"), Restrictions.eq("active", Boolean.TRUE))); } else if (!request.showCancelled()) { cri.add(Restrictions.isNull("cancelReason")); } /* Order the results be booking start time. */ cri.addOrder(Order.asc("startTime")); @SuppressWarnings("unchecked") List<Bookings> list = cri.list(); for (Bookings booking : list) { bookings.addBookings(this.populateBookingType(new BookingType(), booking)); } } finally { dao.closeSession(); } return response; }
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.pages.KeysPage.java
License:Open Source License
/** * Returns the list of keys for a user class. If the parameter 'historical' * is part of the request parameters and has a value of 'true', non-usable * keys are returned otherwise usable keys are returned. Usable keys are * those that are 'active', have remaining uses and have not elapsed * their expiry time. //ww w .j a v a 2s . c o m * * @param request request * @return list of permission keys * @throws JSONException */ @SuppressWarnings("unchecked") public JSONArray getList(HttpServletRequest request) throws JSONException { JSONArray arr = new JSONArray(); String className = request.getParameter("name"); if (className == null) { this.logger.warn("Unable to provide access key list because the user class name was not provided."); return arr; } Criteria qu = this.db.createCriteria(UserClassKey.class).add(Restrictions.eq("userTargeted", Boolean.FALSE)) .addOrder(Order.asc("id")); if ("true".equals(request.getAttribute("historical"))) { qu.add(Restrictions.disjunction().add(Restrictions.eq("active", Boolean.FALSE)) .add(Restrictions.eq("remaining", 0))) .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.lt("expiry", new Date()))); } else { qu.add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("remaining", 0)) .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.gt("expiry", new Date()))); } qu = qu.createCriteria("userClass").add(Restrictions.eq("name", className)); for (UserClassKey key : (List<UserClassKey>) qu.list()) { JSONObject keyObj = new JSONObject(); keyObj.put("key", key.getRedeemKey()); keyObj.put("active", key.isActive()); keyObj.put("remaining", key.getRemaining()); arr.put(keyObj); } return arr; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Use this method when we want to load the Collection of Administrator roles as a Collectio<String>. The method looks up Ark Super Administrator * and Administrator roles given a LdapUserName. It populates it into a Collection<String> that represent a unique set of administration roles for * this user. It does not take into account the Module or Study. This is usually when the user has logged in first and we want to know if the user * has a role of type Administator so he can have access to Create function. * /*from w w w. ja v a2s .c o m*/ * @param ldapUserName * @return Collection<String> * @throws EntityNotFoundException */ @SuppressWarnings("unchecked") public Collection<String> getUserAdminRoles(String ldapUserName) throws EntityNotFoundException { ArkUser arkUser = getArkUser(ldapUserName); StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(ArkUserRole.class);// getSession().createCriteria(ArkUserRole.class); ArkRole arkRoleSuperAdmin = getArkRoleByName(RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR); ArkRole arkRoleAdmin = getArkRoleByName(RoleConstants.ARK_ROLE_ADMINISTATOR); criteria.add(Restrictions.or(Restrictions.eq("arkRole", arkRoleSuperAdmin), Restrictions.eq("arkRole", arkRoleAdmin))); criteria.add(Restrictions.eq("arkUser", arkUser)); List<ArkUserRole> arkUserRoleList = (List<ArkUserRole>) criteria.list(); Set<String> roles = new HashSet<String>(0); for (ArkUserRole arkUserRole : arkUserRoleList) { String roleName = arkUserRole.getArkRole().getName(); roles.add(roleName); } Collection<String> userRoles = new ArrayList<String>(); for (String roleName : roles) { userRoles.add(roleName); } session.close(); return userRoles; }
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 w w w . j ava 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<Study> getParentAndChildStudies(Long id) { Criteria studyCriteria = getSession().createCriteria(Study.class); Study study = getStudy(id);//w w w .j a va2 s. com 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"); } } if (study.getParentStudy() != null && !study.getParentStudy().equals(study)) { studyCriteria.add( Restrictions.or(Restrictions.idEq(id), Restrictions.eq("parentStudy", study.getParentStudy()))); } else { studyCriteria.add(Restrictions.or(Restrictions.idEq(id), Restrictions.eq("parentStudy", study))); } studyCriteria.addOrder(Order.asc("id")); studyCriteria.addOrder(Order.asc(Constants.STUDY_NAME)); return studyCriteria.list(); }
From source file:au.org.theark.report.model.dao.ReportDao.java
License:Open Source License
public List<LinkSubjectStudy> getStudyLevelConsentDetailsList(ConsentDetailsReportVO cdrVO) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); // Add study in context to criteria first (linkSubjectStudy on the VO should never be null) criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy())); if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) { criteria.add(Restrictions.ilike(Constants.LINKSUBJECTSTUDY_SUBJECTUID, cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); }/*from ww w . jav a 2 s.co m*/ if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq(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(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus()), Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS))); } else { criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus())); } } if (cdrVO.getConsentDate() != null) { criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate())); } criteria.addOrder(Order.asc("consentStatus")); // although MySQL causes NULLs to come first criteria.addOrder(Order.asc("subjectUID")); return (List<LinkSubjectStudy>) criteria.list(); }
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 ww w .j a v a2s .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()); 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 ww . j a v 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()); //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; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
/** * The count can be based on CustomFieldDisplay only instead of a left join with it using SubjectCustomFieldData *///from w w w . j a v a2 s . c om public long getSubjectCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.createAlias("customField", "cfield", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("cfield.customFieldType", "cfieldType", JoinType.LEFT_OUTER_JOIN); criteria.add(Restrictions.eq("cfield.study", linkSubjectStudyCriteria.getStudy())); criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction)); criteria.add(Restrictions.or(Restrictions.isNull("cfield.customFieldType"), Restrictions.eq("cfieldType.name", "SUBJECT"))); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }