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

/**
 * Get the ArkUserRole details for the given user for a specific study
 * /*w  w  w .  ja  v a 2  s. c  o 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

/**
 * 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./*www .j av  a  2  s. c o  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

/**
 * //from   www.  j  ava2 s . 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

public StudyStatus getStudyStatus(String statusName) throws StatusNotAvailableException {
    StudyStatus studyStatus = new StudyStatus();
    studyStatus.setName("Archive");
    Example studyStatusExample = Example.create(studyStatus);

    Criteria studyStatusCriteria = getSession().createCriteria(StudyStatus.class).add(studyStatusExample);
    if (studyStatusCriteria != null && studyStatusCriteria.list() != null
            && studyStatusCriteria.list().size() > 0) {
        return (StudyStatus) studyStatusCriteria.list().get(0);
    } else {/*from   w ww  . j ava2  s . c om*/
        log.error("Study Status Table maybe out of synch. Please check if it has an entry for Archive status");
        throw new StatusNotAvailableException();
    }
}

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 {//from  w ww  .  j  a  va  2  s . c om
        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  w  w w  .j  av  a 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));
    }/* www .  jav a 2 s  .  c  o  m*/
    arkRolePolicyTemplateList = (List<ArkRolePolicyTemplate>) criteria.list();
    return arkRolePolicyTemplateList;
}

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

License:Open Source License

/**
 * Invoke this mehod when the ArkUser is permitted(a Super Administrator) to view all studies.
 * // www .  j  av a  2 s . co  m
 * @param searchStudy
 * @return List<Study>
 */
@SuppressWarnings("unchecked")
private List<Study> getAllStudiesForSuperAdmin(Study searchStudy) {
    Criteria criteria = getSession().createCriteria(Study.class);
    applyStudySearchCriteria(searchStudy, criteria, true);
    return criteria.list();
}

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 a  v  a 2  s.c  o m*/
        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  ava 2  s  .  c o  m*/
        // 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;

}