Example usage for org.hibernate.criterion ProjectionList add

List of usage examples for org.hibernate.criterion ProjectionList add

Introduction

In this page you can find the example usage for org.hibernate.criterion ProjectionList add.

Prototype

public ProjectionList add(Projection projection, String alias) 

Source Link

Document

Adds a projection to this list of projections after wrapping it with an alias

Usage

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

protected Criteria buildArkRoleModuleFunctionVoCriteria(
        ArkRoleModuleFunctionVO arkRoleModuleFunctionVoCriteria) {
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class, "arpt");

    if (arkRoleModuleFunctionVoCriteria.getArkRole() != null) {
        criteria.add(Restrictions.eq("arpt.arkRole", arkRoleModuleFunctionVoCriteria.getArkRole()));
    }//from  w w  w.  j  av  a 2 s.  c om

    if (arkRoleModuleFunctionVoCriteria.getArkModule() != null) {
        criteria.add(Restrictions.eq("arpt.arkModule", arkRoleModuleFunctionVoCriteria.getArkModule()));
    }

    if (arkRoleModuleFunctionVoCriteria.getArkFunction() != null) {
        criteria.add(Restrictions.eq("arpt.arkFunction", arkRoleModuleFunctionVoCriteria.getArkFunction()));
    }

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arpt.arkRole"), "arkRole");
    projectionList.add(Projections.groupProperty("arpt.arkModule"), "arkModule");
    projectionList.add(Projections.groupProperty("arpt.arkFunction"), "arkFunction");

    criteria.setProjection(projectionList);

    ResultTransformer resultTransformer = Transformers.aliasToBean(ArkRoleModuleFunctionVO.class);
    criteria.setResultTransformer(resultTransformer);

    return criteria;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkRoleModuleFunctionVO> getArkRoleModuleFunctionVoList(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkRolePolicyTemplate.class, "arpt");
    criteria.add(Restrictions.eq("arpt.arkRole", arkRole));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arpt.arkRole"), "arkRole");
    projectionList.add(Projections.groupProperty("arpt.arkModule"), "arkModule");
    projectionList.add(Projections.groupProperty("arpt.arkFunction"), "arkFunction");

    criteria.setProjection(projectionList);

    ResultTransformer resultTransformer = Transformers.aliasToBean(ArkRoleModuleFunctionVO.class);
    criteria.setResultTransformer(resultTransformer);

    return criteria.list();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkModule> getArkModuleList(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);

    if (arkRole != null) {
        criteria.add(Restrictions.eq("arkRole", arkRole));
    }//from w  w w . java 2s. c  o m
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkModule"), "arkModule");
    criteria.setProjection(projectionList);

    return criteria.list();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkFunction> getArkFunctionListByArkModule(ArkModule arkModule) {
    Criteria criteria = getSession().createCriteria(ArkModuleFunction.class);
    if (arkModule.getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }/*from  w  w  w.  j  a v  a2  s .  c o m*/
    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));
    criteria.addOrder(Order.asc("functionSequence"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkFunction"), "arkFunction");
    criteria.setProjection(projectionList);
    return criteria.list();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkModule> getArkModuleListByArkRole(ArkRole arkRole) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    if (arkRole != null) {
        criteria.add(Restrictions.eq("arkRole", arkRole));
    }/* w ww  .j av  a 2s .  com*/
    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkModule"), "arkModule");
    criteria.setProjection(projectionList);
    return criteria.list();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public List<ArkRole> getArkRoleListByArkModule(ArkModule arkModule) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    if (arkModule.getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }//from   w w  w  .ja  v  a  2s . co m

    // Restrict searching/selecting of Super Administrator
    criteria.add(Restrictions.ne("arkModule",
            getArkRoleByName(au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)));

    criteria.createAlias("arkRole", "role");
    criteria.addOrder(Order.asc("role.name"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkRole"), "arkRole");
    criteria.setProjection(projectionList);
    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 {/* ww  w . j  ava2 s  .co 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  a v  a  2s .  co 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;

}

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;/*from w w  w. j ava  2 s  .c  o m*/
    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.ArkAuthorisationDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ArkUser> getArkUserListByStudy(ArkUser arkUser, Study study) {
    Criteria criteria = getSession().createCriteria(ArkUserRole.class);
    // Restrict by user if NOT Super Administrator
    try {//from  ww w .  jav a  2  s . c  o  m
        if (!isUserAdminHelper(arkUser.getLdapUserName(), RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) {
            criteria.add(Restrictions.eq("study", study));
        }
    } catch (EntityNotFoundException e) {
        log.info("User Name doen not exsists");
    }
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("arkUser"), "arkUser");
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(ArkUserRole.class));
    List<ArkUserRole> arkUserRoles = (List<ArkUserRole>) criteria.list();
    List<ArkUser> arkUserLst = new ArrayList<ArkUser>();
    for (ArkUserRole arkRolePol : arkUserRoles) {
        arkUserLst.add(arkRolePol.getArkUser());
    }
    //Added on 2015-12-10 filter study wise users.
    //changed on 2016-04-28.
    return arkUserLst;
}