rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlu...@apache.org
Subject svn commit: r1222389 - in /incubator/rave/trunk: rave-components/rave-core/src/main/java/org/apache/rave/portal/service/ rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/ rave-components/rave-web/src/main/java/org/apache/rave/p...
Date Thu, 22 Dec 2011 18:33:59 GMT
Author: carlucci
Date: Thu Dec 22 18:33:58 2011
New Revision: 1222389

URL: http://svn.apache.org/viewvc?rev=1222389&view=rev
Log:
RAVE-69: Widget metadata can be imported into the Widget Repository from Shindig
 
Applying patch submitted by Venkat Mahadevan

Added:
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMetadataResolver.java
    incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/WidgetApi.java
    incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/main/java/org/apache/rave/provider/opensocial/service/impl/OpenSocialWidgetMetadataResolver.java
    incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialWidgetMetadataResolverTest.java
Modified:
    incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js
    incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveApiSpec.js

Added: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMetadataResolver.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMetadataResolver.java?rev=1222389&view=auto
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMetadataResolver.java
(added)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMetadataResolver.java
Thu Dec 22 18:33:58 2011
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.service;
+
+import org.apache.rave.portal.model.Widget;
+
+public interface WidgetMetadataResolver {
+    String getSupportedContext();
+    Widget getMetadata(String url);
+}

Added: incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/WidgetApi.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/WidgetApi.java?rev=1222389&view=auto
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/WidgetApi.java
(added)
+++ incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/WidgetApi.java
Thu Dec 22 18:33:58 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.api.rpc;
+
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.service.WidgetMetadataResolver;
+import org.apache.rave.portal.web.api.rpc.model.RpcOperation;
+import org.apache.rave.portal.web.api.rpc.model.RpcResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Defines RPC operations for a Widget or its components
+ */
+@Controller(value = "rpcWidgetApi")
+@RequestMapping(value = "/api/rpc/widget/*")
+public class WidgetApi {
+
+    private Map<String, WidgetMetadataResolver> widgetMetadataResolverMap;
+
+    @Autowired
+    public WidgetApi(List<WidgetMetadataResolver> widgetMetadataResolvers) {
+        widgetMetadataResolverMap = new HashMap<String, WidgetMetadataResolver>();
+        for (WidgetMetadataResolver widgetMetadataResolver : widgetMetadataResolvers) {
+            widgetMetadataResolverMap.put(widgetMetadataResolver.getSupportedContext(), widgetMetadataResolver);
+        }
+    }
+
+    @ResponseBody
+    @RequestMapping(method = RequestMethod.POST, value = "metadata/get")
+    public RpcResult<Widget> getWidgetMetadata(@RequestParam final String url,
+                                               @RequestParam final String type) {
+        return new RpcOperation<Widget>() {
+            @Override
+            public Widget execute() {
+                if (widgetMetadataResolverMap.get(type) == null) {
+                    throw new IllegalArgumentException("Get Metadata for provider " + type
+ " is not implemented");
+                }
+                return widgetMetadataResolverMap.get(type).getMetadata(url);
+            }
+        }.getResult();
+    }
+}

