usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [3/3] usergrid git commit: add ability for sysadmin to return ES query instead of results
Date Fri, 15 Dec 2017 17:44:39 GMT
add ability for sysadmin to return ES query instead of results


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

Branch: refs/heads/master
Commit: bd2385d76c3343d96b3b8648d1f68904e2247ed7
Parents: c2a0303
Author: Mike Dunker <mdunker@google.com>
Authored: Tue Dec 12 14:37:11 2017 -0800
Committer: Mike Dunker <mdunker@google.com>
Committed: Fri Dec 15 09:43:43 2017 -0800

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      |  6 +++
 .../pipeline/builder/IdBuilder.java             | 18 +++++---
 .../pipeline/read/FilterFactory.java            |  6 ++-
 .../search/AbstractElasticSearchFilter.java     |  7 ++-
 .../read/search/SearchCollectionFilter.java     |  5 ++-
 .../read/search/SearchConnectionFilter.java     |  5 ++-
 .../service/CollectionSearch.java               | 10 +++++
 .../service/ConnectionSearch.java               | 10 +++++
 .../service/ConnectionServiceImpl.java          |  6 ++-
 .../org/apache/usergrid/persistence/Query.java  | 11 ++++-
 .../usergrid/persistence/index/EntityIndex.java | 19 ++++++++
 .../index/exceptions/QueryReturnException.java  | 47 ++++++++++++++++++++
 .../index/impl/EsEntityIndexImpl.java           | 12 ++++-
 .../rest/applications/ServiceResource.java      | 13 ++++--
 .../exceptions/QueryReturnExceptionMapper.java  | 35 +++++++++++++++
 .../usergrid/services/AbstractService.java      |  2 +-
 .../usergrid/services/ServiceManager.java       | 11 ++---
 .../usergrid/services/ServiceRequest.java       | 27 ++++++++---
 18 files changed, 215 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/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 e329c29..218c695 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
@@ -634,6 +634,7 @@ public class CpRelationManager implements RelationManager {
         final Optional<String> queryString = query.isGraphSearch()? Optional.<String>absent():
query.getQl();
         final Id ownerId = headEntity.asId();
         final boolean analyzeOnly = query.getAnalyzeOnly();
+        final boolean returnQuery = query.getReturnQuery();
 
 
         if(query.getLevel() == Level.IDS ){
@@ -648,6 +649,7 @@ public class CpRelationManager implements RelationManager {
                             queryString, cursor );
 
                     search.setAnalyzeOnly(analyzeOnly);
+                    search.setReturnQuery(returnQuery);
 
                     return collectionService.searchCollectionIds( search );
                 }
@@ -666,6 +668,7 @@ public class CpRelationManager implements RelationManager {
                         queryString, cursor );
 
                 search.setAnalyzeOnly(analyzeOnly);
+                search.setReturnQuery(returnQuery);
                 IndexConsistency indexConsistency = getIndexConsistencyForType(collectionName);
                 search.setKeepStaleEntries(indexConsistency == IndexConsistency.LATEST);
 
@@ -931,6 +934,7 @@ public class CpRelationManager implements RelationManager {
         headEntity = em.validate( headEntity );
 
         final boolean analyzeOnly = query.getAnalyzeOnly();
+        final boolean returnQuery = query.getReturnQuery();
 
 
         final Query toExecute = adjustQuery( query );
@@ -965,6 +969,7 @@ public class CpRelationManager implements RelationManager {
                         new ConnectionSearch( applicationScope, sourceId, entityType, connection,
toExecute.getLimit(),
                             queryString, cursor, isConnecting );
                     search.setAnalyzeOnly(analyzeOnly);
+                    search.setReturnQuery(returnQuery);
                     return connectionService.searchConnectionAsRefs( search );
                 }
             }.next();
@@ -981,6 +986,7 @@ public class CpRelationManager implements RelationManager {
                     new ConnectionSearch( applicationScope, sourceId, entityType, connection,
toExecute.getLimit(),
                         queryString, cursor, isConnecting );
                 search.setAnalyzeOnly(analyzeOnly);
+                search.setReturnQuery(returnQuery);
                 return connectionService.searchConnection( search );
             }
         }.next();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/IdBuilder.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/IdBuilder.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/IdBuilder.java
