Author: [email protected]
Date: Tue Jan 24 10:03:59 2012
New Revision: 1975

Log:
[AMDATUOPENSOCIAL-186] Fixed by reading title and height from the gadgetspec 
when returning the dashboard widgets

Modified:
   
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java

Modified: 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
 (original)
+++ 
trunk/amdatu-opensocial/opensocial-gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/rest/DashboardRESTServiceImpl.java
 Tue Jan 24 10:03:59 2012
@@ -189,11 +189,12 @@
                     // Security tokens are stored in APP_DATA but are 
typically short lived
                     // and so they probably expired when the user logs in. 
Security tokens
                     // should be re-generated each time the user opens the 
dashboard.
-                    for (DashboardWidget widget : dashboard.getData()) {
-                        String st = 
generateSecurityToken(widget.getMetadata().getGadgetUrl(), request);
-                        widget.getMetadata().setSecureToken(st);
+                    if (dashboard.getData() != null) {
+                        for (DashboardWidget widget : dashboard.getData()) {
+                            // Generate a security token and retrieve the 
title and height from the spec
+                            updateWidget(widget, request);
+                        }
                     }
-
                     return get200(dashboard);
                 }
             }
@@ -222,8 +223,8 @@
      * @param request The http request
      * @return <ul>
      *         <li>200 (OK) : The user preferences were returned 
successfully.</li>
-     *         <li>404 (NOT FOUND) : The user preferences could not be 
retrieved since either the widgetid 
-     *         does not refer to an existing widget, or the gadgetspec could 
not be retrieved from the 
+     *         <li>404 (NOT FOUND) : The user preferences could not be 
retrieved since either the widgetid
+     *         does not refer to an existing widget, or the gadgetspec could 
not be retrieved from the
      *         specified uri </li>
      *         <li>500 (INTERNAL SERVER ERROR) : returned in case an 
unexpected internal error occurred.</li>
      *         </ul>
@@ -249,7 +250,8 @@
             UserPrefsBean userPrefs = 
getOpenSocialContainer().getUserPreferences(uri, persistedUserPrefs);
             if (userPrefs != null) {
                 return get200(userPrefs);
-            } else {
+            }
+            else {
                 return get404();
             }
         }
@@ -282,20 +284,17 @@
             if (!gadgetUrl.startsWith("http://";) && 
!gadgetUrl.startsWith("https://";)) {
                 // This is a relative URL
                 gadgetUrl = toAbsoluteUrl(gadgetUrl, request);
-
             }
-            Map<String, String> gadgetSpec = 
getOpenSocialContainer().getGadgetSpec(request, gadgetUrl, null);
-            // Ignore the widget if its gadgetspec could not be found
-            if (gadgetSpec != null) {
-                widget.setTitle(gadgetSpec.get("title"));
-                widget.setHeight(gadgetSpec.get("height"));
 
-                // Generate a security token for the widget and set it in the 
metadata field
-                String st = generateSecurityToken(gadgetUrl, request);
-                Metadata metadata = new Metadata();
-                metadata.setGadgetUrl(gadgetUrl);
-                metadata.setSecureToken(st);
-                widget.setMetadata(metadata);
+            Metadata metadata = new Metadata();
+            metadata.setGadgetUrl(gadgetUrl);
+            widget.setMetadata(metadata);
+
+            // Generate a security token and retrieve the title and height 
from the spec
+            updateWidget(widget, request);
+
+            // Verify if a security token was generfated successfully, only 
append the widget if that succeeded
+            if (widget.getMetadata().getSecureToken() != null) {
                 widgets.add(widget);
             }
         }
@@ -316,4 +315,28 @@
         }
         return getOpenSocialContainer().getSecurityToken(url, request);
     }
+
+    /**
+     * Updates the following properties of the dashboard widget:
+     * secure token - generated
+     * height - retrieved from the gadgetspec
+     * title - retrieved from the gadgetspec
+     * 
+     * @param widget
+     * @param request
+     */
+    private void updateWidget(DashboardWidget widget, HttpServletRequest 
request) {
+        if (widget.getMetadata() != null) {
+            Map<String, String> gadgetSpec =
+                getOpenSocialContainer().getGadgetSpec(request, 
widget.getMetadata().getGadgetUrl(), null);
+            if (gadgetSpec != null) {
+                widget.setHeight(getGadgetSpecValue(gadgetSpec, "height", ""));
+                widget.setTitle(getGadgetSpecValue(gadgetSpec, "title", ""));
+
+                String gadgetUrl = widget.getMetadata().getGadgetUrl();
+                String st = generateSecurityToken(gadgetUrl, request);
+                widget.getMetadata().setSecureToken(st);
+            }
+        }
+    }
 }
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to