return role;
}
public Representation delete() {
try {
Role role = fetch();
if (role!=null) {
if (permissionId!=null) {
// delete for permission by id
try {
UUID id = UUID.fromString(permissionId);
Permission p = db.getPermission(id);
if (p==null || !role.hasPermission(p)) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
} else {
role.removePermission(p);
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
}
return null;
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Error deleting permission "+permissionId,ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Database error retrieving permission, see logs.");
} catch (IllegalArgumentException ex) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Bad UUID value "+permissionId);
}
} else if (permissionName!=null) {
// delete for permission by name
try {
Permission p = db.getPermission(permissionName);
if (p==null || !role.hasPermission(p)) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
} else {
role.removePermission(p);
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
}
return null;
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Error deleting permission "+permissionName,ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Database error retrieving permission, see logs.");
}
} else {
role.delete();
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
return null;
}
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);