public void addAssetCategories(Class<?> clazz, long classPK) throws SystemException {

    List<AssetCategory> assetCategories =
        AssetCategoryLocalServiceUtil.getCategories(clazz.getName(), classPK);

    _assetCategoryUuidsMap.put(
        getPrimaryKeyString(clazz, classPK),
        StringUtil.split(ListUtil.toString(assetCategories, AssetCategory.UUID_ACCESSOR)));
    _assetCategoryIdsMap.put(
        getPrimaryKeyString(clazz, classPK),
        StringUtil.split(
            ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L));
  }
  public List<KBArticle> getKBArticleAndAllDescendants(
      long resourcePrimKey, int status, OrderByComparator orderByComparator)
      throws SystemException {

    List<KBArticle> kbArticles = getKBArticles(new long[] {resourcePrimKey}, status, null);

    kbArticles = ListUtil.copy(kbArticles);

    Long[][] params = new Long[][] {new Long[] {resourcePrimKey}};

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
      List<KBArticle> curKBArticles = null;

      if (status == WorkflowConstants.STATUS_ANY) {
        curKBArticles = kbArticlePersistence.findByP_L(ArrayUtil.toArray(params[1]), true);
      } else if (status == WorkflowConstants.STATUS_APPROVED) {
        curKBArticles = kbArticlePersistence.findByP_M(ArrayUtil.toArray(params[1]), true);
      } else {
        curKBArticles = kbArticlePersistence.findByP_S(ArrayUtil.toArray(params[1]), status);
      }

      kbArticles.addAll(curKBArticles);

      long[] resourcePrimKeys =
          StringUtil.split(ListUtil.toString(curKBArticles, "resourcePrimKey"), 0L);

      params[0] = ArrayUtil.append(params[0], ArrayUtil.toArray(resourcePrimKeys));
    }

    if (orderByComparator != null) {
      kbArticles = ListUtil.sort(kbArticles, orderByComparator);
    }

    return new UnmodifiableList<KBArticle>(kbArticles);
  }
