You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2012/05/30 16:56:14 UTC

svn commit: r1344290 - in /incubator/wookie/trunk: etc/ddl-schema/wookie-schema.xml src/org/apache/wookie/beans/IParticipant.java src/org/apache/wookie/beans/SharedContext.java src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java

Author: scottbw
Date: Wed May 30 14:56:13 2012
New Revision: 1344290

URL: http://svn.apache.org/viewvc?rev=1344290&view=rev
Log:
Added "role" property to Participant to support getHost() and similar methods - see WOOKIE-66

Modified:
    incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
    incubator/wookie/trunk/src/org/apache/wookie/beans/IParticipant.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/SharedContext.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java

Modified: incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml?rev=1344290&r1=1344289&r2=1344290&view=diff
==============================================================================
--- incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml (original)
+++ incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml Wed May 30 14:56:13 2012
@@ -180,6 +180,7 @@
     <column name="participant_display_name" required="true" size="255" type="VARCHAR"/>
     <column name="participant_thumbnail_url" size="1024" type="VARCHAR"/>
     <column name="sharedDataKey" required="true" size="255" type="VARCHAR"/>
+    <column name="role" size="255" type="VARCHAR"/>
   </table>
 
   <table name="Preference">

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/IParticipant.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/IParticipant.java?rev=1344290&r1=1344289&r2=1344290&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/IParticipant.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/IParticipant.java Wed May 30 14:56:13 2012
@@ -23,6 +23,9 @@ package org.apache.wookie.beans;
  */
 public interface IParticipant extends IBean
 {
+	
+	public static final String HOST_ROLE = "host";
+	
     /**
      * Get widget shared data key.
      * 
@@ -78,4 +81,15 @@ public interface IParticipant extends IB
      * @param participantThumbnailUrl participant thumbnail URL
      */
     void setParticipantThumbnailUrl(String participantThumbnailUrl);
+    
+    /**
+     * @return get the role of the participant in the current context
+     */
+    String getRole();
+    
+    /**
+     * Set the role of the participant in the current context
+     * @param role
+     */
+    void setRole(String role);
 }

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/SharedContext.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/SharedContext.java?rev=1344290&r1=1344289&r2=1344290&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/SharedContext.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/SharedContext.java Wed May 30 14:56:13 2012
@@ -41,6 +41,7 @@ import org.apache.wookie.helpers.SharedD
 public class SharedContext {
   
   private String sharedDataKey;
+  private IWidgetInstance widgetInstance;
   
   public SharedContext(String sharedDataKey){
     this.sharedDataKey = sharedDataKey; 
@@ -51,6 +52,7 @@ public class SharedContext {
     // Use the internal shared data key of the instance
     //
     this.sharedDataKey = SharedDataHelper.getInternalSharedDataKey(widgetInstance);
+    this.widgetInstance = widgetInstance;
   }
   
   /**
@@ -190,7 +192,7 @@ public class SharedContext {
     IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
     return persistenceManager.findByValue(IParticipant.class, "sharedDataKey", this.sharedDataKey);
   }
-  
+
   /**
    * Add a participant to a shared context
    * @param participantId the id property of the participant to add
@@ -199,6 +201,17 @@ public class SharedContext {
    * @return true if the participant was successfully added, otherwise false
    */
   public boolean addParticipant(String participantId, String participantDisplayName, String participantThumbnailUrl) {
+	  return addParticipant(participantId, participantDisplayName, participantThumbnailUrl, null);
+  }
+  
+  /**
+   * Add a participant to a shared context
+   * @param participantId the id property of the participant to add
+   * @param participantDisplayName the display name property of the participant to add
+   * @param participantThumbnailUrl the thumbnail url property of the participant to add
+   * @return true if the participant was successfully added, otherwise false
+   */
+  public boolean addParticipant(String participantId, String participantDisplayName, String participantThumbnailUrl, String role) {
 
     //
     // Does participant already exist?
@@ -214,6 +227,7 @@ public class SharedContext {
     participant.setParticipantId(participantId);
     participant.setParticipantDisplayName(participantDisplayName);
     participant.setParticipantThumbnailUrl(participantThumbnailUrl);
+    participant.setRole(role);
     participant.setSharedDataKey(this.sharedDataKey);
     persistenceManager.save(participant);
     return true;
@@ -280,4 +294,39 @@ public class SharedContext {
     if(participants != null && participants.length == 1) return participants[0];
     return null;
   }
+  
+  /**
+   * Get the participant associated with the widget instance as the viewer
+   * @param widgetInstance
+   * @return the IParticipant representing the viewer, or null if no match is found
+   */
+  public IParticipant getViewer(){
+    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
+    Map<String, Object> map = new HashMap<String, Object>();
+    map.put("sharedDataKey", this.sharedDataKey);//$NON-NLS-1$
+    map.put("participantId", this.widgetInstance.getUserId());//$NON-NLS-1$
+    IParticipant [] participants = persistenceManager.findByValues(IParticipant.class, map);
+    if(participants != null && participants.length == 1) return participants[0];
+    return null;
+  }
+  
+  /**
+   * Get the participant designated as the host of the shared context. Note that
+   * if there are multiple hosts, only the first is returned.
+   * @return a participant designated the host, or null if no participant is host
+   */
+  public IParticipant getHost(){
+	  for (IParticipant participant : this.getParticipants()){
+		  if (participant.getRole().equals(IParticipant.HOST_ROLE)) return participant;
+	  }
+	  return null;
+  }
+  
+  public IParticipant[] getHosts(){
+	    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
+	    Map<String, Object> map = new HashMap<String, Object>();
+	    map.put("sharedDataKey", this.sharedDataKey);//$NON-NLS-1$
+	    map.put("role", IParticipant.HOST_ROLE); //$NON-NLS-1$
+	    return persistenceManager.findByValues(IParticipant.class, map);
+  }
 }

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java?rev=1344290&r1=1344289&r2=1344290&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ParticipantImpl.java Wed May 30 14:56:13 2012
@@ -25,6 +25,7 @@ import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 import javax.persistence.Version;
 
+import org.apache.openjpa.persistence.Type;
 import org.apache.wookie.beans.IParticipant;
 
 /**
@@ -64,6 +65,11 @@ public class ParticipantImpl implements 
     @Basic(optional=false)
     @Column(name="sharedDataKey", nullable=false)
     private String sharedDataKey;
+    
+    @Basic
+    @Column(name="role", nullable=false)
+    @Type(String.class)
+    private String role;
 
     /* (non-Javadoc)
      * @see org.apache.wookie.beans.IBean#getId()
@@ -136,4 +142,19 @@ public class ParticipantImpl implements 
     {
         this.sharedDataKey = sharedDataKey;
     }
+
+	/* (non-Javadoc)
+	 * @see org.apache.wookie.beans.IParticipant#getRole()
+	 */
+	public String getRole() {
+		return role;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.wookie.beans.IParticipant#setRole(java.lang.String)
+	 */
+	public void setRole(String role) {
+		this.role = role;
+	}
+
 }