usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [27/36] usergrid git commit: Added a delete test and a delete endpoint so that we can delete schema's
Date Fri, 08 Apr 2016 20:21:14 GMT
Added a delete test and a delete endpoint so that we can delete schema's


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

Branch: refs/heads/release-2.1.1
Commit: 956a6f5a552d2b627b0ac0547d40beed9712d416
Parents: f4769e6
Author: George Reyes <grey@apache.org>
Authored: Thu Mar 31 12:53:45 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Thu Mar 31 12:53:45 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  33 ++++-
 .../corepersistence/index/IndexSchemaCache.java |   2 +
 .../index/IndexSchemaCacheImpl.java             |   7 +-
 .../corepersistence/index/IndexServiceImpl.java |   4 +
 .../usergrid/persistence/EntityManager.java     |   2 +
 .../rest/applications/CollectionResource.java   |  35 ++++-
 .../collection/CollectionsResourceIT.java       | 142 +++++++++++++++++++
 7 files changed, 217 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/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 642b837..08204c9 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
@@ -51,6 +51,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
 
+import org.apache.avro.generic.GenericData;
+
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
 import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
@@ -1786,16 +1788,41 @@ public class CpEntityManager implements EntityManager {
         else {
             schemaMap.put( "lastReindexed", 0 );
         }
-        schemaMap.putAll( properties );
 
-        //TODO: we have to update then invalidate previous entry.
+
+        ArrayList<String> fieldProperties = ( ArrayList<String> ) properties.get(
"fields" );
+
+        //TODO: do tests for * , and now add put and delete.
+        if(fieldProperties.contains( "*" )){
+            ArrayList<String> wildCardArrayList = new ArrayList<>(  );
+            wildCardArrayList.add( "*" );
+            schemaMap.put( "fields",wildCardArrayList );
+        }
+        else {
+            schemaMap.putAll( properties );
+        }
+
+        //do a check to see if you have a * field. If you do have a * field then ignore all
other fields
+        //and only accept the * field. That logic goes below and in the put.
+
         indexSchemaCache.putCollectionSchema( collectionName, JsonUtils.mapToJsonString(
schemaMap ) );
-        
+
         return schemaMap;
 
     }
 
     @Override
