@DELETE @Path("/{value}") public Response delete(@PathParam("value") final String value) { // TODO: should use this for deleting items from restful table int v = Integer.valueOf(value); boolean flag = false; for (CustomlinksResourceModel.Link link : customlinks) if (link.getLinkNum() == v) { customlinks.remove(link); flag = true; break; } CacheControl cc = new CacheControl(); cc.setNoCache(true); if (flag) return Response.ok(customlinks).cacheControl(cc).build(); return Response.status(204).cacheControl(cc).build(); }
@POST @Path("/update") // TODO: modify data consumed later public Response update( @FormParam("value") String value, @FormParam("label") String label, @FormParam("url") String url, @FormParam("text") String text) { boolean flag = false; for (CustomlinksResourceModel.Link link : customlinks) if (link.getLinkNum() == Integer.valueOf(value)) { link.setLabel(label); link.setUrl(url); link.setText(text); flag = true; } CacheControl cc = new CacheControl(); cc.setNoCache(true); if (flag) return Response.ok(customlinks).cacheControl(cc).build(); return Response.status(204).cacheControl(cc).build(); }
// check for duplicate before adding the new link private boolean duplicateCheck(String label) { for (CustomlinksResourceModel.Link link : customlinks) if (link.getLabel().equals(label)) return true; return false; }