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