@Override
 public Page<Permission> findAllPermissions(Pageable pageable) {
   if (pageable == null) {
     pageable = new PageRequest(0, 20);
   }
   return permissionDao.findAll(pageable);
 }
 @Override
 public Permission findPermissionById(String id) {
   if (!StringUtils.hasText(id)) {
     return null;
   }
   return permissionDao.findOne(id);
 }
  @Override
  public List<Permission> findPermissionsNotInRole(Role role) {
    if (role == null) {
      return new ArrayList<Permission>();
    }

    Role r = findRoleById(role.getId());
    if (r == null || r.getPermissionSet().isEmpty()) {
      return new ArrayList<Permission>();
    }

    List<String> ids = new ArrayList<String>();
    for (Permission p : r.getPermissionSet()) {
      ids.add(p.getId());
    }

    return permissionDao.findByIdNotIn(ids);
  }
 @Override
 public Long countAllPermissions() {
   return permissionDao.count();
 }
 @Override
 public void delete(Permission m) {
   permissionDao.delete(m);
 }
 @Override
 public void save(Permission m) {
   permissionDao.save(m);
 }