Package com.commafeed.frontend.model

Examples of com.commafeed.frontend.model.Category


  @GET
  @Path("/get")
  @UnitOfWork
  @ApiOperation(value = "Get feed categories", notes = "Get all categories and subscriptions of the user", response = Category.class)
  public Response getSubscriptions(@SecurityCheck User user) {
    Category root = cache.getUserRootCategory(user);
    if (root == null) {
      log.debug("tree cache miss for {}", user.getId());
      List<FeedCategory> categories = feedCategoryDAO.findAll(user);
      List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(user);
      Map<Long, UnreadCount> unreadCount = feedSubscriptionService.getUnreadCount(user);

      root = buildCategory(null, categories, subscriptions, unreadCount);
      root.setId("all");
      root.setName("All");
      cache.setUserRootCategory(user, root);
    }

    return Response.ok(root).build();
  }
View Full Code Here


    return Response.ok(root).build();
  }

  private Category buildCategory(Long id, List<FeedCategory> categories, List<FeedSubscription> subscriptions,
      Map<Long, UnreadCount> unreadCount) {
    Category category = new Category();
    category.setId(String.valueOf(id));
    category.setExpanded(true);

    for (FeedCategory c : categories) {
      if ((id == null && c.getParent() == null) || (c.getParent() != null && Objects.equals(c.getParent().getId(), id))) {
        Category child = buildCategory(c.getId(), categories, subscriptions, unreadCount);
        child.setId(String.valueOf(c.getId()));
        child.setName(c.getName());
        child.setPosition(c.getPosition());
        if (c.getParent() != null && c.getParent().getId() != null) {
          child.setParentId(String.valueOf(c.getParent().getId()));
        }
        child.setExpanded(!c.isCollapsed());
        category.getChildren().add(child);
      }
    }
    Collections.sort(category.getChildren(), new Comparator<Category>() {
      @Override
View Full Code Here

    }
  }

  @Override
  public Category getUserRootCategory(User user) {
    Category cat = null;
    try (Jedis jedis = pool.getResource()) {
      String key = buildRedisUserRootCategoryKey(user);
      String json = jedis.get(key);
      if (json != null) {
        cat = MAPPER.readValue(json, Category.class);
View Full Code Here

TOP

Related Classes of com.commafeed.frontend.model.Category

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.