Search in sources :

Example 1 with AdminPermissionImpl

use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminPermissionDaoImpl method readAdminPermissionByNameAndType.

@Override
public AdminPermission readAdminPermissionByNameAndType(String name, String type) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
    Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
    criteria.select(adminPerm);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(adminPerm.get("name"), name));
    restrictions.add(builder.equal(adminPerm.get("type"), type));
    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<AdminPermission> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
    List<AdminPermission> results = query.getResultList();
    if (results == null || results.size() == 0) {
        return null;
    } else {
        return results.get(0);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminPermissionImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 2 with AdminPermissionImpl

use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminPermissionDataProvider method createAdminUser.

@DataProvider(name = "setupAdminPermission")
public static Object[][] createAdminUser() {
    AdminPermission adminPermission = new AdminPermissionImpl();
    adminPermission.setName("TestAdminPermissionName");
    adminPermission.setDescription("Test Admin Permission Description");
    adminPermission.setType(PermissionType.ALL);
    return new Object[][] { new Object[] { adminPermission } };
}
Also used : AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminPermissionImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl) DataProvider(org.testng.annotations.DataProvider)

Example 3 with AdminPermissionImpl

use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminPermissionDaoImpl method readAdminPermissionByName.

@Override
public AdminPermission readAdminPermissionByName(String name) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
    Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
    criteria.select(adminPerm);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(adminPerm.get("name"), name));
    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<AdminPermission> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
    List<AdminPermission> results = query.getResultList();
    if (results == null || results.size() == 0) {
        return null;
    } else {
        return results.get(0);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminPermissionImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Aggregations

AdminPermission (org.broadleafcommerce.openadmin.server.security.domain.AdminPermission)3 AdminPermissionImpl (org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 DataProvider (org.testng.annotations.DataProvider)1