Package org.lab41.dendrite.metagraph

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


    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

    @PreAuthorize("hasPermission(#branchId, 'branch', 'admin')")
    @RequestMapping(value = "/api/branches/{branchId}/search", method = RequestMethod.POST)
    public ResponseEntity<String> branchSearch(@PathVariable String branchId,
                                               @RequestBody String body) throws JSONException, UnsupportedEncodingException {

        MetaGraphTx tx = metaGraphService.newTransaction();

        try {
            BranchMetadata branchMetadata = tx.getBranch(branchId);
            if (branchMetadata == null) {
                HttpHeaders responseHeaders = new HttpHeaders();
                responseHeaders.setContentType(MediaType.APPLICATION_JSON);

                JSONObject json = new JSONObject();
                json.put("status", "error");
                json.put("msg", "unknown branch '" + branchId + "'");

                return new ResponseEntity<>(json.toString(), responseHeaders, HttpStatus.BAD_REQUEST);
            }

            GraphMetadata graphMetadata = branchMetadata.getGraph();
            if (graphMetadata == null) {
                HttpHeaders responseHeaders = new HttpHeaders();
                responseHeaders.setContentType(MediaType.APPLICATION_JSON);

                JSONObject json = new JSONObject();
                json.put("status", "error");
                json.put("msg", "branch '" + branchId + "' does not point at a graph!");

                return new ResponseEntity<>(json.toString(), responseHeaders, HttpStatus.BAD_REQUEST);
            }

            return graphSearch(graphMetadata.getId().toString(), body);
        } finally {
            tx.rollback();
        }
    }
