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"));
}
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"));
}
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();
}
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");
}
Aggregations