Author: scottbw
Date: Wed May 30 14:58:57 2012
New Revision: 1344293

URL: http://svn.apache.org/viewvc?rev=1344293&view=rev
Log:
Added wave.getHost() and wave.getHosts() methods to the Wave API. See WOOKIE-66.

Modified:
    incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml
    incubator/wookie/trunk/features/wave/wave.js
    incubator/wookie/trunk/src/org/apache/wookie/feature/wave/IWaveAPI.java
    incubator/wookie/trunk/src/org/apache/wookie/feature/wave/WaveAPIImpl.java

Modified: incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml?rev=1344293&r1=1344292&r2=1344293&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml (original)
+++ incubator/wookie/trunk/WebContent/WEB-INF/dwr.xml Wed May 30 14:58:57 2012
@@ -24,7 +24,9 @@
       <include method="state"/>   
       <include method="submitDelta"/> 
       <include method="getParticipants"/>
-      <include method="getViewer"/>      
+      <include method="getViewer"/>   
+      <include method="getHost"/>    
+      <include method="getHosts"/>      
     </create>
 
     <create creator="new" javascript="OAuthConnector" scope="application">

Modified: incubator/wookie/trunk/features/wave/wave.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/features/wave/wave.js?rev=1344293&r1=1344292&r2=1344293&view=diff
==============================================================================
--- incubator/wookie/trunk/features/wave/wave.js (original)
+++ incubator/wookie/trunk/features/wave/wave.js Wed May 30 14:58:57 2012
@@ -81,6 +81,7 @@
  */
  wave = new function Wave(){
        this.participants = null;
+    this.hosts = null;
        this.viewer = null;
     this.callback = null;
     this.pcallback = null;
@@ -94,6 +95,8 @@
                dwr.engine.beginBatch();
                WaveImpl.getParticipants(Widget.instanceid_key, 
this.setParticipants);
                WaveImpl.getViewer(Widget.instanceid_key, this.setViewer);
+        WaveImpl.getHost(Widget.instanceid_key, this.setHost);
+        WaveImpl.getHosts(Widget.instanceid_key, this.setHosts);
         WaveImpl.state(Widget.instanceid_key, this.setState);
                dwr.engine.endBatch({async:false});             
         dwr.engine.setActiveReverseAjax(true);
@@ -116,6 +119,19 @@
         }
     }
     
+    this.setHosts = function(parts){
+        var json = parts;
+        if (json && json!=null && json!=""){
+            var obj = eval('('+json+')');
+            wave.hosts = obj.Participants;
+            for(participant in wave.hosts){
+                wave.hosts[participant].getDisplayName = function(){return 
this.participant_display_name}
+                wave.hosts[participant].getThumbnailUrl = function(){return 
this.participant_thumbnail_url};
+                wave.hosts[participant].getId = function(){return 
this.participant_id};        
+            }
+        }
+    }
+    
     this.setViewer = function(v){
         if (v && v!=null && v!=""){ 
             var vobj = eval('('+v+')');
@@ -125,6 +141,16 @@
             wave.viewer.getId = function(){return this.participant_id};
         }
        }
+    
+    this.setHost = function(v){
+        if (v && v!=null && v!=""){ 
+            var vobj = eval('('+v+')');
+            wave.host = vobj.Participant;
+            wave.host.getDisplayName = function(){return 
this.participant_display_name};
+            wave.host.getThumbnailUrl = function(){return 
this.participant_thumbnail_url};
+            wave.host.getId = function(){return this.participant_id};
+        }
+       }
 
     
     //////////////////////////////////////////////////
