usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [10/15] usergrid git commit: Add endpoint for setting apigee mobile config properties on the application.
Date Thu, 22 Oct 2015 18:29:39 GMT
Add endpoint for setting apigee mobile config properties on the application.


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

Branch: refs/heads/2.1-release
Commit: 88d11790c2d077140a71347f97ad5bc75346af2c
Parents: f3693c8
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Wed Oct 21 21:16:50 2015 -0700
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Wed Oct 21 21:16:50 2015 -0700

----------------------------------------------------------------------
 .../rest/applications/ApplicationResource.java  | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/88d11790/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index c521d4f..4eaf09a 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.applications;
 
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sun.jersey.api.json.JSONWithPadding;
 import com.sun.jersey.api.view.Viewable;
 import org.apache.amber.oauth2.common.error.OAuthError;
@@ -47,6 +48,7 @@ import org.apache.usergrid.rest.exceptions.NotFoundExceptionMapper;
 import org.apache.usergrid.rest.exceptions.RedirectionException;
 import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
 import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 import org.apache.usergrid.security.oauth.AccessInfo;
 import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
 import org.slf4j.Logger;
@@ -601,4 +603,52 @@ public class ApplicationResource extends ServiceResource {
         }
         return new JSONWithPadding( value, callback );
     }
+
+    // Specifically require superuser access as this is setting app properties directly (only
way to currently do this
+    // with Apigee's apigeeMobileConfig
+    @RequireSystemAccess
+    @POST
+    @Path("apm/apigeeMobileConfig")
+    @Consumes(APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public JSONWithPadding setAPMConfig( @Context UriInfo ui,
+                                         @QueryParam("callback") @DefaultValue("callback")
String callback,
+                                         Map<String, Object> json) throws Exception
{
+
+        if(json == null || json.size() < 1){
+            logger.error("Param {} cannot be null for POST apm/apigeeMobileConfig", APIGEE_MOBILE_APM_CONFIG_JSON_KEY);
+            throw new IllegalArgumentException("Request body cannot be empty and must include
apigeeMobileConfig params");
+        }
+
+        final String requestAppUUID = (String) json.get("applicationUUID");
+        if(!requestAppUUID.equalsIgnoreCase(applicationId.toString())){
+            logger.error("Provided application UUID {} does not match actual application
UUID {}",
+                requestAppUUID,
+                applicationId.toString());
+            throw new IllegalArgumentException(
+                String.format("Provided application UUID %s does not match actual application
UUID %s",
+                requestAppUUID,
+                applicationId.toString())
+            );
+        }
+
+        final String apmConfig = new ObjectMapper().writeValueAsString(json);
+        if(logger.isDebugEnabled()){
+            logger.debug("Received request to set apigeeMobileConfig properties with: {}",
apmConfig);
+        }
+
+
+        EntityManager em = emf.getEntityManager( applicationId );
+        em.setProperty(new SimpleEntityRef(Application.ENTITY_TYPE, applicationId),
+            APIGEE_MOBILE_APM_CONFIG_JSON_KEY,
+            apmConfig
+        );
+
+        logger.info("Successfully set apigeeMobileConfig properties with: {}", apmConfig);
+
+        return new JSONWithPadding(apmConfig, callback);
+
+    }
+
+
 }


Mime
View raw message