@GET @Produces(MediaType.APPLICATION_JSON) @Path("/class/{fullName}/instances") public String getInstances(@PathParam("fullName") String fullName) { Clazz clazz = LomBusinessFacade.getInstance().getClass(fullName); ArrayNode instancesNode = JsonNodeFactory.instance.arrayNode(); if (clazz != null) { List<Instance> instances = LomBusinessFacade.getInstance().getInstancesByClassID(clazz.getId()); for (Instance instance : instances) { instancesNode.add(instance.getJson()); } } return instancesNode.toString(); }
@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(); } }
@POST @Path("/class/{fullName}/instances") public Response addInstanceToClass(@PathParam("fullName") String fullName, String json) { Clazz clazz = LomBusinessFacade.getInstance().getClass(fullName); if (clazz != null) { try { ObjectNode instanceJson = (ObjectNode) jsonNodeFromString(json); Instance instance = Instance.instanceFromJson(instanceJson); instance.setClassID(clazz.getId()); instance = LomBusinessFacade.getInstance().addInstance(instance); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(201); builder.entity(instance.getJson().toString()); return builder.build(); } catch (Exception e) { return Response.notAcceptable(null).build(); } } return Response.notAcceptable(null).build(); }