usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject usergrid git commit: USERGRID-992: handle config file org config defaults and returning those defaults when app not associated with an org (as in mgmt app at this point).
Date Sat, 26 Sep 2015 02:37:43 GMT
Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-992 109ce2de7 -> faa3450d1


USERGRID-992: handle config file org config defaults
and returning those defaults when app not associated with an org
(as in mgmt app at this point).

Only the connection parameter org config item works at this point.

Will add other parameters' functionality in USERGRID-933 branch.


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

Branch: refs/heads/USERGRID-992
Commit: faa3450d1bf5855b4f2d012ecae2446a23fc59cd
Parents: 109ce2d
Author: Mike Dunker <mdunker@apigee.com>
Authored: Fri Sep 25 19:34:39 2015 -0700
Committer: Mike Dunker <mdunker@apigee.com>
Committed: Fri Sep 25 19:34:39 2015 -0700

----------------------------------------------------------------------
 .../usergrid/management/OrganizationConfig.java | 119 +++++++----
 .../management/OrganizationConfigProps.java     |  40 ++++
 .../cassandra/ManagementServiceImpl.java        | 202 +++++++++++--------
 .../cassandra/OrganizationConfigPropsImpl.java  |  71 +++++++
 4 files changed, 300 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/faa3450d/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
index 0fe775b..276bad8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
@@ -17,61 +17,113 @@
 package org.apache.usergrid.management;
 
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
-import static org.apache.usergrid.persistence.Schema.PROPERTY_PATH;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
-
 
 public class OrganizationConfig {
 
-    public static final String DEFAULT_CONNECTION_PARAM_PROPERTY = "defaultConnectionParam";
-    private static final String DEFAULT_CONNECTION_PARAM_DEFAULT_VALUE = "all";
+    private static final String DEFAULT_CONNECTION_PARAM_DEFAULTVALUE = "all";
+
+    private static final String ADMIN_SYSADMIN_EMAIL_DEFAULTVALUE = null; // null will fall
back to system level admin
+
+    private static final String ADMIN_ACTIVATION_URL_DEFAULTVALUE = ""; // should be configured
in properties file
+
+    private static final String ADMIN_CONFIRMATION_URL_DEFAULTVALUE = ""; // should be configured
in properties file
 
+    private static final String ADMIN_RESETPW_URL_DEFAULTVALUE = ""; // should be configured
in properties file
+
+    // properties in property file and
     private static final String [] propertyNames = {
-            DEFAULT_CONNECTION_PARAM_PROPERTY
+            OrganizationConfigProps.PROPERTIES_DEFAULT_CONNECTION_PARAM,
+            OrganizationConfigProps.PROPERTIES_ADMIN_SYSADMIN_EMAIL,
+            OrganizationConfigProps.PROPERTIES_ADMIN_ACTIVATION_URL,
+            OrganizationConfigProps.PROPERTIES_ADMIN_CONFIRMATION_URL,
+            OrganizationConfigProps.PROPERTIES_ADMIN_RESETPW_URL
     };
 
-    private static final String [] defaultValues = {
-            DEFAULT_CONNECTION_PARAM_DEFAULT_VALUE
+    // values to use if not found in config files
+    private static final String [] noConfigDefaults = {
+            DEFAULT_CONNECTION_PARAM_DEFAULTVALUE,
+            ADMIN_SYSADMIN_EMAIL_DEFAULTVALUE,
+            ADMIN_ACTIVATION_URL_DEFAULTVALUE,
+            ADMIN_CONFIRMATION_URL_DEFAULTVALUE,
+            ADMIN_RESETPW_URL_DEFAULTVALUE
     };
 
+    private Map<String, String> defaultProperties;
+
     private UUID id;
     private String name;
-    private Map<String, Object> properties;
+    private Map<String, Object> orgConfigProperties;
 
+    private void setDefaultProperties(OrganizationConfigProps configFileProperties) {
+        defaultProperties = new HashMap<>();
+        for (int i = 0; i < propertyNames.length; i++) {
+            String propertyValue = configFileProperties != null ? configFileProperties.getProperty(propertyNames[i])
: null;
+            defaultProperties.put(propertyNames[i], propertyValue != null ? propertyValue
: noConfigDefaults[i]);
+        }
+    }
 
-    public OrganizationConfig() {
+    private OrganizationConfig() {
     }
 
+    public OrganizationConfig(OrganizationConfigProps configFileProperties) {
+        setDefaultProperties(configFileProperties);
+        // will add id and name once default org exists
+    }
 
-    public OrganizationConfig(UUID id, String name) {
+    public OrganizationConfig(OrganizationConfigProps configFileProperties, UUID id, String
name) {
+        setDefaultProperties(configFileProperties);
         this.id = id;
         this.name = name;
     }
 
+    public OrganizationConfig(OrganizationConfigProps configFileProperties, UUID id, String
name, Map<String, Object> entityProperties) {
 
-    public OrganizationConfig(Map<String, Object> properties) {
-        id = ( UUID ) properties.get( PROPERTY_UUID );
-        name = ( String ) properties.get( PROPERTY_PATH );
+        this( configFileProperties, id, name );
+        setOrgConfigProperties(entityProperties);
     }
 
+    // replaces properties with supplied properties, and then adds defaults
+    private void setOrgConfigProperties(Map<String, Object> orgConfigProperties) {
+        this.orgConfigProperties = orgConfigProperties;
+
+        // add default values to properties map
+        addDefaultstoConfigProperties();
+    }
 
-    public OrganizationConfig(UUID id, String name, Map<String, Object> properties)
{
-        this( id, name );
-        this.properties = properties;
+    // adds supplied properties to existing properties, and then adds defaults
+    public void addProperties( Map<String, Object> orgConfigProperties ) {
+        this.orgConfigProperties.putAll(orgConfigProperties);
 
         // add default values to properties map
-        addDefaultsToProperties();
+        addDefaultstoConfigProperties();
     }
 
-    private void addDefaultsToProperties()  {
+    private void addDefaultstoConfigProperties()  {
         for (int i=0; i < propertyNames.length; i++) {
-            if (!properties.containsKey(propertyNames[i])) {
-                properties.put(propertyNames[i], defaultValues[i]);
+            if (!orgConfigProperties.containsKey(propertyNames[i])) {
+                orgConfigProperties.put(propertyNames[i], defaultProperties.get(propertyNames[i]));
+            }
+        }
+    }
+
+
+    public Map<String, Object> getOrgConfigProperties() {
+        return orgConfigProperties;
+    }
+
+    public String getProperty(String key) {
+        String retValue = null;
+        if (orgConfigProperties != null) {
+            Object value = orgConfigProperties.get(key);
+            if (value instanceof String) {
+                retValue = (String) value;
             }
         }
+        return retValue != null ? retValue : defaultProperties.get(key);
     }
 
 
@@ -96,9 +148,9 @@ public class OrganizationConfig {
 
 
     public String getDefaultConnectionParam() {
-        String defaultParam = DEFAULT_CONNECTION_PARAM_DEFAULT_VALUE;
-        if ( properties != null ) {
-            Object paramValue = properties.get( DEFAULT_CONNECTION_PARAM_PROPERTY );
+        String defaultParam = DEFAULT_CONNECTION_PARAM_DEFAULTVALUE;
+        if ( orgConfigProperties != null ) {
+            Object paramValue = orgConfigProperties.get( OrganizationConfigProps.PROPERTIES_DEFAULT_CONNECTION_PARAM
);
             if ( paramValue instanceof String ) {
                 defaultParam = ( String ) paramValue;
             }
@@ -148,23 +200,4 @@ public class OrganizationConfig {
         return true;
     }
 
-
-    public Map<String, Object> getProperties() {
-        return properties;
-    }
-
-
-    public void setProperties( Map<String, Object> properties ) {
-        this.properties = properties;
-
-        // add default values to properties map
-        addDefaultsToProperties();
-    }
-
-    public void addProperties( Map<String, Object> properties ) {
-        this.properties.putAll(properties);
-
-        // add default values to properties map
-        addDefaultsToProperties();
-    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/faa3450d/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfigProps.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfigProps.java
b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfigProps.java
new file mode 100644
index 0000000..16c4a74
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfigProps.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.management;
+
+
+import java.util.Properties;
+
+public interface OrganizationConfigProps {
+    public static final String PROPERTIES_DEFAULT_CONNECTION_PARAM = "usergrid.rest.default-connection-param";
+    public static final String PROPERTIES_ADMIN_SYSADMIN_EMAIL = AccountCreationProps.PROPERTIES_ADMIN_SYSADMIN_EMAIL;
+    public static final String PROPERTIES_ADMIN_ACTIVATION_URL = AccountCreationProps.PROPERTIES_ADMIN_ACTIVATION_URL;
+    public static final String PROPERTIES_ADMIN_CONFIRMATION_URL = AccountCreationProps.PROPERTIES_ADMIN_CONFIRMATION_URL;
+    public static final String PROPERTIES_ADMIN_RESETPW_URL = AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
+
+
+    public String getProperty(String name);
+
+    public String getProperty(String name, String defaultValue);
+
+    public boolean isProperty(String name);
+
+    public int intProperty(String name, String defaultValue);
+
+    public void setProperty(String name, String value);
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/faa3450d/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 03b798c..61c12c8 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
@@ -137,6 +137,8 @@ public class ManagementServiceImpl implements ManagementService {
 
     protected AccountCreationPropsImpl properties;
 
+    protected OrganizationConfigPropsImpl orgConfigProperties;
+
     protected LockManager lockManager;
 
     protected TokenService tokens;
@@ -167,7 +169,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Autowired
     public void setProperties( Properties properties ) {
         this.properties = new AccountCreationPropsImpl( properties );
-
+        this.orgConfigProperties = new OrganizationConfigPropsImpl( properties );
 
     }
 
@@ -342,7 +344,7 @@ public class ManagementServiceImpl implements ManagementService {
     public void postOrganizationActivity( UUID organizationId, final UserInfo user, String
verb, final EntityRef object,
                                           final String objectType, final String objectName,
String title,
                                           String content ) throws Exception {
-        ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
+        ServiceManager sm = smf.getServiceManager(smf.getManagementAppId());
 
         Map<String, Object> properties = new HashMap<String, Object>();
         properties.put( PROPERTY_VERB, verb );
@@ -377,7 +379,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public ServiceResults getOrganizationActivity( OrganizationInfo organization ) throws
Exception {
-        ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
+        ServiceManager sm = smf.getServiceManager(smf.getManagementAppId());
         return sm.newRequest( ServiceAction.GET, parameters(
             Schema.COLLECTION_GROUPS, organization.getUuid(), "feed" ) ).execute();
     }
@@ -386,7 +388,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public ServiceResults getOrganizationActivityForAdminUser( OrganizationInfo organization,
UserInfo user )
             throws Exception {
-        ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
+        ServiceManager sm = smf.getServiceManager(smf.getManagementAppId());
         return sm.newRequest( ServiceAction.GET, parameters( Schema.COLLECTION_GROUPS, organization.getUuid(),
             "users", user.getUuid(), "feed" ) ).execute();
     }
@@ -418,8 +420,8 @@ public class ManagementServiceImpl implements ManagementService {
                                                              String email, String password,
boolean activated,
                                                              boolean disabled ) throws Exception
{
         logger.debug("createOwnerAndOrganization2");
-        return createOwnerAndOrganization( organizationName, username, name, email, password,
-                activated, disabled, null, null );
+        return createOwnerAndOrganization(organizationName, username, name, email, password,
+                activated, disabled, null, null);
     }
 
 
@@ -481,14 +483,14 @@ public class ManagementServiceImpl implements ManagementService {
     private OrganizationInfo createOrganizationInternal(
         UUID orgUuid, String organizationName, UserInfo user, boolean activated ) throws
Exception {
         logger.debug("createOrganizationInternal1");
-        return createOrganizationInternal( orgUuid, organizationName, user, activated, null
);
+        return createOrganizationInternal(orgUuid, organizationName, user, activated, null);
     }
 
 
     private OrganizationInfo createOrganizationInternal( UUID orgUuid, String organizationName,
UserInfo user, boolean activated,
                                                          Map<String, Object> properties
) throws Exception {
 
-        logger.info( "createOrganizationInternal2: {}", organizationName );
+        logger.info("createOrganizationInternal2: {}", organizationName);
 
         if (  organizationName == null ) {
             logger.debug("organizationName = null");
@@ -542,7 +544,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public OrganizationInfo createOrganization(String organizationName, UserInfo user, boolean
activated)
             throws Exception {
-        return createOrganization( null, organizationName, user, activated );
+        return createOrganization(null, organizationName, user, activated);
     }
 
     @Override
@@ -633,8 +635,8 @@ public class ManagementServiceImpl implements ManagementService {
             return null;
         }
 
-        properties.put( PROPERTY_PATH, organizationName );
-        properties.put( PROPERTY_SECRET, generateOAuthSecretKey( AuthPrincipalType.ORGANIZATION
) );
+        properties.put(PROPERTY_PATH, organizationName);
+        properties.put(PROPERTY_SECRET, generateOAuthSecretKey(AuthPrincipalType.ORGANIZATION));
         Entity organization = em.create( organizationId, Group.ENTITY_TYPE, properties );
         // em.addToCollection(organization, "users", new SimpleEntityRef(
         // User.ENTITY_TYPE, userId));
@@ -754,7 +756,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     public void postUserActivity( UserInfo user, String verb, EntityRef object, String objectType,
String objectName,
                                   String title, String content ) throws Exception {
-        ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
+        ServiceManager sm = smf.getServiceManager(smf.getManagementAppId());
 
         Map<String, Object> properties = new HashMap<String, Object>();
         properties.put( PROPERTY_VERB, verb );
@@ -780,7 +782,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public ServiceResults getAdminUserActivities( UserInfo user ) throws Exception {
         ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
-        ServiceRequest request = sm.newRequest( ServiceAction.GET, parameters( "users", user.getUuid(),
"feed" ) );
+        ServiceRequest request = sm.newRequest(ServiceAction.GET, parameters("users", user.getUuid(),
"feed"));
         ServiceResults results = request.execute();
         return results;
     }
@@ -943,7 +945,7 @@ public class ManagementServiceImpl implements ManagementService {
         EntityManager em = emf.getEntityManager(smf.getManagementAppId());
         Results results =
                 em.getCollection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId),
"users", null, 10000,
-                    Level.ALL_PROPERTIES, false);
+                        Level.ALL_PROPERTIES, false);
         for ( Entity entity : results.getEntities() ) {
             users.add( getUserInfo( smf.getManagementAppId(), entity ) );
         }
@@ -1023,7 +1025,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public User getUserEntityByIdentifier( UUID applicationId, Identifier identifier ) throws
Exception {
-        EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager(applicationId);
         return em.get(em.getUserByIdentifier(identifier), User.class);
     }
 
@@ -1056,7 +1058,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public User getAdminUserEntityByIdentifier( Identifier id ) throws Exception {
-        return getUserEntityByIdentifier( smf.getManagementAppId(), id );
+        return getUserEntityByIdentifier(smf.getManagementAppId(), id);
     }
 
 
@@ -1116,7 +1118,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public UserInfo findAdminUser( String identifier ) {
-        return getUserInfo( smf.getManagementAppId(), findUserEntity( smf.getManagementAppId(),
identifier ) );
+        return getUserInfo( smf.getManagementAppId(), findUserEntity(smf.getManagementAppId(),
identifier) );
     }
 
 
@@ -1206,8 +1208,8 @@ public class ManagementServiceImpl implements ManagementService {
         int size = 0;
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
 
-        Results orgResults = em.getCollection( new SimpleEntityRef( User.ENTITY_TYPE, userId
),
-                Schema.COLLECTION_GROUPS, null, 10000, Level.REFS, false );
+        Results orgResults = em.getCollection(new SimpleEntityRef(User.ENTITY_TYPE, userId),
+                Schema.COLLECTION_GROUPS, null, 10000, Level.REFS, false);
 
         logger.debug("    orgResults.size() = " + orgResults.size());
 
@@ -1231,7 +1233,7 @@ public class ManagementServiceImpl implements ManagementService {
         }
         User user = emf.getEntityManager( smf.getManagementAppId() ).get( userId, User.class
);
 
-        return verify( smf.getManagementAppId(), user.getUuid(), password );
+        return verify(smf.getManagementAppId(), user.getUuid(), password);
     }
 
 
@@ -1241,7 +1243,7 @@ public class ManagementServiceImpl implements ManagementService {
 
         logger.debug("verifyAdminUserPasswordCredentials for {}/{}", name, password);
 
-        User user = findUserEntity( smf.getManagementAppId(), name );
+        User user = findUserEntity(smf.getManagementAppId(), name);
         if ( user == null ) {
             return null;
         }
@@ -1270,7 +1272,7 @@ public class ManagementServiceImpl implements ManagementService {
             }
             return userInfo;
         }
-        logger.info( "password compare fail for {}", name );
+        logger.info("password compare fail for {}", name);
         return null;
     }
 
@@ -1278,7 +1280,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public UserInfo verifyMongoCredentials( String name, String nonce, String key ) throws
Exception {
 
-        Entity user = findUserEntity( smf.getManagementAppId(), name );
+        Entity user = findUserEntity(smf.getManagementAppId(), name);
 
         if ( user == null ) {
             return null;
@@ -1422,7 +1424,7 @@ public class ManagementServiceImpl implements ManagementService {
             throw new IllegalArgumentException( "token is required" );
         }
 
-        Entity user = getAdminUserEntityFromAccessToken( token );
+        Entity user = getAdminUserEntityFromAccessToken(token);
         if ( !user.getUuid().equals( userId ) ) {
             throw new TokenException( "Could not match token : " + token );
         }
@@ -1486,7 +1488,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public Map<String, Object> getAdminUserOrganizationData( UUID userId ) throws Exception
{
-        UserInfo user = getAdminUserByUuid( userId );
+        UserInfo user = getAdminUserByUuid(userId);
         return getAdminUserOrganizationData( user, true );
     }
 
@@ -1551,10 +1553,10 @@ public class ManagementServiceImpl implements ManagementService {
         Map<String, Object> jsonOrganization = new HashMap<>();
         jsonOrganization.putAll( JsonUtils.toJsonMap( organization ) );
 
-        BiMap<UUID, String> applications = getApplicationsForOrganization( organization.getUuid()
);
+        BiMap<UUID, String> applications = getApplicationsForOrganization(organization.getUuid());
         jsonOrganization.put( "applications", applications.inverse() );
 
-        List<UserInfo> users = getAdminUsersForOrganization( organization.getUuid()
);
+        List<UserInfo> users = getAdminUsersForOrganization(organization.getUuid());
         Map<String, Object> jsonUsers = new HashMap<>();
         for ( UserInfo u : users ) {
             jsonUsers.put( u.getUsername(), u );
@@ -1573,7 +1575,7 @@ public class ManagementServiceImpl implements ManagementService {
             return;
         }
 
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
         em.addToCollection(new SimpleEntityRef(Group.ENTITY_TYPE, organization.getUuid()),
"users",
             new SimpleEntityRef(User.ENTITY_TYPE, user.getUuid()));
 
@@ -1590,7 +1592,7 @@ public class ManagementServiceImpl implements ManagementService {
             return;
         }
 
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
 
         try {
             if ( em.getCollection( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId
), "users", null, 2,
@@ -1653,9 +1655,9 @@ public class ManagementServiceImpl implements ManagementService {
             logger.warn("Error getting user, application created activity will not be created",
e);
         }
         if ( ( user != null ) && user.isAdminUser() ) {
-            postOrganizationActivity( organizationId, user, "create", appInfo, "Application",
applicationName,
-                "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + "
(" + user.getEmail()
-                    + ")</a> created a new application named " + applicationName, null
);
+            postOrganizationActivity(organizationId, user, "create", appInfo, "Application",
applicationName,
+                    "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName()
+ " (" + user.getEmail()
+                            + ")</a> created a new application named " + applicationName,
null);
         }
 
 
@@ -1666,7 +1668,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public void deleteApplication(UUID applicationId) throws Exception {
-        emf.deleteApplication( applicationId );
+        emf.deleteApplication(applicationId);
     }
 
 
@@ -1782,8 +1784,8 @@ public class ManagementServiceImpl implements ManagementService {
 
         // query for application_info entities
         final Results results = em.getTargetEntities(
-            new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId),
-            ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES);
+                new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId),
+                ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES);
 
         final PagingResultsIterator itr = new PagingResultsIterator( results );
 
@@ -1918,7 +1920,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public ApplicationInfo getApplicationInfoFromAccessToken( String token ) throws Exception
{
-        Entity entity = getEntityFromAccessToken( token, null, APPLICATION );
+        Entity entity = getEntityFromAccessToken(token, null, APPLICATION);
         if ( entity == null ) {
             throw new TokenException( "Could not find an entity for that access token: "
+ token );
         }
@@ -1936,7 +1938,7 @@ public class ManagementServiceImpl implements ManagementService {
         EntityManager em = emf.getEntityManager( applicationId );
         Entity entity = em.get( em.getApplicationRef() );
 
-        Results r = Results.fromEntity( entity );
+        Results r = Results.fromEntity(entity);
 
         Map<String, Object> collections = em.getApplicationCollectionMetadata();
         if ( collections.size() > 0 ) {
@@ -2001,13 +2003,13 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public String newClientSecretForOrganization( UUID organizationId ) throws Exception
{
-        return newSecretKey( AuthPrincipalType.ORGANIZATION, organizationId );
+        return newSecretKey(AuthPrincipalType.ORGANIZATION, organizationId);
     }
 
 
     @Override
     public String newClientSecretForApplication( UUID applicationId ) throws Exception {
-        return newSecretKey( AuthPrincipalType.APPLICATION, applicationId );
+        return newSecretKey(AuthPrincipalType.APPLICATION, applicationId);
     }
 
 
@@ -2088,8 +2090,8 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public String getPasswordResetTokenForAdminUser( UUID userId, long ttl ) throws Exception
{
-        return getTokenForPrincipal( EMAIL, TOKEN_TYPE_PASSWORD_RESET, smf.getManagementAppId(),
ADMIN_USER, userId,
-                ttl );
+        return getTokenForPrincipal(EMAIL, TOKEN_TYPE_PASSWORD_RESET, smf.getManagementAppId(),
ADMIN_USER, userId,
+                ttl);
     }
 
 
@@ -2151,7 +2153,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public boolean isAdminUserActivated( UUID userId ) throws Exception {
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-        return Boolean.TRUE.equals( em.getProperty( new SimpleEntityRef( User.ENTITY_TYPE,
userId ), "activated" ) );
+        return Boolean.TRUE.equals(em.getProperty(new SimpleEntityRef(User.ENTITY_TYPE, userId),
"activated"));
     }
 
 
@@ -2200,7 +2202,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public String emailMsg( Map<String, String> values, String propertyName ) {
-        return new StrSubstitutor( values ).replace( properties.getProperty( propertyName
) );
+        return new StrSubstitutor( values ).replace(properties.getProperty(propertyName));
     }
 
 
@@ -2219,11 +2221,11 @@ public class ManagementServiceImpl implements ManagementService {
 
         Map<String, String> pageContext = hashMap( "reset_url", reset_url )
                 .map( "reset_url_base", properties.getProperty( PROPERTIES_ADMIN_RESETPW_URL
) )
-                .map( "user_uuid", user.getUuid().toString() ).map( "raw_token", token );
+                .map( "user_uuid", user.getUuid().toString() ).map("raw_token", token);
 
 
-        sendHtmlMail( properties, user.getDisplayEmailAddress(), properties.getProperty(
PROPERTIES_MAILER_EMAIL ),
-                "Password Reset", appendEmailFooter( emailMsg( pageContext, PROPERTIES_EMAIL_ADMIN_PASSWORD_RESET
) ) );
+        sendHtmlMail(properties, user.getDisplayEmailAddress(), properties.getProperty(PROPERTIES_MAILER_EMAIL),
+                "Password Reset", appendEmailFooter(emailMsg(pageContext, PROPERTIES_EMAIL_ADMIN_PASSWORD_RESET)));
     }
 
 
@@ -2299,9 +2301,9 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendOrganizationActivatedEmail( OrganizationInfo organization ) throws Exception
{
-        sendOrganizationEmail( organization, "Organization Account Activated: " + organization.getName(),
-                emailMsg( hashMap( "organization_name", organization.getName() ),
-                        PROPERTIES_EMAIL_ORGANIZATION_ACTIVATED ) );
+        sendOrganizationEmail(organization, "Organization Account Activated: " + organization.getName(),
+                emailMsg(hashMap("organization_name", organization.getName()),
+                        PROPERTIES_EMAIL_ORGANIZATION_ACTIVATED));
     }
 
 
@@ -2422,10 +2424,10 @@ public class ManagementServiceImpl implements ManagementService {
 
     public void sendSysAdminNewAdminActivatedNotificationEmail( UserInfo user ) throws Exception
{
         if ( properties.notifySysAdminOfNewAdminUsers() ) {
-            sendHtmlMail( properties, getAdminSystemEmail(),
-                    properties.getProperty( PROPERTIES_MAILER_EMAIL ),
+            sendHtmlMail(properties, getAdminSystemEmail(),
+                    properties.getProperty(PROPERTIES_MAILER_EMAIL),
                     "Admin User Account Activated " + user.getEmail(), appendEmailFooter(
-                    emailMsg( hashMap( "user_email", user.getEmail() ), PROPERTIES_EMAIL_SYSADMIN_ADMIN_ACTIVATED
) ) );
+                            emailMsg(hashMap("user_email", user.getEmail()), PROPERTIES_EMAIL_SYSADMIN_ADMIN_ACTIVATED)));
         }
     }
 
@@ -2446,8 +2448,8 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendAdminUserInvitedEmail( UserInfo user, OrganizationInfo organization )
throws Exception {
-        sendAdminUserEmail( user, "User Invited To Organization",
-                emailMsg( hashMap( "organization_name", organization.getName() ), PROPERTIES_EMAIL_ADMIN_INVITED
) );
+        sendAdminUserEmail(user, "User Invited To Organization",
+                emailMsg(hashMap("organization_name", organization.getName()), PROPERTIES_EMAIL_ADMIN_INVITED));
     }
 
 
@@ -2476,7 +2478,7 @@ public class ManagementServiceImpl implements ManagementService {
             }
         }
         if ( sendEmail ) {
-            startOrganizationActivationFlow( organization );
+            startOrganizationActivationFlow(organization);
         }
 
     }
@@ -2485,7 +2487,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public void deactivateOrganization( UUID organizationId ) throws Exception {
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-        em.setProperty( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ), "activated",
false );
+        em.setProperty(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "activated",
false);
     }
 
 
@@ -2500,7 +2502,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public void enableOrganization( UUID organizationId ) throws Exception {
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-        em.setProperty( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ), "disabled",
false );
+        em.setProperty(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "disabled",
false);
     }
 
 
@@ -2547,7 +2549,7 @@ public class ManagementServiceImpl implements ManagementService {
    */
     @Override
     public void revokeAccessTokensForAppUser( UUID applicationId, UUID userId ) throws Exception
{
-        revokeTokensForPrincipal( APPLICATION_USER, applicationId, userId );
+        revokeTokensForPrincipal(APPLICATION_USER, applicationId, userId);
     }
 
 
@@ -2557,7 +2559,7 @@ public class ManagementServiceImpl implements ManagementService {
             throw new IllegalArgumentException( "token is required" );
         }
 
-        UserInfo userInfo = getAppUserFromAccessToken( token );
+        UserInfo userInfo = getAppUserFromAccessToken(token);
         if ( userInfo == null ) {
             throw new TokenException( "Could not match token : " + token );
         }
@@ -2586,7 +2588,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public User getAppUserByIdentifier( UUID applicationId, Identifier identifier ) throws
Exception {
         EntityManager em = emf.getEntityManager(applicationId);
-        return em.get( em.getUserByIdentifier( identifier ), User.class );
+        return em.get(em.getUserByIdentifier(identifier), User.class);
     }
 
 
@@ -2604,8 +2606,8 @@ public class ManagementServiceImpl implements ManagementService {
      * properties.getProperty(PROPERTIES_USER_RESETPW_URL), oi.getName(),
      * ai.getName(), user.getUuid().toString()) + "?token=" + token;
      */
-        sendHtmlMail( properties, user.getDisplayEmailAddress(), properties.getProperty(
PROPERTIES_MAILER_EMAIL ),
-                "Password Reset", appendEmailFooter( emailMsg( pageContext, PROPERTIES_EMAIL_USER_PASSWORD_RESET
) ) );
+        sendHtmlMail(properties, user.getDisplayEmailAddress(), properties.getProperty(PROPERTIES_MAILER_EMAIL),
+                "Password Reset", appendEmailFooter(emailMsg(pageContext, PROPERTIES_EMAIL_USER_PASSWORD_RESET)));
     }
 
 
@@ -2621,7 +2623,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public boolean newAppUsersRequireConfirmation( UUID applicationId ) throws Exception
{
-        EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager(applicationId);
         Boolean registration_requires_email_confirmation = ( Boolean ) em
                 .getProperty( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId
),
                         REGISTRATION_REQUIRES_EMAIL_CONFIRMATION );
@@ -2739,17 +2741,17 @@ public class ManagementServiceImpl implements ManagementService {
 
     public void sendAdminNewAppUserActivatedNotificationEmail( UUID applicationId, User user
) throws Exception {
         if ( notifyAdminOfNewAppUsers( applicationId ) ) {
-            OrganizationInfo organization = this.getOrganizationForApplication( applicationId
);
-            this.sendOrganizationEmail( organization, "New User Account Activated " + user.getEmail(),
-                    emailMsg( hashMap( "organization_name", organization.getName() ),
-                            PROPERTIES_EMAIL_ADMIN_USER_ACTIVATION ) );
+            OrganizationInfo organization = this.getOrganizationForApplication(applicationId);
+            this.sendOrganizationEmail(organization, "New User Account Activated " + user.getEmail(),
+                    emailMsg(hashMap("organization_name", organization.getName()),
+                            PROPERTIES_EMAIL_ADMIN_USER_ACTIVATION));
         }
     }
 
 
     public void sendAppUserConfirmedAwaitingActivationEmail( UUID applicationId, User user
) throws Exception {
         sendAppUserEmail( user, "User Account Confirmed",
-                properties.getProperty( PROPERTIES_EMAIL_USER_CONFIRMED_AWAITING_ACTIVATION
) );
+                properties.getProperty(PROPERTIES_EMAIL_USER_CONFIRMED_AWAITING_ACTIVATION)
);
     }
 
 
@@ -2760,7 +2762,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public void activateAppUser( UUID applicationId, UUID userId ) throws Exception {
-        EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager(applicationId);
         em.setProperty(new SimpleEntityRef(User.ENTITY_TYPE, userId), "activated", true);
     }
 
@@ -2781,7 +2783,7 @@ public class ManagementServiceImpl implements ManagementService {
         User user = em.get(userId, User.class);
 
         writeUserPassword(applicationId, user,
-            encryptionService.defaultEncryptedCredentials(newPassword, user.getUuid(), applicationId));
+                encryptionService.defaultEncryptedCredentials(newPassword, user.getUuid(),
applicationId));
     }
 
 
@@ -2832,8 +2834,8 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendAppUserEmail( User user, String subject, String html ) throws Exception
{
-        sendHtmlMail( properties, user.getDisplayEmailAddress(), properties.getProperty(
PROPERTIES_MAILER_EMAIL ),
-                subject, appendEmailFooter( html ) );
+        sendHtmlMail(properties, user.getDisplayEmailAddress(), properties.getProperty(PROPERTIES_MAILER_EMAIL),
+                subject, appendEmailFooter(html));
     }
 
 
@@ -2949,13 +2951,13 @@ public class ManagementServiceImpl implements ManagementService {
 
     /** Write the user's token */
     protected void writeUserToken( UUID appId, EntityRef owner, CredentialsInfo token ) throws
Exception {
-        writeCreds( appId, owner, token, USER_TOKEN );
+        writeCreds(appId, owner, token, USER_TOKEN);
     }
 
 
     /** Read the credentials info for the user's token */
     protected CredentialsInfo readUserToken( UUID appId, UUID ownerId, String ownerType )
throws Exception {
-        return readCreds( appId, ownerId, ownerType, USER_TOKEN );
+        return readCreds(appId, ownerId, ownerType, USER_TOKEN);
     }
 
 
@@ -2985,7 +2987,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     private void writeCreds( UUID appId, EntityRef owner, CredentialsInfo creds, String key
) throws Exception {
         EntityManager em = emf.getEntityManager( appId );
-        em.addToDictionary( owner, DICTIONARY_CREDENTIALS, key, creds );
+        em.addToDictionary(owner, DICTIONARY_CREDENTIALS, key, creds);
     }
 
 
@@ -3045,7 +3047,7 @@ public class ManagementServiceImpl implements ManagementService {
             return false;
         }
 
-        return encryptionService.verify( password, ci, userId, applicationId );
+        return encryptionService.verify(password, ci, userId, applicationId);
     }
 
 
@@ -3074,7 +3076,7 @@ public class ManagementServiceImpl implements ManagementService {
         }
 
         ApplicationService service = injector.getInstance(ApplicationService.class);
-        return service.deleteAllEntities(CpNamingUtils.getApplicationScope(applicationId),limit);
+        return service.deleteAllEntities(CpNamingUtils.getApplicationScope(applicationId),
limit);
     }
 
     private String getProperty(String key) {
@@ -3113,15 +3115,17 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public OrganizationConfig getOrganizationConfigByUuid( UUID id ) throws Exception {
 
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
         Entity entity = em.get( new SimpleEntityRef( Group.ENTITY_TYPE, id ) );
         if ( entity == null ) {
             return null;
         }
-        Map properties = em.getDictionaryAsMap( entity, ORGANIZATION_CONFIG_DICTIONARY );
-        OrganizationConfig orgConfig = new OrganizationConfig( entity.getProperties() );
-        orgConfig.setProperties( properties );
-        return orgConfig;
+        Map entityProperties = em.getDictionaryAsMap(entity, ORGANIZATION_CONFIG_DICTIONARY);
+        return new OrganizationConfig( orgConfigProperties,
+                (UUID)entity.getProperty(PROPERTY_UUID),
+                (String)entity.getProperty(PROPERTY_PATH),
+                entityProperties );
+
     }
 
 
@@ -3129,12 +3133,31 @@ public class ManagementServiceImpl implements ManagementService {
     public Map<String, Object> getOrganizationConfigData( OrganizationConfig organizationConfig
) throws Exception {
 
         Map<String, Object> jsonOrganizationConfig = new HashMap<>();
-        jsonOrganizationConfig.putAll( JsonUtils.toJsonMap( organizationConfig.getProperties()
) );
+        jsonOrganizationConfig.putAll( JsonUtils.toJsonMap( organizationConfig.getOrgConfigProperties()
) );
 
         return jsonOrganizationConfig;
     }
 
 
+    private OrganizationConfig getOrganizationConfigForUserInfo(UserInfo user) throws Exception
{
+        return getOrganizationConfigForApplication(user.getApplicationId());
+    }
+
+    private String getOrganizationConfigPropertyForUserInfo(UserInfo user, String key) throws
Exception {
+        return getOrganizationConfigForUserInfo(user).getProperty(key);
+    }
+
+    private String getOrganizationConfigPropertyForApplication(UUID applicationId, String
key) throws Exception {
+        return getOrganizationConfigForApplication(applicationId).getProperty(key);
+    }
+
+    private String getOrganizationConfigPropertyByUuid(UUID organizationId, String key) throws
Exception {
+        return getOrganizationConfigByUuid(organizationId).getProperty(key);
+    }
+
+
+
+
     @Override
     public OrganizationConfig getOrganizationConfigForApplication( UUID applicationInfoId
) throws Exception {
 
@@ -3151,21 +3174,22 @@ public class ManagementServiceImpl implements ManagementService {
         Entity entity = r.getEntity();
 
         if ( entity != null ) {
-            Map properties = em.getDictionaryAsMap(entity, ORGANIZATION_CONFIG_DICTIONARY);
-            return new OrganizationConfig(entity.getUuid(), entity.getName(), properties);
+            Map entityProperties = em.getDictionaryAsMap(entity, ORGANIZATION_CONFIG_DICTIONARY);
+            return new OrganizationConfig(orgConfigProperties, entity.getUuid(), entity.getName(),
entityProperties);
         }
 
-        return null;
+        // return the defaults
+        return new OrganizationConfig(orgConfigProperties);
     }
 
 
     @Override
     public void updateOrganizationConfig( OrganizationConfig organizationConfig ) throws
Exception {
-        Map<String, Object> properties = organizationConfig.getProperties();
-        if ( properties != null ) {
+        Map<String, Object> orgConfigProperties = organizationConfig.getOrgConfigProperties();
+        if ( orgConfigProperties != null ) {
             EntityRef organizationEntity = new SimpleEntityRef( Group.ENTITY_TYPE, organizationConfig.getUuid()
);
             EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-            for ( Map.Entry<String, Object> entry : properties.entrySet() ) {
+            for ( Map.Entry<String, Object> entry : orgConfigProperties.entrySet()
) {
                 if ( "".equals( entry.getValue() ) ) {
                     em.removeFromDictionary( organizationEntity, ORGANIZATION_CONFIG_DICTIONARY,
entry.getKey() );
                 } else {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/faa3450d/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
new file mode 100644
index 0000000..bae0a17
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/OrganizationConfigPropsImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.management.cassandra;
+
+
+import org.apache.usergrid.management.AccountCreationProps;
+import org.apache.usergrid.management.OrganizationConfigProps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import static java.lang.Boolean.parseBoolean;
+import static java.lang.Integer.parseInt;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.usergrid.utils.ListUtils.anyNull;
+
+
+public class OrganizationConfigPropsImpl implements OrganizationConfigProps {
+    private static final Logger logger = LoggerFactory.getLogger( OrganizationConfigPropsImpl.class
);
+
+    protected final Properties properties;
+
+    public OrganizationConfigPropsImpl(Properties properties) {
+        this.properties = properties;
+    }
+
+
+    public String getProperty( String name ) {
+        String propertyValue = properties.getProperty( name );
+        if ( isBlank( propertyValue ) ) {
+            logger.warn( "Missing value for " + name );
+            propertyValue = null;
+        }
+        return propertyValue;
+    }
+
+
+    public String getProperty( String name, String defaultValue ) {
+        return properties.getProperty( name, defaultValue );
+    }
+
+
+    public boolean isProperty( String name ) {
+        return parseBoolean( getProperty( name ) );
+    }
+
+    public int intProperty( String name, String defaultValue ) {
+        return parseInt( getProperty( name, defaultValue ) );
+    }
+
+    public void setProperty( String name, String value ) {
+        properties.setProperty( name, value );
+    }
+
+}


Mime
View raw message