View Full Code Here

    @PreAuthorize("hasPermission(#branchId, 'branch', 'admin')")
    @RequestMapping(value = "/api/branches/{branchId}/search/mapping", method = RequestMethod.GET)
    public ResponseEntity<Map<String, Object>> branchMapping(@PathVariable String branchId) throws JSONException, IOException {

        MetaGraphTx tx = metaGraphService.newTransaction();

        try {
            BranchMetadata branchMetadata = tx.getBranch(branchId);
            if (branchMetadata == null) {
                Map<String, Object> response = new HashMap<>();
                response.put("status", "error");
                response.put("msg", "unknown branch '" + branchId + "'");

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

            GraphMetadata graphMetadata = branchMetadata.getGraph();
            if (graphMetadata == null) {
                Map<String, Object> response = new HashMap<>();
                response.put("status", "error");
                response.put("msg", "branch '" + branchId + "' does not point at a graph!");

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

            return graphMapping(graphMetadata.getId());
        } finally {
            tx.rollback();
        }
    }
View Full Code Here

    @PreAuthorize("hasPermission(#projectId, 'project', 'admin')")
    @RequestMapping(value = "/projects/{projectId}/current-branch", method = RequestMethod.GET)
    @ResponseBody
    public GetBranchResponse getCurrentBranch(@PathVariable String projectId) throws NotFound {

        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            BranchMetadata branchMetadata = projectMetadata.getCurrentBranch();
            if (branchMetadata == null) {
                throw new NotFound(BranchController.class);
            }

            return new GetBranchResponse(branchMetadata);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

            throw new BindingException(result);
        }

        String branchName = item.getBranchName();

        MetaGraphTx tx = metaGraphService.newTransaction();

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            BranchMetadata branchMetadata = projectMetadata.getBranchByName(branchName);
            if (branchMetadata == null) {
                throw new NotFound(BranchController.class, branchName);
            }

            projectMetadata.setCurrentBranch(branchMetadata);

            Git git = historyService.projectGitRepository(projectMetadata);
            try {
                git.checkout()
                        .setName(branchName)
                        .call();
            } finally {
                git.close();
            }
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        // Commit must come after all branch access.
        tx.commit();

        return new SetCurrentBranchResponse();
    }
View Full Code Here

    @RequestMapping(value = "/projects/{projectId}/current-branch/commit", method = RequestMethod.POST)
    @ResponseBody
    public BranchJobResponse commitBranch(@PathVariable String projectId) throws GitAPIException, IOException, NotFound {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        MetaGraphTx tx = metaGraphService.newTransaction();
        BranchCommitJob branchCommitJob;

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            BranchMetadata branchMetadata = projectMetadata.getCurrentBranch();
            if (branchMetadata == null) {
                throw new NotFound(BranchMetadata.class);
            }

            GraphMetadata srcGraphMetadata = branchMetadata.getGraph();
            if (srcGraphMetadata == null) {
                throw new NotFound(GraphMetadata.class);
            }

            GraphMetadata dstGraphMetadata = tx.createGraph(srcGraphMetadata);

            JobMetadata jobMetadata = tx.createJob(projectMetadata);

            Git git = historyService.projectGitRepository(projectMetadata);
            try {
                git.commit()
                        .setAuthor(authentication.getName(), "")
                        .setMessage("commit")
                        .call();
            } finally {
                git.close();
            }

            // We can't pass the values directly because they'll live in a separate thread.
            branchCommitJob = new BranchCommitJob(
                    metaGraphService.getMetaGraph(),
                    jobMetadata.getId(),
                    projectMetadata.getId(),
                    branchMetadata.getId(),
                    srcGraphMetadata.getId(),
                    dstGraphMetadata.getId());

        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        //taskExecutor.execute(branchCommitJob);
        branchCommitJob.run();

        return new BranchJobResponse(branchCommitJob);
View Full Code Here

        }

        String query = item.getQuery();
        int steps = item.getSteps();

        MetaGraphTx tx = metaGraphService.newTransaction();
        BranchCommitSubsetJob branchCommitSubsetJob;

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            BranchMetadata branchMetadata = projectMetadata.getCurrentBranch();
            if (branchMetadata == null) {
                throw new NotFound(BranchMetadata.class);
            }

            GraphMetadata srcGraphMetadata = branchMetadata.getGraph();
            if (srcGraphMetadata == null) {
                throw new NotFound(GraphMetadata.class);
            }

            GraphMetadata dstGraphMetadata = tx.createGraph(srcGraphMetadata);

            JobMetadata jobMetadata = tx.createJob(projectMetadata);

            // We can't pass the values directly because they'll live in a separate thread.
            branchCommitSubsetJob = new BranchCommitSubsetJob(
                    metaGraphService.getMetaGraph(),
                    jobMetadata.getId(),
                    projectMetadata.getId(),
                    branchMetadata.getId(),
                    srcGraphMetadata.getId(),
                    dstGraphMetadata.getId(),
                    query,
                    steps);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        //taskExecutor.execute(branchCommitSubsetJob);
        branchCommitSubsetJob.run();

        return new BranchJobResponse(branchCommitSubsetJob);
View Full Code Here

        String name = item.getName();
        String query = item.getQuery();
        int steps = item.getSteps();

        MetaGraphTx tx = metaGraphService.newTransaction();
        BranchCommitSubsetJob branchCommitSubsetJob;

        try {
            UserMetadata userMetadata = tx.getOrCreateUser(principal);
            if (userMetadata == null) {
                throw new NotFound(UserMetadata.class, principal.getName());
            }

            ProjectMetadata srcProjectMetadata = tx.getProject(projectId);
            if (srcProjectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            BranchMetadata srcBranchMetadata = srcProjectMetadata.getCurrentBranch();
            if (srcBranchMetadata == null) {
                throw new NotFound(BranchMetadata.class);
            }

            GraphMetadata srcGraphMetadata = srcBranchMetadata.getGraph();
            if (srcGraphMetadata == null) {
                throw new NotFound(GraphMetadata.class);
            }

            ProjectMetadata dstProjectMetadata = tx.createProject(name, userMetadata);

            BranchMetadata dstBranchMetadata = dstProjectMetadata.getCurrentBranch();
            if (dstBranchMetadata == null) {
                throw new NotFound(BranchMetadata.class);
            }

            GraphMetadata dstGraphMetadata = dstBranchMetadata.getGraph();
            if (dstGraphMetadata == null) {
                throw new NotFound(GraphMetadata.class);
            }

            JobMetadata jobMetadata = tx.createJob(srcProjectMetadata);

            // We can't pass the values directly because they'll live in a separate thread.
            branchCommitSubsetJob = new BranchCommitSubsetJob(
                    metaGraphService.getMetaGraph(),
                    jobMetadata.getId(),
                    dstProjectMetadata.getId(),
                    dstBranchMetadata.getId(),
                    srcGraphMetadata.getId(),
                    dstGraphMetadata.getId(),
                    query,
                    steps);

        } catch (Exception e) {
            tx.rollback();
            throw e;
        }

        tx.commit();

        //taskExecutor.execute(branchCommitSubsetJob);
        branchCommitSubsetJob.run();

        return new BranchJobResponse(branchCommitSubsetJob);
View Full Code Here

    @RequestMapping(value = "/jobs", method = RequestMethod.GET)
    @ResponseBody
    public GetJobsResponse getJobs(Principal principal) {

        // This needs to be a read/write transaction as we might make a user.
        MetaGraphTx tx = metaGraphService.buildTransaction().start();
        GetJobsResponse getJobsResponse;

        try {
            UserMetadata userMetadata = tx.getOrCreateUser(principal);

            List<GetJobResponse> jobs = new ArrayList<>();

            for (ProjectMetadata projectMetadata : userMetadata.getProjects()) {
                for (JobMetadata jobMetadata : projectMetadata.getJobs()) {
                    jobs.add(new GetJobResponse(jobMetadata));
                }
            }

            getJobsResponse = new GetJobsResponse(jobs);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        // Commit must come after all graph access.
        tx.commit();

        return getJobsResponse;
    }
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.