Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File UserQuestionnaireCheck.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% 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 31 46 25
0.00%
 

Contributing tests

No tests hitting this source file were found.

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    import jalview.util.MessageManager;
24   
25    import java.io.BufferedReader;
26    import java.io.InputStreamReader;
27    import java.net.URL;
28   
29    import javax.swing.JOptionPane;
30   
 
31    public class UserQuestionnaireCheck implements Runnable
32    {
33    /**
34    * Implements the client side machinery for detecting a new questionnaire,
35    * checking if the user has responded to an existing one, and prompting the
36    * user for responding to a questionnaire. This is intended to work with the
37    * perl CGI scripts checkresponder.pl and questionnaire.pl
38    */
39    String url = null;
40   
 
41  0 toggle UserQuestionnaireCheck(String url)
42    {
43  0 if (url.indexOf("questionnaire.pl") == -1)
44    {
45  0 jalview.bin.Cache.log.error("'" + url
46    + "' is an Invalid URL for the checkForQuestionnaire() method.\n"
47    + "This argument is only for questionnaires derived from jalview's questionnaire.pl cgi interface.");
48    }
49    else
50    {
51  0 this.url = url;
52    }
53    }
54   
55    String qid = null, rid = null;
56   
 
57  0 toggle private boolean checkresponse(URL qurl) throws Exception
58    {
59  0 jalview.bin.Cache.log.debug("Checking Response for : " + qurl);
60  0 boolean prompt = false;
61    // see if we have already responsed to this questionnaire or get a new
62    // qid/rid pair
63  0 BufferedReader br = new BufferedReader(
64    new InputStreamReader(qurl.openStream()));
65  0 String qresp;
66  0 while ((qresp = br.readLine()) != null)
67    {
68  0 if (qresp.indexOf("NOTYET:") == 0)
69    {
70  0 prompt = true; // not yet responded under that ID
71    }
72    else
73    {
74  0 if (qresp.indexOf("QUESTIONNAIRE:") == 0)
75    {
76    // QUESTIONNAIRE:qid:rid for the latest questionnaire.
77  0 int p = qresp.indexOf(':', 14);
78  0 if (p > -1)
79    {
80  0 rid = null;
81  0 qid = qresp.substring(14, p);
82  0 if (p < (qresp.length() - 1))
83    {
84  0 rid = qresp.substring(p + 1);
85  0 prompt = true; // this is a new qid/rid pair
86    }
87    }
88    }
89    }
90    }
91  0 return prompt;
92    }
93   
 
94  0 toggle public void run()
95    {
96  0 if (url == null)
97    {
98  0 return;
99    }
100  0 boolean prompt = false;
101  0 try
102    {
103    // First - check to see if wee have an old questionnaire/response id pair.
104  0 String lastq = jalview.bin.Cache.getProperty("QUESTIONNAIRE");
105  0 if (lastq == null)
106    {
107  0 prompt = checkresponse(new URL(url
108  0 + (url.indexOf('?') > -1 ? "&" : "?") + "checkresponse=1"));
109    }
110    else
111    {
112  0 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?")
113    + "checkresponse=1";
114    // query the server with the old qid/id pair
115  0 String qqid = lastq.indexOf(':') > -1
116    ? lastq.substring(0, lastq.indexOf(':'))
117    : null;
118  0 if (qqid != null && qqid != "null" && qqid.length() > 0)
119    {
120  0 qurl += "&qid=" + qqid;
121  0 qid = qqid;
122  0 String qrid = lastq.substring(lastq.indexOf(':') + 1); // retrieve
123    // old rid
124  0 if (qrid != null && !qrid.equals("null"))
125    {
126  0 rid = qrid;
127  0 qurl += "&rid=" + qrid;
128    }
129    }
130    // see if we have already responsed to this questionnaire.
131  0 prompt = checkresponse(new URL(qurl));
132    }
133  0 if (qid != null && rid != null)
134    {
135    // Update our local property cache with latest qid and rid
136  0 jalview.bin.Cache.setProperty("QUESTIONNAIRE", qid + ":" + rid);
137    }
138  0 if (prompt)
139    {
140  0 String qurl = url + (url.indexOf('?') > -1 ? "&" : "?") + "qid="
141    + qid + "&rid=" + rid;
142  0 jalview.bin.Cache.log
143    .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 jalview.bin.Cache.log.debug("Opening " + qurl);
152  0 jalview.util.BrowserLauncher.openURL(qurl);
153    }
154    }
155    } catch (Exception e)
156    {
157  0 jalview.bin.Cache.log
158    .warn("When trying to access questionnaire URL " + url, e);
159    }
160    }
161   
162    }