@@ -175,7 +201,11 @@
        }
     
     this.getHost = function(){
-        return null; // NOT IMPLEMENTED
+        return this.host;
+    }
+    
+    this.getHosts = function(){
+        return this.hosts;
     }
     
     this.getParticipantById = function(id){

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/feature/wave/IWaveAPI.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/feature/wave/IWaveAPI.java?rev=1344293&r1=1344292&r2=1344293&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/feature/wave/IWaveAPI.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/feature/wave/IWaveAPI.java Wed 
May 30 14:58:57 2012
@@ -56,5 +56,13 @@ public interface IWaveAPI{
         * @return
         */
        public String getHost(String id_key);
+       
+       /**
+        * Returns the hosts (owners) of the widget, typically the
+        * owner of the context in which it has been instantiated
+        * @param id_key
+        * @return
+        */
+       public String getHosts(String id_key);
 
 }

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/feature/wave/WaveAPIImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/feature/wave/WaveAPIImpl.java?rev=1344293&r1=1344292&r2=1344293&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/feature/wave/WaveAPIImpl.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/feature/wave/WaveAPIImpl.java 
Wed May 30 14:58:57 2012
@@ -71,8 +71,12 @@ public class WaveAPIImpl implements IFea
        /* (non-Javadoc)
         * @see 
org.apache.wookie.feature.wave.IWaveAPI#getHost(java.lang.String)
         */
-       public String getHost(String idKey) {
-               // TODO FIXME see WOOKIE-66
+       public String getHost(String id_key) {
+               SharedContext sharedContext = this.getSharedContext(id_key);
+               if (sharedContext != null){
+                       IParticipant host = sharedContext.getHost();
+                       if (host != null) return 
ParticipantHelper.createJSONParticipantDocument(host);
+               }
                return null;
        }
 
@@ -105,29 +109,41 @@ public class WaveAPIImpl implements IFea
         * @see 
org.apache.wookie.feature.wave.IWaveAPI#getParticipants(java.lang.String)
         */
        public String getParticipants(String id_key) {
-               HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
-               Messages localizedMessages = 
LocaleHandler.localizeMessages(request);
-               if(id_key == null) return 
localizedMessages.getString("WidgetAPIImpl.0"); //$NON-NLS-1$
-               IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
-               IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
-               if(widgetInstance==null) return 
localizedMessages.getString("WidgetAPIImpl.0"); //$NON-NLS-1$
-               IParticipant[] participants = new 
SharedContext(widgetInstance).getParticipants();
-               return 
ParticipantHelper.createJSONParticipantsDocument(participants);
+               SharedContext sharedContext = this.getSharedContext(id_key);
+               if (sharedContext != null){
+                       return 
ParticipantHelper.createJSONParticipantsDocument(sharedContext.getParticipants());
       
+               } else {
+                       Messages localizedMessages = 
LocaleHandler.localizeMessages(WebContextFactory.get().getHttpServletRequest());
+                       return localizedMessages.getString("WidgetAPIImpl.0"); 
//$NON-NLS-1$
+               }
        }
        
+       
+       
+       /* (non-Javadoc)
+        * @see 
org.apache.wookie.feature.wave.IWaveAPI#getHosts(java.lang.String)
+        */
+       public String getHosts(String id_key) {
+               SharedContext sharedContext = this.getSharedContext(id_key);
+               if (sharedContext != null){
+                       return 
ParticipantHelper.createJSONParticipantsDocument(sharedContext.getHosts());     
 
+               } else {
+                       Messages localizedMessages = 
LocaleHandler.localizeMessages(WebContextFactory.get().getHttpServletRequest());
+                       return localizedMessages.getString("WidgetAPIImpl.0"); 
//$NON-NLS-1$
+               }
+       }
+
        /* (non-Javadoc)
         * @see 
org.apache.wookie.feature.wave.IWaveAPI#getViewer(java.lang.String)
         */
        public String getViewer(String id_key) {
-               HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
-               Messages localizedMessages = 
LocaleHandler.localizeMessages(request);
-               if(id_key == null) return 
localizedMessages.getString("WidgetAPIImpl.0"); //$NON-NLS-1$
-        IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
-        IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
-               if(widgetInstance == null) return 
localizedMessages.getString("WidgetAPIImpl.0"); //$NON-NLS-1$
-               IParticipant participant = new 
SharedContext(widgetInstance).getViewer(widgetInstance);
-               if (participant != null) return 
ParticipantHelper.createJSONParticipantDocument(participant); //$NON-NLS-1$
-               return null; // no viewer i.e. widget is anonymous
+               SharedContext sharedContext = this.getSharedContext(id_key);
+               if (sharedContext != null){
+                       return 
ParticipantHelper.createJSONParticipantDocument(sharedContext.getViewer());     
 
+               } else {
+                       Messages localizedMessages = 
LocaleHandler.localizeMessages(WebContextFactory.get().getHttpServletRequest());
+                       return localizedMessages.getString("WidgetAPIImpl.0"); 
//$NON-NLS-1$
+               }
        }
        
        /* (non-Javadoc)
@@ -146,5 +162,14 @@ public class WaveAPIImpl implements IFea
                Notifier.notifySiblings(widgetInstance);
                return "okay"; //$NON-NLS-1$
        }
+       
+       private SharedContext getSharedContext(String id_key){
+        IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
+        IWidgetInstance widgetInstance = 
persistenceManager.findWidgetInstanceByIdKey(id_key);
+               if (widgetInstance != null){
+                       return new SharedContext(widgetInstance);
+               }
+               return null;
+       }
 
 }


Reply via email to