Пример #1
0
 private MembershipUser toMembershipUser(Membership membership) throws Exception {
   OrganizationService service = getApplicationComponent(OrganizationService.class);
   String userName = membership.getUserName();
   UserHandler handler = service.getUserHandler();
   User user = handler.findUserByName(userName);
   if (user == null) return null;
   return new MembershipUser(user, membership.getMembershipType(), membership.getId());
 }
Пример #2
0
 /**
  * initialize administrators, called from {@link #getAdministratorsList()}
  *
  * @throws Exception
  */
 public void initAdministrators() throws Exception {
   SpaceService spaceService = getSpaceService();
   Space space = spaceService.getSpaceByUrl(SpaceUtils.getSpaceUrl());
   administratorsList = new ArrayList<User>();
   OrganizationService orgSrc = getApplicationComponent(OrganizationService.class);
   UserHandler userHandler = orgSrc.getUserHandler();
   String[] managers = space.getManagers();
   if (managers != null) {
     for (String name : managers) {
       administratorsList.add(userHandler.findUserByName(name));
     }
   }
 }
Пример #3
0
  public void testGetIdentitiesByName() throws Exception {
    User user = userHandler.createUserInstance("alex");
    user.setFirstName("");
    user.setLastName("");
    user.setEmail("");
    userHandler.createUser(user, true);
    User found = userHandler.findUserByName("alex");
    assertNotNull(found);
    String providerId = OrganizationIdentityProvider.NAME;

    Identity identity = new Identity(providerId, "alex");
    identityManager.saveIdentity(identity);
    Profile profile = new Profile(identity);
    profile.setProperty(Profile.USERNAME, "alex");
    profile.setProperty(Profile.FIRST_NAME, "Mary");
    profile.setProperty(Profile.LAST_NAME, "Williams");
    profile.setProperty(Profile.FULL_NAME, "Mary " + "Williams");
    profile.setProperty(Profile.POSITION, "developer");
    profile.setProperty(Profile.GENDER, "female");
    identityManager.saveProfile(profile);
    identity.setProfile(profile);
    tearDownIdentityList.add(identity);

    ProfileFilter pf = new ProfileFilter();

    // Search by name full name
    pf.setName("Mary");
    ListAccess<Identity> idsListAccess =
        identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
    assertEquals(1, idsListAccess.getSize());
    pf.setName("Williams");
    idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
    assertEquals(1, idsListAccess.getSize());
    pf.setName("Mary Williams");
    idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
    assertEquals(1, idsListAccess.getSize());

    // update profile name
    profile.setProperty(Profile.FIRST_NAME, "Mary-James");
    profile.setProperty(Profile.FULL_NAME, "Mary-James Williams");
    identityManager.updateProfile(profile);
    Identity alex =
        identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "alex", true);
    assertEquals("Mary-James Williams", alex.getProfile().getFullName());

    pf.setName("Mary-James Williams");
    idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
    assertEquals(1, idsListAccess.getSize());

    //
    List<ExoSocialActivity> activities =
        activityManager.getActivitiesWithListAccess(identity).loadAsList(0, 20);
    for (ExoSocialActivity act : activities) {
      List<ExoSocialActivity> comments =
          activityManager.getCommentsWithListAccess(act).loadAsList(0, 20);
      for (ExoSocialActivity cmt : comments) {
        activityManager.deleteComment(act, cmt);
      }
      activityManager.deleteActivity(act);
    }
    userHandler.removeUser(user.getUserName(), false);
  }