You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2016/04/08 22:20:50 UTC

[03/36] usergrid git commit: Cherry picking 2 more commits with the working selective indexing but improperly

Cherry picking 2 more commits with the working selective indexing but improperly


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

Branch: refs/heads/release-2.1.1
Commit: 99c75ccd6ca16f93e3be934e5f1c5455d6e375c5
Parents: 58e6cf3
Author: George Reyes <gr...@apache.org>
Authored: Wed Mar 9 12:18:36 2016 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Thu Mar 24 09:06:42 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  21 +-
 .../usergrid/persistence/EntityManager.java     |   2 +-
 .../rest/applications/ApplicationResource.java  |   2 +-
 .../rest/applications/CollectionResource.java   | 199 +++++++++++++++++++
 .../rest/applications/ServiceResource.java      | 142 ++++++-------
 .../collection/CollectionsResourceIT.java       |  13 +-
 .../services/AbstractCollectionService.java     |  23 ++-
 .../services/AbstractConnectionsService.java    |  10 +-
 .../usergrid/services/AbstractService.java      |  12 +-
 .../org/apache/usergrid/services/Service.java   |   3 +
 .../usergrid/services/ServiceRequest.java       |   5 +
 .../applications/ApplicationsService.java       |  11 +-
 12 files changed, 338 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/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 6a6d036..d5ba946 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
@@ -1754,27 +1754,32 @@ public class CpEntityManager implements EntityManager {
         schemaMap.put("lastReindexed",0);
         schemaMap.putAll( properties );
 
-        //Map<String,Object> fields = properties.get( "properties" );
-
-        //for(Object)
-
         MapManager mm = getMapManagerForTypes();
-        mm.putString( collectionName,schemaMap.toString() );
+        mm.putString( collectionName,JsonUtils.mapToJsonString( schemaMap ) );
 
         return schemaMap;
 
     }
 
     @Override
