List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Retrieve a Logged in user's role by providing the Ldap User Name, Usecase id, module id & or study id. We need the Ldap User Name & ArkUseCase * Id as a mandatory one./*w w w. ja v a2 s . c o m*/ * * @throws EntityNotFoundException */ @SuppressWarnings("unchecked") public String getUserRole(String ldapUserName, ArkFunction arkFunction, ArkModule arkModule, Study study) throws EntityNotFoundException { String roleName = ""; ArkUser arkUser = getArkUser(ldapUserName); Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.createAlias("arkUser", "auserObject"); criteria.add(Restrictions.eq("arkUser", arkUser)); // Even if there is a study in session the criteria must be applied only if the logged in user has a study registered for him. Ie if he is not a // Super Admin if (!isSuperAdministrator(ldapUserName) && study != null) { criteria.add(Restrictions.eq("study", study)); if (arkModule != null) { criteria.add(Restrictions.eq("arkModule", arkModule)); } // criteria.setMaxResults(1); List<ArkUserRole> list = (List<ArkUserRole>) criteria.list(); if (list.size() > 0) { ArkUserRole arkUserRole = (ArkUserRole) criteria.list().get(0); // ArkUserRole arkUserRole = (ArkUserRole)criteria.list().get(0); if (arkUserRole != null) { roleName = arkUserRole.getArkRole().getName(); } } } else { if (arkModule != null) { criteria.add(Restrictions.eq("arkModule", arkModule)); } criteria.setMaxResults(1); ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult(); if (arkUserRole != null) { roleName = arkUserRole.getArkRole().getName(); } } return roleName; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public Collection<String> getArkRolePermission(ArkFunction arkFunction, String userRole, ArkModule arkModule) throws EntityNotFoundException { Collection<String> stringPermissions = new ArrayList<String>(); ArkRole arkRole = getArkRoleByName(userRole); Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class); if (arkModule != null) { criteria.add(Restrictions.eq("arkModule", arkModule)); }//from w ww. jav a 2 s. c o m if (arkFunction != null) { criteria.add(Restrictions.eq("arkFunction", arkFunction)); } if (arkRole != null) { criteria.add(Restrictions.eq("arkRole", arkRole)); criteria.createAlias("arkPermission", "permission"); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("permission.name")); criteria.setProjection(projectionList); stringPermissions = criteria.list(); } return stringPermissions; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public Collection<ArkModuleRole> getArkModuleAndLinkedRoles() { Collection<ArkModuleRole> arkModuleList = new ArrayList<ArkModuleRole>(); Criteria criteria = getSession().createCriteria(ArkModuleRole.class); criteria.createAlias("arkModule", "moduleName"); criteria.addOrder(Order.asc("moduleName.name")); arkModuleList = criteria.list();//from w ww . ja va 2s . c o m //TODO: What are we iterating for if we are not doing anything? delete? /*for (Iterator iterator = arkModuleList.iterator(); iterator.hasNext();) { ArkModuleRole arkModuleRole = (ArkModuleRole) iterator.next(); }*/ return arkModuleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Get a list of Modules that are linked to the study and then get the roles linked to each module A VO List of ArkModuleVO will contain the * ArkModule and a list of ArkRoles. Note:This implementation will exclude Reporting Module from the list specifically. * /*from w ww. ja v a 2 s . c o m*/ * @param study * @return Collection<ArkModuleVO> Minus the Reporting Module */ @SuppressWarnings("unchecked") public Collection<ArkModuleVO> getArkModulesAndRolesLinkedToStudy(Study study) { ArkModule arkModuleToExclude = getArkModuleByName(Constants.ARK_MODULE_REPORTING); Collection<LinkStudyArkModule> arkStudyLinkedModuleList = new ArrayList<LinkStudyArkModule>(); Collection<ArkModuleVO> arkModuleVOList = new ArrayList<ArkModuleVO>(); Criteria criteria = getSession().createCriteria(LinkStudyArkModule.class); criteria.add(Restrictions.eq("study", study)); //criteria.add(Restrictions.ne("arkModule", arkModuleToExclude)); criteria.createAlias("arkModule", "module"); criteria.addOrder(Order.asc("module.id")); arkStudyLinkedModuleList = criteria.list(); // For each one in the List get the associated Roles i.e for each module get the Roles for (LinkStudyArkModule linkStudyArkModule : arkStudyLinkedModuleList) { // Here is a Module linked to a study get the Roles linked to this module ArkModuleVO arkModuleVO = new ArkModuleVO(); arkModuleVO.setArkModule(linkStudyArkModule.getArkModule()); arkModuleVO.setArkModuleRoles(getArkRoleLinkedToModule(linkStudyArkModule.getArkModule())); arkModuleVOList.add(arkModuleVO); } // getArkUserRoleList(study,null); return arkModuleVOList; }
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()); }/* w w w .j a v a 2 s . co m*/ return arkModuleList; }
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 * /*from w w w . j a va2s.co m*/ * @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
@SuppressWarnings("unchecked") public List<ArkModule> getArkModuleListByArkUser(ArkUser arkUser) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); ArkModule arkModule = null;/* ww w . jav a2s. c om*/ 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.AuditDao.java
License:Open Source License
@Override public String getFieldName(Class<?> cls, String field) { Criteria criteria = getSession().createCriteria(AuditField.class); criteria.add(Restrictions.eq("fieldName", field)); criteria.createAlias("auditEntity", "ae"); criteria.add(Restrictions.eq("ae.classIdentifier", cls.getCanonicalName())); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return ((AuditField) criteria.uniqueResult()).getName(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
/** * Look up the Link Subject Study for subjects linked to a study * /*from www . j a v a2 s .co m*/ * @param subjectVO * @return */ @SuppressWarnings("unchecked") public Collection<SubjectVO> getSubject(SubjectVO subjectVO) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("person", "p"); criteria.add(Restrictions.eq("study.id", subjectVO.getLinkSubjectStudy().getStudy().getId())); 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) { criteria.add(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE)); } 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().getSubjectUID() != null && subjectVO.getLinkSubjectStudy().getSubjectUID().length() > 0) { criteria.add(Restrictions.eq("subjectUID", subjectVO.getLinkSubjectStudy().getSubjectUID())); } 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)); } } criteria.addOrder(Order.asc("subjectUID")); List<LinkSubjectStudy> list = criteria.list(); Collection<SubjectVO> subjectVOList = new ArrayList<SubjectVO>(); for (Iterator iterator = list.iterator(); iterator.hasNext();) { LinkSubjectStudy linkSubjectStudy = (LinkSubjectStudy) iterator.next(); // Place the LinkSubjectStudy instance into a SubjectVO and add the // SubjectVO into a List SubjectVO subject = new SubjectVO(); subject.setLinkSubjectStudy(linkSubjectStudy); Person person = subject.getLinkSubjectStudy().getPerson(); subject.setSubjectPreviousLastname(getPreviousLastname(person)); subjectVOList.add(subject); } return subjectVOList; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean isSubjectConsentedToComponent(StudyComp studyComponent, Person person, Study study) { boolean isConsented = false; Criteria criteria = getSession().createCriteria(Consent.class); criteria.add(Restrictions.eq("studyComp", studyComponent)); criteria.add(Restrictions.eq("study", study)); criteria.createAlias("linkSubjectStudy", "lss"); criteria.add(Restrictions.eq("lss.person", person)); List list = criteria.list();/*from www .j a v a 2 s. c om*/ if (list != null && list.size() > 0) { isConsented = true; } return isConsented; }