summaryrefslogtreecommitdiffstats
path: root/verigraph/src/it/polito/verigraph/resources
diff options
context:
space:
mode:
Diffstat (limited to 'verigraph/src/it/polito/verigraph/resources')
-rw-r--r--verigraph/src/it/polito/verigraph/resources/GraphResource.java194
-rw-r--r--verigraph/src/it/polito/verigraph/resources/NeighbourResource.java146
-rw-r--r--verigraph/src/it/polito/verigraph/resources/NodeResource.java206
-rw-r--r--verigraph/src/it/polito/verigraph/resources/beans/VerificationBean.java65
4 files changed, 611 insertions, 0 deletions
diff --git a/verigraph/src/it/polito/verigraph/resources/GraphResource.java b/verigraph/src/it/polito/verigraph/resources/GraphResource.java
new file mode 100644
index 0000000..cae90e7
--- /dev/null
+++ b/verigraph/src/it/polito/verigraph/resources/GraphResource.java
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Politecnico di Torino and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+package it.polito.verigraph.resources;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+import javax.ws.rs.BeanParam;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.JAXBException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import it.polito.neo4j.exceptions.MyInvalidDirectionException;
+import it.polito.neo4j.exceptions.MyInvalidIdException;
+import it.polito.neo4j.exceptions.MyNotFoundException;
+import it.polito.verigraph.model.ErrorMessage;
+import it.polito.verigraph.model.Graph;
+import it.polito.verigraph.model.Node;
+import it.polito.verigraph.model.Verification;
+import it.polito.verigraph.resources.beans.VerificationBean;
+import it.polito.verigraph.service.GraphService;
+import it.polito.verigraph.service.VerificationService;
+
+@Path("/graphs")
+@Api(value = "/graphs", description = "Manage graphs")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class GraphResource {
+ GraphService graphService= new GraphService();
+ VerificationService verificationService= new VerificationService();
+
+ @GET
+ @ApiOperation(httpMethod = "GET",
+ value = "Returns all graphs",
+ notes = "Returns an array of graphs",
+ response = Graph.class,
+ responseContainer = "List")
+ @ApiResponses(value = { @ApiResponse(code = 200,
+ message = "All the graphs have been returned in the message body",
+ response = Graph.class,
+ responseContainer = "List"),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class)})
+ public List<Graph> getGraphs() throws JsonProcessingException, MyNotFoundException {
+ return graphService.getAllGraphs();
+ }
+
+ @POST
+ @ApiOperation(httpMethod = "POST",
+ value = "Creates a graph",
+ notes = "Creates a signle graph",
+ response = Response.class)
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid graph supplied", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 201, message = "Graph successfully created", response = Graph.class) })
+ public Response addGraph(@ApiParam(value = "New graph object", required = true) Graph graph,
+ @Context UriInfo uriInfo) throws JAXBException, JsonParseException, JsonMappingException, IOException, MyInvalidIdException {
+ Graph newGraph = graphService.addGraph(graph);
+ String newId = String.valueOf(newGraph.getId());
+ URI uri = uriInfo.getAbsolutePathBuilder().path(newId).build();
+ return Response.created(uri).entity(newGraph).build();
+ }
+
+ @GET
+ @Path("/{graphId}")
+ @ApiOperation(httpMethod = "GET",
+ value = "Returns a graph",
+ notes = "Returns a signle graph",
+ response = Graph.class)
+ @ApiResponses(value = {@ApiResponse(code = 403, message = "Invalid graph id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200,
+ message = "The requested graph has been returned in the message body",
+ response = Graph.class) })
+ public Graph getGraph(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @Context UriInfo uriInfo) throws JsonParseException, JsonMappingException, JAXBException, IOException {
+ Graph graph = graphService.getGraph(graphId);
+ graph.addLink(getUriForSelf(uriInfo, graph), "self");
+ graph.addLink(getUriForNodes(uriInfo, graph), "nodes");
+ return graph;
+ }
+
+ @PUT
+ @Path("/{graphId}")
+ @ApiOperation(httpMethod = "PUT", value = "Edits a graph", notes = "Edits a single graph", response = Graph.class)
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid graph object", response = ErrorMessage.class),
+ @ApiResponse(code = 403, message = "Invalid graph id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "Graph edited successfully", response = Graph.class) })
+ public Graph updateGraph(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long id,
+ @ApiParam(value = "Updated graph object", required = true) Graph graph) throws JAXBException, JsonParseException, JsonMappingException, IOException, MyInvalidIdException {
+ graph.setId(id);
+ return graphService.updateGraph(graph);
+ }
+
+ @DELETE
+ @Path("/{graphId}")
+ @ApiOperation(httpMethod = "DELETE", value = "Deletes a graph", notes = "Deletes a signle graph")
+ @ApiResponses(value = {@ApiResponse(code = 403, message = "Invalid graph id", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 204, message = "Graph successfully deleted") })
+ public void deleteGraph(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long id) {
+ graphService.removeGraph(id);
+ }
+
+ @GET
+ @Path("/{graphId}/policy")
+ @ApiOperation(httpMethod = "GET",
+ value = "Verifies a given policy in a graph",
+ notes = "In order to verify a given policy (e.g. 'reachability') all nodes of the desired graph must have a valid configuration.")
+ @ApiResponses(value = {@ApiResponse(code = 403,
+ message = "Invalid graph id or invalid configuration for source and/or destination node",
+ response = ErrorMessage.class),
+ @ApiResponse(code = 404,
+ message = "Graph not found or source node not found or destination node not found or configuration for source and/or destination node not available",
+ response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),})
+ public Verification verifyGraph(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "'source' and 'destination' must refer to names of existing nodes in the same graph, 'type' refers to the required verification between the two (e.g. 'reachability')",
+ required = true) @BeanParam VerificationBean verificationBean) throws MyInvalidDirectionException, JsonParseException, JsonMappingException, JAXBException, IOException {
+
+ return verificationService.verify(graphId, verificationBean);
+ }
+
+ private String getUriForSelf(UriInfo uriInfo, Graph graph) {
+ String uri = uriInfo.getBaseUriBuilder()
+ .path(GraphResource.class)
+ .path(Long.toString(graph.getId()))
+ .build()
+ .toString();
+ return uri;
+ }
+
+ @GET
+ @Path("/{graphId}/paths")
+ @ApiOperation(httpMethod = "GET",value = "Retrieve all paths between two nodes")
+ @ApiResponses(value = {@ApiResponse(code = 403,
+ message = "Invalid graph id or invalid configuration for source and/or destination node",
+ response = ErrorMessage.class),
+ @ApiResponse(code = 404,
+ message = "Graph not found or source node not found or destination node not found or configuration for source and/or destination node not available",
+ response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),})
+
+ public List<List<Node>> getPaths(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "'source' must refer to name of existing nodes in the same graph",
+ required = true) @QueryParam("source") String srcName,
+ @ApiParam(value = "'destination' must refer to name of existing nodes in the same graph",
+ required = true)@QueryParam("destination") String dstName) throws MyInvalidDirectionException, JsonParseException, JsonMappingException, JAXBException, IOException {
+
+ return verificationService.getPaths(graphId, srcName, dstName);
+ }
+
+ private String getUriForNodes(UriInfo uriInfo, Graph graph) {
+ String uri = uriInfo.getBaseUriBuilder()
+ .path(GraphResource.class)
+ .path(GraphResource.class, "getNodeResource")
+ // .path(NodeResource.class)
+ .resolveTemplate("graphId", graph.getId())
+ .build()
+ .toString();
+ return uri;
+ }
+
+ @Path("/{graphId}/nodes")
+ public NodeResource getNodeResource() {
+ return new NodeResource();
+ }
+} \ No newline at end of file
diff --git a/verigraph/src/it/polito/verigraph/resources/NeighbourResource.java b/verigraph/src/it/polito/verigraph/resources/NeighbourResource.java
new file mode 100644
index 0000000..3758f6b
--- /dev/null
+++ b/verigraph/src/it/polito/verigraph/resources/NeighbourResource.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Politecnico di Torino and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+package it.polito.verigraph.resources;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.JAXBException;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import it.polito.verigraph.model.ErrorMessage;
+import it.polito.verigraph.model.Neighbour;
+import it.polito.verigraph.service.NeighbourService;
+
+//@Path("/")
+@Api( hidden= true, value = "", description = "Manage neighbours" )
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class NeighbourResource {
+ private NeighbourService neighboursService = new NeighbourService();
+
+ @GET
+ @ApiOperation(
+ httpMethod = "GET",
+ value = "Returns all neighbours of a given node belonging to a given graph",
+ notes = "Returns an array of neighbours of a given node belonging to a given graph",
+ response = Neighbour.class,
+ responseContainer = "List")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node id", response=ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response=ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "All the neighbours have been returned in the message body", response=Neighbour.class, responseContainer="List")})
+ public List<Neighbour> getAllNeighbours(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId) throws JsonProcessingException{
+ return neighboursService.getAllNeighbours(graphId, nodeId);
+ }
+
+ @POST
+ @ApiOperation(
+ httpMethod = "POST",
+ value = "Adds a neighbour to a given node belonging to a given graph",
+ notes = "Adds single neighbour to a given node belonging to a given graph",
+ response = Neighbour.class)
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node id", response=ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response=ErrorMessage.class),
+ @ApiResponse(code = 400, message = "Invalid neighbour object", response=ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 201, message = "Neighbour successfully created", response=Neighbour.class)})
+ public Response addNeighbour(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "New neighbour object. Neighbour name must refer to the name of an existing node of the same graph", required = true) Neighbour neighbour,
+ @Context UriInfo uriInfo) throws JsonParseException, JsonMappingException, JAXBException, IOException{
+ Neighbour newNeighbour = neighboursService.addNeighbour(graphId, nodeId, neighbour);
+ String newId = String.valueOf(newNeighbour.getId());
+ URI uri = uriInfo.getAbsolutePathBuilder().path(newId).build();
+ return Response.created(uri)
+ .entity(newNeighbour)
+ .build();
+ }
+
+ @PUT
+ @Path("{neighbourId}")
+ @ApiOperation(
+ httpMethod = "PUT",
+ value = "Edits a neighbour of a given node belonging to a given graph",
+ notes = "Edits a single neighbour of a given node belonging to a given graph",
+ response = Neighbour.class)
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node and/or neighbour id", response=ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node and /or neighbour not found", response=ErrorMessage.class),
+ @ApiResponse(code = 400, message = "Invalid neighbour object", response=ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "Neighbour edited successfully", response=Neighbour.class)})
+ public Neighbour updateNeighbour(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "Neighbour id", required = true) @PathParam("neighbourId") long neighbourId,
+ @ApiParam(value = "Updated neighbour object. Neighbour name must refer to the name of an existing node of the same graph", required = true) Neighbour neighbour) throws JAXBException, IOException{
+ neighbour.setId(neighbourId);
+ return neighboursService.updateNeighbour(graphId, nodeId, neighbour);
+ }
+
+ @DELETE
+ @Path("{neighbourId}")
+ @ApiOperation(
+ httpMethod = "DELETE",
+ value = "Removes a neighbour from a given node belonging to a given graph",
+ notes = "Deletes a single neighbour of a given node belonging to a given graph",
+ response = Neighbour.class)
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node and/or neighbour id", response=ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response=ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 204, message = "Node successfully deleted")})
+ public void deleteNeighbour(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "Neighbour id", required = true) @PathParam("neighbourId") long neighbourId){
+ neighboursService.removeNeighbour(graphId, nodeId, neighbourId);
+ }
+
+ @GET
+ @Path("{neighbourId}")
+ @ApiOperation(
+ httpMethod = "GET",
+ value = "Returns a neighbour of a given node belonging to a given graph",
+ notes = "Returns a single neighbour of a given node belonging to a given graph",
+ response = Neighbour.class)
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node and/or neighbour id", response=ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node and /or neighbour not found", response=ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "The requested neighbour has been returned in the message body", response=Neighbour.class)})
+ public Neighbour getNeighbour(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "Neighbour id", required = true) @PathParam("neighbourId") long neighbourId) throws JsonProcessingException{
+ return neighboursService.getNeighbour(graphId, nodeId, neighbourId);
+ }
+}
diff --git a/verigraph/src/it/polito/verigraph/resources/NodeResource.java b/verigraph/src/it/polito/verigraph/resources/NodeResource.java
new file mode 100644
index 0000000..9fa7319
--- /dev/null
+++ b/verigraph/src/it/polito/verigraph/resources/NodeResource.java
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Politecnico di Torino and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+package it.polito.verigraph.resources;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.JAXBException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import it.polito.neo4j.exceptions.MyInvalidIdException;
+import it.polito.neo4j.exceptions.MyNotFoundException;
+import it.polito.neo4j.manager.Neo4jDBManager;
+import it.polito.verigraph.exception.BadRequestException;
+import it.polito.verigraph.exception.ForbiddenException;
+import it.polito.verigraph.model.Configuration;
+import it.polito.verigraph.model.ErrorMessage;
+import it.polito.verigraph.model.Graph;
+import it.polito.verigraph.model.Neighbour;
+import it.polito.verigraph.model.Node;
+import it.polito.verigraph.service.GraphService;
+import it.polito.verigraph.service.NodeService;
+
+@Api( hidden= true, value = "", description = "Manage nodes" )
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class NodeResource {
+
+ NodeService nodeService = new NodeService();
+
+ @GET
+ @ApiOperation(
+ httpMethod = "GET",
+ value = "Returns all nodes of a given graph",
+ notes = "Returns an array of nodes belonging to a given graph",
+ response = Node.class,
+ responseContainer = "List")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "All the nodes have been returned in the message body", response = Node.class, responseContainer = "List") })
+ public List<Node> getNodes(@ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId) throws JsonParseException, JsonMappingException, JAXBException, IOException, MyNotFoundException{
+ return nodeService.getAllNodes(graphId);
+ }
+
+ @POST
+ @ApiOperation(
+ httpMethod = "POST",
+ value = "Creates a node in a given graph",
+ notes = "Creates a single node for a given graph",
+ response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid node supplied", response = ErrorMessage.class),
+ @ApiResponse(code = 403, message = "Invalid graph id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 201, message = "Node successfully created", response = Node.class)})
+ public Response addNode(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "New node object", required = true) Node node,
+ @Context UriInfo uriInfo) throws JsonParseException, JsonMappingException, JAXBException, IOException, MyInvalidIdException {
+ Node newNode = nodeService.addNode(graphId, node);
+ String newId = String.valueOf(newNode.getId());
+ URI uri = uriInfo.getAbsolutePathBuilder().path(newId).build();
+ return Response.created(uri)
+ .entity(newNode)
+ .build();
+ }
+
+ @GET
+ @Path("{nodeId}")
+ @ApiOperation(
+ httpMethod = "GET",
+ value = "Returns a node of a given graph",
+ notes = "Returns a single node of a given graph",
+ response = Node.class)
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "The requested node has been returned in the message body", response = Node.class)})
+ public Node getNode(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @Context UriInfo uriInfo) throws JsonParseException, JsonMappingException, JAXBException, IOException, MyNotFoundException{
+ Node node = nodeService.getNode(graphId, nodeId);
+ node.addLink(getUriForSelf(uriInfo, graphId, node), "self");
+ node.addLink(getUriForNeighbours(uriInfo, graphId, node), "neighbours");
+ return node;
+ }
+
+ @PUT
+ @Path("{nodeId}/configuration")
+ @ApiOperation(
+ httpMethod = "PUT",
+ value = "Adds/edits a configuration to a node of a given graph",
+ notes = "Configures a node. Once all the nodes of a graph have been configured a given policy can be verified for the graph (e.g. 'reachability' between two nodes).")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "Configuration updated for the requested node", response=Configuration.class)})
+ public Configuration addNodeConfiguration(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "Node configuration", required = true) Configuration nodeConfiguration,
+ @Context UriInfo uriInfo) throws JsonParseException, JsonMappingException, JAXBException, IOException, MyNotFoundException, MyInvalidIdException{
+
+ Configuration conf=nodeService.addNodeConfiguration(graphId, nodeId, nodeConfiguration);
+ return conf;
+
+ }
+
+
+ @PUT
+ @Path("{nodeId}")
+ @ApiOperation(
+ httpMethod = "PUT",
+ value = "Edits a node of a given graph",
+ notes = "Edits a single node of a given graph",
+ response = Node.class)
+ @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid node object", response = ErrorMessage.class),
+ @ApiResponse(code = 403, message = "Invalid graph and/or node id", response = ErrorMessage.class),
+ @ApiResponse(code = 404, message = "Graph and/or node not found", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 200, message = "Node edited successfully", response = Node.class)})
+ public Node updateNode(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId,
+ @ApiParam(value = "Updated node object", required = true) Node node) throws JAXBException, IOException, MyInvalidIdException{
+ node.setId(nodeId);
+ return nodeService.updateNode(graphId, node);
+ }
+
+ @DELETE
+ @Path("{nodeId}")
+ @ApiOperation(
+ httpMethod = "DELETE",
+ value = "Deletes a node of a given graph",
+ notes = "Deletes a single node of a given graph")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Invalid graph and/or node id", response = ErrorMessage.class),
+ @ApiResponse(code = 500, message = "Internal server error", response = ErrorMessage.class),
+ @ApiResponse(code = 204, message = "Node successfully deleted")})
+ public void deleteNode(
+ @ApiParam(value = "Graph id", required = true) @PathParam("graphId") long graphId,
+ @ApiParam(value = "Node id", required = true) @PathParam("nodeId") long nodeId) throws JsonParseException, JsonMappingException, JAXBException, IOException{
+ nodeService.removeNode(graphId, nodeId);
+ }
+
+ private String getUriForSelf(UriInfo uriInfo, long graphId, Node node) {
+ String uri = uriInfo.getBaseUriBuilder()
+ //.path(NodeResource.class)
+ .path(GraphResource.class)
+ .path(GraphResource.class, "getNodeResource")
+ .resolveTemplate("graphId", graphId)
+ .path(Long.toString(node.getId()))
+ .build()
+ .toString();
+ return uri;
+ }
+
+ private String getUriForNeighbours(UriInfo uriInfo, long graphId, Node node) {
+ String uri = uriInfo.getBaseUriBuilder()
+ .path(GraphResource.class)
+ .path(GraphResource.class, "getNodeResource")
+ .resolveTemplate("graphId", graphId)
+ .path(Long.toString(node.getId()))
+ .path("neighbours")
+ .build()
+ .toString();
+ // .path(NodeResource.class)
+ // .path(NodeResource.class, "getNeighbourResource")
+ // .path(NeighbourResource.class)
+ // .resolveTemplate("nodeId", node.getId())
+ // .build()
+ // .toString();
+ return uri;
+ }
+
+ @Path("{nodeId}/neighbours")
+ public NeighbourResource getNeighbourResource(){
+ return new NeighbourResource();
+ }
+} \ No newline at end of file
diff --git a/verigraph/src/it/polito/verigraph/resources/beans/VerificationBean.java b/verigraph/src/it/polito/verigraph/resources/beans/VerificationBean.java
new file mode 100644
index 0000000..619ee46
--- /dev/null
+++ b/verigraph/src/it/polito/verigraph/resources/beans/VerificationBean.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Politecnico di Torino and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+package it.polito.verigraph.resources.beans;
+
+import javax.ws.rs.QueryParam;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("Verification")
+public class VerificationBean {
+
+ @ApiModelProperty(example = "webclient", value = "Source node. Must refer to an existing node of the same graph")
+ private @QueryParam("source") String source;
+
+ @ApiModelProperty(example = "webserver",
+ value = "Destination node. Must refer to an existing node of the same graph")
+ private @QueryParam("destination") String destination;
+
+ @ApiModelProperty(example = "reachability",
+ value = "Verification policy ('reachability', 'isolation', 'traversal')")
+ private @QueryParam("type") String type;
+
+ @ApiModelProperty(example = "firewall",
+ value = "Absent if verification type is 'reachability', equal to the name of a middlebox to be avoided if verification type is 'isolation', equal to the name of a middlebox to be traversed if verification type is 'traversal'")
+ private @QueryParam("middlebox") String middlebox;
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getDestination() {
+ return destination;
+ }
+
+ public void setDestination(String destination) {
+ this.destination = destination;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getMiddlebox() {
+ return middlebox;
+ }
+
+ public void setMiddlebox(String middlebox) {
+ this.middlebox = middlebox;
+ }
+
+} \ No newline at end of file