Modified: incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
Thu Dec 22 18:33:58 2011
@@ -167,6 +167,7 @@ public class WidgetStoreController {
         widgetValidator.validate(widget, results);
         if (results.hasErrors()) {
             model.addAttribute(ModelKeys.WIDGET, widget);
+            model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
             return ViewNames.ADD_WIDGET_FORM;
         }
         widget.setWidgetStatus(WidgetStatus.PREVIEW);

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties Thu
Dec 22 18:33:58 2011
@@ -72,6 +72,8 @@ page.general.addpage.layout.columns_4=Fo
 page.general.addpage.layout.columns_3nwn_1_bottom=Four Columns (narrow/wide/narrow/bottom)
 page.general.addpage.selectlayout=Select Page Layout:
 
+page.getWidgetMetadata.button=Get widget metadata
+
 page.home.title=Home
 page.mobile_home.title=Home
 page.home.welcome=Hello {0}, welcome to Rave!

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties Thu
Dec 22 18:33:58 2011
@@ -72,6 +72,8 @@ page.general.addpage.layout.columns_4=Vi
 page.general.addpage.layout.columns_3nwn_1_bottom=Vier kolommen (smal/breed/smal/beneden)
 page.general.addpage.selectlayout=Selecteer de Pagina indeling:
 
+page.getWidgetMetadata.button=Get widget metadata
+
 page.home.title=Home
 page.mobile_home.title=Home
 page.home.welcome=Hallo {0}, welkom bij Rave!

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
(original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
Thu Dec 22 18:33:58 2011
@@ -64,12 +64,6 @@
             <p><fmt:message key="form.some.fields.required"/></p>
 
             <p>
-                <form:label path="title"><fmt:message key="widget.title"/> *</form:label>
-                <form:input path="title" cssClass="long" required="required" autofocus="autofocus"/>
-                <form:errors path="title" cssClass="error"/>
-            </p>
-
-            <p>
                 <spring:bind path="url">
                     <label for="url"><fmt:message key="widget.url"/> *</label>
                     <input type="url" name="url" id="url"
@@ -88,59 +82,99 @@
                 <form:errors path="type" cssClass="error"/>
             </p>
 
-            <p>
-                <form:label path="description"><fmt:message key="widget.description"/>
*</form:label>
-                <form:textarea path="description" required="required" cssClass="long"/>
-                <form:errors path="description" cssClass="error"/>
-            </p>
-
-            <p>
-                <spring:bind path="thumbnailUrl">
-                    <label for="thumbnailUrl"><fmt:message key="widget.thumbnailUrl"/></label>
-                    <input type="url" name="thumbnailUrl" id="thumbnailUrl"
-                           placeholder="http://example.com/thumbnail.png" class="long"
-                           value="<c:out value="${widget.thumbnailUrl}"/>"/>
-                </spring:bind>
-                <form:errors path="thumbnailUrl" cssClass="error"/>
-            </p>
-
-            <p>
-                <spring:bind path="screenshotUrl">
-                    <label for="screenshotUrl"><fmt:message key="widget.screenshotUrl"/></label>
-                    <input type="url" name="screenshotUrl" id="screenshotUrl"
-                           placeholder="http://example.com/screenshot.png" class="long"
-                           value="<c:out value="${widget.screenshotUrl}"/>"/>
-                </spring:bind>
-                <form:errors path="screenshotUrl" cssClass="error"/>
-            </p>
-
-            <p>
-                <spring:bind path="titleUrl">
-                    <label for="titleUrl"><fmt:message key="widget.titleUrl"/></label>
-                    <input type="url" name="titleUrl" id="titleUrl"
-                           class="long" value="<c:out value="${widget.titleUrl}"/>"/>
-                </spring:bind>
-                <form:errors path="titleUrl" cssClass="error"/>
-            </p>
-
-            <p>
-                <form:label path="author"><fmt:message key="widget.author"/></form:label>
-                <form:input path="author" cssClass="long"/>
-                <form:errors path="author" cssClass="error"/>
-            </p>
-            <p>
-                <spring:bind path="authorEmail">
-                    <label for="authorEmail"><fmt:message key="widget.authorEmail"/></label>
-                    <input type="email" name="authorEmail" id="authorEmail" class="long"
-                            value="<c:out value="${widget.authorEmail}"/>"/>
-                </spring:bind>
-                <form:errors path="titleUrl" cssClass="error"/>
-            </p>
-
-        </fieldset>
-        <fieldset>
-            <fmt:message key="page.addwidget.form.submit" var="submit"/>
-            <input type="submit" value="${submit}"/>
-        </fieldset>
+            <a href="#" class="storeItemButton"
+                    id="fetchMetadataButton"
+                    onclick="rave.api.rpc.getWidgetMetadata({
+                                url: $('#url').get(0).value,
+                                providerType: $('input:radio[name=type]:checked').val(),
+                                successCallback: function(result) {
+                                    var widget = result.result;
+                                    $('#title').val(widget.title);
+                                    $('#description').val(widget.description);
+                                    $('#thumbnailUrl').val(widget.thumbnailUrl);
+                                    $('#screenshotUrl').val(widget.screenshotUrl);
+                                    $('#titleUrl').val(widget.titleUrl);
+                                    $('#author').val(widget.author);
+                                    $('#authorEmail').val(widget.authorEmail);
+                                    $('#addWidgetForm').show();
+                                    $('#addWidgetFormSubmit').show();
+                                }
+                            });">
+                    <fmt:message key="page.getWidgetMetadata.button"/>
+            </a>
+
+            <div id="addWidgetForm">
+                <p>
+                    <form:label path="title"><fmt:message key="widget.title"/>
*</form:label>
+                    <form:input path="title" cssClass="long" required="required" autofocus="autofocus"/>
+                    <form:errors path="title" cssClass="error"/>
+                </p>
+
+                <p>
+                    <form:label path="description"><fmt:message key="widget.description"/>
*</form:label>
+                    <form:textarea path="description" required="required" cssClass="long"/>
+                    <form:errors path="description" cssClass="error"/>
+                </p>
+
+                <p>
+                    <spring:bind path="thumbnailUrl">
+                        <label for="thumbnailUrl"><fmt:message key="widget.thumbnailUrl"/></label>
+                        <input type="url" name="thumbnailUrl" id="thumbnailUrl"
+                               placeholder="http://example.com/thumbnail.png" class="long"
+                               value="<c:out value="${widget.thumbnailUrl}"/>"/>
+                    </spring:bind>
+                    <form:errors path="thumbnailUrl" cssClass="error"/>
+                </p>
+
+                <p>
+                    <spring:bind path="screenshotUrl">
+                        <label for="screenshotUrl"><fmt:message key="widget.screenshotUrl"/></label>
+                        <input type="url" name="screenshotUrl" id="screenshotUrl"
+                               placeholder="http://example.com/screenshot.png" class="long"
+                               value="<c:out value="${widget.screenshotUrl}"/>"/>
+                    </spring:bind>
+                    <form:errors path="screenshotUrl" cssClass="error"/>
+                </p>
+
+                <p>
+                    <spring:bind path="titleUrl">
+                        <label for="titleUrl"><fmt:message key="widget.titleUrl"/></label>
+                        <input type="url" name="titleUrl" id="titleUrl"
+                               class="long" value="<c:out value="${widget.titleUrl}"/>"/>
+                    </spring:bind>
+                    <form:errors path="titleUrl" cssClass="error"/>
+                </p>
+
+                <p>
+                    <form:label path="author"><fmt:message key="widget.author"/></form:label>
+                    <form:input path="author" cssClass="long"/>
+                    <form:errors path="author" cssClass="error"/>
+                </p>
+                <p>
+                    <spring:bind path="authorEmail">
+                        <label for="authorEmail"><fmt:message key="widget.authorEmail"/></label>
+                        <input type="email" name="authorEmail" id="authorEmail" class="long"
+                                value="<c:out value="${widget.authorEmail}"/>"/>
+                    </spring:bind>
+                    <form:errors path="titleUrl" cssClass="error"/>
+                </p>
+            </div>
+            </fieldset>
+            <div id="addWidgetFormSubmit">
+                <fieldset>
+                    <fmt:message key="page.addwidget.form.submit" var="submit"/>
+                    <input type="submit" value="${submit}"/>
+                </fieldset>
+            </div>
     </form:form>
