Search in sources :

Example 11 with GraphML

use of org.opennms.features.graphml.model.GraphML in project opennms by OpenNMS.

the class GraphMLRestService method createGraph.

@POST
@Path("{graph-name}")
public Response createGraph(@PathParam("graph-name") String graphname, GraphmlType graphmlType) throws IOException {
    return runWithGraphmlRepositoryBlock(graphmlRepository -> {
        if (graphmlRepository.exists(graphname)) {
            return Response.status(500).entity("Graph with name " + graphname + " already exists").build();
        }
        try {
            GraphML convertedGraphML = GraphMLReader.convert(graphmlType);
            String label = convertedGraphML.getProperty("label", graphname);
            graphmlRepository.save(graphname, label, graphmlType);
            return Response.status(Response.Status.CREATED).build();
        } catch (InvalidGraphException ex) {
            return Response.status(500).entity(ex.getMessage()).build();
        }
    });
}
Also used : GraphML(org.opennms.features.graphml.model.GraphML) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

GraphML (org.opennms.features.graphml.model.GraphML)11 Test (org.junit.Test)6 List (java.util.List)5 TestNodeProvider (org.opennms.features.topology.plugins.topo.asset.util.TestNodeProvider)5 ArrayList (java.util.ArrayList)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 File (java.io.File)3 NodeBuilder (org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder)3 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 GraphmlType (org.graphdrawing.graphml.GraphmlType)2 GraphMLEdge (org.opennms.features.graphml.model.GraphMLEdge)2 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)2 InvalidGraphException (org.opennms.features.graphml.model.InvalidGraphException)2 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1