index 4f44ac4..14237d6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/IdBuilder.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/builder/IdBuilder.java
@@ -118,13 +118,15 @@ public class IdBuilder {
      * @param collectionName  The name of the collection
      * @param ql The user's query to execute
      * @param entityType The type of the entity
-     * @param analyzeOnly
+     * @param analyzeOnly Whether only query analysis should be performed
+     * @param returnQuery Whether query should be returned instead of results
      * @return  Candidate results
      */
-    public CandidateBuilder searchCollection(final String collectionName, final String ql,
final String entityType, boolean analyzeOnly) {
+    public CandidateBuilder searchCollection(final String collectionName, final String ql,
final String entityType,
+                                             final boolean analyzeOnly, final boolean returnQuery)
{
 
         final Pipeline<FilterResult<Candidate>> newFilter = pipeline.withFilter(
filterFactory.searchCollectionFilter(
-            ql, collectionName, entityType, analyzeOnly ) );
+            ql, collectionName, entityType, analyzeOnly, returnQuery ) );
 
         return new CandidateBuilder( newFilter, filterFactory , null);
     }
@@ -132,7 +134,7 @@ public class IdBuilder {
     public CandidateBuilder searchCollection(final String collectionName, final String ql,
final CollectionSearch search ) {
 
         final Pipeline<FilterResult<Candidate>> newFilter = pipeline.withFilter(
filterFactory.searchCollectionFilter(
-            ql, collectionName, search.getEntityType(), search.getAnalyzeOnly() ) );
+            ql, collectionName, search.getEntityType(), search.getAnalyzeOnly(), search.getReturnQuery()
) );
 
         return new CandidateBuilder( newFilter, filterFactory, search );
     }
