List of usage examples for org.hibernate StatelessSession close
void close();
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Looks up a ArkUser based on a String that represents the user name in LDAP. If the user name provided is null or is invalid/does not exist in * the database, the method will return NULL for a ArkUser instance. * /*from www . ja v a2s .c om*/ * @param ldapUserName * @return ArkUser */ public ArkUser getArkUser(String ldapUserName) throws EntityNotFoundException { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(ArkUser.class); criteria.add(Restrictions.eq("ldapUserName", ldapUserName)); ArkUser arkUser = (ArkUser) criteria.uniqueResult(); // Close the session session.close(); if (arkUser != null) { return arkUser; } else { throw new EntityNotFoundException("The given Ldap User does not exist in the database system"); } }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
/** * Overloaded method to lookup an ArkUser by username and study * /* w w w . j a v a2 s .c om*/ * @param ldapUserName * @param study * @return * @throws EntityNotFoundException */ public ArkUser getArkUser(String ldapUserName, Study study) throws EntityNotFoundException { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(ArkUser.class); criteria.add(Restrictions.eq("ldapUserName", ldapUserName)); criteria.add(Restrictions.eq("study", study)); ArkUser arkUser = (ArkUser) criteria.uniqueResult(); // Close the session session.close(); if (arkUser != null) { return arkUser; } else { throw new EntityNotFoundException("The given Ldap User does not exist in the database system"); } }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
public boolean isUserAdminHelper(String ldapUserName, String roleName) throws EntityNotFoundException { boolean isAdminType = false; StatelessSession session = getStatelessSession(); // Check or get user ark_user object based on ldapUserName ArkUser arkUser = getArkUser(ldapUserName); Criteria criteria = session.createCriteria(ArkUserRole.class); ArkRole arkRole = getArkRoleByName(roleName); criteria.add(Restrictions.eq("arkRole", arkRole)); criteria.add(Restrictions.eq("arkUser", arkUser)); criteria.setMaxResults(1);//from ww w .ja v a 2s .c o m ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult(); if (arkUserRole != null) { isAdminType = true; } session.close(); return isAdminType; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
private boolean isUserAdminHelper(String ldapUserName, String roleName, ArkFunction arkFunction, ArkModule arkModule) throws EntityNotFoundException { boolean isAdminType = false; StatelessSession session = getStatelessSession(); // Check or get user ark_user object based on ldapUserName ArkUser arkUser = getArkUser(ldapUserName); Criteria criteria = session.createCriteria(ArkUserRole.class); ArkRole arkRole = getArkRoleByName(roleName); criteria.add(Restrictions.eq("arkRole", arkRole)); criteria.add(Restrictions.eq("arkUser", arkUser)); criteria.add(Restrictions.eq("arkModule", arkModule)); criteria.setMaxResults(1);//from w ww . ja va 2s . c o m ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult(); if (arkUserRole != null) { isAdminType = true; } session.close(); return isAdminType; }
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.j a v a2 s . 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.ArkAuthorisationDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ArkUserRole> getArkUserAdminRoles(String ldapUserName) throws EntityNotFoundException { ArkUser arkUser = getArkUser(ldapUserName); StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(ArkUserRole.class);// getSession().createCriteria(ArkUserRole.class); ArkRole arkRoleStudyAdmin = getArkRoleByName(RoleConstants.ARK_ROLE_STUDY_ADMINISTATOR); criteria.add(Restrictions.eq("arkRole", arkRoleStudyAdmin)); criteria.add(Restrictions.eq("arkUser", arkUser)); List<ArkUserRole> arkUserRoleList = (List<ArkUserRole>) criteria.list(); session.close(); return arkUserRoleList; }
From source file:au.org.theark.core.dao.ArkAuthorisationDao.java
License:Open Source License
public String getUserRoleForStudy(String ldapUserName, Study study) throws EntityNotFoundException { String roleName = ""; ArkUser arkUser = getArkUser(ldapUserName); StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(ArkUserRole.class);// getSession().createCriteria(ArkUserRole.class); criteria.createAlias("arkUser", "auserObject"); criteria.add(Restrictions.eq("arkUser", arkUser)); criteria.add(Restrictions.eq("auserObject.study", study)); criteria.setMaxResults(1);//from www. j a va2s . co m ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult(); if (arkUserRole != null) { roleName = arkUserRole.getArkRole().getName(); } session.close(); return roleName; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasSubjects(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(LinkSubjectStudy.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close(); return totalCount.intValue() > 0; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasBiospecimen(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(Biospecimen.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close(); return totalCount.intValue() > 0; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public Boolean studyHasBioCollection(Study study) { StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BioCollection.class); criteria.add(Restrictions.eq("study", study)); criteria.setProjection(Projections.rowCount()); Long totalCount = (Long) criteria.uniqueResult(); session.close(); return totalCount.intValue() > 0; }