+    public void deleteCollectionSchema( String collectionName ){
+        MapManager mm = getMapManagerForTypes();
+
+        IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
+
+        indexSchemaCache.deleteCollectionSchema( collectionName );
+
+    }
+
+
+    @Override
     public Object getCollectionSchema( String collectionName ){
         MapManager mm = getMapManagerForTypes();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
index 6fbe148..debfe2a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
@@ -31,6 +31,8 @@ public interface IndexSchemaCache {
 
     void putCollectionSchema( String collectionName, String collectionSchema );
 
+    void deleteCollectionSchema( String collectionName );
+
     /**
      * Evict the collection schema from the cache.
      * @param collectionName

http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
index 9e57480..14752b4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
@@ -80,11 +80,16 @@ public class IndexSchemaCacheImpl implements IndexSchemaCache {
     }
 
     @Override
-    public void putCollectionSchema(final String collectionName ,final String collectionSchema){
+    public void putCollectionSchema( final String collectionName, final String collectionSchema
){
         mapManager.putString( collectionName, collectionSchema );
         evictCollectionSchema( collectionName );
     }
 
+    @Override
+    public void deleteCollectionSchema(final String collectionName){
+        mapManager.delete( collectionName );
+        evictCollectionSchema( collectionName );
+    }
 
     @Override
     public void evictCollectionSchema( final String collectionName ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
index f931528..9e05df3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
@@ -229,6 +229,10 @@ public class IndexServiceImpl implements IndexService {
             defaultProperties = schema.getRequiredProperties( collectionName );
             fieldsToKeep = ( ArrayList ) jsonMapData.get( "fields" );
 
+            if(fieldsToKeep.contains( "*" )){
+                return Optional.empty();
+            }
+
             defaultProperties.addAll( fieldsToKeep );
         }
         else {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/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 f5b398a..ef96f10 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,6 +514,8 @@ public interface EntityManager {
 
     public Map createCollectionSchema( String collectionName, String owner ,Map<String,
Object> properties );
 
+    void deleteCollectionSchema( 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/956a6f5a/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 80ed36b..b097469 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
@@ -21,6 +21,7 @@ package org.apache.usergrid.rest.applications;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
+import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -94,9 +95,7 @@ public class CollectionResource extends ServiceResource {
         if(logger.isTraceEnabled()){
             logger.trace( "ServiceResource.executePostOnIndexes" );
         }
-        /**
 
-         */
         addItemToServiceContext( ui, itemName );
 
         Object json;
@@ -119,7 +118,6 @@ 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( "{" ) ) {
@@ -135,6 +133,35 @@ public class CollectionResource extends ServiceResource {
         addMatrixParams( getServiceParameters(), ui, itemName );
     }
 
+    @DELETE
+    @Path( "{itemName}/_indexes" )
+    @Produces({ MediaType.APPLICATION_JSON,"application/javascript"})
+    @RequireApplicationAccess
+    @JSONP
+    public ApiResponse executeDeleteOnIndexesWithCollectionName( @Context UriInfo ui, @PathParam("itemName")
PathSegment itemName,
+                                                               String body,
+                                                               @QueryParam("callback") @DefaultValue("callback")
String callback )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "CollectionResource.executeDeleteOnIndexesWithCollectionName" );
+        }
+
+        addItemToServiceContext( ui, itemName );
+
+        ApiResponse response = createApiResponse();
+
+        response.setAction( "delete" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
+
+
+        emf.getEntityManager( services.getApplicationId() ).deleteCollectionSchema( itemName.getPath().toLowerCase()
);
+
+        return response;
+    }
+
+
 
     @GET
     @Path( "{itemName}/_index")
@@ -162,7 +189,7 @@ public class CollectionResource extends ServiceResource {
     }
 
 
-    //TODO: this can't be controlled and until it can be controlled we should allow muggles
to do this. So system access only.
+    //TODO: this can't be controlled and until it can be controlled we shouldn' 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("{itemName}/_reindex")

http://git-wip-us.apache.org/repos/asf/usergrid/blob/956a6f5a/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 04ed18e..8ec4a3a 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
@@ -115,6 +115,148 @@ public class CollectionsResourceIT extends AbstractRestIT {
 
     }
 
