usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [19/50] [abbrv] usergrid git commit: Add endpoint which lists all orgs in the system (up to 10k) and provides all apps within the org as well.
Date Fri, 30 Oct 2015 23:32:53 GMT
Add endpoint which lists all orgs in the system (up to 10k) and provides all apps within the
org as well.


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

Branch: refs/heads/master
Commit: 752bf4e3fcb5e9b6064cac477bbde68a6c8727f3
Parents: 5eed978
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Mon Oct 26 15:24:11 2015 -0700
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Mon Oct 26 15:24:11 2015 -0700

----------------------------------------------------------------------
 .../organizations/OrganizationsResource.java    | 42 +++++++++++++-------
 1 file changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/752bf4e3/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
index 4eac80d..ac07aaa 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
@@ -17,23 +17,14 @@
 package org.apache.usergrid.rest.management.organizations;
 
 
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import java.util.*;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
-
 import org.apache.usergrid.rest.RootResource;
 import org.apache.usergrid.rest.management.ManagementResource;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,9 +37,7 @@ import org.apache.usergrid.management.exceptions.ManagementException;
 import org.apache.usergrid.rest.AbstractContextResource;
 import org.apache.usergrid.rest.ApiResponse;
 import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
-
 import org.apache.commons.lang.StringUtils;
-
 import com.google.common.base.Preconditions;
 import com.sun.jersey.api.json.JSONWithPadding;
 
@@ -74,6 +63,31 @@ public class OrganizationsResource extends AbstractContextResource {
     }
 
 
+    @GET
+    @RequireSystemAccess
+    public JSONWithPadding getAllOrganizations() throws Exception{
+
+        ApiResponse response = createApiResponse();
+        List<OrganizationInfo> orgs = management.getOrganizations(null, 10000);
+        List<Object> jsonOrgList = new ArrayList<>();
+
+        for(OrganizationInfo org: orgs){
+
+
+            Map<String, Object> jsonOrg = new HashMap<>();
+            Map<String, UUID> apps = management.getApplicationsForOrganization(org.getUuid()).inverse();
+
+            jsonOrg.put("name", org.getName());
+            jsonOrg.put("uuid", org.getUuid());
+            jsonOrg.put("properties", org.getProperties());
+            jsonOrg.put("applications", apps);
+            jsonOrgList.add(jsonOrg);
+        }
+
+        response.setProperty("organizations", jsonOrgList);
+        return new JSONWithPadding(response);
+    }
+
     @Path(RootResource.ORGANIZATION_ID_PATH)
     @RequireOrganizationAccess
     public OrganizationResource getOrganizationById( @Context UriInfo ui,


Mime
View raw message