rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scot...@apache.org
Subject svn commit: r1101982 - in /incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal: service/WidgetService.java service/impl/DefaultWidgetService.java web/controller/HomeController.java
Date Wed, 11 May 2011 17:13:28 GMT
Author: scottbw
Date: Wed May 11 17:13:27 2011
New Revision: 1101982

URL: http://svn.apache.org/viewvc?rev=1101982&view=rev
Log:
Added support for Widget service to process W3C Widgets using Wookie (not currently hooked
in as we need the Wookie Connector in Maven). See RAVE-30.

Added:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/HomeController.java

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java?rev=1101982&r1=1101981&r2=1101982&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
Wed May 11 17:13:27 2011
@@ -18,5 +18,18 @@
  */
 package org.apache.rave.portal.service;
 
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.Widget;
+
 public interface WidgetService {
+    
+    /**
+     * Gets the object that represents the metadata about the widget for 
+     * the viewer in the current context
+     * @param viewer the current logged in user
+     * @param context the context identifier for where the widget is displayed (e.g. regionwidget
id)
+     * @param widget the default widget
+     * @return valid widget
+     */
+    Widget getWidget(User viewer, String context, Widget widget);
 }
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java?rev=1101982&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
Wed May 11 17:13:27 2011
@@ -0,0 +1,97 @@
+/*
+ * 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.io.IOException;
+
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.service.WidgetService;
+//import org.apache.wookie.connector.framework.WidgetInstance;
+//import org.apache.wookie.connector.framework.WookieConnectorException;
+//import org.apache.wookie.connector.framework.WookieConnectorService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DefaultWidgetService implements WidgetService {
+	
+	// TODO uncomment when Wookie Connector is available in Maven
+    
+    private static final String WOOKIE_SERVER_URL = "http://localhost:8080/wookie";
+    private static final String WOOKIE_API_KEY = "TEST"; 
+    //private static WookieConnectorService  connectorService;
+    
+    public DefaultWidgetService(){   
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.rave.portal.service.WidgetService#getWidget(org.apache.rave.portal.model.User)
+     */
+    @Override
+    public Widget getWidget(User viewer, String context, Widget widget) {
+        //if (widget.getType().equals("W3C")) return getWidgetForViewer(widget, context,
viewer);  
+        return widget;
+    }
+    
+
+    /*
+    private Widget getWidgetForViewer(Widget widget, String context, User viewer){
+        try {
+            connectorService = getWookieConnectorService(WOOKIE_SERVER_URL, WOOKIE_API_KEY,
context);
+            org.apache.wookie.connector.framework.User user = new org.apache.wookie.connector.framework.User(String.valueOf(viewer.getUserId()),
viewer.getUsername());
+            connectorService.setCurrentUser(user);
+            
+            System.out.println("Getting widget:"+widget.getUrl()+" from:" +connectorService.getConnection().getURL());
+            WidgetInstance instance = connectorService.getOrCreateInstance(widget.getUrl());
+            return createWidget(instance);
+        } catch (WookieConnectorException e) {
+            e.printStackTrace();
+            return null;
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * Create a Rave Widget object for the widget instance.
+     * This is a transient object and is not persisted
+     * @return
+     *
+    private Widget createWidget(WidgetInstance instance){
+        Widget widget = new Widget();
+        widget.setUrl(instance.getUrl());
+        widget.setTitle(instance.getTitle());
+        widget.setType("W3C");
+        return widget;
+    }
+    
+    
+    // Get the wookie service connector
+    private WookieConnectorService getWookieConnectorService(String serverURL, String apiKey,
String sharedDataKey ) throws WookieConnectorException {
+      if (connectorService == null) {
+        connectorService = new WookieConnectorService(serverURL, apiKey, sharedDataKey);
+      }
+      return connectorService;
+    }
+    
+    */
+    
+
+}

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/HomeController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/HomeController.java?rev=1101982&r1=1101981&r2=1101982&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/HomeController.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/HomeController.java
Wed May 11 17:13:27 2011
@@ -19,9 +19,12 @@
 package org.apache.rave.portal.web.controller;
 
 import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.Region;
+import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.service.PageService;
 import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.WidgetService;
 import org.apache.rave.portal.web.util.ModelKeys;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -40,17 +43,26 @@ import java.util.List;
 public class HomeController {
     private PageService pageService;
     private UserService userService;
+    private WidgetService widgetService;
 
     @Autowired
-    public HomeController(PageService pageService, UserService userService) {
+    public HomeController(PageService pageService, UserService userService, WidgetService
widgetService) {
         this.pageService = pageService;
         this.userService = userService;
+        this.widgetService = widgetService;
     }
 
     @RequestMapping(value = {"/", "/index.html"})
     public String getHome(Model model) {
         User user = userService.getAuthenticatedUser();
         List<Page> pages = pageService.getAllPages(user.getUserId());
+        for (Page page: pages){
+            for (Region region: page.getRegions()){
+                for (RegionWidget regionWidget: region.getRegionWidgets()){
+                    regionWidget.setWidget(widgetService.getWidget(user, regionWidget.getId().toString(),
regionWidget.getWidget()));
+                }
+            }
+        }
         model.addAttribute(ModelKeys.PAGES, pages);
         return "home";
     }



Mime
View raw message