You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ps...@apache.org on 2012/12/17 13:44:49 UTC

svn commit: r1422906 - in /rave/trunk/rave-components: rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/ rave-core/src/main/java/org/apache/rave/portal/service/ rave-core/src/main/java/org/apache/rave/portal/service/impl/ rave-core/src/te...

Author: psharples
Date: Mon Dec 17 12:44:47 2012
New Revision: 1422906

URL: http://svn.apache.org/viewvc?rev=1422906&view=rev
Log:
Improvements made to the OMDL import.  The import routine will now attempt to download any remote widgets it finds in the omdl instance and make them available in the page. See RAVE-820.

Added:
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java   (with props)
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java   (with props)
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java   (with props)
Modified:
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlConstants.java
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlInputAdapter.java
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlOutputAdapter.java
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMarketplaceService.java
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultOmdlService.java
    rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceService.java
    rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceServiceTest.java
    rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/MarketplaceAPI.java

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlConstants.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlConstants.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlConstants.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlConstants.java Mon Dec 17 12:44:47 2012
@@ -55,8 +55,9 @@ public interface OmdlConstants {
     public final String APP_TYPE_W3C = "application/widget";
     public final String APP_TYPE_OPENSOCIAL = "application/vnd-opensocial+xml";
     public final String APP_TYPE_UNKNOWN = "application/unknown";
-
     public final String REL_TYPE = "source";
+    public final String RAVE_APP_TYPE_OPENSOCIAL = "OpenSocial";
+    public final String RAVE_APP_TYPE_W3C = "W3C";
 
     // XML Element and attributes
     public final String NAMESPACE = "http://omdl.org";
@@ -64,7 +65,11 @@ public interface OmdlConstants {
     public final String TITLE = "title";
     public final String LAYOUT = "layout";
     public final String APP = "app";
+    public final String LINK = "link";
     public final String POSITION = "position";
+    public final String ID_ATTRIBUTE = "id";
+    public final String TYPE_ATTRIBUTE = "type";
+    public final String HREF = "href";
 
     public final String DEFAULT_LAYOUT = FLOW_LAYOUT;
 

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlInputAdapter.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlInputAdapter.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlInputAdapter.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlInputAdapter.java Mon Dec 17 12:44:47 2012
@@ -42,35 +42,35 @@ public class OmdlInputAdapter implements
     private String layoutCode;
 
     // region 1
-    private List<String> topLeft;
-    private List<String> middleLeft;
-    private List<String> bottomLeft;
+    private List<OmdlWidgetReference> topLeft;
+    private List<OmdlWidgetReference> middleLeft;
+    private List<OmdlWidgetReference> bottomLeft;
     // region 2
-    private List<String> topCenter;
-    private List<String> middleCenter;
-    private List<String> bottomCenter;
+    private List<OmdlWidgetReference> topCenter;
+    private List<OmdlWidgetReference> middleCenter;
+    private List<OmdlWidgetReference> bottomCenter;
     // region 3
-    private List<String> topRight;
-    private List<String> middleRight;
-    private List<String> bottomRight;
+    private List<OmdlWidgetReference> topRight;
+    private List<OmdlWidgetReference> middleRight;
+    private List<OmdlWidgetReference> bottomRight;
     // unknown region (possibly a 4th region)
-    private List<String> unknown;
+    private List<OmdlWidgetReference> unknown;
 
     public OmdlInputAdapter() {
-        topLeft = new ArrayList<String>();
-        middleLeft = new ArrayList<String>();
-        bottomLeft = new ArrayList<String>();
-        topCenter = new ArrayList<String>();
-        middleCenter = new ArrayList<String>();
-        bottomCenter = new ArrayList<String>();
-        topRight = new ArrayList<String>();
-        middleRight = new ArrayList<String>();
-        bottomRight = new ArrayList<String>();
-        unknown = new ArrayList<String>();
+        topLeft = new ArrayList<OmdlWidgetReference>();
+        middleLeft = new ArrayList<OmdlWidgetReference>();
+        bottomLeft = new ArrayList<OmdlWidgetReference>();
+        topCenter = new ArrayList<OmdlWidgetReference>();
+        middleCenter = new ArrayList<OmdlWidgetReference>();
+        bottomCenter = new ArrayList<OmdlWidgetReference>();
+        topRight = new ArrayList<OmdlWidgetReference>();
+        middleRight = new ArrayList<OmdlWidgetReference>();
+        bottomRight = new ArrayList<OmdlWidgetReference>();
+        unknown = new ArrayList<OmdlWidgetReference>();
     }
 
-    public List<String> getAllUrls(){
-        List<String> newList = new ArrayList<String>();
+    public List<OmdlWidgetReference> getAllUrls(){
+        List<OmdlWidgetReference> newList = new ArrayList<OmdlWidgetReference>();
         newList.addAll(getAllLeftUrls());
         newList.addAll(getAllCenterUrls());
         newList.addAll(getAllRightUrls());
@@ -78,16 +78,16 @@ public class OmdlInputAdapter implements
         return newList;
     }
 
-    public List<String> getAllUnknownUrls(){
+    public List<OmdlWidgetReference> getAllUnknownUrls(){
         Collections.reverse(unknown);
         return unknown;
     }
 
-    public List<String> getAllRightUrls(){
+    public List<OmdlWidgetReference> getAllRightUrls(){
         Collections.reverse(topRight);
         Collections.reverse(middleRight);
         Collections.reverse(bottomRight);
-        List<String> newList = new ArrayList<String>();
+        List<OmdlWidgetReference> newList = new ArrayList<OmdlWidgetReference>();
         newList.addAll(topRight);
         newList.addAll(middleRight);
         newList.addAll(bottomRight);
@@ -95,11 +95,11 @@ public class OmdlInputAdapter implements
         return newList;
     }
 
-    public List<String> getAllCenterUrls(){
+    public List<OmdlWidgetReference> getAllCenterUrls(){
         Collections.reverse(topCenter);
         Collections.reverse(middleCenter);
         Collections.reverse(bottomCenter);
-        List<String> newList = new ArrayList<String>();
+        List<OmdlWidgetReference> newList = new ArrayList<OmdlWidgetReference>();
         newList.addAll(topCenter);
         newList.addAll(middleCenter);
         newList.addAll(bottomCenter);
@@ -107,11 +107,11 @@ public class OmdlInputAdapter implements
         return newList;
     }
 
-    public List<String> getAllLeftUrls(){
+    public List<OmdlWidgetReference> getAllLeftUrls(){
         Collections.reverse(topLeft);
         Collections.reverse(middleLeft);
         Collections.reverse(bottomLeft);
-        List<String> newList = new ArrayList<String>();
+        List<OmdlWidgetReference> newList = new ArrayList<OmdlWidgetReference>();
         newList.addAll(topLeft);
         newList.addAll(middleLeft);
         newList.addAll(bottomLeft);
@@ -119,39 +119,39 @@ public class OmdlInputAdapter implements
         return newList;
     }
 
-    public void addToAppMap(String url, String position){
+    public void addToAppMap(OmdlWidgetReference widgetReference, String position){
         if(position.contains(POSITION_LEFT)){
             LEFT_FOUND = true;
             if(position.contains(POSITION_TOP)){
-                topLeft.add(url);
+                topLeft.add(widgetReference);
             }else if (position.contains(POSITION_MIDDLE)) {
-                middleLeft.add(url);
+                middleLeft.add(widgetReference);
             }else{// otherwise go to bottom
-                bottomLeft.add(url);
+                bottomLeft.add(widgetReference);
             }
         }
         else if(position.contains(POSITION_CENTER)){
             CENTER_FOUND = true;
             if(position.contains(POSITION_TOP)){
-                topCenter.add(url);
+                topCenter.add(widgetReference);
             }else if (position.contains(POSITION_MIDDLE)) {
-                middleCenter.add(url);
+                middleCenter.add(widgetReference);
             }else{// otherwise go to bottom
-                bottomCenter.add(url);
+                bottomCenter.add(widgetReference);
             }
         }
         else if(position.contains(POSITION_RIGHT)){
             RIGHT_FOUND = true;
             if(position.contains(POSITION_TOP)){
-                topRight.add(url);
+                topRight.add(widgetReference);
             }else if (position.contains(POSITION_MIDDLE)) {
-                middleRight.add(url);
+                middleRight.add(widgetReference);
             }else{// otherwise go to bottom
-                bottomRight.add(url);
+                bottomRight.add(widgetReference);
             }
         }
         else{
-            unknown.add(url);
+            unknown.add(widgetReference);
         }
     }
 

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlOutputAdapter.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlOutputAdapter.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlOutputAdapter.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlOutputAdapter.java Mon Dec 17 12:44:47 2012
@@ -135,7 +135,7 @@ public class OmdlOutputAdapter implement
             appType = APP_TYPE_OPENSOCIAL;
         }else if(appType.equals("W3C")){
             appType = APP_TYPE_W3C;
-            url = wookieUrl + "/widgets/" + url + "?format=application/widget";
+            url = wookieUrl + "/widgets/" + url;
         }else{
             appType = APP_TYPE_UNKNOWN;
         }

Added: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java?rev=1422906&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java (added)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java Mon Dec 17 12:44:47 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.model.util.omdl;
+/**
+ * Simple bean to model the identifier and url link for a given omdl widget
+ */
+public class OmdlWidgetReference {
+
+    private String widgetIdentifier;
+    private String widgetLink;
+    private String widgetType;
+
+    public OmdlWidgetReference(String widgetIdentifier, String widgetLink, String widgetType) {
+        this.widgetIdentifier = widgetIdentifier;
+        this.widgetLink = widgetLink;
+        this.widgetType = widgetType;
+    }
+    
+    public String getRaveWidgetTypeFromFormatType(){
+        if(widgetType.equals(OmdlConstants.APP_TYPE_OPENSOCIAL)){
+            return OmdlConstants.RAVE_APP_TYPE_OPENSOCIAL;
+        }else if(widgetType.equals(OmdlConstants.APP_TYPE_W3C)){
+            return OmdlConstants.RAVE_APP_TYPE_W3C;
+        }
+        return null;
+    }
+
+    public String getWidgetIdentifier() {
+        return widgetIdentifier;
+    }
+
+    public void setWidgetIdentifier(String widgetIdentifier) {
+        this.widgetIdentifier = widgetIdentifier;
+    }
+
+    public String getWidgetLink() {
+        if(!widgetLink.contains("?format=") && widgetType != null){
+            return widgetLink + "?format=" + widgetType; 
+        }
+        return widgetLink;
+    }
+
+    public void setWidgetLink(String widgetLink) {
+        this.widgetLink = widgetLink;
+    }
+
+    public String getWidgetType() {
+        return widgetType;
+    }
+
+    public void setWidgetType(String widgetType) {
+        this.widgetType = widgetType;
+    }
+
+}

Propchange: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/util/omdl/OmdlWidgetReference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java?rev=1422906&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java (added)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java Mon Dec 17 12:44:47 2012
@@ -0,0 +1,49 @@
+/*
+ * 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 RemoteWidgetResolverService {
+
+    /**
+     * For a given url and widget type wrap the widgetServices implementation of getWidgetMetatdat
+     * so that a remote W3C widget can be downloaded and installed into wookie first.
+     * @param url - the url of the opensocial or W3C resource on the web
+     * @param type - providertype
+     * @return - a widget
+     * @throws Exception
+     */
+    public Widget resolveAndDownloadWidgetMetadata(String url, String type) throws Exception;
+    
+    /**
+     * Add a widget to raves DB.
+     * @param widget - widget not yet part of rave
+     * @return widget - A rave widget with its internal id now set
+     * @throws Exception
+     */
+    public Widget addWidget(Widget widget) throws Exception;
+    
+    /**
+     * Is the config property for widget status set to PUBLISHED
+     * @return true if it is set to PUBLISHED
+     */
+    public boolean isPublished();
+
+}

Propchange: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/RemoteWidgetResolverService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMarketplaceService.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMarketplaceService.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMarketplaceService.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetMarketplaceService.java Mon Dec 17 12:44:47 2012
@@ -77,7 +77,7 @@ public interface WidgetMarketplaceServic
      * @return
      * @throws Exception
      */
-    Widget getWidgetMetadata(String url, String type) throws Exception;
+    Widget resolveWidgetMetadata(String url, String type) throws Exception;
     
     /**
      * Gets the specified Widget

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultOmdlService.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultOmdlService.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultOmdlService.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultOmdlService.java Mon Dec 17 12:44:47 2012
@@ -31,14 +31,17 @@ import org.apache.commons.io.FileUtils;
 import org.apache.rave.exception.DuplicateItemException;
 import org.apache.rave.portal.model.Page;
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.impl.WidgetImpl;
 import org.apache.rave.portal.model.util.omdl.BadOmdlXmlFormatException;
 import org.apache.rave.portal.model.util.omdl.OmdlConstants;
 import org.apache.rave.portal.model.util.omdl.OmdlInputAdapter;
 import org.apache.rave.portal.model.util.omdl.OmdlModelUtils;
 import org.apache.rave.portal.model.util.omdl.OmdlOutputAdapter;
+import org.apache.rave.portal.model.util.omdl.OmdlWidgetReference;
 import org.apache.rave.portal.service.OmdlService;
 import org.apache.rave.portal.service.PageService;
 import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.RemoteWidgetResolverService;
 import org.apache.rave.portal.service.WidgetService;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,14 +72,17 @@ public class DefaultOmdlService implemen
     private PageService pageService;
     private WidgetService widgetService;
     private UserService userService;
+    private RemoteWidgetResolverService widgetResolverService;
     
     public DefaultOmdlService(){}
 
     @Autowired
-    public DefaultOmdlService(PageService pageService, WidgetService widgetService, UserService userService){
+    public DefaultOmdlService(PageService pageService, WidgetService widgetService, 
+            UserService userService, RemoteWidgetResolverService widgetResolverService){
         this.pageService = pageService;
         this.widgetService = widgetService;
         this.userService = userService;
+        this.widgetResolverService = widgetResolverService;
     }
     
     @Override
@@ -145,12 +151,44 @@ public class DefaultOmdlService implemen
         return page;
     }
 
-    private void populateRegionWidgets(Page page, List<String> urlList, String regionId ){
-        Widget widget = null;
-        for (String widgetUrl : urlList){
-            widget = widgetService.getWidgetByUrl(widgetUrl);
-            if(widget != null){
-                pageService.addWidgetToPageRegion(page.getId(), widget.getId(), regionId);
+    private void populateRegionWidgets(Page page, List<OmdlWidgetReference> widgetReferences, String regionId ){
+        Widget raveWidget = null;
+        for (OmdlWidgetReference widgetReference : widgetReferences){
+            // try to find if the widget is already installed in rave by its identifier (should be the rave widget url)
+            logger.info("Found OMDL widget reference ("+widgetReference.getWidgetIdentifier()+")");
+            raveWidget = widgetService.getWidgetByUrl(widgetReference.getWidgetIdentifier());
+            
+            // If not found download and install to widget container, then to rave.
+            if(raveWidget==null){
+                String providerType = widgetReference.getRaveWidgetTypeFromFormatType();
+                if(!providerType.equals(null)){
+                    try {
+                        Widget resolvedWidget = widgetResolverService.resolveAndDownloadWidgetMetadata(widgetReference.getWidgetLink(), providerType);
+                        // Check again in case the OMDL id attribute is not the same as the one found in the href attribute
+                        if(widgetService.getWidgetByUrl(resolvedWidget.getUrl())==null){
+                            raveWidget = widgetResolverService.addWidget(resolvedWidget);
+                            logger.info("Widget added to rave. ("+raveWidget.getUrl()+")");
+                        }else{
+                            logger.info("Widget was already added to rave. ("+resolvedWidget.getUrl()+")");
+                        }
+                    } catch (Exception e) {
+                        logger.error("Problem installing widget: "+ e.getMessage());
+                        throw new RuntimeException(e);
+                    }
+                }
+            }
+            
+            if(raveWidget != null){
+                if(widgetResolverService.isPublished()){
+                    pageService.addWidgetToPageRegion(page.getId(), raveWidget.getId(), regionId);
+                }
+                else{
+                    logger.error("Unable to add widget to page as the default status is set to PREVIEW. (" + raveWidget.getUrl() + ")");
+                }
+            }
+            else{
+                logger.error("Unable to resolve widget entry found in OMDL file. " + widgetReference.getWidgetIdentifier() 
+                        + " : " + widgetReference.getWidgetLink());
             }
         }
     }
@@ -198,15 +236,24 @@ public class DefaultOmdlService implemen
         nodeList = rootEl.getElementsByTagNameNS(namespace, APP);
         if(nodeList != null && nodeList.getLength() > 0) {
             for(int i = 0 ; i < nodeList.getLength();i++) {
-                Element el = (Element)nodeList.item(i);
-                String id = el.getAttribute("id");
+                Element appElement = (Element)nodeList.item(i);
+                String id = appElement.getAttribute(ID_ATTRIBUTE);
                 if(id != null){
-                    Node positionNode = el.getElementsByTagName(POSITION).item(0);
+                    String position = null;
+                    String hrefLink = null;
+                    String hrefType = null;
+                    Node positionNode = appElement.getElementsByTagNameNS(namespace, POSITION).item(0);
                     if(positionNode != null){
-                        el = (Element)positionNode;
-                        String position = el.getTextContent();
-                        omdlInputAdapter.addToAppMap(id, position);
+                        Element positionElement = (Element)positionNode;
+                        position = positionElement.getTextContent();
+                    }
+                    Node linkNode = appElement.getElementsByTagNameNS(namespace, LINK).item(0);
+                    if(linkNode != null){
+                        Element linkElement = (Element)linkNode;
+                        hrefLink = linkElement.getAttribute(HREF);
+                        hrefType = linkElement.getAttribute(TYPE_ATTRIBUTE);
                     }
+                    omdlInputAdapter.addToAppMap(new OmdlWidgetReference(id, hrefLink, hrefType), position);
                 }
             }
         }

Added: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java?rev=1422906&view=auto
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java (added)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java Mon Dec 17 12:44:47 2012
@@ -0,0 +1,113 @@
+/*
+ * 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.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.rave.portal.model.PortalPreference;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
+import org.apache.rave.portal.service.PortalPreferenceService;
+import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.WidgetMetadataResolver;
+import org.apache.rave.portal.service.RemoteWidgetResolverService;
+import org.apache.rave.portal.service.WidgetService;
+import org.apache.rave.portal.web.util.PortalPreferenceKeys;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DefaultRemoteWidgetResolverService implements RemoteWidgetResolverService {
+
+    private final WidgetService widgetService;
+    private final UserService userService;
+    private PortalPreferenceService portalPreferenceService;
+    private Map<String, WidgetMetadataResolver> widgetMetadataResolverMap;
+
+    @Autowired
+    public DefaultRemoteWidgetResolverService(WidgetService widgetService, UserService userService, 
+        PortalPreferenceService pps,  List<WidgetMetadataResolver> widgetMetadataResolvers){
+        this.widgetService = widgetService;
+        this.userService = userService;
+        this.portalPreferenceService = pps;
+        widgetMetadataResolverMap = new HashMap<String, WidgetMetadataResolver>();
+        for (WidgetMetadataResolver widgetMetadataResolver : widgetMetadataResolvers) {
+            widgetMetadataResolverMap.put(widgetMetadataResolver.getSupportedContext(), widgetMetadataResolver);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.rave.portal.service.WidgetResolverService#resolveWidgetMetadata(java.lang.String, java.lang.String)
+     */
+    @Override
+    public Widget resolveAndDownloadWidgetMetadata(String url, String type) throws Exception{
+        Widget widget = null;
+        // check for namespaces in the the type element
+        if(type.contains("#")){
+            String[] deNamespacedType = type.split("#");
+            if(deNamespacedType.length > 0){
+                type = deNamespacedType[1];
+            }
+        }
+        if (type.equals("W3C") || type.equals("W3C Widget") || type.equals("W3CWidget")){
+            widget = widgetMetadataResolverMap.get("W3C").publishRemote(url);
+        }else if (type.equals("OpenSocial") || type.startsWith("OpenSocial")|| type.startsWith("Open Social")){
+            widget = widgetMetadataResolverMap.get("OpenSocial").getMetadata(url);
+        }else{
+            // there may be resources in a marketplace store (or in an OMDL instance) other than W3C & OpenSocial 
+            // gadgets so return null if it isn't one of the supported types in rave.
+            throw new Exception("Unsupported Widget format");
+        }
+        return widget;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.rave.portal.service.WidgetResolverService#addWidget(org.apache.rave.portal.model.Widget)
+     */
+    @Override
+    public Widget addWidget(Widget widget) throws Exception{
+        PortalPreference status = portalPreferenceService.getPreference(PortalPreferenceKeys.INITIAL_WIDGET_STATUS);
+        User user = userService.getAuthenticatedUser();
+        widget.setOwnerId(user.getId());
+        if (status != null && status.getValue().equals("PUBLISHED")){
+            widget.setWidgetStatus(WidgetStatus.PUBLISHED);
+        } else {
+            widget.setWidgetStatus(WidgetStatus.PREVIEW);
+        }
+        return widgetService.registerNewWidget(widget);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.rave.portal.service.RemoteWidgetResolverService#isPublished()
+     */
+    @Override
+    public boolean isPublished() {
+        PortalPreference status = portalPreferenceService.getPreference(PortalPreferenceKeys.INITIAL_WIDGET_STATUS);
+        if (status != null && status.getValue().equals("PUBLISHED")){
+            return true;
+        }
+        return false;
+    }
+}

Propchange: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultRemoteWidgetResolverService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceService.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceService.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceService.java (original)
+++ rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceService.java Mon Dec 17 12:44:47 2012
@@ -21,22 +21,17 @@ package org.apache.rave.portal.service.i
 
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.rave.portal.model.PortalPreference;
-import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.model.Widget;
-import org.apache.rave.portal.model.WidgetStatus;
 import org.apache.rave.portal.model.util.SearchResult;
 import org.apache.rave.portal.model.util.WidgetMarketplaceSearchResult;
 import org.apache.rave.portal.model.util.WidgetMarketplaceWidgetResult;
 import org.apache.rave.portal.service.PortalPreferenceService;
-import org.apache.rave.portal.service.UserService;
 import org.apache.rave.portal.service.WidgetMarketplaceService;
-import org.apache.rave.portal.service.WidgetMetadataResolver;
-import org.apache.rave.portal.service.WidgetService;
+import org.apache.rave.portal.service.RemoteWidgetResolverService;
 import org.apache.rave.portal.web.util.PortalPreferenceKeys;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,10 +53,8 @@ import org.springframework.web.client.Re
 @Service
 public class DefaultWidgetMarketplaceService implements WidgetMarketplaceService {
 
-    private final WidgetService widgetService;
-    private final UserService userService;
     private PortalPreferenceService portalPreferenceService;
-    private Map<String, WidgetMetadataResolver> widgetMetadataResolverMap;
+    private RemoteWidgetResolverService widgetResolverService;
     private static final String DEFAULT_URL = null;
     private static final Logger logger = LoggerFactory.getLogger(DefaultWidgetMarketplaceService.class);
     private static final String SEARCH = "search?q=${SEARCHTERM}&start=${OFFSET}&rows=${LIMIT}";
@@ -70,16 +63,10 @@ public class DefaultWidgetMarketplaceSer
     private static final String CATEGORY_LIST = "tag/all";
     
     @Autowired
-    public DefaultWidgetMarketplaceService(WidgetService widgetService, UserService userService, 
-        PortalPreferenceService pps,  List<WidgetMetadataResolver> widgetMetadataResolvers){
-        this.widgetService = widgetService;
-        this.userService = userService;
+    public DefaultWidgetMarketplaceService(RemoteWidgetResolverService widgetResolverService, PortalPreferenceService pps){
+        this.widgetResolverService = widgetResolverService;
         this.portalPreferenceService = pps;
-        widgetMetadataResolverMap = new HashMap<String, WidgetMetadataResolver>();
-        for (WidgetMetadataResolver widgetMetadataResolver : widgetMetadataResolvers) {
-            widgetMetadataResolverMap.put(widgetMetadataResolver.getSupportedContext(), widgetMetadataResolver);
-        }
-	}
+    }
 
     /* (non-Javadoc)
      * @see org.apache.rave.portal.service.WidgetMarketplaceService#getWidgetsByFreeTextSearch(java.lang.String, int, int)
@@ -186,48 +173,6 @@ public class DefaultWidgetMarketplaceSer
         return restTemplate;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.rave.portal.service.WidgetMarketplaceService#getWidgetMetadata(java.lang.String, java.lang.String)
-     */
-    public Widget getWidgetMetadata(String url, String type) throws Exception{
-        Widget widget = null;
-        // check for namespaces in the the type element
-        if(type.contains("#")){
-            String[] deNamespacedType = type.split("#");
-            if(deNamespacedType.length > 0){
-                type = deNamespacedType[1];
-            }
-        }
-        if (type.equals("W3C") || type.equals("W3C Widget") || type.equals("W3CWidget")){
-            widget = widgetMetadataResolverMap.get("W3C").publishRemote(url);
-        } else if (type.equals("OpenSocial") || type.startsWith("OpenSocial")|| type.startsWith("Open Social")){
-            widget = widgetMetadataResolverMap.get("OpenSocial").getMetadata(url);
-        }else{
-            // there may be resources in a marketplace store other than W3C & OpenSocial 
-            // gadgets so return null if it isn't one of the supported types in rave.
-            throw new Exception("Unsupported Widget format");
-        }
-        return widget;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.rave.portal.service.WidgetMarketplaceService#addWidget(org.apache.rave.portal.model.Widget)
-     */
-    @Override
-    public Widget addWidget(Widget widget) throws Exception{
-        PortalPreference status = portalPreferenceService.getPreference(PortalPreferenceKeys.INITIAL_WIDGET_STATUS);
-        User user = userService.getAuthenticatedUser();
-        widget.setOwnerId(user.getId());
-        if (status != null && status.getValue().equals("PUBLISHED")){
-            widget.setWidgetStatus(WidgetStatus.PUBLISHED);
-        } else {
-            widget.setWidgetStatus(WidgetStatus.PREVIEW);
-        }
-        widgetService.registerNewWidget(widget);
-        return widget;
-    }
-
     /* (non-Javadoc)
      * @see org.apache.rave.portal.service.WidgetMarketplaceService#getWidget(java.lang.String)
      */
@@ -241,4 +186,14 @@ public class DefaultWidgetMarketplaceSer
         return widget;
     }
 
+    @Override
+    public Widget addWidget(Widget widget) throws Exception {
+        return widgetResolverService.addWidget(widget);
+    }
+
+    @Override
+    public Widget resolveWidgetMetadata(String url, String type) throws Exception {
+       return widgetResolverService.resolveAndDownloadWidgetMetadata(url, type);
+    }
+
 }

Modified: rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceServiceTest.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceServiceTest.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceServiceTest.java (original)
+++ rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetMarketplaceServiceTest.java Mon Dec 17 12:44:47 2012
@@ -25,10 +25,9 @@ import java.util.Map;
 import org.apache.rave.portal.model.Widget;
 import org.apache.rave.portal.model.util.SearchResult;
 import org.apache.rave.portal.service.PortalPreferenceService;
-import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.RemoteWidgetResolverService;
 import org.apache.rave.portal.service.WidgetMarketplaceService;
 import org.apache.rave.portal.service.WidgetMetadataResolver;
-import org.apache.rave.portal.service.WidgetService;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -36,9 +35,7 @@ import static org.easymock.EasyMock.*;
 
 public class DefaultWidgetMarketplaceServiceTest {
 
-    static WidgetService widgetService;
-    static UserService userService;
-    static PortalPreferenceService portalPreferenceService;
+    static RemoteWidgetResolverService widgetResolverService;
     static PortalPreferenceService prefs;
     static WidgetMarketplaceService service;
     static Map<String, WidgetMetadataResolver> widgetMetadataResolverMap;
@@ -46,11 +43,9 @@ public class DefaultWidgetMarketplaceSer
 
     @BeforeClass
     public static void setup(){
-        widgetService = createMock(WidgetService.class);
-        userService = createMock(UserService.class);
         prefs = createMock(PortalPreferenceService.class);
         metadataResolver = new ArrayList<WidgetMetadataResolver>();
-        service = new DefaultWidgetMarketplaceService(widgetService, userService, prefs, metadataResolver);
+        service = new DefaultWidgetMarketplaceService(widgetResolverService, prefs);
     }
 
     @Ignore
@@ -67,7 +62,7 @@ public class DefaultWidgetMarketplaceSer
     @Test
     public void getCategoryResults() throws Exception{
         prefs = createMock(PortalPreferenceService.class);
-        service = new DefaultWidgetMarketplaceService(widgetService, userService, prefs, metadataResolver);
+        service = new DefaultWidgetMarketplaceService(widgetResolverService, prefs);
         SearchResult<Widget> results = service.getWidgetsByCategory("a", 0, 10);
         for (Widget widget: results.getResultSet()){
             System.out.println(widget.getTitle());
@@ -79,7 +74,7 @@ public class DefaultWidgetMarketplaceSer
     @Test
     public void getCategories() throws Exception{
         prefs = createMock(PortalPreferenceService.class);
-        service = new DefaultWidgetMarketplaceService(widgetService, userService, prefs, metadataResolver);
+        service = new DefaultWidgetMarketplaceService(widgetResolverService, prefs);
         List<String> results = service.getCategories();
         for (String category: results){
             System.out.println(category);

Modified: rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/MarketplaceAPI.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/MarketplaceAPI.java?rev=1422906&r1=1422905&r2=1422906&view=diff
==============================================================================
--- rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/MarketplaceAPI.java (original)
+++ rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/MarketplaceAPI.java Mon Dec 17 12:44:47 2012
@@ -63,7 +63,7 @@ public class MarketplaceAPI {
                  Widget widget = null;
                  // TODO - improve info sent back to marketplace, rather then just writing to the console
                  try {
-                    widget =  marketplaceService.getWidgetMetadata(url, providerType);
+                    widget =  marketplaceService.resolveWidgetMetadata(url, providerType);
                     if(widget == null){
                         return null;
                     }