use of fi.otavanopisto.muikku.plugins.feed.model.FeedItem in project muikku by otavanopisto.
the class FeedItemDAO method findByFeeds.
public List<FeedItem> findByFeeds(List<Feed> feeds, int numItems, FeedSortOrder order) {
EntityManager entityManager = getEntityManager();
if (feeds == null || feeds.size() == 0) {
return Collections.emptyList();
}
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<FeedItem> criteria = criteriaBuilder.createQuery(FeedItem.class);
Root<FeedItem> root = criteria.from(FeedItem.class);
criteria.select(root);
criteria.where(root.get(FeedItem_.feed).in(feeds));
switch(order) {
case ASCENDING:
criteria.orderBy(criteriaBuilder.asc(root.get(FeedItem_.publicationDate)));
break;
case DESCENDING:
criteria.orderBy(criteriaBuilder.desc(root.get(FeedItem_.publicationDate)));
break;
}
return entityManager.createQuery(criteria).setMaxResults(numItems).getResultList();
}
use of fi.otavanopisto.muikku.plugins.feed.model.FeedItem in project muikku by otavanopisto.
the class FeedRESTService method findFeedByNames.
@GET
@Path("/feeds/{NAMES}")
@RESTPermit(handling = Handling.UNSECURED)
public Response findFeedByNames(@PathParam("NAMES") String names, @QueryParam("numItems") @DefaultValue("10") int numItems, @QueryParam("order") @DefaultValue("DESCENDING") FeedSortOrder order) {
if (StringUtils.isBlank(names)) {
return Response.status(Status.NOT_FOUND).build();
}
Set<String> nameSet = Stream.of(names.split(",")).collect(Collectors.toSet());
List<Feed> feeds = new ArrayList<>();
for (String name : nameSet) {
Feed feed = feedDAO.findByName(name);
if (feed != null) {
feeds.add(feed);
}
}
List<FeedItem> feedItems = feedItemDao.findByFeeds(feeds, numItems, order);
return Response.ok(feedItems).build();
}
Aggregations