usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject incubator-usergrid git commit: Small fixes to ImportAdmins tool based on results of testing.
Date Fri, 05 Jun 2015 20:22:19 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/master 4ca6e2c34 -> e8a5d47d0


Small fixes to ImportAdmins tool based on results of testing.


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

Branch: refs/heads/master
Commit: e8a5d47d0e84e0f387aac98c1f15503eeee9131d
Parents: 4ca6e2c
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Fri Jun 5 16:04:17 2015 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Fri Jun 5 16:04:17 2015 -0400

----------------------------------------------------------------------
 .../cassandra/ManagementServiceImpl.java        |  7 +++-
 .../org/apache/usergrid/tools/ImportAdmins.java | 43 ++++++++++++--------
 .../usergrid/tools/ExportImportAdminsTest.java  | 12 +++---
 3 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e8a5d47d/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 8561300..46739b4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -1480,7 +1480,12 @@ public class ManagementServiceImpl implements ManagementService {
                 path = path.toLowerCase();
             }
 
-            organizations.put( entity.getUuid(), path );
+            try {
+                organizations.put( entity.getUuid(), path );
+            } catch (IllegalArgumentException e) {
+                logger.warn("Error adding " + entity.getUuid() + ":" + path + " to BiMap:
" + e.getMessage() );
+            }
+
         }
 
         return organizations;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e8a5d47d/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 bf0a2e4..49757ee 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
@@ -363,31 +363,38 @@ public class ImportAdmins extends ToolBase {
         List<Object> organizationsList = (List<Object>) metadata.get( "organizations"
);
         if (organizationsList != null && !organizationsList.isEmpty()) {
 
-            for ( Object orgObject : organizationsList ) {
+            User user = em.get( entityRef, User.class );
 
-                Map<String, Object> orgMap = (Map<String, Object>)orgObject;
-                UUID orgUuid = UUID.fromString( (String)orgMap.get("uuid") );
-                String orgName = (String)orgMap.get("name");
+            if ( user == null ) {
+                logger.error("User with uuid={} not found, not adding to organizations");
+
+            } else {
 
-                User user = em.get( entityRef, User.class );
                 final UserInfo userInfo = managementService.getAdminUserByEmail( user.getEmail()
);
 
-                // create org only if it does not exist
-                OrganizationInfo orgInfo = managementService.getOrganizationByUuid( orgUuid
);
-                if ( orgInfo == null ) {
-                    try {
-                        managementService.createOrganization( orgUuid, orgName, userInfo,
false );
-                        orgInfo = managementService.getOrganizationByUuid( orgUuid );
+                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" );
 
-                        logger.debug( "Created new org {} for user {}",
-                            new Object[]{orgInfo.getName(), user.getEmail()} );
+                    // create org only if it does not exist
+                    OrganizationInfo orgInfo = managementService.getOrganizationByUuid( orgUuid
);
+                    if (orgInfo == null) {
+                        try {
+                            managementService.createOrganization( orgUuid, orgName, userInfo,
false );
+                            orgInfo = managementService.getOrganizationByUuid( orgUuid );
 
-                    } catch (DuplicateUniquePropertyExistsException dpee ) {
-                        logger.error("Org {} already exists", orgName );
+                            logger.debug( "Created new org {} for user {}",
+                                    new Object[]{orgInfo.getName(), user.getEmail()} );
+
+                        } catch (DuplicateUniquePropertyExistsException dpee) {
+                            logger.error( "Org {} already exists", orgName );
+                        }
+                    } else {
+                        managementService.addAdminUserToOrganization( userInfo, orgInfo,
false );
+                        logger.debug( "Added user {} to org {}", new Object[]{user.getEmail(),
orgName} );
                     }
-                } else {
-                    managementService.addAdminUserToOrganization( userInfo, orgInfo, false
);
-                    logger.debug( "Added user {} to org {}", new Object[]{user.getEmail(),
orgName} );
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e8a5d47d/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 bab6150..898a97d 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
@@ -37,10 +37,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
 
 import static junit.framework.TestCase.assertNotNull;
 import static org.junit.Assert.assertEquals;
@@ -227,6 +224,11 @@ public class ExportImportAdminsTest {
 
         List<UserInfo> org2_users = setup.getMgmtSvc().getAdminUsersForOrganization(
org_uuid_2 );
         assertEquals("org2 has two users", 2, org2_users.size() );
-    }
 
+        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


Mime
View raw message