@Override
  protected String getTitle(
      JSONObject jsonObject, AssetRenderer<?> assetRenderer, ServiceContext serviceContext) {

    MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(jsonObject.getLong("classPK"));

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetRenderer.getClassName());

    String typeName = assetRendererFactory.getTypeName(serviceContext.getLocale());

    ResourceBundle resourceBundle =
        ResourceBundle.getBundle("content.Language", serviceContext.getLocale());

    if ((mbMessage != null) && mbMessage.isDiscussion()) {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-comment-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    } else {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    }
  }
Esempio n. 2
0
  protected String getEntryURLViewInContext(
      PortletRequest portletRequest, PortletResponse portletResponse, AssetEntry assetEntry)
      throws Exception {

    AssetRendererFactory assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetEntry.getClassName());

    AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

    String viewInContextURL =
        assetRenderer.getURLViewInContext(
            (LiferayPortletRequest) portletRequest, (LiferayPortletResponse) portletResponse, null);

    if (Validator.isNotNull(viewInContextURL)
        && !viewInContextURL.startsWith(Http.HTTP_WITH_SLASH)
        && !viewInContextURL.startsWith(Http.HTTPS_WITH_SLASH)) {

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

      viewInContextURL = themeDisplay.getPortalURL() + viewInContextURL;
    }

    return viewInContextURL;
  }
  protected static AssetRenderer doGetAssetRenderer(String className, long classPK)
      throws Exception {

    if (className.equals(MBThread.class.getName())) {
      className = MBMessage.class.getName();

      MBThread mbThread = MBThreadLocalServiceUtil.getThread(classPK);

      classPK = mbThread.getRootMessageId();
    }

    AssetRendererFactory assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

    return assetRendererFactory.getAssetRenderer(classPK);
  }
Esempio n. 4
0
  protected String getEntryURLAssetPublisher(
      PortletRequest portletRequest, PortletResponse portletResponse, AssetEntry assetEntry)
      throws Exception {

    AssetRendererFactory assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetEntry.getClassName());

    StringBundler sb = new StringBundler(4);

    sb.append(getAssetPublisherURL(portletRequest));
    sb.append(assetRendererFactory.getType());
    sb.append("/id/");
    sb.append(assetEntry.getEntryId());

    return sb.toString();
  }
  protected void setDDMStructure() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _ddmStructureDisplayFieldValue = StringPool.BLANK;
    _ddmStructureFieldLabel = StringPool.BLANK;
    _ddmStructureFieldName = StringPool.BLANK;
    _ddmStructureFieldValue = null;

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

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)) {

      _ddmStructureDisplayFieldValue =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureDisplayFieldValue", StringPool.BLANK));
      _ddmStructureFieldName =
          GetterUtil.getString(
              _portletPreferences.getValue("ddmStructureFieldName", StringPool.BLANK));
      _ddmStructureFieldValue =
          _portletPreferences.getValue("ddmStructureFieldValue", StringPool.BLANK);

      if (Validator.isNotNull(_ddmStructureFieldName)
          && Validator.isNotNull(_ddmStructureFieldValue)) {

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

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

        _ddmStructureFieldLabel = (String) classTypeFieldName.getObject(0);
      }
    }
  }
  protected String getArticleId(PortletRequest portletRequest) throws PortalException {

    long assetEntryId = GetterUtil.getLong(getParameter(portletRequest, "assetEntryId"));

    AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(assetEntryId);

    if (assetEntry == null) {
      return StringPool.BLANK;
    }

    JournalArticleAssetRendererFactory articleAssetRendererFactory =
        (JournalArticleAssetRendererFactory)
            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
                JournalArticle.class.getName());

    JournalArticleAssetRenderer articleAssetRenderer =
        (JournalArticleAssetRenderer)
            articleAssetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

    JournalArticle article = articleAssetRenderer.getArticle();

    return StringUtil.toUpperCase(article.getArticleId());
  }
 protected AssetRendererFactory getAssetRendererFactory() {
   return AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(getClassName());
 }
 @Override
 public AssetRendererFactory getAssetRendererFactory() {
   return AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(getClassName());
 }
  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;
  }
