Package org.apache.jackrabbit.oak.api

Examples of org.apache.jackrabbit.oak.api.Root


        }
    }

    @Test
    public void testValidTokenCredentials() throws Exception {
        Root root = adminSession.getLatestRoot();
        AuthenticationConfiguration authConfig = getSecurityProvider().getConfiguration(AuthenticationConfiguration.class);
        TokenProvider tp = authConfig.getTokenProvider(root);

        SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
        TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());
View Full Code Here


                throw new LoginException();
            }

            ContentSession session = repository.login(credentials, null);
            try {
                Root root = session.getLatestRoot();
                request.setAttribute("root", root);

                // Find the longest part of the given path that matches
                // an existing node. The tail part might be used when
                // creating new nodes or when exposing virtual resources.
                // Note that we need to traverse the path in reverse
                // direction as some parent nodes may be read-protected.
                String head = request.getPathInfo();
                String tail = "";
                Tree tree = root.getTree(head);
                while (!tree.exists()) {
                    if (tree.isRoot()) {
                        response.sendError(HttpServletResponse.SC_NOT_FOUND);
                        return;
                    }
View Full Code Here

    @Override
    protected void doPost(
            HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            Root root = (Root) request.getAttribute("root");
            Tree tree = (Tree) request.getAttribute("tree");
            String path = (String) request.getAttribute("path");

            for (String name : PathUtils.elements(path)) {
                tree = tree.addChild(name);
            }

            ObjectMapper mapper = new ObjectMapper();
            JsonNode node = mapper.readTree(request.getInputStream());
            if (node.isObject()) {
                post(node, tree);
                root.commit();
                doGet(request, response);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            }
        } catch (CommitFailedException e) {
View Full Code Here

    @Override
    protected void doDelete(
            HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            Root root = (Root) request.getAttribute("root");
            Tree tree = (Tree) request.getAttribute("tree");
            if (!tree.isRoot()) {
                Tree parent = tree.getParent();
                Tree child = parent.getChild(tree.getName());
                if (child.exists()) {
                    child.remove();
                }
                root.commit();
                response.sendError(HttpServletResponse.SC_OK);
            } else {
                // Can't remove the root node
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
            }
View Full Code Here

    @Before
    public void setUp() throws CommitFailedException {
        session = createContentSession();

        // Add test content
        Root root = session.getLatestRoot();
        Tree tree = root.getTree("/");
        tree.setProperty("a", 1);
        tree.setProperty("b", 2);
        tree.setProperty("c", 3);
        Tree x = tree.addChild("x");
        x.addChild("xx");
        x.setProperty("xa", "value");
        tree.addChild("y");
        tree.addChild("z");
        root.commit();
    }
View Full Code Here

        session = null;
    }

    @Test
    public void getTree() {
        Root root = session.getLatestRoot();

        List<String> validPaths = new ArrayList<String>();
        validPaths.add("/");
        validPaths.add("/x");
        validPaths.add("/x/xx");
        validPaths.add("/y");
        validPaths.add("/z");

        for (String treePath : validPaths) {
            Tree tree = root.getTree(treePath);
            assertTrue(tree.exists());
            assertEquals(treePath, tree.getPath());
        }

        List<String> invalidPaths = new ArrayList<String>();
        invalidPaths.add("/any");
        invalidPaths.add("/x/any");

        for (String treePath : invalidPaths) {
            assertFalse(root.getTree(treePath).exists());
        }
    }
View Full Code Here

        }
    }

    @Test
    public void move() throws CommitFailedException {
        Root root = session.getLatestRoot();
        Tree tree = root.getTree("/");

        Tree y = tree.getChild("y");
        Tree x = tree.getChild("x");
        assertTrue(x.exists());

        assertFalse(root.hasPendingChanges());
        root.move("/x", "/y/xx");
        assertTrue(root.hasPendingChanges());
        assertFalse(tree.hasChild("x"));
        assertTrue(y.hasChild("xx"));
        assertEquals("/y/xx", x.getPath());

        root.commit();
        assertFalse(root.hasPendingChanges());

        assertFalse(tree.hasChild("x"));
        assertTrue(tree.hasChild("y"));
        assertTrue(tree.getChild("y").hasChild("xx"));
    }
View Full Code Here

        assertTrue(tree.getChild("y").hasChild("xx"));
    }

    @Test
    public void moveRemoveAdd() {
        Root root = session.getLatestRoot();

        Tree x = root.getTree("/x");
        Tree z = root.getTree("/z");
        z.setProperty("p", "1");

        root.move("/z", "/x/z");
        root.getTree("/x/z").remove();

        assertFalse(z.exists());

        x.addChild("z");
        assertEquals(Status.NEW, z.getStatus());
View Full Code Here

        assertEquals("2", p.getValue(Type.STRING));
    }

    @Test
    public void moveNew() {
        Root root = session.getLatestRoot();
        Tree tree = root.getTree("/");

        Tree t = tree.addChild("new");

        root.move("/new", "/y/new");
        assertEquals("/y/new", t.getPath());

        assertFalse(tree.getChild("new").exists());
    }
View Full Code Here

        assertFalse(tree.getChild("new").exists());
    }

    @Test
    public void moveExistingParent() throws CommitFailedException {
        Root root = session.getLatestRoot();
        root.getTree("/").addChild("parent").addChild("new");
        root.commit();

        Tree parent = root.getTree("/parent");
        Tree n = root.getTree("/parent/new");

        root.move("/parent", "/moved");

        assertEquals(Status.NEW, parent.getStatus());
        assertEquals(Status.NEW, n.getStatus());

        assertEquals("/moved", parent.getPath());
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.api.Root

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.