Beispiel #1
0
  protected List<User> getUsers(
      ActionRequest actionRequest, ActionResponse actionResponse, ThemeDisplay themeDisplay)
      throws Exception {

    PortletURL portletURL =
        ((ActionResponseImpl) actionResponse).createRenderURL(PortletKeys.USERS_ADMIN);

    UserSearch userSearch = new UserSearch(actionRequest, portletURL);

    UserSearchTerms searchTerms = (UserSearchTerms) userSearch.getSearchTerms();

    searchTerms.setStatus(WorkflowConstants.STATUS_APPROVED);

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

    long organizationId = searchTerms.getOrganizationId();

    if (organizationId > 0) {
      params.put("usersOrgs", new Long(organizationId));
    }

    long roleId = searchTerms.getRoleId();

    if (roleId > 0) {
      params.put("usersRoles", new Long(roleId));
    }

    long userGroupId = searchTerms.getUserGroupId();

    if (userGroupId > 0) {
      params.put("usersUserGroups", new Long(userGroupId));
    }

    if (searchTerms.isAdvancedSearch()) {
      return UserLocalServiceUtil.search(
          themeDisplay.getCompanyId(),
          searchTerms.getFirstName(),
          searchTerms.getMiddleName(),
          searchTerms.getLastName(),
          searchTerms.getScreenName(),
          searchTerms.getEmailAddress(),
          searchTerms.getStatus(),
          params,
          searchTerms.isAndOperator(),
          QueryUtil.ALL_POS,
          QueryUtil.ALL_POS,
          (OrderByComparator) null);
    } else {
      return UserLocalServiceUtil.search(
          themeDisplay.getCompanyId(),
          searchTerms.getKeywords(),
          searchTerms.getStatus(),
          params,
          QueryUtil.ALL_POS,
          QueryUtil.ALL_POS,
          (OrderByComparator) null);
    }
  }
 @Override
 public List<User> findMatchingUsers(String prefix) {
   try {
     List<com.liferay.portal.model.User> search =
         UserLocalServiceUtil.search(
             PortalUtil.getDefaultCompanyId(),
             prefix,
             0,
             null,
             0,
             100,
             (OrderByComparator) null);
     List<User> result = new ArrayList<User>(search.size());
     for (com.liferay.portal.model.User portalUser : search) {
       result.add(new LiferayUserImpl(portalUser));
     }
     return result;
   } catch (SystemException e) {
     throw new RuntimeException(e);
   }
 }
  public static JSONObject getJSONRecipients(
      long userId, String type, String keywords, int start, int end)
      throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    User user = UserLocalServiceUtil.getUser(userId);

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

    if (type.equals("site")) {
      params.put("inherit", Boolean.TRUE);

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

      groupParams.put("inherit", Boolean.FALSE);
      groupParams.put("site", Boolean.TRUE);
      groupParams.put("usersGroups", userId);

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

      params.put(
          "usersGroups",
          SitesUtil.filterGroups(groups, PortletPropsValues.AUTOCOMPLETE_RECIPIENT_SITE_EXCLUDES));
    } else if (!type.equals("all")) {
      params.put(
          "socialRelationType",
          new Long[] {userId, new Long(SocialRelationConstants.TYPE_BI_CONNECTION)});
    }

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

      if (role != null) {
        params.put("inherit", Boolean.TRUE);
        params.put("usersRoles", new Long(role.getRoleId()));
      }
    } catch (NoSuchRoleException nsre) {
    }

    int total =
        UserLocalServiceUtil.searchCount(
            user.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params);

    jsonObject.put("total", total);

    List<User> users =
        UserLocalServiceUtil.search(
            user.getCompanyId(),
            keywords,
            WorkflowConstants.STATUS_APPROVED,
            params,
            start,
            end,
            new UserFirstNameComparator(true));

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    for (User curUser : users) {
      JSONObject userJSONObject = JSONFactoryUtil.createJSONObject();

      StringBundler sb = new StringBundler(5);

      sb.append(curUser.getFullName());
      sb.append(CharPool.SPACE);
      sb.append(CharPool.LESS_THAN);
      sb.append(curUser.getScreenName());
      sb.append(CharPool.GREATER_THAN);

      userJSONObject.put("name", sb.toString());

      jsonArray.put(userJSONObject);
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
  }