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/04/15 01:01:19 UTC

[1/5] usergrid git commit: Disable indexing per Entity type for USERGRID-1278. https://issues.apache.org/jira/browse/USERGRID-1278

Repository: usergrid
Updated Branches:
  refs/heads/release-2.1.1 2e576f373 -> 8dce5ed8c


Disable indexing per Entity type for USERGRID-1278. https://issues.apache.org/jira/browse/USERGRID-1278


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

Branch: refs/heads/release-2.1.1
Commit: fbced588bdf7de5f7192d20e2da6a8740df0218a
Parents: 2e576f3
Author: Dave Johnson <sn...@apache.org>
Authored: Thu Apr 14 12:26:06 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Thu Apr 14 12:26:06 2016 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 86 ++++++++++++++------
 .../collection/CollectionsResourceIT.java       | 56 +++++++++++--
 2 files changed, 112 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/fbced588/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 891c1fe..b2330f3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -601,14 +601,36 @@ public class CpEntityManager implements EntityManager {
             handleWriteUniqueVerifyException( entity, wuve );
         }
 
-        // queue an event to update the new entity
-        indexService.queueEntityIndexUpdate( applicationScope, cpEntity, 0 );
+        if ( !skipIndexingForType( cpEntity.getId().getType() ) ) {
 
+            // queue an event to update the new entity
+            indexService.queueEntityIndexUpdate( applicationScope, cpEntity, 0 );
 
-        // queue up an event to clean-up older versions than this one from the index
-        if(entityManagerFig.getDeindexOnUpdate()) {
-            indexService.queueDeIndexOldVersion(applicationScope, entityId);
+            // queue up an event to clean-up older versions than this one from the index
+            if (entityManagerFig.getDeindexOnUpdate()) {
+                indexService.queueDeIndexOldVersion( applicationScope, entityId );
+            }
+        }
+    }
+
+    private boolean skipIndexingForType( String type ) {
+
+        boolean skipIndexing = false;
+
+        MapManager mm = getMapManagerForTypes();
+        IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
+        String collectionName = Schema.defaultCollectionName( type );
+        Optional<Map> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema( collectionName );
+
+        if ( collectionIndexingSchema.isPresent()) {
+            Map jsonMapData = collectionIndexingSchema.get();
+            final ArrayList fields = (ArrayList) jsonMapData.get( "fields" );
+            if ( fields.size() == 1 && fields.get(0).equals("!")) {
+                skipIndexing = true;
+            }
         }
+
+        return skipIndexing;
     }
 
 
