usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [33/50] [abbrv] incubator-usergrid git commit: fixed userresourceit, added property filters
Date Mon, 01 Jun 2015 21:48:42 GMT
fixed userresourceit, added property filters


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

Branch: refs/heads/USERGRID-628
Commit: 7f7dc82e18bce85d92e043a669d96e5d08ff7c4c
Parents: 68833ad
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Fri May 29 16:49:34 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Fri May 29 16:49:34 2015 -0600

----------------------------------------------------------------------
 .../pipeline/builder/EntityBuilder.java         |  2 +-
 .../search/AbstractElasticSearchFilter.java     | 13 ++--
 .../pipeline/read/search/Candidate.java         | 11 +++-
 .../read/search/CandidateEntityFilter.java      | 66 +++++++++++++-------
 .../org/apache/usergrid/persistence/Query.java  |  2 +-
 .../apache/usergrid/persistence/IndexIT.java    | 44 +++++++++++--
 .../persistence/model/field/AbstractField.java  |  1 +
 .../usergrid/persistence/model/field/Field.java | 13 ++--
 .../collection/users/UserResourceIT.java        | 17 ++---
 .../usergrid/services/ConnectionsServiceIT.java |  2 +-
 10 files changed, 121 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/EntityBuilder.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/EntityBuilder.java
