Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

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

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

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));
    }/*from w  w  w.j  av a 2s . c o m*/
    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

private List<ArkModuleRole> getArkModuleRoleByArkModule(ArkModule arkModule) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);

    if (arkModule.getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModule));
    }//  w ww .  j  a  va 2s. co  m

    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));

    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   www  . ja  v  a  2s .  c  o 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.admin.model.dao.AdminDao.java

License:Open Source License

private Criteria buildArkModuleRoleCriteria(ArkModuleRole arkModuleRoleCriteria) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);

    if (arkModuleRoleCriteria.getArkModule() != null && arkModuleRoleCriteria.getArkModule().getId() != null) {
        criteria.add(Restrictions.eq("arkModule", arkModuleRoleCriteria.getArkModule()));
    }//  w ww .  j a  v  a 2  s  .  c om

    if (arkModuleRoleCriteria.getArkRole() != null && arkModuleRoleCriteria.getArkRole().getId() != null) {
        criteria.add(Restrictions.eq("arkRole", arkModuleRoleCriteria.getArkRole()));
    }

    criteria.createAlias("arkModule", "module");
    criteria.addOrder(Order.asc("module.name"));

    return criteria;
}

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

License:Open Source License

public ArkModuleRole getArkModuleRole(Long id) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    criteria.add(Restrictions.eq("id", id));
    return (ArkModuleRole) criteria.uniqueResult();
}

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   w  ww  .  ja va 2  s.c o m
 * @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
 * // ww w. ja va 2s.c  o  m
 * @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

/**
 * <p>// ww  w  .j  a v a  2  s .  c o  m
 * Given a String Role name like Super Administrator or Administrator the method will return the actual instance of ArkRole object.
 * </p>
 * 
 * @param roleName
 * @return ArkRole
 */
public ArkRole getArkRoleByName(String roleName) {
    Criteria criteria = getSession().createCriteria(ArkRole.class);
    criteria.add(Restrictions.eq("name", roleName));
    ArkRole arkRole = (ArkRole) criteria.uniqueResult();
    return arkRole;
}

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 w ww  . j  a v a  2s  . co  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

@SuppressWarnings("unchecked")
public List<ArkUserRole> getArkSuperAdministratorList() throws EntityNotFoundException {
    Criteria criteria = getSession().createCriteria(ArkUserRole.class);
    ArkRole arkRole = getArkRoleByName(RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR);
    criteria.add(Restrictions.eq("arkRole", arkRole));
    return criteria.list();
}