Package com.couchace.core.api.query

Examples of com.couchace.core.api.query.CouchPageNavigation


                // Parse entity documents
                List<EntityDocument<T>> entityDocuments = jsonStrategy.readEntityDocuments(
                    couch.get(),
                        entityMeta,
                    couchHttpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(couchHttpResponse.getUri(), entityDocuments, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(couchHttpResponse.getUri(), entityDocuments, request.getPageQuery());
                } else {
View Full Code Here


                        CouchPageNavigation.empty(),
                        documentList);

            } else {
                List<TextDocument> documentList = jsonStrategy.readTextDocuments(couchHttpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(couchHttpResponse.getUri(), documentList, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(couchHttpResponse.getUri(), documentList, request.getPageQuery());
                } else {
View Full Code Here

            documentList.remove(pageQuery.getPageSize());
            CouchDocument pageEndEntity = documentList.get(documentList.size() - 1);
            forwardPageUri = httpClient.pageUri(requestedPageUri, pageEndEntity, pageQuery.isReverse()).toString();
        }

        CouchPageNavigation pageNavigation;
        if (pageQuery.isReverse()) {
            Collections.reverse(documentList);
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), forwardPageUri, backPageUri, pageQuery.isIncludeDocs());
        } else {
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), backPageUri, forwardPageUri, pageQuery.isIncludeDocs());
        }

        return pageNavigation;
    }
View Full Code Here

        String requestedPage = requestedPageUri.toString();
        int designIndex = requestedPage.indexOf("_design");
        if (designIndex > 0) {
            requestedPage = requestedPage.substring(designIndex);
        }
        return new CouchPageNavigation(viewQuery.getLimit(), requestedPage, null, nextPage, viewQuery.isIncludeDocs());
    }
View Full Code Here

        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byId").limit(3).key(2).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 1);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[1]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
    }