@@ -142,14 +144,16 @@ public class IdBuilder {
      * @param connectionName The connection name to search
      * @param ql The query to execute
      * @param entityType The optional type of entity.  If this is absent, all entity types
in the connection will be searched
-     * @param analyzeOnly
+     * @param analyzeOnly Whether only query analysis should be performed
+     * @param returnQuery Whether index query should be returned instead of results
      * @return  Candidate results
      */
-    public CandidateBuilder searchConnection(final String connectionName, final String ql,
final Optional<String> entityType, boolean analyzeOnly) {
+    public CandidateBuilder searchConnection(final String connectionName, final String ql,
final Optional<String> entityType,
+                                             final boolean analyzeOnly, final boolean returnQuery)
{
 
 
         final Pipeline<FilterResult<Candidate>> newFilter = pipeline.withFilter(
filterFactory.searchConnectionFilter(
-            ql, connectionName, entityType,analyzeOnly ) );
+            ql, connectionName, entityType, analyzeOnly, returnQuery ) );
 
         return new CandidateBuilder( newFilter, filterFactory );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/FilterFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/FilterFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/FilterFactory.java
index 7b61b3d..6cce6ec 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/FilterFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/FilterFactory.java
@@ -97,7 +97,8 @@ public interface FilterFactory {
     SearchCollectionFilter searchCollectionFilter( @Assisted( "query" ) final String query,
                                                    @Assisted( "collectionName" ) final String
collectionName,
                                                    @Assisted( "entityType" ) final String
entityType,
-                                                   @Assisted( "analyzeOnly") final boolean
analyzeOnly);
+                                                   @Assisted( "analyzeOnly") final boolean
analyzeOnly,
+                                                   @Assisted( "returnQuery" ) final boolean
returnQuery);
 
 
     /**
@@ -110,7 +111,8 @@ public interface FilterFactory {
     SearchConnectionFilter searchConnectionFilter( @Assisted( "query" ) final String query,
                                                    @Assisted( "connectionName" ) final String
connectionName,
                                                    @Assisted( "connectedEntityType" ) final
Optional<String> connectedEntityType,
-                                                   @Assisted( "analyzeOnly") final boolean
analyzeOnly);
+                                                   @Assisted( "analyzeOnly") final boolean
analyzeOnly,
+                                                   @Assisted( "returnQuery") final boolean
returnQuery);
 
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/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 9f6be2a..7a46507 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
@@ -57,6 +57,7 @@ public abstract class AbstractElasticSearchFilter extends AbstractPathFilter<Id,
     private final String query;
     private final Timer searchTimer;
     private final boolean analyzeOnly;
+    private final boolean returnQuery;
 
 
     /**
@@ -65,12 +66,13 @@ public abstract class AbstractElasticSearchFilter extends AbstractPathFilter<Id,
     public AbstractElasticSearchFilter(final EntityIndexFactory entityIndexFactory,
                                        final MetricsFactory metricsFactory,
                                        final IndexLocationStrategyFactory indexLocationStrategyFactory,
-                                       final String query, boolean analyzeOnly) {
+                                       final String query, boolean analyzeOnly, boolean returnQuery)
{
         this.entityIndexFactory = entityIndexFactory;
         this.indexLocationStrategyFactory = indexLocationStrategyFactory;
         this.query = query;
         this.searchTimer = metricsFactory.getTimer( AbstractElasticSearchFilter.class, "query.search"
);
         this.analyzeOnly = analyzeOnly;
+        this.returnQuery = returnQuery;
     }
 
 
@@ -127,7 +129,8 @@ public abstract class AbstractElasticSearchFilter extends AbstractPathFilter<Id,
 
                     try {
                         final CandidateResults candidateResults =
-                            applicationEntityIndex.search( searchEdge, searchTypes, query,
limit, currentOffSet, propertiesWithType, analyzeOnly );
+                            applicationEntityIndex.search( searchEdge, searchTypes, query,
limit, currentOffSet,
+                                propertiesWithType, analyzeOnly, returnQuery);
 
 
                         Collection<SelectFieldMapping> fieldMappingCollection = candidateResults.getGetFieldMappings();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchCollectionFilter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchCollectionFilter.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchCollectionFilter.java
index 214bcbb..176d986 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchCollectionFilter.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchCollectionFilter.java
@@ -53,8 +53,9 @@ public class SearchCollectionFilter extends AbstractElasticSearchFilter
{
                                    @Assisted( "query" ) final String query,
                                    @Assisted( "collectionName" ) final String collectionName,
                                    @Assisted( "entityType" ) final String entityType,
-                                   @Assisted( "analyzeOnly") final boolean analyzeOnly) {
-        super( entityIndexFactory, metricsFactory, indexLocationStrategyFactory, query, analyzeOnly
);
+                                   @Assisted( "analyzeOnly") final boolean analyzeOnly,
+                                   @Assisted( "returnQuery" ) final boolean returnQuery)
{
+        super( entityIndexFactory, metricsFactory, indexLocationStrategyFactory, query, analyzeOnly,
returnQuery);
         this.collectionName = collectionName;
         this.entityType = entityType;
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchConnectionFilter.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchConnectionFilter.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchConnectionFilter.java
index 4a61120..4e8aed7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchConnectionFilter.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/read/search/SearchConnectionFilter.java
@@ -51,8 +51,9 @@ public class SearchConnectionFilter extends AbstractElasticSearchFilter
{
                                    @Assisted( "query" ) final String query,
                                    @Assisted( "connectionName" ) final String connectionName,
                                    @Assisted( "connectedEntityType" ) final Optional<String>
connectedEntityType,
-                                   @Assisted( "analyzeOnly") final boolean analyzeOnly) {
-        super( entityIndexFactory, metricsFactory, indexLocationStrategyFactory, query, analyzeOnly);
+                                   @Assisted( "analyzeOnly") final boolean analyzeOnly,
+                                   @Assisted( "returnQuery" ) final boolean returnQuery)
{
+        super( entityIndexFactory, metricsFactory, indexLocationStrategyFactory, query, analyzeOnly,
returnQuery);
 
         this.connectionName = connectionName;
         this.connectedEntityType = connectedEntityType;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/CollectionSearch.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/CollectionSearch.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/CollectionSearch.java
index 6b6edfc..3cbbf14 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/CollectionSearch.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/CollectionSearch.java
@@ -42,6 +42,7 @@ public class CollectionSearch {
     private final Optional<String> cursor;
     private Level level = Level.ALL;
     private boolean analyzeOnly;
+    private boolean returnQuery;
     private boolean keepStaleEntries;
 
 
@@ -56,6 +57,7 @@ public class CollectionSearch {
         this.query = query;
         this.cursor = cursor;
         this.analyzeOnly = false;
+        this.returnQuery = false;
     }
 
 
@@ -105,6 +107,14 @@ public class CollectionSearch {
         this.analyzeOnly = analyzeOnly;
     }
 
+    public boolean getReturnQuery() {
+        return returnQuery;
+    }
+
+    public void setReturnQuery(final boolean returnQuery) {
+        this.returnQuery = returnQuery;
+    }
+
     public boolean getKeepStaleEntries() {
         return keepStaleEntries;
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionSearch.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionSearch.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionSearch.java
index 98f36be..c7a563a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionSearch.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionSearch.java
@@ -38,6 +38,7 @@ public class ConnectionSearch {
     private final Optional<String> cursor;
     private final boolean isConnecting;
     private boolean analyzeOnly;
+    private boolean returnQuery;
 
 
 
@@ -53,6 +54,7 @@ public class ConnectionSearch {
         this.cursor = cursor;
         this.isConnecting = isConnecting;
         this.analyzeOnly = false;
+        this.returnQuery = false;
 
     }
 
@@ -102,4 +104,12 @@ public class ConnectionSearch {
     public void setAnalyzeOnly(final boolean analyzeOnly){
         this.analyzeOnly = analyzeOnly;
     }
+
+    public boolean getReturnQuery() {
+        return returnQuery;
+    }
+
+    public void setReturnQuery(final boolean returnQuery) {
+        this.returnQuery = returnQuery;
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionServiceImpl.java
index 7c70a3d..259e4b9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ConnectionServiceImpl.java
@@ -106,7 +106,8 @@ public class ConnectionServiceImpl implements ConnectionService {
         else {
 
             results =
-                pipelineBuilder.searchConnection( search.getConnectionName(), query.get(),
search.getEntityType(), search.getAnalyzeOnly() )
+                pipelineBuilder.searchConnection( search.getConnectionName(), query.get(),
search.getEntityType(),
+                    search.getAnalyzeOnly(), search.getReturnQuery() )
                                .loadEntities();
         }
 
@@ -135,7 +136,8 @@ public class ConnectionServiceImpl implements ConnectionService {
         }
         else {
             traversedIds =
-                pipelineBuilder.searchConnection( connectionName, query.get(), search.getEntityType(),
search.getAnalyzeOnly() ).loadIds();
+                pipelineBuilder.searchConnection( connectionName, query.get(), search.getEntityType(),
+                    search.getAnalyzeOnly(), search.getReturnQuery() ).loadIds();
         }
 
         //create connection refs

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/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 4c9d16c..034bc10 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
@@ -82,6 +82,7 @@ public class Query {
     private String ql;
     private Collection<SelectFieldMapping> selectFields;
     private boolean analyzeOnly = false;
+    private boolean returnQuery = false;
 
 
     private static ObjectMapper mapper = new ObjectMapper();
@@ -125,7 +126,7 @@ public class Query {
         collection = q.collection;
         level = q.level;
         analyzeOnly = q.analyzeOnly;
-
+        returnQuery = q.returnQuery;
     }
 
 
@@ -506,6 +507,14 @@ public class Query {
         return analyzeOnly;
     }
 
+    public void setReturnQuery(final boolean returnQuery) {
+        this.returnQuery = returnQuery;
+    }
+
+    public boolean getReturnQuery() {
+        return returnQuery;
+    }
+
     public boolean isMergeSelectResults() {
         return mergeSelectResults;
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index 437f9bf..afcfdd7 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -121,6 +121,25 @@ public interface EntityIndex extends CPManager {
                             final int limit, final int offset, final Map<String, Class>
fieldsWithType,
                             final boolean analyzeOnly);
 
+    /**
+     * Search on every document in the specified search edge.  Also search by the types if
specified
+     *
+     * @param searchEdge        The edge to search on
+     * @param searchTypes       The search types to search
+     * @param query             The query to execute
+     * @param limit             The limit of values to return
+     * @param offset            The offset to query on
+     * @param fieldsWithType    An optional param that allows the caller to provide schema
related info which might
+     *                          relate to data in the query, such as sort predicate types
+     * @param analyzeOnly       This optional param will instruct the query processing to
only analyze the query and
+     *                          provide info but not actually execute the query.
+     * @param returnQuery       This optional param will cause the index query to be returned
instead of run.
+     * @return
+     */
+    CandidateResults search(final SearchEdge searchEdge, final SearchTypes searchTypes, final
String query,
+                            final int limit, final int offset, final Map<String, Class>
fieldsWithType,
+                            final boolean analyzeOnly, final boolean returnQuery);
+
 
     /**
      * Same as search, just iterates all documents that match the index edge exactly.

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryReturnException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryReturnException.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryReturnException.java
new file mode 100644
index 0000000..54d9455
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/QueryReturnException.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.exceptions;
+
+
+import java.util.UUID;
+
+public class QueryReturnException extends RuntimeException {
+
+    private String originalQuery;
+    private String indexQuery;
+    private UUID applicationUUID;
+
+    public QueryReturnException(final String originalQuery, final String indexQuery,
+                                final UUID applicationUUID) {
+        super("Return Query");
+        this.originalQuery = originalQuery;
+        this.indexQuery = indexQuery;
+        this.applicationUUID = applicationUUID;
+    }
+
+    public String getOriginalQuery(){
+        return originalQuery;
+    }
+    public String getIndexQuery(){
+        return indexQuery;
+    }
+
+    public UUID getApplicationUUID(){
+        return applicationUUID;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 211cf70..e3121e1 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -39,6 +39,7 @@ import org.apache.usergrid.persistence.index.ElasticSearchQueryBuilder.SearchReq
 import org.apache.usergrid.persistence.index.exceptions.IndexException;
 import org.apache.usergrid.persistence.index.exceptions.QueryAnalyzerException;
 import org.apache.usergrid.persistence.index.exceptions.QueryAnalyzerEnforcementException;
+import org.apache.usergrid.persistence.index.exceptions.QueryReturnException;
 import org.apache.usergrid.persistence.index.migration.IndexDataVersions;
 import org.apache.usergrid.persistence.index.query.ParsedQuery;
 import org.apache.usergrid.persistence.index.query.ParsedQueryBuilder;
@@ -430,6 +431,12 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
     public CandidateResults search( final SearchEdge searchEdge, final SearchTypes searchTypes,
final String query,
                                     final int limit, final int offset, final Map<String,
Class> fieldsWithType,
                                     final boolean analyzeOnly ) {
+        return search(searchEdge, searchTypes, query, limit, offset, fieldsWithType, analyzeOnly,
false);
+    }
+
+    public CandidateResults search( final SearchEdge searchEdge, final SearchTypes searchTypes,
final String query,
+                                    final int limit, final int offset, final Map<String,
Class> fieldsWithType,
+                                    final boolean analyzeOnly, final boolean returnQuery
) {
 
         IndexValidationUtils.validateSearchEdge(searchEdge);
         Preconditions.checkNotNull(searchTypes, "searchTypes cannot be null");
@@ -453,7 +460,6 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
             hasGeoSortPredicates = visitor.getGeoSorts().contains(sortPredicate.getPropertyName());
         }
 
-
         final String cacheKey = applicationScope.getApplication().getUuid().toString()+"_"+searchEdge.getEdgeName();
         final Object totalEdgeSizeFromCache = sizeCache.getIfPresent(cacheKey);
         long totalEdgeSizeInBytes;
@@ -494,6 +500,10 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
                 searchTypes.getTypeNames( applicationScope ), srb );
         }
 
+        if (returnQuery) {
+            throw new QueryReturnException(parsedQuery.getOriginalQuery(), srb.toString(),
applicationScope.getApplication().getUuid());
+        }
+
         //Added For Graphite Metrics
         final Timer.Context timerContext = searchTimer.time();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index 9373f5e..9fc5457 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -34,6 +34,7 @@ import org.apache.usergrid.rest.RootResource;
 import org.apache.usergrid.rest.applications.assets.AssetsResource;
 import org.apache.usergrid.rest.security.annotations.CheckPermissionsForPath;
 import org.apache.usergrid.security.oauth.AccessInfo;
+import org.apache.usergrid.security.shiro.utils.SubjectUtils;
 import org.apache.usergrid.services.*;
 import org.apache.usergrid.services.assets.BinaryStoreFactory;
 import org.apache.usergrid.services.assets.data.*;
@@ -50,6 +51,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
+import javax.security.auth.Subject;
 import javax.ws.rs.*;
 import javax.ws.rs.core.*;
 import java.io.InputStream;
@@ -245,7 +247,7 @@ public class ServiceResource extends AbstractContextResource {
         addQueryParams( getServiceParameters(), ui );
 
         ServiceRequest r = services.newRequest( action, tree, getServiceParameters(), payload,
-            returnInboundConnections, returnOutboundConnections, false);
+            returnInboundConnections, returnOutboundConnections, false, false);
 
         response.setServiceRequest( r );
 
@@ -299,7 +301,7 @@ public class ServiceResource extends AbstractContextResource {
         addQueryParams( getServiceParameters(), ui );
 
         ServiceRequest r = services.newRequest( action, tree, getServiceParameters(), payload,
-            returnInboundConnections, returnOutboundConnections, false);
+            returnInboundConnections, returnOutboundConnections, false, false);
 
         response.setServiceRequest( r );
 
@@ -384,6 +386,11 @@ public class ServiceResource extends AbstractContextResource {
         }
 
         boolean analyzeQueryOnly = Boolean.valueOf(ui.getQueryParameters().getFirst("analyzeOnly"));
+        boolean returnQuery = false;
+        // currently only allow query return if service admin
+        if (SubjectUtils.isServiceAdmin()) {
+            returnQuery = Boolean.valueOf(ui.getQueryParameters().getFirst("returnQuery"));
+        }
 
         boolean collectionGet = false;
         if ( action == ServiceAction.GET ) {
@@ -391,7 +398,7 @@ public class ServiceResource extends AbstractContextResource {
         }
         addQueryParams( getServiceParameters(), ui );
         ServiceRequest r = services.newRequest( action, tree, getServiceParameters(), payload,
-            returnInboundConnections, returnOutboundConnections, analyzeQueryOnly);
+            returnInboundConnections, returnOutboundConnections, analyzeQueryOnly, returnQuery);
         response.setServiceRequest( r );
         ServiceResults results = r.execute();
         if ( results != null ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/QueryReturnExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/QueryReturnExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/QueryReturnExceptionMapper.java
new file mode 100644
index 0000000..875e17e
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/QueryReturnExceptionMapper.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest.exceptions;
+
+
+import org.apache.usergrid.persistence.index.exceptions.QueryReturnException;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+
+@Provider
+public class QueryReturnExceptionMapper extends AbstractExceptionMapper<QueryReturnException>
{
+
+    // returns query as JSON with 200 response
+
+    @Override
+    public Response toResponse( QueryReturnException e ) {
+        return toResponse(200, e.getIndexQuery());
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
index f60bfdd..60a79e5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
@@ -29,7 +29,6 @@ import org.apache.usergrid.persistence.cache.CacheFactory;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.core.metrics.ObservableTimer;
 import org.apache.usergrid.persistence.core.rx.RxTaskScheduler;
-import org.apache.usergrid.persistence.index.exceptions.QueryAnalyzerException;
 import org.apache.usergrid.security.shiro.utils.LocalShiroCache;
 import org.apache.usergrid.security.shiro.utils.SubjectUtils;
 import org.apache.usergrid.services.ServiceParameter.IdParameter;
@@ -688,6 +687,7 @@ public abstract class AbstractService implements Service {
         }
         else if ( query != null ) {
             query.setAnalyzeOnly(request.isAnalyzeQueryOnly());
+            query.setReturnQuery(request.shouldReturnQuery());
             return new ServiceContext( this, action, request, previousResults, owner, collectionName,
query, parameters,
                     payload );
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
index 075278f..7e0cf07 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
@@ -357,13 +357,13 @@ public class ServiceManager {
 
 
     public ServiceRequest newRequest( ServiceAction action, List<ServiceParameter>
parameters ) throws Exception {
-        return newRequest( action, false, parameters, null, true, true, false);
+        return newRequest( action, false, parameters, null, true, true, false, false);
     }
 
 
     public ServiceRequest newRequest( ServiceAction action, List<ServiceParameter>
parameters, ServicePayload payload )
             throws Exception {
-        return newRequest( action, false, parameters, payload, true, true, false);
+        return newRequest( action, false, parameters, payload, true, true, false, false);
     }
 
 
@@ -382,7 +382,8 @@ public class ServiceManager {
 
     public ServiceRequest newRequest(ServiceAction action, boolean returnsTree, List<ServiceParameter>
parameters,
                                      ServicePayload payload, boolean returnsInboundConnections,
-                                     boolean returnsOutboundConnections, boolean analyzeQueryOnly)
throws Exception {
+                                     boolean returnsOutboundConnections, boolean analyzeQueryOnly,
+                                     boolean returnQuery) throws Exception {
 
         if ( em != null ) {
             if ( action != null ) {
@@ -413,12 +414,12 @@ public class ServiceManager {
 
         String serviceName = pluralize( ServiceParameter.dequeueParameter( parameters ).getName()
);
         return new ServiceRequest( this, action, serviceName, parameters, payload, returnsTree,
-            returnsInboundConnections, returnsOutboundConnections, analyzeQueryOnly);
+            returnsInboundConnections, returnsOutboundConnections, analyzeQueryOnly, returnQuery);
     }
 
     public ServiceRequest newRequest( ServiceAction action, boolean returnsTree, List<ServiceParameter>
parameters,
                                       ServicePayload payload ) throws Exception {
-        return newRequest( action, returnsTree, parameters, payload, true, true, false);
+        return newRequest( action, returnsTree, parameters, payload, true, true, false, false);
     }
 
     public void notifyExecutionEventListeners( ServiceAction action, ServiceRequest request,
ServiceResults results,

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bd2385d7/stack/services/src/main/java/org/apache/usergrid/services/ServiceRequest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceRequest.java
b/stack/services/src/main/java/org/apache/usergrid/services/ServiceRequest.java
index 89f4976..f0f3227 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceRequest.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceRequest.java
@@ -60,13 +60,15 @@ public class ServiceRequest {
     private final ServicePayload payload;
     private final List<ServiceParameter> originalParameters;
     private final boolean analyzeQueryOnly;
+    private final boolean returnQuery;
 
     // return results_set, result_entity, new_service, param_list, properties
 
 
     public ServiceRequest(ServiceManager services, ServiceAction action, String serviceName,
                           List<ServiceParameter> parameters, ServicePayload payload,
boolean returnsTree,
-                          boolean returnsInboundConnections, boolean returnsOutboundConnections,
boolean analyzeQueryOnly) {
+                          boolean returnsInboundConnections, boolean returnsOutboundConnections,
+                          boolean analyzeQueryOnly, boolean returnQuery) {
         this.services = services;
         this.action = action;
         parent = null;
@@ -80,6 +82,7 @@ public class ServiceRequest {
         this.returnsInboundConnections = returnsInboundConnections;
         this.returnsOutboundConnections = returnsOutboundConnections;
         this.analyzeQueryOnly = analyzeQueryOnly;
+        this.returnQuery = returnQuery;
         if ( payload == null ) {
             payload = new ServicePayload();
         }
@@ -89,13 +92,13 @@ public class ServiceRequest {
 
     public ServiceRequest( ServiceManager services, ServiceAction action, String serviceName,
                            List<ServiceParameter> parameters, ServicePayload payload,
boolean returnsTree) {
-        this( services, action, serviceName, parameters, payload, returnsTree, true, true,
false);
+        this( services, action, serviceName, parameters, payload, returnsTree, true, true,
false, false);
     }
 
 
     public ServiceRequest( ServiceManager services, ServiceAction action, String serviceName,
                            List<ServiceParameter> parameters, ServicePayload payload
) {
-        this( services, action, serviceName, parameters, payload, false, true, true, false);
+        this( services, action, serviceName, parameters, payload, false, true, true, false,
false);
     }
 
 
@@ -106,6 +109,7 @@ public class ServiceRequest {
         this.returnsInboundConnections = parent.returnsInboundConnections;
         this.returnsOutboundConnections = parent.returnsOutboundConnections;
         this.analyzeQueryOnly = parent.analyzeQueryOnly;
+        this.returnQuery = parent.returnQuery;
         this.action = parent.action;
         this.payload = parent.payload;
         this.parent = parent;
@@ -124,7 +128,8 @@ public class ServiceRequest {
     public ServiceRequest( ServiceManager services, ServiceAction action, ServiceRequest
parent, EntityRef owner,
                            String path, String childPath, String serviceName, List<ServiceParameter>
parameters,
                            ServicePayload payload, boolean returnsTree, boolean returnsInboundConnections,
-                           boolean returnsOutboundConnections, boolean analyzeQueryOnly )
{
+                           boolean returnsOutboundConnections, boolean analyzeQueryOnly,
+                           boolean returnQuery) {
         this.services = services;
         this.action = action;
         this.parent = parent;
@@ -138,25 +143,29 @@ public class ServiceRequest {
         this.returnsInboundConnections = returnsInboundConnections;
         this.returnsOutboundConnections = returnsOutboundConnections;
         this.analyzeQueryOnly = analyzeQueryOnly;
+        this.returnQuery = returnQuery;
         this.payload = payload;
     }
 
     public ServiceRequest( ServiceManager services, ServiceAction action, ServiceRequest
parent, EntityRef owner,
                            String path, String childPath, String serviceName, List<ServiceParameter>
parameters,
                            ServicePayload payload, boolean returnsTree ) {
-        this(services, action, parent, owner, path, childPath, serviceName, parameters, payload,
returnsTree, true, true, false);
+        this(services, action, parent, owner, path, childPath, serviceName, parameters, payload,
returnsTree,
+            true, true, false, false);
     }
 
 
     public static ServiceRequest withPath( ServiceRequest r, String path ) {
         return new ServiceRequest( r.services, r.action, r.parent, r.owner, path, r.childPath,
r.serviceName,
-                r.parameters, r.payload, r.returnsTree, r.returnsInboundConnections, r.returnsOutboundConnections,
r.analyzeQueryOnly );
+            r.parameters, r.payload, r.returnsTree, r.returnsInboundConnections, r.returnsOutboundConnections,
+            r.analyzeQueryOnly, r.returnQuery);
     }
 
 
     public static ServiceRequest withChildPath( ServiceRequest r, String childPath ) {
         return new ServiceRequest( r.services, r.action, r.parent, r.owner, r.path, childPath,
r.serviceName,
-                r.parameters, r.payload, r.returnsTree, r.returnsInboundConnections, r.returnsOutboundConnections,
r.analyzeQueryOnly );
+            r.parameters, r.payload, r.returnsTree, r.returnsInboundConnections, r.returnsOutboundConnections,
+            r.analyzeQueryOnly, r.returnQuery);
     }
 
 
@@ -398,4 +407,8 @@ public class ServiceRequest {
     public boolean isAnalyzeQueryOnly(){
         return analyzeQueryOnly;
     }
+
+    public boolean shouldReturnQuery(){
+        return returnQuery;
+    }
 }


Mime
View raw message