[gatein-commits] gatein SVN: r1530 - in portal/trunk/component/identity/src: test/java/org/exoplatform/services/organization and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Feb 4 04:38:48 EST 2010


Author: bdaw
Date: 2010-02-04 04:38:47 -0500 (Thu, 04 Feb 2010)
New Revision: 1530

Modified:
   portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java
   portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
Log:
- a workaround to search user by email more efficient. PLIDM implementation specific method

Modified: portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java
===================================================================
--- portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java	2010-02-04 09:21:28 UTC (rev 1529)
+++ portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java	2010-02-04 09:38:47 UTC (rev 1530)
@@ -292,6 +292,25 @@
       return new LazyPageList(new IDMUserListAccess(this, service_, qb, 20, false), 20);
    }
 
+   public User findUserByEmail(String email) throws Exception
+   {
+      IdentitySession session = service_.getIdentitySession();
+
+
+      org.picketlink.idm.api.User plUser;
+      plUser = session.getAttributesManager().findUserByUniqueAttribute(USER_EMAIL, email);
+      User user = null;
+
+      if (plUser != null)
+      {
+         user = new UserImpl(plUser.getId());
+         populateUser(user, session);
+
+      }
+
+      return user;
+   }
+
    public ListAccess<User> findUsersByGroupId(String groupId) throws Exception
    {
       throw new UnsupportedOperationException();
@@ -387,16 +406,24 @@
          return null;
       }
 
+      User user = new UserImpl(userName);
+
+      populateUser(user, session);
+
+      return user;
+
+   }
+
+   public static void populateUser(User user, IdentitySession session) throws Exception
+   {
+
       AttributesManager am = session.getAttributesManager();
 
-      Map<String, Attribute> attrs = am.getAttributes(userName);
+      Map<String, Attribute> attrs = am.getAttributes(user.getUserName());
 
-      User user = new UserImpl(userName);
-
       if (attrs == null)
       {
-
-         return user;
+         return;
       }
       else
       {
@@ -429,9 +456,6 @@
             user.setPassword(attrs.get(USER_PASSWORD).getValue().toString());
          }
       }
-
-      return user;
-
    }
 
 }

Modified: portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
===================================================================
--- portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java	2010-02-04 09:21:28 UTC (rev 1529)
+++ portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java	2010-02-04 09:38:47 UTC (rev 1530)
@@ -23,6 +23,7 @@
 import org.exoplatform.container.PortalContainer;
 import org.exoplatform.container.component.ComponentRequestLifecycle;
 import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.services.organization.idm.UserDAOImpl;
 import org.exoplatform.test.BasicTestCase;
 
 import java.util.ArrayList;
@@ -184,6 +185,36 @@
       assertNull(" user's profile of USER was removed:", profileHandler_.findUserProfileByName(USER));
    }
 
+   public void testUniqueAttribute() throws Exception
+   {
+      if (userHandler_ instanceof UserDAOImpl)
+      {
+         UserDAOImpl ud = (UserDAOImpl)userHandler_;
+
+         User user = userHandler_.createUserInstance("toto");
+         user.setEmail("toto at gatein.org");
+         userHandler_.createUser(user, true);
+
+         user = userHandler_.createUserInstance("lolo");
+         user.setEmail("lolo at gatein.org");
+         userHandler_.createUser(user, true);
+
+         // Find by unique attribute
+         assertNull(ud.findUserByEmail("foobar"));
+         user = ud.findUserByEmail("toto at gatein.org");
+         assertNotNull(user);
+         assertEquals("toto", user.getUserName());
+
+         user = ud.findUserByEmail("lolo at gatein.org");
+         assertNotNull(user);
+         assertEquals("lolo", user.getUserName());
+
+         ud.removeUser("toto", false);
+         ud.removeUser("lolo", false);
+
+      }
+   }
+
    //
    public void testGroup() throws Exception
    {



More information about the gatein-commits mailing list