Package org.lab41.dendrite.metagraph

Examples of org.lab41.dendrite.metagraph.MetaGraphTx


    @RequestMapping(value = "/projects", method = RequestMethod.GET)
    @ResponseBody
    public GetProjectsResponse getProjects(Principal principal) {

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

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

            List<GetProjectResponse> projects = new ArrayList<>();
            for (ProjectMetadata projectMetadata : userMetadata.getProjects()) {
                projects.add(new GetProjectResponse(projectMetadata));
            }

            getProjectsResponse = new GetProjectsResponse(projects);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        return getProjectsResponse;
    }
View Full Code Here


    @PreAuthorize("hasPermission(#projectId, 'project', 'admin')")
    @RequestMapping(value = "/projects/{projectId}", method = RequestMethod.GET)
    @ResponseBody
    public GetProjectResponse getProject(@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);
            }

            // FIXME: Temporary hack to force loading the graph until the UI can handle it occurring asynchronously.
            metaGraphService.getDendriteGraph(projectMetadata.getCurrentGraph().getId());

            return new GetProjectResponse(projectMetadata);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

        }

        String name = item.getName();
        boolean createGraph = item.createGraph();

        MetaGraphTx tx = metaGraphService.newTransaction();
        GetProjectResponse getProjectResponse;
        HttpHeaders headers = new HttpHeaders();

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

            ProjectMetadata projectMetadata = tx.createProject(name, userMetadata, createGraph);

            headers.setLocation(builder.path("/projects/{projectId}").buildAndExpand(projectMetadata.getId()).toUri());

            getProjectResponse = new GetProjectResponse(projectMetadata);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

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

        return new ResponseEntity<>(getProjectResponse, headers, HttpStatus.CREATED);
    }
View Full Code Here

    @PreAuthorize("hasPermissions(#projectId, 'project', 'read')")
    @RequestMapping(value = "/projects/{projectId}", method = RequestMethod.DELETE)
    @ResponseBody
    public DeleteProjectResponse deleteProject(@PathVariable String projectId) throws Exception {

        MetaGraphTx tx = metaGraphService.newTransaction();

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

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

        tx.commit();

        return new DeleteProjectResponse();
    }
View Full Code Here

    @PreAuthorize("hasPermission(#projectId, 'project', 'admin')")
    @RequestMapping(value = "/projects/{projectId}/users", method = RequestMethod.GET)
    @ResponseBody
    public GetUsersResponse addUser(@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);
            }

            List<GetUserResponse> users = new ArrayList<>();

            for (UserMetadata userMetadata : projectMetadata.getUsers()) {
                users.add(new GetUserResponse(userMetadata));
            }

            return new GetUsersResponse(users);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

        if (result.hasErrors()) {
            throw new BindingException(result);
        }

        MetaGraphTx tx = metaGraphService.newTransaction();

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

            UserMetadata otherUserMetadata = tx.getUserByName(item.getName());
            if (otherUserMetadata == null) {
                throw new NotFound(UserMetadata.class);
            }

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

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

        return new AddUserToProjectResponse();
    }
View Full Code Here

    @Autowired
    MetaGraphService metaGraphService;

    private boolean checkUserForBranch(Authentication authentication, Serializable targetId) {
        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();
        boolean authenticated;

        try {
            BranchMetadata branchMetadata = tx.getBranch((String) targetId);
            if (branchMetadata == null) {
                return false;
            }

            ProjectMetadata projectMetadata = branchMetadata.getProject();
            if (projectMetadata == null) {
                return false;
            }

            authenticated = checkAuthAgainstUserOfProject(tx, authentication, projectMetadata);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        return authenticated;
    }
View Full Code Here

        }
        return false;
    }

    boolean checkUserForProject(Authentication authentication, Serializable targetId) {
        MetaGraphTx tx = metaGraphService.buildTransaction().start();
        boolean authenticated;

        try {
            ProjectMetadata projectMetadata = tx.getProject((String) targetId);
            if (projectMetadata == null) {
                return false;
            }

            authenticated = checkAuthAgainstUserOfProject(tx, authentication, projectMetadata);
        } catch (Throwable t){
            tx.rollback();
            throw t;
        }

        tx.commit();

        return authenticated;
    }
View Full Code Here

    @RequestMapping(value = "/graphs", method = RequestMethod.GET)
    @ResponseBody
    public GetGraphsResponse getGraphs(Principal principal) {

        // This needs to be a read/write transaction as we might make a user.
        MetaGraphTx tx = metaGraphService.buildTransaction().start();
        List<GetGraphResponse> graphs = new ArrayList<>();

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

            for (ProjectMetadata projectMetadata : userMetadata.getProjects()) {
                for (GraphMetadata graphMetadata : projectMetadata.getGraphs()) {
                    graphs.add(new GetGraphResponse(graphMetadata));
                }
            }
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

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

        return new GetGraphsResponse(graphs);
    }
View Full Code Here

        return authenticated;
    }

    boolean checkUserForGraph(Authentication authentication, Serializable targetId) {
        MetaGraphTx tx = metaGraphService.buildTransaction().start();
        boolean authenticated;

        try {
            GraphMetadata graphMetadata = tx.getGraph((String) targetId);
            if (graphMetadata == null) {
                return false;
            }

            ProjectMetadata projectMetadata = graphMetadata.getProject();
            if (projectMetadata == null) {
                return false;
            }

            authenticated = checkAuthAgainstUserOfProject(tx, authentication, projectMetadata);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        return authenticated;
    }
View Full Code Here

TOP

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

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.