Esempio n. 3
0
  public static String getAssetKeywords(String className, long classPK) {
    List<AssetTag> tags = AssetTagLocalServiceUtil.getTags(className, classPK);
    List<AssetCategory> categories =
        AssetCategoryLocalServiceUtil.getCategories(className, classPK);

    StringBuffer sb = new StringBuffer();

    sb.append(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR));

    if (!tags.isEmpty()) {
      sb.append(StringPool.COMMA);
    }

    sb.append(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR));

    return sb.toString();
  }
  @Override
  public String[] getSelectedLabels(String selectLocator) {
    WebElement selectLocatorWebElement = getWebElement(selectLocator);

    Select select = new Select(selectLocatorWebElement);

    List<WebElement> allSelectedOptionsWebElements = select.getAllSelectedOptions();

    return StringUtil.split(ListUtil.toString(allSelectedOptionsWebElements, "text"));
  }
  public static boolean addBreadcrumbEntry(PortletRequest request, Entry entry, String currentURL)
      throws SystemException {

    HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);

    PortalUtil.addPortletBreadcrumbEntry(servletRequest, entry.getName(), currentURL);

    PortalUtil.setPageSubtitle(entry.getName(), servletRequest);
    PortalUtil.setPageDescription(entry.getName(), servletRequest);

    List<AssetTag> assetTags =
        AssetTagLocalServiceUtil.getTags(Guestbook.class.getName(), entry.getGuestbookId());
    PortalUtil.setPageKeywords(ListUtil.toString(assetTags, "name"), servletRequest);

    return true;
  }
  public AssetEntry updateAsset(
      long userId, FileEntry fileEntry, FileVersion fileVersion, long assetClassPk)
      throws PortalException, SystemException {

    long[] assetCategoryIds =
        assetCategoryLocalService.getCategoryIds(DLFileEntryConstants.getClassName(), assetClassPk);
    String[] assetTagNames =
        assetTagLocalService.getTagNames(DLFileEntryConstants.getClassName(), assetClassPk);

    AssetEntry assetEntry =
        assetEntryLocalService.getEntry(DLFileEntryConstants.getClassName(), assetClassPk);

    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(assetEntry.getEntryId());

    long[] assetLinkIds =
        StringUtil.split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);

    return updateAsset(
        userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, assetLinkIds);
  }
  @Override
  public void notifySubscribers(
      PortletPreferences preferences, long plid, String portletId, List<AssetEntry> assetEntries)
      throws PortalException, SystemException {

    if (!getEmailAssetEntryAddedEnabled(preferences) || assetEntries.isEmpty()) {

      return;
    }

    AssetEntry assetEntry = assetEntries.get(0);

    String fromName = getEmailFromName(preferences, assetEntry.getCompanyId());
    String fromAddress = getEmailFromAddress(preferences, assetEntry.getCompanyId());

    Map<Locale, String> localizedSubjectMap = getEmailAssetEntryAddedSubjectMap(preferences);
    Map<Locale, String> localizedBodyMap = getEmailAssetEntryAddedBodyMap(preferences);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setCompanyId(assetEntry.getCompanyId());
    subscriptionSender.setContextAttributes(
        "[$ASSET_ENTRIES$]",
        ListUtil.toString(assetEntries, _titleAccessor, StringPool.COMMA_AND_SPACE));
    subscriptionSender.setContextUserPrefix("ASSET_PUBLISHER");
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("asset_entry", assetEntry.getEntryId());
    subscriptionSender.setPortletId(PortletKeys.ASSET_PUBLISHER);
    subscriptionSender.setReplyToAddress(fromAddress);

    subscriptionSender.addPersistedSubscribers(
        com.liferay.portal.model.PortletPreferences.class.getName(),
        _getPortletPreferencesId(plid, portletId));

    subscriptionSender.flushNotificationsAsync();
  }
  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);
  }
 protected long[] getCategoryIds(List<AssetCategory> categories) {
   return StringUtil.split(ListUtil.toString(categories, "categoryId"), 0L);
 }
  public void updateStatus(
      long userId,
      FileEntry fileEntry,
      FileVersion latestFileVersion,
      int oldStatus,
      int newStatus,
      Map<String, Serializable> workflowContext)
      throws PortalException, SystemException {

    if (newStatus == WorkflowConstants.STATUS_APPROVED) {

      // Asset

      String latestFileVersionVersion = latestFileVersion.getVersion();

      if (latestFileVersionVersion.equals(fileEntry.getVersion())) {
        if (!latestFileVersionVersion.equals(DLFileEntryConstants.VERSION_DEFAULT)) {

          AssetEntry draftAssetEntry = null;

          try {
            long fileEntryTypeId = getFileEntryTypeId(fileEntry);

            draftAssetEntry =
                assetEntryLocalService.getEntry(
                    DLFileEntryConstants.getClassName(), latestFileVersion.getPrimaryKey());

            long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
            String[] assetTagNames = draftAssetEntry.getTagNames();

            List<AssetLink> assetLinks =
                assetLinkLocalService.getDirectLinks(
                    draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED);

            long[] assetLinkEntryIds =
                StringUtil.split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);

            AssetEntry assetEntry =
                assetEntryLocalService.updateEntry(
                    userId,
                    fileEntry.getGroupId(),
                    DLFileEntryConstants.getClassName(),
                    fileEntry.getFileEntryId(),
                    fileEntry.getUuid(),
                    fileEntryTypeId,
                    assetCategoryIds,
                    assetTagNames,
                    true,
                    null,
                    null,
                    null,
                    draftAssetEntry.getMimeType(),
                    fileEntry.getTitle(),
                    fileEntry.getDescription(),
                    null,
                    null,
                    null,
                    0,
                    0,
                    null,
                    false);

            assetLinkLocalService.updateLinks(
                userId,
                assetEntry.getEntryId(),
                assetLinkEntryIds,
                AssetLinkConstants.TYPE_RELATED);

            assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
          } catch (NoSuchEntryException nsee) {
          }
        }

        assetEntryLocalService.updateVisible(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(), true);
      }

      // Sync

      String event = (String) workflowContext.get("event");

      if (!isStagingGroup(fileEntry.getGroupId()) && Validator.isNotNull(event)) {

        if (event.equals(DLSyncConstants.EVENT_ADD)) {
          dlSyncLocalService.addSync(
              fileEntry.getFileEntryId(),
              fileEntry.getUuid(),
              fileEntry.getCompanyId(),
              fileEntry.getRepositoryId(),
              fileEntry.getFolderId(),
              fileEntry.getTitle(),
              fileEntry.getDescription(),
              DLSyncConstants.TYPE_FILE,
              fileEntry.getVersion());
        } else if (event.equals(DLSyncConstants.EVENT_UPDATE)) {
          dlSyncLocalService.updateSync(
              fileEntry.getFileEntryId(),
              fileEntry.getFolderId(),
              fileEntry.getTitle(),
              fileEntry.getDescription(),
              DLSyncConstants.EVENT_UPDATE,
              fileEntry.getVersion());
        }
      }

      // Social

      int activityType = DLActivityKeys.UPDATE_FILE_ENTRY;

      if (latestFileVersionVersion.equals(DLFileEntryConstants.VERSION_DEFAULT)) {

        activityType = DLActivityKeys.ADD_FILE_ENTRY;
      }

      if (oldStatus != WorkflowConstants.STATUS_IN_TRASH) {
        socialActivityLocalService.addUniqueActivity(
            latestFileVersion.getStatusByUserId(),
            fileEntry.getGroupId(),
            latestFileVersion.getCreateDate(),
            DLFileEntryConstants.getClassName(),
            fileEntry.getFileEntryId(),
            activityType,
            StringPool.BLANK,
            0);
      }
    } else {

      // Asset

      if (newStatus == WorkflowConstants.STATUS_IN_TRASH) {
        assetEntryLocalService.moveEntryToTrash(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
      } else {
        boolean visible = false;

        if (Validator.isNotNull(fileEntry.getVersion())) {
          visible = true;
        }

        assetEntryLocalService.updateVisible(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(), visible);
      }
    }
  }
  public void checkAssetEntry(long userId, FileEntry fileEntry, FileVersion fileVersion)
      throws PortalException, SystemException {

    AssetEntry fileEntryAssetEntry =
        assetEntryLocalService.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    long[] assetCategoryIds = new long[0];
    String[] assetTagNames = new String[0];

    long fileEntryTypeId = getFileEntryTypeId(fileEntry);

    if (fileEntryAssetEntry == null) {
      fileEntryAssetEntry =
          assetEntryLocalService.updateEntry(
              userId,
              fileEntry.getGroupId(),
              DLFileEntryConstants.getClassName(),
              fileEntry.getFileEntryId(),
              fileEntry.getUuid(),
              fileEntryTypeId,
              assetCategoryIds,
              assetTagNames,
              false,
              null,
              null,
              null,
              fileEntry.getMimeType(),
              fileEntry.getTitle(),
              fileEntry.getDescription(),
              null,
              null,
              null,
              0,
              0,
              null,
              false);
    }

    AssetEntry fileVersionAssetEntry =
        assetEntryLocalService.fetchEntry(
            DLFileEntryConstants.getClassName(), fileVersion.getFileVersionId());

    if ((fileVersionAssetEntry == null)
        && !fileVersion.isApproved()
        && !fileVersion.getVersion().equals(DLFileEntryConstants.VERSION_DEFAULT)) {

      assetCategoryIds =
          assetCategoryLocalService.getCategoryIds(
              DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());
      assetTagNames =
          assetTagLocalService.getTagNames(
              DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

      fileVersionAssetEntry =
          assetEntryLocalService.updateEntry(
              userId,
              fileEntry.getGroupId(),
              DLFileEntryConstants.getClassName(),
              fileVersion.getFileVersionId(),
              fileEntry.getUuid(),
              fileEntryTypeId,
              assetCategoryIds,
              assetTagNames,
              false,
              null,
              null,
              null,
              fileEntry.getMimeType(),
              fileEntry.getTitle(),
              fileEntry.getDescription(),
              null,
              null,
              null,
              0,
              0,
              null,
              false);

      List<AssetLink> assetLinks =
          assetLinkLocalService.getDirectLinks(fileEntryAssetEntry.getEntryId());

      long[] assetLinkIds =
          StringUtil.split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);

      assetLinkLocalService.updateLinks(
          userId,
          fileVersionAssetEntry.getEntryId(),
          assetLinkIds,
          AssetLinkConstants.TYPE_RELATED);
    }
  }
