1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.io.BufferedReader; |
24 |
|
import java.io.InputStreamReader; |
25 |
|
import java.net.URL; |
26 |
|
|
27 |
|
import jalview.bin.Cache; |
28 |
|
import jalview.bin.Console; |
29 |
|
import jalview.util.HttpUtils; |
30 |
|
import jalview.util.MessageManager; |
31 |
|
|
|
|
| 34.9% |
Uncovered Elements: 54 (83) |
Complexity: 25 |
Complexity Density: 0.54 |
|
32 |
|
public class UserQuestionnaireCheck implements Runnable |
33 |
|
{ |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
String url = null; |
41 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
42 |
17 |
UserQuestionnaireCheck(String url)... |
43 |
|
{ |
44 |
17 |
if (url.indexOf("questionnaire.pl") == -1) |
45 |
|
{ |
46 |
0 |
Console.error("'" + url |
47 |
|
+ "' is an Invalid URL for the checkForQuestionnaire() method.\n" |
48 |
|
+ "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface."); |
49 |
|
} |
50 |
|
else |
51 |
|
{ |
52 |
17 |
this.url = url; |
53 |
|
} |
54 |
|
} |
55 |
|
|
56 |
|
String qid = null, rid = null; |
57 |
|
|
|
|
| 38.5% |
Uncovered Elements: 16 (26) |
Complexity: 6 |
Complexity Density: 0.38 |
|
58 |
17 |
private boolean checkresponse(URL qurl) throws Exception... |
59 |
|
{ |
60 |
17 |
Console.debug("Checking Response for : " + qurl); |
61 |
17 |
boolean prompt = false; |
62 |
|
|
63 |
|
|
64 |
17 |
BufferedReader br = new BufferedReader( |
65 |
|
new InputStreamReader(HttpUtils.openStream(qurl))); |
66 |
17 |
String qresp; |
67 |
? |
while ((qresp = br.readLine()) != null) |
68 |
|
{ |
69 |
17 |
if (qresp.indexOf("NOTYET:") == 0) |
70 |
|
{ |
71 |
0 |
prompt = true; |
72 |
|
} |
73 |
|
else |
74 |
|
{ |
75 |
17 |
if (qresp.indexOf("QUESTIONNAIRE:") == 0) |
76 |
|
{ |
77 |
|
|
78 |
0 |
int p = qresp.indexOf(':', 14); |
79 |
0 |
if (p > -1) |
80 |
|
{ |
81 |
0 |
rid = null; |
82 |
0 |
qid = qresp.substring(14, p); |
83 |
0 |
if (p < (qresp.length() - 1)) |
84 |
|
{ |
85 |
0 |
rid = qresp.substring(p + 1); |
86 |
0 |
prompt = true; |
87 |
|
} |
88 |
|
} |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
17 |
return prompt; |
93 |
|
} |
94 |
|
|
|
|
| 26.5% |
Uncovered Elements: 36 (49) |
Complexity: 17 |
Complexity Density: 0.63 |
|
95 |
17 |
public void run()... |
96 |
|
{ |
97 |
17 |
if (url == null) |
98 |
|
{ |
99 |
0 |
return; |
100 |
|
} |
101 |
17 |
boolean prompt = false; |
102 |
17 |
try |
103 |
|
{ |
104 |
|
|
105 |
17 |
String lastq = Cache.getProperty("QUESTIONNAIRE"); |
106 |
17 |
if (lastq == null) |
107 |
|
{ |
108 |
17 |
prompt = checkresponse(new URL(url |
109 |
17 |
+ (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1")); |
110 |
|
} |
111 |
|
else |
112 |
|
{ |
113 |
0 |
String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") |
114 |
|
+ "checkresponse=1"; |
115 |
|
|
116 |
0 |
String qqid = lastq.indexOf(':') > -1 |
117 |
|
? lastq.substring(0, lastq.indexOf(':')) |
118 |
|
: null; |
119 |
0 |
if (qqid != null && qqid != "null" && qqid.length() > 0) |
120 |
|
{ |
121 |
0 |
qurl += "&qid=" + qqid; |
122 |
0 |
qid = qqid; |
123 |
0 |
String qrid = lastq.substring(lastq.indexOf(':') + 1); |
124 |
|
|
125 |
0 |
if (qrid != null && !qrid.equals("null")) |
126 |
|
{ |
127 |
0 |
rid = qrid; |
128 |
0 |
qurl += "&rid=" + qrid; |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
0 |
prompt = checkresponse(new URL(qurl)); |
133 |
|
} |
134 |
17 |
if (qid != null && rid != null) |
135 |
|
{ |
136 |
|
|
137 |
0 |
Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid); |
138 |
|
} |
139 |
17 |
if (prompt) |
140 |
|
{ |
141 |
0 |
String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid=" |
142 |
|
+ qid + "&rid=" + rid; |
143 |
0 |
Console.info("Prompting user for questionnaire at " + qurl); |
144 |
0 |
int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, |
145 |
|
MessageManager.getString("label.jalview_new_questionnaire"), |
146 |
|
MessageManager.getString("label.jalview_user_survey"), |
147 |
|
JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE); |
148 |
|
|
149 |
0 |
if (reply == JvOptionPane.YES_OPTION) |
150 |
|
{ |
151 |
0 |
Console.debug("Opening " + qurl); |
152 |
0 |
jalview.util.BrowserLauncher.openURL(qurl); |
153 |
|
} |
154 |
|
} |
155 |
|
} catch (Exception e) |
156 |
|
{ |
157 |
0 |
Console.warn("When trying to access questionnaire URL " + url, e); |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
} |