Esempio n. 10
0
  public static Map<String, PortletURL> getAddPortletURLs(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long groupId,
      long[] classNameIds,
      long[] classTypeIds,
      long[] allAssetCategoryIds,
      String[] allAssetTagNames,
      String redirect)
      throws Exception {

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

    Map<String, PortletURL> addPortletURLs =
        new TreeMap<>(new ModelResourceComparator(themeDisplay.getLocale()));

    for (long classNameId : classNameIds) {
      String className = PortalUtil.getClassName(classNameId);

      AssetRendererFactory<?> assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

      if (Validator.isNull(assetRendererFactory.getPortletId())) {
        continue;
      }

      Portlet portlet =
          PortletLocalServiceUtil.getPortletById(
              themeDisplay.getCompanyId(), assetRendererFactory.getPortletId());

      if (!portlet.isActive()) {
        continue;
      }

      ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

      List<ClassType> classTypes =
          classTypeReader.getAvailableClassTypes(
              PortalUtil.getCurrentAndAncestorSiteGroupIds(themeDisplay.getScopeGroupId()),
              themeDisplay.getLocale());

      if ((classTypeIds.length == 0) || classTypes.isEmpty()) {
        PortletURL addPortletURL =
            getAddPortletURL(
                liferayPortletRequest,
                liferayPortletResponse,
                groupId,
                className,
                0,
                allAssetCategoryIds,
                allAssetTagNames,
                redirect);

        if (addPortletURL != null) {
          addPortletURLs.put(className, addPortletURL);
        }
      }

      for (ClassType classType : classTypes) {
        long classTypeId = classType.getClassTypeId();

        if (ArrayUtil.contains(classTypeIds, classTypeId) || (classTypeIds.length == 0)) {

          PortletURL addPortletURL =
              getAddPortletURL(
                  liferayPortletRequest,
                  liferayPortletResponse,
                  groupId,
                  className,
                  classTypeId,
                  allAssetCategoryIds,
                  allAssetTagNames,
                  redirect);

          if (addPortletURL != null) {
            String mesage = className + CLASSNAME_SEPARATOR + classType.getName();

            addPortletURLs.put(mesage, addPortletURL);
          }
        }
      }
    }

    return addPortletURLs;
  }
Esempio n. 11
0
  public static PortletURL getAddPortletURL(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long groupId,
      String className,
      long classTypeId,
      long[] allAssetCategoryIds,
      String[] allAssetTagNames,
      String redirect)
      throws Exception {

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

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

    if ((assetRendererFactory == null)
        || !assetRendererFactory.hasAddPermission(
            themeDisplay.getPermissionChecker(), groupId, classTypeId)) {

      return null;
    }

    PortletURL addPortletURL =
        assetRendererFactory.getURLAdd(liferayPortletRequest, liferayPortletResponse, classTypeId);

    if (addPortletURL == null) {
      return null;
    }

    if (redirect != null) {
      addPortletURL.setParameter("redirect", redirect);
    }

    String referringPortletResource = ParamUtil.getString(liferayPortletRequest, "portletResource");

    if (Validator.isNotNull(referringPortletResource)) {
      addPortletURL.setParameter("referringPortletResource", referringPortletResource);
    } else {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      addPortletURL.setParameter("referringPortletResource", portletDisplay.getId());

      if (allAssetCategoryIds != null) {
        Map<Long, String> assetVocabularyAssetCategoryIds = new HashMap<>();

        for (long assetCategoryId : allAssetCategoryIds) {
          AssetCategory assetCategory =
              AssetCategoryLocalServiceUtil.fetchAssetCategory(assetCategoryId);

          if (assetCategory == null) {
            continue;
          }

          long assetVocabularyId = assetCategory.getVocabularyId();

          if (assetVocabularyAssetCategoryIds.containsKey(assetVocabularyId)) {

            String assetCategoryIds = assetVocabularyAssetCategoryIds.get(assetVocabularyId);

            assetVocabularyAssetCategoryIds.put(
                assetVocabularyId, assetCategoryIds + StringPool.COMMA + assetCategoryId);
          } else {
            assetVocabularyAssetCategoryIds.put(assetVocabularyId, String.valueOf(assetCategoryId));
          }
        }

        for (Map.Entry<Long, String> entry : assetVocabularyAssetCategoryIds.entrySet()) {

          long assetVocabularyId = entry.getKey();
          String assetCategoryIds = entry.getValue();

          addPortletURL.setParameter("assetCategoryIds_" + assetVocabularyId, assetCategoryIds);
        }
      }

      if (allAssetTagNames != null) {
        addPortletURL.setParameter("assetTagNames", StringUtil.merge(allAssetTagNames));
      }
    }

    addPortletURL.setPortletMode(PortletMode.VIEW);
    addPortletURL.setWindowState(LiferayWindowState.POP_UP);

    return addPortletURL;
  }