Search in sources :

Example 1 with PermissionList

use of com.salesmanager.core.model.user.PermissionList in project shopizer by shopizer-ecommerce.

the class SecurityFacadeImpl method getPermissions.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List<ReadablePermission> getPermissions(List<String> groups) {
    List<Group> userGroups = null;
    try {
        userGroups = groupService.listGroupByNames(groups);
        List<Integer> ids = new ArrayList<Integer>();
        for (Group g : userGroups) {
            ids.add(g.getId());
        }
        PermissionCriteria criteria = new PermissionCriteria();
        criteria.setGroupIds(new HashSet(ids));
        PermissionList permissions = permissionService.listByCriteria(criteria);
        throw new ServiceRuntimeException("Not implemented");
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : PermissionCriteria(com.salesmanager.core.model.user.PermissionCriteria) Group(com.salesmanager.core.model.user.Group) ServiceException(com.salesmanager.core.business.exception.ServiceException) PermissionList(com.salesmanager.core.model.user.PermissionList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PermissionList

use of com.salesmanager.core.model.user.PermissionList in project shopizer by shopizer-ecommerce.

the class PermissionRepositoryImpl method listByCriteria.

@Override
public PermissionList listByCriteria(PermissionCriteria criteria) {
    PermissionList permissionList = new PermissionList();
    StringBuilder countBuilderSelect = new StringBuilder();
    countBuilderSelect.append("select count(p) from Permission as p");
    StringBuilder countBuilderWhere = new StringBuilder();
    if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
        countBuilderSelect.append(" INNER JOIN p.groups grous");
        countBuilderWhere.append(" where grous.id in (:cid)");
    }
    Query countQ = em.createQuery(countBuilderSelect.toString() + countBuilderWhere.toString());
    if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
        countQ.setParameter("cid", criteria.getGroupIds());
    }
    Number count = (Number) countQ.getSingleResult();
    permissionList.setTotalCount(count.intValue());
    if (count.intValue() == 0)
        return permissionList;
    StringBuilder qs = new StringBuilder();
    qs.append("select p from Permission as p ");
    qs.append("join fetch p.groups grous ");
    if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
        qs.append(" where grous.id in (:cid)");
    }
    qs.append(" order by p.id asc ");
    String hql = qs.toString();
    Query q = em.createQuery(hql);
    if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
        q.setParameter("cid", criteria.getGroupIds());
    }
    if (criteria.getMaxCount() > 0) {
        q.setFirstResult(criteria.getStartIndex());
        if (criteria.getMaxCount() < count.intValue()) {
            q.setMaxResults(criteria.getMaxCount());
            permissionList.setTotalCount(criteria.getMaxCount());
        } else {
            q.setMaxResults(count.intValue());
            permissionList.setTotalCount(count.intValue());
        }
    }
    @SuppressWarnings("unchecked") List<Permission> permissions = q.getResultList();
    permissionList.setPermissions(permissions);
    return permissionList;
}
Also used : Query(javax.persistence.Query) PermissionList(com.salesmanager.core.model.user.PermissionList) Permission(com.salesmanager.core.model.user.Permission)

Aggregations

PermissionList (com.salesmanager.core.model.user.PermissionList)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Group (com.salesmanager.core.model.user.Group)1 Permission (com.salesmanager.core.model.user.Permission)1 PermissionCriteria (com.salesmanager.core.model.user.PermissionCriteria)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Query (javax.persistence.Query)1