You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/02/04 01:27:07 UTC

[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.

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 <gr...@apache.org>
Authored: Thu Jan 28 11:24:22 2016 -0800
Committer: George Reyes <gr...@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() );
     }
 
 


[4/6] usergrid git commit: Readded previous put by Name logic for the case that the entity ref is null. Also fixed some of the existing functionality which was included in the null check.

Posted by mr...@apache.org.
Readded previous put by Name logic for the case that the entity ref is null. Also fixed some of the existing functionality which was included in the null check.


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

Branch: refs/heads/1.x
Commit: b09a5e4d4d4638a1537c67fafaa4bdc5fd667c74
Parents: 234472c
Author: George Reyes <gr...@apache.org>
Authored: Fri Jan 29 16:45:10 2016 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Fri Jan 29 16:45:10 2016 -0800

----------------------------------------------------------------------
 .../usergrid/services/AbstractCollectionService.java  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b09a5e4d/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 72625be..2ad51f2 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
@@ -291,6 +291,20 @@ public class AbstractCollectionService extends AbstractService {
     public ServiceResults putItemByName( ServiceContext context, String name ) throws Exception {
 
         EntityRef ref = em.getAlias( getEntityType(), name );
+        if(ref == null){
+            logger.error("The following name wasn't found in entity_unique column family. {}",name);
+
+            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 entity = em.create( getEntityType(), properties );
+            return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntity( entity ), null, null );
+        }
+
         return putItemById( context, ref.getUuid() );
     }
 


[3/6] usergrid git commit: Removed extra unused imports.

Posted by mr...@apache.org.
Removed extra unused imports.


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

Branch: refs/heads/1.x
Commit: 234472cfa69ecccb20a952657675b4c3af18098c
Parents: ac0652f
Author: George Reyes <gr...@apache.org>
Authored: Fri Jan 29 15:47:59 2016 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Fri Jan 29 15:47:59 2016 -0800

----------------------------------------------------------------------
 .../applications/users/CollectionsResourceIT.java     |  8 ++++----
 .../usergrid/services/AbstractCollectionService.java  | 14 +-------------
 2 files changed, 5 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/234472cf/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 82d6d7f..4b4b13a 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
@@ -29,6 +29,7 @@ import org.junit.Assert;
 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;
@@ -37,21 +38,20 @@ 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.hamcrest.CoreMatchers.*;
-
 
 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.MapUtils.hashMap;
 import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
 import static org.apache.usergrid.utils.UUIDUtils.newTimeUUID;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.not;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.junit.Assert.assertThat;
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/234472cf/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 38295c8..72625be 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
@@ -17,7 +17,6 @@
 package org.apache.usergrid.services;
 
 
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -27,6 +26,7 @@ import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.Query;
@@ -37,19 +37,7 @@ import org.apache.usergrid.persistence.exceptions.UnexpectedEntityTypeException;
 import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.ForbiddenServiceOperationException;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
-import org.apache.usergrid.utils.MapUtils;
-import org.apache.usergrid.utils.UUIDUtils;
-
-import com.fasterxml.uuid.impl.UUIDUtil;
-
-import me.prettyprint.cassandra.service.RangeSlicesIterator;
-import me.prettyprint.hector.api.beans.ColumnSlice;
-import me.prettyprint.hector.api.factory.HFactory;
-import me.prettyprint.hector.api.query.ColumnQuery;
-import me.prettyprint.hector.api.query.RangeSlicesQuery;
 
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_UNIQUE;
-import static org.apache.usergrid.persistence.cassandra.Serializers.be;
 import static org.apache.usergrid.utils.ClassUtils.cast;
 
 


[6/6] usergrid git commit: Merge commit 'refs/pull/478/head' of github.com:apache/usergrid into 1.x

Posted by mr...@apache.org.
Merge commit 'refs/pull/478/head' of github.com:apache/usergrid into 1.x


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

Branch: refs/heads/1.x
Commit: f0b108fc09c832092e30a9ba37706f73b37d945e
Parents: 0d543a5 341b25b
Author: Michael Russo <mi...@gmail.com>
Authored: Wed Feb 3 16:26:57 2016 -0800
Committer: Michael Russo <mi...@gmail.com>
Committed: Wed Feb 3 16:26:57 2016 -0800

----------------------------------------------------------------------
 .../cassandra/EntityManagerImpl.java            |   2 +-
 .../java/org/apache/usergrid/rest/ITSetup.java  |   9 +-
 .../users/CollectionsResourceIT.java            | 154 ++++++++++++++++++-
 .../services/AbstractCollectionService.java     |  51 +++---
 4 files changed, 189 insertions(+), 27 deletions(-)
----------------------------------------------------------------------



[2/6] usergrid git commit: Added functionality to delete by name and added a test to verify.

Posted by mr...@apache.org.
Added functionality to delete by name and added a test to verify.


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

