usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/4] incubator-usergrid git commit: Duplicate user merge.
Date Tue, 21 Jul 2015 19:58:44 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/master e1b352ef9 -> 897fd5083


Duplicate user merge.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/16de78d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/16de78d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/16de78d9

Branch: refs/heads/master
Commit: 16de78d9d5a42941c76907ffe2986b16c7195976
Parents: e1b352e
Author: Dave Johnson <snoopdave@apache.org>
Authored: Thu Jul 16 13:56:17 2015 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Thu Jul 16 13:56:17 2015 -0400

----------------------------------------------------------------------
 .../org/apache/usergrid/tools/ExportAdmins.java |   2 +
 .../org/apache/usergrid/tools/ImportAdmins.java | 203 ++++++++++++++-----
 stack/tools/src/main/resources/log4j.properties |   2 +-
 .../usergrid/tools/ExportImportAdminsTest.java  |  71 ++++---
 ...adata.usergrid-management.1433331614293.json |  52 +++++
 ...users.usergrid-management.1433331614293.json |  12 ++
 6 files changed, 263 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/main/java/org/apache/usergrid/tools/ExportAdmins.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ExportAdmins.java b/stack/tools/src/main/java/org/apache/usergrid/tools/ExportAdmins.java
index 2c14da1..ae9c16b 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ExportAdmins.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ExportAdmins.java
@@ -489,6 +489,8 @@ public class ExportAdmins extends ExportingToolBase {
                 jg.writeObject( orgs.get( uuid ) );
 
                 jg.writeEndObject();
+                
+                logger.debug( "Exported organization {}:{}", uuid, orgs.get( uuid ) );
             }
 
             jg.writeEndArray();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java b/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
index 0b693c8..c6aada7 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ImportAdmins.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.tools;
 
 
+import com.sun.org.apache.bcel.internal.generic.DUP;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
@@ -26,6 +27,8 @@ import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.management.UserInfo;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.Identifier;
+import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
 import org.codehaus.jackson.JsonFactory;
