You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/04 05:21:31 UTC
git commit: Removed OAuthResponse to simplify code. Created test for
new error checking in ExportInfo.
Repository: incubator-usergrid
Updated Branches:
refs/pull/60/head a09dc39d8 -> e965147bf
Removed OAuthResponse to simplify code.
Created test for new error checking in ExportInfo.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e965147b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e965147b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e965147b
Branch: refs/pull/60/head
Commit: e965147bfdd87e9411be361a7d63978948cbb8d1
Parents: a09dc39
Author: grey <gr...@apigee.com>
Authored: Mon Mar 3 20:10:10 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Mar 3 20:10:10 2014 -0800
----------------------------------------------------------------------
.../applications/ApplicationResource.java | 30 +++++---------------
.../rest/management/ManagementResourceIT.java | 29 +++++++++++++++++++
.../apache/usergrid/management/ExportInfo.java | 15 ++++++----
3 files changed, 46 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e965147b/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 7f7c6e4..91be7f9 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
@@ -233,12 +233,8 @@ public class ApplicationResource extends AbstractContextResource {
uuidRet.put( "jobUUID", jobUUID.toString() );
}
catch ( NullPointerException e ) {
- OAuthResponse errorMsg =
- OAuthResponse.errorResponse( SC_BAD_REQUEST ).setErrorDescription( e.getMessage() )
- .buildJSONMessage();
-
- return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType( callback ) )
- .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(), callback ) ).build();
+ return Response.status( SC_BAD_REQUEST ).type( JSONPUtils.jsonMediaType( callback ) )
+ .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build();
}
catch ( Exception e ) {
//TODO:throw descriptive error message and or include on in the response
@@ -274,12 +270,8 @@ public class ApplicationResource extends AbstractContextResource {
uuidRet.put( "jobUUID", jobUUID.toString() );
}
catch ( NullPointerException e ) {
- OAuthResponse errorMsg =
- OAuthResponse.errorResponse( SC_BAD_REQUEST ).setErrorDescription( e.getMessage())
- .buildJSONMessage();
-
- return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType( callback ) )
- .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(), callback ) ).build();
+ return Response.status( SC_BAD_REQUEST ).type( JSONPUtils.jsonMediaType( callback ) )
+ .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build();
}
catch ( Exception e ) {
//TODO:throw descriptive error message and or include on in the response
@@ -305,18 +297,10 @@ public class ApplicationResource extends AbstractContextResource {
try {
entity = smf.getServiceManager( applicationId ).getEntityManager().get( jobUUIDStr, Export.class );
}
- catch ( Exception e ) {
- //this might be due to other reasons, but gotta look up what service manager does.
-
- OAuthResponse errorMsg =
- OAuthResponse.errorResponse( SC_BAD_REQUEST ).setErrorDescription( e.getMessage())
- .buildJSONMessage();
-
- return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType( callback ) )
- .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(), callback ) ).build();
- // return Response.status( SC_BAD_REQUEST ).build();
+ catch ( Exception e ) { //this might not be a bad request and needs better error checking
+ return Response.status( SC_BAD_REQUEST ).type( JSONPUtils.jsonMediaType( callback ) )
+ .entity( ServiceResource.wrapWithCallback( e.getMessage(), callback ) ).build();
}
- //validate this user owns it
if ( entity == null ) {
return Response.status( SC_BAD_REQUEST ).build();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e965147b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index a81d9fb..a67a157 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -666,6 +666,35 @@ public class ManagementResourceIT extends AbstractRestIT {
assertEquals( Status.BAD_REQUEST, responseStatus );
}
+ @Test
+ public void exportPostNullPointer() throws Exception {
+ JsonNode node = null;
+ Status responseStatus = Status.OK;
+
+ HashMap<String, Object> payload = new HashMap<String, Object>();
+ Map<String, Object> properties = new HashMap<String, Object>();
+ Map<String, Object> storage_info = new HashMap<String, Object>();
+ //TODO: always put dummy values here and ignore this test.
+ //TODO: add a ret for when s3 values are invalid.
+ storage_info.put( "bucket_location", "insert bucket name here" );
+
+
+ properties.put( "storage_provider", "s3" );
+ properties.put( "storage_info", storage_info );
+
+ payload.put( "path", "test-organization/test-app" );
+
+ try {
+ node = resource().path( "/management/orgs/test-organization/apps/test-app/export" )
+ .queryParam( "access_token", superAdminToken() ).accept( MediaType.APPLICATION_JSON )
+ .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,payload );
+ }
+ catch ( UniformInterfaceException uie ) {
+ responseStatus = uie.getResponse().getClientResponseStatus();
+ }
+ assertEquals( Status.BAD_REQUEST, responseStatus );
+ }
+
@Test
public void exportGetUnauthorized() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e965147b/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java b/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java
index 4347aac..fecf700 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ExportInfo.java
@@ -25,8 +25,13 @@ public class ExportInfo extends TypedEntity {
private UUID organizationId;
- public ExportInfo( Map<String, Object> exportData ) {
- //path = ( String ) exportData.get( "path" );
+ public ExportInfo( Map<String, Object> exportData ) {
+ if(exportData == null) {
+ throw new NullPointerException( );
+ }
+ if(exportData.get( "properties" ) == null) {
+ throw new NullPointerException( );
+ }
properties = ( Map ) exportData.get( "properties" );
storage_provider = ( String ) properties.get( "storage_provider" );
storage_info = ( Map ) properties.get( "storage_info" );
@@ -43,9 +48,9 @@ public class ExportInfo extends TypedEntity {
public UUID getOrganizationId() { return organizationId; }
- public String getPath() {
- return path;
- }
+ // public String getPath() {
+ // return path;
+ //}
//Wouldn't get exposed.