@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(); }
@DELETE @Produces(MediaType.APPLICATION_JSON) @Path("/attribute/{id}") public Response deleteInstance(@PathParam("id") Long id) { if (LomBusinessFacade.getInstance().removeInstance(id)) return Response.ok().build(); 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(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/class") public String getClasses() { ArrayNode noClasses = JsonNodeFactory.instance.arrayNode(); for (Clazz clazz : LomBusinessFacade.getInstance().getAllClasses()) { noClasses.add(clazz.getJson()); } return noClasses.toString(); }
@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(); }
@POST @Path("/class") public Response addClass(String json) { try { ObjectNode clazzJson = (ObjectNode) jsonNodeFromString(json); Clazz clazz = LomBusinessFacade.getInstance().addClass(Clazz.clazzFromJson(clazzJson)); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(201); builder.entity(clazz.getJson().toString()); return builder.build(); } catch (Exception e) { return Response.notAcceptable(null).build(); } }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("/instance") public Response addInstance(String json) { try { ObjectNode instanceJson = (ObjectNode) jsonNodeFromString(json); Instance instance = LomBusinessFacade.getInstance().addInstance(Instance.instanceFromJson(instanceJson)); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(201); builder.entity(instance.getJson().toString()); return builder.build(); } catch (Exception e) { return Response.notAcceptable(null).build(); } }
@DELETE @Path("/class/{id}") public Response deleteClass(@PathParam("id") Long id) { if (LomBusinessFacade.getInstance().removeClass(id)) return Response.ok().build(); return Response.notAcceptable(null).build(); }
@DELETE @Path("/class") public Response deleteAllClasses() { LomBusinessFacade.getInstance().removeAllClasses(); return Response.ok().build(); }