Commit 4268557f0a5f3770369363b67d800cc908b5ac4d
1 parent
d3a65e87
Exists in
master
Fix some Sonar issues
Showing
13 changed files
with
79 additions
and
63 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
... | ... | @@ -164,16 +164,16 @@ public class EpnTapController implements MainViewListener { |
164 | 164 | try { |
165 | 165 | Object object = args[0]; |
166 | 166 | switch (event) { |
167 | - case serviceSelected: | |
167 | + case SERVICE_SELECTED: | |
168 | 168 | updateSelected(((Integer) args[0]).intValue()); |
169 | 169 | break; |
170 | - case btnSendClicked: | |
170 | + case SEND_BUTTON_CLICKED: | |
171 | 171 | sendQuery((String) object); |
172 | 172 | break; |
173 | - case paramChanged: | |
173 | + case PARAMETER_CHANGED: | |
174 | 174 | updateParameter((String) object, args[1]); |
175 | 175 | break; |
176 | - case paramRemoved: | |
176 | + case PARAMETER_REMOVED: | |
177 | 177 | removeParameter((String) object); |
178 | 178 | break; |
179 | 179 | default: |
... | ... | @@ -182,7 +182,7 @@ public class EpnTapController implements MainViewListener { |
182 | 182 | } catch (Exception e) { |
183 | 183 | mainView.displayError("Error", e.getMessage()); |
184 | 184 | logger.log(Level.WARNING, |
185 | - "Exception thrown when " + event.toString() + ": " + e.getMessage()); | |
185 | + "Exception thrown when " + event.toString() + ": " + e.getMessage(), e); | |
186 | 186 | } |
187 | 187 | } |
188 | 188 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java
... | ... | @@ -47,6 +47,10 @@ public final class Queries { |
47 | 47 | + "1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') " |
48 | 48 | + "ORDER BY short_name, table_name"; |
49 | 49 | |
50 | + /** Constructor to hide the implicit public one. */ | |
51 | + private Queries() { | |
52 | + } | |
53 | + | |
50 | 54 | /** |
51 | 55 | * The default query, with these parameters, respectively: max_rows, target_name, time_min, |
52 | 56 | * time_max, dataproduct_type, spectral_range_min, spectral_range_max. |
... | ... | @@ -76,8 +80,4 @@ public final class Queries { |
76 | 80 | return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; |
77 | 81 | } |
78 | 82 | |
79 | - /** Constructor to hide the implicit public one. */ | |
80 | - private Queries() { | |
81 | - } | |
82 | - | |
83 | 83 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/Dim.java
... | ... | @@ -39,4 +39,8 @@ public class Dim { |
39 | 39 | public static final int BOTTOM_PANEL_HEIGHT = 150; |
40 | 40 | /** The minimum height of the bottom panel (result view). */ |
41 | 41 | public static final int BOTTOM_PANEL_MIN_HEIGHT = 100; |
42 | + | |
43 | + /** Private constructor to hide the implicit public one. */ | |
44 | + private Dim() { | |
45 | + } | |
42 | 46 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java
src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java
... | ... | @@ -21,11 +21,11 @@ package eu.omp.irap.vespa.epntapclient.view; |
21 | 21 | */ |
22 | 22 | public enum Event { |
23 | 23 | /** When a service is selected on the service panel. */ |
24 | - serviceSelected, | |
24 | + SERVICE_SELECTED, | |
25 | 25 | /** When the `Send query` button is clicked. */ |
26 | - btnSendClicked, | |
26 | + SEND_BUTTON_CLICKED, | |
27 | 27 | /** When a parameter is removed on the parameter panel. */ |
28 | - paramRemoved, | |
28 | + PARAMETER_REMOVED, | |
29 | 29 | /** When a parameter is updated to a valid value on the parameter panel. */ |
30 | - paramChanged; | |
30 | + PARAMETER_CHANGED; | |
31 | 31 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... | ... | @@ -138,9 +138,9 @@ public abstract class ParamField extends JPanel { |
138 | 138 | @Override |
139 | 139 | public void update(JTextField textField) { |
140 | 140 | if ("".equals(textField.getText())) { |
141 | - mainView.event(Event.paramChanged, paramName, null); | |
141 | + mainView.event(Event.PARAMETER_CHANGED, paramName, null); | |
142 | 142 | } else { |
143 | - mainView.event(Event.paramChanged, paramName, textField.getText()); | |
143 | + mainView.event(Event.PARAMETER_CHANGED, paramName, textField.getText()); | |
144 | 144 | } |
145 | 145 | } |
146 | 146 | } |
... | ... | @@ -178,11 +178,11 @@ public abstract class ParamField extends JPanel { |
178 | 178 | public void update(JTextField textField) { |
179 | 179 | if ("".equals(textField.getText())) { |
180 | 180 | textField.setBackground(Color.WHITE); |
181 | - mainView.event(Event.paramRemoved, paramName); | |
181 | + mainView.event(Event.PARAMETER_REMOVED, paramName); | |
182 | 182 | } else { |
183 | 183 | try { |
184 | 184 | float value = Float.parseFloat(textField.getText()); |
185 | - mainView.event(Event.paramChanged, paramName, value); | |
185 | + mainView.event(Event.PARAMETER_CHANGED, paramName, value); | |
186 | 186 | textField.setBackground(Color.WHITE); |
187 | 187 | } catch (@SuppressWarnings("unused") NumberFormatException e) { |
188 | 188 | textField.setBackground(Color.PINK); |
... | ... | @@ -238,12 +238,12 @@ public abstract class ParamField extends JPanel { |
238 | 238 | DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); |
239 | 239 | if ("".equals(field.getText())) { |
240 | 240 | field.setBackground(Color.WHITE); |
241 | - mainView.event(Event.paramRemoved, paramName + field.getName()); | |
241 | + mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName()); | |
242 | 242 | } else if (field.getText().matches(DATE_REGEX)) { |
243 | 243 | try { |
244 | 244 | long date = df.parse(field.getText()).getTime(); |
245 | 245 | date = Math.round((date / 86400000.0) + 2440587.5); // to JD |
246 | - mainView.event(Event.paramChanged, paramName + field.getName(), date); | |
246 | + mainView.event(Event.PARAMETER_CHANGED, paramName + field.getName(), date); | |
247 | 247 | field.setBackground(Color.WHITE); |
248 | 248 | } catch (@SuppressWarnings("unused") ParseException e) { |
249 | 249 | field.setBackground(Color.PINK); |
... | ... | @@ -296,10 +296,10 @@ public abstract class ParamField extends JPanel { |
296 | 296 | public void update(JTextField field) { |
297 | 297 | if ("".equals(field.getText())) { |
298 | 298 | field.setBackground(Color.WHITE); |
299 | - mainView.event(Event.paramRemoved, paramName + field.getName()); | |
299 | + mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName()); | |
300 | 300 | } else { |
301 | 301 | try { |
302 | - mainView.event(Event.paramChanged, paramName + field.getName(), | |
302 | + mainView.event(Event.PARAMETER_CHANGED, paramName + field.getName(), | |
303 | 303 | Float.parseFloat(field.getText())); |
304 | 304 | field.setBackground(Color.WHITE); |
305 | 305 | } catch (@SuppressWarnings("unused") NumberFormatException e) { |
... | ... | @@ -332,6 +332,36 @@ public abstract class ParamField extends JPanel { |
332 | 332 | String lastContent; |
333 | 333 | |
334 | 334 | /** |
335 | + * This method is called each time the field is modified. A Runnable is used it is | |
336 | + * impossible to modify the comboBox from a DocumentEvent. | |
337 | + */ | |
338 | + Runnable updateComboBox = new Runnable() { | |
339 | + @Override | |
340 | + public void run() { | |
341 | + String content = field.getText(); | |
342 | + if (!content.equals(lastContent)) { | |
343 | + if (content.length() >= 2) { | |
344 | + lastContent = content; | |
345 | + comboBox.removeAllItems(); | |
346 | + try { | |
347 | + for (String s : getItems(content)) { | |
348 | + comboBox.addItem(s); | |
349 | + } | |
350 | + } catch (CantSendQueryException e) { | |
351 | + logger.log(Level.WARNING, "Can't get table names for the resolver", e); | |
352 | + } | |
353 | + comboBox.getEditor().setItem(content); | |
354 | + } | |
355 | + if ("".equals(content)) { | |
356 | + mainView.event(Event.PARAMETER_REMOVED, paramName); | |
357 | + } else { | |
358 | + mainView.event(Event.PARAMETER_CHANGED, paramName, content); | |
359 | + } | |
360 | + } | |
361 | + } | |
362 | + }; | |
363 | + | |
364 | + /** | |
335 | 365 | * Method constructor |
336 | 366 | * |
337 | 367 | * @param mainView The main view of the application. |
... | ... | @@ -356,7 +386,7 @@ public abstract class ParamField extends JPanel { |
356 | 386 | * @throws CantSendQueryException If the resolver do not work. |
357 | 387 | */ |
358 | 388 | static String[] getItems(String begining) throws CantSendQueryException { |
359 | - StringBuilder resolverResult = null; | |
389 | + StringBuilder resolverResult; | |
360 | 390 | resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); |
361 | 391 | JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject(); |
362 | 392 | int count = Integer.parseInt(root.get("count").toString()); |
... | ... | @@ -371,36 +401,6 @@ public abstract class ParamField extends JPanel { |
371 | 401 | } |
372 | 402 | |
373 | 403 | /** |
374 | - * This method is called each time the field is modified. A Runnable is used it is | |
375 | - * impossible to modify the comboBox from a DocumentEvent. | |
376 | - */ | |
377 | - Runnable updateComboBox = new Runnable() { | |
378 | - @Override | |
379 | - public void run() { | |
380 | - String content = field.getText(); | |
381 | - if (!content.equals(lastContent)) { | |
382 | - if (content.length() >= 2) { | |
383 | - lastContent = content; | |
384 | - comboBox.removeAllItems(); | |
385 | - try { | |
386 | - for (String s : getItems(content)) { | |
387 | - comboBox.addItem(s); | |
388 | - } | |
389 | - } catch (CantSendQueryException e) { | |
390 | - logger.log(Level.WARNING, "Can't get table names for the resolver", e); | |
391 | - } | |
392 | - comboBox.getEditor().setItem(content); | |
393 | - } | |
394 | - if ("".equals(content)) { | |
395 | - mainView.event(Event.paramRemoved, paramName); | |
396 | - } else { | |
397 | - mainView.event(Event.paramChanged, paramName, content); | |
398 | - } | |
399 | - } | |
400 | - } | |
401 | - }; | |
402 | - | |
403 | - /** | |
404 | 404 | * This method is called each time the field is modified. |
405 | 405 | */ |
406 | 406 | @Override |
... | ... | @@ -500,9 +500,9 @@ public abstract class ParamField extends JPanel { |
500 | 500 | void update() { |
501 | 501 | DataProductType item = (DataProductType) comboBox.getSelectedItem(); |
502 | 502 | if (DataProductType.ALL.equals(item)) { |
503 | - mainView.event(Event.paramRemoved, paramName); | |
503 | + mainView.event(Event.PARAMETER_REMOVED, paramName); | |
504 | 504 | } else { |
505 | - mainView.event(Event.paramChanged, paramName, item.query()); | |
505 | + mainView.event(Event.PARAMETER_CHANGED, paramName, item.query()); | |
506 | 506 | } |
507 | 507 | } |
508 | 508 | } |
... | ... | @@ -581,9 +581,9 @@ public abstract class ParamField extends JPanel { |
581 | 581 | void update() { |
582 | 582 | TargetClass value = (TargetClass) comboBox.getSelectedItem(); |
583 | 583 | if (TargetClass.ALL.equals(value)) { |
584 | - mainView.event(Event.paramRemoved, paramName); | |
584 | + mainView.event(Event.PARAMETER_REMOVED, paramName); | |
585 | 585 | } else { |
586 | - mainView.event(Event.paramChanged, paramName, value.query()); | |
586 | + mainView.event(Event.PARAMETER_CHANGED, paramName, value.query()); | |
587 | 587 | } |
588 | 588 | } |
589 | 589 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java
... | ... | @@ -169,7 +169,7 @@ public class RequestPanel extends JPanel implements ActionListener { |
169 | 169 | @Override |
170 | 170 | public void actionPerformed(ActionEvent evt) { |
171 | 171 | if (((JButton) evt.getSource()).getName() == BTN_NAME) { |
172 | - this.mainView.event(Event.btnSendClicked, queryArea.getText()); | |
172 | + this.mainView.event(Event.SEND_BUTTON_CLICKED, queryArea.getText()); | |
173 | 173 | } |
174 | 174 | } |
175 | 175 | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java
... | ... | @@ -69,7 +69,7 @@ public class ServicesPanel extends JPanel { |
69 | 69 | .addListSelectionListener(new ListSelectionListener() { |
70 | 70 | @Override |
71 | 71 | public void valueChanged(ListSelectionEvent evt) { |
72 | - mainView.event(Event.serviceSelected, | |
72 | + mainView.event(Event.SERVICE_SELECTED, | |
73 | 73 | voTableView.getTable().getSelectedRow()); |
74 | 74 | } |
75 | 75 | }); | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java
... | ... | @@ -34,6 +34,10 @@ public class Utils { |
34 | 34 | /** The logger for the class Utils. */ |
35 | 35 | private static final Logger logger = Logger.getLogger(Utils.class.getName()); |
36 | 36 | |
37 | + /** Private constructor to hide the implicit public one. */ | |
38 | + private Utils() { | |
39 | + } | |
40 | + | |
37 | 41 | /** |
38 | 42 | * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7 |
39 | 43 | * compatibility. | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | |
17 | 17 | package eu.omp.irap.vespa.epntapclient.votable; |
18 | 18 | |
19 | +import java.util.logging.Level; | |
19 | 20 | import java.util.logging.Logger; |
20 | 21 | |
21 | 22 | import javax.swing.JFrame; |
... | ... | @@ -35,6 +36,10 @@ public class VOTableApp { |
35 | 36 | /** The logger for the class VOTableApp. */ |
36 | 37 | static final Logger logger = Logger.getLogger(VOTableApp.class.getName()); |
37 | 38 | |
39 | + /** Private constructor to hide the implicit public one. */ | |
40 | + private VOTableApp() { | |
41 | + } | |
42 | + | |
38 | 43 | /** |
39 | 44 | * Main function to start the application as standalone. |
40 | 45 | * |
... | ... | @@ -57,13 +62,14 @@ public class VOTableApp { |
57 | 62 | @Override |
58 | 63 | public void run() { |
59 | 64 | // TODO: Add option to export to CSV and HTML in CLI. |
60 | - VOTableController voTableControl = null; | |
65 | + VOTableController voTableControl; | |
61 | 66 | logger.info("Lauching VOTable app with arguments:\n " + new Gson().toJson(args)); |
62 | 67 | if (args.length == 1) { |
63 | 68 | try { |
64 | 69 | voTableControl = new VOTableController(args[0]); |
65 | 70 | } catch (VOTableException e) { |
66 | 71 | System.console().writer().println("Error: " + e.getMessage()); |
72 | + logger.log(Level.WARNING, e.getMessage(), e); | |
67 | 73 | return; |
68 | 74 | } |
69 | 75 | } else if (args.length == 3) { | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableConnection.java
... | ... | @@ -27,6 +27,7 @@ import java.net.URL; |
27 | 27 | import java.net.URLEncoder; |
28 | 28 | import java.text.SimpleDateFormat; |
29 | 29 | import java.util.Date; |
30 | +import java.util.logging.Level; | |
30 | 31 | import java.util.logging.Logger; |
31 | 32 | |
32 | 33 | import eu.omp.irap.vespa.epntapclient.utils.Const; |
... | ... | @@ -132,7 +133,8 @@ public final class VOTableConnection { |
132 | 133 | response.append(inputLine); |
133 | 134 | } |
134 | 135 | in.close(); |
135 | - } catch (@SuppressWarnings("unused") IOException e1) { | |
136 | + } catch (IOException e1) { | |
137 | + logger.log(Level.WARNING, "Can not get input stream", e1); | |
136 | 138 | try (BufferedReader in = new BufferedReader( |
137 | 139 | new InputStreamReader(con.getErrorStream()))) { |
138 | 140 | while ((inputLine = in.readLine()) != null) { | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
... | ... | @@ -82,8 +82,7 @@ public class VOTableController { |
82 | 82 | * @param queryLanguage The language used for the queries (ie. "ADQL"). |
83 | 83 | * @param query The query to ask to the registry. |
84 | 84 | * @throws CantSendQueryException If the query can not be sent. |
85 | - * @throws CantDisplayVOTableException If the table can not be filled. @see | |
86 | - * CantFillTableException | |
85 | + * @throws CantDisplayVOTableException If the table can not be filled. | |
87 | 86 | */ |
88 | 87 | public void fillTable(String targetURL, String queryLanguage, String query) |
89 | 88 | throws CantDisplayVOTableException, CantSendQueryException { | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java
... | ... | @@ -132,7 +132,7 @@ public abstract class VOTableException extends Exception { |
132 | 132 | */ |
133 | 133 | public CantGetErrorStream(String uri, IOException e) { |
134 | 134 | super("Can not get the input stream of the result, neither the error stream " |
135 | - + "for the request " + uri); | |
135 | + + "for the request " + uri, e); | |
136 | 136 | } |
137 | 137 | } |
138 | 138 | ... | ... |