Example usage for org.hibernate.criterion Restrictions eq

List of usage examples for org.hibernate.criterion Restrictions eq

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions eq.

Prototype

public static SimpleExpression eq(String propertyName, Object value) 

Source Link

Document

Apply an "equal" constraint to the named property

Usage

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

License:Open Source License

private Criteria buildArkRoleCriteria(ArkRole arkRoleCriteria) {
    Criteria criteria = getSession().createCriteria(ArkRole.class);

    if (arkRoleCriteria.getId() != null) {
        criteria.add(Restrictions.eq("id", arkRoleCriteria.getId()));
    }//from  w ww.j  a  v a  2  s.com

    if (arkRoleCriteria.getName() != null) {
        criteria.add(Restrictions.eq("name", arkRoleCriteria.getName()));
    }

    if (arkRoleCriteria.getDescription() != null) {
        criteria.add(Restrictions.ilike("description", arkRoleCriteria.getName(), MatchMode.ANYWHERE));
    }

    criteria.addOrder(Order.asc("id"));
    return criteria;
}

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  a v a2  s.  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));
    }//from  ww w .  j a v  a2s  . c  om

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

    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.jav a2  s.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
 * /*  www  .j  a  v a  2  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

/**
 * <p>//from   ww w . j  a v  a 2  s . co  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  w  w .ja va2 s . co  m*/
    ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult();
    if (arkUserRole != null) {
        isAdminType = true;
    }
    session.close();
    return isAdminType;
}