Examples of DendriteGraphTx


Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

        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

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

                throw new NotFound(GraphMetadata.class, graphId);
            }

            DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);

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

            try {
                Map<Object, Object> verticesMap = new HashMap<>();
                Map<Object, Object> edgesMap = new HashMap<>();

                for (Vertex vertex : dendriteGraphTx.query().limit(300).vertices()) {
                    addVertex(verticesMap, vertex);
                }

                for (Edge edge : dendriteGraphTx.query().limit(300).edges()) {
                    addEdge(verticesMap, edgesMap, edge);
                }

                response.put("vertices", new ArrayList<>(verticesMap.values()));
                response.put("edges", new ArrayList<>(edgesMap.values()));
            } finally {
                dendriteGraphTx.commit();
            }

            return new ResponseEntity<>(response, HttpStatus.OK);
        } finally {
            tx.commit();
View Full Code Here

Examples of org.lab41.dendrite.metagraph.DendriteGraphTx

    protected void copyIndices(DendriteGraph srcGraph, DendriteGraph dstGraph) {
        // This is very much a hack, but unfortunately Titan does not yet expose a proper way to copy indices from
        // one graph to another.

        TitanTransaction srcTx = srcGraph.newTransaction();
        DendriteGraphTx dstTx = dstGraph.newTransaction();

        for(TitanKey titanKey: srcTx.getTypes(TitanKey.class)) {
            if (titanKey instanceof TitanKeyVertex) {
                TitanKeyVertex keyVertex = (TitanKeyVertex) titanKey;
                TypeAttribute.Map definition = getDefinition(keyVertex);
                if (dstTx.getType(keyVertex.getName()) == null) {
                    dstTx.makePropertyKey(keyVertex.getName(), definition);
                }
            }
        }

        for(TitanLabel titanLabel: srcTx.getTypes(TitanLabel.class)) {
            TitanLabelVertex keyVertex = (TitanLabelVertex) titanLabel;
            TypeAttribute.Map definition = getDefinition(keyVertex);
            if (dstTx.getType(keyVertex.getName()) == null) {
                dstTx.makeEdgeLabel(keyVertex.getName(), definition);
            }
        }

        dstTx.commit();
        srcTx.commit();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.