EdgeResource extends AbstractSubResource { @DELETE @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.delete", absolute = true) public Response deleteEdge(@PathParam("graphname") String graphName, @PathParam("id") String id) { final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName); final Graph graph = rag.getGraph(); try { final List<String> keys = this.getNonRexsterRequestKeys(); final Edge edge = graph.getEdge(id); if (null != edge) { if (keys.size() > 0) { for (final String key : keys) { edge.removeProperty(key); } } else { graph.removeEdge(edge); } } else { final String msg = "Edge with id [" + id + "] cannot be found."; logger.info(msg); final JSONObject error = generateErrorObject(msg); throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(error).build()); } rag.tryCommit(); this.resultObject.put(Tokens.QUERY_TIME, sh.stopWatch()); } catch (JSONException ex) { logger.error(ex); rag.tryRollback(); final JSONObject error = generateErrorObjectJsonFail(ex); throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build()); } catch (WebApplicationException wae) { rag.tryRollback(); throw wae; } catch (Exception ex) { rag.tryRollback(); final JSONObject error = generateErrorObject("Transaction failed on DELETE of edge.", ex); throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build()); } return Response.ok(this.resultObject).build(); } EdgeResource();  EdgeResource(final UriInfo ui, final HttpServletRequest req, final RexsterApplication ra); @OPTIONS Response optionsAllEdges(); @GET @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.edges.collection.get", absolute = true) Response getAllEdges(@PathParam("graphname") final String graphName); @GET @Produces({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.collection.get", absolute = true) Response getAllEdgesRexsterTypedJson(@PathParam("graphname") final String graphName); @OPTIONS @Path("/{id}") Response optionsSingleEdge(); @GET @Path("/{id}") @Produces({MediaType.APPLICATION_JSON}) @Timed(name = "http.rest.edges.object.get", absolute = true) Response getSingleEdge(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @GET @Path("/{id}") @Produces({RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.edges.object.get", absolute = true) Response getSingleEdgeRexsterJson(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @GET @Path("/{id}") @Produces({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.get", absolute = true) Response getSingleEdgeRexsterTypedJson(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @HEAD @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_JSON) Response headEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final JSONObject json); @HEAD @Path("/{id}/{extension: .+}") Response headEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @PUT @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_JSON) @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final JSONObject json); @PUT @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final MultivaluedMap<String, String> formParams); @PUT @Path("/{id}/{extension: .+}") @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @OPTIONS @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_JSON) Response optionsEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final JSONObject json); @OPTIONS @Path("/{id}/{extension: .+}") Response optionsEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @DELETE @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_JSON) @Timed(name = "http.rest.edges.object.delete", absolute = true) Response deleteEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final JSONObject json); @DELETE @Path("/{id}/{extension: .+}") @Timed(name = "http.rest.edges.object.delete", absolute = true) Response deleteEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @POST @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_JSON) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final JSONObject json); @POST @Path("/{id}/{extension: .+}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id, final MultivaluedMap<String, String> formParams); @POST @Path("/{id}/{extension: .+}") @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @GET @Path("/{id}/{extension: .+}") @Timed(name = "http.rest.edges.object.get", absolute = true) Response getEdgeExtension(@PathParam("graphname") final String graphName, @PathParam("id") final String id); @POST @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postNullEdgeConsumesJson(@Context final Request request,
                                             @PathParam("graphname") final String graphName, final JSONObject json); @POST @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postNullEdgeConsumesTypedJson(@Context final Request request,
                                                  @PathParam("graphname") final String graphName, final JSONObject json); @POST @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postNullEdgeConsumesUri(@Context final Request request, @PathParam("graphname") final String graphName); @POST @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeConsumesJson(@Context final Request request,
                                         @PathParam("graphname") final String graphName,
                                         @PathParam("id") final String id, final JSONObject json); @POST @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeConsumesTypedJson(@Context final Request request,
                                              @PathParam("graphname") final String graphName,
                                              @PathParam("id") final String id, final JSONObject json); @POST @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.post", absolute = true) Response postEdgeConsumesUri(@Context final Request request,
                                        @PathParam("graphname") final String graphName,
                                        @PathParam("id") final String id); @PUT @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON}) @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeConsumesJson(@Context Request request, @PathParam("graphname") String graphName, @PathParam("id") String id, JSONObject json); @PUT @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Consumes({RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeConsumesTypedJson(@Context Request request, @PathParam("graphname") String graphName, @PathParam("id") String id, JSONObject json); @PUT @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.put", absolute = true) Response putEdgeOnUri(@Context Request request, @PathParam("graphname") String graphName, @PathParam("id") String id); @DELETE @Path("/{id}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.edges.object.delete", absolute = true) Response deleteEdge(@PathParam("graphname") String graphName, @PathParam("id") String id);  }
@Test(expected = WebApplicationException.class) public void deleteEdgeEdgeNotFound() { final EdgeResource resource = this.constructEdgeResourceWithToyGraph().getResource(); resource.deleteEdge(graphName, "100"); }
@Test public void deleteEdgeRemoveEdgeFromGraph() { Assert.assertNotNull(this.toyGraph.getEdge(12)); final EdgeResource resource = this.constructEdgeResourceWithToyGraph().getResource(); resource.deleteEdge(graphName, "12"); Assert.assertNull(this.toyGraph.getEdge(12)); }
@Test public void deleteEdgeRemovePropertyFromEdge() { final HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("to-delete", ""); final Vertex v1 = this.emptyGraph.addVertex(1); final Vertex v2 = this.emptyGraph.addVertex(2); final Edge e = this.emptyGraph.addEdge(1, v1, v2, "knows"); e.setProperty("to-delete", "get rid of me"); Assert.assertTrue(this.emptyGraph.getEdge(1).getPropertyKeys().contains("to-delete")); final ResourceHolder<EdgeResource> holder = this.constructEdgeResource(false, parameters); final EdgeResource resource = holder.getResource(); final Response response = resource.deleteEdge(graphName, "1"); Assert.assertFalse(this.emptyGraph.getEdge(1).getPropertyKeys().contains("to-delete")); }