private List<LogRecord> filterRecords(List<LogRecord> list, SearchCondition<LogRecord> theSearch) { return theSearch == null ? list : theSearch.findAll(list); }
@GET @Path("/books/{search}/chapter/{chapter}") @Produces("application/xml") public Chapter getChapterFromSelectedBook(@Context SearchContext searchContext, @PathParam("search") String expression, @PathParam("chapter") int chapter) { SearchCondition<Book> sc = searchContext.getCondition(expression, Book.class); if (sc == null) { throw new WebApplicationException(404); } List<Book> found = sc.findAll(books.values()); if (found.size() != 1) { throw new WebApplicationException(404); } Book selectedBook = found.get(0); return selectedBook.getChapter(chapter); }
@GET @Path("/books/search") @Produces("application/xml") public Book getBook(@Context SearchContext searchContext) throws BookNotFoundFault { SearchCondition<Book> sc = searchContext.getCondition(Book.class); if (sc == null) { throw new BookNotFoundFault("Search exception"); } List<Book> found = sc.findAll(books.values()); if (found.size() != 1) { throw new BookNotFoundFault("Single book is expected"); } return found.get(0); }