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

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

License:Open Source License

private boolean isUserAdminHelper(String ldapUserName, String roleName, ArkFunction arkFunction,
        ArkModule arkModule) 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.add(Restrictions.eq("arkModule", arkModule));

    criteria.setMaxResults(1);//from   www .ja va 2  s .  c o  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

/**
 * Use this method when we want to load the Collection of Administrator roles as a Collectio<String>. The method looks up Ark Super Administrator
 * and Administrator roles given a LdapUserName. It populates it into a Collection<String> that represent a unique set of administration roles for
 * this user. It does not take into account the Module or Study. This is usually when the user has logged in first and we want to know if the user
 * has a role of type Administator so he can have access to Create function.
 * /*from  www  .  j  av a 2s .  c om*/
 * @param ldapUserName
 * @return Collection<String>
 * @throws EntityNotFoundException
 */
@SuppressWarnings("unchecked")
public Collection<String> getUserAdminRoles(String ldapUserName) throws EntityNotFoundException {

    ArkUser arkUser = getArkUser(ldapUserName);

    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(ArkUserRole.class);// getSession().createCriteria(ArkUserRole.class);
    ArkRole arkRoleSuperAdmin = getArkRoleByName(RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR);
    ArkRole arkRoleAdmin = getArkRoleByName(RoleConstants.ARK_ROLE_ADMINISTATOR);
    criteria.add(Restrictions.or(Restrictions.eq("arkRole", arkRoleSuperAdmin),
            Restrictions.eq("arkRole", arkRoleAdmin)));
    criteria.add(Restrictions.eq("arkUser", arkUser));
    List<ArkUserRole> arkUserRoleList = (List<ArkUserRole>) criteria.list();
    Set<String> roles = new HashSet<String>(0);
    for (ArkUserRole arkUserRole : arkUserRoleList) {
        String roleName = arkUserRole.getArkRole().getName();
        roles.add(roleName);
    }

    Collection<String> userRoles = new ArrayList<String>();
    for (String roleName : roles) {
        userRoles.add(roleName);
    }
    session.close();
    return userRoles;
}

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();/*from   w  ww  .  java2 s .c  o  m*/
    return arkUserRoleList;
}

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

License:Open Source License

public String getUserRoleForStudy(String ldapUserName, Study study) throws EntityNotFoundException {
    String roleName = "";
    ArkUser arkUser = getArkUser(ldapUserName);
    StatelessSession session = getStatelessSession();

    Criteria criteria = session.createCriteria(ArkUserRole.class);// getSession().createCriteria(ArkUserRole.class);
    criteria.createAlias("arkUser", "auserObject");
    criteria.add(Restrictions.eq("arkUser", arkUser));
    criteria.add(Restrictions.eq("auserObject.study", study));
    criteria.setMaxResults(1);/*  w w w.  j  a  v a 2  s  .  c o m*/
    ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult();
    if (arkUserRole != null) {
        roleName = arkUserRole.getArkRole().getName();
    }
    session.close();
    return roleName;
}

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./*from w  w  w  . j  a v a2s . 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

public ArkFunction getArkFunctionByName(String functionName) {
    Criteria criteria = getSession().createCriteria(ArkFunction.class);
    criteria.add(Restrictions.eq("name", functionName));
    criteria.setMaxResults(1);//from  w w w . j a va 2  s .c o  m
    ArkFunction arkFunction = (ArkFunction) criteria.uniqueResult();
    return arkFunction;
}

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

License:Open Source License

public ArkModule getArkModuleByName(String moduleName) {
    Criteria criteria = getSession().createCriteria(ArkModule.class);
    criteria.add(Restrictions.eq("name", moduleName));
    criteria.setMaxResults(1);/*from w  w w .  j a va2 s  .  c  o  m*/
    ArkModule arkModule = (ArkModule) criteria.uniqueResult();
    return arkModule;
}

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

License:Open Source License

public ArkModule getArkModuleById(Long moduleId) {
    Criteria criteria = getSession().createCriteria(ArkModule.class);
    criteria.add(Restrictions.eq("id", moduleId));
    criteria.setMaxResults(1);//from w ww.  ja va2  s.  com
    ArkModule arkModule = (ArkModule) criteria.uniqueResult();
    return arkModule;
}

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));
    }//from  ww  w  . j ava2s .c  om

    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;
}