X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FDeleteProfileFieldAjaxPage.java;h=b787e8c7b323dfb015ea1d62e29be7c220933c72;hb=f10d40f746f6c7c716f783da11791d28c1117447;hp=cb33fb951f06fb8a01eb640389a59fbc552c9700;hpb=629ddb006542df2b671e172d8f544815bbab639b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java index cb33fb9..b787e8c 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java @@ -27,6 +27,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; +import com.google.common.base.Optional; /** * AJAX page that lets the user delete a profile field. @@ -45,22 +46,19 @@ public class DeleteProfileFieldAjaxPage extends JsonPage { super("deleteProfileField.ajax", webInterface); } - /** - * {@inheritDoc} - */ @Override protected JsonReturnObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); - Field field = profile.getFieldById(fieldId); - if (field == null) { + Optional field = profile.getFieldById(fieldId); + if (!field.isPresent()) { return createErrorJsonObject("invalid-field-id"); } - profile.removeField(field); + profile.removeField(field.get()); currentSone.setProfile(profile); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("field", new ObjectNode(instance).put("id", new TextNode(field.getId()))); + return createSuccessJsonObject().put("field", new ObjectNode(instance).put("id", new TextNode(field.get().getId()))); } }