-    public Entity createCollectionSchema( String collectionName ){
+    public Object getCollectionSchema( String collectionName ){
         MapManager mm = getMapManagerForTypes();
         String jsonMap = mm.getString( collectionName );
 
         Object obj = JsonUtils.parse( jsonMap );
-
-        return null;
+        return obj;
     }
 
+//    @Override
+//    public Entity createCollectionSchema( String collectionName ){
+//        MapManager mm = getMapManagerForTypes();
+//        String jsonMap = mm.getString( collectionName );
+//
+//        Object obj = JsonUtils.parse( jsonMap );
+//
+//        return null;
+//    }
+
 
         @Override
     public void grantRolePermission( String roleName, String permission ) throws Exception {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 7c5cc5b..13fb098 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -514,7 +514,7 @@ public interface EntityManager {
 
     public Map createCollectionSchema( String collectionName, String owner ,Map<String, Object> properties );
 
-    Entity createCollectionSchema( String collectionName );
+    Object getCollectionSchema( String collectionName );
 
     public void grantRolePermission( String roleName, String permission ) throws Exception;
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index f2d07e3..9836f1c 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -82,7 +82,7 @@ import static org.apache.usergrid.utils.StringUtils.stringOrSubstringBeforeFirst
         MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
         "application/ecmascript", "text/jscript"
 })
-public class ApplicationResource extends ServiceResource {
+public class ApplicationResource extends CollectionResource {
 
     public static final Logger logger = LoggerFactory.getLogger( ApplicationResource.class );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
new file mode 100644
index 0000000..856bce0
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
@@ -0,0 +1,199 @@
+/*
+ * 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.applications;
+
+
+import java.util.UUID;
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriInfo;
+
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.RootResource;
+import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
+import org.apache.usergrid.services.AbstractCollectionService;
+import org.apache.usergrid.services.ServiceAction;
+import org.apache.usergrid.services.ServiceParameter;
+import org.apache.usergrid.services.ServicePayload;
+
+import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
+
+
+/**
+ * A collection resource that stands before the Service Resource. If it cannot find
+ * the specified method then we should route the call to the service resource proper.
+ * Otherwise handle it in here.
+ */
+@Component
+@Scope("prototype")
+@Produces({
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
+})
+public class CollectionResource extends ServiceResource {
+
+    public CollectionResource() {
+    }
+
+    /**
+     * THE BEGINNINGS OF AN ENDPOINT THAT WILL ALLOW TO DEFINE WHAT TO
+     * STORE IN ELASTICSEARCH.
+     * @param ui
+     * @param callback
+     * @return
+     * @throws Exception
+     */
+    @POST
+    @Path("_indexes")
+    @Produces({ MediaType.APPLICATION_JSON,"application/javascript"})
+    @RequireApplicationAccess
+    @JSONP
+    public ApiResponse executePostOnIndexes( @Context UriInfo ui, String body,
+                                             @QueryParam("callback") @DefaultValue("callback") String callback )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.executePostOnIndexes" );
+        }
+
+        Object json;
+        if ( StringUtils.isEmpty( body ) ) {
+            json = null;
+        } else {
+            json = readJsonToObject( body );
+        }
+
+        ApiResponse response = createApiResponse();
+
+        response.setAction( "post" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
+
+        ServicePayload payload = getPayload( json );
+
+        executeServicePostRequestForSchema( ui,response, ServiceAction.POST,payload );
+
+        return response;
+    }
+
+    @GET
+    @Path("_index")
+    @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
+    @RequireApplicationAccess
+    @JSONP
+    public ApiResponse executeGetOnIndex( @Context UriInfo ui, String body,
+                                          @QueryParam("callback") @DefaultValue("callback") String callback )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "CollectionResource.executeGetOnIndex" );
+        }
+
+        Object json;
+        if ( StringUtils.isEmpty( body ) ) {
+            json = null;
+        } else {
+            json = readJsonToObject( body );
+        }
+
+        ApiResponse response = createApiResponse();
+
+
+
+        response.setAction( "get" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
+
+        executeServiceGetRequestForSchema( ui,response,ServiceAction.GET,null );
+
+        ///ServicePayload payload = getPayload( json );
+
+        ///emf.getEntityManager( getApplicationId() ).get
+
+        //executeServiceRequest( ui, response, ServiceAction.GET, payload );
+
+        return response;
+    }
+
+    @Override
+    @Path( RootResource.ENTITY_ID_PATH)
+    public AbstractContextResource addIdParameter( @Context UriInfo ui, @PathParam("entityId") PathSegment entityId )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.addIdParameter" );
+        }
+
+        UUID itemId = UUID.fromString( entityId.getPath() );
+
+        ServiceParameter.addParameter( getServiceParameters(), itemId );
+
+        addMatrixParams( getServiceParameters(), ui, entityId );
+
+        return getSubResource( CollectionResource.class );
+    }
+
+
+    @Override
+    @Path("{itemName}")
+    public AbstractContextResource addNameParameter( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName )
+        throws Exception {
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.addNameParameter" );
+            logger.trace( "Current segment is {}", itemName.getPath() );
+        }
+
+
+        if ( itemName.getPath().startsWith( "{" ) ) {
+            Query query = Query.fromJsonString( itemName.getPath() );
+            if ( query != null ) {
+                ServiceParameter.addParameter( getServiceParameters(), query );
+            }
+        }
+        else {
+            ServiceParameter.addParameter( getServiceParameters(), itemName.getPath() );
+        }
+
+        addMatrixParams( getServiceParameters(), ui, itemName );
+
+        return getSubResource( CollectionResource.class );
+    }
+
+//    @
+//    public ServiceResource doLogicInServiceResource() throws Exception{
+//        return getSubResource( ServiceResource.class );
+//    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/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 3318adf..c723366 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
@@ -244,7 +244,64 @@ public class ServiceResource extends AbstractContextResource {
         return getSubResource( ServiceResource.class );
     }
 
