usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [2/4] usergrid git commit: Added ability to check one email.
Date Sat, 12 Dec 2015 19:39:24 GMT
Added ability to check one email.


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

Branch: refs/heads/unique_index_logging
Commit: cabd54a13c99aa25984be1bffc36df1fb87f381b
Parents: 5a96416
Author: George Reyes <grey@apache.org>
Authored: Fri Dec 11 10:15:58 2015 -0800
Committer: George Reyes <grey@apache.org>
Committed: Fri Dec 11 10:15:58 2015 -0800

----------------------------------------------------------------------
 .../usergrid/tools/ManagementUserAudit.java     | 117 ++++++++++++-------
 1 file changed, 74 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/cabd54a1/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
b/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
index d1eea62..9c100d9 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/ManagementUserAudit.java
@@ -32,6 +32,7 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 
+import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.Query;
 
@@ -73,7 +74,9 @@ public class ManagementUserAudit extends ToolBase {
 
     private static final Logger logger = LoggerFactory.getLogger( ManagementUserAudit.class
);
 
-    private static final String ENTITY_UNIQUE_PROPERTY_VALUE = "file";
+    private static final String FILE_PATH = "file";
+
+    private static final String DUPLICATE_EMAIL = "dup";
 
 
     @Override
@@ -89,11 +92,15 @@ public class ManagementUserAudit extends ToolBase {
 
         options.addOption( hostOption );
 
-        Option entityUniquePropertyValue =
-                OptionBuilder.withArgName( ENTITY_UNIQUE_PROPERTY_VALUE ).hasArg().isRequired(
true )
-                             .withDescription( "file path" ).create( ENTITY_UNIQUE_PROPERTY_VALUE
);
-        options.addOption( entityUniquePropertyValue );
+        Option file_path =
+                OptionBuilder.withArgName( FILE_PATH ).hasArg().isRequired( false )
+                             .withDescription( "file path" ).create( FILE_PATH );
+        options.addOption( file_path );
 
+        Option duplicate_email =
+                OptionBuilder.withArgName( DUPLICATE_EMAIL ).hasArg().isRequired( false )
+                             .withDescription( "duplicate email to examine" ).create( DUPLICATE_EMAIL
);
+        options.addOption( duplicate_email );
 
         return options;
     }
@@ -113,59 +120,83 @@ public class ManagementUserAudit extends ToolBase {
 
         EntityManager em = emf.getEntityManager( MANAGEMENT_APPLICATION_ID );
 
-        ObjectMapper objectMapper = new ObjectMapper(  );
-
-        File jsonObjectFile = new File(line.getOptionValue( "file" ));
-
-        JsonNode node =  objectMapper.readTree( jsonObjectFile );
-
-        JsonNode users = node.get( "user" );
+        if(line.getOptionValue( ("file") ) == null) {
+            if ( line.getOptionValue( "dup" )!=null){
+                String extractedEmail = line.getOptionValue( "dup" );
+                column_verification( em, extractedEmail );
+             }
+            else{
+                logger.error("Need to have -file or -dup not both and certainly not neither.");
+            }
+        }
+        else {
+            ObjectMapper objectMapper = new ObjectMapper();
 
-        for(JsonNode email:users) {
+            File jsonObjectFile = new File( line.getOptionValue( "file" ) );
 
-            String extractedEmail = email.get( "name" ).getTextValue();
+            JsonNode node = objectMapper.readTree( jsonObjectFile );
 
-            Query query = new Query();
-            query.setEntityType( "user" );
-            query.addEqualityFilter( "email", extractedEmail );
-            //maybe this could be changed to detect duplicates
-            query.setLimit( 1 );
-            query.setResultsLevel( REFS );
+            JsonNode users = node.get( "user" );
 
+            for ( JsonNode email : users ) {
 
+                String extractedEmail = email.get( "name" ).getTextValue();
+                column_verification( em, extractedEmail );
+            }
+            logger.info( "Completed logging successfully" );
+        }
+    }
 
-            UUID applicationId = MANAGEMENT_APPLICATION_ID;
-            String collectionName = "users";
-            String uniqueValueKey = "email";
-            String uniqueValue = extractedEmail;
+    private void column_verification( final EntityManager em, final String extractedEmail
) throws Exception {UUID
+            applicationId = MANAGEMENT_APPLICATION_ID;
+        String collectionName = "users";
+        String uniqueValueKey = "email";
+        String uniqueValue = extractedEmail;
 
 
-            Object key = key( applicationId, collectionName, uniqueValueKey, uniqueValue
);
+        Object key = key( applicationId, collectionName, uniqueValueKey, uniqueValue );
 
 
-            List<HColumn<ByteBuffer, ByteBuffer>> cols = cass.getAllColumns(
cass.getApplicationKeyspace( applicationId ),ENTITY_UNIQUE,key,be,be );
+        List<HColumn<ByteBuffer, ByteBuffer>> cols =
+                cass.getAllColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_UNIQUE,
key, be, be );
 
-            if ( cols.size() == 1  ) {
+        if ( cols.size() == 1 ) {
+            UUID uuid = null;
+            for ( HColumn<ByteBuffer, ByteBuffer> col : cols ) {
+                uuid = ue.fromByteBuffer( col.getName() );
+            }
+            if ( em.get( uuid ) == null ) {
+                logger.error( "Email: {} with uuid: {} doesn't exist in ENTITY_PROPERTIES.",
extractedEmail,
+                        uuid );
+            }
+            else {
+                logger.info( "Email: {}  with uuid: {} exists in ENTITY_PROPERTIES", extractedEmail,
uuid );
+            }
+        }
+        else {
+            if ( cols.size() == 0 ) {
+                logger.error( "Email: {} doesn't exist in ENTITY_UNIQUE.", extractedEmail
);
+            }
+            else {
+                logger.error( "Email: {} has {} number of duplicate columns in ENTITY_UNIQUE",
extractedEmail,
+                        cols.size() );
                 UUID uuid = null;
                 for ( HColumn<ByteBuffer, ByteBuffer> col : cols ) {
-                    uuid = ue.fromByteBuffer( col.getName());
-                }
-                if ( em.get( uuid ) == null ) {
-                    logger.error( "Email: {} with uuid: {} doesn't exist in ENTITY_PROPERTIES.",
extractedEmail,uuid);
-                }
-                else {
-                    logger.info( "Email: {}  with uuid: {} exists in ENTITY_PROPERTIES",
extractedEmail,uuid);
-                }
-            }
-            else{
-                if(cols.size() == 0) {
-                    logger.error( "Email: {} doesn't exist in ENTITY_UNIQUE.", extractedEmail
);
-                }
-                else{
-                    logger.error("Email: {} has {} number of duplicate columns in ENTITY_UNIQUE",extractedEmail,cols.size());
+                    uuid = ue.fromByteBuffer( col.getName() );
+                    Entity entity = em.get( uuid );
+                    if ( entity == null ) {
+                        logger.error( "Email: {} with duplicate uuid: {} doesn't exist in
ENTITY_PROPERTIES.", extractedEmail,
+                                uuid );
+                    }
+                    else {
+                        Object[] loggerObject = new Object[3];
+                        loggerObject[0] = extractedEmail;
+                        loggerObject[1] = uuid;
+                        loggerObject[2] = entity;
+                        logger.info( "Email: {}  with duplicate uuid: {} with the following
data: {} exists in ENTITY_PROPERTIES", extractedEmail, uuid );
+                    }
                 }
             }
         }
-        logger.info( "Completed logging successfully" );
     }
 }


Mime
View raw message