usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [41/50] incubator-usergrid git commit: changing return types to optional
Date Mon, 13 Apr 2015 17:46:06 GMT
changing return types to optional


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

Branch: refs/heads/USERGRID-536
Commit: 47e74cd63b1e85b73eac0eef5e1a5b698178a777
Parents: 6019076
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Apr 8 17:02:52 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Apr 8 17:02:52 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/ApplicationIdCache.java         |  3 +--
 .../corepersistence/ApplicationIdCacheImpl.java     | 14 ++++----------
 .../corepersistence/CpEntityManagerFactory.java     | 10 ++++++----
 .../usergrid/persistence/EntityManagerFactory.java  |  3 ++-
 .../cassandra/EntityManagerFactoryImpl.java         |  7 ++++---
 .../cassandra/EntityManagerFactoryImplIT.java       |  8 ++++----
 .../org/apache/usergrid/mongo/BasicMongoTest.java   |  8 ++++----
 .../rest/organizations/OrganizationResource.java    | 11 +++++++----
 .../usergrid/rest/test/RefreshIndexResource.java    | 16 ++--------------
 .../management/cassandra/ManagementServiceImpl.java |  9 +++++----
 .../migration/AppInfoMigrationPluginTest.java       | 12 +++++++-----
 11 files changed, 46 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
index 4aa1113..a7d1c4e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
@@ -22,7 +22,6 @@ package org.apache.usergrid.corepersistence;
 
 import java.util.UUID;
 
-import org.apache.usergrid.persistence.Entity;
 
 import com.google.common.base.Optional;
 
