Commit 4268557f0a5f3770369363b67d800cc908b5ac4d

Authored by Nathanael Jourdane
1 parent d3a65e87
Exists in master

Fix some Sonar issues

src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
@@ -164,16 +164,16 @@ public class EpnTapController implements MainViewListener { @@ -164,16 +164,16 @@ public class EpnTapController implements MainViewListener {
164 try { 164 try {
165 Object object = args[0]; 165 Object object = args[0];
166 switch (event) { 166 switch (event) {
167 - case serviceSelected: 167 + case SERVICE_SELECTED:
168 updateSelected(((Integer) args[0]).intValue()); 168 updateSelected(((Integer) args[0]).intValue());
169 break; 169 break;
170 - case btnSendClicked: 170 + case SEND_BUTTON_CLICKED:
171 sendQuery((String) object); 171 sendQuery((String) object);
172 break; 172 break;
173 - case paramChanged: 173 + case PARAMETER_CHANGED:
174 updateParameter((String) object, args[1]); 174 updateParameter((String) object, args[1]);
175 break; 175 break;
176 - case paramRemoved: 176 + case PARAMETER_REMOVED:
177 removeParameter((String) object); 177 removeParameter((String) object);
178 break; 178 break;
179 default: 179 default:
@@ -182,7 +182,7 @@ public class EpnTapController implements MainViewListener { @@ -182,7 +182,7 @@ public class EpnTapController implements MainViewListener {
182 } catch (Exception e) { 182 } catch (Exception e) {
183 mainView.displayError("Error", e.getMessage()); 183 mainView.displayError("Error", e.getMessage());
184 logger.log(Level.WARNING, 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,6 +47,10 @@ public final class Queries {
47 + "1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') " 47 + "1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') "
48 + "ORDER BY short_name, table_name"; 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 * The default query, with these parameters, respectively: max_rows, target_name, time_min, 55 * The default query, with these parameters, respectively: max_rows, target_name, time_min,
52 * time_max, dataproduct_type, spectral_range_min, spectral_range_max. 56 * time_max, dataproduct_type, spectral_range_min, spectral_range_max.
@@ -76,8 +80,4 @@ public final class Queries { @@ -76,8 +80,4 @@ public final class Queries {
76 return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; 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,4 +39,8 @@ public class Dim {
39 public static final int BOTTOM_PANEL_HEIGHT = 150; 39 public static final int BOTTOM_PANEL_HEIGHT = 150;
40 /** The minimum height of the bottom panel (result view). */ 40 /** The minimum height of the bottom panel (result view). */
41 public static final int BOTTOM_PANEL_MIN_HEIGHT = 100; 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
@@ -63,6 +63,7 @@ public class EpnTapMainView extends JPanel { @@ -63,6 +63,7 @@ public class EpnTapMainView extends JPanel {
63 * @author N. Jourdane 63 * @author N. Jourdane
64 */ 64 */
65 public interface MainViewListener { 65 public interface MainViewListener {
  66 +
66 /** 67 /**
67 * When an event is detected on the main view. 68 * When an event is detected on the main view.
68 * 69 *
src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java
@@ -21,11 +21,11 @@ package eu.omp.irap.vespa.epntapclient.view; @@ -21,11 +21,11 @@ package eu.omp.irap.vespa.epntapclient.view;
21 */ 21 */
22 public enum Event { 22 public enum Event {
23 /** When a service is selected on the service panel. */ 23 /** When a service is selected on the service panel. */
24 - serviceSelected, 24 + SERVICE_SELECTED,
25 /** When the `Send query` button is clicked. */ 25 /** When the `Send query` button is clicked. */
26 - btnSendClicked, 26 + SEND_BUTTON_CLICKED,
27 /** When a parameter is removed on the parameter panel. */ 27 /** When a parameter is removed on the parameter panel. */
28 - paramRemoved, 28 + PARAMETER_REMOVED,
29 /** When a parameter is updated to a valid value on the parameter panel. */ 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,9 +138,9 @@ public abstract class ParamField extends JPanel {
138 @Override 138 @Override
139 public void update(JTextField textField) { 139 public void update(JTextField textField) {
140 if ("".equals(textField.getText())) { 140 if ("".equals(textField.getText())) {
141 - mainView.event(Event.paramChanged, paramName, null); 141 + mainView.event(Event.PARAMETER_CHANGED, paramName, null);
142 } else { 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,11 +178,11 @@ public abstract class ParamField extends JPanel {
178 public void update(JTextField textField) { 178 public void update(JTextField textField) {
179 if ("".equals(textField.getText())) { 179 if ("".equals(textField.getText())) {
180 textField.setBackground(Color.WHITE); 180 textField.setBackground(Color.WHITE);
181 - mainView.event(Event.paramRemoved, paramName); 181 + mainView.event(Event.PARAMETER_REMOVED, paramName);
182 } else { 182 } else {
183 try { 183 try {
184 float value = Float.parseFloat(textField.getText()); 184 float value = Float.parseFloat(textField.getText());
185 - mainView.event(Event.paramChanged, paramName, value); 185 + mainView.event(Event.PARAMETER_CHANGED, paramName, value);
186 textField.setBackground(Color.WHITE); 186 textField.setBackground(Color.WHITE);
187 } catch (@SuppressWarnings("unused") NumberFormatException e) { 187 } catch (@SuppressWarnings("unused") NumberFormatException e) {
188 textField.setBackground(Color.PINK); 188 textField.setBackground(Color.PINK);
@@ -238,12 +238,12 @@ public abstract class ParamField extends JPanel { @@ -238,12 +238,12 @@ public abstract class ParamField extends JPanel {
238 DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); 238 DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
239 if ("".equals(field.getText())) { 239 if ("".equals(field.getText())) {
240 field.setBackground(Color.WHITE); 240 field.setBackground(Color.WHITE);
241 - mainView.event(Event.paramRemoved, paramName + field.getName()); 241 + mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName());
242 } else if (field.getText().matches(DATE_REGEX)) { 242 } else if (field.getText().matches(DATE_REGEX)) {
243 try { 243 try {
244 long date = df.parse(field.getText()).getTime(); 244 long date = df.parse(field.getText()).getTime();
245 date = Math.round((date / 86400000.0) + 2440587.5); // to JD 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 field.setBackground(Color.WHITE); 247 field.setBackground(Color.WHITE);
248 } catch (@SuppressWarnings("unused") ParseException e) { 248 } catch (@SuppressWarnings("unused") ParseException e) {
249 field.setBackground(Color.PINK); 249 field.setBackground(Color.PINK);
@@ -296,10 +296,10 @@ public abstract class ParamField extends JPanel { @@ -296,10 +296,10 @@ public abstract class ParamField extends JPanel {
296 public void update(JTextField field) { 296 public void update(JTextField field) {
297 if ("".equals(field.getText())) { 297 if ("".equals(field.getText())) {
298 field.setBackground(Color.WHITE); 298 field.setBackground(Color.WHITE);
299 - mainView.event(Event.paramRemoved, paramName + field.getName()); 299 + mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName());
300 } else { 300 } else {
301 try { 301 try {
302 - mainView.event(Event.paramChanged, paramName + field.getName(), 302 + mainView.event(Event.PARAMETER_CHANGED, paramName + field.getName(),
303 Float.parseFloat(field.getText())); 303 Float.parseFloat(field.getText()));
304 field.setBackground(Color.WHITE); 304 field.setBackground(Color.WHITE);
305 } catch (@SuppressWarnings("unused") NumberFormatException e) { 305 } catch (@SuppressWarnings("unused") NumberFormatException e) {
@@ -332,6 +332,36 @@ public abstract class ParamField extends JPanel { @@ -332,6 +332,36 @@ public abstract class ParamField extends JPanel {
332 String lastContent; 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 * Method constructor 365 * Method constructor
336 * 366 *
337 * @param mainView The main view of the application. 367 * @param mainView The main view of the application.
@@ -356,7 +386,7 @@ public abstract class ParamField extends JPanel { @@ -356,7 +386,7 @@ public abstract class ParamField extends JPanel {
356 * @throws CantSendQueryException If the resolver do not work. 386 * @throws CantSendQueryException If the resolver do not work.
357 */ 387 */
358 static String[] getItems(String begining) throws CantSendQueryException { 388 static String[] getItems(String begining) throws CantSendQueryException {
359 - StringBuilder resolverResult = null; 389 + StringBuilder resolverResult;
360 resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); 390 resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\"");
361 JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject(); 391 JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject();
362 int count = Integer.parseInt(root.get("count").toString()); 392 int count = Integer.parseInt(root.get("count").toString());
@@ -371,36 +401,6 @@ public abstract class ParamField extends JPanel { @@ -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 * This method is called each time the field is modified. 404 * This method is called each time the field is modified.
405 */ 405 */
406 @Override 406 @Override
@@ -500,9 +500,9 @@ public abstract class ParamField extends JPanel { @@ -500,9 +500,9 @@ public abstract class ParamField extends JPanel {
500 void update() { 500 void update() {
501 DataProductType item = (DataProductType) comboBox.getSelectedItem(); 501 DataProductType item = (DataProductType) comboBox.getSelectedItem();
502 if (DataProductType.ALL.equals(item)) { 502 if (DataProductType.ALL.equals(item)) {
503 - mainView.event(Event.paramRemoved, paramName); 503 + mainView.event(Event.PARAMETER_REMOVED, paramName);
504 } else { 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,9 +581,9 @@ public abstract class ParamField extends JPanel {
581 void update() { 581 void update() {
582 TargetClass value = (TargetClass) comboBox.getSelectedItem(); 582 TargetClass value = (TargetClass) comboBox.getSelectedItem();
583 if (TargetClass.ALL.equals(value)) { 583 if (TargetClass.ALL.equals(value)) {
584 - mainView.event(Event.paramRemoved, paramName); 584 + mainView.event(Event.PARAMETER_REMOVED, paramName);
585 } else { 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,7 +169,7 @@ public class RequestPanel extends JPanel implements ActionListener {
169 @Override 169 @Override
170 public void actionPerformed(ActionEvent evt) { 170 public void actionPerformed(ActionEvent evt) {
171 if (((JButton) evt.getSource()).getName() == BTN_NAME) { 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,7 +69,7 @@ public class ServicesPanel extends JPanel {
69 .addListSelectionListener(new ListSelectionListener() { 69 .addListSelectionListener(new ListSelectionListener() {
70 @Override 70 @Override
71 public void valueChanged(ListSelectionEvent evt) { 71 public void valueChanged(ListSelectionEvent evt) {
72 - mainView.event(Event.serviceSelected, 72 + mainView.event(Event.SERVICE_SELECTED,
73 voTableView.getTable().getSelectedRow()); 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,6 +34,10 @@ public class Utils {
34 /** The logger for the class Utils. */ 34 /** The logger for the class Utils. */
35 private static final Logger logger = Logger.getLogger(Utils.class.getName()); 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 * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7 42 * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7
39 * compatibility. 43 * compatibility.
src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 package eu.omp.irap.vespa.epntapclient.votable; 17 package eu.omp.irap.vespa.epntapclient.votable;
18 18
  19 +import java.util.logging.Level;
19 import java.util.logging.Logger; 20 import java.util.logging.Logger;
20 21
21 import javax.swing.JFrame; 22 import javax.swing.JFrame;
@@ -35,6 +36,10 @@ public class VOTableApp { @@ -35,6 +36,10 @@ public class VOTableApp {
35 /** The logger for the class VOTableApp. */ 36 /** The logger for the class VOTableApp. */
36 static final Logger logger = Logger.getLogger(VOTableApp.class.getName()); 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 * Main function to start the application as standalone. 44 * Main function to start the application as standalone.
40 * 45 *
@@ -57,13 +62,14 @@ public class VOTableApp { @@ -57,13 +62,14 @@ public class VOTableApp {
57 @Override 62 @Override
58 public void run() { 63 public void run() {
59 // TODO: Add option to export to CSV and HTML in CLI. 64 // TODO: Add option to export to CSV and HTML in CLI.
60 - VOTableController voTableControl = null; 65 + VOTableController voTableControl;
61 logger.info("Lauching VOTable app with arguments:\n " + new Gson().toJson(args)); 66 logger.info("Lauching VOTable app with arguments:\n " + new Gson().toJson(args));
62 if (args.length == 1) { 67 if (args.length == 1) {
63 try { 68 try {
64 voTableControl = new VOTableController(args[0]); 69 voTableControl = new VOTableController(args[0]);
65 } catch (VOTableException e) { 70 } catch (VOTableException e) {
66 System.console().writer().println("Error: " + e.getMessage()); 71 System.console().writer().println("Error: " + e.getMessage());
  72 + logger.log(Level.WARNING, e.getMessage(), e);
67 return; 73 return;
68 } 74 }
69 } else if (args.length == 3) { 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,6 +27,7 @@ import java.net.URL;
27 import java.net.URLEncoder; 27 import java.net.URLEncoder;
28 import java.text.SimpleDateFormat; 28 import java.text.SimpleDateFormat;
29 import java.util.Date; 29 import java.util.Date;
  30 +import java.util.logging.Level;
30 import java.util.logging.Logger; 31 import java.util.logging.Logger;
31 32
32 import eu.omp.irap.vespa.epntapclient.utils.Const; 33 import eu.omp.irap.vespa.epntapclient.utils.Const;
@@ -132,7 +133,8 @@ public final class VOTableConnection { @@ -132,7 +133,8 @@ public final class VOTableConnection {
132 response.append(inputLine); 133 response.append(inputLine);
133 } 134 }
134 in.close(); 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 try (BufferedReader in = new BufferedReader( 138 try (BufferedReader in = new BufferedReader(
137 new InputStreamReader(con.getErrorStream()))) { 139 new InputStreamReader(con.getErrorStream()))) {
138 while ((inputLine = in.readLine()) != null) { 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,8 +82,7 @@ public class VOTableController {
82 * @param queryLanguage The language used for the queries (ie. "ADQL"). 82 * @param queryLanguage The language used for the queries (ie. "ADQL").
83 * @param query The query to ask to the registry. 83 * @param query The query to ask to the registry.
84 * @throws CantSendQueryException If the query can not be sent. 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 public void fillTable(String targetURL, String queryLanguage, String query) 87 public void fillTable(String targetURL, String queryLanguage, String query)
89 throws CantDisplayVOTableException, CantSendQueryException { 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,7 +132,7 @@ public abstract class VOTableException extends Exception {
132 */ 132 */
133 public CantGetErrorStream(String uri, IOException e) { 133 public CantGetErrorStream(String uri, IOException e) {
134 super("Can not get the input stream of the result, neither the error stream " 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