index b120c56..81e7bf8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/EntityBuilder.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/EntityBuilder.java
@@ -49,6 +49,6 @@ public class EntityBuilder {
      */
     public Observable<ResultsPage<Entity>> build(){
         //we must add our resume filter so we drop our previous page first element if it's
present
-        return pipeline.withFilter( new EntityResumeFilter() ).withFilter( new ResultsPageCollector<>()
).execute();
+        return pipeline.withFilter( new EntityResumeFilter() ).withFilter(new ResultsPageCollector<>()).execute();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/AbstractElasticSearchFilter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/AbstractElasticSearchFilter.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/AbstractElasticSearchFilter.java
index eaf74c1..2fdffd2 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/AbstractElasticSearchFilter.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/AbstractElasticSearchFilter.java
@@ -20,6 +20,7 @@
 package org.apache.usergrid.corepersistence.pipeline.read.search;
 
 
+import org.apache.usergrid.persistence.index.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,12 +29,6 @@ import org.apache.usergrid.corepersistence.pipeline.read.AbstractPathFilter;
 import org.apache.usergrid.corepersistence.pipeline.read.FilterResult;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.core.metrics.ObservableTimer;
-import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
-import org.apache.usergrid.persistence.index.CandidateResult;
-import org.apache.usergrid.persistence.index.CandidateResults;
-import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.SearchEdge;
-import org.apache.usergrid.persistence.index.SearchTypes;
 import org.apache.usergrid.persistence.model.entity.Id;
 
 import com.codahale.metrics.Timer;
@@ -41,6 +36,8 @@ import com.google.common.base.Optional;
 
 import rx.Observable;
 
+import java.util.Collection;
+
 
 /**
  * Command for reading graph edges
@@ -107,6 +104,8 @@ public abstract class AbstractElasticSearchFilter extends AbstractPathFilter<Id,
                             applicationEntityIndex.search( searchEdge, searchTypes, query,
limit, currentOffSet );
 
 
+                        Collection<SelectFieldMapping> fieldMappingCollection = candidateResults.getGetFieldMappings();
+
 
                         for( CandidateResult candidateResult: candidateResults){
 
@@ -115,7 +114,7 @@ public abstract class AbstractElasticSearchFilter extends AbstractPathFilter<Id,
                                 return;
                             }
 
-                            final Candidate candidate = new Candidate( candidateResult, searchEdge
);
+                            final Candidate candidate = new Candidate( candidateResult, searchEdge,
fieldMappingCollection );
 
                             final FilterResult<Candidate>
                                 result = createFilterResult( candidate, currentOffSet, idFilterResult.getPath()
);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/Candidate.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/Candidate.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/Candidate.java
index 7ada4ba..4a19b56 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/Candidate.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/Candidate.java
@@ -22,6 +22,10 @@ package org.apache.usergrid.corepersistence.pipeline.read.search;
 
 import org.apache.usergrid.persistence.index.CandidateResult;
 import org.apache.usergrid.persistence.index.SearchEdge;
+import org.apache.usergrid.persistence.index.SelectFieldMapping;
+
+import java.util.Collection;
+import java.util.List;
 
 
 /**
@@ -31,16 +35,19 @@ public class Candidate {
 
     private final CandidateResult candidateResult;
     private final SearchEdge searchEdge;
+    private final Collection<SelectFieldMapping>  fields;
 
 
     /**
      * Create a new Candidate for further processing
      * @param candidateResult  The candidate result
      * @param searchEdge The search edge this was searched on
+     * @param fields
      */
-    public Candidate( final CandidateResult candidateResult, final SearchEdge searchEdge
) {
+    public Candidate( final CandidateResult candidateResult, final SearchEdge searchEdge,
final Collection<SelectFieldMapping> fields ) {
         this.candidateResult = candidateResult;
         this.searchEdge = searchEdge;
+        this.fields = fields;
     }
 
 
@@ -52,4 +59,6 @@ public class Candidate {
     public SearchEdge getSearchEdge() {
         return searchEdge;
     }
+
+    public Collection<SelectFieldMapping>  getFields(){ return fields; }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java
index d0b6af9..d8a9c68 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/CandidateEntityFilter.java
@@ -20,10 +20,10 @@
 package org.apache.usergrid.corepersistence.pipeline.read.search;
 
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
+import org.apache.usergrid.persistence.index.*;
+import org.apache.usergrid.persistence.model.field.Field;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,11 +35,6 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory
 import org.apache.usergrid.persistence.collection.EntitySet;
 import org.apache.usergrid.persistence.collection.MvccEntity;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
-import org.apache.usergrid.persistence.index.CandidateResult;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 
@@ -93,22 +88,45 @@ public class CandidateEntityFilter extends AbstractFilter<FilterResult<Candidate
 
             //load them
             .flatMap( candidateResults -> {
-                    //flatten toa list of ids to load
-                    final Observable<List<Id>> candidateIds =
-                        Observable.from( candidateResults ).map( filterResultCandidate ->
filterResultCandidate.getValue().getCandidateResult().getId() ).toList();
-
-                    //load the ids
-                    final Observable<EntitySet> entitySetObservable =
-                        candidateIds.flatMap( ids -> entityCollectionManager.load( ids
) );
-
-                    //now we have a collection, validate our canidate set is correct.
-
-                    return entitySetObservable.map(
-                        entitySet -> new EntityVerifier( applicationIndex.createBatch(),
entitySet,
-                            candidateResults ) ).doOnNext( entityCollector -> entityCollector.merge()
)
-                                              .flatMap(
-                                                  entityCollector -> Observable.from(
entityCollector.getResults() ) );
-                } );
+
+                //flatten toa list of ids to load
+                final Observable<List<Candidate>> candidates =
+                    Observable.from(candidateResults)
+                        .map(filterResultCandidate -> filterResultCandidate.getValue()).toList();
+                //load the ids
+                final Observable<FilterResult<Entity>> entitySetObservable =
+                    candidates.flatMap(candidatesList -> {
+                        Collection<SelectFieldMapping> mappings = candidatesList.get(0).getFields();
+                        Observable<EntitySet> entitySets = Observable.from(candidatesList)
+                            .map(candidateEntry -> candidateEntry.getCandidateResult().getId()).toList()
+                            .flatMap(idList -> entityCollectionManager.load(idList));
+                        //now we have a collection, validate our canidate set is correct.
+                        return entitySets.map(
+                            entitySet -> new EntityVerifier(
+                                applicationIndex.createBatch(), entitySet, candidateResults)
+                        )
+                            .doOnNext(entityCollector -> entityCollector.merge())
+                            .flatMap(entityCollector -> Observable.from(entityCollector.getResults()))
+                            .map(entityFilterResult -> {
+                                final Entity entity = entityFilterResult.getValue();
+                                if (mappings.size() > 0) {
+                                    Map<String,Field> fieldMap = new HashMap<String,
Field>(mappings.size());
+                                    rx.Observable.from(mappings)
+                                        .filter(mapping -> entity.getFieldMap().containsKey(mapping.getSourceFieldName()))
+                                        .doOnNext(mapping -> {
+                                            Field field = entity.getField(mapping.getSourceFieldName());
+                                            field.setName(mapping.getTargetFieldName());
+                                            fieldMap.put(mapping.getTargetFieldName(),field);
+                                        }).toBlocking().last();
+                                    entity.setFieldMap(fieldMap);
+                                }
+                                return entityFilterResult;
+                            });
+                    });
+                return entitySetObservable;
+
+
+            } );
 
         //if we filter all our results, we want to continue to try the next page
         return searchIdSetObservable;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
index a4cccbc..ead73f0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
@@ -854,7 +854,7 @@ public class Query {
      * @return
      */
     public boolean isGraphSearch(){
-        return ql == null;
+        return ql == null || ql.trim().toLowerCase().equals("select *");
     }
 
     public Query setQl( String ql ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/core/src/test/java/org/apache/usergrid/persistence/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/IndexIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/IndexIT.java
index 4ab3c7d..50b0ba3 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/IndexIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/IndexIT.java
@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
 
+import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,10 +38,7 @@ import me.prettyprint.hector.api.Keyspace;
 import me.prettyprint.hector.api.mutation.Mutator;
 
 import static me.prettyprint.hector.api.factory.HFactory.createMutator;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
+import static org.junit.Assert.*;
 
 
 public class IndexIT extends AbstractCoreIT {
@@ -287,6 +285,44 @@ public class IndexIT extends AbstractCoreIT {
 
 
     @Test
+    public void testEntityReduction() throws Exception {
+
+        UUID applicationId = app.getId();
+
+        EntityManager em = setup.getEmf().getEntityManager(applicationId);
+
+
+        Map<String, Object> entity1 = new LinkedHashMap<String, Object>();
+        entity1.put("name", "name_1");
+        entity1.put("status", "pickled");
+
+        em.create("names", entity1);
+
+        app.refreshIndex();
+
+        //should return valid values
+        Query query = Query.fromQL("select status where status = 'pickled'");
+        Results r = em.searchCollection( em.getApplicationRef(), "names", query );
+        assertTrue(r.getEntities() != null && r.getEntities().size() > 0);
+        Entity first =  r.getEntities().get(0);
+        assertTrue(first.getDynamicProperties().size() == 1);
+
+        //should return valid values
+        query = Query.fromQL("select uuid where status = 'pickled'");
+        r = em.searchCollection( em.getApplicationRef(), "names", query );
+        assertTrue(r.getEntities() != null && r.getEntities().size() > 0);
+        first =  r.getEntities().get(0);
+        assertTrue(first.getDynamicProperties().size() == 0);
+
+        //should return valid values
+        query = Query.fromQL("select uuid:myid where status = 'pickled'");
+        r = em.searchCollection( em.getApplicationRef(), "names", query );
+        assertTrue(r.getEntities() != null && r.getEntities().size() > 0);
+        first =  r.getEntities().get(0);
+        assertTrue(first.getDynamicProperties().size() == 0);
+
+    }
+    @Test
     public void testPropertyUpdateWithConnection() throws Exception {
 
         UUID applicationId = app.getId();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
index 9cf0af0..f6a44eb 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
@@ -74,6 +74,7 @@ public abstract class AbstractField<T> implements Field<T> {
     public String getName() {
         return name;
     }
+    public void setName(final String newName){name = newName;}
 
     public boolean isUnique() {
         return unique;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
index c0a111f..e4841bf 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
@@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
 
 
 /**
- * Interface for fields.  All fields must implement this method The T is the type of field

+ * Interface for fields.  All fields must implement this method The T is the type of field
  * (in the java runtime) The V is the value of the field
  * @param <T>
  */
@@ -39,7 +39,12 @@ public interface Field<T> extends Serializable {
      */
     @JsonProperty
     public String getName();
-
+    /**
+     * Get the name of the field
+     * @return
+     */
+    @JsonProperty
+    public void setName(final String newName);
     /**
      * Get the value of the field
      * @return
@@ -47,9 +52,9 @@ public interface Field<T> extends Serializable {
     @JsonProperty
     public T getValue();
 
-    /** 
+    /**
      * True if field value must be unique within Entity Collection.
-     * @return 
+     * @return
      */
     public boolean isUnique();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
index 7b9414a..dd3cfe1 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
@@ -74,9 +74,9 @@ public class UserResourceIT extends AbstractRestIT {
     public void usernameQuery() throws IOException {
         String ql = "username = 'user*'";
         Collection collection = usersResource.get(new QueryParameters().setQuery(ql));
-        assertEquals(userRepo.getByUserName("user1"), getIdFromSearchResults(collection,
0));
+        assertEquals(userRepo.getByUserName("user1"), getIdFromSearchResults(collection,
2));
         assertEquals(userRepo.getByUserName("user2"), getIdFromSearchResults(collection,
1));
-        assertEquals(userRepo.getByUserName("user3"), getIdFromSearchResults(collection,
2));
+        assertEquals(userRepo.getByUserName("user3"), getIdFromSearchResults(collection,
0));
     }
 
 
@@ -85,8 +85,8 @@ public class UserResourceIT extends AbstractRestIT {
         String ql = "name = 'John*'";
 
         Collection collection = usersResource.get(new QueryParameters().setQuery(ql));
-        assertEquals(userRepo.getByUserName("user2"), getIdFromSearchResults(collection,
0));
-        assertEquals(userRepo.getByUserName("user3"), getIdFromSearchResults(collection,
1));
+        assertEquals(userRepo.getByUserName("user2"), getIdFromSearchResults(collection,
1));
+        assertEquals(userRepo.getByUserName("user3"), getIdFromSearchResults(collection,
0));
     }
 
 
@@ -94,7 +94,7 @@ public class UserResourceIT extends AbstractRestIT {
     public void nameQueryByUUIDs() throws Exception {
         String ql = "select uuid name = 'John*'";
         Collection response = this.app().collection("users").get(new QueryParameters().setQuery(ql));
-        assertNotNull(response.getResponse().list());
+        assertNotNull(response.getResponse().getEntities());
     }
 
 
@@ -1068,8 +1068,11 @@ public class UserResourceIT extends AbstractRestIT {
         {
             final Collection response = usersResource.get(new QueryParameters().setQuery("select
uuid"));
 
-            assertNotNull("List must exist", response.getResponse().list());
-            assertTrue("Must be some list items", response.getResponse().list().size() >
0);
+            assertNotNull("List must exist", response.getResponse().getEntities());
+            assertTrue("Must be some list items", response.getResponse().getEntities().size()
> 0);
+
+            assertTrue("Must be some list items", response.getResponse().getEntities().get(0).keySet().size()
== 3);
+
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f7dc82e/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
index e281bf8..57fadca 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
@@ -63,7 +63,7 @@ public class ConnectionsServiceIT extends AbstractServiceIT {
         //DELETE users/conn-user1/manages/user2/conn-user2 (qualified by collection type
on second entity)
         app.testRequest( ServiceAction.DELETE, 1, "users", "conn-user1", "manages", "users",
"conn-user2" );
 
-        //TODO: test fails because the connections metadata is null. When before, data would
still be returned. 
+        //TODO: test fails because the connections metadata is null. When before, data would
still be returned.
         // "manages" connection removed from both entities
         user1 = app.testRequest( ServiceAction.GET, 1, "users", "conn-user1" ).getEntities().get(
0 );
         assertFalse( ( ( Map ) user1.getMetadata( "connections" ) ).containsKey( "manages"
) );


Mime
View raw message