コード例 #1
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};
  }
コード例 #2
0
  protected void setPortletScope(PortletDataContext portletDataContext, Element portletElement) {

    // Portlet data scope

    String scopeLayoutUuid =
        GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid"));
    String scopeLayoutType =
        GetterUtil.getString(portletElement.attributeValue("scope-layout-type"));

    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
    portletDataContext.setScopeType(scopeLayoutType);

    // Layout scope

    try {
      Group scopeGroup = null;

      if (scopeLayoutType.equals("company")) {
        scopeGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());
      } else if (Validator.isNotNull(scopeLayoutUuid)) {
        Layout scopeLayout =
            LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
                scopeLayoutUuid, portletDataContext.getGroupId());

        if (scopeLayout.hasScopeGroup()) {
          scopeGroup = scopeLayout.getScopeGroup();
        } else {
          String name = String.valueOf(scopeLayout.getPlid());

          scopeGroup =
              GroupLocalServiceUtil.addGroup(
                  portletDataContext.getUserId(null),
                  Layout.class.getName(),
                  scopeLayout.getPlid(),
                  name,
                  null,
                  0,
                  null,
                  false,
                  true,
                  null);
        }

        Group group = scopeLayout.getGroup();

        if (group.isStaged() && !group.isStagedRemotely()) {
          try {
            Layout oldLayout =
                LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
                    scopeLayoutUuid, portletDataContext.getSourceGroupId());

            Group oldScopeGroup = oldLayout.getScopeGroup();

            oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId());

            GroupLocalServiceUtil.updateGroup(oldScopeGroup, true);
          } catch (NoSuchLayoutException nsle) {
            if (_log.isWarnEnabled()) {
              _log.warn(nsle);
            }
          }
        }

        portletDataContext.setScopeGroupId(scopeGroup.getGroupId());
      }
    } catch (PortalException pe) {
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
コード例 #3
0
  protected static String exportDLFileEntries(
      PortletDataContext portletDataContext,
      Element dlFileEntryTypesElement,
      Element dlFoldersElement,
      Element dlFileEntriesElement,
      Element dlFileRanksElement,
      Element dlRepositoriesElement,
      Element dlRepositoryEntriesElement,
      Element entityElement,
      String content,
      boolean checkDateRange)
      throws Exception {

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId());

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    if (group.isStaged()
        && !group.isStagedRemotely()
        && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

      return content;
    }

    StringBuilder sb = new StringBuilder(content);

    int beginPos = content.length();
    int currentLocation = -1;

    boolean legacyURL = true;

    while (true) {
      String contextPath = PortalUtil.getPathContext();

      currentLocation =
          content.lastIndexOf(contextPath.concat("/c/document_library/get_file?"), beginPos);

      if (currentLocation == -1) {
        currentLocation =
            content.lastIndexOf(contextPath.concat("/image/image_gallery?"), beginPos);
      }

      if (currentLocation == -1) {
        currentLocation = content.lastIndexOf(contextPath.concat("/documents/"), beginPos);

        legacyURL = false;
      }

      if (currentLocation == -1) {
        return sb.toString();
      }

      beginPos = currentLocation + contextPath.length();

      int endPos1 = content.indexOf(CharPool.APOSTROPHE, beginPos);
      int endPos2 = content.indexOf(CharPool.CLOSE_BRACKET, beginPos);
      int endPos3 = content.indexOf(CharPool.CLOSE_CURLY_BRACE, beginPos);
      int endPos4 = content.indexOf(CharPool.CLOSE_PARENTHESIS, beginPos);
      int endPos5 = content.indexOf(CharPool.LESS_THAN, beginPos);
      int endPos6 = content.indexOf(CharPool.QUESTION, beginPos);
      int endPos7 = content.indexOf(CharPool.QUOTE, beginPos);
      int endPos8 = content.indexOf(CharPool.SPACE, beginPos);

      int endPos = endPos1;

      if ((endPos == -1) || ((endPos2 != -1) && (endPos2 < endPos))) {
        endPos = endPos2;
      }

      if ((endPos == -1) || ((endPos3 != -1) && (endPos3 < endPos))) {
        endPos = endPos3;
      }

      if ((endPos == -1) || ((endPos4 != -1) && (endPos4 < endPos))) {
        endPos = endPos4;
      }

      if ((endPos == -1) || ((endPos5 != -1) && (endPos5 < endPos))) {
        endPos = endPos5;
      }

      if ((endPos == -1) || ((endPos6 != -1) && (endPos6 < endPos) && !legacyURL)) {

        endPos = endPos6;
      }

      if ((endPos == -1) || ((endPos7 != -1) && (endPos7 < endPos))) {
        endPos = endPos7;
      }

      if ((endPos == -1) || ((endPos8 != -1) && (endPos8 < endPos))) {
        endPos = endPos8;
      }

      if ((beginPos == -1) || (endPos == -1)) {
        break;
      }

      try {
        String oldParameters = content.substring(beginPos, endPos);

        while (oldParameters.contains(StringPool.AMPERSAND_ENCODED)) {
          oldParameters = oldParameters.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
        }

        Map<String, String[]> map = new HashMap<String, String[]>();

        if (oldParameters.startsWith("/documents/")) {
          String[] pathArray = oldParameters.split(StringPool.SLASH);

          map.put("groupId", new String[] {pathArray[2]});

          if (pathArray.length == 4) {
            map.put("uuid", new String[] {pathArray[3]});
          } else if (pathArray.length == 5) {
            map.put("folderId", new String[] {pathArray[3]});

            String title = HttpUtil.decodeURL(pathArray[4]);

            int pos = title.indexOf(StringPool.QUESTION);

            if (pos != -1) {
              title = title.substring(0, pos);
            }

            map.put("title", new String[] {title});
          } else if (pathArray.length > 5) {
            String uuid = pathArray[5];

            int pos = uuid.indexOf(StringPool.QUESTION);

            if (pos != -1) {
              uuid = uuid.substring(0, pos);
            }

            map.put("uuid", new String[] {uuid});
          }
        } else {
          oldParameters = oldParameters.substring(oldParameters.indexOf(CharPool.QUESTION) + 1);

          map = HttpUtil.parameterMapFromString(oldParameters);
        }

        FileEntry fileEntry = null;

        String uuid = MapUtil.getString(map, "uuid");

        if (Validator.isNotNull(uuid)) {
          String groupIdString = MapUtil.getString(map, "groupId");

          long groupId = GetterUtil.getLong(groupIdString);

          if (groupIdString.equals("@group_id@")) {
            groupId = portletDataContext.getScopeGroupId();
          }

          fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
        } else {
          String folderIdString = MapUtil.getString(map, "folderId");

          if (Validator.isNotNull(folderIdString)) {
            long folderId = GetterUtil.getLong(folderIdString);
            String name = MapUtil.getString(map, "name");
            String title = MapUtil.getString(map, "title");

            String groupIdString = MapUtil.getString(map, "groupId");

            long groupId = GetterUtil.getLong(groupIdString);

            if (groupIdString.equals("@group_id@")) {
              groupId = portletDataContext.getScopeGroupId();
            }

            if (Validator.isNotNull(title)) {
              fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, title);
            } else {
              DLFileEntry dlFileEntry =
                  DLFileEntryLocalServiceUtil.getFileEntryByName(groupId, folderId, name);

              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          } else if (map.containsKey("image_id")
              || map.containsKey("img_id")
              || map.containsKey("i_id")) {

            long imageId = MapUtil.getLong(map, "image_id");

            if (imageId <= 0) {
              imageId = MapUtil.getLong(map, "img_id");

              if (imageId <= 0) {
                imageId = MapUtil.getLong(map, "i_id");
              }
            }

            DLFileEntry dlFileEntry =
                DLFileEntryLocalServiceUtil.fetchFileEntryByAnyImageId(imageId);

            if (dlFileEntry != null) {
              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          }
        }

        if (fileEntry == null) {
          beginPos--;

          continue;
        }

        beginPos = currentLocation;

        DLPortletDataHandler.exportFileEntry(
            portletDataContext,
            dlFileEntryTypesElement,
            dlFoldersElement,
            dlFileEntriesElement,
            dlFileRanksElement,
            dlRepositoriesElement,
            dlRepositoryEntriesElement,
            fileEntry,
            checkDateRange);

        Element dlReferenceElement = entityElement.addElement("dl-reference");

        dlReferenceElement.addAttribute(
            "default-repository", String.valueOf(fileEntry.isDefaultRepository()));

        String path = null;

        if (fileEntry.isDefaultRepository()) {
          path = DLPortletDataHandler.getFileEntryPath(portletDataContext, fileEntry);

        } else {
          path =
              DLPortletDataHandler.getRepositoryEntryPath(
                  portletDataContext, fileEntry.getFileEntryId());
        }

        dlReferenceElement.addAttribute("path", path);

        String dlReference = "[$dl-reference=" + path + "$]";

        sb.replace(beginPos, endPos, dlReference);
      } catch (Exception e) {
        if (_log.isDebugEnabled()) {
          _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
          _log.warn(e.getMessage());
        }
      }

      beginPos--;
    }

    return sb.toString();
  }
コード例 #4
0
  @Override
  public String getDescriptiveName(Locale locale) throws PortalException {
    Group curGroup = this;

    String name = getName(locale);

    if (Validator.isNull(name)) {
      Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(getGroupId());

      name = getName(siteDefaultLocale);
    }

    if (isCompany() && !isCompanyStagingGroup()) {
      name = LanguageUtil.get(locale, "global");
    } else if (isControlPanel()) {
      name = LanguageUtil.get(locale, "control-panel");
    } else if (isGuest()) {
      Company company = CompanyLocalServiceUtil.getCompany(getCompanyId());

      Account account = company.getAccount();

      name = account.getName();
    } else if (isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());

      name = layout.getName(locale);
    } else if (isLayoutPrototype()) {
      LayoutPrototype layoutPrototype =
          LayoutPrototypeLocalServiceUtil.getLayoutPrototype(getClassPK());

      name = layoutPrototype.getName(locale);
    } else if (isLayoutSetPrototype()) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(getClassPK());

      name = layoutSetPrototype.getName(locale);
    } else if (isOrganization()) {
      long organizationId = getOrganizationId();

      Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

      name = organization.getName();

      curGroup = organization.getGroup();
    } else if (isUser()) {
      long userId = getClassPK();

      User user = UserLocalServiceUtil.getUser(userId);

      name = user.getFullName();
    } else if (isUserGroup()) {
      long userGroupId = getClassPK();

      UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId);

      name = userGroup.getName();
    } else if (isUserPersonalSite()) {
      name = LanguageUtil.get(locale, "user-personal-site");
    }

    if (curGroup.isStaged() && !curGroup.isStagedRemotely() && curGroup.isStagingGroup()) {

      Group liveGroup = getLiveGroup();

      name = liveGroup.getDescriptiveName(locale);
    }

    return name;
  }