protected void getRootFolders(CommandArgument argument, Document doc, Element foldersEl)
      throws Exception {

    LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();

    groupParams.put("usersGroups", new Long(argument.getUserId()));

    List<Group> groups =
        GroupLocalServiceUtil.search(
            argument.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    List<Organization> userOrgs =
        OrganizationLocalServiceUtil.getUserOrganizations(argument.getUserId(), true);

    for (Organization organization : userOrgs) {
      groups.add(0, organization.getGroup());
    }

    if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED
        || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {

      Group userGroup =
          GroupLocalServiceUtil.getUserGroup(argument.getCompanyId(), argument.getUserId());

      groups.add(0, userGroup);
    }

    ThemeDisplay themeDisplay = argument.getThemeDisplay();

    long scopeGroupId = themeDisplay.getScopeGroupId();

    for (Group group : groups) {
      Element folderEl = doc.createElement("Folder");

      foldersEl.appendChild(folderEl);

      boolean setNameAttribute = false;

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

        if (stagingGroup.getGroupId() == scopeGroupId) {
          folderEl.setAttribute(
              "name",
              stagingGroup.getGroupId()
                  + " - "
                  + HtmlUtil.escape(stagingGroup.getDescriptiveName()));

          setNameAttribute = true;
        }
      }

      if (!setNameAttribute) {
        folderEl.setAttribute(
            "name", group.getGroupId() + " - " + HtmlUtil.escape(group.getDescriptiveName()));
      }
    }
  }
  private void _buildParentGroupsBreadcrumb(
      LayoutSet layoutSet, PortletURL portletURL, ThemeDisplay themeDisplay, StringBundler sb)
      throws Exception {
    Group group = layoutSet.getGroup();

    if (group.isOrganization()) {
      Organization organization =
          OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());

      Organization parentOrganization = organization.getParentOrganization();

      if (parentOrganization != null) {
        Group parentGroup = parentOrganization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    } else if (group.isUser()) {
      User groupUser = UserLocalServiceUtil.getUser(group.getClassPK());

      List<Organization> organizations =
          OrganizationLocalServiceUtil.getUserOrganizations(groupUser.getUserId(), true);

      if (!organizations.isEmpty()) {
        Organization organization = organizations.get(0);

        Group parentGroup = organization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    }

    int layoutsPageCount = 0;

    if (layoutSet.isPrivateLayout()) {
      layoutsPageCount = group.getPrivateLayoutsPageCount();
    } else {
      layoutsPageCount = group.getPublicLayoutsPageCount();
    }

    if ((layoutsPageCount > 0) && !group.getName().equals(GroupConstants.GUEST)) {
      String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay);

      sb.append("<li><span><a href=\"");
      sb.append(layoutSetFriendlyURL);
      sb.append("\">");
      sb.append(HtmlUtil.escape(group.getDescriptiveName()));
      sb.append("</a></span></li>");
    }
  }
  protected Map<Locale, String> getCalendarNameMap(
      PortletDataContext portletDataContext, Calendar calendar) throws Exception {

    Group sourceGroup = _groupLocalService.fetchGroup(portletDataContext.getSourceGroupId());

    String calendarName = calendar.getName(LocaleUtil.getDefault());

    if ((sourceGroup == null) || !calendarName.equals(sourceGroup.getDescriptiveName())) {

      return calendar.getNameMap();
    }

    Map<Locale, String> calendarNameMap = new HashMap<>();

    Group scopeGroup = _groupLocalService.getGroup(portletDataContext.getScopeGroupId());

    calendarNameMap.put(LocaleUtil.getDefault(), scopeGroup.getDescriptiveName());

    return calendarNameMap;
  }
  public String getGroupEntriesRSS(
      long groupId,
      int max,
      String type,
      double version,
      String displayStyle,
      String feedURL,
      String entryURL)
      throws PortalException, SystemException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    String name = group.getDescriptiveName();

    List blogsEntries = getGroupEntries(groupId, max);

    return exportToRSS(name, null, type, version, displayStyle, feedURL, entryURL, blogsEntries);
  }
