@SuppressWarnings({"unchecked", "rawtypes"})
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Long articleCategoryId =
        FreemarkerUtils.getParameter(ARTICLE_CATEGORY_ID_PARAMETER_NAME, Long.class, params);

    ArticleCategory articleCategory = articleCategoryService.find(articleCategoryId);

    List<ArticleCategory> articleCategories;
    if (articleCategoryId != null && articleCategory == null) {
      articleCategories = new ArrayList<ArticleCategory>();
    } else {
      boolean useCache = useCache(env, params);
      String cacheRegion = getCacheRegion(env, params);
      Integer count = getCount(params);
      if (useCache) {
        articleCategories =
            articleCategoryService.findChildren(articleCategory, count, cacheRegion);
      } else {
        articleCategories = articleCategoryService.findChildren(articleCategory, count);
      }
    }
    setLocalVariable(VARIABLE_NAME, articleCategories, env, body);
  }
Ejemplo n.º 2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Long articleCategoryId =
        FreemarkerUtils.getParameter(ARTICLE_CATEGORY_ID_PARAMETER_NAME, Long.class, params);
    Long[] tagIds = FreemarkerUtils.getParameter(TAG_IDS_PARAMETER_NAME, Long[].class, params);

    ArticleCategory articleCategory = articleCategoryService.find(articleCategoryId);
    List<Tag> tags = tagService.findList(tagIds);

    List<Article> articles;
    if ((articleCategoryId != null && articleCategory == null)
        || (tagIds != null && tags.isEmpty())) {
      articles = new ArrayList<Article>();
    } else {
      boolean useCache = useCache(env, params);
      String cacheRegion = getCacheRegion(env, params);
      Integer count = getCount(params);
      List<Filter> filters = getFilters(params, Article.class);
      List<Order> orders = getOrders(params);
      if (useCache) {
        articles =
            articleService.findList(articleCategory, tags, count, filters, orders, cacheRegion);
      } else {
        articles = articleService.findList(articleCategory, tags, count, filters, orders);
      }
    }
    setLocalVariable(VARIABLE_NAME, articles, env, body);
  }