Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.gui

File UserQuestionnaireCheck.java

 

Coverage histogram

../../img/srcFileCovDistChart4.png
49% of files have more coverage

Code metrics

34
46
3
1
162
118
25
0.54
15.33
3
8.33

Classes

Class Line # Actions
UserQuestionnaireCheck 33 46 25
0.349397634.9%
 

Contributing tests

This file is covered by 37 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23   
24    import java.io.BufferedReader;
25    import java.io.InputStreamReader;
26    import java.net.URL;
27   
28    import jalview.bin.Cache;
29    import jalview.bin.Console;
30    import jalview.util.HttpUtils;
31    import jalview.util.MessageManager;
32   
 
33    public class UserQuestionnaireCheck implements Runnable
34    {
35    /**
36    * Implements the client side machinery for detecting a new questionnaire,
37    * checking if the user has responded to an existing one, and prompting the
38    * user for responding to a questionnaire. This is intended to work with the
39    * perl CGI scripts checkresponder.pl and questionnaire.pl
40    */
41    String url = null;
42   
 
43  39 toggle UserQuestionnaireCheck(String url)
44    {
45  39 if (url.indexOf("questionnaire.pl") == -1)
46    {
47  0 Console.error("'" + url
48    + "' is an Invalid URL for the checkForQuestionnaire() method.\n"
49    + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
50    }
51    else
52    {
53  39 this.url = url;
54    }
55    }
56   
57    String qid = null, rid = null;
58   
 
59  39 toggle private boolean checkresponse(URL qurl) throws Exception
60    {
61  39 Console.debug("Checking Response for : " + qurl);
62  39 boolean prompt = false;
63    // see if we have already responsed to this questionnaire or get a new
64    // qid/rid pair
65  39 BufferedReader br = new BufferedReader(
66    new InputStreamReader(HttpUtils.openStream(qurl)));
67  39 String qresp;
68  ? while ((qresp = br.readLine()) != null)
69    {
70  39 if (qresp.indexOf("NOTYET:") == 0)
71    {
72  0 prompt = true; // not yet responded under that ID
73    }
74    else
75    {
76  39 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
77    {
78    // QUESTIONNAIRE:qid:rid for the latest questionnaire.
79  0 int p = qresp.indexOf(':', 14);
80  0 if (p > -1)
81    {
82  0 rid = null;
83  0 qid = qresp.substring(14, p);
84  0 if (p < (qresp.length() - 1))
85    {
86  0 rid = qresp.substring(p + 1);
87  0 prompt = true; // this is a new qid/rid pair
88    }
89    }
90    }
91    }
92    }
93  39 return prompt;
94    }
95   
 
96  39 toggle public void run()
97    {
98  39 if (url == null)
99    {
100  0 return;
101    }
102  39 boolean prompt = false;
103  39 try
104    {
105    // First - check to see if wee have an old questionnaire/response id pair.
106  39 String lastq = Cache.getProperty("QUESTIONNAIRE");
107  39 if (lastq == null)
108    {
109  39 prompt = checkresponse(new URL(url
110  39 + (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1"));
111    }
112    else
113    {
114  0 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?")
115    + "checkresponse=1";
116    // query the server with the old qid/id pair
117  0 String qqid = lastq.indexOf(':') > -1
118    ? lastq.substring(0, lastq.indexOf(':'))
119    : null;
120  0 if (qqid != null && qqid != "null" && qqid.length() > 0)
121    {
122  0 qurl += "&qid=" + qqid;
123  0 qid = qqid;
124  0 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve
125    // old rid
126  0 if (qrid != null && !qrid.equals("null"))
127    {
128  0 rid = qrid;
129  0 qurl += "&rid=" + qrid;
130    }
131    }
132    // see if we have already responsed to this questionnaire.
133  0 prompt = checkresponse(new URL(qurl));
134    }
135  39 if (qid != null && rid != null)
136    {
137    // Update our local property cache with latest qid and rid
138  0 Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
139    }
140  39 if (prompt)
141    {
142  0 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid="
143    + qid + "&rid=" + rid;
144  0 Console.info("Prompting user for questionnaire at " + qurl);
145  0 int reply = JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(),
146    MessageManager.getString("label.jalview_new_questionnaire"),
147    MessageManager.getString("label.jalview_user_survey"),
148    JvOptionPane.YES_NO_OPTION, JvOptionPane.QUESTION_MESSAGE);
149   
150  0 if (reply == JvOptionPane.YES_OPTION)
151    {
152  0 Console.debug("Opening " + qurl);
153  0 jalview.util.BrowserLauncher.openURL(qurl);
154    }
155    }
156    } catch (Exception e)
157    {
158  0 Console.warn("When trying to access questionnaire URL " + url, e);
159    }
160    }
161   
162    }