You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by rg...@apache.org on 2010/02/28 03:11:17 UTC
svn commit: r917090 - in
/incubator/wookie/trunk/src/org/apache/wookie/connector/framework:
AbstractWookieConnectorService.java IWookieConnectorService.java User.java
Widget.java
Author: rgardler
Date: Sun Feb 28 02:11:16 2010
New Revision: 917090
URL: http://svn.apache.org/viewvc?rev=917090&view=rev
Log:
Add participants to new widgets
Modified:
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java
incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
Modified: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java?rev=917090&r1=917089&r2=917090&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/AbstractWookieConnectorService.java Sun Feb 28 02:11:16 2010
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
@@ -55,6 +57,7 @@
* @return the ID of the widget instance
* @throws IOException
* @throws SimalRepositoryException
+ *
*/
public WidgetInstance getOrCreateInstance(Widget widget) throws IOException,
WookieConnectorException {
@@ -89,6 +92,8 @@
wr.close();
is.close();
+
+ addParticipant(instance, getCurrentUser());
} catch (MalformedURLException e) {
throw new RuntimeException("URL for supplied Wookie Server is malformed",
e);
@@ -102,6 +107,101 @@
}
/**
+ * @refactor At time of writing the REST API for adding a participant is broken so we are
+ * using the non-REST approach. The code for REST API is commented out and should be used
+ * in the future.
+ */
+ public void addParticipant(WidgetInstance widget, User user) throws WookieConnectorException {
+ /*
+ * REST API approach - REST API is broken at time of writing
+ StringBuilder postdata;
+ try {
+ postdata = new StringBuilder("api_key=");
+ postdata.append(URLEncoder.encode(getConnection().getApiKey(), "UTF-8"));
+ postdata.append("&shareddatakey=");
+ postdata.append(URLEncoder.encode(getConnection().getSharedDataKey(), "UTF-8"));
+ postdata.append("&userid=");
+ postdata.append(URLEncoder.encode(getCurrentUser().getLoginName(), "UTF-8"));
+ postdata.append("&widgetid=");
+ postdata.append(URLEncoder.encode(widget.getId(), "UTF-8"));
+ postdata.append("&participant_id=");
+ postdata.append(URLEncoder.encode(user.getLoginName(), "UTF-8"));
+ postdata.append("&participant_display_name=");
+ postdata.append(URLEncoder.encode(user.getScreenName(), "UTF-8"));
+ postdata.append("&participant_thumbnail_url=");
+ postdata.append(URLEncoder.encode(user.getThumbnailUrl(), "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new WookieConnectorException("Must support UTF-8 encoding", e);
+ }
+
+ URL url = null;
+ try {
+ url = new URL(conn.getURL() + "/participants");
+ URLConnection conn = url.openConnection();
+ conn.setDoOutput(true);
+ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+ wr.write(postdata.toString());
+ wr.flush();
+
+ InputStream is = conn.getInputStream();
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db;
+ db = dbf.newDocumentBuilder();
+ Document xml = db.parse(is);
+ } catch (MalformedURLException e) {
+ throw new WookieConnectorException("Participants rest URL is incorrect: " + url, e);
+ } catch (IOException e) {
+ StringBuilder sb = new StringBuilder("Problem adding a participant. ");
+ sb.append("URL: ");
+ sb.append(url);
+ sb.append(" data: ");
+ sb.append(postdata);
+ throw new WookieConnectorException(sb.toString(), e);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException("Unable to configure XML parser", e);
+ } catch (SAXException e) {
+ throw new RuntimeException("Problem parsing XML from Wookie Server", e);
+ }
+ */
+
+ StringBuilder url;
+ try {
+ url = new StringBuilder(conn.getURL());
+ url.append("/WidgetServiceServlet?");
+ url.append("requestid=addparticipant");
+ url.append("&api_key=");
+ url.append(URLEncoder.encode(getConnection().getApiKey(), "UTF-8"));
+ url.append("&shareddatakey=");
+ url.append(URLEncoder.encode(getConnection().getSharedDataKey(), "UTF-8"));
+ url.append("&userid=");
+ url.append(URLEncoder.encode(getCurrentUser().getLoginName(), "UTF-8"));
+ url.append("&widgetid=");
+ url.append(URLEncoder.encode(widget.getId(), "UTF-8"));
+ url.append("&participant_id=");
+ url.append(URLEncoder.encode(user.getLoginName(), "UTF-8"));
+ url.append("&participant_display_name=");
+ url.append(URLEncoder.encode(user.getScreenName(), "UTF-8"));
+ url.append("&participant_thumbnail_url=");
+ url.append(URLEncoder.encode(user.getThumbnailUrl(), "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new WookieConnectorException("Must support UTF-8 encoding", e);
+ }
+
+ try {
+ HttpURLConnection conn = (HttpURLConnection)new URL(url.toString()).openConnection();
+ conn.disconnect();
+ } catch (MalformedURLException e) {
+ throw new WookieConnectorException("Participants rest URL is incorrect: " + url, e);
+ } catch (IOException e) {
+ StringBuilder sb = new StringBuilder("Problem adding a participant. ");
+ sb.append("URL: ");
+ sb.append(url);
+ throw new WookieConnectorException(sb.toString(), e);
+ }
+ }
+
+ /**
* Get a set of all the available widgets in the server. If there is an error
* communicating with the server return an empty set, or the set received so
* far in order to allow the application to proceed. The application should
Modified: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java?rev=917090&r1=917089&r2=917090&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/IWookieConnectorService.java Sun Feb 28 02:11:16 2010
@@ -56,7 +56,7 @@
public User getUser(String login);
/**
- * Get or create an instance of a widget.
+ * Get or create an instance of a widget. The current user will be added as a participant.
*
* @param widget
* @return the ID of the widget instance
@@ -67,6 +67,16 @@
WookieConnectorException;
/**
+ * Add a participant to a widget.
+ *
+ * @param instance the Widget Instance to add the participant to
+ * @param user the user to add as a participant
+ *
+ * @throws WookieConnectorexception
+ */
+ public void addParticipant(WidgetInstance widget, User user) throws WookieConnectorException;
+
+ /**
* Get a set of all the available widgets in the server. If there is an error
* communicating with the server return an empty set, or the set received so
* far in order to allow the application to proceed. The application should
Modified: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java?rev=917090&r1=917089&r2=917090&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/User.java Sun Feb 28 02:11:16 2010
@@ -65,5 +65,14 @@
*/
public void setScreenName(String screenName) {
this.screenName = screenName;
+ }
+
+ /**
+ * Get the URL for a thumbnail representing this user.
+ * @return
+ */
+ public String getThumbnailUrl() {
+ // FIXME: manage user thumbnails
+ return "http://fixme.org/thumbnail";
}
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java?rev=917090&r1=917089&r2=917090&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/connector/framework/Widget.java Sun Feb 28 02:11:16 2010
@@ -85,7 +85,7 @@
public WidgetInstance addInstance(Document xml) {
Element rootEl = xml.getDocumentElement();
String url = rootEl.getElementsByTagName("url").item(0).getTextContent();
- String id = rootEl.getElementsByTagName("identifier").item(0).getTextContent();
+ String id = getIdentifier();
String title = rootEl.getElementsByTagName("title").item(0).getTextContent();
String height = rootEl.getElementsByTagName("height").item(0).getTextContent();
String width = rootEl.getElementsByTagName("width").item(0).getTextContent();