-    public ServiceResults executeServiceRequestForSchema(UriInfo ui, ApiResponse response, ServiceAction action,
+
+    public ServiceResults executeServiceGetRequestForSchema(UriInfo ui, ApiResponse response, ServiceAction action,
+                                                             ServicePayload payload) throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.executeServiceRequest" );
+        }
+
+
+        boolean tree = "true".equalsIgnoreCase( ui.getQueryParameters().getFirst( "tree" ) );
+
+        String connectionQueryParm = ui.getQueryParameters().getFirst("connections");
+        boolean returnInboundConnections = true;
+        boolean returnOutboundConnections = true;
+
+        addQueryParams( getServiceParameters(), ui );
+
+        ServiceRequest r = services.newRequest( action, tree, getServiceParameters(), payload,
+            returnInboundConnections, returnOutboundConnections );
+
+        response.setServiceRequest( r );
+
+
+        AbstractCollectionService abstractCollectionService = new AbstractCollectionService();
+
+       // abstractCollectionService
+        ServiceResults results = abstractCollectionService.getCollectionSchema( r );
+
+        //        ServiceResults results = r.execute();
+        if ( results != null ) {
+            if ( results.hasData() ) {
+                response.setData( results.getData() );
+            }
+            if ( results.getServiceMetadata() != null ) {
+                response.setMetadata( results.getServiceMetadata() );
+            }
+            Query query = r.getLastQuery();
+            if ( query != null ) {
+                if ( query.hasSelectSubjects() ) {
+                    response.setList( QueryUtils.getSelectionResults( query, results ) );
+                    response.setCount( response.getList().size() );
+                    response.setNext( results.getNextResult() );
+                    response.setPath( results.getPath() );
+                    return results;
+                }
+            }
+
+            response.setResults( results );
+        }
+
+        httpServletRequest.setAttribute( "applicationId", services.getApplicationId() );
+
+        return results;
+
+
+    }
+
+    public ServiceResults executeServicePostRequestForSchema(UriInfo ui, ApiResponse response, ServiceAction action,
                                                          ServicePayload payload) throws Exception {
 
         if(logger.isTraceEnabled()){
@@ -264,7 +321,13 @@ public class ServiceResource extends AbstractContextResource {
             returnInboundConnections, returnOutboundConnections );
 
         response.setServiceRequest( r );
-        ServiceResults results = r.execute();
+
+
+        AbstractCollectionService abstractCollectionService = new AbstractCollectionService();
+
+        ServiceResults results = abstractCollectionService.postCollectionSchema( r );
+
+//        ServiceResults results = r.execute();
         if ( results != null ) {
             if ( results.hasData() ) {
                 response.setData( results.getData() );
@@ -402,81 +465,6 @@ public class ServiceResource extends AbstractContextResource {
     }
 
 
-    /**
-     * THE BEGINNINGS OF AN ENDPOINT THAT WILL ALLOW TO DEFINE WHAT TO
-     * STORE IN ELASTICSEARCH.
-     * @param ui
-     * @param callback
-     * @return
-     * @throws Exception
-     */
-    @POST
-    @Path("_indexes")
-    @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
-    @RequireApplicationAccess
-    @JSONP
-    public ApiResponse executePostOnIndexes( @Context UriInfo ui, String body,
-                                   @QueryParam("callback") @DefaultValue("callback") String callback )
-        throws Exception {
-
-        if(logger.isTraceEnabled()){
-            logger.trace( "ServiceResource.executePostOnIndexes" );
-        }
-
-        Object json;
-        if ( StringUtils.isEmpty( body ) ) {
-            json = null;
-        } else {
-            json = readJsonToObject( body );
-        }
-
-        ApiResponse response = createApiResponse();
-
-        response.setAction( "post" );
-        response.setApplication( services.getApplication() );
-        response.setParams( ui.getQueryParameters() );
-
-        ServicePayload payload = getPayload( json );
-
-        executeServiceRequestForSchema( ui,response,ServiceAction.SCHEMA,payload );
-
-        return response;
-    }
-
-    @GET
-    @Path("_index")
-    @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
-    @RequireApplicationAccess
-    @JSONP
-    public ApiResponse executeGetOnIndex( @Context UriInfo ui, String body,
-                                             @QueryParam("callback") @DefaultValue("callback") String callback )
-        throws Exception {
-
-        if(logger.isTraceEnabled()){
-            logger.trace( "ServiceResource.executePostOnIndexes" );
-        }
-
-        Object json;
-        if ( StringUtils.isEmpty( body ) ) {
-            json = null;
-        } else {
-            json = readJsonToObject( body );
-        }
-
-        ApiResponse response = createApiResponse();
-
-
-
-        response.setAction( "get" );
-        response.setApplication( services.getApplication() );
-        response.setParams( ui.getQueryParameters() );
-
-        ServicePayload payload = getPayload( json );
-
-        executeServiceRequest( ui, response, ServiceAction.GET, payload );
-
-        return response;
-    }
 
 
     @SuppressWarnings({ "unchecked" })

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/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 773317b..cea9d5e 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
@@ -149,7 +149,7 @@ public class CollectionsResourceIT extends AbstractRestIT {
         payload.put( "fields", indexingArray);
 
         //Post index to the collection metadata
-        Object thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload );
+        Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload );
         refreshIndex();
 
         //Below is what needs to be implemented along with the index call above
@@ -157,12 +157,11 @@ public class CollectionsResourceIT extends AbstractRestIT {
         //Get the collection schema and verify that it contains the same schema as posted above.
         Collection collection = this.app().collection( "testCollection" ).collection( "_index" ).get();
 
-        Entity testCollectionSchema = (Entity)collection.getResponse().getEntity();
-        //the below will have to be replaced by the values that I deem correct.
-        assertEquals( "lastUpdated", testCollectionSchema.get( "lastUpdated" ));
-        assertEquals( "lastUpdatedBy",testCollectionSchema.get( "lastUpdatedBy" ) );
-        assertEquals( "lastReindex",testCollectionSchema.get( "lastReindex" ) );
-
+        LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData();
+        //TODO: the below will have to be replaced by the values that I deem correct.
+        assertEquals( ( thing ).get( "lastUpdated" ), testCollectionSchema.get( "lastUpdated" ));
+        assertEquals( ( thing ).get( "lastUpdateBy" ),testCollectionSchema.get( "lastUpdateBy" ) );
+        assertEquals( ( thing ).get( "lastReindexed" ),testCollectionSchema.get( "lastReindexed" ) );
 
         ArrayList<String> schema = ( ArrayList<String> ) testCollectionSchema.get( "fields" );
         assertEquals( "one",schema.get( 0 ) );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index f6d2849..4d73fa5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -55,6 +55,11 @@ public class AbstractCollectionService extends AbstractService {
         declareMetadataType( "indexes" );
     }
 
+    public AbstractCollectionService(ServiceRequest serviceRequest){
+        setServiceManager( serviceRequest.getServices() );
+    }
+
+
     @Override
     public Entity getEntity( ServiceRequest request, UUID uuid ) throws Exception {
         if ( !isRootService() ) {
@@ -324,7 +329,10 @@ public class AbstractCollectionService extends AbstractService {
     }
 
     @Override
-    public ServiceResults postCollectionSchema( ServiceContext context ) throws Exception {
+    public ServiceResults postCollectionSchema( ServiceRequest serviceRequest ) throws Exception {
+        setServiceManager( serviceRequest.getServices() );
+        ServiceContext context = serviceRequest.getAppContext();
+
         context.setAction( ServiceAction.POST );
         checkPermissionsForCollection( context );
         Subject currentUser = SubjectUtils.getSubject();
@@ -337,6 +345,19 @@ public class AbstractCollectionService extends AbstractService {
 
     }
 
+    @Override
+    public ServiceResults getCollectionSchema( ServiceRequest serviceRequest ) throws Exception {
+        setServiceManager( serviceRequest.getServices() );
+        ServiceContext context = serviceRequest.getAppContext();
+        context.setAction( ServiceAction.GET );
+        checkPermissionsForCollection( context );
+
+        Object collectionSchema = em.getCollectionSchema( context.getCollectionName() );
+
+        return new ServiceResults( this, context, Type.COLLECTION, Results.fromData( collectionSchema ), null, null );
+
+    }
+
 
     @Override
     public ServiceResults postCollection( ServiceContext context ) throws Exception {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
index 666f676..395f2d4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
@@ -392,8 +392,14 @@ public class AbstractConnectionsService extends AbstractService {
 
 
     @Override
-    public ServiceResults postCollectionSchema( final ServiceContext context ) throws Exception {
-        throw new UnsupportedServiceOperationException( context );
+    public ServiceResults postCollectionSchema( final ServiceRequest request ) throws Exception {
+        throw new UnsupportedServiceOperationException( request );
+    }
+
+
+    @Override
+    public ServiceResults getCollectionSchema( final ServiceRequest serviceRequest ) throws Exception {
+        throw new UnsupportedServiceOperationException( serviceRequest );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/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 3c5503c..7d33144 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
@@ -656,6 +656,7 @@ public abstract class AbstractService implements Service {
      * the queue. Remaining parameters are left for next service request to allow for request chaining.
      */
 
+    @Override
     public ServiceContext getContext( ServiceAction action, ServiceRequest request, ServiceResults previousResults,
                                       ServicePayload payload ) throws Exception {
 
@@ -828,9 +829,6 @@ public abstract class AbstractService implements Service {
 
             case HEAD:
                 return headCollection( context );
-
-            case SCHEMA:
-                return postCollectionSchema( context );
         }
 
         throw new ServiceInvocationException( context, "Request action unhandled " + context.getAction() );
@@ -891,8 +889,10 @@ public abstract class AbstractService implements Service {
         return getItemsByQuery( context, query );
     }
 
+    public abstract ServiceResults postCollectionSchema( ServiceRequest serviceRequest ) throws Exception;
+
 
-    public abstract ServiceResults postCollectionSchema( ServiceContext context ) throws Exception;
+    public abstract ServiceResults getCollectionSchema( ServiceRequest serviceRequest ) throws Exception;
 
 
     public ServiceResults postCollection( ServiceContext context ) throws Exception {
@@ -1366,8 +1366,8 @@ public abstract class AbstractService implements Service {
         if ( currentUser == null ) {
             return;
         }
-        String perm =
-                getPermissionFromPath( em.getApplicationRef().getUuid(), context.getAction().toString().toLowerCase(),
+        //this is breaking because there is no entity manager there.
+        String perm = getPermissionFromPath( em.getApplicationRef().getUuid(), context.getAction().toString().toLowerCase(),
                         path );
         boolean permitted = currentUser.isPermitted( perm );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/services/src/main/java/org/apache/usergrid/services/Service.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/Service.java b/stack/services/src/main/java/org/apache/usergrid/services/Service.java
index f463813..0a84dbf 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/Service.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/Service.java
@@ -47,4 +47,7 @@ public interface Service {
     public Entity writeEntity( ServiceRequest request, Entity entity ) throws Exception;
 
     public Entity updateEntity( ServiceRequest request, EntityRef ref, ServicePayload payload ) throws Exception;
+
+    ServiceContext getContext( ServiceAction action, ServiceRequest request, ServiceResults previousResults,
+                               ServicePayload payload ) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/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 2c95465..f8a5abb 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
@@ -236,6 +236,11 @@ public class ServiceRequest {
         return sb.toString();
     }
 
+    public ServiceContext getAppContext() throws Exception {
+        Service s = services.getService( serviceName );
+
+        return s.getContext( action,this,null,payload );
+    }
 
     public ServiceResults execute( ServiceResults previousResults ) throws Exception {
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/99c75ccd/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
index cf4aa80..0eef711 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
@@ -32,6 +32,7 @@ import org.apache.usergrid.services.AbstractService;
 import org.apache.usergrid.services.ServiceContext;
 import org.apache.usergrid.services.ServiceParameter.QueryParameter;
 import org.apache.usergrid.services.ServicePayload;
+import org.apache.usergrid.services.ServiceRequest;
 import org.apache.usergrid.services.ServiceResults;
 import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
@@ -95,8 +96,14 @@ public class ApplicationsService extends AbstractService {
 
 
     @Override
-    public ServiceResults postCollectionSchema( final ServiceContext context ) throws Exception {
-        throw new UnsupportedServiceOperationException( context );
+    public ServiceResults postCollectionSchema( final ServiceRequest request ) throws Exception {
+        throw new UnsupportedServiceOperationException( request );
+    }
+
+
+    @Override
+    public ServiceResults getCollectionSchema( final ServiceRequest serviceRequest ) throws Exception {
+        throw new UnsupportedServiceOperationException( serviceRequest );
     }