usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [46/51] [abbrv] git commit: Avoid NPE in ManagementServiceImpl
Date Thu, 16 Jan 2014 17:30:42 GMT
Avoid NPE in ManagementServiceImpl


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

Branch: refs/heads/two-dot-o
Commit: 3f762ece4bcd0eaa8acbb0f8fb2114becbfbf332
Parents: 1140631
Author: Sungju Jin <sungju@softwaregeeks.org>
Authored: Thu Jan 16 22:52:26 2014 +0900
Committer: Sungju Jin <sungju@softwaregeeks.org>
Committed: Thu Jan 16 22:52:26 2014 +0900

----------------------------------------------------------------------
 .../cassandra/ManagementServiceImpl.java        | 32 ++++++++++++++------
 1 file changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3f762ece/stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
index f7cc99c..8257514 100644
--- a/stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -290,7 +290,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public void setup() throws Exception {
 
-        if ( parseBoolean( properties.getProperty( PROPERTIES_SETUP_TEST_ACCOUNT ) ) ) {
+        if ( getBooleanProperty( PROPERTIES_SETUP_TEST_ACCOUNT ) ) {
             String test_app_name = properties.getProperty( PROPERTIES_TEST_ACCOUNT_APP );
             String test_organization_name = properties.getProperty( PROPERTIES_TEST_ACCOUNT_ORGANIZATION
);
             String test_admin_username = properties.getProperty( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_USERNAME
);
@@ -328,7 +328,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public boolean superuserEnabled() {
-        boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
) );
+        boolean superuser_enabled = getBooleanProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
);
         String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME
);
         String superuser_email = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL
);
         String superuser_password = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_PASSWORD
);
@@ -339,7 +339,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public void provisionSuperuser() throws Exception {
-        boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
) );
+        boolean superuser_enabled = getBooleanProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
);
         String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME
);
         String superuser_email = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL
);
         String superuser_password = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_PASSWORD
);
@@ -1247,13 +1247,11 @@ public class ManagementServiceImpl implements ManagementService {
             userInfo = getUserInfo( MANAGEMENT_APPLICATION_ID, user );
 
             boolean userIsSuperAdmin =
-                    properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL ).equals( userInfo.getEmail()
);
-
-            boolean testUserEnabled = parseBoolean( properties.getProperty( PROPERTIES_SETUP_TEST_ACCOUNT
) );
+                    StringUtils.equals( getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL ), userInfo.getEmail()
);
+            boolean testUserEnabled = getBooleanProperty( PROPERTIES_SETUP_TEST_ACCOUNT );
 
             boolean userIsTestUser = !testUserEnabled ? false :
-                                     properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL
)
-                                               .equals( userInfo.getEmail() );
+                    StringUtils.equals(getProperty( PROPERTIES_SYSADMIN_LOGIN_EMAIL ), userInfo.getEmail());
 
             if ( !userIsSuperAdmin && !userIsTestUser ) {
 
@@ -1489,7 +1487,7 @@ public class ManagementServiceImpl implements ManagementService {
 
         Map<UUID, String> organizations;
 
-        boolean superuser_enabled = parseBoolean( properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
) );
+        boolean superuser_enabled = getBooleanProperty( PROPERTIES_SYSADMIN_LOGIN_ALLOWED
);
         String superuser_username = properties.getProperty( PROPERTIES_SYSADMIN_LOGIN_NAME
);
         if ( superuser_enabled && ( superuser_username != null ) && superuser_username.equals(
user.getUsername() ) ) {
             organizations = buildOrgBiMap( getOrganizations( null, 10 ) );
@@ -2906,4 +2904,20 @@ public class ManagementServiceImpl implements ManagementService {
         // TODO Auto-generated method stub
         return null;
     }
+
+    private String getProperty(String key) {
+        String obj = properties.getProperty(key);
+        if(StringUtils.isEmpty(obj))
+            return null;
+        else
+            return obj;
+    }
+
+    private boolean getBooleanProperty(String key) {
+        String obj = getProperty(key);
+        if(StringUtils.isEmpty(obj))
+            return false;
+        else
+            return Boolean.parseBoolean(obj);
+    }
 }


Mime
View raw message