Branch: refs/heads/1.x
Commit: ac0652f3493725fc5ce863db5cff922b17df22b8
Parents: dd5b324
Author: George Reyes <gr...@apache.org>
Authored: Fri Jan 29 15:45:53 2016 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Fri Jan 29 15:45:53 2016 -0800

----------------------------------------------------------------------
 .../users/CollectionsResourceIT.java            | 90 +++++++++++++++-----
 .../services/AbstractCollectionService.java     | 42 +++++++--
 2 files changed, 104 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/ac0652f3/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 a88334d..82d6d7f 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
@@ -39,6 +39,8 @@ 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.hamcrest.CoreMatchers.*;
+
 
 import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_PROPERTIES;
 import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addDeleteToMutator;
@@ -50,6 +52,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.assertThat;
 
 
 /**
@@ -210,21 +213,23 @@ public class CollectionsResourceIT extends AbstractRestIT {
         }
     }
 
+
     @Test
-    public void testUpdatingRandomEntity() throws Exception {
+    public void testUpdatingMissingEntityByName() throws Exception {
 
         UUID entityId = null;
 
-            // create an "app_user" object with name fred
-            Map<String, String> payload = hashMap( "type", "app_user" ).map( "name", "fred" );
+        // create an "app_user" object with name fred
+        Map<String, String> payload = hashMap( "type", "app_user" ).map( "name", "mokey" );
 
-            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 );
+        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());
+        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();
@@ -234,27 +239,74 @@ public class CollectionsResourceIT extends AbstractRestIT {
         Keyspace ko = setup.getCassSvc().getApplicationKeyspace( applicationId );
 
         Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
-        addDeleteToMutator( m, ENTITY_PROPERTIES, key( entityId ), timestamp);
+        addDeleteToMutator( m, ENTITY_PROPERTIES, key( entityId ), timestamp );
 
         m.execute();
 
-        payload = hashMap( "name", "ted" );
+        payload = hashMap( "name", "mokey" );
 
 
         // 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 );
+        // have to look at raw response data, Jackson will remove dups
+        node = resource().path( "/test-organization/test-app/app_users/mokey" ) //+entityId )
+                         .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                         .type( MediaType.APPLICATION_JSON_TYPE ).put( JsonNode.class, payload );
 
-            assertNotNull(node);
+        assertNotNull( node );
 
 
-        node = resource().path( "/test-organization/test-app/app_users/fred")//+entityId )
+        node = resource().path( "/test-organization/test-app/app_users/mokey" )//+entityId )
                          .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
-                         .type( MediaType.APPLICATION_JSON_TYPE ).get(JsonNode.class );
+                         .type( MediaType.APPLICATION_JSON_TYPE ).get( JsonNode.class );
+
+        assertNotNull( node );
+    }
+
+
+    @Test
+    public void testDeleteByNameOfMissingEntityAndRecreation() throws Exception {
+
+        UUID entityId = null;
+
+        // create an "app_user" object with name fred
+        Map<String, String> payload = hashMap( "type", "app_user" ).map( "name", "rock" );
+
+        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();
+
+        //delete the incomplete entity
+        node = resource().path( "/test-organization/test-app/app_users/rock" )
+                         .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                         .type( MediaType.APPLICATION_JSON_TYPE ).delete( JsonNode.class );
+
+        assertNotNull( node );
 
-        assertNotNull(node);
+        //try recreating an entity with the exact same payload and see if it can be recreated with a different uuid.
+        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 );
 
+        assertNotNull( node );
+        uuidString = node.get( "entities" ).get( 0 ).get( "uuid" ).asText();
+        assertThat( entityId, not( UUIDUtils.tryGetUUID( uuidString ) ) );
+        assertThat( "rock", equalTo( node.get( "entities" ).get( 0 ).get( "name" ).asText() ) );
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/ac0652f3/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 b45b528..38295c8 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
@@ -17,7 +17,9 @@
 package org.apache.usergrid.services;
 
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -35,7 +37,19 @@ import org.apache.usergrid.persistence.exceptions.UnexpectedEntityTypeException;
 import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.ForbiddenServiceOperationException;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
+import org.apache.usergrid.utils.MapUtils;
+import org.apache.usergrid.utils.UUIDUtils;
 
+import com.fasterxml.uuid.impl.UUIDUtil;
+
+import me.prettyprint.cassandra.service.RangeSlicesIterator;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.ColumnQuery;
+import me.prettyprint.hector.api.query.RangeSlicesQuery;
+
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_UNIQUE;
+import static org.apache.usergrid.persistence.cassandra.Serializers.be;
 import static org.apache.usergrid.utils.ClassUtils.cast;
 
 
@@ -289,7 +303,7 @@ public class AbstractCollectionService extends AbstractService {
     public ServiceResults putItemByName( ServiceContext context, String name ) throws Exception {
 
         EntityRef ref = em.getAlias( getEntityType(), name );
-        return putItemById(context ,ref.getUuid() );
+        return putItemById( context, ref.getUuid() );
     }
 
 
@@ -447,6 +461,9 @@ public class AbstractCollectionService extends AbstractService {
 
         Entity item = em.get( id );
         if ( item == null ) {
+            logger.error(
+                    "Found entity reference but not entity properties when trying to delete uuid: {}.Please delete by"
+                            + " Name.", id );
             throw new ServiceResourceNotFoundException( context );
         }
 
@@ -454,8 +471,6 @@ public class AbstractCollectionService extends AbstractService {
 
         item = importEntity( context, item );
 
-        prepareToDelete( context, item );
-
         em.removeFromCollection( context.getOwner(), context.getCollectionName(), item );
 
         return new ServiceResults( this, context, Type.COLLECTION, Results.fromEntity( item ), null, null );
@@ -468,20 +483,29 @@ public class AbstractCollectionService extends AbstractService {
         if ( context.moreParameters() ) {
             return getItemByName( context, name );
         }
-
         EntityRef ref = em.getAlias( getEntityType(), name );
+
         if ( ref == null ) {
             throw new ServiceResourceNotFoundException( context );
         }
+
+        checkPermissionsForEntity( context, ref );
+
         Entity entity = em.get( ref );
         if ( entity == null ) {
-            throw new ServiceResourceNotFoundException( context );
-        }
-        entity = importEntity( context, entity );
+            logger.error(
+                    "Found entity reference but not entity properties when trying to delete. Cleaning up uuid: {}",
+                    ref.getUuid() );
+            String entityType = getEntityType();
+            Map<String, Object> properties = new HashMap<String, Object>();
+            properties.put( "name", name );
+            em.create( ref.getUuid(), entityType, properties );
 
-        checkPermissionsForEntity( context, entity );
+            em.removeFromCollection( context.getOwner(), context.getCollectionName(), ref );
+            return new ServiceResults( this, context, Type.COLLECTION, Results.fromRef( ref ), null, null );
+        }
 
-        prepareToDelete( context, entity );
+        entity = importEntity( context, entity );
 
         em.removeFromCollection( context.getOwner(), context.getCollectionName(), entity );
 


[5/6] usergrid git commit: Added a test verifying that older properties are patched instead of completely removed. And that the entity isn't entirely recreated with the new PUT logic. Also removed the redundant properties delete from the entityManager wi

Posted by mr...@apache.org.
Added a test verifying that older properties are patched instead of completely removed. And that the entity isn't entirely recreated with the new PUT logic.
Also removed the redundant properties delete from the entityManager with no change to functionality.


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

Branch: refs/heads/1.x
Commit: 341b25bf10b4b04cc148ebaab6249eb10090a18a
Parents: b09a5e4
Author: George Reyes <gr...@apache.org>
Authored: Wed Feb 3 16:17:59 2016 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Wed Feb 3 16:17:59 2016 -0800

----------------------------------------------------------------------
 .../cassandra/EntityManagerImpl.java            |  2 +-
 .../users/CollectionsResourceIT.java            | 40 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/341b25bf/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index c6ba7eb..4581850 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -1615,7 +1615,7 @@ public class EntityManagerImpl implements EntityManager {
             }
         }
 
-        addDeleteToMutator( m, ENTITY_PROPERTIES, key( entityId ), timestamp );
+        //addDeleteToMutator( m, ENTITY_PROPERTIES, key( entityId ), timestamp );
 
         batchExecute( m, CassandraService.RETRY_COUNT );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/341b25bf/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 4b4b13a..1e64c5b 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
@@ -262,6 +262,46 @@ public class CollectionsResourceIT extends AbstractRestIT {
         assertNotNull( node );
     }
 
+    @Test
+    public void testAddingAndRemovingProperties() throws Exception {
+
+        UUID entityId = null;
+        String entityName = "tonythetiger";
+        // create an "app_user" object with name fred
+        Map<String, String> payload = hashMap( "type", "app_user" ).map( "name", entityName ).map("testProperty","randomValue");
+
+        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() );
+
+        payload = hashMap( "testProperty", null );
+        payload.put( "newTestProperty","newRandomValue" );
+
+
+        // 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/"+entityName ) //+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/"+entityName )//+entityId )
+                         .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON )
+                         .type( MediaType.APPLICATION_JSON_TYPE ).get( JsonNode.class );
+
+        assertNotNull( node );
+        assertEquals( entityName,node.get( "entities" ).get( 0 ).get( "name" ).asText() );
+        assertNull( node.get( "entities" ).get( 0 ).get( "testProperty" ) );
+        assertEquals( "newRandomValue",node.get( "entities" ).get( 0 ).get( "newTestProperty" ).asText() );
+    }
+
 
     @Test
     public void testDeleteByNameOfMissingEntityAndRecreation() throws Exception {