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;
  }
示例#2
0
  protected List<AssetEntry> getAssetEntries(
      PortletRequest portletRequest, PortletPreferences preferences) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(
            preferences, new long[] {themeDisplay.getScopeGroupId()});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds();

      long[] classNameIds = AssetPublisherUtil.getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    int rssDelta = GetterUtil.getInteger(preferences.getValue("rssDelta", "20"));

    assetEntryQuery.setEnd(rssDelta);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds =
        AssetPublisherUtil.getGroupIds(
            preferences, themeDisplay.getScopeGroupId(), themeDisplay.getLayout());

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

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

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    return AssetEntryServiceUtil.getEntries(assetEntryQuery);
  }
  @Override
  public List<AssetEntry> getAssetEntries(
      PortletPreferences preferences,
      Layout layout,
      long scopeGroupId,
      int max,
      boolean checkPermission)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(preferences, new long[] {scopeGroupId});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds =
          AssetRendererFactoryRegistryUtil.getClassNameIds(layout.getCompanyId());

      long[] classNameIds = getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    assetEntryQuery.setEnd(max);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds = getGroupIds(preferences, scopeGroupId, layout);

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

    if (showOnlyLayoutAssets) {
      assetEntryQuery.setLayout(layout);
    }

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    if (checkPermission) {
      return AssetEntryServiceUtil.getEntries(assetEntryQuery);
    } else {
      return AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
    }
  }