public String getClassName() {
    if (getClassNameId() <= 0) {
      return StringPool.BLANK;
    }

    return PortalUtil.getClassName(getClassNameId());
  }
  /**
   * Enables all activity counters of an asset identified by the class name ID and class primary
   * key.
   *
   * <p>This method is used by the recycle bin to enable all counters of assets restored from the
   * recycle bin. It adjusts the owner's contribution score.
   *
   * @param classNameId the primary key of the asset's class
   * @param classPK the primary key of the asset
   * @throws PortalException if the asset owner's contribution counter could not be updated
   */
  @Override
  public void enableActivityCounters(long classNameId, long classPK) throws PortalException {

    String className = PortalUtil.getClassName(classNameId);

    enableActivityCounters(className, classPK);
  }
  @Override
  public void deleteSubscription(Subscription subscription)
      throws PortalException, SystemException {

    // Subscription

    subscriptionPersistence.remove(subscription);

    // Social

    AssetEntry assetEntry =
        assetEntryPersistence.fetchByC_C(subscription.getClassNameId(), subscription.getClassPK());

    if (assetEntry != null) {
      String className = PortalUtil.getClassName(subscription.getClassNameId());

      socialActivityLocalService.addActivity(
          subscription.getUserId(),
          assetEntry.getGroupId(),
          className,
          subscription.getClassPK(),
          SocialActivityConstants.TYPE_UNSUBSCRIBE,
          StringPool.BLANK,
          0);

      socialEquityLogLocalService.deactivateEquityLogs(
          subscription.getUserId(),
          className,
          subscription.getClassPK(),
          ActionKeys.SUBSCRIBE,
          StringPool.BLANK);
    }
  }
  protected void setReferrerClassNameId(long referrerClassNameId) {
    if (referrerClassNameId > 0) {
      _referrerClassName = PortalUtil.getClassName(referrerClassNameId);
    } else {
      _referrerClassName = null;
    }

    _referrerClassNameId = referrerClassNameId;
  }
  public void reindex(List<AssetEntry> entries) throws PortalException {
    for (AssetEntry entry : entries) {
      String className = PortalUtil.getClassName(entry.getClassNameId());

      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);

      indexer.reindex(className, entry.getClassPK());
    }
  }
  protected void setClassNameId(long classNameId) {
    if (classNameId > 0) {
      _className = PortalUtil.getClassName(classNameId);
      _classSimpleName = getSimpleName(_className);
    } else {
      _className = null;
      _classSimpleName = null;
    }

    _classNameId = classNameId;
  }
  public static void getArticle(HttpServletRequest request) throws Exception {
    long groupId = ParamUtil.getLong(request, "groupId");
    long classNameId = ParamUtil.getLong(request, "classNameId");
    long classPK = ParamUtil.getLong(request, "classPK");
    String articleId = ParamUtil.getString(request, "articleId");
    String structureId = ParamUtil.getString(request, "structureId");

    JournalArticle article = null;

    if (Validator.isNotNull(articleId)) {
      article =
          JournalArticleServiceUtil.getLatestArticle(
              groupId, articleId, WorkflowConstants.STATUS_ANY);
    } else if ((classNameId > 0) && (classPK > 0)) {
      String className = PortalUtil.getClassName(classNameId);

      article = JournalArticleServiceUtil.getLatestArticle(groupId, className, classPK);
    } else if (Validator.isNotNull(structureId)) {
      JournalStructure structure = null;

      try {
        structure = JournalStructureServiceUtil.getStructure(groupId, structureId);
      } catch (NoSuchStructureException nsse1) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        if (groupId == themeDisplay.getCompanyGroupId()) {
          return;
        }

        try {
          structure =
              JournalStructureServiceUtil.getStructure(
                  themeDisplay.getCompanyGroupId(), structureId);
        } catch (NoSuchStructureException nsse2) {
          return;
        }
      }

      article =
          JournalArticleServiceUtil.getArticle(
              groupId, JournalStructure.class.getName(), structure.getId());

      article.setNew(true);

      article.setId(0);
      article.setClassNameId(0);
      article.setClassPK(0);
      article.setArticleId(null);
      article.setVersion(0);
    }

    request.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
  }
Esempio n. 8
0
  @Override
  public String[] getSearchClassNames() {
    long[] classNameIds = _assetEntryQuery.getClassNameIds();

    String[] classNames = new String[classNameIds.length];

    for (int i = 0; i < classNames.length; i++) {
      long classNameId = classNameIds[i];

      classNames[i] = PortalUtil.getClassName(classNameId);
    }

    return classNames;
  }
  /**
   * Deletes all activity counters, limits, and settings related to the entity identified by the
   * class name ID and class primary key.
   *
   * @param classNameId the primary key of the entity's class
   * @param classPK the primary key of the entity
   * @throws PortalException if the entity is an asset and its owner's contribution counter could
   *     not be updated
   */
  @Override
  public void deleteActivityCounters(long classNameId, long classPK) throws PortalException {

    String className = PortalUtil.getClassName(classNameId);

    if (!className.equals(User.class.getName())) {
      AssetEntry assetEntry = assetEntryLocalService.fetchEntry(className, classPK);

      deleteActivityCounters(assetEntry);
    } else {
      socialActivityCounterPersistence.removeByC_C(classNameId, classPK);

      socialActivityLimitPersistence.removeByUserId(classPK);
    }

    clearFinderCache();
  }
  @Override
  public void addPermissionFields(long companyId, Document document) {
    try {
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));

      String className = document.get(Field.ENTRY_CLASS_NAME);

      boolean relatedEntry = GetterUtil.getBoolean(document.get(Field.RELATED_ENTRY));

      if (relatedEntry) {
        long classNameId = GetterUtil.getLong(document.get(Field.CLASS_NAME_ID));

        className = PortalUtil.getClassName(classNameId);
      }

      if (Validator.isNull(className)) {
        return;
      }

      String classPK = document.get(Field.ROOT_ENTRY_CLASS_PK);

      if (Validator.isNull(classPK)) {
        classPK = document.get(Field.ENTRY_CLASS_PK);
      }

      if (relatedEntry) {
        classPK = document.get(Field.CLASS_PK);
      }

      if (Validator.isNull(classPK)) {
        return;
      }

      Indexer indexer = IndexerRegistryUtil.getIndexer(className);

      if (!indexer.isPermissionAware()) {
        return;
      }

      doAddPermissionFields_6(companyId, groupId, className, classPK, document);
    } catch (NoSuchResourceException nsre) {
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  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);
      }
    }
  }
 public ICollabActivityInterpreter getInterpreterForClass(Long classNameId) {
   return getInterpreterForClass(PortalUtil.getClassName(classNameId));
 }
  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. 14
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;
  }