Exemple #5
0
  /** @deprecated As of 6.2.0, replaced by {@link #getGroupName(long, ServiceContext)} */
  protected String getGroupName(long groupId, ThemeDisplay themeDisplay) {
    try {
      if (groupId <= 0) {
        return StringPool.BLANK;
      }

      Group group = GroupLocalServiceUtil.getGroup(groupId);

      String groupName = group.getDescriptiveName();

      if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
        return HtmlUtil.escape(groupName);
      }

      String groupDisplayURL =
          themeDisplay.getPortalURL()
              + themeDisplay.getPathMain()
              + "/my_sites/view?groupId="
              + group.getGroupId();

      if (group.hasPublicLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=0";
      } else if (group.hasPrivateLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=1";
      } else {
        return HtmlUtil.escape(groupName);
      }

      groupName =
          "<a class=\"group\" href=\""
              + groupDisplayURL
              + "\">"
              + HtmlUtil.escape(groupName)
              + "</a>";

      return groupName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  public static String getTitleText(Locale locale, String className, long classPK, String title)
      throws PortalException, SystemException {

    if (Validator.isNotNull(title)) {
      return title;
    }

    if (className.equals(BlogsEntry.class.getName())) {
      title = "Blog at ";
    } else if (className.equals(BookmarksFolder.class.getName())) {
      BookmarksFolder bookmarksFolder = BookmarksFolderLocalServiceUtil.getBookmarksFolder(classPK);

      return bookmarksFolder.getName();
    } else if (className.equals(Layout.class.getName())) {
      Layout layout = LayoutLocalServiceUtil.getLayout(classPK);

      return layout.getName(locale);
    } else if (className.equals(MBCategory.class.getName())) {
      title = "Message Board at ";
    } else if (className.equals(WikiNode.class.getName())) {
      WikiNode wikiNode = WikiNodeLocalServiceUtil.getWikiNode(classPK);

      return wikiNode.getName();
    }

    try {
      Group group = GroupLocalServiceUtil.getGroup(classPK);

      title += group.getDescriptiveName(locale);
    } catch (Exception e) {
    }

    if (Validator.isNull(title)) {
      title = String.valueOf(classPK);
    }

    return title;
  }
  protected void sendEmail(
      String emailAddress, MemberRequest memberRequest, ThemeDisplay themeDisplay)
      throws Exception {

    long companyId = memberRequest.getCompanyId();

    Group group = groupLocalService.getGroup(memberRequest.getGroupId());

    User user = userLocalService.getUser(memberRequest.getUserId());

    User receiverUser = null;

    if (memberRequest.getReceiverUserId() > 0) {
      receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId());
    }

    String fromName = PrefsPropsUtil.getString(companyId, "admin.email.from.name");
    String fromAddress = PrefsPropsUtil.getString(companyId, "admin.email.from.address");

    String toName = StringPool.BLANK;
    String toAddress = emailAddress;

    if (receiverUser != null) {
      toName = receiverUser.getFullName();
    }

    ClassLoader classLoader = getClass().getClassLoader();

    String subject =
        StringUtil.read(classLoader, "com/liferay/so/invitemembers/dependencies/subject.tmpl");

    String body = StringPool.BLANK;

    if (memberRequest.getReceiverUserId() > 0) {
      body =
          StringUtil.read(
              classLoader,
              "com/liferay/so/invitemembers/dependencies/" + "existing_user_body.tmpl");
    } else {
      body =
          StringUtil.read(
              classLoader, "com/liferay/so/invitemembers/dependencies/" + "new_user_body.tmpl");
    }

    String createAccountURL = getCreateAccountURL(memberRequest.getKey(), themeDisplay);
    String loginURL = getLoginURL(memberRequest.getKey(), themeDisplay);

    subject =
        StringUtil.replace(
            subject,
            new String[] {"[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]"},
            new String[] {group.getDescriptiveName(), user.getFullName()});

    body =
        StringUtil.replace(
            body,
            new String[] {
              "[$ADMIN_ADDRESS$]",
              "[$ADMIN_NAME$]",
              "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]",
              "[$MEMBER_REQUEST_GROUP$]",
              "[$MEMBER_REQUEST_LOGIN_URL$]",
              "[$MEMBER_REQUEST_USER$]"
            },
            new String[] {
              fromAddress,
              fromName,
              createAccountURL,
              group.getDescriptiveName(),
              loginURL,
              user.getFullName()
            });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

    MailServiceUtil.sendEmail(mailMessage);
  }
  @Override
  public String getCategoryMessagesRSS(
      long groupId,
      long categoryId,
      int status,
      int max,
      String type,
      double version,
      String displayStyle,
      String feedURL,
      String entryURL,
      ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    String name = StringPool.BLANK;
    String description = StringPool.BLANK;

    MBCategory category = mbCategoryLocalService.fetchMBCategory(categoryId);

    if (category == null) {
      Group group = groupLocalService.getGroup(categoryId);

      groupId = group.getGroupId();
      categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
      name = group.getDescriptiveName();
      description = group.getDescription();
    } else {
      groupId = category.getGroupId();
      name = category.getName();
      description = category.getDescription();
    }

    List<MBMessage> messages = new ArrayList<MBMessage>();

    int lastIntervalStart = 0;
    boolean listNotExhausted = true;
    MessageCreateDateComparator comparator = new MessageCreateDateComparator(false);

    while ((messages.size() < max) && listNotExhausted) {
      List<MBMessage> messageList =
          mbMessageLocalService.getCategoryMessages(
              groupId, categoryId, status, lastIntervalStart, lastIntervalStart + max, comparator);

      lastIntervalStart += max;
      listNotExhausted = (messageList.size() == max);

      for (MBMessage message : messageList) {
        if (messages.size() >= max) {
          break;
        }

        if (MBMessagePermission.contains(getPermissionChecker(), message, ActionKeys.VIEW)) {

          messages.add(message);
        }
      }
    }

    return exportToRSS(
        name, description, type, version, displayStyle, feedURL, entryURL, messages, themeDisplay);
  }
  protected void sendEmail(
      String emailAddress, MemberRequest memberRequest, ServiceContext serviceContext)
      throws Exception {

    long companyId = memberRequest.getCompanyId();

    Group group = groupLocalService.getGroup(memberRequest.getGroupId());

    User user = userLocalService.getUser(memberRequest.getUserId());

    User receiverUser = null;

    if (memberRequest.getReceiverUserId() > 0) {
      receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId());
    }

    String fromName = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String toName = StringPool.BLANK;
    String toAddress = emailAddress;

    if (receiverUser != null) {
      toName = receiverUser.getFullName();
    }

    String subject =
        StringUtil.read(getClassLoader(), "com/liferay/so/invitemembers/dependencies/subject.tmpl");

    String body = StringPool.BLANK;

    if (memberRequest.getReceiverUserId() > 0) {
      body =
          StringUtil.read(
              getClassLoader(),
              "com/liferay/so/invitemembers/dependencies/" + "existing_user_body.tmpl");
    } else {
      body =
          StringUtil.read(
              getClassLoader(),
              "com/liferay/so/invitemembers/dependencies/" + "new_user_body.tmpl");
    }

    subject =
        StringUtil.replace(
            subject,
            new String[] {"[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]"},
            new String[] {
              group.getDescriptiveName(serviceContext.getLocale()), user.getFullName()
            });

    String createAccountURL = (String) serviceContext.getAttribute("createAccountURL");

    if (Validator.isNull(createAccountURL)) {
      createAccountURL = serviceContext.getPortalURL();
    }

    createAccountURL = HttpUtil.addParameter(createAccountURL, "key", memberRequest.getKey());

    String loginURL = (String) serviceContext.getAttribute("loginURL");

    if (Validator.isNull(loginURL)) {
      loginURL = serviceContext.getPortalURL();
    }

    loginURL = HttpUtil.addParameter(loginURL, "key", memberRequest.getKey());

    body =
        StringUtil.replace(
            body,
            new String[] {
              "[$ADMIN_ADDRESS$]",
              "[$ADMIN_NAME$]",
              "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]",
              "[$MEMBER_REQUEST_GROUP$]",
              "[$MEMBER_REQUEST_LOGIN_URL$]",
              "[$MEMBER_REQUEST_USER$]"
            },
            new String[] {
              fromAddress,
              fromName,
              createAccountURL,
              group.getDescriptiveName(serviceContext.getLocale()),
              loginURL,
              user.getFullName()
            });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

    MailServiceUtil.sendEmail(mailMessage);
  }
  @Override
  public List<Group> getUserSitesGroups() throws PortalException {
    try {
      User user = getUser();

      List<Group> groups = new ArrayList<>();

      LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

      groupParams.put("active", true);
      groupParams.put("usersGroups", user.getUserId());

      List<Group> userSiteGroups =
          groupLocalService.search(
              user.getCompanyId(), null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (Group userSiteGroup : userSiteGroups) {
        if (SyncUtil.isSyncEnabled(userSiteGroup)) {
          userSiteGroup.setName(userSiteGroup.getDescriptiveName());

          groups.add(userSiteGroup);
        }
      }

      List<Organization> organizations =
          organizationLocalService.getOrganizations(
              user.getUserId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

      for (Organization organization : organizations) {
        Group userOrganizationGroup = organization.getGroup();

        if (SyncUtil.isSyncEnabled(userOrganizationGroup)) {
          groups.add(userOrganizationGroup);
        }

        if (!GetterUtil.getBoolean(PropsUtil.get(PropsKeys.ORGANIZATIONS_MEMBERSHIP_STRICT))) {

          for (Organization ancestorOrganization : organization.getAncestors()) {

            Group userAncestorOrganizationGroup = ancestorOrganization.getGroup();

            if (SyncUtil.isSyncEnabled(userAncestorOrganizationGroup)) {

              groups.add(userAncestorOrganizationGroup);
            }
          }
        }
      }

      if (PrefsPropsUtil.getBoolean(
          user.getCompanyId(),
          PortletPropsKeys.SYNC_ALLOW_USER_PERSONAL_SITES,
          PortletPropsValues.SYNC_ALLOW_USER_PERSONAL_SITES)) {

        groups.add(user.getGroup());
      }

      Collections.sort(groups, new GroupNameComparator());

      return ListUtil.unique(groups);
    } catch (PortalException pe) {
      throw new PortalException(pe.getClass().getName(), pe);
    }
  }
  @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;
  }
Exemple #12
0
  protected void notifyUsers(AnnouncementsEntry entry) throws PortalException {

    Company company = companyPersistence.findByPrimaryKey(entry.getCompanyId());

    String className = entry.getClassName();
    long classPK = entry.getClassPK();

    String toName = PropsValues.ANNOUNCEMENTS_EMAIL_TO_NAME;
    String toAddress = PropsValues.ANNOUNCEMENTS_EMAIL_TO_ADDRESS;

    long teamId = 0;

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    params.put("announcementsDeliveryEmailOrSms", entry.getType());

    if (classPK > 0) {
      if (className.equals(Group.class.getName())) {
        Group group = groupPersistence.findByPrimaryKey(classPK);

        toName = group.getDescriptiveName();

        params.put("inherit", Boolean.TRUE);
        params.put("usersGroups", classPK);
      } else if (className.equals(Organization.class.getName())) {
        Organization organization = organizationPersistence.findByPrimaryKey(classPK);

        toName = organization.getName();

        params.put("usersOrgsTree", ListUtil.fromArray(new Organization[] {organization}));
      } else if (className.equals(Role.class.getName())) {
        Role role = rolePersistence.findByPrimaryKey(classPK);

        toName = role.getName();

        if (role.getType() == RoleConstants.TYPE_REGULAR) {
          params.put("inherit", Boolean.TRUE);
          params.put("usersRoles", classPK);
        } else if (role.isTeam()) {
          teamId = role.getClassPK();
        } else {
          params.put("userGroupRole", new Long[] {Long.valueOf(0), classPK});
        }
      } else if (className.equals(UserGroup.class.getName())) {
        UserGroup userGroup = userGroupPersistence.findByPrimaryKey(classPK);

        toName = userGroup.getName();

        params.put("usersUserGroups", classPK);
      }
    }

    if (className.equals(User.class.getName())) {
      User user = userPersistence.findByPrimaryKey(classPK);

      if (Validator.isNull(user.getEmailAddress())) {
        return;
      }

      notifyUsers(
          ListUtil.fromArray(new User[] {user}),
          entry,
          company.getLocale(),
          user.getEmailAddress(),
          user.getFullName());
    } else {
      int count = 0;

      if (teamId > 0) {
        count = userLocalService.getTeamUsersCount(teamId);
      } else {
        count =
            userLocalService.searchCount(
                company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED, params);
      }

      int pages = count / Indexer.DEFAULT_INTERVAL;

      for (int i = 0; i <= pages; i++) {
        int start = (i * Indexer.DEFAULT_INTERVAL);
        int end = start + Indexer.DEFAULT_INTERVAL;

        List<User> users = null;

        if (teamId > 0) {
          users = userLocalService.getTeamUsers(teamId, start, end);
        } else {
          users =
              userLocalService.search(
                  company.getCompanyId(),
                  null,
                  WorkflowConstants.STATUS_APPROVED,
                  params,
                  start,
                  end,
                  (OrderByComparator<User>) null);
        }

        notifyUsers(users, entry, company.getLocale(), toAddress, toName);
      }
    }
  }