Example usage for org.hibernate Criteria list

List of usage examples for org.hibernate Criteria list

Introduction

In this page you can find the example usage for org.hibernate Criteria list.

Prototype

public List list() throws HibernateException;

Source Link

Document

Get the results.

Usage

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();/*  ww w. j  a  va 2  s  .com*/
    return arkUserRoleList;
}

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  .j  a v  a 2  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));
    }// www.  j  av  a  2 s.  co  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

/**
 * Returns a list of All Permissions in Ark System
 * /*from  w  ww  . jav a  2 s . co m*/
 * @return
 */
@SuppressWarnings("unchecked")
public Collection<String> getArkPermission() {
    Collection<String> arkStringPermissions = new ArrayList<String>();
    Criteria criteria = getSession().createCriteria(ArkPermission.class);
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("name"));
    criteria.setProjection(projectionList);
    arkStringPermissions = criteria.list();
    return arkStringPermissions;
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public Collection<Class<T>> getEntityList(Class aClass) {
    Collection<Class<T>> arkModuleList = new ArrayList<Class<T>>();
    Criteria criteria = getSession().createCriteria(aClass);
    arkModuleList = criteria.list();
    return (Collection<Class<T>>) arkModuleList;
}

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();

    //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();
            /*from w w  w.  j a va  2  s  .  com*/
    }*/
    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 va2 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());
    }/*from  w  w  w.  j a  v a 2  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();
    ArrayList<ArkRole> moduleArkRolesList = new ArrayList<ArkRole>();
    for (ArkModuleRole arkModuleRole : arkModuleList) {

        ArkRole arkRole = arkModuleRole.getArkRole();
        moduleArkRolesList.add(arkRole);
    }/*from   w  ww .ja  va  2  s .  com*/
    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 a v a  2s.  co  m
    //      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;

}