-</div>
\ No newline at end of file
+</div>
+<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js"></script>
+<script src="//ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.min.js"></script>
+<script src="<spring:url value="/script/rave.js"/>"></script>
+<script src="<spring:url value="/script/rave_api.js"/>"></script>
+<script>
+    $(function() {
+        rave.setContext("<spring:url value="/app/" />");
+        $('#addWidgetForm').hide();
+        $('#addWidgetFormSubmit').hide();
+    });</script>
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js Thu Dec
22 18:33:58 2011
@@ -352,6 +352,27 @@ rave.api = rave.api || (function() {
             }
         }
 
+        function getWidgetMetadata(args) {
+            var url = args.url;
+            var providerType = args.providerType;
+            if ( url == null || providerType == null ) {
+                alert('Both url and type are needed to get the metadata');
+                return;
+            }
+            $.post(rave.getContext() + path + "widget/metadata/get",
+               {"url": url, "type": providerType},
+               function(result) {
+                   if (result.error) {
+                       alert("Unable to parse Widget for its metadata.\n\nPlease verify that
the url is pointing to a valid Widget of the type specified.");
+                   }
+                   else {
+                       if (typeof args.successCallback == 'function') {
+                            args.successCallback(result);
+                       }
+                   }
+               }).error(handleError);
+        }
+
         return {
             moveWidget : moveWidgetOnPage,
             addWidgetToPage : addWidgetToPage,
@@ -360,7 +381,8 @@ rave.api = rave.api || (function() {
             updatePagePrefs: updatePagePrefs,
             getPagePrefs: getPagePrefs,
             movePage: movePage,
-            moveWidgetToPage: moveWidgetToPage
+            moveWidgetToPage: moveWidgetToPage,
+            getWidgetMetadata: getWidgetMetadata
         };
 
     })();

Modified: incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveApiSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveApiSpec.js?rev=1222389&r1=1222388&r2=1222389&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveApiSpec.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/test/javascript/raveApiSpec.js Thu Dec
22 18:33:58 2011
@@ -293,7 +293,23 @@ describe("Rave API", function() {
                 rave.api.rpc.getPagePrefs({pageId: pageId, successCallback: callback});
                 expect(callbackCalled).toBeTruthy();
             });
-        });        
+        });
+
+        describe("getWidgetMetadata", function() {
+            it("gets the metadata metadata for a url provided", function() {
+                $.post = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/widget/metadata/get");
+                    expect(data.url).toEqual("http://www.gstatic.com/ig/modules/tabnews/tabnews.xml");
+                    expect(data.type).toEqual("OpenSocial");
+                    expect(typeof(callback)).toEqual("function");
+                    return {
+                        error: function(a, b, c) {
+                        }
+                    }
+                };
+                rave.api.rpc.getWidgetMetadata({url: "http://www.gstatic.com/ig/modules/tabnews/tabnews.xml",
type: "OpenSocial"});
+            });
+        });
         
         describe("updatePagePrefs", function() {
             it("posts the correct values to RPC service for updating page metadata", function()
{

Added: incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/main/java/org/apache/rave/provider/opensocial/service/impl/OpenSocialWidgetMetadataResolver.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/main/java/org/apache/rave/provider/opensocial/service/impl/OpenSocialWidgetMetadataResolver.java?rev=1222389&view=auto
==============================================================================
--- incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/main/java/org/apache/rave/provider/opensocial/service/impl/OpenSocialWidgetMetadataResolver.java
(added)
+++ incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/main/java/org/apache/rave/provider/opensocial/service/impl/OpenSocialWidgetMetadataResolver.java
Thu Dec 22 18:33:58 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.provider.opensocial.service.impl;
+
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.service.WidgetMetadataResolver;
+import org.apache.rave.provider.opensocial.Constants;
+import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OpenSocialWidgetMetadataResolver implements WidgetMetadataResolver {
+    private GadgetMetadataRepository gadgetMetadataRepository;
+
+    @Autowired
+    public OpenSocialWidgetMetadataResolver(GadgetMetadataRepository gadgetMetadataRepository)
{
+        this.gadgetMetadataRepository = gadgetMetadataRepository;
+    }
+
+    public String getSupportedContext() {
+        return Constants.WIDGET_TYPE;
+    }
+
+    /**
+     * Get the opensocial widget metadata
+     * @param url   url for the widget
+     * @return
+     */
+    public Widget getMetadata(String url) {
+        Widget widget = new Widget();
+        JSONObject jsonGadget = null;
+        try {
+            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
+            if ( jsonGadget != null ) {
+                String query = jsonGadget.getString("modulePrefs");
+                JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
+                if ( jsonModulePrefsObject != null ) {
+                    String title = jsonModulePrefsObject.getString("title");
+                    String titleUrl = jsonModulePrefsObject.getString("titleUrl");
+                    String description =  jsonModulePrefsObject.getString("description");
+                    String author = jsonModulePrefsObject.getString("author");
+                    String authorEmail = jsonModulePrefsObject.getString("authorEmail");
+                    String thumbnailUrl = jsonModulePrefsObject.getString("thumbnail");
+                    String screenShot = jsonModulePrefsObject.getString("screenshot");
+
+                    widget.setTitle(title);
+                    widget.setTitleUrl(titleUrl);
+                    widget.setDescription(description);
+                    widget.setAuthor(author);
+                    widget.setAuthorEmail(authorEmail);
+                    widget.setThumbnailUrl(thumbnailUrl);
+                    widget.setScreenshotUrl(screenShot);
+                    widget.setUrl(url);
+                    widget.setType(getSupportedContext());
+                }
+            }
+        } catch (JSONException e) {
+            try {
+                String query = jsonGadget.getString("error");
+                if (query != null ) {
+                    JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
+                    if ( jsonModuleErrorObject != null ) {
+                        String errorMessage = jsonModuleErrorObject.getString("message");
+                        String errorCode = jsonModuleErrorObject.getString("code");
+                        throw new IllegalArgumentException("HTTP error: " + errorCode + ".
Message: " + errorMessage);
+                    }
+                }
+            } catch ( JSONException e1) {
+                throw new IllegalArgumentException("Error occurred while processing response
for Widget metadata call", e1);
+            }
+            throw new IllegalArgumentException("Error occurred while processing response
for Widget metadata call", e);
+        }
+        return widget;
+    }
+}

Added: incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialWidgetMetadataResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialWidgetMetadataResolverTest.java?rev=1222389&view=auto
==============================================================================
--- incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialWidgetMetadataResolverTest.java
(added)
+++ incubator/rave/trunk/rave-providers/rave-opensocial-provider/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialWidgetMetadataResolverTest.java
Thu Dec 22 18:33:58 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.provider.opensocial.service;
+
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.service.WidgetMetadataResolver;
+import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
+import org.apache.rave.provider.opensocial.service.impl.OpenSocialWidgetMetadataResolver;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.assertNotNull;
+
+public class OpenSocialWidgetMetadataResolverTest {
+
+    private GadgetMetadataRepository gadgetMetadataRepository;
+    private WidgetMetadataResolver widgetMetadataResolver;
+    private final String TYPE = "OpenSocial";
+    private static final String VALID_GADGET_URL = "http://www.example.com/gadget.xml";
+    private static final String VALID_METADATA = "{\"modulePrefs\":{\"screenshot\":\"http://www.gstatic.com/ig/modules/dictionary/dictionary_content/ALL_ALL.cache.png\",\"authorEmail\":\"googlemodules+dictionary+201109071@google.com\",\"authorLink\":\"\",\"links\":{},\"author\":\"Google
Taiwan\",\"title\":\"Google Translate\",\"authorAffiliation\":\"Google Inc.\",\"titleUrl\":\"http://translate.google.com/\",\"thumbnail\":\"http://www.gstatic.com/ig/modules/dictionary/dictionary_content/ALL_ALL-thm.cache.png\",\"authorLocation\":\"Taiwan\",\"description\":\"Google
Translation gadget can translate between common languages in the world\",\"features\":{\"dynamic-height\":{\"name\":\"dynamic-height\",\"params\":{},\"required\":true},\"setprefs\":{\"name\":\"setprefs\",\"params\":{},\"required\":true},\"core\":{\"name\":\"core\",\"params\":{},\"required\":true}}}}";
+    private static final String INVALID_METADATA = "{\"hasPrefsToEdit\":false,\"error\":{\"message\":\"Unable
to retrieve spec for http://www.gstatic.com/ig/modules/dictionary/123dictionary.xml. HTTP
error 404\",\"code\":404}}";
+
+    @Before
+    public void setup() {
+        gadgetMetadataRepository = createNiceMock(GadgetMetadataRepository.class);
+        widgetMetadataResolver = new OpenSocialWidgetMetadataResolver(gadgetMetadataRepository);
+    }
+
+    @Test
+    public void getSupportedContext_test() {
+        assertNotNull(widgetMetadataResolver.getSupportedContext());
+    }
+
+    @Test
+    public void getMetadata() {
+        expect(gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL)).andReturn(VALID_METADATA);
+        replay(gadgetMetadataRepository);
+        Widget w = widgetMetadataResolver.getMetadata(VALID_GADGET_URL);
+        assertNotNull(w);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void getMetadata_invalid() {
+        expect(gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL)).andReturn(INVALID_METADATA);
+        replay(gadgetMetadataRepository);
+        Widget w = widgetMetadataResolver.getMetadata(VALID_GADGET_URL);
+        assertNotNull(w);
+    }
+}



Mime
View raw message