usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject incubator-usergrid git commit: Added ability to export all admin users along with some other management data.
Date Wed, 08 Apr 2015 23:43:45 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/Export_Fixes 447169064 -> b9d02ad93


Added ability to export all admin users along with some other management data.


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

Branch: refs/heads/Export_Fixes
Commit: b9d02ad9373543330bee13948c40b9eb6abd76de
Parents: 4471690
Author: GERey <greyes@apigee.com>
Authored: Wed Apr 8 16:43:44 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Wed Apr 8 16:43:44 2015 -0700

----------------------------------------------------------------------
 .../rest/management/users/UsersResource.java    | 82 ++++++++++++++++++++
 .../management/export/ExportServiceImpl.java    |  6 +-
 2 files changed, 86 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b9d02ad9/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
index 144a6de..4037055 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.management.users;
 
 
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -32,14 +33,24 @@ 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.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.usergrid.management.exceptions.ManagementException;
+import org.apache.usergrid.management.export.ExportService;
 import org.apache.usergrid.rest.RootResource;
+import org.apache.usergrid.rest.applications.ServiceResource;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+import org.apache.usergrid.rest.utils.JSONPUtils;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+
 import org.apache.usergrid.management.UserInfo;
 import org.apache.usergrid.rest.AbstractContextResource;
 import org.apache.usergrid.rest.ApiResponse;
@@ -53,6 +64,11 @@ import com.sun.jersey.api.view.Viewable;
 import net.tanesha.recaptcha.ReCaptchaImpl;
 import net.tanesha.recaptcha.ReCaptchaResponse;
 
+import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
+import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
 import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.apache.usergrid.rest.exceptions.SecurityException.mappableSecurityException;
 
@@ -66,6 +82,8 @@ public class UsersResource extends AbstractContextResource {
 
     private static final Logger logger = LoggerFactory.getLogger( UsersResource.class );
 
+    @Autowired
+    protected ExportService exportService;
     String errorMsg;
     UserInfo user;
 
@@ -219,6 +237,70 @@ public class UsersResource extends AbstractContextResource {
         }
     }
 
+    @POST
+    @Path( "export" )
+    @Consumes(APPLICATION_JSON)
+    @RequireSystemAccess
+    public Response exportPostJson( @Context UriInfo ui,Map<String, Object> json,
+                                    @QueryParam("callback") @DefaultValue("") String callback
)
+        throws OAuthSystemException {
+
+        UUID jobUUID = null;
+        Map<String, String> uuidRet = new HashMap<String, String>();
+
+        Map<String,Object> properties;
+        Map<String, Object> storage_info;
+
+        try {
+            //checkJsonExportProperties(json);
+            if((properties = ( Map<String, Object> )  json.get( "properties" )) ==
null){
+                throw new NullPointerException("Could not find 'properties'");
+            }
+            storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
+            String storage_provider = ( String ) properties.get( "storage_provider" );
+            if(storage_provider == null) {
+                throw new NullPointerException( "Could not find field 'storage_provider'"
);
+            }
+            if(storage_info == null) {
+                throw new NullPointerException( "Could not find field 'storage_info'" );
+            }
+
+
+            String bucketName = ( String ) storage_info.get( "bucket_location" );
+            String accessId = ( String ) storage_info.get( "s3_access_id" );
+            String secretKey = ( String ) storage_info.get( "s3_key" );
+
+            if(bucketName == null) {
+                throw new NullPointerException( "Could not find field 'bucketName'" );
+            }
+            if(accessId == null) {
+                throw new NullPointerException( "Could not find field 's3_access_id'" );
+            }
+            if(secretKey == null) {
+                throw new NullPointerException( "Could not find field 's3_key'" );
+            }
+
+
+            jobUUID = exportService.schedule( json );
+            uuidRet.put( "Export Entity", jobUUID.toString() );
+        }
+        catch ( NullPointerException e ) {
+            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
+            //TODO:fix below, it doesn't work if there is an exception. Make it look like
the OauthResponse.
+            OAuthResponse errorMsg =
+                    OAuthResponse.errorResponse( SC_INTERNAL_SERVER_ERROR ).setErrorDescription(
e.getMessage() )
+                                 .buildJSONMessage();
+            return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType(
callback ) )
+                           .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(),
callback ) ).build();
+        }
+
+        return Response.status( SC_ACCEPTED ).entity( uuidRet ).build();
+    }
+
 
     public String getErrorMsg() {
         return errorMsg;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b9d02ad9/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
index effacf0..9081650 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
@@ -36,6 +36,7 @@ import org.apache.usergrid.batch.JobExecution;
 import org.apache.usergrid.batch.service.SchedulerService;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.ManagementService;
+import org.apache.usergrid.management.UserInfo;
 import org.apache.usergrid.persistence.ConnectionRef;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManager;
@@ -222,8 +223,9 @@ public class ExportServiceImpl implements ExportService {
         }
 
         if ( config.get( "organizationId" ) == null ) {
-            logger.error( "No organization could be found" );
-            export.setState( Export.State.FAILED );
+            //Since this would happen without an organization id ( a case that is impossible
using it regularly
+            //then they could only reach this code with system level access.
+            exportApplicationFromOrg( null, MANAGEMENT_APPLICATION_ID,config,jobExecution,s3Export
);
             em.update( export );
             return;
         }


Mime
View raw message