Ejemplo n.º 1
0
  public List<GeneralMessage> getUnreadMessages(String userId, String tagId, UserTags tags) {

    Query<UnreaddenMessage> q =
        ds.createQuery(UnreaddenMessage.class).field("userId").equal(userId.toString());
    String order = tags.getOrder();
    if (!tagId.equals(UserTags.ALL_TAGS)) {
      SocioTag tag = tags.getTag(tagId);
      order = tag.getOrder();
      List<String> tagsIds = new ArrayList<String>();
      List<SocioTag> leaves = tag.getLeaves();
      for (SocioTag leaf : leaves) {
        tagsIds.add(leaf.getUniqueId());
      }
      q.field("tagId").hasAnyOf(tagsIds);
    }
    if (order.equals(SocioTag.ASCENDING_ORDER)) {
      q.order("-messageDate");
    } else {
      q.order("messageDate");
    }
    q.limit(tags.getRange());
    List<GeneralMessage> messagesList = new ArrayList<GeneralMessage>();
    Iterable<UnreaddenMessage> messages = q.fetch();
    for (UnreaddenMessage unreaddenMessage : messages) {
      messagesList.add(unreaddenMessage.getMessage());
    }
    tags.setSelectedTag(tagId);
    ds.save(tags);
    return messagesList;
  }
Ejemplo n.º 2
0
 public static List<Quote> findAllSortedByCreationDate(boolean onlyApproved) {
   Query<Quote> query = DBHolder.ds.find(Quote.class).field("deleted").equal(false);
   if (onlyApproved) {
     query = query.field("quoteState").equal(QuoteState.APPROVED);
   }
   return query.order("-creationDate").asList();
 }
Ejemplo n.º 3
0
    @Override
    public List<play.db.Model> fetch(
        int offset,
        int size,
        String orderBy,
        String order,
        List<String> searchFields,
        String keywords,
        String where) {
      if (orderBy == null) orderBy = keyName();
      if ("DESC".equalsIgnoreCase(order)) orderBy = null == orderBy ? null : "-" + orderBy;
      Query<? extends Model> q = ds().createQuery(clazz).offset(offset).limit(size);
      if (null != orderBy) q = q.order(orderBy);

      if (keywords != null && !keywords.equals("")) {
        List<Criteria> cl = new ArrayList<Criteria>();
        for (String f : fillSearchFieldsIfEmpty_(searchFields)) {
          cl.add(q.criteria(f).containsIgnoreCase(keywords));
        }
        q.or(cl.toArray(new Criteria[] {}));
      }

      processWhere(q, where);

      List<play.db.Model> l = new ArrayList<play.db.Model>();
      l.addAll(q.asList());
      return l;
    }
Ejemplo n.º 4
0
  public List<User> findWithLimitAndOffset(int limit, int offset, String sortField) {

    Query<User> findQuery = ds.createQuery(User.class);
    if (limit > 0) {
      findQuery = findQuery.limit(limit);
    }
    if (offset > 0) {
      findQuery = findQuery.offset(offset);
    }
    if (null != sortField) {
      findQuery = findQuery.order(sortField);
    }

    if (null == findQuery) {
      return null;
    }

    List<User> users = findQuery.asList();
    return (users.isEmpty()) ? null : users;
  }
Ejemplo n.º 5
0
 public static List<Quote> findAllSortedByVote(QuoteState state) {
   Query<Quote> query = DBHolder.ds.find(Quote.class).field("deleted").equal(false);
   query = query.field("quoteState").equal(state);
   return query.order("-voteCount").asList();
 }