usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [1/6] usergrid git commit: Changed how the put by name method works so that it updates the entity in the exact same way a PUT by uuid would function. Added a test verifying the change restores access to an entity without any entity_properties.
Date Thu, 04 Feb 2016 00:27:07 GMT
Repository: usergrid
Updated Branches:
  refs/heads/1.x 0d543a515 -> f0b108fc0


Changed how the put by name method works so that it updates the entity in the exact same way
a PUT by uuid would function.
Added a test verifying the change restores access to an entity without any entity_properties.


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

Branch: refs/heads/1.x
Commit: dd5b32488d649a057abb7327d6899926dc3fc179
Parents: a5045b8
Author: George Reyes <grey@apache.org>
Authored: Thu Jan 28 11:24:22 2016 -0800
Committer: George Reyes <grey@apache.org>
Committed: Thu Jan 28 11:24:22 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/usergrid/rest/ITSetup.java  |  9 ++-
 .../users/CollectionsResourceIT.java            | 60 ++++++++++++++++++++
 .../services/AbstractCollectionService.java     | 25 +-------
 3 files changed, 69 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd5b3248/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
index f3b1214..91ec062 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
@@ -29,6 +29,7 @@ import org.apache.usergrid.cassandra.CassandraResource;
 import org.apache.usergrid.management.ApplicationCreator;
 import org.apache.usergrid.management.ManagementService;
 import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.security.providers.SignInProviderFactory;
 import org.apache.usergrid.security.tokens.TokenService;
 import org.apache.usergrid.services.ServiceManagerFactory;
@@ -50,6 +51,7 @@ public class ITSetup extends ExternalResource {
     private TokenService tokenService;
     private SignInProviderFactory providerFactory;
     private Properties properties;
+    private CassandraService cassSvc;
 
 
     public ITSetup( CassandraResource cassandraResource ) {
@@ -73,7 +75,6 @@ public class ITSetup extends ExternalResource {
     protected void before() throws Throwable {
         synchronized ( cassandraResource ) {
             super.before();
-
             managementService = cassandraResource.getBean( ManagementService.class );
 
             if ( !setupCalled ) {
@@ -87,6 +88,7 @@ public class ITSetup extends ExternalResource {
             providerFactory = cassandraResource.getBean( SignInProviderFactory.class );
             properties = cassandraResource.getBean( "properties", Properties.class );
             smf = cassandraResource.getBean( ServiceManagerFactory.class );
+            cassSvc = cassandraResource.getBean( CassandraService.class );
 
             tomcatResource.before();
 
@@ -152,6 +154,11 @@ public class ITSetup extends ExternalResource {
         return tokenService;
     }
 
+    public CassandraService getCassSvc(){
+        protect();
+        return cassSvc;
+    }
+
 
     public Properties getProps() {
         protect();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd5b3248/stack/rest/src/test/java/org/apache/usergrid/rest/applications/users/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/users/CollectionsResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/users/CollectionsResourceIT.java
index d18cb62..a88334d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/users/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/users/CollectionsResourceIT.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.applications.users;
 
 
+import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -29,11 +30,22 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.cassandra.Concurrent;
+import org.apache.usergrid.persistence.hector.CountingMutator;
 import org.apache.usergrid.rest.AbstractRestIT;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.sun.jersey.api.client.UniformInterfaceException;
 
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.mutation.MutationResult;
+import me.prettyprint.hector.api.mutation.Mutator;
+
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_PROPERTIES;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addDeleteToMutator;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
+import static org.apache.usergrid.persistence.cassandra.Serializers.be;
+import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
+import static org.apache.usergrid.utils.UUIDUtils.newTimeUUID;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -197,4 +209,52 @@ public class CollectionsResourceIT extends AbstractRestIT {
             Assert.assertEquals( "Should not be more than one name property", -1, secondFred
);
         }
     }
+
+    @Test
+    public void testUpdatingRandomEntity() throws Exception {
+
+        UUID entityId = null;
+
+            // create an "app_user" object with name fred
+            Map<String, String> payload = hashMap( "type", "app_user" ).map( "name",
"fred" );
+
+            JsonNode node = resource().path( "/test-organization/test-app/app_users" )
+                                      .queryParam( "access_token", access_token ).accept(
MediaType.APPLICATION_JSON )
+                                      .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
+
+            String uuidString = node.get( "entities" ).get( 0 ).get( "uuid" ).asText();
+            entityId = UUIDUtils.tryGetUUID( uuidString );
+        UUID applicationId = UUIDUtils.tryGetUUID( node.get( "application").asText());
+
+
+        UUID timestampUuid = newTimeUUID();
+        long timestamp = getTimestampInMicros( timestampUuid );
+
+        //Delete only the entity properties out of the filesystem.
+        Keyspace ko = setup.getCassSvc().getApplicationKeyspace( applicationId );
+
+        Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
+        addDeleteToMutator( m, ENTITY_PROPERTIES, key( entityId ), timestamp);
+
+        m.execute();
+
+        payload = hashMap( "name", "ted" );
+
+
+        // check REST API response for duplicate name property
+            // have to look at raw response data, Jackson will remove dups
+            node = resource().path( "/test-organization/test-app/app_users/fred") //+entityId
)
+                                 .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON
)
+                                 .type( MediaType.APPLICATION_JSON_TYPE ).put(JsonNode.class,
payload );
+
+            assertNotNull(node);
+
+
+        node = resource().path( "/test-organization/test-app/app_users/fred")//+entityId
)
+                         .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON
)
+                         .type( MediaType.APPLICATION_JSON_TYPE ).get(JsonNode.class );
+
+        assertNotNull(node);
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd5b3248/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index 10c208f..b45b528 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -288,31 +288,8 @@ public class AbstractCollectionService extends AbstractService {
     @Override
     public ServiceResults putItemByName( ServiceContext context, String name ) throws Exception
{
 
-        if ( context.moreParameters() ) {
-            return getItemByName( context, name );
-        }
-
         EntityRef ref = em.getAlias( getEntityType(), name );
-        Entity entity;
-        if ( ref == null ) {
-            // null entity ref means we tried to put a non-existing entity
-            // before we create a new entity for it, we should check for permission
-            checkPermissionsForCollection(context);
-            Map<String, Object> properties = context.getPayload().getProperties();
-            if ( !properties.containsKey( "name" ) || !( ( String ) properties.get( "name"
) ).trim().equalsIgnoreCase(
-                    name ) ) {
-                properties.put( "name", name );
-            }
-            entity = em.create( getEntityType(), properties );
-        }
-        else {
-            entity = em.get( ref );
-            entity = importEntity( context, entity );
-            checkPermissionsForEntity( context, entity );
-            updateEntity( context, entity );
-        }
-
-        return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntity( entity
), null, null );
+        return putItemById(context ,ref.getUuid() );
     }
 
 


Mime
View raw message