Commit fd93317f6efa43271675765c8d20d95b40cfb7c9

Authored by Nathanael Jourdane
1 parent 30e4599b
Exists in master

Solve Sonar/Eclipse warnings/findbugs issues.

Showing 24 changed files with 201 additions and 204 deletions   Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java
... ... @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController;
33 33 public class EpnTapController {
34 34  
35 35 /** The logger for the class EpnTapController. */
36   - private static final Logger logger = Logger.getLogger(EpnTapController.class.getName());
  36 + private static final Logger LOGGER = Logger.getLogger(EpnTapController.class.getName());
37 37  
38 38 /** The controller of the VOTable displaying the list of services. */
39 39 private VOTableController servicesCtrl;
... ... @@ -79,7 +79,7 @@ public class EpnTapController {
79 79 */
80 80 @SuppressWarnings("static-method")
81 81 public void displayError(String message, Exception e) {
82   - logger.log(Level.SEVERE, message, e);
  82 + LOGGER.log(Level.SEVERE, message, e);
83 83 }
84 84  
85 85 /**
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java
... ... @@ -34,7 +34,7 @@ import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelView;
34 34 public class EpnTapMainApp {
35 35  
36 36 /** The logger for the class EpnTapMainApp. */
37   - private static final Logger logger = Logger.getLogger(EpnTapMainApp.class.getName());
  37 + private static final Logger LOGGER = Logger.getLogger(EpnTapMainApp.class.getName());
38 38  
39 39 /** Error message when the user put a wrong command. */
40 40 private static final String WRONG_COMMAND = "Usage: EpnTapMainApp";
... ... @@ -50,7 +50,7 @@ public class EpnTapMainApp {
50 50 * @param args The program arguments (not used).
51 51 */
52 52 public static void main(final String[] args) {
53   - EpnTapMainApp.logger.info("Lauching EPNTAP app with arguments: " + new Gson().toJson(args));
  53 + EpnTapMainApp.LOGGER.info("Lauching EPNTAP app with arguments: " + new Gson().toJson(args));
54 54 if (args.length != 0) {
55 55 System.console().writer().println(EpnTapMainApp.WRONG_COMMAND);
56 56 return;
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/Query.java
... ... @@ -20,17 +20,21 @@ package eu.omp.irap.vespa.epntapclient;
20 20 * @author N. Jourdane
21 21 */
22 22 public enum Query {
23   - // @noformat
24   - GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL(
25   - "SELECT * FROM %s"),
26   - GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL_AND_SURFACE_AREA(
27   - "SELECT * FROM %s");
  23 + /** Query to get a the scene from a target and a time interval. */
  24 + GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL("SELECT * FROM %s"),
  25 + /** Query to get a the scene from a target, a time interval and a surface area. */
  26 + GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL_AND_SURFACE_AREA("SELECT * FROM %s");
28 27 // TBC
29   - // @format
30 28  
  29 + /** The string literal of the query. */
31 30 private String literalQuery;
32 31  
33 32  
  33 + /**
  34 + * Enumeration constructor
  35 + *
  36 + * @param literalQuery The query.
  37 + */
34 38 Query(String literalQuery) {
35 39 this.literalQuery = literalQuery;
36 40 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java
... ... @@ -36,23 +36,39 @@ public class RequestCtrl {
36 36 /** The URL of the resolver used for the `target name` field. */
37 37 private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete";
38 38  
  39 + /** The query template to get granules. */
  40 + private static final String QUERY = "SELECT TOP %s target_name, target_class FROM %s%s";
  41 +
39 42 /** The parameters fields for the request. */
40   - protected Map<String, Object> paramValues = new HashMap<>();
  43 + protected Map<String, Object> parameters = new HashMap<>();
  44 +
  45 + /** The maximum number of rows returned by the query. */
  46 + private int nbMaxResult;
41 47  
42 48  
  49 + /** Constructor of RequestCtrl. */
43 50 public RequestCtrl() {
44   - /* Subclasses initializes their own attributes, we don't want to initialize them twice. */
  51 + nbMaxResult = 20;
45 52 }
46 53  
47 54 /**
48   - * @param nbRow The maximum number of rows returned.
49   - * @param tableName The name of the target table for the query.
50   - * @param params A map of parameters, for the `WHERE` keywords.
51   - * @return The literal string of the query.
  55 + * Constructor of RequestCtrl.
  56 + *
  57 + * @param nbMaxResult The maximum number of rows returned by the query.
52 58 */
53   - public String getQuery(String tableName, int nbRow) {
  59 + public RequestCtrl(int nbMaxResult) {
  60 + this.nbMaxResult = nbMaxResult;
  61 + }
  62 +
  63 + /**
  64 + * Build an ADQL from the table name, the parameter values and the max results.
  65 + *
  66 + * @param tableName The name of the table, to put in FROM keyword.
  67 + * @return The query.
  68 + */
  69 + public String buildQuery(String tableName) {
54 70 StringJoiner addJoin = new StringJoiner(" AND ");
55   - for (Map.Entry<String, Object> param : paramValues.entrySet()) {
  71 + for (Map.Entry<String, Object> param : parameters.entrySet()) {
56 72 if (param.getValue() instanceof ArrayList) {
57 73 StringJoiner orJoin = new StringJoiner(" OR ");
58 74 @SuppressWarnings("unchecked")
... ... @@ -69,7 +85,7 @@ public class RequestCtrl {
69 85 }
70 86 String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin;
71 87  
72   - return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where;
  88 + return String.format(QUERY, nbMaxResult, tableName, where);
73 89 }
74 90  
75 91 /**
... ... @@ -77,8 +93,7 @@ public class RequestCtrl {
77 93 *
78 94 * @param begining The beginning of the target_name.
79 95 * @return An array of Strings corresponding to the target names got.
80   - * @throws CantSendQueryException
81   - * @throws CantGetXMLException If the resolver do not work.
  96 + * @throws CantSendQueryException Can not read the JSON file.
82 97 */
83 98 public static String[] getTargetNames(String begining) throws CantSendQueryException {
84 99 Map<String, String> params = new HashMap<>();
... ... @@ -96,16 +111,48 @@ public class RequestCtrl {
96 111 return targetNames;
97 112 }
98 113  
  114 + /**
  115 + * Update a parameter in the query. If the parameter do not exists yet, create it.
  116 + *
  117 + * @param paramName The name of the parameter.
  118 + * @param paramValue The value of the parameter.
  119 + */
99 120 public void updateParameter(String paramName, Object paramValue) {
100   - paramValues.put(paramName, paramValue);
  121 + parameters.put(paramName, paramValue);
101 122 }
102 123  
  124 + /**
  125 + * Remove a parameter from the query.
  126 + *
  127 + * @param paramName The name of the parameter to remove.
  128 + */
103 129 public void removeParameter(String paramName) {
104   - paramValues.remove(paramName);
  130 + parameters.remove(paramName);
  131 + }
  132 +
  133 + /**
  134 + * Get the parameters.
  135 + *
  136 + * @return A map of couple <parameter name, parameter value>.
  137 + */
  138 + public Map<String, Object> getParameters() {
  139 + return parameters;
  140 + }
  141 +
  142 + /**
  143 + * @return The maximum number of rows returned by the query.
  144 + */
  145 + public int getNbMaxResult() {
  146 + return nbMaxResult;
105 147 }
106 148  
107   - public Map<String, Object> getParamValues() {
108   - return paramValues;
  149 + /**
  150 + * Set the maximum number of rows returned by the query.
  151 + *
  152 + * @param nbRows The number of rows.
  153 + */
  154 + public void setNbMaxResult(int nbRows) {
  155 + nbMaxResult = nbRows;
109 156 }
110 157  
111 158 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java
... ... @@ -280,10 +280,6 @@ public class Granule {
280 280 private String timeScale;
281 281  
282 282  
283   - /** Private constructor to hide the default public one. */
284   - private Granule() {
285   - }
286   -
287 283 /**
288 284 * Constructor of Granule
289 285 *
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java
... ... @@ -32,7 +32,7 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableData;
32 32 public class GranuleCtrl {
33 33  
34 34 /** The logger for the class GranuleCtrl. */
35   - private static final Logger logger = Logger.getLogger(GranuleCtrl.class.getName());
  35 + private static final Logger LOGGER = Logger.getLogger(GranuleCtrl.class.getName());
36 36  
37 37 /** The data to parse */
38 38 private VOTableData data;
... ... @@ -62,7 +62,7 @@ public class GranuleCtrl {
62 62 try {
63 63 res = (String) data.getCell(rowId, granule.toString());
64 64 } catch (IllegalArgumentException e) {
65   - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty string"), e);
  65 + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty string"), e);
66 66 }
67 67 return res;
68 68 }
... ... @@ -81,7 +81,7 @@ public class GranuleCtrl {
81 81 try {
82 82 date = sdf.parse((String) data.getCell(rowId, granule.toString()));
83 83 } catch (IllegalArgumentException e) {
84   - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty date"), e);
  84 + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty date"), e);
85 85 }
86 86  
87 87 return date;
... ... @@ -99,7 +99,7 @@ public class GranuleCtrl {
99 99 try {
100 100 d = (Double) data.getCell(rowId, granule.toString());
101 101 } catch (IllegalArgumentException e) {
102   - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "double.NaN"), e);
  102 + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "double.NaN"), e);
103 103 }
104 104  
105 105 return d == null ? Double.NaN : d;
... ... @@ -117,7 +117,7 @@ public class GranuleCtrl {
117 117 try {
118 118 val = (Integer) data.getCell(rowId, granule.toString());
119 119 } catch (IllegalArgumentException e) {
120   - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "0"), e);
  120 + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "0"), e);
121 121 }
122 122 return val;
123 123 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
... ... @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
33 33 public class MainPanelCtrl extends EpnTapController {
34 34  
35 35 /** The logger for the class GUIController. */
36   - private static final Logger logger = Logger.getLogger(MainPanelCtrl.class.getName());
  36 + private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName());
37 37  
38 38 /** The controller of the request panel. */
39 39 private RequestPanelCtrl requestPanelCtrl;
... ... @@ -47,9 +47,6 @@ public class MainPanelCtrl extends EpnTapController {
47 47 /** The main view of the application. */
48 48 private MainPanelView view;
49 49  
50   - /** The maximum number of rows returned by the query. */
51   - private int nbMaxResult = 10;
52   -
53 50  
54 51 /**
55 52 * Constructor of MainPanelCtrl.
... ... @@ -73,21 +70,24 @@ public class MainPanelCtrl extends EpnTapController {
73 70  
74 71 /**
75 72 * Send the specified query to the selected service and update the result table content.
76   - *
  73 + *
77 74 * @param query The query to send.
78 75 */
79 76 public void sendQuery(String query) {
80 77 String serviceURL = servicesPanelCtrl.getSelectedServiceURL();
81   - logger.info("Sending query: " + query + " on " + serviceURL);
  78 + LOGGER.info("Sending query: " + query + " on " + serviceURL);
82 79 try {
83 80 resultPanelCtrl.updateVOTable(serviceURL, query);
84 81 view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData());
85 82 } catch (CantGetVOTableException e) {
86 83 displayError("Can not send the query.", e);
87   - MainPanelCtrl.logger.log(Level.WARNING, "Can not send query.", e);
  84 + LOGGER.log(Level.WARNING, "Can not send query.", e);
88 85 }
89 86 }
90 87  
  88 + /**
  89 + * @return The controller of the request panel.
  90 + */
91 91 public RequestPanelCtrl getRequestPanelCtrl() {
92 92 return requestPanelCtrl;
93 93 }
... ... @@ -106,22 +106,7 @@ public class MainPanelCtrl extends EpnTapController {
106 106  
107 107 @Override
108 108 public void displayError(String message, Exception e) {
109   - logger.log(Level.SEVERE, message, e);
  109 + LOGGER.log(Level.SEVERE, message, e);
110 110 JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE);
111 111 }
112   -
113   - /**
114   - * @return the nb max of result
115   - */
116   - public int getNbMaxResult() {
117   - return nbMaxResult;
118   - }
119   -
120   - /**
121   - * set the nb max of result for a query
122   - */
123   - public void setNbMaxResult(int nb) {
124   - nbMaxResult = nb;
125   - }
126   -
127 112 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java
... ... @@ -20,7 +20,6 @@ import java.util.logging.Logger;
20 20  
21 21 import eu.omp.irap.vespa.epntapclient.RequestCtrl;
22 22 import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl;
23   -import eu.omp.irap.vespa.epntapclient.service.Queries;
24 23  
25 24 /**
26 25 * @author N. Jourdane
... ... @@ -28,7 +27,7 @@ import eu.omp.irap.vespa.epntapclient.service.Queries;
28 27 public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListener {
29 28  
30 29 /** The logger for the class RequestPanelCtrl. */
31   - private static final Logger logger = Logger.getLogger(RequestPanelCtrl.class.getName());
  30 + private static final Logger LOGGER = Logger.getLogger(RequestPanelCtrl.class.getName());
32 31  
33 32 MainPanelCtrl mainPanelCtrl;
34 33  
... ... @@ -63,8 +62,7 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene
63 62 * Update the query area with a working ADQL query, based on the parameters list.
64 63 */
65 64 public void updateQueryArea() {
66   - String query = Queries.getQuery(mainPanelCtrl.getServicePanelCtrl().getSelectedTableName(),
67   - paramValues, mainPanelCtrl.getNbMaxResult());
  65 + String query = buildQuery(mainPanelCtrl.getServicePanelCtrl().getSelectedTableName());
68 66 view.updateQueryArea(query);
69 67 }
70 68  
... ... @@ -72,13 +70,13 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene
72 70 public void onParameterRemoved(String paramName) {
73 71 removeParameter(paramName);
74 72 updateQueryArea();
75   - logger.info("removed " + paramName);
  73 + LOGGER.info("removed " + paramName);
76 74 }
77 75  
78 76 @Override
79 77 public void onParameterChanged(String paramName, Object paramValue) {
80 78 updateParameter(paramName, paramValue);
81 79 updateQueryArea();
82   - logger.info("uploaded " + paramName + ": " + paramValue);
  80 + LOGGER.info("uploaded " + paramName + ": " + paramValue);
83 81 }
84 82 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java
... ... @@ -64,7 +64,7 @@ public class RequestPanelView extends JPanel {
64 64 /** The height of the buttons panel. */
65 65 private static final int BUTTON_PANEL_HEIGHT = 20;
66 66  
67   - private RequestPanelListener requestPanelListener;
  67 + RequestPanelListener requestPanelListener;
68 68  
69 69  
70 70 /**
... ... @@ -194,7 +194,7 @@ public class RequestPanelView extends JPanel {
194 194 }
195 195 });
196 196 buttonPanel.add(btnSend);
197   - buttonPanel.setMaximumSize(new Dimension(1000, RequestPanelView.BUTTON_PANEL_HEIGHT));
  197 + buttonPanel.setMaximumSize(new Dimension(1000, BUTTON_PANEL_HEIGHT));
198 198  
199 199 return buttonPanel;
200 200 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java
... ... @@ -64,9 +64,7 @@ public class DataProductTypeField extends ParamField {
64 64 if (comboBox == null) {
65 65 comboBox = new JComboBox<>(DataProductType.values());
66 66 comboBox.setSelectedItem(DataProductType.ALL);
67   - comboBox.setPreferredSize(
68   - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
69   -
  67 + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
70 68 comboBox.addActionListener(new ActionListener() {
71 69  
72 70 @Override
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java
... ... @@ -47,7 +47,7 @@ public class FloatField extends ParamField implements TextFieldListener {
47 47 public FloatField(RequestPanelListener requestPanelListener, String paramName) {
48 48 super(requestPanelListener, paramName);
49 49 field = new JTextField();
50   - ParamField.addChangeListener(this, field);
  50 + addChangeListener(this, field);
51 51 this.add(field);
52 52 }
53 53  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java
... ... @@ -50,13 +50,13 @@ public class FloatRangeField extends ParamField implements TextFieldListener {
50 50 public FloatRangeField(RequestPanelListener requestPanelListener, String paramName) {
51 51 super(requestPanelListener, paramName);
52 52 fieldMin = new JTextField();
53   - fieldMin.setName(ParamField.MIN_SUFFIX);
54   - ParamField.addChangeListener(this, fieldMin);
  53 + fieldMin.setName(MIN_SUFFIX);
  54 + addChangeListener(this, fieldMin);
55 55 this.add(fieldMin);
56 56  
57 57 fieldMax = new JTextField();
58   - fieldMax.setName(ParamField.MAX_SUFFIX);
59   - ParamField.addChangeListener(this, fieldMax);
  58 + fieldMax.setName(MAX_SUFFIX);
  59 + addChangeListener(this, fieldMax);
60 60 this.add(fieldMax);
61 61 }
62 62  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java
... ... @@ -42,7 +42,7 @@ public abstract class ParamField extends JPanel {
42 42 private static final long serialVersionUID = 1L;
43 43  
44 44 /** The logger for the class ParamField. */
45   - static final Logger logger = Logger.getLogger(ParamField.class.getName());
  45 + static final Logger LOGGER = Logger.getLogger(ParamField.class.getName());
46 46  
47 47 /** The minimum width of the field. */
48 48 static final int MIN_FIELD_WIDTH = 30;
... ... @@ -88,11 +88,11 @@ public abstract class ParamField extends JPanel {
88 88 private void buildParamField() {
89 89 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
90 90  
91   - setMaximumSize(new Dimension(ParamField.MAX_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  91 + setMaximumSize(new Dimension(MAX_FIELD_WIDTH, FIELD_HEIGHT));
92 92  
93 93 String strLabel = paramName.replaceAll("_", " ").trim();
94 94 JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1));
95   - label.setPreferredSize(new Dimension(ParamField.LABEL_WIDTH, ParamField.FIELD_HEIGHT));
  95 + label.setPreferredSize(new Dimension(LABEL_WIDTH, FIELD_HEIGHT));
96 96  
97 97 this.add(label);
98 98 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java
... ... @@ -44,7 +44,7 @@ public class StringField extends ParamField implements TextFieldListener {
44 44 public StringField(RequestPanelListener requestPanelListener, String paramName) {
45 45 super(requestPanelListener, paramName);
46 46 field = new JTextField();
47   - ParamField.addChangeListener(this, field);
  47 + addChangeListener(this, field);
48 48 this.add(field);
49 49 }
50 50  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java
... ... @@ -51,8 +51,7 @@ public class TargetClassField extends ParamField {
51 51 public TargetClassField(RequestPanelListener requestPanelListener, String paramName) {
52 52 super(requestPanelListener, paramName);
53 53 comboBox = new JComboBox<>(TargetClass.values());
54   - comboBox.setPreferredSize(
55   - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
  54 + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
56 55 comboBox.addActionListener(new ActionListener() {
57 56  
58 57 @Override
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java
... ... @@ -53,39 +53,6 @@ public class TargetNameField extends ParamField implements TextFieldListener {
53 53 */
54 54 String lastContent;
55 55  
56   - /**
57   - * This method is called each time the field is modified. A Runnable is used it is impossible to
58   - * modify the comboBox from a DocumentEvent.
59   - */
60   - Runnable updateComboBox = new Runnable() {
61   -
62   - @Override
63   - public void run() {
64   - String content = field.getText();
65   - if (!content.equals(lastContent)) {
66   - if (content.length() >= 2) {
67   - lastContent = content;
68   - comboBox.removeAllItems();
69   - try {
70   - for (String s : RequestCtrl.getTargetNames(content)) {
71   - comboBox.addItem(s);
72   - }
73   - } catch (CantSendQueryException e) {
74   - ParamField.logger.log(Level.WARNING,
75   - "Can't get table names for the resolver", e);
76   - }
77   - comboBox.getEditor().setItem(content);
78   - comboBox.showPopup();
79   - }
80   - if (content.isEmpty()) {
81   - requestPanelListener.onParameterRemoved(paramName);
82   - } else {
83   - requestPanelListener.onParameterChanged(paramName, content);
84   - }
85   - }
86   - }
87   - };
88   -
89 56  
90 57 /**
91 58 * Method constructor
... ... @@ -96,26 +63,60 @@ public class TargetNameField extends ParamField implements TextFieldListener {
96 63 public TargetNameField(RequestPanelListener requestPanelListener, String paramName) {
97 64 super(requestPanelListener, paramName);
98 65 comboBox = new JComboBox<>();
99   - comboBox.setPreferredSize(
100   - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT));
101   -
  66 + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
102 67 comboBox.setEditable(true);
103 68 field = (JTextField) comboBox.getEditor().getEditorComponent();
104   - ParamField.addChangeListener(this, field);
  69 + addChangeListener(this, field);
105 70 this.add(comboBox);
106 71 }
107 72  
108 73 public TargetNameField(String paraName) {
109   - // @noformat
110 74 this(new RequestPanelListener() {
  75 +
111 76 @Override
112   - public void onSendButtonClicked(String query) {/** no SendButtonClicked event, we just want the field */}
  77 + public void onSendButtonClicked(String query) {
  78 + /** No SendButtonClicked event, we just want the field itself. */
  79 + }
  80 +
113 81 @Override
114   - public void onParameterRemoved(String paramName) {/** no ParameterRemoved event, we just want the field */}
  82 + public void onParameterRemoved(String paramName) {
  83 + /** No ParameterRemoved event, we just want the field itself. */
  84 + }
  85 +
115 86 @Override
116   - public void onParameterChanged(String paramName, Object paramValue) {/** no ParameterChanged event, we just want the field */}
  87 + public void onParameterChanged(String paramName, Object paramValue) {
  88 + /** No ParameterChanged event, we just want the field itself. */
  89 + }
117 90 }, paraName);
118   - // @format
  91 + }
  92 +
  93 + /**
  94 + * This method is called each time the field is modified. A Runnable is used it is impossible to
  95 + * modify the comboBox from a DocumentEvent.
  96 + */
  97 + void updateComboBox() {
  98 + String content = field.getText();
  99 + if (!content.equals(lastContent)) {
  100 + if (content.length() >= 2) {
  101 + lastContent = content;
  102 + comboBox.removeAllItems();
  103 + try {
  104 + for (String s : RequestCtrl.getTargetNames(content)) {
  105 + comboBox.addItem(s);
  106 + }
  107 + } catch (CantSendQueryException e) {
  108 + LOGGER.log(Level.WARNING,
  109 + "Can't get table names for the resolver", e);
  110 + }
  111 + comboBox.getEditor().setItem(content);
  112 + comboBox.showPopup();
  113 + }
  114 + if (content.isEmpty()) {
  115 + requestPanelListener.onParameterRemoved(paramName);
  116 + } else {
  117 + requestPanelListener.onParameterChanged(paramName, content);
  118 + }
  119 + }
119 120 }
120 121  
121 122 /**
... ... @@ -123,7 +124,13 @@ public class TargetNameField extends ParamField implements TextFieldListener {
123 124 */
124 125 @Override
125 126 public void update(JTextField textField) {
126   - SwingUtilities.invokeLater(updateComboBox);
  127 + SwingUtilities.invokeLater(new Runnable() {
  128 +
  129 + @Override
  130 + public void run() {
  131 + updateComboBox();
  132 + }
  133 + });
127 134 }
128 135  
129 136 }
130 137 \ No newline at end of file
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java
... ... @@ -32,7 +32,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController;
32 32 public class ResultPanelCtrl extends VOTableController implements ResultPanelListener {
33 33  
34 34 /** The logger for the class ResultPanelCtrl. */
35   - private static final Logger logger = Logger.getLogger(ResultPanelCtrl.class.getName());
  35 + private static final Logger LOGGER = Logger.getLogger(ResultPanelCtrl.class.getName());
36 36  
37 37 private MainPanelCtrl mainPanelCtrl;
38 38  
... ... @@ -50,7 +50,7 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis
50 50 Files.copy(Paths.get(voTablePath), Paths.get(file.getAbsolutePath()));
51 51 } catch (IOException e) {
52 52 mainPanelCtrl.displayError("Can not save the file.", e);
53   - logger.log(Level.WARNING, "Can not save the file.", e);
  53 + LOGGER.log(Level.WARNING, "Can not save the file.", e);
54 54 }
55 55 }
56 56  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java
... ... @@ -30,7 +30,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController;
30 30 public class ServicesPanelCtrl extends VOTableController implements ServicesPanelListener {
31 31  
32 32 /** The logger for the class ServicesPanelCtrl. */
33   - private static final Logger logger = Logger.getLogger(ServicesPanelCtrl.class.getName());
  33 + private static final Logger LOGGER = Logger.getLogger(ServicesPanelCtrl.class.getName());
34 34  
35 35 /** The name of the table selected by the user on the table list panel. */
36 36 private String selectedTableName;
... ... @@ -71,7 +71,7 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
71 71 selectedServiceURL = serviceURL;
72 72 selectedTableName = tableName;
73 73 mainPanelCtrl.getRequestPanelCtrl().updateQueryArea();
74   - logger.info(
  74 + LOGGER.info(
75 75 "Selected table: " + selectedTableName + " - service: " + selectedServiceURL);
76 76 }
77 77 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java
... ... @@ -37,7 +37,7 @@ public class ServicesPanelView extends VOTableView {
37 37 /** The serial version UID. */
38 38 private static final long serialVersionUID = 1L;
39 39  
40   - private ServicesPanelListener viewListener;
  40 + ServicesPanelListener viewListener;
41 41  
42 42 private JButton serviceButton;
43 43  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
... ... @@ -16,12 +16,6 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.service;
18 18  
19   -import java.util.ArrayList;
20   -import java.util.List;
21   -import java.util.Map;
22   -
23   -import eu.omp.irap.vespa.votable.utils.StringJoiner;
24   -
25 19 /**
26 20 * Defines the queries and the query patterns usually used in the application.
27 21 *
... ... @@ -29,8 +23,6 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner;
29 23 */
30 24 public final class Queries {
31 25  
32   - public static final String RETURN_PARAMETERS = "target_name, target_class";
33   -
34 26 private static final String SELECT = "SELECT DISTINCT short_name, res_title, "
35 27 + "table_name, schema_name, ivoid, access_url ";
36 28  
... ... @@ -52,29 +44,25 @@ public final class Queries {
52 44  
53 45 /** Query to get all TAP services. */
54 46 public static final String SELECT_ALL_TAP_SERVICES =
55   - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY;
  47 + SELECT + FROM + WHERE_TAP + ORDER_BY;
56 48  
57 49 /** Query to get TAP services which implement the specified core. */
58 50 public static final String SELECT_ALL_TAP_SERVICES_WHERE_CORE =
59   - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
60   - + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') "
61   - + Queries.ORDER_BY;
  51 + SELECT + FROM + WHERE_TAP
  52 + + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') " + ORDER_BY;
62 53  
63 54 /** Query to get the TAP service with the specified ivoid. */
64 55 public static final String SELECT_ALL_TAP_SERVICES_WHERE_IVOID =
65   - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
66   - + "AND ivoid = '%s'";
  56 + SELECT + FROM + WHERE_TAP + "AND ivoid = '%s'";
67 57  
68 58 public static final String SELECT_TAP_SERVICES_WHERE_IVOID =
69   - "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP
70   - + "AND ivoid = '%s'";
  59 + "SELECT DISTINCT %s " + FROM + WHERE_TAP + "AND ivoid = '%s'";
71 60  
72 61 public static final String SELECT_TAP_SERVICES =
73   - "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP;
  62 + "SELECT DISTINCT %s " + FROM + WHERE_TAP;
74 63  
75 64 public static final String SELECT_TAP_SERVICES_WHERE_SUBJECT =
76   - "SELECT DISTINCT %s " + Queries.FROM + "NATURAL JOIN rr.res_subject "
77   - + Queries.WHERE_TAP + "AND (%s)";
  65 + "SELECT DISTINCT %s " + FROM + "NATURAL JOIN rr.res_subject " + WHERE_TAP + "AND (%s)";
78 66  
79 67 public static final String SELECT_FROM =
80 68 "SELECT DISTINCT %s FROM %s";
... ... @@ -88,38 +76,4 @@ public final class Queries {
88 76 private Queries() {
89 77 }
90 78  
91   - /**
92   - * The default query, with these parameters, respectively: max_rows, target_name, time_min,
93   - * time_max, dataproduct_type, spectral_range_min, spectral_range_max.
94   - *
95   - * @param nbRow The maximum number of rows returned.
96   - * @param tableName The name of the target table for the query.
97   - * @param params A map of parameters, for the `WHERE` keywords.
98   - * @return The literal string of the query.
99   - */
100   - public static String getQuery(String tableName, Map<String, Object> params, int nbRow) {
101   - StringJoiner addJoin = new StringJoiner(" AND ");
102   - for (Map.Entry<String, Object> param : params.entrySet()) {
103   - if (param.getValue() instanceof ArrayList) {
104   - StringJoiner orJoin = new StringJoiner(" OR ");
105   - @SuppressWarnings("unchecked")
106   - List<String> possibleValues = (List<String>) param.getValue();
107   - for (String possibleValue : possibleValues) {
108   - orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'");
109   - }
110   - addJoin.add("(" + orJoin + ")");
111   - } else if (param.getValue() instanceof String) {
112   - addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'");
113   - } else {
114   - addJoin.add(param.getKey() + " = " + param.getValue().toString());
115   - }
116   - }
117   - String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin;
118   -
119   - return "SELECT TOP " + nbRow + " "
120   - + RETURN_PARAMETERS
121   - + " "
122   - + "FROM " + tableName + where;
123   - }
124   -
125 79 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java
... ... @@ -42,9 +42,6 @@ public class Service {
42 42 private String updated;
43 43  
44 44  
45   - private Service() {
46   - }
47   -
48 45 Service(String ivoid) {
49 46 this.ivoid = ivoid;
50 47 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
... ... @@ -49,7 +49,7 @@ import eu.omp.irap.vespa.votable.utils.XMLUtils;
49 49 public class VOResourceCtrl {
50 50  
51 51 /** The logger for the class VOResourceController. */
52   - private static final Logger logger = Logger.getLogger(VOResourceCtrl.class.getName());
  52 + private static final Logger LOGGER = Logger.getLogger(VOResourceCtrl.class.getName());
53 53  
54 54 private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml";
55 55  
... ... @@ -72,7 +72,7 @@ public class VOResourceCtrl {
72 72  
73 73 public static List<String> getVOResources(ServiceCore type) throws VOResourceException {
74 74 List<String> ivoidResources;
75   - Map<String, String> parameters = new HashMap();
  75 + Map<String, String> parameters = new HashMap<>();
76 76  
77 77 parameters.put("keywords", "datamodel:\"" + type.toString() + "\"");
78 78 parameters.put("max", String.valueOf(MAX_VORESOURCES));
... ... @@ -82,14 +82,14 @@ public class VOResourceCtrl {
82 82 } catch (CantSendQueryException e) {
83 83 throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
84 84 }
85   - logger.info("Got resources: " + StringJoiner.join(ivoidResources));
  85 + LOGGER.info("Got resources: " + StringJoiner.join(ivoidResources));
86 86 return ivoidResources;
87 87 }
88 88  
89 89 public static List<String> getVOResources(ServiceCore type, List<String> keywords)
90 90 throws CantGetVOResourceException {
91 91 List<String> ivoidResources;
92   - Map<String, String> parameters = new HashMap();
  92 + Map<String, String> parameters = new HashMap<>();
93 93 String subjects = StringJoiner.join(keywords);
94 94 parameters.put("keywords",
95 95 "datamodel:\"" + type.toString() + "\" subjects:\"" + subjects + "\"");
... ... @@ -101,23 +101,23 @@ public class VOResourceCtrl {
101 101 } catch (CantSendQueryException e) {
102 102 throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
103 103 }
104   - logger.info("Got resources: " + StringJoiner.join(ivoidResources));
  104 + LOGGER.info("Got resources: " + StringJoiner.join(ivoidResources));
105 105 return ivoidResources;
106 106 }
107 107  
108 108 public static Resource getVOresource(String identifier) throws VOResourceException {
109   - Map<String, String> parameters = new HashMap();
  109 + Map<String, String> parameters = new HashMap<>();
110 110 parameters.put("identifier", identifier);
111 111 String voResourcePath;
112 112  
113 113 try {
114   - logger.info("Trying to get VOResource '" + identifier + "'...");
  114 + LOGGER.info("Trying to get VOResource '" + identifier + "'...");
115 115 String query = Network.buildQuery(GET_VORESOURCE_URL, parameters);
116 116 voResourcePath = Network.saveQuery(query);
117 117 } catch (CantSendQueryException e) {
118 118 throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
119 119 }
120   - logger.info("VOResource downloaded in " + voResourcePath);
  120 + LOGGER.info("VOResource downloaded in " + voResourcePath);
121 121  
122 122 try {
123 123 changeNamespaces(voResourcePath);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java
... ... @@ -43,6 +43,10 @@ public class VOResourceException extends Exception {
43 43  
44 44 public static class CantReadVOResourceException extends VOResourceException {
45 45  
  46 + /** The serial version UID. */
  47 + private static final long serialVersionUID = 1L;
  48 +
  49 +
46 50 /**
47 51 * @param voTablePath The path of the VOTable.
48 52 * @param e The exception thrown.
... ... @@ -54,6 +58,10 @@ public class VOResourceException extends Exception {
54 58  
55 59 public static class CantGetVOResourceException extends VOResourceException {
56 60  
  61 + /** The serial version UID. */
  62 + private static final long serialVersionUID = 1L;
  63 +
  64 +
57 65 /**
58 66 * @param voTablePath The path of the VOTable.
59 67 * @param e The exception thrown.
... ... @@ -65,6 +73,10 @@ public class VOResourceException extends Exception {
65 73  
66 74 public static class VOResourceIsNotValidException extends VOResourceException {
67 75  
  76 + /** The serial version UID. */
  77 + private static final long serialVersionUID = 1L;
  78 +
  79 +
68 80 /**
69 81 * @param voTablePath The path of the VOTable.
70 82 * @param e The exception thrown.
... ...
src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java
... ... @@ -42,7 +42,7 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableData;
42 42 public class EpnTapConnectionTest {
43 43  
44 44 /** The logger for the class Main. */
45   - private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName());
  45 + private static final Logger LOGGER = Logger.getLogger(EpnTapConnectionTest.class.getName());
46 46  
47 47 /** The AMDA ivoid, for testing purposes. */
48 48 private static final String AMDA_IVOID = "ivo://cdpp/amda";
... ... @@ -80,7 +80,7 @@ public class EpnTapConnectionTest {
80 80 */
81 81 @Test
82 82 public void getVOResourceTest() throws VOResourceException {
83   - logger.info("getVOResourceTest");
  83 + LOGGER.info("getVOResourceTest");
84 84 EpnTapConnection facade = new EpnTapConnection();
85 85  
86 86 Resource resource = facade.getEPNVOresource(AMDA_IVOID);
... ... @@ -98,7 +98,7 @@ public class EpnTapConnectionTest {
98 98 */
99 99 @Test
100 100 public void getEPNVOResourcesTest() throws VOResourceException {
101   - logger.info("getEPNVOResourcesTest");
  101 + LOGGER.info("getEPNVOResourcesTest");
102 102 EpnTapConnection facade = new EpnTapConnection();
103 103  
104 104 List<Resource> resources = facade.getEPNVOResources();
... ... @@ -129,7 +129,7 @@ public class EpnTapConnectionTest {
129 129 */
130 130 @Test
131 131 public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException {
132   - logger.info("getEPNVOResourcesWithKeywordsTest");
  132 + LOGGER.info("getEPNVOResourcesWithKeywordsTest");
133 133 EpnTapConnection facade = new EpnTapConnection();
134 134  
135 135 final List<String> keywords = new ArrayList<>();
... ... @@ -156,7 +156,7 @@ public class EpnTapConnectionTest {
156 156 */
157 157 @Test
158 158 public void getEPNServiceTest() throws CantGetVOTableException {
159   - logger.info("getEPNServiceTest");
  159 + LOGGER.info("getEPNServiceTest");
160 160 EpnTapConnection facade = new EpnTapConnection();
161 161  
162 162 VOTABLE voTable = facade.getEPNService(AMDA_IVOID);
... ... @@ -178,7 +178,7 @@ public class EpnTapConnectionTest {
178 178 */
179 179 @Test
180 180 public void getEPNServiceWithAttributesTest() throws CantGetVOTableException {
181   - logger.info("getEPNServiceWithAttributesTest");
  181 + LOGGER.info("getEPNServiceWithAttributesTest");
182 182 EpnTapConnection facade = new EpnTapConnection();
183 183  
184 184 final List<String> attributes = new ArrayList<>();
... ... @@ -203,7 +203,7 @@ public class EpnTapConnectionTest {
203 203 */
204 204 @Test
205 205 public void getEPNServicesTest() throws CantGetVOTableException {
206   - logger.info("getEPNServicesTest");
  206 + LOGGER.info("getEPNServicesTest");
207 207 EpnTapConnection facade = new EpnTapConnection();
208 208  
209 209 VOTABLE voTable = facade.getEPNServices();
... ... @@ -226,7 +226,7 @@ public class EpnTapConnectionTest {
226 226 @Test
227 227 public void getEPNServicesWithAttributesTest()
228 228 throws CantGetVOTableException {
229   - logger.info("getEPNServicesWithAttributesTest");
  229 + LOGGER.info("getEPNServicesWithAttributesTest");
230 230 EpnTapConnection facade = new EpnTapConnection();
231 231  
232 232 final List<String> attributes = new ArrayList<>();
... ... @@ -258,7 +258,7 @@ public class EpnTapConnectionTest {
258 258 @Test
259 259 public void getEPNServicesWithKeywordsAndAttributesTest()
260 260 throws CantGetVOTableException, VOResourceException {
261   - logger.info("getEPNServicesWithKeywordsAndAttributesTest");
  261 + LOGGER.info("getEPNServicesWithKeywordsAndAttributesTest");
262 262 EpnTapConnection facade = new EpnTapConnection();
263 263  
264 264 final List<String> keywords = new ArrayList<>();
... ... @@ -293,7 +293,7 @@ public class EpnTapConnectionTest {
293 293 */
294 294 @Test
295 295 public void getEPNCoreTableNameTest() throws CantGetVOTableException {
296   - logger.info("getEPNCoreTableNameTest");
  296 + LOGGER.info("getEPNCoreTableNameTest");
297 297 EpnTapConnection facade = new EpnTapConnection();
298 298  
299 299 String epnCoreTableName = facade.getEPNCoreTableName(AMDA_IVOID);
... ... @@ -308,7 +308,7 @@ public class EpnTapConnectionTest {
308 308 */
309 309 @Test
310 310 public void getTAPURLTest() throws CantGetVOTableException {
311   - logger.info("getTAPURLTest");
  311 + LOGGER.info("getTAPURLTest");
312 312 EpnTapConnection facade = new EpnTapConnection();
313 313  
314 314 String tapURL = facade.getTAPURL("ivo://cdpp/amda");
... ... @@ -325,7 +325,7 @@ public class EpnTapConnectionTest {
325 325 */
326 326 @Test
327 327 public void sendADQLQueryTest() throws CantGetVOTableException {
328   - logger.info("sendADQLQueryTest");
  328 + LOGGER.info("sendADQLQueryTest");
329 329 EpnTapConnection facade = new EpnTapConnection();
330 330  
331 331 List<Granule> granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL,
... ... @@ -351,7 +351,7 @@ public class EpnTapConnectionTest {
351 351 */
352 352 @Test
353 353 public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException {
354   - logger.info("sendADQLQueryWithSchemaNameTest");
  354 + LOGGER.info("sendADQLQueryWithSchemaNameTest");
355 355 EpnTapConnection facade = new EpnTapConnection();
356 356 List<Granule> granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL,
357 357 SERVICE_EPNCOREV2_TABLE_NAME, Query.GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL);
... ...