Package org.lab41.dendrite.metagraph

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx


    @RequestMapping(value = "/api/graphs/{graphId}/analysis/{algorithm}", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Object>> startJob(@PathVariable String graphId, @PathVariable String algorithm) throws Exception {

        Map<String, Object> response = new HashMap<>();

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "missing graph metadata '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }
View Full Code Here


    @RequestMapping(value = "/api/graphs/{graphId}/analysis/titan-degrees", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Object>> startJob(@PathVariable String graphId) throws Exception {

        Map<String, Object> response = new HashMap<>();

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "missing graph metadata '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }
View Full Code Here

    @RequestMapping(value = "/api/graphs/{graphId}/analysis/faunus-degrees", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Object>> startFaunusJob(@PathVariable String graphId) throws Exception {

        Map<String, Object> response = new HashMap<>();

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "missing graph metadata '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }
View Full Code Here

    @RequestMapping(value = "/api/graphs/{graphId}/analysis/snap/{algorithm}", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Object>> startJob(@PathVariable String graphId, @PathVariable String algorithm) throws Exception {

        Map<String, Object> response = new HashMap<>();

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "missing graph metadata '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }
View Full Code Here

        String format = item.getFormat();
        HttpHeaders headers = new HttpHeaders();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

        DendriteGraphTx tx = graph.buildTransaction().readOnly().start();

        try {
            if (format.equalsIgnoreCase("GraphSON")) {
                headers.setContentType(new MediaType("application", "vnd.rexster+json"));
                headers.set("Content-Disposition", "attachment; filename=\"graph.json\"");

                GraphSONWriter.outputGraph(tx, byteArrayOutputStream);
            } else if (format.equalsIgnoreCase("GraphML")) {
                headers.setContentType(new MediaType("application", "vnd.rexster+xml"));
                headers.set("Content-Disposition", "attachment; filename=\"graph.xml\"");

                GraphMLWriter.outputGraph(tx, byteArrayOutputStream);
            } else if (format.equalsIgnoreCase("GML")) {
                headers.setContentType(new MediaType("application", "vnd.rexster+gml"));
                headers.set("Content-Disposition", "attachment; filename=\"graph.gml\"");

                GMLWriter.outputGraph(tx, byteArrayOutputStream);
            } else {
                tx.rollback();

                return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
            }
        } catch (IOException e) {
            tx.rollback();

            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }

        tx.commit();

        return new ResponseEntity<>(byteArrayOutputStream.toByteArray(), headers, HttpStatus.OK);
    }
View Full Code Here

        logger.debug("saving graph '" + graphId + "'");

        // extract the storage location for the history
        String format = item.getFormat();

        DendriteGraphTx tx = graph.buildTransaction().readOnly().start();

        try {
            try {
                String path;

                if (format.equalsIgnoreCase("GraphSON")) {
                    path = new File(git.getRepository().getWorkTree(), graphId + ".json").getPath();
                    GraphSONWriter.outputGraph(tx, path);
                } else if (format.equalsIgnoreCase("GraphML")) {
                    path = new File(git.getRepository().getWorkTree(), graphId + ".xml").getPath();
                    GraphMLWriter.outputGraph(tx, path);
                } else if (format.equalsIgnoreCase("GML")) {
                    path = new File(git.getRepository().getWorkTree(), graphId + ".gml").getPath();
                    GMLWriter.outputGraph(tx, path);
                } else {
                    tx.rollback();

                    response.put("status", "error");
                    response.put("msg", "unknown format '" + format + "'");
                    return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
                }

                git.add()
                        .addFilepattern(".")
                        .call();

                git.commit()
                        .setAuthor(authentication.getName(), "")
                        .setMessage("commit")
                        .call();
            } finally {
                git.close();
            }
        } catch (IOException e) {
            tx.rollback();

            response.put("status", "error");
            response.put("msg", "exception: " + e.toString());
            return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
        }

        tx.commit();

        response.put("status", "ok");

        return new ResponseEntity<>(response, HttpStatus.NO_CONTENT);
    }
View Full Code Here

        srcGraphId = srcGraphMetadata.getId();
        dstGraphId = dstGraphMetadata.getId();
        jobId = jobMetadata.getId();
        srcGraph = metaGraph.getGraph(srcGraphMetadata.getId());

        DendriteGraphTx srcTx;

        srcTx = srcGraph.newTransaction();
        try {
            srcTx.makeKey("name")
                    .dataType(String.class)
                    .indexed("search", Vertex.class, Parameter.of(Mapping.MAPPING_PREFIX, Mapping.STRING))
                    .make();
            srcTx.makeKey("age")
                    .dataType(Integer.class)
                    .indexed("search", Vertex.class)
                    .make();
            srcTx.makeLabel("friends").make();
            srcTx.makeLabel("enemies").make();
        } finally {
            srcTx.commit();
        }

        // Create a trivial graph.
        srcTx = srcGraph.newTransaction();
        try {
            Vertex srcAVertex = srcTx.addVertex(null);
            srcAVertex.setProperty("name", "A");
            srcAVertex.setProperty("age", 42);

            Vertex srcBVertex = srcTx.addVertex(null);
            srcBVertex.setProperty("name", "B");
            srcBVertex.setProperty("age", 50);

            Vertex srcCVertex = srcTx.addVertex(null);
            srcCVertex.setProperty("name", "C");
            srcCVertex.setProperty("age", 36);

            Vertex srcDVertex = srcTx.addVertex(null);
            srcDVertex.setProperty("name", "D");
            srcDVertex.setProperty("age", 10);

            srcTx.addEdge(null, srcAVertex, srcBVertex, "friends");
            srcTx.addEdge(null, srcBVertex, srcCVertex, "enemies");
            srcTx.addEdge(null, srcCVertex, srcDVertex, "friends");
        } finally {
            srcTx.commit();
        }
    }
View Full Code Here

        branchCommitSubsetJob.run();

        DendriteGraph dstGraph = metaGraph.getGraph(branchCommitSubsetJob.getDstGraphId());
        Assert.assertNotNull(dstGraph);

        DendriteGraphTx dstTx = dstGraph.newTransaction();

        try {
            Vertex dstAVertex = dstTx.getVertices("name", "A").iterator().next();
            Assert.assertNotNull(dstAVertex);
            Assert.assertEquals(dstAVertex.getProperty("name"), "A");
            Assert.assertEquals(dstAVertex.getProperty("age"), 42);

            Assert.assertFalse(dstAVertex.getEdges(Direction.BOTH).iterator().hasNext());

            Assert.assertFalse(dstTx.getVertices("name", "B").iterator().hasNext());
            Assert.assertFalse(dstTx.getVertices("name", "C").iterator().hasNext());
            Assert.assertFalse(dstTx.getVertices("name", "D").iterator().hasNext());
        } finally {
            dstTx.commit();
        }
    }
View Full Code Here

        branchCommitSubsetJob.run();

        DendriteGraph dstGraph = metaGraph.getGraph(branchCommitSubsetJob.getDstGraphId());
        Assert.assertNotNull(dstGraph);

        DendriteGraphTx dstTx = dstGraph.newTransaction();

        try {
            Vertex dstAVertex = dstTx.getVertices("name", "A").iterator().next();
            Assert.assertNotNull(dstAVertex);
            Assert.assertEquals(dstAVertex.getProperty("name"), "A");
            Assert.assertEquals(dstAVertex.getProperty("age"), 42);

            Vertex dstBVertex = dstTx.getVertices("name", "B").iterator().next();
            Assert.assertNotNull(dstBVertex);
            Assert.assertEquals(dstBVertex.getProperty("name"), "B");
            Assert.assertEquals(dstBVertex.getProperty("age"), 50);

            Edge dstABEdge = dstAVertex.getEdges(Direction.OUT).iterator().next();
            Assert.assertNotNull(dstABEdge);
            Assert.assertEquals(dstABEdge.getLabel(), "friends");

            Assert.assertFalse(dstBVertex.getEdges(Direction.OUT).iterator().hasNext());

            Assert.assertFalse(dstTx.getVertices("name", "C").iterator().hasNext());
            Assert.assertFalse(dstTx.getVertices("name", "D").iterator().hasNext());
        } finally {
            dstTx.commit();
        }
    }
View Full Code Here

        branchCommitSubsetJob.run();

        DendriteGraph dstGraph = metaGraph.getGraph(branchCommitSubsetJob.getDstGraphId());
        Assert.assertNotNull(dstGraph);

        DendriteGraphTx dstTx = dstGraph.newTransaction();

        try {
            Vertex dstAVertex = dstTx.getVertices("name", "A").iterator().next();
            Assert.assertNotNull(dstAVertex);
            Assert.assertEquals(dstAVertex.getProperty("name"), "A");
            Assert.assertEquals(dstAVertex.getProperty("age"), 42);

            Vertex dstBVertex = dstTx.getVertices("name", "B").iterator().next();
            Assert.assertNotNull(dstBVertex);
            Assert.assertEquals(dstBVertex.getProperty("name"), "B");
            Assert.assertEquals(dstBVertex.getProperty("age"), 50);

            Edge dstABEdge = dstAVertex.getEdges(Direction.OUT).iterator().next();
            Assert.assertNotNull(dstABEdge);
            Assert.assertEquals(dstABEdge.getLabel(), "friends");

            Vertex dstCVertex = dstTx.getVertices("name", "C").iterator().next();
            Assert.assertNotNull(dstCVertex);
            Assert.assertEquals(dstCVertex.getProperty("name"), "C");
            Assert.assertEquals(dstCVertex.getProperty("age"), 36);

            Edge dstBCEdge = dstBVertex.getEdges(Direction.OUT).iterator().next();
            Assert.assertNotNull(dstBCEdge);
            Assert.assertEquals(dstBCEdge.getLabel(), "enemies");

            Assert.assertFalse(dstCVertex.getEdges(Direction.OUT).iterator().hasNext());

            Assert.assertFalse(dstTx.getVertices("name", "D").iterator().hasNext());
        } finally {
            dstTx.commit();
        }
    }
View Full Code Here

TOP

Related Classes of org.lab41.dendrite.metagraph.DendriteGraphTx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.