summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCheng Chen2012-05-22 01:41:40 (EDT)
committer Cheng Chen2012-05-22 01:41:40 (EDT)
commit3fed5ad920c27115ff471f8d5e8650bf1f3ba56c (patch)
tree55ecfd0942b0560bc9e404e325a783ebe48e51b2
parent0964802ee63c31e770423ac52792e30a4cfdc353 (diff)
downloadorg.eclipse.recommenders-3fed5ad920c27115ff471f8d5e8650bf1f3ba56c.zip
org.eclipse.recommenders-3fed5ad920c27115ff471f8d5e8650bf1f3ba56c.tar.gz
org.eclipse.recommenders-3fed5ad920c27115ff471f8d5e8650bf1f3ba56c.tar.bz2
[snipmatch] switch to remote client for SendFeedbackThreadrefs/changes/68/6068/1
Change-Id: Icd0228ef9c048692161480bb7f42ad923c49b06c Signed-off-by: Cheng Chen <chengchendoc@gmail.com>
-rw-r--r--[-rwxr-xr-x]plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/SendFeedbackThread.java346
1 files changed, 172 insertions, 174 deletions
diff --git a/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/SendFeedbackThread.java b/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/SendFeedbackThread.java
index 76427b8..ad3e938 100755..100644
--- a/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/SendFeedbackThread.java
+++ b/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/SendFeedbackThread.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
-*/
+ */
package org.eclipse.recommenders.snipmatch.web;
@@ -23,180 +23,178 @@ import org.eclipse.recommenders.snipmatch.core.MatchNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
-
/**
* A misnomer. This class is used to send feedback as well as to log usage.
*/
public class SendFeedbackThread extends PostThread {
-
- String query;
- MatchNode match;
- String comment;
- int rating;
- boolean flag;
- boolean isLog;
- boolean isStartup;
- boolean used;
- long clientId;
- long waitTime;
- ISendFeedbackListener listener;
-
- public SendFeedbackThread(MatchClient client, String query, MatchNode match,
- String comment, int rating, boolean flag, boolean isLog, boolean isStartup, long clientId,
- boolean used, long waitTime, ISendFeedbackListener listener) {
-
- super(client, MatchClient.FEEDBACK_URL);
- this.query = query;
- this.match = match;
- this.comment = comment;
- this.rating = rating;
- this.flag = flag;
- this.isLog = isLog;
- this.isStartup = isStartup;
- this.clientId = clientId;
- this.used = used;
- this.waitTime = waitTime;
- this.listener = listener;
- }
-
- @Override
- public void run() {
-
- if (!client.isLoggedIn() && !isStartup) {
- listener.sendFeedbackFailed("User not authenticated.");
- done = true;
- return;
- }
-
- try {
- sleep(waitTime);
- }
- catch (Exception e) {
- e.printStackTrace();
- listener.sendFeedbackFailed("Client thread error.");
- done = true;
- return;
- }
-
- String feedbackString = buildFeedbackString();
-
- if (feedbackString == null) {
- listener.sendFeedbackFailed("Client XML error.");
- done = true;
- return;
- }
-
- if (client.isLoggedIn()) {
-
- addParameter("username", client.getUsername());
- addParameter("password", client.getPassword());
- }
-
- addParameter("clientName", client.getName());
- addParameter("clientVersion", client.getVersion());
- addParameter("feedbackXML", feedbackString);
- addParameter("clientId", "" + clientId);
-
- if (isLog) addParameter("comment", "log");
- else if (isStartup) addParameter("comment", "startup");
-
- if (done) return;
-
- InputStream response = post();
-
- if (response == null) {
- listener.sendFeedbackFailed("Connection error.");
- done = true;
- return;
- }
-
- if (done) return;
-
- DocumentBuilderFactory dbf;
- DocumentBuilder db;
- Document responseXml;
-
- try {
-
- dbf = DocumentBuilderFactory.newInstance();
- db = dbf.newDocumentBuilder();
- responseXml = db.parse(response);
- }
- catch (Exception e) {
-
- e.printStackTrace();
- listener.sendFeedbackFailed("Bad response format.");
- done = true;
- return;
- }
-
- String msg = responseXml.getDocumentElement().getTextContent();
-
- if (msg.equals("Flagged.")) {
- listener.sendFeedbackSucceeded();
- }
- else {
- listener.sendFeedbackFailed(msg);
- }
-
- done = true;
- }
-
- private String buildFeedbackString() {
-
- if (isStartup) return "";
-
- DocumentBuilderFactory dbf;
- DocumentBuilder db;
- Document doc;
-
- try {
- dbf = DocumentBuilderFactory.newInstance();
- db = dbf.newDocumentBuilder();
- doc = db.newDocument();
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
-
- Element rootNode = doc.createElement("feedback");
- doc.appendChild(rootNode);
-
- rootNode.setAttribute("effect", "" + ((EffectMatchNode) match).getEffect().getId());
-
- Element queryNode = doc.createElement("query");
- rootNode.appendChild(queryNode);
- queryNode.setTextContent(query);
-
- if (isLog) {
-
- rootNode.setAttribute("serverTime", "" + client.getServerProcessingTime());
- rootNode.setAttribute("clientTime", "" + client.getProcessingTime());
- rootNode.setAttribute("used", "" + used);
- }
- else {
-
- rootNode.setAttribute("rating", "" + rating);
- rootNode.setAttribute("flag", "" + flag);
-
- Element commentNode = doc.createElement("comment");
- rootNode.appendChild(commentNode);
- if (comment != null) commentNode.setTextContent(comment);
- }
-
- StringWriter sw = new StringWriter();
-
- try {
- Transformer tr = TransformerFactory.newInstance().newTransformer();
- tr.transform(new DOMSource(doc), new StreamResult(sw));
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
-
- return sw.toString();
- }
-}
+
+ String query;
+ MatchNode match;
+ String comment;
+ int rating;
+ boolean flag;
+ boolean isLog;
+ boolean isStartup;
+ boolean used;
+ long clientId;
+ long waitTime;
+ ISendFeedbackListener listener;
+
+ public SendFeedbackThread(RemoteMatchClient client, String query, MatchNode match, String comment, int rating,
+ boolean flag, boolean isLog, boolean isStartup, long clientId, boolean used, long waitTime,
+ ISendFeedbackListener listener) {
+
+ super(client, RemoteMatchClient.FEEDBACK_URL);
+ this.query = query;
+ this.match = match;
+ this.comment = comment;
+ this.rating = rating;
+ this.flag = flag;
+ this.isLog = isLog;
+ this.isStartup = isStartup;
+ this.clientId = clientId;
+ this.used = used;
+ this.waitTime = waitTime;
+ this.listener = listener;
+ }
+
+ @Override
+ public void run() {
+
+ if (!client.isLoggedIn() && !isStartup) {
+ listener.sendFeedbackFailed("User not authenticated.");
+ done = true;
+ return;
+ }
+
+ try {
+ sleep(waitTime);
+ } catch (Exception e) {
+ e.printStackTrace();
+ listener.sendFeedbackFailed("Client thread error.");
+ done = true;
+ return;
+ }
+
+ String feedbackString = buildFeedbackString();
+
+ if (feedbackString == null) {
+ listener.sendFeedbackFailed("Client XML error.");
+ done = true;
+ return;
+ }
+
+ if (client.isLoggedIn()) {
+
+ addParameter("username", client.getUsername());
+ addParameter("password", client.getPassword());
+ }
+
+ addParameter("clientName", client.getName());
+ addParameter("clientVersion", client.getVersion());
+ addParameter("feedbackXML", feedbackString);
+ addParameter("clientId", "" + clientId);
+
+ if (isLog)
+ addParameter("comment", "log");
+ else if (isStartup)
+ addParameter("comment", "startup");
+
+ if (done)
+ return;
+
+ InputStream response = post();
+
+ if (response == null) {
+ listener.sendFeedbackFailed("Connection error.");
+ done = true;
+ return;
+ }
+
+ if (done)
+ return;
+
+ DocumentBuilderFactory dbf;
+ DocumentBuilder db;
+ Document responseXml;
+
+ try {
+
+ dbf = DocumentBuilderFactory.newInstance();
+ db = dbf.newDocumentBuilder();
+ responseXml = db.parse(response);
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ listener.sendFeedbackFailed("Bad response format.");
+ done = true;
+ return;
+ }
+
+ String msg = responseXml.getDocumentElement().getTextContent();
+
+ if (msg.equals("Flagged.")) {
+ listener.sendFeedbackSucceeded();
+ } else {
+ listener.sendFeedbackFailed(msg);
+ }
+
+ done = true;
+ }
+
+ private String buildFeedbackString() {
+
+ if (isStartup)
+ return "";
+
+ DocumentBuilderFactory dbf;
+ DocumentBuilder db;
+ Document doc;
+
+ try {
+ dbf = DocumentBuilderFactory.newInstance();
+ db = dbf.newDocumentBuilder();
+ doc = db.newDocument();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ Element rootNode = doc.createElement("feedback");
+ doc.appendChild(rootNode);
+
+ rootNode.setAttribute("effect", "" + ((EffectMatchNode) match).getEffect().getId());
+
+ Element queryNode = doc.createElement("query");
+ rootNode.appendChild(queryNode);
+ queryNode.setTextContent(query);
+
+ if (isLog) {
+
+ rootNode.setAttribute("serverTime", "" + client.getServerProcessingTime());
+ rootNode.setAttribute("clientTime", "" + client.getProcessingTime());
+ rootNode.setAttribute("used", "" + used);
+ } else {
+
+ rootNode.setAttribute("rating", "" + rating);
+ rootNode.setAttribute("flag", "" + flag);
+
+ Element commentNode = doc.createElement("comment");
+ rootNode.appendChild(commentNode);
+ if (comment != null)
+ commentNode.setTextContent(comment);
+ }
+
+ StringWriter sw = new StringWriter();
+
+ try {
+ Transformer tr = TransformerFactory.newInstance().newTransformer();
+ tr.transform(new DOMSource(doc), new StreamResult(sw));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return sw.toString();
+ }
+} \ No newline at end of file