Package org.lab41.dendrite.metagraph

Examples of org.lab41.dendrite.metagraph.DendriteGraph


        logger.debug("receiving file: '" +  file.getOriginalFilename() + "'");
        logger.debug("file format: '" +  format + "'");
        logger.debug("search keys: '" + searchKeys + "'");

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "cannot find graph '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }

        try {
            // extract search indices from client JSON
            JSONObject jsonKeys = new JSONObject(searchKeys);
            JSONArray jsonVertices = jsonKeys.getJSONArray("vertices");
            JSONArray jsonEdges = jsonKeys.getJSONArray("edges");

            // build search indices for vertices
            for (int i = 0; i < jsonVertices.length(); ++i){
              JSONObject jsonVertex = jsonVertices.getJSONObject(i);
              String key = jsonVertex.getString("name");
              String type = jsonVertex.getString("type");

              // create the search index (if it doesn't already exist and isn't a reserved key)
              if (graph.getType(key) == null && !RESERVED_KEYS.contains(key)) {
                  Class cls;
                  List<Parameter> parameters = new ArrayList<>();

                  if (type.equals("string")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.STRING));
                  } else if (type.equals("text")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.TEXT));
                  } else if (type.equals("integer")) {
                      cls = Integer.class;
                  } else if (type.equals("float")) {
                      cls = FullFloat.class;
                  } else if (type.equals("double")) {
                      cls = FullDouble.class;
                  } else if (type.equals("geocoordinate")) {
                      cls = Geoshape.class;
                  } else {
                      graph.rollback();
                      response.put("status", "error");
                      response.put("msg", "unknown type '" + type + "'");
                      return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
                  }

                  graph.makeKey(key)
                          .dataType(cls)
                          .indexed(Vertex.class)
                          .indexed(DendriteGraph.INDEX_NAME, Vertex.class, parameters.toArray(new Parameter[parameters.size()]))
                          .make();
              }
            }

            // build search indices for edges
            for (int i = 0; i < jsonEdges.length(); ++i){
              JSONObject jsonEdge = jsonEdges.getJSONObject(i);
              String key = jsonEdge.getString("name");
              String type = jsonEdge.getString("type");

              // create the search index (if it doesn't already exist and isn't a reserved key)
              if (graph.getType(key) == null && !RESERVED_KEYS.contains(key)) {
                  Class cls;
                  List<Parameter> parameters = new ArrayList<>();

                  if (type.equals("string")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.STRING));
                  } else if (type.equals("text")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.TEXT));
                  } else if (type.equals("integer")) {
                      cls = Integer.class;
                  } else if (type.equals("float")) {
                      cls = FullFloat.class;
                  } else if (type.equals("double")) {
                      cls = FullDouble.class;
                  } else if (type.equals("geocoordinate")) {
                      cls = Geoshape.class;
                  } else {
                      graph.rollback();
                      response.put("status", "error");
                      response.put("msg", "unknown type '" + type + "'");
                      return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
                  }

                  graph.makeKey(key)
                          .dataType(cls)
                          .indexed(Edge.class)
                          .indexed(DendriteGraph.INDEX_NAME, Edge.class, parameters.toArray(new Parameter[parameters.size()]))
                          .make();
              }
            }

            // commit the indices
            graph.commit();

            InputStream inputStream = file.getInputStream();
            if (format.equalsIgnoreCase("GraphSON")) {
                GraphSONReader.inputGraph(graph, inputStream);
            } else if (format.equalsIgnoreCase("GraphML")) {
                GraphMLReader.inputGraph(graph, inputStream);
            } else if (format.equalsIgnoreCase("GML")) {
                GMLReader.inputGraph(graph, inputStream);
            } else if (format.equalsIgnoreCase("FaunusGraphSON")) {
                FaunusGraphSONReader.inputGraph(graph, inputStream);
            } else {
                graph.rollback();

                response.put("status", "error");
                response.put("msg", "unknown format '" + format + "'");
                inputStream.close();
                return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
            }
            inputStream.close();
        } catch (Throwable t) {
            t.printStackTrace();

            graph.rollback();

            response.put("status", "error");
            response.put("msg", "exception: " + t.toString());

            return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
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

    @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

TOP

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

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.