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/10 21:26:21 UTC

[28/50] [abbrv] git commit: Re added in the “export” endpoint that lets you export all entities in all collections. Currently not separated by any visual identifier.

Re added in the “export” endpoint that lets you export all entities in all collections. Currently not separated by any visual identifier.


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

Branch: refs/pull/70/merge
Commit: c7553a3c98d0d3104c9bd89642af8b4e466043f9
Parents: 152c72d
Author: grey <gr...@apigee.com>
Authored: Fri Feb 28 09:11:16 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 28 09:11:16 2014 -0800

----------------------------------------------------------------------
 .../applications/ApplicationResource.java       | 38 ++++++++++++++++++++
 .../management/export/ExportServiceImpl.java    | 32 ++++++++++++-----
 2 files changed, 61 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7553a3c/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 0ddf61b..4187e3e 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
@@ -210,6 +210,44 @@ public class ApplicationResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @POST
+    @Path("export")
+    @Consumes(APPLICATION_JSON)
+    @RequireOrganizationAccess
+    public Response exportPostJson( @Context UriInfo ui,Map<String, Object> json,
+                                    @QueryParam("callback") @DefaultValue("") String callback )
+            throws OAuthSystemException {
+
+
+        OAuthResponse response = null;
+        UUID jobUUID = null;
+        Map<String, String> uuidRet = new HashMap<String, String>();
+
+        try {
+            //parse the json into some useful object (the config params)
+            ExportInfo objEx = new ExportInfo( json );
+            objEx.setOrganizationId( organization.getUuid() );
+            objEx.setApplicationId( applicationId );
+
+            jobUUID = exportService.schedule( objEx );
+            uuidRet.put( "jobUUID", jobUUID.toString() );
+        }
+        catch ( NullPointerException e ) {
+            OAuthResponse errorMsg =
+                    OAuthResponse.errorResponse( SC_BAD_REQUEST ).setErrorDescription( "Job Not Created" )
+                                 .buildJSONMessage();
+
+            return Response.status( errorMsg.getResponseStatus() ).type( JSONPUtils.jsonMediaType( callback ) )
+                           .entity( ServiceResource.wrapWithCallback( errorMsg.getBody(), 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.
+            return Response.status( SC_INTERNAL_SERVER_ERROR ).build();
+        }
+
+        return Response.status( SC_ACCEPTED ).entity( uuidRet ).build();
+    }
 
     @POST
     @Path("collection/{collection_name}/export")

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c7553a3c/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 7e5833f..f0fa965 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
@@ -140,15 +140,29 @@ public class ExportServiceImpl implements ExportService {
         export.setState( Export.State.STARTED );
         em.update( export );
 
-        try {
-            //exports all the applications for a single organization
-            exportApplicationForOrg( config.getOrganizationId(), config, jobExecution );
+        if ( config.getCollection() == null ) {
+            Map<UUID, String> organizations = getOrgs();
+            for ( Map.Entry<UUID, String> organization : organizations.entrySet() ) {
+                try {
+                    exportApplicationsForOrg( organization, config, jobExecution );
+                }catch ( Exception e ) {
+                    export.setState( Export.State.FAILED );
+                    em.update( export );
+                    return;
+                }
+            }
         }
-        catch ( Exception e ) {
-            //if for any reason the backing up fails, then update the entity with a failed state.
-            export.setState( Export.State.FAILED );
-            em.update( export );
-            return;
+        else {
+            try {
+                //exports all the applications for a single organization
+                exportApplicationForOrg( config.getOrganizationId(), config, jobExecution );
+            }
+            catch ( Exception e ) {
+                //if for any reason the backing up fails, then update the entity with a failed state.
+                export.setState( Export.State.FAILED );
+                em.update( export );
+                return;
+            }
         }
         export.setState( Export.State.FINISHED );
         em.update( export );
@@ -161,7 +175,7 @@ public class ExportServiceImpl implements ExportService {
      * @return Map<UUID, String>
      * @throws Exception
      */
-    private Map<UUID, String> getOrgs( ExportInfo exportInfo ) throws Exception {
+    private Map<UUID, String> getOrgs() throws Exception {
         // Loop through the organizations
         UUID orgId = null;