Search in sources :

Example 16 with RemoteTree

use of org.apache.jackrabbit.oak.remote.RemoteTree in project jackrabbit-oak by apache.

the class ContentRemoteTreeTest method testGetChildrenWithStart.

@Test
public void testGetChildrenWithStart() {
    Tree foo = mock(Tree.class);
    doReturn("foo").when(foo).getName();
    Tree bar = mock(Tree.class);
    doReturn("bar").when(bar).getName();
    Tree tree = mock(Tree.class);
    doReturn(asList(foo, bar)).when(tree).getChildren();
    ContentRemoteTree remoteTree = createTree(tree, new RemoteTreeFilters() {

        @Override
        public int getChildrenStart() {
            return 1;
        }
    });
    Map<String, RemoteTree> children = remoteTree.getChildren();
    assertFalse(children.containsKey("foo"));
    assertTrue(children.containsKey("bar"));
}
Also used : RemoteTreeFilters(org.apache.jackrabbit.oak.remote.RemoteTreeFilters) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Tree(org.apache.jackrabbit.oak.api.Tree) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Test(org.junit.Test)

Example 17 with RemoteTree

use of org.apache.jackrabbit.oak.remote.RemoteTree in project jackrabbit-oak by apache.

the class ContentRemoteTreeTest method testGetChildrenWithNegativeStart.

@Test
public void testGetChildrenWithNegativeStart() {
    Tree foo = mock(Tree.class);
    doReturn("foo").when(foo).getName();
    Tree bar = mock(Tree.class);
    doReturn("bar").when(bar).getName();
    Tree tree = mock(Tree.class);
    doReturn(asList(foo, bar)).when(tree).getChildren();
    ContentRemoteTree remoteTree = createTree(tree, new RemoteTreeFilters() {

        @Override
        public int getChildrenStart() {
            return -1;
        }
    });
    Map<String, RemoteTree> children = remoteTree.getChildren();
    assertTrue(children.containsKey("foo"));
    assertTrue(children.containsKey("bar"));
}
Also used : RemoteTreeFilters(org.apache.jackrabbit.oak.remote.RemoteTreeFilters) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Tree(org.apache.jackrabbit.oak.api.Tree) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Test(org.junit.Test)

Example 18 with RemoteTree

use of org.apache.jackrabbit.oak.remote.RemoteTree in project jackrabbit-oak by apache.

the class GetTreeHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session == null) {
        sendInternalServerError(response, "session not found");
        return;
    }
    RemoteRevision revision = readRevision(request, session);
    if (revision == null) {
        sendGone(response, "unable to read the revision");
        return;
    }
    RemoteTree tree = session.readTree(revision, readPath(request), readFilters(request));
    if (tree == null) {
        sendNotFound(response, singletonMap("Oak-Revision", revision.asString()), "tree not found");
        return;
    }
    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader("Oak-Revision", revision.asString());
    response.setContentType("application/json");
    ServletOutputStream stream = response.getOutputStream();
    JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
    renderResponse(generator, tree);
    generator.flush();
    stream.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Example 19 with RemoteTree

use of org.apache.jackrabbit.oak.remote.RemoteTree in project jackrabbit-oak by apache.

the class HeadTreeHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session == null) {
        sendInternalServerError(response, "session not found");
        return;
    }
    RemoteRevision revision = readRevision(request, session);
    if (revision == null) {
        sendGone(response, "revision not found");
        return;
    }
    RemoteTree tree = session.readTree(revision, readPath(request), new RemoteTreeFilters());
    if (tree == null) {
        sendNotFound(response, singletonMap("Oak-Revision", revision.asString()), "tree not found");
        return;
    }
    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader("Oak-Revision", revision.asString());
    response.setContentType("application/json");
}
Also used : RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) RemoteTreeFilters(org.apache.jackrabbit.oak.remote.RemoteTreeFilters) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision)

Aggregations

RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)19 Tree (org.apache.jackrabbit.oak.api.Tree)17 RemoteTreeFilters (org.apache.jackrabbit.oak.remote.RemoteTreeFilters)17 Test (org.junit.Test)17 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)5 Set (java.util.Set)5 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)4 InputStream (java.io.InputStream)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 RemoteRevision (org.apache.jackrabbit.oak.remote.RemoteRevision)2 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ServletOutputStream (javax.servlet.ServletOutputStream)1