List of usage examples for org.hibernate Criteria add
public Criteria add(Criterion criterion);
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public Collection<ArkModule> getArkModulesLinkedWithStudy(Study study) { Criteria criteria = getSession().createCriteria(LinkStudyArkModule.class); criteria.add(Restrictions.eq("study", study)); criteria.createAlias("arkModule", "module"); criteria.addOrder(Order.asc("module.id")); Collection<LinkStudyArkModule> arkStudyLinkedModuleList = criteria.list(); Collection<ArkModule> arkModuleList = new ArrayList<ArkModule>(); for (LinkStudyArkModule linkStudyArkModule : arkStudyLinkedModuleList) { arkModuleList.add(linkStudyArkModule.getArkModule()); }/*from ww w . ja va2 s . c o m*/ return arkModuleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public ArrayList<ArkRole> getArkRoleLinkedToModule(ArkModule arkModule) { Collection<ArkModuleRole> arkModuleList = new ArrayList<ArkModuleRole>(); Criteria criteria = getSession().createCriteria(ArkModuleRole.class); criteria.add(Restrictions.eq("arkModule", arkModule)); criteria.createAlias("arkRole", "role", JoinType.LEFT_OUTER_JOIN); criteria.addOrder(Order.asc("role.name")); arkModuleList = criteria.list();/* www .ja v a2s . com*/ ArrayList<ArkRole> moduleArkRolesList = new ArrayList<ArkRole>(); for (ArkModuleRole arkModuleRole : arkModuleList) { ArkRole arkRole = arkModuleRole.getArkRole(); moduleArkRolesList.add(arkRole); } return moduleArkRolesList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ArkUserRole> getArkUserRoleList(Study study, ArkUser arkUser) { // Criteria criteria = getSession().createCriteria(LinkStudyArkModule.class, "linkStudyArkModule"); // criteria.add(Restrictions.eq("study", study)); // criteria.createAlias("arkUserRoleList", "userRole", Criteria.LEFT_JOIN); // criteria.add(Restrictions.or(Restrictions.eq("userRole.arkUser", arkUser), Restrictions.isNull("userRole.arkUser"))); // criteria.add(Restrictions.eq("userRole.study", study)); ////from www. j av a 2s .com // ProjectionList projection = Projections.projectionList(); // projection.add(Projections.property("userRole.id"), "id"); // projection.add(Projections.property("userRole.arkUser"), "arkUser"); // projection.add(Projections.property("userRole.arkRole"), "arkRole"); // projection.add(Projections.property("linkStudyArkModule.arkModule"), "arkModule"); // projection.add(Projections.property("linkStudyArkModule.study"), "study"); // // criteria.setProjection(projection); // // criteria.setResultTransformer(Transformers.aliasToBean(ArkUserRole.class)); // List<ArkUserRole> listOfResults = criteria.list(); Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkUser", arkUser)); List<ArkUserRole> listOfResults = criteria.list(); return listOfResults; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Get the ArkUserRole details for the given user for a specific study * //ww w .ja v a 2 s . c om * @throws EntityNotFoundException */ @SuppressWarnings("unchecked") public List<ArkUserRole> getArkUserLinkedModuleAndRoles(ArkUserVO arkUserVO) throws EntityNotFoundException { ArkUser arkUser; List<ArkUserRole> arkUserRoleList = new ArrayList<ArkUserRole>(); arkUser = getArkUser(arkUserVO.getUserName()); arkUserVO.setArkUserPresentInDatabase(true); Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUser)); criteria.createAlias("arkModule", "module"); criteria.addOrder(Order.asc("module.id")); // Restrict by Study if NOT Super Administrator if (!isUserAdminHelper(arkUser.getLdapUserName(), au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { criteria.add(Restrictions.eq("study", arkUserVO.getStudy())); } try { arkUserRoleList = criteria.list(); } catch (org.hibernate.TransientObjectException toe) { log.error(toe.getMessage(), toe); } return arkUserRoleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Get a List of ArkUserRole objects for a given study and Module. This method can be used to determine a list of Ark Modules arkUsers are linked * to for a given study.//from w w w. j a v a2 s . co m * * @param study * @param arkModule * @return */ @SuppressWarnings("unchecked") public List<ArkUserRole> getArkUserLinkedModule(Study study, ArkModule arkModule) { List<ArkUserRole> arkUserRoleList = new ArrayList<ArkUserRole>(); Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkModule", arkModule)); criteria.add(Restrictions.eq("study", study)); arkUserRoleList = criteria.list(); return arkUserRoleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * // ww w. ja v a 2s.co m * Returns an existing collection of LinkStudyArkModule objects for a given Study * * @param study * @return List<LinkStudyArkModule> */ @SuppressWarnings("unchecked") public List<LinkStudyArkModule> getLinkStudyArkModulesList(Study study) { Criteria criteria = getSession().createCriteria(LinkStudyArkModule.class); criteria.add(Restrictions.eq("study", study)); return criteria.list(); }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ArkUserRole> getArkRoleListByUser(ArkUserVO arkUserVo) { List<ArkUserRole> arkUserRoleList = new ArrayList<ArkUserRole>(0); Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUserVo.getArkUserEntity())); // Restrict by Study if NOT Super Administrator try {/* w ww. jav a 2 s. com*/ if (!isUserAdminHelper(arkUserVo.getArkUserEntity().getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { Criteria studycriteria = criteria.createCriteria("study"); studycriteria.addOrder(Order.asc("name")); } } catch (HibernateException e) { log.error(e.getMessage(), e); } catch (EntityNotFoundException e) { log.error(e.getMessage(), e); } criteria.addOrder(Order.asc("arkModule")); criteria.addOrder(Order.asc("arkRole")); arkUserRoleList = (List<ArkUserRole>) criteria.list(); return arkUserRoleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ArkUserRole> getArkRoleListByUserAndStudy(ArkUserVO arkUserVo, Study study) { List<ArkUserRole> arkUserRoleList; Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.add(Restrictions.eq("arkUser", arkUserVo.getArkUserEntity())); try {//from ww w . j ava 2 s . c o m if (!isUserAdminHelper(arkUserVo.getArkUserEntity().getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR) && study != null && study.getId() != null) { criteria.add(Restrictions.eq("study", study)); } } catch (EntityNotFoundException e) { e.printStackTrace(); } //Criteria studycriteria = criteria.createCriteria("study"); //studycriteria.addOrder(Order.asc("name")); //criteria.addOrder(Order.asc("study.name")); criteria.addOrder(Order.asc("arkModule")); criteria.addOrder(Order.asc("arkRole")); arkUserRoleList = (List<ArkUserRole>) criteria.list(); return arkUserRoleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ArkRolePolicyTemplate> getArkRolePolicyTemplate(ArkRole arkRole, ArkModule arkModule) { List<ArkRolePolicyTemplate> arkRolePolicyTemplateList = new ArrayList<ArkRolePolicyTemplate>(0); Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class); criteria.add(Restrictions.eq("arkRole", arkRole)); if (!arkRole.getName() .equalsIgnoreCase(au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) { criteria.add(Restrictions.eq("arkModule", arkModule)); }/*ww w . jav a 2 s . c om*/ arkRolePolicyTemplateList = (List<ArkRolePolicyTemplate>) criteria.list(); return arkRolePolicyTemplateList; }
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 w w.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")); }