@GET @Produces(MediaType.APPLICATION_JSON) @Path("/attribute") public String getAttributes() { ArrayNode noAttributes = JsonNodeFactory.instance.arrayNode(); for (Attribute attribute : LomBusinessFacade.getInstance().getAllAttributes()) { noAttributes.add(attribute.getJson()); } return noAttributes.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/class/{fullName}/attributes") public String getAttributesFromClass(@PathParam("fullName") String fullName) { Clazz clazz = LomBusinessFacade.getInstance().getClass(fullName); ArrayNode attributesNode = JsonNodeFactory.instance.arrayNode(); if (clazz != null) { List<Attribute> attributes = LomBusinessFacade.getInstance().getAttributesByClassID(clazz.getId()); for (Attribute attribute : attributes) { attributesNode.add(attribute.getJson()); } } return attributesNode.toString(); }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("/attribute") public Response addAttribute(String json) { try { ObjectNode attributeJson = (ObjectNode) jsonNodeFromString(json); Attribute attribute = LomBusinessFacade.getInstance().addAttribute(Attribute.attributeFromJson(attributeJson)); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(201); builder.entity(attribute.getJson().toString()); return builder.build(); } catch (Exception e) { return Response.notAcceptable(null).build(); } }
@POST @Path("/class/{fullName}/attributes") public Response addAttributeToClass(@PathParam("fullName") String fullName, String json) { Clazz clazz = LomBusinessFacade.getInstance().getClass(fullName); if (clazz != null) { try { ObjectNode attributeJson = (ObjectNode) jsonNodeFromString(json); Attribute attribute = Attribute.attributeFromJson(attributeJson); attribute.setClassID(clazz.getId()); attribute = LomBusinessFacade.getInstance().addAttribute(attribute); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(201); builder.entity(attribute.getJson().toString()); return builder.build(); } catch (Exception e) { return Response.notAcceptable(null).build(); } } return Response.notAcceptable(null).build(); }