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:21:05 UTC

[18/36] usergrid git commit: Simplified the CollectionResource and remove recursive call based on serviceResource wonkiness

Simplified the CollectionResource and remove recursive call based on serviceResource wonkiness


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

Branch: refs/heads/release-2.1.1
Commit: 0e53dcf118c71a7d9e496f62372ade25ca9a597d
Parents: b5d81ac
Author: George Reyes <gr...@apache.org>
Authored: Tue Mar 29 15:46:44 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Tue Mar 29 15:46:44 2016 -0700

----------------------------------------------------------------------
 .../rest/applications/CollectionResource.java   | 82 ++++++++------------
 1 file changed, 31 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/0e53dcf1/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
index fb660fa..8f4bdf0 100644
--- 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
@@ -82,12 +82,13 @@ public class CollectionResource extends ServiceResource {
      * @throws Exception
      */
     @POST
-    @Path("_indexes")
+    @Path( "{itemName}/_indexes" )
     @Produces({ MediaType.APPLICATION_JSON,"application/javascript"})
     @RequireApplicationAccess
     @JSONP
-    public ApiResponse executePostOnIndexes( @Context UriInfo ui, String body,
-                                             @QueryParam("callback") @DefaultValue("callback") String callback )
+    public ApiResponse executePostOnIndexesWithCollectionName( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName,
+                                                               String body,
+                                                               @QueryParam("callback") @DefaultValue("callback") String callback )
         throws Exception {
 
         if(logger.isTraceEnabled()){
@@ -96,6 +97,7 @@ public class CollectionResource extends ServiceResource {
         /**
 
          */
+        addItemToServiceContext( ui, itemName );
 
         Object json;
         if ( StringUtils.isEmpty( body ) ) {
@@ -117,12 +119,29 @@ public class CollectionResource extends ServiceResource {
         return response;
     }
 
+
+    private void addItemToServiceContext( final @Context UriInfo ui,
+                                          final @PathParam( "itemName" ) PathSegment itemName ) throws Exception {
+        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 );
+    }
+
+
     @GET
-    @Path("_index")
+    @Path( "{itemName}/_index")
     @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
     @RequireApplicationAccess
     @JSONP
-    public ApiResponse executeGetOnIndex( @Context UriInfo ui,
+    public ApiResponse executeGetOnIndex( @Context UriInfo ui,@PathParam("itemName") PathSegment itemName,
                                           @QueryParam("callback") @DefaultValue("callback") String callback )
         throws Exception {
 
@@ -130,6 +149,8 @@ public class CollectionResource extends ServiceResource {
             logger.trace( "CollectionResource.executeGetOnIndex" );
         }
 
+        addItemToServiceContext( ui, itemName );
+
         ApiResponse response = createApiResponse();
         response.setAction( "get" );
         response.setApplication( services.getApplication() );
@@ -140,17 +161,21 @@ public class CollectionResource extends ServiceResource {
         return response;
     }
 
+
     //TODO: this can't be controlled and until it can be controlled we should allow muggles to do this. So system access only.
     //TODO: use scheduler here to get around people sending a reindex call 30 times.
     @POST
-    @Path("_reindex")
+    @Path("{itemName}/_reindex")
     @Produces({ MediaType.APPLICATION_JSON,"application/javascript"})
     @RequireSystemAccess
     @JSONP
     public ApiResponse executePostForReindexing( @Context UriInfo ui, String body,
+                                                 @PathParam("itemName") PathSegment itemName,
                                              @QueryParam("callback") @DefaultValue("callback") String callback )
         throws Exception {
 
+        addItemToServiceContext( ui, itemName );
+
         final ReIndexRequestBuilder request =
             createRequest().withApplicationId( services.getApplicationId() ).withCollection(
                 String.valueOf( getServiceParameters().get( 0 ) ) ).withDelay( 1, TimeUnit.SECONDS );
@@ -158,51 +183,6 @@ public class CollectionResource extends ServiceResource {
         return executeAndCreateResponse( request, callback );
     }
 
-    @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 );
-    }
-
-
-    //TODO: change this to {itemName}/_indexes and that should do what we already have. Then we don't have this overriden method.
-    @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 );
-    }
-
     private ReIndexService getReIndexService() {
         return injector.getInstance( ReIndexService.class );
     }