Repository: usergrid Updated Branches: refs/heads/master e83897bf6 -> 705891c13
Added a test to try to prove the issue with collections that you create. Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/12d344ff Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/12d344ff Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/12d344ff Branch: refs/heads/master Commit: 12d344ff44cee242f448e3738869aa21a9dfb3d5 Parents: 93b864f Author: George Reyes <[email protected]> Authored: Thu Feb 18 14:48:36 2016 -0800 Committer: George Reyes <[email protected]> Committed: Thu Feb 18 14:48:36 2016 -0800 ---------------------------------------------------------------------- .../corepersistence/CpEntityManager.java | 26 ++++++++++- .../applications/ApplicationResource.java | 27 +++++++---- .../rest/applications/ApplicationDeleteIT.java | 12 ++--- .../collection/CollectionsResourceIT.java | 49 ++++++++++++++++++++ 4 files changed, 97 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/12d344ff/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 6c2ef0b..d2f549b 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 @@ -745,7 +745,31 @@ public class CpEntityManager implements EntityManager { @Override public Set<String> getApplicationCollections() throws Exception { - return getRelationManager( getApplication() ).getCollections(); + Set<String> existingCollections = getRelationManager( getApplication() ).getCollections(); + + Set<String> dynamic_collections = cast( getDictionaryAsSet( getApplicationRef(), Schema.DICTIONARY_COLLECTIONS ) ); + if ( dynamic_collections != null ) { + for ( String collection : dynamic_collections ) { + if ( !Schema.isAssociatedEntityType( collection ) ) { + if(!existingCollections.contains( collection )) { + existingCollections.add( collection ); + } + } + } + } + Set<String> system_collections = Schema.getDefaultSchema().getCollectionNames( Application.ENTITY_TYPE ); + if ( system_collections != null ) { + for ( String collection : system_collections ) { + if ( !Schema.isAssociatedEntityType( collection ) ) { + if(!existingCollections.contains( collection )) { + existingCollections.add( collection ); + } + } + } + } + + return existingCollections; + } http://git-wip-us.apache.org/repos/asf/usergrid/blob/12d344ff/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java index fd137a0..61a7e0a 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java @@ -482,20 +482,27 @@ public class ApplicationResource extends AbstractContextResource { @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) public ApiResponse executeDelete( @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback, - @QueryParam("app_delete_confirm") String confirmDelete) throws Exception { + @QueryParam("application_identifier") String applicationConfirmedDelete) throws Exception { - if (!"confirm_delete_of_application_and_data".equals( confirmDelete ) ) { + //If the path uses name then expect name, otherwise if they use uuid then expect uuid. + if(application==null){ + if(!applicationId.toString().equals( applicationConfirmedDelete )){ + throw new IllegalArgumentException( + "Cannot delete application without supplying correct application id."); + } + } + else if (!application.getName().equals( applicationConfirmedDelete ) ) { throw new IllegalArgumentException( - "Cannot delete application without app_delete_confirm parameter"); + "Cannot delete application without supplying correct application name"); } - Properties props = management.getProperties(); - - // for now, only works in test mode - String testProp = ( String ) props.get( "usergrid.test" ); - if ( testProp == null || !Boolean.parseBoolean( testProp ) ) { - throw new UnsupportedRestOperationException("Test props not not functioning correctly."); - } +// Properties props = management.getProperties(); +// +// //for now, only works in test mode +// String testProp = ( String ) props.get( "usergrid.test" ); +// if ( testProp == null || !Boolean.parseBoolean( testProp ) ) { +// throw new UnsupportedRestOperationException("Test props not not functioning correctly."); +// } if ( applicationId == null ) { throw new IllegalArgumentException("Application ID not specified in request"); http://git-wip-us.apache.org/repos/asf/usergrid/blob/12d344ff/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java index d215256..7b4751d 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java @@ -84,7 +84,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { clientSetup.getRestClient().management().orgs() .org(orgName).apps().app(appToDeleteId.toString() ).getTarget() .queryParam("access_token", orgAdminToken.getAccessToken() ) - .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data") + .queryParam("application_identifier", appToDeleteId) .request() .delete(); @@ -175,7 +175,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { final Response response1 = clientSetup.getRestClient().management() .orgs().org( orgName ).apps().app( appToDeleteId.toString() ) .getTarget().queryParam( "access_token", orgAdminToken.getAccessToken() ) - .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" ) + .queryParam( "application_identifier", appToDeleteId ) .request() .delete(); Assert.assertEquals( "Error must be 404", 404, response1.getStatus() ); @@ -223,7 +223,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { clientSetup.getRestClient().management().orgs() .org( orgName ).apps().app( appToDeleteName ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ) - .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data") + .queryParam("application_identifier", appToDeleteName) .request() .delete(); @@ -303,7 +303,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { clientSetup.getRestClient().management().orgs() .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ) - .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data") + .queryParam("application_identifier", appToDeleteId) .request() .delete(); @@ -345,7 +345,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { clientSetup.getRestClient().management() .orgs().org( orgName ).apps().app( appToDeleteId.toString() ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ) - .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" ) + .queryParam( "application_identifier", appToDeleteId ) .request() .delete(); @@ -358,7 +358,7 @@ public class ApplicationDeleteIT extends AbstractRestIT { final Response response = clientSetup.getRestClient().management() .orgs().org( orgName ).apps().app( newAppId.toString() ).getTarget() .queryParam( "access_token", orgAdminToken.getAccessToken() ) - .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" ) + .queryParam( "application_identifier", newAppId ) .request() .delete(); http://git-wip-us.apache.org/repos/asf/usergrid/blob/12d344ff/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 48daba4..66c94ce 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 @@ -18,7 +18,11 @@ package org.apache.usergrid.rest.applications.collection; import com.fasterxml.jackson.databind.JsonNode; + +import org.apache.usergrid.persistence.Schema; +import org.apache.usergrid.persistence.entities.Application; import org.apache.usergrid.rest.test.resource.AbstractRestIT; +import org.apache.usergrid.rest.test.resource.model.ApiResponse; import org.apache.usergrid.rest.test.resource.model.Collection; import org.apache.usergrid.rest.test.resource.model.Entity; import org.apache.usergrid.rest.test.resource.model.QueryParameters; @@ -30,6 +34,10 @@ import org.slf4j.LoggerFactory; import javax.ws.rs.ClientErrorException; import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; import static org.junit.Assert.*; @@ -226,6 +234,47 @@ public class CollectionsResourceIT extends AbstractRestIT { } + @Test + public void testDefaultCollectionReturning() throws IOException { + + ApiResponse usersDefaultCollection = this.app().get(); + + LinkedHashMap collectionHashMap = ( LinkedHashMap ) usersDefaultCollection.getEntity().get( "metadata" ); + + //make sure you have all the other default collections once you have users in place. + Set<String> system_collections = Schema.getDefaultSchema().getCollectionNames( Application.ENTITY_TYPE ); + for(String collectionName : system_collections){ + assertNotSame( null,((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName )); + } + } + + @Test + public void testNewlyCreatedCollectionReturnWhenEmpty(){ + String collectionName = "testDefaultCollectionReturnings"; + + Map<String,Object> payload = new HashMap( ); + payload.put( "hello","test" ); + ApiResponse testEntity = this.app().collection( collectionName ).post( payload ); + + //Verify that the below collection actually does exist. + ApiResponse usersDefaultCollection = this.app().get(); + + LinkedHashMap collectionHashMap = ( LinkedHashMap ) usersDefaultCollection.getEntity().get( "metadata" ); + + assertNotSame( null,((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName.toLowerCase() )); + + this.refreshIndex(); + this.app().collection( collectionName ).entity( testEntity.getEntity().getUuid() ).delete(); + + + //Verify that the collection still exists despite deleting its only entity.) + usersDefaultCollection = this.app().get(); + + collectionHashMap = ( LinkedHashMap ) usersDefaultCollection.getEntity().get( "metadata" ); + + assertNotSame( null,((LinkedHashMap)(collectionHashMap.get( "collections" ))).get( collectionName )); + } + /** * Test to verify "name property returns twice in AppServices response" is fixed.