+    @Test
+    public void deleteCollectionSchema() throws Exception {
+        //Creating schema.
+        //this could be changed to a hashmap.
+        ArrayList<String> indexingArray = new ArrayList<>(  );
+
+
+        //field "fields" is required.
+        Entity payload = new Entity();
+        payload.put( "fields", indexingArray);
+
+        //Post index to the collection metadata
+        Entity thing = this.app().collection( "testCollections" ).collection( "_indexes"
).post( payload );
+        refreshIndex();
+
+
+        //The above verifies the test case.
+
+
+        //Create test collection with a test entity that is partially indexed.
+        Entity testEntity = new Entity();
+        testEntity.put( "one", "helper" );
+        testEntity.put( "two","query" );
+
+        //Post entity.
+        Entity postedEntity = this.app().collection( "testCollections" ).post( testEntity
);
+        refreshIndex();
+
+        //Do a query to see if you can find the indexed query.
+        String query = "two ='query'";
+        QueryParameters queryParameters = new QueryParameters().setQuery(query);
+
+        //having a name breaks it. Need to get rid of the stack trace and also
+        Collection tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals( 0,tempEntity.getResponse().getEntities().size() );
+
+        //Verify if you can query on an entity that was not indexed and that no entities
are returned.
+        query = "one = 'helper'";
+        queryParameters = new QueryParameters().setQuery(query);
+        tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals(0,tempEntity.getResponse().getEntities().size());
+
+        query = "uuid = "+postedEntity.getUuid().toString();
+        queryParameters = new QueryParameters().setQuery(query);
+        tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals(1,tempEntity.getResponse().getEntities().size());
+
+        //since the collection schema doesn't index anything it shouldn't show up except
for the default properties
+        //to prove that the entity exists
+
+        //next part is to delete the schema then reindex it and it should work.
+        this.app().collection( "testCollections" ).collection( "_indexes" ).delete();
+        refreshIndex();
+
+        this.app().collection( "testCollections" ).collection( "_reindex" ).post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
+        refreshIndex();
+
+
+        //Do a query to see if you can find the indexed query.
+        query = "two ='query'";
+        queryParameters = new QueryParameters().setQuery(query);
+
+        //having a name breaks it. Need to get rid of the stack trace and also
+        tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals( 1,tempEntity.getResponse().getEntities().size() );
+
+        //Verify if you can query on an entity that was not indexed and that no entities
are returned.
+        query = "one = 'helper'";
+        queryParameters = new QueryParameters().setQuery(query);
+        tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals(1,tempEntity.getResponse().getEntities().size());
+
+        query = "uuid = "+postedEntity.getUuid().toString();
+        queryParameters = new QueryParameters().setQuery(query);
+        tempEntity = this.app().collection( "testCollections" ).get(queryParameters,true);
+        assertEquals(1,tempEntity.getResponse().getEntities().size());
+
+    }
+
+    @Test
+    public void putCollectionSchema() throws Exception {
+
+
+    }
+
+
+    @Test
+    public void postCollectionSchemaWithWildcardIndexAll() throws Exception {
+        //Creating schema.
+        //this could be changed to a hashmap.
+        ArrayList<String> indexingArray = new ArrayList<>(  );
+        indexingArray.add( "*" );
+        indexingArray.add( "one" );
+        indexingArray.add( "two" );
+
+
+        //field "fields" is required.
+        Entity payload = new Entity();
+        payload.put( "fields", indexingArray);
+
+        //Post index to the collection metadata
+        Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post(
payload );
+        refreshIndex();
+
+
+        Collection collection = this.app().collection( "testCollection" ).collection( "_index"
).get();
+
+        LinkedHashMap testCollectionSchema = (LinkedHashMap)collection.getResponse().getData();
+        ArrayList<String> schema = ( ArrayList<String> ) testCollectionSchema.get(
"fields" );
+        assertTrue( schema.contains( "*" ) );
+        assertFalse( schema.contains( "one" ) );
+        assertFalse( schema.contains( "two" ) );
+
+
+//The above verifies the test case.
+
+
+        //Create test collection with a test entity that is partially indexed.
+        Entity testEntity = new Entity();
+        testEntity.put( "one", "helper" );
+        testEntity.put( "two","query" );
+
+        //Post entity.
+        this.app().collection( "testCollection" ).post( testEntity );
+        refreshIndex();
+
+        //Do a query to see if you can find the indexed query.
+        String query = "two ='query'";
+        QueryParameters queryParameters = new QueryParameters().setQuery(query);
+
+        //having a name breaks it. Need to get rid of the stack trace and also
+        Collection tempEntity = this.app().collection( "testCollection" ).get(queryParameters,true);
+        Entity reindexedEntity = tempEntity.getResponse().getEntity();
+        assertEquals( "helper",reindexedEntity.get( "one" ) );
+
+        //Verify if you can query on an entity that was not indexed and that no entities
are returned.
+        query = "one = 'helper'";
+        queryParameters = new QueryParameters().setQuery(query);
+        tempEntity = this.app().collection( "testCollection" ).get(queryParameters,true);
+        assertEquals(1,tempEntity.getResponse().getEntities().size());
+    }
+
 
     /**
      * Create test collection


Mime
View raw message