usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject usergrid git commit: Fixed up AdminPointerFix to work with non standard data.
Date Wed, 02 Dec 2015 19:04:47 GMT
Repository: usergrid
Updated Branches:
  refs/heads/FixedAdminPointerFix [created] 9e0f0d30d


Fixed up AdminPointerFix to work with non standard data.


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

Branch: refs/heads/FixedAdminPointerFix
Commit: 9e0f0d30d93dc260f1807d97591587ac07ac62fd
Parents: 65ed997
Author: George Reyes <grey@apache.org>
Authored: Wed Dec 2 11:04:44 2015 -0800
Committer: George Reyes <grey@apache.org>
Committed: Wed Dec 2 11:04:44 2015 -0800

----------------------------------------------------------------------
 .../apache/usergrid/tools/AdminPointerFix.java  | 61 +++++---------------
 1 file changed, 16 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/9e0f0d30/stack/tools/src/main/java/org/apache/usergrid/tools/AdminPointerFix.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/AdminPointerFix.java b/stack/tools/src/main/java/org/apache/usergrid/tools/AdminPointerFix.java
index 6243571..b3cd649 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/AdminPointerFix.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/AdminPointerFix.java
@@ -33,6 +33,7 @@ import org.apache.commons.cli.Options;
 import org.apache.usergrid.management.UserInfo;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.PagingResultsIterator;
 import org.apache.usergrid.persistence.Query;
 import org.apache.usergrid.persistence.Results;
 import org.apache.usergrid.persistence.cassandra.CassandraService;
@@ -54,6 +55,9 @@ public class AdminPointerFix extends ExportingToolBase {
 
     private static final Logger logger = LoggerFactory.getLogger( AdminPointerFix.class );
 
+    private static final String QUERY_ARG = "query";
+
+
 
     @Override
     @SuppressWarnings( "static-access" )
@@ -63,10 +67,13 @@ public class AdminPointerFix extends ExportingToolBase {
                 OptionBuilder.withArgName( "host" ).hasArg().isRequired( true ).withDescription(
"Cassandra host" )
                              .create( "host" );
 
+        Option queryOption = OptionBuilder.withArgName( QUERY_ARG ).hasArg().isRequired(
false )
+                                          .withDescription( "query" ).create( QUERY_ARG );
 
 
         Options options = new Options();
         options.addOption( hostOption );
+        options.addOption( queryOption );
 
         return options;
     }
@@ -87,59 +94,23 @@ public class AdminPointerFix extends ExportingToolBase {
         // search for all orgs
 
         Query query = new Query();
-        query.setLimit( PAGE_SIZE );
-        Results r = null;
-
-        Multimap<String, UUID> emails = HashMultimap.create();
-        Multimap<String, UUID> usernames = HashMultimap.create();
-        do {
-
-            //get all users in the management app and page for each set of a PAGE_SIZE
-            r = em.searchCollection( app, "users", query );
-
-            for ( Entity entity : r.getEntities() ) {
-                //grab all emails returned
-                emails.put( entity.getProperty( "email" ).toString().toLowerCase(), entity.getUuid()
);
-                //grab all usernames returned.
-                usernames.put( entity.getProperty( "username" ).toString().toLowerCase(),
entity.getUuid() );
-            }
-
-            query.setCursor( r.getCursor() );
-
-            logger.info( "Searching next page" );
+        if(line.getOptionValue( QUERY_ARG ) !=null){
+            query = query.fromQL( line.getOptionValue( QUERY_ARG )  );
         }
-        while ( r != null && r.size() == PAGE_SIZE );
-
-
-        //do  a get on a specific username, if it shows up more than once then remove it
-        for ( String username : usernames.keySet() ) {
-            Collection<UUID> ids = usernames.get( username );
-
-            if ( ids.size() > 1 ) {
-                logger.info( "Found multiple users with the username {}", username );
-                System.out.println("Found multiple users with the username"+ username+".
Run DupAdmiRepair.");
-
-            }
-        }
-
-        for ( String email : emails.keySet() ) {
-            Collection<UUID> ids = emails.get( email );
+        query.setLimit( PAGE_SIZE );
 
-            if ( ids.size() > 1 ) {
-                logger.info( "Found multiple users with the email {}", email );
-                System.out.println("Found multiple users with the username"+ email+". Run
DupAdmiRepair.");
+        PagingResultsIterator pagingResultsIterator = new PagingResultsIterator( em.searchCollection(
app, "users", query ) );
 
-            }
 
+        while(pagingResultsIterator.hasNext()){
+            Entity entity = ( Entity ) pagingResultsIterator.next();
 
+            String email = entity.getProperty( "email" ).toString().toLowerCase();
             UserInfo targetUser = managementService.getAdminUserByEmail( email );
 
             if ( targetUser == null ) {
-                //This means that the org is mis associated with the user.
-                List<UUID> tempIds = new ArrayList<UUID>( ids );
-                //Collections.sort( tempIds );
 
-                UUID toLoad = tempIds.get( 0 );
+                UUID toLoad = entity.getUuid();
 
                 logger.warn( "Could not load target user by email {}, loading by UUID {}
instead", email, toLoad );
                 System.out.println("Could not load the target user by email: "+email+". Loading
by the following uuid instead: "+toLoad.toString());
@@ -150,7 +121,7 @@ public class AdminPointerFix extends ExportingToolBase {
                 }catch(DuplicateUniquePropertyExistsException dup){
                     System.out.println("Found duplicate unique property: "+dup.getPropertyName()+
". Duplicate property is: "+dup.getPropertyValue());
                     if (dup.getPropertyName().equals( "username" )){
-                       targetUserEntity.setUsername( targetUserEntity.getEmail() );
+                        targetUserEntity.setUsername( targetUserEntity.getEmail() );
                     }
                     else
                         throw dup;


Mime
View raw message