Beispiel #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;
  }
Beispiel #2
0
 public <T extends ISocioObject> List<T> getObjects(Class<T> T) {
   Query<T> q = (Query<T>) ds.createQuery(T);
   Iterable<T> objects = q.fetch();
   ArrayList<T> ret = new ArrayList<T>();
   for (T object : objects) {
     ret.add(object);
   }
   return ret;
 }
Beispiel #3
0
 @Override
 public <T extends GeneralMessage> List<T> getMessagesAfterDate(
     Class<T> T, Long date, String sourceField, String sourceId) {
   Query<T> q =
       (Query<T>)
           ds.createQuery(T)
               .field("date")
               .greaterThanOrEq(date)
               .field(sourceField)
               .equal(sourceId);
   Iterable<T> messages = q.fetch();
   ArrayList<T> ret = new ArrayList<T>();
   for (T message : messages) {
     ret.add(message);
   }
   return ret;
 }