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