@@ -84,6 +87,7 @@ public class ImportAdmins extends ToolBase {
     private Map<Stoppable, Thread> adminAuditThreads = new HashMap<Stoppable, Thread>();
     private Map<Stoppable, Thread> metadataWorkerThreadMap = new HashMap<Stoppable,
Thread>();
 
+    Map<UUID, DuplicateUser> dupsByDupUuid = new HashMap<UUID, DuplicateUser>(200);
 
     JsonFactory jsonFactory = new JsonFactory();
 
@@ -94,6 +98,19 @@ public class ImportAdmins extends ToolBase {
     AtomicInteger auditEmptyCount = new AtomicInteger( 0 );
     AtomicInteger metadataEmptyCount = new AtomicInteger( 0 );
     
+    
+    static class DuplicateUser {
+        String email;
+        String username;
+        public DuplicateUser( String propName, Map<String, Object> user ) {
+            if ( "email".equals(propName)) {
+                email = user.get("email").toString();
+            } else {
+                username = user.get("username").toString();
+            }
+        }
+    }
+    
 
 
     @Override
@@ -382,7 +399,7 @@ public class ImportAdmins extends ToolBase {
                 String entityOwnerId = jp.getCurrentName();
 
                 try {
-                    EntityRef entityRef = em.get( UUID.fromString( entityOwnerId ) );
+                    EntityRef entityRef = new SimpleEntityRef( "user", UUID.fromString( entityOwnerId
) );
                     Map<String, Object> metadata = (Map<String, Object>) jp.readValueAs(
Map.class );
                     
                     workQueue.put( new ImportMetadataTask( entityRef, metadata ) );
@@ -408,31 +425,33 @@ public class ImportAdmins extends ToolBase {
     private void importEntityMetadata(
             EntityManager em, EntityRef entityRef, Map<String, Object> metadata) throws
Exception {
 
-        List<Object> organizationsList = (List<Object>) metadata.get("organizations");
-        if (organizationsList != null && !organizationsList.isEmpty()) {
+        DuplicateUser dup = dupsByDupUuid.get( entityRef.getUuid() );
+        
+        if ( dup == null ) { // not a duplicate
 
-            User user = em.get(entityRef, User.class);
-            
-            if (user == null) {
-                logger.error("User not found, not adding to organizations: " 
-                    + (entityRef == null ? null : entityRef.getUuid()));
+            User user = em.get( entityRef, User.class );
+            final UserInfo userInfo = managementService.getAdminUserByEmail( user.getEmail()
);
 
-            } else {
+            if (user == null || userInfo == null) {
+                logger.error( "User {} does not exist, not processing metadata", entityRef.getUuid()
);
+                return;
+            }
 
-                final UserInfo userInfo = managementService.getAdminUserByEmail(user.getEmail());
+            List<Object> organizationsList = (List<Object>) metadata.get("organizations");
+            if (organizationsList != null && !organizationsList.isEmpty()) {
 
                 for (Object orgObject : organizationsList) {
 
                     Map<String, Object> orgMap = (Map<String, Object>) orgObject;
-                    UUID orgUuid = UUID.fromString((String) orgMap.get("uuid"));
-                    String orgName = (String) orgMap.get("name");
+                    UUID orgUuid = UUID.fromString( (String) orgMap.get( "uuid" ) );
+                    String orgName = (String) orgMap.get( "name" );
 
-                    // create org only if it does not exist
-                    OrganizationInfo orgInfo = managementService.getOrganizationByUuid(orgUuid);
-                    if (orgInfo == null) {
+                    OrganizationInfo orgInfo = managementService.getOrganizationByUuid( orgUuid
);
+
+                    if (orgInfo == null) { // org does not exist yet, create it and add user
                         try {
-                            managementService.createOrganization(orgUuid, orgName, userInfo,
false);
-                            orgInfo = managementService.getOrganizationByUuid(orgUuid);
+                            managementService.createOrganization( orgUuid, orgName, userInfo,
false );
+                            orgInfo = managementService.getOrganizationByUuid( orgUuid );
 
                             logger.debug( "Created new org {} for user {}",
                                     new Object[]{orgInfo.getName(), user.getEmail()} );
@@ -440,49 +459,107 @@ public class ImportAdmins extends ToolBase {
                         } catch (DuplicateUniquePropertyExistsException dpee) {
                             logger.debug( "Org {} already exists", orgName );
                         }
-                    } else {
+                    } else { // org exists, add original user to it
                         try {
                             managementService.addAdminUserToOrganization( userInfo, orgInfo,
false );
                             logger.debug( "Added user {} to org {}", new Object[]{user.getEmail(),
orgName} );
-                            
-                        } catch ( Exception e ) {
+
+                        } catch (Exception e) {
                             logger.error( "Error Adding user {} to org {}", new Object[]{user.getEmail(),
orgName} );
                         }
                     }
                 }
             }
+            
+            Map<String, Object> dictionariesMap = (Map<String, Object>) metadata.get("dictionaries");
+            if (dictionariesMap != null && !dictionariesMap.isEmpty()) {
+                for (String name : dictionariesMap.keySet()) {
+                    try {
+                        Map<String, Object> dictionary = (Map<String, Object>)
dictionariesMap.get(name);
+                        em.addMapToDictionary( entityRef, name, dictionary);
 
-        } else {
-            logger.warn("User {} has no organizations", entityRef.getUuid() );
-        }
-
-        Map<String, Object> dictionariesMap = (Map<String, Object>) metadata.get("dictionaries");
-
-        if (dictionariesMap != null && !dictionariesMap.isEmpty()) {
-            for (String name : dictionariesMap.keySet()) {
-                try {
-                    Map<String, Object> dictionary = (Map<String, Object>) dictionariesMap.get(name);
-                    em.addMapToDictionary( entityRef, name, dictionary);
-
-                    logger.debug( "Creating dictionary for {} name {}",
-                            new Object[]{entityRef, name} );
+                        logger.debug( "Creating dictionary for {} name {}",
+                                new Object[]{entityRef, name} );
 
-                } catch (Exception e) {
-                    if (logger.isDebugEnabled()) {
-                        logger.error("Error importing dictionary name "
-                                + name + " for user " + entityRef.getUuid(), e);
-                    } else {
-                        logger.error("Error importing dictionary name "
-                                + name + " for user " + entityRef.getUuid());
+                    } catch (Exception e) {
+                        if (logger.isDebugEnabled()) {
+                            logger.error("Error importing dictionary name "
+                                    + name + " for user " + entityRef.getUuid(), e);
+                        } else {
+                            logger.error("Error importing dictionary name "
+                                    + name + " for user " + entityRef.getUuid());
+                        }
                     }
                 }
+
+            } else {
+                logger.warn("User {} has no dictionaries", entityRef.getUuid() );
             }
             
-        } else {
-            logger.warn("User {} has no dictionaries", entityRef.getUuid() );
-        }
+        } else { // this is a duplicate user, so merge orgs
+
+            logger.info("Processing duplicate username={} email={}", dup.email, dup.username
);
+           
+            Identifier identifier = dup.email != null ? 
+                Identifier.fromEmail( dup.email ) : Identifier.from( dup.username );
+            User originalUser = em.get( em.getUserByIdentifier(identifier), User.class );
+
+            // get map of original user's orgs
+            
+            UserInfo originalUserInfo = managementService.getAdminUserByEmail( originalUser.getEmail()
);
+            Map<String, Object> originalUserOrgData =
+                    managementService.getAdminUserOrganizationData( originalUser.getUuid()
);
+            Map<String, Map<String, Object>> originalUserOrgs =
+                    (Map<String, Map<String, Object>>) originalUserOrgData.get(
"organizations" );
 
+            // loop through duplicate user's orgs and give orgs to original user
 
+            List<Object> organizationsList = (List<Object>) metadata.get("organizations");
+            for (Object orgObject : organizationsList) {
+
+                Map<String, Object> orgMap = (Map<String, Object>) orgObject;
+                UUID orgUuid = UUID.fromString( (String) orgMap.get( "uuid" ) );
+                String orgName = (String) orgMap.get( "name" );
+
+                if (originalUserOrgs.get( orgName ) == null) { // original user does not
have this org
+
+                    OrganizationInfo orgInfo = managementService.getOrganizationByUuid( orgUuid
);
+                    
+                    if (orgInfo == null) { // org does not exist yet, create it and add original
user to it
+                        try {
+                            managementService.createOrganization( orgUuid, orgName, originalUserInfo,
false );
+                            orgInfo = managementService.getOrganizationByUuid( orgUuid );
+
+                            logger.debug( "Created new org {} for user {}:{}:{} from duplicate
user {}:{}",
+                                new Object[]{
+                                        orgInfo.getName(),
+                                        originalUser.getUuid(), originalUser.getUsername(),
originalUser.getEmail(),
+                                        dup.username, dup.email
+                                });
+
+                        } catch (DuplicateUniquePropertyExistsException dpee) {
+                            logger.debug( "Org {} already exists", orgName );
+                        }
+                    } else { // org exists so add original user to it
+                        try {
+                            managementService.addAdminUserToOrganization( originalUserInfo,
orgInfo, false );
+                            logger.debug( "Added to org user {}:{}:{} from duplicate user
{}:{}",
+                                    new Object[]{
+                                            orgInfo.getName(),
+                                            originalUser.getUuid(), originalUser.getUsername(),
originalUser.getEmail(),
+                                            dup.username, dup.email
+                                    });
+
+                        } catch (Exception e) {
+                            logger.error( "Error Adding user {} to org {}", 
+                                    new Object[]{originalUserInfo.getEmail(), orgName} );
+                        }
+                    }
+                    
+                } // else original user already has this org
+                
+            }
+        }
     }
 
 
@@ -685,15 +762,15 @@ public class ImportAdmins extends ToolBase {
 
                     // Import/create the entity
                     UUID uuid = getId(entityProps);
-                    String type = getType(entityProps);
+                    String type = getType( entityProps );
 
                     try {
                         long startTime = System.currentTimeMillis();
                         
                         em.create(uuid, type, entityProps);
 
-                        logger.debug( "Imported admin user {} / {}",
-                            new Object[] { uuid, entityProps.get( "username" ) } );
+                        logger.debug( "Imported admin user {}:{}:{}",
+                            new Object[] { uuid, entityProps.get( "username" ), entityProps.get("email")
} );
 
                         userCount.getAndIncrement();
                         auditQueue.put(entityProps);
@@ -709,19 +786,37 @@ public class ImportAdmins extends ToolBase {
                         }
                         
                     } catch (DuplicateUniquePropertyExistsException de) {
-                        logger.warn("Unable to create admin user {}:{}, duplicate property
{}",
-                                new Object[]{ uuid, entityProps.get("username"), de.getPropertyName()
});
-                        if (logger.isDebugEnabled()) {
-                            logger.debug("Exception", de);
-                        }
+                        String dupProperty = de.getPropertyName();
+                        handleDuplicateAccount( em, dupProperty, entityProps );
+                        continue;
+
+                        
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        logger.error("Error", e);
                     }
                 } catch (InterruptedException e) {
-                    e.printStackTrace();
+                    logger.error( "Error", e );
                 }
 
             }
         }
+
+        
+        private void handleDuplicateAccount(EntityManager em, String dupProperty, Map<String,
Object> entityProps ) {
+
+            logger.info( "Processing duplicate user {}:{}:{} with duplicate {}", new Object[]{
+                    entityProps.get( "uuid" ), entityProps.get( "username" ), entityProps.get(
"email" ), dupProperty} );
+           
+            UUID dupUuid = UUID.fromString( entityProps.get("uuid").toString() );
+            try {
+                dupsByDupUuid.put( dupUuid, new DuplicateUser( dupProperty, entityProps )
);
+                
+            } catch (Exception e) {
+                logger.error("Error processing dup user {}:{}:{}",
+                        new Object[] {entityProps.get( "username" ), entityProps.get("email"),
dupUuid});
+                return;
+            }
+
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/resources/log4j.properties b/stack/tools/src/main/resources/log4j.properties
index 6cf0a92..80c32a1 100644
--- a/stack/tools/src/main/resources/log4j.properties
+++ b/stack/tools/src/main/resources/log4j.properties
@@ -26,7 +26,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) [%c] - %m%n
 
-log4j.logger.org.apache.usergrid.tools=INFO
+log4j.logger.org.apache.usergrid.tools=DEBUG
 
 log4j.logger.org.apache.usergrid.management.cassandra=WARN
 log4j.logger.org.apache.usergrid.persistence.cassandra.DB=WARN

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/test/java/org/apache/usergrid/tools/ExportImportAdminsTest.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/test/java/org/apache/usergrid/tools/ExportImportAdminsTest.java
b/stack/tools/src/test/java/org/apache/usergrid/tools/ExportImportAdminsTest.java
index 898a97d..9cce040 100644
--- a/stack/tools/src/test/java/org/apache/usergrid/tools/ExportImportAdminsTest.java
+++ b/stack/tools/src/test/java/org/apache/usergrid/tools/ExportImportAdminsTest.java
@@ -4,7 +4,7 @@
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
+ * the License.  You may obtain a copy of the License at:223
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -26,6 +26,8 @@ import org.apache.usergrid.ServiceITSuite;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.management.OrganizationOwnerInfo;
 import org.apache.usergrid.management.UserInfo;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.utils.UUIDUtils;
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
@@ -40,13 +42,13 @@ import java.io.FilenameFilter;
 import java.util.*;
 
 import static junit.framework.TestCase.assertNotNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.apache.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION_ID;
+import static org.junit.Assert.*;
 
 
 public class ExportImportAdminsTest {
     static final Logger logger = LoggerFactory.getLogger( ExportImportAdminsTest.class );
-
+    
     @ClassRule
     public static ServiceITSetup setup = new ServiceITSetupImpl( ServiceITSuite.cassandraResource
);
 
@@ -146,21 +148,28 @@ public class ExportImportAdminsTest {
     public void testImportAdminUsersAndOrgs() throws Exception {
 
         // first: generate the data file with unique user and org IDs and names
+        
+        // data contains three users each with a unique org, one user has a duplicate email
 
         String rand1 = RandomStringUtils.randomAlphanumeric( 10 );
         String rand2 = RandomStringUtils.randomAlphanumeric( 10 );
+        String rand3 = RandomStringUtils.randomAlphanumeric( 10 );
 
         UUID user_uuid_1 = UUIDUtils.newTimeUUID();
         UUID user_uuid_2 = UUIDUtils.newTimeUUID();
+        UUID user_uuid_3 = UUIDUtils.newTimeUUID();
 
         UUID org_uuid_1  = UUIDUtils.newTimeUUID();
         UUID org_uuid_2  = UUIDUtils.newTimeUUID();
+        UUID org_uuid_3  = UUIDUtils.newTimeUUID();
 
-        String user_name_1 = "user_" + rand1;
-        String user_name_2 = "user_" + rand2;
+        String user_name_1 = "user1_" + rand1;
+        String user_name_2 = "user2_" + rand2;
+        String user_name_3 = "user3_" + rand3;
 
-        String org_name_1  = "org_"  + rand1;
-        String org_name_2  = "org_"  + rand2;
+        String org_name_1  = "org1_"  + rand1;
+        String org_name_2  = "org2_"  + rand2;
+        String org_name_3  = "org3_"  + rand3;
 
         // loop through resource files with prefix 'admin-user' those are the data file templates
 
@@ -179,15 +188,19 @@ public class ExportImportAdminsTest {
 
                 fileContent = fileContent.replaceAll( "USER_UUID_1", user_uuid_1.toString()
);
                 fileContent = fileContent.replaceAll( "USER_UUID_2", user_uuid_2.toString()
);
+                fileContent = fileContent.replaceAll( "USER_UUID_3", user_uuid_3.toString()
);
 
                 fileContent = fileContent.replaceAll( "ORG_UUID_1",  org_uuid_1.toString()
);
                 fileContent = fileContent.replaceAll( "ORG_UUID_2",  org_uuid_2.toString()
);
+                fileContent = fileContent.replaceAll( "ORG_UUID_3",  org_uuid_3.toString()
);
 
                 fileContent = fileContent.replaceAll( "USER_NAME_1", user_name_1 );
                 fileContent = fileContent.replaceAll( "USER_NAME_2", user_name_2 );
+                fileContent = fileContent.replaceAll( "USER_NAME_3", user_name_3 );
 
                 fileContent = fileContent.replaceAll( "ORG_NAME_1", org_name_1 );
                 fileContent = fileContent.replaceAll( "ORG_NAME_2", org_name_2 );
+                fileContent = fileContent.replaceAll( "ORG_NAME_3", org_name_3 );
 
                 FileOutputStream os = new FileOutputStream(
                         tempDir.getAbsolutePath() + File.separator + fileName );
@@ -200,35 +213,45 @@ public class ExportImportAdminsTest {
         // import data from temp directory
 
         ImportAdmins importAdmins = new ImportAdmins();
-        importAdmins.startTool( new String[] {
-            "-host", "localhost:" + ServiceITSuite.cassandraResource.getRpcPort(),
-            "-inputDir", tempDir.getAbsolutePath()
+        importAdmins.startTool( new String[]{
+                "-host", "localhost:" + ServiceITSuite.cassandraResource.getRpcPort(),
+                "-inputDir", tempDir.getAbsolutePath()
         }, false );
 
         // verify that users and orgs were created correctly
 
         OrganizationInfo orgInfo1 = setup.getMgmtSvc().getOrganizationByUuid( org_uuid_1
);
-        assertNotNull( orgInfo1 );
+        assertNotNull( "org 1 exists", orgInfo1 );
+        List<UserInfo> org1_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_1 );
+        assertEquals("org1 has one user", 1, org1_users.size() );
 
         OrganizationInfo orgInfo2 = setup.getMgmtSvc().getOrganizationByUuid( org_uuid_2
);
-        assertNotNull( orgInfo2 );
+        assertNotNull( "org 2 exists", orgInfo2 );
+        List<UserInfo> org2_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_2 );
+        assertEquals( "org2 has two users", 2, org2_users.size() );
+        
+        OrganizationInfo orgInfo3 = setup.getMgmtSvc().getOrganizationByUuid( org_uuid_3
);
+        assertNotNull( "org 3 exists", orgInfo3 );
+        List<UserInfo> org3_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_3 );
+        assertEquals( "org 3 has 1 users", 1, org3_users.size() );
 
         BiMap<UUID, String> user1_orgs = setup.getMgmtSvc().getOrganizationsForAdminUser(
user_uuid_1 );
-        assertEquals("user1 has two orgs", 2, user1_orgs.size() );
-
+        assertEquals( "user 1 has 2 orgs", 2, user1_orgs.size() );
+        
         BiMap<UUID, String> user2_orgs = setup.getMgmtSvc().getOrganizationsForAdminUser(
user_uuid_2 );
-        assertEquals("user2 has one orgs", 1, user2_orgs.size() );
+        assertEquals( "user 2 has two orgs gained one from duplicate", 2, user2_orgs.size()
);
 
-        List<UserInfo> org1_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_1 );
-        assertEquals("org1 has one user", 1, org1_users.size() );
+        try {
+            BiMap<UUID, String> user3_orgs = setup.getMgmtSvc().getOrganizationsForAdminUser(
user_uuid_3 );
+            fail("fetch user 3 should have thrown exception");
+        } catch ( Exception expected ) {
+            logger.info("EXCEPTION EXPECTED");
+        }
 
-        List<UserInfo> org2_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_2 );
-        assertEquals("org2 has two users", 2, org2_users.size() );
+        EntityManager em = setup.getEmf().getEntityManager( MANAGEMENT_APPLICATION_ID );
+        Entity user3 = em.get( user_uuid_3 );
+        assertNull( "duplicate user does not exist", user3 );
 
-        UserInfo user1info = setup.getMgmtSvc().getAdminUserByUuid( user_uuid_1 );
-        Map<String, Object> user1_data = setup.getMgmtSvc().getAdminUserOrganizationData(
user1info, false );
-        Map<String, Object> user1_data_orgs = (Map<String, Object>)user1_data.get("organizations");
-        assertEquals( 2, user1_data_orgs.size());
 
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/test/resources/admin-user-metadata.usergrid-management.1433331614293.json
----------------------------------------------------------------------
diff --git a/stack/tools/src/test/resources/admin-user-metadata.usergrid-management.1433331614293.json
b/stack/tools/src/test/resources/admin-user-metadata.usergrid-management.1433331614293.json
index 320f8ed..86d7363 100644
--- a/stack/tools/src/test/resources/admin-user-metadata.usergrid-management.1433331614293.json
+++ b/stack/tools/src/test/resources/admin-user-metadata.usergrid-management.1433331614293.json
@@ -81,5 +81,57 @@
         }
       }
     }
+  }, 
+  "USER_UUID_3" : {
+    "activities": [],
+    "devices": [],
+    "feed": [
+      "4c8fee64-09e5-11e5-b3c6-57cd4e12c0b1"
+    ],
+    "groups": [
+      "4c88c26a-09e5-11e5-8a66-594dd93a503d"
+    ],
+    "roles": [],
+    "connections": {},
+    "organizations": [
+      {
+        "uuid": "ORG_UUID_3",
+        "name": "ORG_NAME_3"
+      }
+    ],
+    "dictionaries": {
+      "credentials": {
+        "mongo_pwd": {
+          "recoverable": true,
+          "encrypted": false,
+          "secret": "e7b4fc7db5b97088997e44eced015d42",
+          "hashType": null,
+          "created": 1433331614067,
+          "cryptoChain": [
+            "plaintext"
+          ]
+        },
+        "password": {
+          "recoverable": false,
+          "encrypted": true,
+          "secret": "JDJhJDA5JER0RTdNSldMRjkxSUlJVm5hZWJMTy5DelFLemwvd2tXdUttaHViZWdyRjRURVdxYk5TUGJt",
+          "hashType": null,
+          "created": 1433331614018,
+          "cryptoChain": [
+            "bcrypt"
+          ]
+        },
+        "secret": {
+          "recoverable": true,
+          "encrypted": false,
+          "secret": "YWQ6Rx9A-m5U-TihpkPVS4PmyQO4qig",
+          "hashType": null,
+          "created": 1433331614067,
+          "cryptoChain": [
+            "plaintext"
+          ]
+        }
+      }
+    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/16de78d9/stack/tools/src/test/resources/admin-users.usergrid-management.1433331614293.json
----------------------------------------------------------------------
diff --git a/stack/tools/src/test/resources/admin-users.usergrid-management.1433331614293.json
b/stack/tools/src/test/resources/admin-users.usergrid-management.1433331614293.json
index 5f192bf..3f15986 100644
--- a/stack/tools/src/test/resources/admin-users.usergrid-management.1433331614293.json
+++ b/stack/tools/src/test/resources/admin-users.usergrid-management.1433331614293.json
@@ -20,4 +20,16 @@
   "activated" : true,
   "confirmed" : true,
   "disabled" : false
+}, {
+  "uuid" : "USER_UUID_3",
+  "type" : "user",
+  "name" : "USER_NAME_3",
+  "created" : 1433331614002,
+  "modified" : 1433331614002,
+  "username" : "USER_NAME_3",
+  "comment" : "this is a duplicate user, has same email address as user2",
+  "email" : "USER_NAME_2@example.com",
+  "activated" : true,
+  "confirmed" : true,
+  "disabled" : false
 } ]
\ No newline at end of file


Mime
View raw message