public static Permission fetchById(Long id) {
    if (id == null) throw new RuntimeException("id required");

    Permission perm = Permission.findById(id);
    if (perm == null) throw new RuntimeException("Permission not found");

    return perm;
  }
Beispiel #2
0
 /**
  * This method checks whether user has a permission by its id.
  *
  * @param permissionName
  * @return true if exists
  */
 public boolean hasPermission(Long permissionId) {
   if (permissionId != null) {
     Permission permission = Permission.findById(permissionId);
     if (this.permissions.contains(permission)) {
       return true;
     }
   }
   return false;
 }
  public static void deleteById(Long id) {
    if (id == null) throw new RuntimeException("id required");

    Permission permission = Permission.findById(id);
    if (permission == null) throw new RuntimeException("Permission not found");

    try {
      permission.delete();
    } catch (Throwable e) {
      throw new RuntimeException(
          "Could Not Delete This Permission Cause It is Assigned to Roles !");
    }
  }
  public static void updateByVO(PermVO vo) {
    vo.validate();
    Permission p = Permission.findById(Long.parseLong(vo.id));
    if (p == null) throw new RuntimeException("Permission not found");

    p.action = vo.action;
    p.desc = vo.desc;

    Permission db_p = Permission.findByAction(p.action);
    if (db_p != null && db_p.id != p.id) throw new RuntimeException("Action duplicate!");

    p.save();
  }