@@ -670,8 +692,9 @@ public class CpEntityManager implements EntityManager {
 
         Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
 
-        //Step 4 && 5
-        indexService.queueEntityDelete( applicationScope, entityId );
+        if ( !skipIndexingForType( entityId.getType() ) ) {
+            indexService.queueEntityDelete( applicationScope, entityId );
+        }
 
         //Step 6
         //delete from our UUID index
@@ -714,7 +737,8 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Results searchCollectionConsistent( EntityRef entityRef, String collectionName, Query query, int expectedResults) throws Exception {
+    public Results searchCollectionConsistent(
+        EntityRef entityRef, String collectionName, Query query, int expectedResults) throws Exception {
 
         return getRelationManager( entityRef ).searchCollectionConsistent(collectionName, query, expectedResults);
     }
@@ -754,8 +778,8 @@ public class CpEntityManager implements EntityManager {
     public RelationManager getRelationManager( EntityRef entityRef ) {
         Preconditions.checkNotNull(entityRef, "entityRef cannot be null");
 
-        CpRelationManager relationManager =
-            new CpRelationManager(managerCache, indexService, collectionService, connectionService, this, entityManagerFig, applicationId, entityRef );
+        CpRelationManager relationManager = new CpRelationManager( managerCache, indexService, collectionService,
+            connectionService, this, entityManagerFig, applicationId, entityRef );
         return relationManager;
     }
 
@@ -830,7 +854,8 @@ public class CpEntityManager implements EntityManager {
 
         Timer.Context repairedEntityGet = entGetRepairedEntityTimer.time();
 
-        //TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField we can verify it is correct?
+        // TODO: can't we just sub in the getEntityRepair method here
+        // so for every read of a uniqueEntityField we can verify it is correct?
 
         StringField uniqueLookupRepairField =  new StringField( propertyName, aliasType.toString());
 
@@ -916,8 +941,8 @@ public class CpEntityManager implements EntityManager {
         // add a warn statement so we can see if we have data migration issues.
         // TODO When we get an event system, trigger a repair if this is detected
         if ( results.size() > 1 ) {
-            logger.warn( "More than 1 entity with Owner id '{}' of type '{}' and alias '{}' exists. This is a duplicate alias, and needs audited",
-                    ownerRef, collectionType, aliasValue );
+            logger.warn( "More than 1 entity with Owner id '{}' of type '{}' and alias '{}' exists. " +
+                "This is a duplicate alias, and needs audited", ownerRef, collectionType, aliasValue );
         }
 
         return results.get(aliasValue);
@@ -1139,7 +1164,9 @@ public class CpEntityManager implements EntityManager {
 
         //Adding graphite metrics
 
-        indexService.queueEntityIndexUpdate(applicationScope, cpEntity, 0);
+        if ( !skipIndexingForType( cpEntity.getId().getType() ) ) {
+            indexService.queueEntityIndexUpdate( applicationScope, cpEntity, 0 );
+        }
     }
 
 
@@ -1785,12 +1812,17 @@ public class CpEntityManager implements EntityManager {
 
         //do a check to see if you have a * field. If you do have a * field then ignore all other fields
         //and only accept the * field.
-        if(fieldProperties.contains( "*" )){
-            ArrayList<String> wildCardArrayList = new ArrayList<>(  );
+        if ( fieldProperties.contains( "*" )) {
+            ArrayList<String> wildCardArrayList = new ArrayList<>();
             wildCardArrayList.add( "*" );
-            schemaMap.put( "fields",wildCardArrayList );
-        }
-        else {
+            schemaMap.put( "fields", wildCardArrayList );
+
+        } else if ( fieldProperties.contains( "!" )) {
+            ArrayList<String> wildCardArrayList = new ArrayList<>();
+            wildCardArrayList.add( "!" );
+            schemaMap.put( "fields", wildCardArrayList );
+
+        } else {
             schemaMap.putAll( properties );
         }
 
@@ -1815,7 +1847,7 @@ public class CpEntityManager implements EntityManager {
     public Object getCollectionSchema( String collectionName ){
         MapManager mm = getMapManagerForTypes();
 
-        IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); //managerCache.getIndexSchema( mm );
+        IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
 
         Optional<Map> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema( collectionName );
 
@@ -2388,7 +2420,8 @@ public class CpEntityManager implements EntityManager {
         if ( !skipAggregateCounters ) {
             long timestamp = cass.createTimestamp();
             Mutator<ByteBuffer> m = createMutator( cass.getApplicationKeyspace( applicationId ), be );
-            counterUtils.batchIncrementAggregateCounters( m, applicationId, userId, groupId, null, category, counters, timestamp );
+            counterUtils.batchIncrementAggregateCounters(
+                m, applicationId, userId, groupId, null, category, counters, timestamp );
 
             //Adding graphite metrics
             Timer.Context timeIncrementCounters =entIncrementAggregateCountersTimer.time();
@@ -2987,8 +3020,9 @@ public class CpEntityManager implements EntityManager {
 
         final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
 
-        return graphManager.getEdgeTypesFromSource( searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) ).collect(
-            () -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last();
+        return graphManager.getEdgeTypesFromSource(
+            searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) )
+                .collect( () -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last();
     }
 
 
@@ -3001,7 +3035,8 @@ public class CpEntityManager implements EntityManager {
         final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
 
         return graphManager.getEdgeTypesToTarget(searchByEdgeType).map(
-                    edgeName -> getConnectionNameFromEdgeName( edgeName ) ).collect( () -> new HashSet<String>(  ), ( r, s ) -> r.add(s) ).toBlocking().last();
+            edgeName -> getConnectionNameFromEdgeName( edgeName ) )
+                .collect( () -> new HashSet<String>(  ), ( r, s ) -> r.add(s) ).toBlocking().last();
     }
 
 
@@ -3030,7 +3065,8 @@ public class CpEntityManager implements EntityManager {
             try {
                 for (int i = 0; i < 20; i++) {
                     if (searchCollection(
-                        new SimpleEntityRef(org.apache.usergrid.persistence.entities.Application.ENTITY_TYPE, getApplicationId()),
+                        new SimpleEntityRef(
+                            org.apache.usergrid.persistence.entities.Application.ENTITY_TYPE, getApplicationId()),
                         InflectionUtils.pluralize("refresh"),
                         Query.fromQL("select * where uuid='" + refreshEntity.getUuid() + "'")
                     ).size() > 0

http://git-wip-us.apache.org/repos/asf/usergrid/blob/fbced588/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index d052564..b240629 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.rest.applications.collection;
 
 import com.fasterxml.jackson.databind.JsonNode;
 
+import org.apache.commons.lang.RandomStringUtils;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.entities.Application;
 
@@ -42,11 +43,7 @@ import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.MediaType;
 
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.ArrayList;
+import java.util.*;
 
 import org.apache.commons.lang.NullArgumentException;
 
@@ -943,4 +940,53 @@ public class CollectionsResourceIT extends AbstractRestIT {
         Assert.assertEquals( "Should not be more than one name property", -1, secondFred );
   */
     }
+
+
+    /**
+     * Test that when schema is "!" entity gets saved but does not get indexed
+     */
+    @Test
+    public void postCollectionSchemaWithWildcardIndexNone() throws Exception {
+
+        // creating schema with no index wildcard and other fields that should be ignored
+        ArrayList<String> indexingArray = new ArrayList<>(  );
+        indexingArray.add( "!" );
+        indexingArray.add( "one" );
+        indexingArray.add( "two" );
+        Entity payload = new Entity();
+        payload.put( "fields", indexingArray);
+
+        String randomizer = RandomStringUtils.randomAlphanumeric(10);
+        String collectionName = "col_" + randomizer;
+        app().collection( collectionName ).collection( "_indexes" ).post( payload );
+        refreshIndex();
+
+        // was the no-index wildcard saved and others ignored?
+        Collection collection = app().collection( collectionName ).collection( "_index" ).get();
+        LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData();
+        ArrayList<String> schema = ( ArrayList<String> ) testCollectionSchema.get( "fields" );
+        assertTrue( schema.contains( "!" ) );
+        assertFalse( schema.contains( "one" ) );
+        assertFalse( schema.contains( "two" ) );
+
+        // post an entity with a name and a color
+        String entityName = "name_" + randomizer;
+        Entity postedEntity = this.app().collection( collectionName )
+            .post( new Entity().withProp("name", entityName).withProp( "color", "magenta" ) );
+
+        // should be able to get entity by ID
+        Entity getByIdEntity = app().collection( collectionName ).entity( postedEntity.getUuid() ).get();
+        assertNotNull( getByIdEntity );
+        assertEquals( postedEntity.getUuid(), getByIdEntity.getUuid() );
+
+        // should be able to get entity by name
+        Entity getByNameEntity = app().collection( collectionName ).entity( entityName ).get();
+        assertNotNull( getByNameEntity );
+        assertEquals( postedEntity.getUuid(), getByNameEntity.getUuid() );
+
+        // should NOT be able to get entity by query
+        Iterator<Entity> getByQuery = app().collection( collectionName )
+            .get( new QueryParameters().setQuery( "select * where color='magenta'" ) ).iterator();
+        assertFalse( getByQuery.hasNext() );
+    }
 }


[3/5] usergrid git commit: Merge commit 'refs/pull/503/head' of github.com:apache/usergrid into release-2.1.1

Posted by mr...@apache.org.
Merge commit 'refs/pull/503/head' of github.com:apache/usergrid into release-2.1.1


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

Branch: refs/heads/release-2.1.1
Commit: 99e6d406cd0d60c95cf4e9e69c292b39ca3def21
Parents: 491aa08 fbced58
Author: Michael Russo <mr...@apigee.com>
Authored: Fri Apr 15 00:47:36 2016 +0200
Committer: Michael Russo <mr...@apigee.com>
Committed: Fri Apr 15 00:47:36 2016 +0200

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 86 ++++++++++++++------
 .../collection/CollectionsResourceIT.java       | 56 +++++++++++--
 2 files changed, 112 insertions(+), 30 deletions(-)
----------------------------------------------------------------------



[4/5] usergrid git commit: Fix issues when groups not being targeted in notifications when referencing by name.

Posted by mr...@apache.org.
Fix issues when groups not being targeted in notifications when referencing by name.


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

Branch: refs/heads/release-2.1.1
Commit: 226cb62b5c6ebf76741054d8a93e09265af21079
Parents: 99e6d40
Author: Michael Russo <mr...@apigee.com>
Authored: Fri Apr 15 00:48:01 2016 +0200
Committer: Michael Russo <mr...@apigee.com>
Committed: Fri Apr 15 00:48:01 2016 +0200

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      |  7 ++++++
 .../apache/usergrid/persistence/PathQuery.java  | 24 ++++++++++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/226cb62b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index b5a4107..9ecf466 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -945,6 +945,13 @@ public class CpRelationManager implements RelationManager {
 
                 query.setQl( newQuery );
             }
+            // groups have a special unique identifier
+            else if ( query.getEntityType().equals( Group.ENTITY_TYPE ) ){
+
+                final String newQuery = "select * where path='" + query.getSingleNameOrEmailIdentifier() + "'";
+
+                query.setQl( newQuery );
+            }
 
             // use the ident with the default alias. could be an email
             else {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/226cb62b/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java b/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
index bb336e1..55839a6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/PathQuery.java
@@ -17,10 +17,13 @@
 package org.apache.usergrid.persistence;
 
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.persistence.index.query.Identifier;
+import org.apache.usergrid.utils.InflectionUtils;
 
 
 public class PathQuery<E> {
@@ -85,6 +88,7 @@ public class PathQuery<E> {
 
     public Iterator<E> iterator( EntityManager em ) {
         try {
+
             if ( uuid != null && type != null ) {
                 return new PagingResultsIterator( getHeadResults( em ), query.getResultsLevel() );
             }
@@ -99,7 +103,20 @@ public class PathQuery<E> {
 
 
     protected Results getHeadResults( EntityManager em ) throws Exception {
+
         EntityRef ref = new SimpleEntityRef(type,uuid);
+
+        // if it's a single name identifier, just directly fetch that
+        if ( !query.getQl().isPresent() && query.getSingleNameOrEmailIdentifier() != null){
+
+            String name = query.getSingleNameOrEmailIdentifier();
+            String entityType = InflectionUtils.singularize(query.getCollection());
+
+            UUID entityId = em.getUniqueIdFromAlias( entityType, name );
+
+            return em.getEntities(Collections.singletonList(entityId), entityType);
+        }
+
         return ( query.getCollection() != null ) ?
                em.searchCollection( ref, query.getCollection(), query ) :
                em.searchTargetEntities(ref, query);
@@ -107,6 +124,13 @@ public class PathQuery<E> {
 
 
     protected Iterator refIterator( EntityManager em ) throws Exception {
+
+        if ( query.getQl() == null && query.getSingleNameOrEmailIdentifier() != null){
+
+            return new PagingResultsIterator( getHeadResults( em ), Level.REFS );
+
+        }
+
         if ( type != null  && uuid != null) {
             return new PagingResultsIterator( getHeadResults( em ), Level.REFS );
         }


[2/5] usergrid git commit: Added test for google and apple to make sure that the receipts flag is honored. Allow people to input strings and boolean values to the receipts flag in order to save receipts. Added receipts flag to notifications.

Posted by mr...@apache.org.
Added test for google and apple to make sure that the receipts flag is honored.
Allow people to input strings and boolean values to the receipts flag in order to save receipts.
Added receipts flag to notifications.


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

Branch: refs/heads/release-2.1.1
Commit: 491aa084f0c633f318dbe67cc566a6be81491b2e
Parents: 2e576f3
Author: George Reyes <gr...@apache.org>
Authored: Thu Apr 14 14:43:05 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Thu Apr 14 14:43:05 2016 -0700

----------------------------------------------------------------------
 .../services/notifications/TaskManager.java     | 18 ++++++------
 .../impl/ApplicationQueueManagerImpl.java       | 30 ++++++++++++++++++--
 .../apns/NotificationsServiceIT.java            | 26 +++++++++++++++++
 .../gcm/NotificationsServiceIT.java             | 27 +++++++++++++++++-
 4 files changed, 90 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index 954724f..ce2b82c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -104,14 +104,16 @@ public class TaskManager {
             }
 
             failures.incrementAndGet();
-            if (receipt.getUuid() != null) {
-                successes.decrementAndGet();
-            }
-            receipt.setErrorCode(code);
-            receipt.setErrorMessage(message);
-            this.saveReceipt(notification, new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID), receipt,true);
-            if (logger.isDebugEnabled()) {
-                logger.debug("notification {} receipt saved for device {}", notification.getUuid(), deviceUUID);
+            if(receipt!=null) {
+                if ( receipt.getUuid() != null ) {
+                    successes.decrementAndGet();
+                }
+                receipt.setErrorCode( code );
+                receipt.setErrorMessage( message );
+                this.saveReceipt( notification, new SimpleEntityRef( Device.ENTITY_TYPE, deviceUUID ), receipt, true );
+                if ( logger.isDebugEnabled() ) {
+                    logger.debug( "notification {} receipt saved for device {}", notification.getUuid(), deviceUUID );
+                }
             }
         } finally {
             completed(notifier, deviceUUID);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index 0b0432d..8b908ee 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -329,8 +329,34 @@ public class ApplicationQueueManagerImpl implements ApplicationQueueManager {
                     String notifierName = message.getNotifierKey().toLowerCase();
                     ProviderAdapter providerAdapter = notifierMap.get(notifierName.toLowerCase());
                     Object payload = translatedPayloads.get(notifierName);
-                    Receipt receipt = new Receipt(notification.getUuid(), message.getNotifierId(), payload, deviceUUID);
-                    TaskTracker tracker = new TaskTracker(providerAdapter.getNotifier(), taskManager, receipt, deviceUUID);
+                    Map dynamicNotificationProperties =notification.getDynamicProperties();
+                    //do additional error checking to make sure other values will work.
+                    Boolean receiptsField = true;
+
+                    Object typelessReceiptsField = dynamicNotificationProperties.getOrDefault( "receipts",true );
+                    if(typelessReceiptsField instanceof Boolean) {
+                        receiptsField = ( boolean ) typelessReceiptsField;
+                    }
+                    else if(typelessReceiptsField instanceof String){
+                        String booleanString = ( String ) typelessReceiptsField;
+                        if(booleanString.toLowerCase().equals( "false" )){
+                            receiptsField=false;
+                        }
+                    }
+
+                    TaskTracker tracker = null;
+                    if(receiptsField==false){
+//                        Receipt receipt =
+//                            new Receipt( notification.getUuid(), message.getNotifierId(), payload, deviceUUID );
+                        tracker =
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager, null, deviceUUID );
+                    }
+                    else {
+                        Receipt receipt =
+                            new Receipt( notification.getUuid(), message.getNotifierId(), payload, deviceUUID );
+                        tracker =
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager, receipt, deviceUUID );
+                    }
                     if (!isOkToSend(notification)) {
                         tracker.failed(0, "Notification is duplicate/expired/cancelled.");
                     } else {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 3923827..0ef5fe4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -163,6 +163,32 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     }
 
     @Test
+    public void singlePushNotificationNoReceipts() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", true);
+        app.put("receipts",false );
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
+        assertEquals(
+            notification.getPayloads().get(notifier.getUuid().toString()),
+            payload);
+
+        // perform push //
+        notification = notificationWaitForComplete(notification);
+        checkReceipts(notification, 0);
+    }
+
+    @Test
     public void pushWithNoValidDevicesShouldComplete() throws Exception {
 
         // create unrelated notifier

http://git-wip-us.apache.org/repos/asf/usergrid/blob/491aa084/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 1c7915a..13b2887 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -150,7 +150,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.put(notifier.getUuid().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
-        app.put("debug", true);
+        app.put("debug", false);
         app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
@@ -166,6 +166,31 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         checkReceipts(notification, 1);
     }
 
+    @Test
+    public void singlePushNotificationNoReceipts() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", true);
+        app.put("receipts",false );
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
+        assertEquals(
+            notification.getPayloads().get(notifier.getUuid().toString()),
+            payload);
+
+        // perform push //
+        notification = notificationWaitForComplete(notification);
+        checkReceipts(notification, 0);
+    }
 
     @Test
     public void singlePushNotificationHighPriority() throws Exception {


[5/5] usergrid git commit: Add receipts property to the notification entity so it gets persisted.

Posted by mr...@apache.org.
Add receipts property to the notification entity so it gets persisted.


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

Branch: refs/heads/release-2.1.1
Commit: 8dce5ed8c26a27cd991375803327407f12efc3ca
Parents: 226cb62
Author: Michael Russo <mr...@apigee.com>
Authored: Fri Apr 15 01:00:58 2016 +0200
Committer: Michael Russo <mr...@apigee.com>
Committed: Fri Apr 15 01:00:58 2016 +0200

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      | 13 +++++++++
 .../notifications/NotificationsService.java     |  2 ++
 .../impl/ApplicationQueueManagerImpl.java       | 30 ++++++--------------
 3 files changed, 24 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/8dce5ed8/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index 1350593..6a6e3fa 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -93,6 +93,10 @@ public class Notification extends TypedEntity {
     @EntityProperty
     protected String errorMessage;
 
+    /** Flag to disable the creation, saving, connecting of receipt entities for a notification.  */
+    @EntityProperty
+    protected boolean saveReceipts;
+
     @EntityCollection(type = "receipt")
     protected List<UUID> receipts;
 
@@ -178,6 +182,15 @@ public class Notification extends TypedEntity {
     }
 
     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public boolean getSaveReceipts() {
+        return saveReceipts;
+    }
+
+    public void setSaveReceipts(boolean saveReceipts) {
+        this.saveReceipts = saveReceipts;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
     public boolean getDebug() {
         return debug;
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8dce5ed8/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index bbdec7a..824089a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -139,6 +139,8 @@ public class NotificationsService extends AbstractCollectionService {
         try {
             validate(null, context.getPayload());
             Notification.PathTokens pathTokens = getPathTokens(context.getRequest().getOriginalParameters());
+            context.getProperties().put("saveReceipts", true); // default saving of receipts
+            context.getProperties().put("processingFinished", 0L); // defaulting processing finished to 0
             context.getProperties().put("state", Notification.State.CREATED);
             context.getProperties().put("pathQuery", pathTokens);
             context.setOwner(sm.getApplication());

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8dce5ed8/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index 8b908ee..faa9a02 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -329,33 +329,21 @@ public class ApplicationQueueManagerImpl implements ApplicationQueueManager {
                     String notifierName = message.getNotifierKey().toLowerCase();
                     ProviderAdapter providerAdapter = notifierMap.get(notifierName.toLowerCase());
                     Object payload = translatedPayloads.get(notifierName);
-                    Map dynamicNotificationProperties =notification.getDynamicProperties();
-                    //do additional error checking to make sure other values will work.
-                    Boolean receiptsField = true;
-
-                    Object typelessReceiptsField = dynamicNotificationProperties.getOrDefault( "receipts",true );
-                    if(typelessReceiptsField instanceof Boolean) {
-                        receiptsField = ( boolean ) typelessReceiptsField;
-                    }
-                    else if(typelessReceiptsField instanceof String){
-                        String booleanString = ( String ) typelessReceiptsField;
-                        if(booleanString.toLowerCase().equals( "false" )){
-                            receiptsField=false;
-                        }
-                    }
 
                     TaskTracker tracker = null;
-                    if(receiptsField==false){
-//                        Receipt receipt =
-//                            new Receipt( notification.getUuid(), message.getNotifierId(), payload, deviceUUID );
+
+                    if(notification.getSaveReceipts()){
+
+                        final Receipt receipt =
+                            new Receipt( notification.getUuid(), message.getNotifierId(), payload, deviceUUID );
                         tracker =
-                            new TaskTracker( providerAdapter.getNotifier(), taskManager, null, deviceUUID );
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager, receipt, deviceUUID );
+
                     }
                     else {
-                        Receipt receipt =
-                            new Receipt( notification.getUuid(), message.getNotifierId(), payload, deviceUUID );
+
                         tracker =
-                            new TaskTracker( providerAdapter.getNotifier(), taskManager, receipt, deviceUUID );
+                            new TaskTracker( providerAdapter.getNotifier(), taskManager, null, deviceUUID );
                     }
                     if (!isOkToSend(notification)) {
                         tracker.failed(0, "Notification is duplicate/expired/cancelled.");