示例#1
0
  private HashMap<String, ICriteria> getCriterias(
      Set<IUser> authors,
      Set<ICategory> categories,
      String text,
      String title,
      Date start,
      Date end) {
    HashMap<String, ICriteria> criterias = new HashMap<String, ICriteria>();

    if (authors != null && !authors.isEmpty()) {
      List<String> authorLogins = new ArrayList<String>(authors.size());
      for (IUser user : authors) {
        authorLogins.add(user.getUserid());
      }
      criterias.put(
          PostManagerRemote.USER_CRITERIA,
          new StringListCriteria(authorLogins, StringListCriteria.OR, StringListCriteria.EQUAL));
    }

    if (categories != null && !categories.isEmpty()) {
      List<String> categoriesId = new ArrayList<String>(categories.size());
      for (ICategory category : categories) {
        categoriesId.add("" + category.getCategoryid());
      }
      criterias.put(PostManagerRemote.CATEGORY_CRITERIA, new MemberOfCriteria(categoriesId));
    }

    if (title != null && !"".equals(title.trim())) {
      String[] titles = title.trim().split(" ");
      criterias.put(
          PostManagerRemote.TITLE_CRITERIA,
          new StringListCriteria(
              Arrays.asList(titles), StringListCriteria.AND, StringListCriteria.LIKE));
    }

    if (text != null && !"".equals(text.trim())) {
      String[] texts = text.trim().split(" ");
      criterias.put(
          PostManagerRemote.TEXT_CRITERIA,
          new StringListCriteria(
              Arrays.asList(texts), StringListCriteria.AND, StringListCriteria.LIKE));
    }

    if (start != null && end != null) {
      criterias.put(PostManagerRemote.DATE_CRITERIA, new BetweenDatesCriteria(start, end));
    }
    if (getConnectedUser() == null) {
      criterias.put(
          PostManagerRemote.PRIVATE_CRITERIA,
          new BooleanCriteria(false, BooleanCriteria.AND, BooleanCriteria.EQUAL));
    }
    return criterias;
  }
示例#2
0
 public int countUserPosts(IUser user) throws BlogException {
   try {
     return bean.countUserPosts(user.getUserid());
   } catch (EJBAccessException e) {
     throw new BlogException(
         null,
         BlogInternationalizationUtils.getMessages().getString("acces.non.autorise"),
         Constants.HOME_PAGE);
   }
 }
示例#3
0
 public List<IPost> findUserPosts(IUser user, int start, int end) throws BlogException {
   List<Post> postsSrv = null;
   try {
     postsSrv = bean.findUserPosts(user.getUserid(), start, end);
   } catch (EJBAccessException e) {
     throw new BlogException(
         null,
         BlogInternationalizationUtils.getMessages().getString("acces.non.autorise"),
         Constants.HOME_PAGE);
   }
   List<IPost> posts = converterPostList(postsSrv);
   return posts;
 }