Пример #1
0
  public static long getGroupId(long companyId, String[] pathArray) throws WebDAVException {

    try {
      if (pathArray.length == 0) {
        return 0;
      }

      String name = pathArray[0];

      Group group = GroupLocalServiceUtil.fetchFriendlyURLGroup(companyId, StringPool.SLASH + name);

      if (group != null) {
        return group.getGroupId();
      }

      User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, name);

      if (user != null) {
        group = user.getGroup();

        return group.getGroupId();
      }
    } catch (Exception e) {
      throw new WebDAVException(e);
    }

    return 0;
  }
Пример #2
0
  /** @deprecated As of 6.2.0, replaced by {@link #getUserName(long, ServiceContext)} */
  protected String getUserName(long userId, ThemeDisplay themeDisplay) {
    try {
      if (userId <= 0) {
        return StringPool.BLANK;
      }

      User user = UserLocalServiceUtil.getUserById(userId);

      if (user.getUserId() == themeDisplay.getUserId()) {
        return HtmlUtil.escape(user.getFirstName());
      }

      String userName = user.getFullName();

      Group group = user.getGroup();

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

      String userDisplayURL = user.getDisplayURL(themeDisplay);

      userName =
          "******"user\" href=\"" + userDisplayURL + "\">" + HtmlUtil.escape(userName) + "</a>";

      return userName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
Пример #3
0
  @Override
  protected void doUpgrade() throws Exception {
    List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (User user : users) {
      try {
        if (user.isDefaultUser()) {
          continue;
        }

        Group group = user.getGroup();

        LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false);

        String themeId = layoutSet.getThemeId();

        if (!themeId.equals("so_WAR_sotheme")) {
          return;
        }

        Role role =
            RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER);

        UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()});

        updateUserGroup(group);
        updateSocialRelations(user);
      } catch (Exception e) {
      }
    }
  }
Пример #4
0
  public static List<Group> getGroups(User user) throws Exception {

    // Guest

    if (user.isDefaultUser()) {
      List<Group> groups = new ArrayList<>();

      Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST);

      groups.add(group);

      return groups;
    }

    // Communities

    Set<Group> groups = new HashSet<>();

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

    params.put("usersGroups", user.getUserId());

    OrderByComparator<Group> orderByComparator = new GroupFriendlyURLComparator(true);

    groups.addAll(
        GroupLocalServiceUtil.search(
            user.getCompanyId(),
            null,
            null,
            params,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            orderByComparator));

    // Organizations

    groups.addAll(
        GroupLocalServiceUtil.getUserOrganizationsGroups(
            user.getUserId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS));

    // User

    if (!user.isDefaultUser()) {
      groups.add(user.getGroup());
    }

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

    Collections.sort(groupsList, orderByComparator);

    return groupsList;
  }
  protected String getThreadURL(User user, long threadId, ThemeDisplay themeDisplay)
      throws Exception {

    Group group = user.getGroup();

    long plid =
        PortalUtil.getPlidFromPortletId(group.getGroupId(), true, PortletKeys.PRIVATE_MESSAGING);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    String privateMessageURL = PortalUtil.getLayoutFullURL(layout, themeDisplay, false);

    return privateMessageURL + "/-/private_messaging/thread/" + threadId;
  }
  private static long _getGroupId(long companyId, String name) throws Exception {

    try {
      Group group = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, StringPool.SLASH + name);

      return group.getGroupId();
    } catch (NoSuchGroupException nsge) {
    }

    User user = UserLocalServiceUtil.getUserByScreenName(companyId, name);

    Group group = user.getGroup();

    return group.getGroupId();
  }
  @Ignore
  @Test
  public void testExportLinksToUserLayouts() throws Exception {
    User user = TestPropsValues.getUser();

    Group group = user.getGroup();

    Layout privateLayout = LayoutTestUtil.addLayout(group, true);
    Layout publicLayout = LayoutTestUtil.addLayout(group, false);

    PortletDataContext portletDataContextExport =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            group.getCompanyId(),
            group.getGroupId(),
            new HashMap<String, String[]>(),
            new Date(System.currentTimeMillis() - Time.HOUR),
            new Date(),
            new TestReaderWriter());

    JournalArticle journalArticle =
        JournalTestUtil.addArticle(
            group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString());

    Element rootElement = SAXReaderUtil.createElement("root");

    rootElement.addElement("entry");

    String content =
        replaceLinksToLayoutsParameters(
            getContent("layout_links_user_group.txt"), privateLayout, publicLayout);

    content =
        ExportImportHelperUtil.replaceExportContentReferences(
            portletDataContextExport, journalArticle, content, true);

    assertLinksToLayouts(content, privateLayout, 0);
    assertLinksToLayouts(content, privateLayout, privateLayout.getGroupId());
    assertLinksToLayouts(content, publicLayout, 0);
    assertLinksToLayouts(content, publicLayout, publicLayout.getGroupId());
  }