@@ -36,7 +35,7 @@ public interface ApplicationIdCache {
     /**
      * Evict the application by name
      */
-    public UUID getApplicationId(final String applicationName);
+    public Optional<UUID> getApplicationId(final String applicationName);
 
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 96066ae..8247ead 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -23,28 +23,22 @@ package org.apache.usergrid.corepersistence;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
-import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import rx.Observable;
 
-import java.util.Optional;
+import com.google.common.base.Optional;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
-import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
 
 
 /**
@@ -73,20 +67,20 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
             .build(new CacheLoader<String, Optional<UUID>>() {
                 @Override
                 public Optional<UUID> load(final String key) throws Exception {
-                    return Optional.of(fetchApplicationId(key));
+                    return Optional.fromNullable(fetchApplicationId(key));
                 }
             });
     }
 
     @Override
-    public UUID getApplicationId( final String applicationName ) {
+    public  Optional<UUID> getApplicationId( final String applicationName ) {
         try {
             Optional<UUID> optionalUuid = appCache.get( applicationName.toLowerCase()
);
             if(!optionalUuid.isPresent()){
                 appCache.invalidate(applicationName.toLowerCase());
             }
             logger.debug("Returning for key {} value {}", applicationName, optionalUuid );
-            return optionalUuid.get();
+            return optionalUuid;
         } catch (Exception e) {
             logger.debug("Returning for key {} value null", applicationName );
             return null;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 642d555..be47974 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -15,6 +15,8 @@
  */
 package org.apache.usergrid.corepersistence;
 
+import com.google.common.base.*;
+import com.google.common.base.Optional;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -205,9 +207,9 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         String appName = buildAppName( orgName, name );
 
 
-        final UUID appId = applicationIdCache.getApplicationId( appName );
+        final Optional<UUID> appId = applicationIdCache.getApplicationId( appName );
 
-        if ( appId != null ) {
+        if ( appId.isPresent()) {
             throw new ApplicationAlreadyExistsException( name );
         }
 
@@ -242,7 +244,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
         // check for pre-existing application
 
-        if ( lookupApplication( appName ) != null ) {
+        if ( lookupApplication( appName ).isPresent()) {
             throw new ApplicationAlreadyExistsException( appName );
         }
 
@@ -392,7 +394,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
-    public UUID lookupApplication( String orgAppName ) throws Exception {
+    public Optional<UUID> lookupApplication( String orgAppName ) throws Exception {
         return applicationIdCache.getApplicationId(orgAppName);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 445cef4..454c3ce 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.persistence;
 import java.util.Map;
 import java.util.UUID;
 
+import com.google.common.base.Optional;
 import org.apache.usergrid.persistence.core.util.Health;
 import rx.Observable;
 
@@ -124,7 +125,7 @@ public interface EntityManagerFactory {
      *
      * @throws Exception the exception
      */
-    UUID lookupApplication( String name ) throws Exception;
+    Optional<UUID> lookupApplication( String name ) throws Exception;
 
     /**
      * Returns all the applications in the system.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index 91d7524..fc33077 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
 
+import com.google.common.base.Optional;
 import org.apache.usergrid.exception.NotImplementedException;
 import org.apache.usergrid.persistence.Entity;
 import org.slf4j.Logger;
@@ -237,7 +238,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory,
Applicati
 
         String appName = buildAppName( organizationName, name );
         // check for pre-existing
-        if ( lookupApplication( appName ) != null ) {
+        if ( lookupApplication( appName ).isPresent()) {
             throw new ApplicationAlreadyExistsException( appName );
         }
         if ( properties == null ) {
@@ -286,12 +287,12 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory,
Applicati
 
 
     @Override
-    public UUID lookupApplication( String name ) throws Exception {
+    public Optional<UUID> lookupApplication( String name ) throws Exception {
         name = name.toLowerCase();
         HColumn<String, ByteBuffer> column =
                 cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name,
PROPERTY_UUID );
         if ( column != null ) {
-            return uuid( column.getValue() );
+            return Optional.fromNullable( uuid( column.getValue() ));
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 36d82be..1a0a13b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -129,7 +129,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         Entity film2 = em.create( "film", properties2 );
 
         for ( int j=0; j<maxRetries; j++ ) {
-            if ( setup.getEmf().lookupApplication( orgName + "/" + appName ) != null ) {
+            if ( setup.getEmf().lookupApplication( orgName + "/" + appName ).isPresent())
{
                 break;
             }
             Thread.sleep( 500 );
@@ -165,7 +165,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         assertTrue("Deleted app must be found in in deleted apps collection", found);
 
         // attempt to get entities in application's collections in various ways should all
fail
-        found =  setup.getEmf().lookupApplication( orgName + "/" + appName ) != null ;
+        found =  setup.getEmf().lookupApplication( orgName + "/" + appName ).isPresent()
;
 
         assertFalse("Lookup of deleted app must fail", found);
 
@@ -193,7 +193,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         assertTrue("Restored app not found in apps collection", found);
 
         // TODO: this assertion should work!
-        assertNotNull(setup.getEmf().lookupApplication( orgName + "/" + appName ));
+        assertTrue(setup.getEmf().lookupApplication( orgName + "/" + appName ).isPresent());
     }
 
 
@@ -289,7 +289,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         UUID appId = setup.createApplication(orgName, appName);
 
-        UUID lookedUpId = setup.getEmf().lookupApplication( orgAppName );
+        UUID lookedUpId = setup.getEmf().lookupApplication( orgAppName ).get();
 
         Assert.assertEquals(appId, lookedUpId);
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/mongo-emulator/src/test/java/org/apache/usergrid/mongo/BasicMongoTest.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/test/java/org/apache/usergrid/mongo/BasicMongoTest.java
b/stack/mongo-emulator/src/test/java/org/apache/usergrid/mongo/BasicMongoTest.java
index bcd4d2b..17e4449 100644
--- a/stack/mongo-emulator/src/test/java/org/apache/usergrid/mongo/BasicMongoTest.java
+++ b/stack/mongo-emulator/src/test/java/org/apache/usergrid/mongo/BasicMongoTest.java
@@ -110,7 +110,7 @@ public class BasicMongoTest extends AbstractMongoTest {
 
         // check we can find it when using the native entity manager
 
-        UUID appId = emf.lookupApplication( "test-organization/test-app" );
+        UUID appId = emf.lookupApplication( "test-organization/test-app" ).get();
         EntityManager em = emf.getEntityManager( appId );
 
         Entity entity = em.get( new SimpleEntityRef( (String)returnedObject.get("type"),
id ));
@@ -228,7 +228,7 @@ public class BasicMongoTest extends AbstractMongoTest {
 
         Thread.sleep( 5000 );
 
-        UUID appId = emf.lookupApplication( "test-organization/test-app" );
+        UUID appId = emf.lookupApplication( "test-organization/test-app" ).get();
         EntityManager em = emf.getEntityManager( appId );
 
         Entity entity = em.get( new SimpleEntityRef( (String)returnedObject.get("type"),
id ) );
@@ -290,7 +290,7 @@ public class BasicMongoTest extends AbstractMongoTest {
 
         // check it has been deleted
 
-        UUID appId = emf.lookupApplication( "test-organization/test-app" );
+        UUID appId = emf.lookupApplication( "test-organization/test-app" ).get();
         EntityManager em = emf.getEntityManager( appId );
 
         Entity entity = em.get( new SimpleEntityRef( (String)returnedObject.get("type"),
id ) );
@@ -345,7 +345,7 @@ public class BasicMongoTest extends AbstractMongoTest {
         assertFalse( cursor.hasNext() );
 
         // check it has been deleted
-        UUID appId = emf.lookupApplication( "test-organization/test-app" );
+        UUID appId = emf.lookupApplication( "test-organization/test-app" ).get();
         EntityManager em = emf.getEntityManager( appId );
 
         Results results =

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
index ff26ba2..5e1d1f7 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.organizations;
 
 
+import com.google.common.base.Optional;
 import com.google.common.collect.BiMap;
 import com.sun.jersey.api.json.JSONWithPadding;
 import java.util.UUID;
@@ -142,19 +143,21 @@ public class OrganizationResource extends AbstractContextResource {
         }
 
         String orgAppName = PathingUtils.assembleAppName( organizationName, applicationName
);
-        UUID applicationId = emf.lookupApplication( orgAppName );
+        Optional<UUID> optionalAppId = emf.lookupApplication( orgAppName );
 
-        if ( applicationId == null ) {
+        if ( !optionalAppId.isPresent()) {
 
             // TODO: fix this hacky work-around for apparent Jersey issue
-            applicationId = UUIDUtils.tryExtractUUID( applicationName );
+            UUID applicationId = UUIDUtils.tryExtractUUID( applicationName );
 
             if ( applicationId == null ) {
                 throw new OrganizationApplicationNotFoundException( orgAppName, uriInfo,
properties );
+            }else{
+                optionalAppId = Optional.fromNullable(applicationId);
             }
         }
 
-        return appResourceFor( applicationId );
+        return appResourceFor( optionalAppId.get() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
index 1717011..19708e6 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
@@ -27,6 +27,8 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+
+import com.google.common.base.Optional;
 import org.apache.usergrid.persistence.EntityManager;
 
 import org.slf4j.Logger;
@@ -66,20 +68,6 @@ public class RefreshIndexResource extends AbstractContextResource {
             // refresh the system apps or app lookup below may fail
             getEntityIndex().refresh();
 
-            UUID appId;
-            if ( orgName != null && appName != null ) {
-                appId = emf.lookupApplication( orgName + "/" + appName );
-            } else {
-                appId = UUID.fromString(appIdString);
-            }
-
-            if ( appId != null ) {
-                // found an app, then refresh it!
-                EntityManager em = emf.getEntityManager( appId );
-                getEntityIndex().refresh();
-
-            }
-
         } catch (Exception e) {
             logger.error("Error in refresh", e);
             return Response.serverError().build();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/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 1049c85..d93eb5f 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
@@ -28,6 +28,7 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.UUID;
 
+import com.google.common.base.Optional;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.exception.ConflictException;
 import org.apache.usergrid.management.exceptions.*;
@@ -1662,7 +1663,7 @@ public class ManagementServiceImpl implements ManagementService {
             throw new EntityNotFoundException("Deleted application ID " + applicationId +
" not found");
         }
 
-        if ( emf.lookupApplication( app.getName() ) != null ) {
+        if ( emf.lookupApplication( app.getName() ).isPresent()) {
             throw new ConflictException("Cannot restore application, one with that name already
exists.");
         }
 
@@ -1821,11 +1822,11 @@ public class ManagementServiceImpl implements ManagementService {
         if ( applicationName == null ) {
             return null;
         }
-        UUID applicationId = emf.lookupApplication( applicationName );
-        if ( applicationId == null ) {
+        Optional<UUID> applicationId = emf.lookupApplication(applicationName);
+        if ( !applicationId.isPresent() ) {
             return null;
         }
-        return new ApplicationInfo( applicationId, applicationName.toLowerCase() );
+        return new ApplicationInfo( applicationId.get(), applicationName.toLowerCase() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/47e74cd6/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
index 5c36876..be999c8 100644
--- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.usergrid.corepersistence.migration;
 
+import com.google.common.base.Optional;
 import org.apache.usergrid.NewOrgAppAdminRule;
 import org.apache.usergrid.ServiceITSetup;
 import org.apache.usergrid.ServiceITSetupImpl;
@@ -187,10 +188,10 @@ public class AppInfoMigrationPluginTest {
         for ( Entity applicationInfo : deletedApps ) {
 
             String appName = applicationInfo.getName();
-            UUID uuid = setup.getEmf().lookupApplication( appName );
+            boolean isPresent = setup.getEmf().lookupApplication( appName ).isPresent();
 
             // missing application_info does not completely break applications, but we...
-            assertNull("Should not be able to lookup deleted application by name" + appName,
uuid);
+            assertFalse("Should not be able to lookup deleted application by name" + appName,
isPresent);
         }
     }
 
@@ -202,10 +203,11 @@ public class AppInfoMigrationPluginTest {
 
             String appName = orgName + "/application" + i;
 
-            UUID uuid = setup.getEmf().lookupApplication( appName );
-            assertNotNull("Should be able to get application", uuid );
+            Optional<UUID> uuid = setup.getEmf().lookupApplication(appName);
 
-            EntityManager em = setup.getEmf().getEntityManager( uuid );
+            assertTrue ("Should be able to get application", uuid.isPresent() );
+
+            EntityManager em = setup.getEmf().getEntityManager( uuid.get() );
 
             Application app = em.getApplication();
             assertEquals( appName, app.getName() );


Mime
View raw message