public static long[] getAssetTagIds(long[] groupIds, KBArticle kbArticle) throws PortalException {

    List<AssetTag> assetTags =
        AssetTagServiceUtil.getTags(KBArticle.class.getName(), kbArticle.getClassPK());

    long[] tagIds =
        AssetTagLocalServiceUtil.getTagIds(
            groupIds, StringUtil.split(ListUtil.toString(assetTags, "name")));

    Set<Long> filteredTagIds = new LinkedHashSet<>();

    for (long tagId : tagIds) {
      try {
        AssetTagServiceUtil.getTag(tagId);
      } catch (PrincipalException pe) {
        continue;
      }

      filteredTagIds.add(tagId);
    }

    return StringUtil.split(StringUtil.merge(filteredTagIds), 0L);
  }
Example #2
0
  @RequestMapping
  public String ver(
      RenderRequest request,
      RenderResponse response,
      @RequestParam(required = false) Integer dias,
      Model model) {
    log.debug("Viendo el versiculo");
    TimeZone tz = null;
    DateTimeZone zone = null;
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    try {
      tz = themeDisplay.getTimeZone();
      zone = DateTimeZone.forID(tz.getID());
    } catch (IllegalArgumentException e) {
      zone = DateTimeZone.forID(ZonaHorariaUtil.getConvertedId(tz.getID()));
    }
    try {
      long scopeGroupId = themeDisplay.getScopeGroupId();

      AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

      DateTime hoy =
          (DateTime)
              request.getPortletSession().getAttribute("hoy", PortletSession.APPLICATION_SCOPE);
      if (hoy == null) {
        hoy = new DateTime(zone);
        log.debug("Subiendo atributo hoy({}) a la sesion", hoy);
        request.getPortletSession().setAttribute("hoy", hoy, PortletSession.APPLICATION_SCOPE);
      }

      // Busca el contenido del dia
      String[] tags = TagsUtil.getTags(new String[4], hoy);
      tags[3] = "versiculo";

      long[] assetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupId, tags);

      assetEntryQuery.setAllTagIds(assetTagIds);

      List<AssetEntry> results = AssetEntryServiceUtil.getEntries(assetEntryQuery);

      log.debug("Buscando el versiculo de la semana {}", hoy);
      for (AssetEntry asset : results) {
        if (asset.getClassName().equals(JournalArticle.class.getName())) {
          JournalArticle ja = JournalArticleLocalServiceUtil.getLatestArticle(asset.getClassPK());
          String contenido =
              JournalArticleLocalServiceUtil.getArticleContent(
                  ja.getGroupId(),
                  ja.getArticleId(),
                  "view",
                  "" + themeDisplay.getLocale(),
                  themeDisplay);
          model.addAttribute("contenido", contenido);
        }
      }

    } catch (Exception e) {
      log.error("No se pudo cargar el contenido", e);
      throw new RuntimeException("No se pudo cargar el contenido", e);
    }

    return "versiculo/ver";
  }
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    long[] groupIds = getGroupIds();

    if (!ArrayUtil.contains(groupIds, themeDisplay.getScopeGroupId())) {
      groupIds = ArrayUtil.append(groupIds, themeDisplay.getScopeGroupId());
    }

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(_portletPreferences, groupIds);

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)
        && Validator.isNotNull(getDDMStructureFieldName())
        && Validator.isNotNull(getDDMStructureFieldValue())) {

      AssetRendererFactory assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
              PortalUtil.getClassName(classNameIds[0]));

      Tuple classTypeFieldName =
          assetRendererFactory.getClassTypeFieldName(
              classTypeIds[0], getDDMStructureFieldName(), themeDisplay.getLocale());

      long ddmStructureId = GetterUtil.getLong(classTypeFieldName.getObject(3));

      assetEntryQuery.setAttribute(
          "ddmStructureFieldName",
          DDMIndexerUtil.encodeName(
              ddmStructureId, getDDMStructureFieldName(), themeDisplay.getLocale()));
      assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
    }

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, assetEntryQuery);

    assetEntryQuery.setAllCategoryIds(getAllAssetCategoryIds());

    if (hasLayoutGroup(groupIds)) {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(groupIds, getAllAssetTagNames()));
    } else {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(getGroupIds(), getAllAssetTagNames()));
    }

    assetEntryQuery.setClassTypeIds(classTypeIds);
    assetEntryQuery.setEnablePermissions(isEnablePermissions());
    assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    String portletName = getPortletName();

    if (!portletName.equals(PortletKeys.RELATED_ASSETS)) {
      assetEntryQuery.setGroupIds(getGroupIds());
    }

    if (isShowOnlyLayoutAssets()) {
      assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    assetEntryQuery.setPaginationType(getPaginationType());
    assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    assetEntryQuery.setOrderByType1(getOrderByType1());
    assetEntryQuery.setOrderByType2(getOrderByType2());

    return assetEntryQuery;
  }
  @Override
  public AssetEntryQuery getAssetEntryQuery(
      PortletPreferences portletPreferences, long[] scopeGroupIds)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    long[] allAssetCategoryIds = new long[0];
    long[] anyAssetCategoryIds = new long[0];
    long[] notAllAssetCategoryIds = new long[0];
    long[] notAnyAssetCategoryIds = new long[0];

    String[] allAssetTagNames = new String[0];
    String[] anyAssetTagNames = new String[0];
    String[] notAllAssetTagNames = new String[0];
    String[] notAnyAssetTagNames = new String[0];

    for (int i = 0; true; i++) {
      String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

      if ((queryValues == null) || (queryValues.length == 0)) {
        break;
      }

      boolean queryContains =
          GetterUtil.getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
      boolean queryAndOperator =
          GetterUtil.getBoolean(
              portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
      String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

      if (Validator.equals(queryName, "assetCategories")) {
        long[] assetCategoryIds = GetterUtil.getLongValues(queryValues);

        if (queryContains && queryAndOperator) {
          allAssetCategoryIds = assetCategoryIds;
        } else if (queryContains && !queryAndOperator) {
          anyAssetCategoryIds = assetCategoryIds;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetCategoryIds = assetCategoryIds;
        } else {
          notAnyAssetCategoryIds = assetCategoryIds;
        }
      } else {
        if (queryContains && queryAndOperator) {
          allAssetTagNames = queryValues;
        } else if (queryContains && !queryAndOperator) {
          anyAssetTagNames = queryValues;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetTagNames = queryValues;
        } else {
          notAnyAssetTagNames = queryValues;
        }
      }
    }

    assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);

    for (String assetTagName : allAssetTagNames) {
      long[] allAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addAllTagIdsArray(allAssetTagIds);
    }

    assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);

    long[] anyAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, anyAssetTagNames);

    assetEntryQuery.setAnyTagIds(anyAssetTagIds);

    assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);

    for (String assetTagName : notAllAssetTagNames) {
      long[] notAllAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addNotAllTagIdsArray(notAllAssetTagIds);
    }

    assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);

    long[] notAnyAssetTagIds =
        AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, notAnyAssetTagNames);

    assetEntryQuery.setNotAnyTagIds(notAnyAssetTagIds);

    return assetEntryQuery;
  }