Пример #1
0
 /**
  * gets memberships of a user in a space.
  *
  * @param userName
  * @return string of membership name
  * @throws Exception
  */
 @SuppressWarnings("unchecked")
 public String getMemberships(String userName) throws Exception {
   String memberShip = null;
   OrganizationService orgService = getApplicationComponent(OrganizationService.class);
   MembershipHandler memberShipHandler = orgService.getMembershipHandler();
   Collection<Membership> memberShips =
       memberShipHandler.findMembershipsByUserAndGroup(userName, getSpace().getGroupId());
   for (Membership aaa : memberShips) {
     if (memberShip == null) {
       memberShip = aaa.getMembershipType();
     } else {
       memberShip += "," + aaa.getMembershipType();
     }
   }
   return memberShip;
 }
Пример #2
0
    public void execute(Event<UISelectUserForm> event) throws Exception {
      UISelectUserForm uiForm = event.getSource();
      OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
      String keyword = uiForm.getUIStringInput(FIELD_KEYWORD).getValue();
      String filter = uiForm.getUIFormSelectBox(FIELD_FILTER).getValue();
      // uiForm.groupId_ = null ;
      // uiForm.setSelectedGroup(null) ;
      if (CalendarUtils.isEmpty(keyword)) {
        uiForm.init(uiForm.pars_);
      } else {
        keyword = "*" + keyword + "*";
        Query q = new Query();
        if (USER_NAME.equals(filter)) {
          q.setUserName(keyword);
        }
        if (LAST_NAME.equals(filter)) {
          q.setLastName(keyword);
        }
        if (FIRST_NAME.equals(filter)) {
          q.setFirstName(keyword);
        }
        if (EMAIL.equals(filter)) {
          q.setEmail(keyword);
        }
        List results = new CopyOnWriteArrayList();
        results.addAll(service.getUserHandler().findUsers(q).getAll());

        MembershipHandler memberShipHandler = service.getMembershipHandler();
        String groupId = uiForm.getSelectedGroup();
        if (groupId != null && groupId.trim().length() != 0) {
          for (Object user : results) {
            if (memberShipHandler
                    .findMembershipsByUserAndGroup(((User) user).getUserName(), groupId)
                    .size()
                == 0) {
              results.remove(user);
            }
          }
        }
        // ObjectPageList objPageList = new ObjectPageList(results, 10) ;
        LazyPageList<User> pageList =
            new LazyPageList<User>(new ListAccessImpl<User>(User.class, results), 10);
        uiForm.uiIterator_.setPageList(pageList);
      }
      event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
    }
Пример #3
0
  public void search(String keyword, String filter, String groupId) throws Exception {
    OrganizationService service = getApplicationComponent(OrganizationService.class);
    Query q = new Query();
    if (keyword != null && (keyword = keyword.trim()).length() != 0) {
      if (keyword.indexOf("*") < 0) {
        if (keyword.charAt(0) != '*') keyword = "*" + keyword;
        if (keyword.charAt(keyword.length() - 1) != '*') keyword += "*";
      }
      keyword = keyword.replace('?', '_');
      if (USER_NAME.equals(filter)) {
        q.setUserName(keyword);
      }
      if (LAST_NAME.equals(filter)) {
        q.setLastName(keyword);
      }
      if (FIRST_NAME.equals(filter)) {
        q.setFirstName(keyword);
      }
      if (EMAIL.equals(filter)) {
        q.setEmail(keyword);
      }
    }
    List results = new CopyOnWriteArrayList();
    results.addAll(service.getUserHandler().findUsers(q).getAll());
    // remove if user doesn't exist in selected group
    MembershipHandler memberShipHandler = service.getMembershipHandler();

    if (groupId != null && (groupId = groupId.trim()).length() != 0) {
      for (Object user : results) {
        if (memberShipHandler
                .findMembershipsByUserAndGroup(((User) user).getUserName(), groupId)
                .size()
            == 0) {
          results.remove(user);
        }
      }
    }
    PageList objPageList = new SerializablePageList(new ListAccessImpl(User.class, results), 10);
    uiIterator_.setPageList(objPageList);
  }