List of usage examples for org.hibernate.criterion Restrictions eq
public static SimpleExpression eq(String propertyName, Object value)
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. * /* w ww . j a va 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> getStudyListForUser(ArkUserVO arkUserVo) { List<Study> studyList = new ArrayList<Study>(0); Study searchStudy = arkUserVo.getStudy(); try {//w w w. j ava 2s . com 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 w w w. j a v a2s . com // 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
public boolean arkUserHasModuleAccess(ArkUser arkUser, ArkModule arkModule) { boolean hasModuleAccess = false; Criteria criteria = getSession().createCriteria(ArkUserRole.class); try {//ww w.j a va2 s. c o m // Restrict by user if NOT Super Administrator if (!isUserAdminHelper(arkUser.getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { criteria.add(Restrictions.eq("arkUser", arkUser)); } // Restrict by arkModule criteria.add(Restrictions.eq("arkModule", arkModule)); List<?> list = criteria.list(); hasModuleAccess = (list.size() > 0); } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } catch (NullPointerException e) { log.error(e.getMessage(), e); } return hasModuleAccess; }
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;//w w w . 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
public Boolean isArkUserLinkedToStudies(ArkUser arkUser) { Boolean flag = false;/* w w w.j a va 2 s. com*/ Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUser)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); if (totalCount > 0) { flag = true; } return flag; }
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 w ww . j a 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 {/*from ww w . ja v a2 s.c om*/ 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 www. ja v a2s. 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.ArkUidGenerator.java
License:Open Source License
/** * TODO this should use a real fkey/*from www . j a va 2s. co m*/ * @param studyNameKy * @return */ public Integer getUidAndIncrement(String studyNameKy, int numToInsert) { Criteria criteria = getSession().createCriteria(SubjectUidSequence.class); criteria.add(Restrictions.eq("studyNameId", studyNameKy)); SubjectUidSequence seqData = (SubjectUidSequence) criteria.uniqueResult(); if (seqData == null) { //log.error("sequence does not exist...creating"); SubjectUidSequence seq = new SubjectUidSequence(studyNameKy, numToInsert, false); getSession().persist(seq); getSession().flush(); return new Integer(0); } else { int currentSeqNumber = seqData.getUidSequence(); seqData.setUidSequence((currentSeqNumber + numToInsert)); getSession().update(seqData); getSession().flush(); return currentSeqNumber;//TODO ...perhaps this should be handled transactionally in one class, and probably with generators...although this isnt really even a key } }