Examples of LinkHeader


Examples of org.jboss.resteasy.spi.LinkHeader

                .header("total", pageResult.getCount())
                .build();
    }

    LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) {
        LinkHeader header = new LinkHeader();

        if (page != 0) {
            header.addLink(buildLink("prev", page - 1, uri));
            header.addLink(buildLink("first", 0, uri));
        }

        if (page < totalPages) {
            header.addLink(buildLink("next", page + 1, uri));
            header.addLink(buildLink("last", totalPages, uri));
        }
        return header;
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

    public void shouldGenerateHeaderLinksFirstPage() throws URISyntaxException {
        //given
        final UriInfoImpl uriInfo = getUriInfo();

        //when
        final LinkHeader linkHeader = endpoint.getLinkHeader(0, 3, uriInfo);

        //then
        assertThat(findLinkByRel(linkHeader, "prev")).isNull();
        final Link next = findLinkByRel(linkHeader, "next");
        assertThat(next).isNotNull();
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

    public void shouldGenerateHeaderLinksNormalPage() throws URISyntaxException {
        //given
        final UriInfoImpl uriInfo = getUriInfo();

        //when
        final LinkHeader linkHeader = endpoint.getLinkHeader(2, 3, uriInfo);

        final Link prev = findLinkByRel(linkHeader, "prev");
        assertThat(prev).isNotNull();
        assertThat(prev.getHref()).isEqualTo("/?page=1");
        final Link next = findLinkByRel(linkHeader, "next");
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

    public void shouldGenerateHeaderLinksLastPage() throws URISyntaxException {
        //given
        final UriInfoImpl uriInfo = getUriInfo();

        //when
        final LinkHeader linkHeader = endpoint.getLinkHeader(3, 3, uriInfo);

        final Link prev = findLinkByRel(linkHeader, "prev");
        assertThat(prev).isNotNull();
        assertThat(prev.getHref()).isEqualTo("/?page=2");
        final Link first = findLinkByRel(linkHeader, "first");
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

        //Find the installations using the variantID
        PageResult<Installation> pageResult = clientInstallationService.findInstallationsByVariant(variantId, page, pageSize);

        final long totalPages = pageResult.getCount() / pageSize;
        LinkHeader header = getLinkHeader(page, totalPages, uri);

        return Response.ok(pageResult.getResultList())
                .header("Link", header.toString())
                .header("total", pageResult.getCount())
                .build();
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

                .header("total", pageResult.getCount())
                .build();
    }

    LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) {
        LinkHeader header = new LinkHeader();

        if (page != 0) {
            header.addLink(buildLink("prev", page - 1, uri));
            header.addLink(buildLink("first", 0, uri));
        }

        if (page < totalPages) {
            header.addLink(buildLink("next", page + 1, uri));
            header.addLink(buildLink("last", totalPages, uri));
        }
        return header;
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

            year.addWeek(w);
        }
        Years years = new Years(new TreeSet<Year>(lookup.values()));

        String url = uriInfo.getAbsolutePath().toASCIIString();
        LinkHeader linkHeader = new LinkHeader().addLink(null, SELF, url, null);
        return Response.ok(years).header("Link", linkHeader.toString()).build();
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

        return now.plus(months(month));
    }

    private Response addLinksForYearMonth(Activities activities, DateMidnight yearMonth)
    {
        LinkHeader linkHeader = new LinkHeader();
        String self = uriInfo.getAbsolutePath().toASCIIString();
        linkHeader.addLink(null, SELF, self, null);

        DateMidnight prevMonth = yearMonth.minusMonths(1);
        DateMidnight nextMonth = yearMonth.plusMonths(1);
        boolean hasPrev = repository.hasActivitiesByYearMonth(prevMonth.year().get(), prevMonth.monthOfYear().get());
        boolean hasNext = repository.hasActivitiesByYearMonth(nextMonth.year().get(), nextMonth.monthOfYear().get());
        if (hasPrev)
        {
            String prev = uriInfo.getBaseUriBuilder().path("activities")
                    .segment(String.valueOf(prevMonth.year().get()), String.valueOf(prevMonth.monthOfYear().get()))
                    .build().toASCIIString();
            linkHeader.addLink(null, PREV, prev, null);
        }
        if (hasNext)
        {
            String next = uriInfo.getBaseUriBuilder().path("activities")
                    .segment(String.valueOf(nextMonth.year().get()), String.valueOf(nextMonth.monthOfYear().get()))
                    .build().toASCIIString();
            linkHeader.addLink(null, NEXT, next, null);
        }

        Response.ResponseBuilder response;
        if (!activities.isEmpty())
        {
            response = Response.ok(activities);
        }
        else
        {
            response = Response.status(NOT_FOUND).entity(
                    String.format("No activities found for %d/%d", yearMonth.monthOfYear().get(),
                            yearMonth.year().get()));
        }
        response.header("Link", linkHeader.toString());
        return response.build();
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

        return now.plus(weeks(week));
    }

    private Response addLinksForYearWeek(Activities activities, DateMidnight yearWeek)
    {
        LinkHeader linkHeader = new LinkHeader();
        String self = uriInfo.getAbsolutePath().toASCIIString();
        linkHeader.addLink(null, SELF, self, null);

        DateMidnight prevWeek = yearWeek.minusWeeks(1);
        DateMidnight nextWeek = yearWeek.plusWeeks(1);
        boolean hasPrev = repository.hasActivitiesByYearWeek(prevWeek.year().get(), prevWeek.weekOfWeekyear().get());
        boolean hasNext = repository.hasActivitiesByYearWeek(nextWeek.year().get(), nextWeek.weekOfWeekyear().get());
        if (hasPrev)
        {
            String prev = uriInfo
                    .getBaseUriBuilder()
                    .path("activities")
                    .segment(String.valueOf(prevWeek.year().get()),
                            "cw" + String.valueOf(prevWeek.weekOfWeekyear().get())).build().toASCIIString();
            linkHeader.addLink(null, PREV, prev, null);
        }
        if (hasNext)
        {
            String next = uriInfo
                    .getBaseUriBuilder()
                    .path("activities")
                    .segment(String.valueOf(nextWeek.year().get()),
                            "cw" + String.valueOf(nextWeek.weekOfWeekyear().get())).build().toASCIIString();
            linkHeader.addLink(null, NEXT, next, null);
        }

        Response.ResponseBuilder response;
        if (!activities.isEmpty())
        {
            response = Response.ok(activities);
        }
        else
        {
            response = Response.status(NOT_FOUND).entity(
                    String.format("No activities found for CW %d/%d", yearWeek.weekOfWeekyear().get(),
                            yearWeek.year().get()));
        }
        response.header("Link", linkHeader.toString());
        return response.build();
    }
View Full Code Here

Examples of org.jboss.resteasy.spi.LinkHeader

                .dayOfMonth().get()));
    }

    private Response addLinksForYearMonthDay(Activities activities, DateMidnight yearMonthDay)
    {
        LinkHeader linkHeader = new LinkHeader();
        String self = uriInfo.getAbsolutePath().toASCIIString();
        linkHeader.addLink(null, SELF, self, null);

        DateMidnight prevDay = yearMonthDay.minusDays(1);
        DateMidnight nextDay = yearMonthDay.plusDays(1);
        boolean hasPrev = repository.hasActivitiesByYearMonthDay(prevDay.year().get(), prevDay.monthOfYear().get(),
                prevDay.dayOfMonth().get());
        boolean hasNext = repository.hasActivitiesByYearMonthDay(nextDay.year().get(), nextDay.monthOfYear().get(),
                nextDay.dayOfMonth().get());
        if (hasPrev)
        {
            String prev = uriInfo
                    .getBaseUriBuilder()
                    .path("activities")
                    .segment(String.valueOf(prevDay.year().get()), String.valueOf(prevDay.monthOfYear().get()),
                            String.valueOf(prevDay.dayOfMonth().get())).build().toASCIIString();
            linkHeader.addLink(null, PREV, prev, null);
        }
        if (hasNext)
        {
            String next = uriInfo
                    .getBaseUriBuilder()
                    .path("activities")
                    .segment(String.valueOf(nextDay.year().get()), String.valueOf(nextDay.monthOfYear().get()),
                            String.valueOf(nextDay.dayOfMonth().get())).build().toASCIIString();
            linkHeader.addLink(null, NEXT, next, null);
        }

        Response.ResponseBuilder response;
        if (!activities.isEmpty())
        {
            response = Response.ok(activities);
        }
        else
        {
            response = Response.status(NOT_FOUND).entity(String
                    .format("No activities found for %d/%d/%d", yearMonthDay.dayOfMonth().get(),
                            yearMonthDay.monthOfYear().get(), yearMonthDay.year().get()));
        }
        response.header("Link", linkHeader.toString());
        return response.build();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.