Esempio n. 12
0
  protected Object[] updateGroup(ActionRequest actionRequest) throws Exception {

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

    long userId = PortalUtil.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    long parentGroupId =
        ParamUtil.getLong(
            actionRequest,
            "parentGroupSearchContainerPrimaryKeys",
            GroupConstants.DEFAULT_PARENT_GROUP_ID);
    String name = null;
    String description = null;
    int type = 0;
    String friendlyURL = null;
    boolean active = false;

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    Group liveGroup = null;
    String oldFriendlyURL = null;
    String oldStagingFriendlyURL = null;

    if (liveGroupId <= 0) {

      // Add group

      name = ParamUtil.getString(actionRequest, "name");
      description = ParamUtil.getString(actionRequest, "description");
      type = ParamUtil.getInteger(actionRequest, "type");
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
      active = ParamUtil.getBoolean(actionRequest, "active");

      liveGroup =
          GroupServiceUtil.addGroup(
              parentGroupId,
              GroupConstants.DEFAULT_LIVE_GROUP_ID,
              name,
              description,
              type,
              friendlyURL,
              true,
              active,
              serviceContext);

      LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

      // Update group

      liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);

      oldFriendlyURL = liveGroup.getFriendlyURL();

      name = ParamUtil.getString(actionRequest, "name", liveGroup.getName());
      description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription());
      type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType());
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
      active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive());

      liveGroup =
          GroupServiceUtil.updateGroup(
              liveGroupId,
              parentGroupId,
              name,
              description,
              type,
              friendlyURL,
              active,
              serviceContext);

      if (type == GroupConstants.TYPE_SITE_OPEN) {
        List<MembershipRequest> membershipRequests =
            MembershipRequestLocalServiceUtil.search(
                liveGroupId,
                MembershipRequestConstants.STATUS_PENDING,
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        for (MembershipRequest membershipRequest : membershipRequests) {
          MembershipRequestServiceUtil.updateStatus(
              membershipRequest.getMembershipRequestId(),
              themeDisplay.translate("your-membership-has-been-approved"),
              MembershipRequestConstants.STATUS_APPROVED,
              serviceContext);

          LiveUsers.joinGroup(
              themeDisplay.getCompanyId(),
              membershipRequest.getGroupId(),
              new long[] {membershipRequest.getUserId()});
        }
      }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName =
        ParamUtil.getString(
            actionRequest,
            "customJspServletContextName",
            typeSettingsProperties.getProperty("customJspServletContextName"));

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    typeSettingsProperties.setProperty(
        "defaultSiteRoleIds",
        ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA));
    typeSettingsProperties.setProperty(
        "defaultTeamIds",
        ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

    String[] analyticsTypes =
        PrefsPropsUtil.getStringArray(
            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE);

    for (String analyticsType : analyticsTypes) {
      if (analyticsType.equalsIgnoreCase("google")) {
        String googleAnalyticsId =
            ParamUtil.getString(
                actionRequest,
                "googleAnalyticsId",
                typeSettingsProperties.getProperty("googleAnalyticsId"));

        typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);
      } else {
        String analyticsScript =
            ParamUtil.getString(
                actionRequest,
                SitesUtil.ANALYTICS_PREFIX + analyticsType,
                typeSettingsProperties.getProperty(analyticsType));

        typeSettingsProperties.setProperty(
            SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript);
      }
    }

    String publicRobots =
        ParamUtil.getString(
            actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt"));
    String privateRobots =
        ParamUtil.getString(
            actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt"));

    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);

    int trashEnabled =
        ParamUtil.getInteger(
            actionRequest,
            "trashEnabled",
            GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled")));

    typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled));

    int trashEntriesMaxAgeCompany =
        PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);

    int defaultTrashEntriesMaxAgeGroup =
        GetterUtil.getInteger(
            typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany);

    int trashEntriesMaxAgeGroup =
        ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup);

    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
      typeSettingsProperties.setProperty(
          "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup));
    } else {
      typeSettingsProperties.remove("trashEntriesMaxAge");
    }

    // Virtual hosts

    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    String publicVirtualHost =
        ParamUtil.getString(
            actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();

    String privateVirtualHost =
        ParamUtil.getString(
            actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    // Staging

    if (liveGroup.hasStagingGroup()) {
      Group stagingGroup = liveGroup.getStagingGroup();

      oldStagingFriendlyURL = stagingGroup.getFriendlyURL();

      friendlyURL =
          ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL());

      GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);

      LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet();

      publicVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPublicVirtualHost",
              stagingPublicLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

      LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet();

      privateVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPrivateVirtualHost",
              stagingPrivateLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);
    }

    liveGroup =
        GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    if (!liveGroup.isStaged()) {
      long privateLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
      long publicLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

      boolean privateLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "privateLayoutSetPrototypeLinkEnabled",
              privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
      boolean publicLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "publicLayoutSetPrototypeLinkEnabled",
              publicLayoutSet.isLayoutSetPrototypeLinkEnabled());

      if ((privateLayoutSetPrototypeId == 0)
          && (publicLayoutSetPrototypeId == 0)
          && !privateLayoutSetPrototypeLinkEnabled
          && !publicLayoutSetPrototypeLinkEnabled) {

        long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
        int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");
        boolean layoutSetPrototypeLinkEnabled =
            ParamUtil.getBoolean(
                actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0));

        if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
          privateLayoutSetPrototypeId = layoutSetPrototypeId;

          privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        } else {
          publicLayoutSetPrototypeId = layoutSetPrototypeId;

          publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        }
      }

      SitesUtil.updateLayoutSetPrototypesLinks(
          liveGroup,
          publicLayoutSetPrototypeId,
          privateLayoutSetPrototypeId,
          publicLayoutSetPrototypeLinkEnabled,
          privateLayoutSetPrototypeLinkEnabled);
    }

    // Staging

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false));

    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive()
        && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {

      if ((refererPlid > 0)
          && liveGroup.hasStagingGroup()
          && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {

        Layout firstLayout =
            LayoutLocalServiceUtil.fetchFirstLayout(
                liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

        if (firstLayout == null) {
          firstLayout =
              LayoutLocalServiceUtil.fetchFirstLayout(
                  liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
        }

        if (firstLayout != null) {
          refererPlid = firstLayout.getPlid();
        } else {
          refererPlid = 0;
        }
      }

      StagingUtil.updateStaging(actionRequest, liveGroup);
    }

    return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
  }
Esempio n. 13
0
 protected String[] getTagNames(List<AssetTag> tags) {
   return StringUtil.split(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR));
 }
 protected String[] getCategoryNames(List<AssetCategory> categories) {
   return StringUtil.split(ListUtil.toString(categories, "name"));
 }
  @Override
  public String getActualURL(
      long companyId,
      long groupId,
      boolean privateLayout,
      String mainPath,
      String friendlyURL,
      Map<String, String[]> params,
      Map<String, Object> requestContext)
      throws PortalException {

    String urlTitle =
        friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle =
        _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = PortalUtil.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
      actualParams.setParentMap(params);
    }

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId =
        typeSettingsProperties.get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
      PortletInstance portletInstance =
          new PortletInstance(AssetPublisherPortletKeys.ASSET_PUBLISHER);

      defaultAssetPublisherPortletId = portletInstance.getPortletInstanceKey();
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
      String actualPortletAuthenticationToken =
          AuthTokenUtil.getToken(request, layout.getPlid(), defaultAssetPublisherPortletId);

      actualParams.put("p_p_auth", new String[] {actualPortletAuthenticationToken});
    }

    actualParams.put("p_p_id", new String[] {defaultAssetPublisherPortletId});
    actualParams.put("p_p_lifecycle", new String[] {"0"});

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
      actualParams.put("p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
    }

    actualParams.put("p_p_mode", new String[] {"view"});
    actualParams.put("p_j_a_id", new String[] {String.valueOf(journalArticle.getId())});

    String namespace = PortalUtil.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] {"/view_content.jsp"});

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] {assetRendererFactory.getType()});

    actualParams.put(namespace + "urlTitle", new String[] {journalArticle.getUrlTitle()});

    String queryString = HttpUtil.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
      layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
      layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = PortalUtil.getLocale(request);

    PortalUtil.addPageSubtitle(journalArticle.getTitle(locale), request);
    PortalUtil.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags =
        _assetTagLocalService.getTags(
            JournalArticle.class.getName(), journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
      PortalUtil.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
  }
  private void _checkAssetEntries(com.liferay.portal.model.PortletPreferences portletPreferences)
      throws PortalException, SystemException {

    Layout layout = LayoutLocalServiceUtil.getLayout(portletPreferences.getPlid());

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.fromXML(
            layout.getCompanyId(),
            portletPreferences.getOwnerId(),
            portletPreferences.getOwnerType(),
            portletPreferences.getPlid(),
            portletPreferences.getPortletId(),
            portletPreferences.getPreferences());

    if (!getEmailAssetEntryAddedEnabled(preferences)) {
      return;
    }

    List<AssetEntry> assetEntries =
        getAssetEntries(
            preferences,
            layout,
            layout.getGroupId(),
            PropsValues.ASSET_PUBLISHER_DYNAMIC_SUBSCRIPTION_LIMIT,
            false);

    if (assetEntries.isEmpty()) {
      return;
    }

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

    List<AssetEntry> newAssetEntries = new ArrayList<AssetEntry>();

    for (int i = 0; i < assetEntries.size(); i++) {
      AssetEntry assetEntry = assetEntries.get(i);

      if (!ArrayUtil.contains(notifiedAssetEntryIds, assetEntry.getEntryId())) {

        newAssetEntries.add(assetEntry);
      }
    }

    notifySubscribers(
        preferences,
        portletPreferences.getPlid(),
        portletPreferences.getPortletId(),
        newAssetEntries);

    try {
      preferences.setValues(
          "notifiedAssetEntryIds",
          StringUtil.split(ListUtil.toString(assetEntries, AssetEntry.ENTRY_ID_ACCESSOR)));

      preferences.store();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    } catch (PortletException pe) {
      throw new SystemException(pe);
    }
  }
 protected String[] getCategoryNames(List<AssetCategory> categories) {
   return StringUtil.split(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR));
 }
 protected long[] getCategoryIds(List<AssetCategory> categories) {
   return StringUtil.split(ListUtil.toString(categories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L);
 }