View Full Code Here

        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 2);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[2]);
        assertEquals(foundPets.get(1), pets[3]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

        // Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 2);
        foundPets = er.getEntityList();
        pageNavigation = er.getCouchPageNavigation();
        assertEquals(foundPets.get(0), pets[4]);
        assertEquals(foundPets.get(1), pets[5]);
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:5&skip=1&descending=true&key=%22DOG%22");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:6&skip=1&descending=false&key=%22DOG%22");

        // Third page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        pageNavigation = er.getCouchPageNavigation();
        foundPets = er.getEntityList();
        assertEquals(er.getSize(), 1);
        assertEquals(foundPets.get(0), pets[6]);
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:7&skip=1&descending=true&key=%22DOG%22");

        // Previous to Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 2);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[4]);
        assertEquals(foundPets.get(1), pets[5]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

        // Previous to first page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 2);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[2]);
        assertEquals(foundPets.get(1), pets[3]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
    }
View Full Code Here

        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
        assertEquals(foundPets.get(2), pets[2]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:3&skip=1&descending=false&endkey=%22DOG%22");

        // Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        pageNavigation = er.getCouchPageNavigation();
        assertEquals(foundPets.get(0), pets[3]);
        assertEquals(foundPets.get(1), pets[4]);
        assertEquals(foundPets.get(2), pets[5]);
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:4&skip=1&descending=true&endkey=%22DOG%22");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:6&skip=1&descending=false&endkey=%22DOG%22");

        // Third page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        pageNavigation = er.getCouchPageNavigation();
        foundPets = er.getEntityList();
        assertEquals(er.getSize(), 1);
        assertEquals(foundPets.get(0), pets[6]);
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:7&skip=1&descending=true&endkey=%22DOG%22");
//    assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:7&skip=1&descending=true&key=%22DOG%22")

        // Previous to Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[3]);
        assertEquals(foundPets.get(1), pets[4]);
        assertEquals(foundPets.get(2), pets[5]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

        // CRITICAL - problem is that startKey has been changed and does not include the original value.

/*
    assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byType?startkey=%22DOG%22&startkey_docid=Pet:7&skip=1&descending=true&endkey=%22DOG%22")
View Full Code Here

        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byTypeAndId").limit(3).key("CAT", 2).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 1);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[1]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

        // http://127.0.0.1:5984/couch-test/_design/pet/_view/byTypeAndId?startkey=[%22DOG%22,%205]
        viewQuery = CouchViewQuery.builder("pet", "byTypeAndId").limit(10).start("DOG", 5).build();
        er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 6);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[4]);
        assertEquals(foundPets.get(1), pets[5]);
        assertEquals(foundPets.get(2), pets[6]);
        assertEquals(foundPets.get(3), pets[7]);
        assertEquals(foundPets.get(4), pets[8]);
        assertEquals(foundPets.get(5), pets[9]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

        // http://127.0.0.1:5984/couch-test/_design/pet/_view/byTypeAndId?startkey=[%22DOG%22,%205]&endkey=[%22DOG%22,%207]
        viewQuery = CouchViewQuery.builder("pet", "byTypeAndId").limit(10).start(new CouchJsonKey("DOG", 5)).end(new CouchJsonKey("DOG", 7)).build();
        er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        pageNavigation = er.getCouchPageNavigation();
//    assertEquals(pageNavigation.requestedPage, "_design/pet/_view/byTypeAndId?include_docs=true&startkey=%5B%[%22DOG%22,%205]&endkey=%5B%[%22DOG%22,%207]&limit=10")
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[4]);
        assertEquals(foundPets.get(1), pets[5]);
        assertEquals(foundPets.get(2), pets[6]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());

    }
View Full Code Here

        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
        assertEquals(foundPets.get(2), pets[2]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?include_docs=true&limit=4");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=3&startkey_docid=Pet:3&skip=1&descending=false");

        // Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[3]);
        assertEquals(foundPets.get(1), pets[4]);
        assertEquals(foundPets.get(2), pets[5]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=3&startkey_docid=Pet:3&skip=1&descending=false");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=4&startkey_docid=Pet:4&skip=1&descending=true");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=6&startkey_docid=Pet:6&skip=1&descending=false");

        // Third page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[6]);
        assertEquals(foundPets.get(1), pets[7]);
        assertEquals(foundPets.get(2), pets[8]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=6&startkey_docid=Pet:6&skip=1&descending=false");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=7&startkey_docid=Pet:7&skip=1&descending=true");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=9&startkey_docid=Pet:9&skip=1&descending=false");

        // Fourth page

        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 1);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[9]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=9&startkey_docid=Pet:9&skip=1&descending=false");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=10&startkey_docid=Pet:10&skip=1&descending=true");

    }
View Full Code Here

        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
        assertEquals(foundPets.get(2), pets[2]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byCreatedAt?include_docs=true&limit=4");
        String nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:3&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
        assertEquals(pageNavigation.getNextPage(), nextPage);

        // Second page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[3]);
        assertEquals(foundPets.get(1), pets[4]);
        assertEquals(foundPets.get(2), pets[5]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), nextPage);
        String previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:4&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
        assertEquals(pageNavigation.getPreviousPage(), previousPage);
        nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:6&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
        assertEquals(pageNavigation.getNextPage(), nextPage);

        // Third page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[6]);
        assertEquals(foundPets.get(1), pets[7]);
        assertEquals(foundPets.get(2), pets[8]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), nextPage);
        previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:7&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
        assertEquals(pageNavigation.getPreviousPage(), previousPage);
        nextPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:9&skip=1&descending=false", foundPets.get(2).getCreatedAt().toString());
        assertEquals(pageNavigation.getNextPage(), nextPage);

        // Fourth page
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
        assertEquals(er.getSize(), 1);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[9]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        previousPage = String.format("_design/pet/_view/byCreatedAt?startkey=%%22%s%%22&startkey_docid=Pet:10&skip=1&descending=true", foundPets.get(0).getCreatedAt().toString());
        assertEquals(pageNavigation.getPreviousPage(), previousPage);

    }
View Full Code Here

TOP

Related Classes of com.couchace.core.api.query.CouchPageNavigation

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.