Пример #8
0
  public static long getGroupId(long companyId, String[] pathArray) throws WebDAVException {

    try {
      if (pathArray.length == 0) {
        return 0;
      }

      String name = pathArray[0];

      try {
        Group group = GroupLocalServiceUtil.getGroup(companyId, name);

        return group.getGroupId();
      } catch (NoSuchGroupException nsge) {
      }

      try {
        Group group = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, StringPool.SLASH + name);

        return group.getGroupId();
      } catch (NoSuchGroupException nsge) {
      }

      try {
        User user = UserLocalServiceUtil.getUserByScreenName(companyId, name);

        Group group = user.getGroup();

        return group.getGroupId();
      } catch (NoSuchUserException nsue) {
      }
    } catch (Exception e) {
      throw new WebDAVException(e);
    }

    return 0;
  }
  /**
   * Returns the user's groups &quot;sites&quot; associated with the group entity class names,
   * including the Control Panel group if the user is permitted to view the Control Panel.
   *
   * <ul>
   *   <li>Class name &quot;User&quot; includes the user's layout set group.
   *   <li>Class name &quot;Organization&quot; includes the user's immediate organization groups and
   *       inherited organization groups.
   *   <li>Class name &quot;Group&quot; includes the user's immediate organization groups and site
   *       groups.
   *   <li>A <code>classNames</code> value of <code>null</code> includes the user's layout set
   *       group, organization groups, inherited organization groups, and site groups.
   * </ul>
   *
   * @param userId the primary key of the user
   * @param classNames the group entity class names (optionally <code>null</code>). For more
   *     information see {@link #getUserSitesGroups(long, String[], int)}.
   * @param max the maximum number of groups to return
   * @return the user's groups &quot;sites&quot;
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public List<Group> getUserSitesGroups(long userId, String[] classNames, int max)
      throws PortalException {

    User user = userPersistence.findByPrimaryKey(userId);

    if (user.isDefaultUser()) {
      return Collections.emptyList();
    }

    Set<Group> userSiteGroups = new LinkedHashSet<>();

    if (classNames == null) {
      classNames =
          new String[] {
            Company.class.getName(), Group.class.getName(),
            Organization.class.getName(), User.class.getName()
          };
    }

    if (ArrayUtil.contains(classNames, User.class.getName())) {
      if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED
          || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {

        userSiteGroups.add(user.getGroup());

        if (userSiteGroups.size() == max) {
          return new ArrayList<>(userSiteGroups);
        }
      }
    }

    if (ArrayUtil.contains(classNames, Company.class.getName())) {
      Group companyGroup = groupLocalService.getCompanyGroup(user.getCompanyId());

      if (GroupPermissionUtil.contains(
          getPermissionChecker(), companyGroup, ActionKeys.VIEW_SITE_ADMINISTRATION)) {

        userSiteGroups.add(companyGroup);

        if (userSiteGroups.size() == max) {
          return new ArrayList<>(userSiteGroups);
        }
      }
    }

    if (ArrayUtil.contains(classNames, Group.class.getName())
        || ArrayUtil.contains(classNames, Organization.class.getName())) {

      UserBag userBag = UserBagFactoryUtil.create(userId);

      if (ArrayUtil.contains(classNames, Group.class.getName())) {
        for (Group group : userBag.getUserGroups()) {
          if (group.isActive() && group.isSite()) {
            if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) {

              return new ArrayList<>(userSiteGroups);
            }
          }
        }
      }

      if (ArrayUtil.contains(classNames, Organization.class.getName())) {
        for (Group group : userBag.getUserOrgGroups()) {
          if (group.isActive() && group.isSite()) {
            if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) {

              return new ArrayList<>(userSiteGroups);
            }
          }
        }
      }
    }

    return new ArrayList<>(userSiteGroups);
  }
  @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);
    }
  }
  public void deactivateEquityLogs(long userId, long assetEntryId, String actionId)
      throws PortalException, SystemException {

    if (!PropsValues.SOCIAL_EQUITY_EQUITY_LOG_ENABLED) {
      return;
    }

    User user = userPersistence.findByPrimaryKey(userId);

    AssetEntry assetEntry = assetEntryPersistence.findByPrimaryKey(assetEntryId);

    // Information Equity

    if (isSocialEquityEnabled(
        assetEntry.getGroupId(),
        assetEntry.getClassName(),
        SocialEquitySettingConstants.TYPE_INFORMATION)) {

      List<SocialEquityLog> equityLogs =
          socialEquityLogPersistence.findByAEI_AID_A_T(
              assetEntryId, actionId, true, SocialEquitySettingConstants.TYPE_INFORMATION);

      SocialEquityValue socialEquityValue = new SocialEquityValue(0, 0);

      for (SocialEquityLog equityLog : equityLogs) {
        double k = calculateK(equityLog.getValue(), equityLog.getLifespan());
        double b =
            calculateB(equityLog.getActionDate(), equityLog.getValue(), equityLog.getLifespan());

        socialEquityValue.subtract(new SocialEquityValue(k, b));

        socialEquityLogPersistence.remove(equityLog);
      }

      socialEquityLogLocalService.incrementSocialEquityAssetEntry_IQ(
          assetEntryId, socialEquityValue);

      socialEquityLogLocalService.incrementSocialEquityUser_CQ(
          assetEntry.getGroupId(), assetEntry.getUserId(), socialEquityValue);
    }

    // Participation Equity

    if (isSocialEquityEnabled(
        assetEntry.getGroupId(),
        assetEntry.getClassName(),
        SocialEquitySettingConstants.TYPE_PARTICIPATION)) {

      List<SocialEquityLog> equityLogs =
          socialEquityLogPersistence.findByU_AID_A_T(
              userId, actionId, true, SocialEquitySettingConstants.TYPE_PARTICIPATION);

      SocialEquityValue socialEquityValue = new SocialEquityValue(0, 0);

      for (SocialEquityLog equityLog : equityLogs) {
        double k = calculateK(equityLog.getValue(), equityLog.getLifespan());
        double b =
            calculateB(equityLog.getActionDate(), equityLog.getValue(), equityLog.getLifespan());

        socialEquityValue.subtract(new SocialEquityValue(k, b));

        socialEquityLogPersistence.remove(equityLog);
      }

      socialEquityLogLocalService.incrementSocialEquityUser_PQ(
          user.getGroup().getGroupId(), userId, socialEquityValue);
    }
  }