diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java index 36e06a8..fdbddc3 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController; public class EpnTapController { /** The logger for the class EpnTapController. */ - private static final Logger logger = Logger.getLogger(EpnTapController.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EpnTapController.class.getName()); /** The controller of the VOTable displaying the list of services. */ private VOTableController servicesCtrl; @@ -79,7 +79,7 @@ public class EpnTapController { */ @SuppressWarnings("static-method") public void displayError(String message, Exception e) { - logger.log(Level.SEVERE, message, e); + LOGGER.log(Level.SEVERE, message, e); } /** diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java index 6f7d02b..cf3bb2b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java @@ -34,7 +34,7 @@ import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelView; public class EpnTapMainApp { /** The logger for the class EpnTapMainApp. */ - private static final Logger logger = Logger.getLogger(EpnTapMainApp.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EpnTapMainApp.class.getName()); /** Error message when the user put a wrong command. */ private static final String WRONG_COMMAND = "Usage: EpnTapMainApp"; @@ -50,7 +50,7 @@ public class EpnTapMainApp { * @param args The program arguments (not used). */ public static void main(final String[] args) { - EpnTapMainApp.logger.info("Lauching EPNTAP app with arguments: " + new Gson().toJson(args)); + EpnTapMainApp.LOGGER.info("Lauching EPNTAP app with arguments: " + new Gson().toJson(args)); if (args.length != 0) { System.console().writer().println(EpnTapMainApp.WRONG_COMMAND); return; diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java b/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java index 7b8566f..77b37eb 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java @@ -20,17 +20,21 @@ package eu.omp.irap.vespa.epntapclient; * @author N. Jourdane */ public enum Query { - // @noformat - GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL( - "SELECT * FROM %s"), - GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL_AND_SURFACE_AREA( - "SELECT * FROM %s"); + /** Query to get a the scene from a target and a time interval. */ + GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL("SELECT * FROM %s"), + /** Query to get a the scene from a target, a time interval and a surface area. */ + GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL_AND_SURFACE_AREA("SELECT * FROM %s"); // TBC - // @format + /** The string literal of the query. */ private String literalQuery; + /** + * Enumeration constructor + * + * @param literalQuery The query. + */ Query(String literalQuery) { this.literalQuery = literalQuery; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java index 720cee1..f5c873b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java @@ -36,23 +36,39 @@ public class RequestCtrl { /** The URL of the resolver used for the `target name` field. */ private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete"; + /** The query template to get granules. */ + private static final String QUERY = "SELECT TOP %s target_name, target_class FROM %s%s"; + /** The parameters fields for the request. */ - protected Map paramValues = new HashMap<>(); + protected Map parameters = new HashMap<>(); + + /** The maximum number of rows returned by the query. */ + private int nbMaxResult; + /** Constructor of RequestCtrl. */ public RequestCtrl() { - /* Subclasses initializes their own attributes, we don't want to initialize them twice. */ + nbMaxResult = 20; } /** - * @param nbRow The maximum number of rows returned. - * @param tableName The name of the target table for the query. - * @param params A map of parameters, for the `WHERE` keywords. - * @return The literal string of the query. + * Constructor of RequestCtrl. + * + * @param nbMaxResult The maximum number of rows returned by the query. */ - public String getQuery(String tableName, int nbRow) { + public RequestCtrl(int nbMaxResult) { + this.nbMaxResult = nbMaxResult; + } + + /** + * Build an ADQL from the table name, the parameter values and the max results. + * + * @param tableName The name of the table, to put in FROM keyword. + * @return The query. + */ + public String buildQuery(String tableName) { StringJoiner addJoin = new StringJoiner(" AND "); - for (Map.Entry param : paramValues.entrySet()) { + for (Map.Entry param : parameters.entrySet()) { if (param.getValue() instanceof ArrayList) { StringJoiner orJoin = new StringJoiner(" OR "); @SuppressWarnings("unchecked") @@ -69,7 +85,7 @@ public class RequestCtrl { } String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; - return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; + return String.format(QUERY, nbMaxResult, tableName, where); } /** @@ -77,8 +93,7 @@ public class RequestCtrl { * * @param begining The beginning of the target_name. * @return An array of Strings corresponding to the target names got. - * @throws CantSendQueryException - * @throws CantGetXMLException If the resolver do not work. + * @throws CantSendQueryException Can not read the JSON file. */ public static String[] getTargetNames(String begining) throws CantSendQueryException { Map params = new HashMap<>(); @@ -96,16 +111,48 @@ public class RequestCtrl { return targetNames; } + /** + * Update a parameter in the query. If the parameter do not exists yet, create it. + * + * @param paramName The name of the parameter. + * @param paramValue The value of the parameter. + */ public void updateParameter(String paramName, Object paramValue) { - paramValues.put(paramName, paramValue); + parameters.put(paramName, paramValue); } + /** + * Remove a parameter from the query. + * + * @param paramName The name of the parameter to remove. + */ public void removeParameter(String paramName) { - paramValues.remove(paramName); + parameters.remove(paramName); + } + + /** + * Get the parameters. + * + * @return A map of couple . + */ + public Map getParameters() { + return parameters; + } + + /** + * @return The maximum number of rows returned by the query. + */ + public int getNbMaxResult() { + return nbMaxResult; } - public Map getParamValues() { - return paramValues; + /** + * Set the maximum number of rows returned by the query. + * + * @param nbRows The number of rows. + */ + public void setNbMaxResult(int nbRows) { + nbMaxResult = nbRows; } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java index f4ddf17..2369ed2 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java @@ -280,10 +280,6 @@ public class Granule { private String timeScale; - /** Private constructor to hide the default public one. */ - private Granule() { - } - /** * Constructor of Granule * diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java index f19a0ca..aa0757c 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java @@ -32,7 +32,7 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableData; public class GranuleCtrl { /** The logger for the class GranuleCtrl. */ - private static final Logger logger = Logger.getLogger(GranuleCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(GranuleCtrl.class.getName()); /** The data to parse */ private VOTableData data; @@ -62,7 +62,7 @@ public class GranuleCtrl { try { res = (String) data.getCell(rowId, granule.toString()); } catch (IllegalArgumentException e) { - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty string"), e); + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty string"), e); } return res; } @@ -81,7 +81,7 @@ public class GranuleCtrl { try { date = sdf.parse((String) data.getCell(rowId, granule.toString())); } catch (IllegalArgumentException e) { - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty date"), e); + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "empty date"), e); } return date; @@ -99,7 +99,7 @@ public class GranuleCtrl { try { d = (Double) data.getCell(rowId, granule.toString()); } catch (IllegalArgumentException e) { - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "double.NaN"), e); + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "double.NaN"), e); } return d == null ? Double.NaN : d; @@ -117,7 +117,7 @@ public class GranuleCtrl { try { val = (Integer) data.getCell(rowId, granule.toString()); } catch (IllegalArgumentException e) { - logger.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "0"), e); + LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "0"), e); } return val; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java index bc84fdf..a55d21d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; public class MainPanelCtrl extends EpnTapController { /** The logger for the class GUIController. */ - private static final Logger logger = Logger.getLogger(MainPanelCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); /** The controller of the request panel. */ private RequestPanelCtrl requestPanelCtrl; @@ -47,9 +47,6 @@ public class MainPanelCtrl extends EpnTapController { /** The main view of the application. */ private MainPanelView view; - /** The maximum number of rows returned by the query. */ - private int nbMaxResult = 10; - /** * Constructor of MainPanelCtrl. @@ -73,21 +70,24 @@ public class MainPanelCtrl extends EpnTapController { /** * Send the specified query to the selected service and update the result table content. - * + * * @param query The query to send. */ public void sendQuery(String query) { String serviceURL = servicesPanelCtrl.getSelectedServiceURL(); - logger.info("Sending query: " + query + " on " + serviceURL); + LOGGER.info("Sending query: " + query + " on " + serviceURL); try { resultPanelCtrl.updateVOTable(serviceURL, query); view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); } catch (CantGetVOTableException e) { displayError("Can not send the query.", e); - MainPanelCtrl.logger.log(Level.WARNING, "Can not send query.", e); + LOGGER.log(Level.WARNING, "Can not send query.", e); } } + /** + * @return The controller of the request panel. + */ public RequestPanelCtrl getRequestPanelCtrl() { return requestPanelCtrl; } @@ -106,22 +106,7 @@ public class MainPanelCtrl extends EpnTapController { @Override public void displayError(String message, Exception e) { - logger.log(Level.SEVERE, message, e); + LOGGER.log(Level.SEVERE, message, e); JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); } - - /** - * @return the nb max of result - */ - public int getNbMaxResult() { - return nbMaxResult; - } - - /** - * set the nb max of result for a query - */ - public void setNbMaxResult(int nb) { - nbMaxResult = nb; - } - } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java index 8aad52a..deafc88 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java @@ -20,7 +20,6 @@ import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.RequestCtrl; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; -import eu.omp.irap.vespa.epntapclient.service.Queries; /** * @author N. Jourdane @@ -28,7 +27,7 @@ import eu.omp.irap.vespa.epntapclient.service.Queries; public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListener { /** The logger for the class RequestPanelCtrl. */ - private static final Logger logger = Logger.getLogger(RequestPanelCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(RequestPanelCtrl.class.getName()); MainPanelCtrl mainPanelCtrl; @@ -63,8 +62,7 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene * Update the query area with a working ADQL query, based on the parameters list. */ public void updateQueryArea() { - String query = Queries.getQuery(mainPanelCtrl.getServicePanelCtrl().getSelectedTableName(), - paramValues, mainPanelCtrl.getNbMaxResult()); + String query = buildQuery(mainPanelCtrl.getServicePanelCtrl().getSelectedTableName()); view.updateQueryArea(query); } @@ -72,13 +70,13 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene public void onParameterRemoved(String paramName) { removeParameter(paramName); updateQueryArea(); - logger.info("removed " + paramName); + LOGGER.info("removed " + paramName); } @Override public void onParameterChanged(String paramName, Object paramValue) { updateParameter(paramName, paramValue); updateQueryArea(); - logger.info("uploaded " + paramName + ": " + paramValue); + LOGGER.info("uploaded " + paramName + ": " + paramValue); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java index c570ab9..69d9182 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java @@ -64,7 +64,7 @@ public class RequestPanelView extends JPanel { /** The height of the buttons panel. */ private static final int BUTTON_PANEL_HEIGHT = 20; - private RequestPanelListener requestPanelListener; + RequestPanelListener requestPanelListener; /** @@ -194,7 +194,7 @@ public class RequestPanelView extends JPanel { } }); buttonPanel.add(btnSend); - buttonPanel.setMaximumSize(new Dimension(1000, RequestPanelView.BUTTON_PANEL_HEIGHT)); + buttonPanel.setMaximumSize(new Dimension(1000, BUTTON_PANEL_HEIGHT)); return buttonPanel; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java index ccb1fba..4fe1f6b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java @@ -64,9 +64,7 @@ public class DataProductTypeField extends ParamField { if (comboBox == null) { comboBox = new JComboBox<>(DataProductType.values()); comboBox.setSelectedItem(DataProductType.ALL); - comboBox.setPreferredSize( - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT)); - + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @Override diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java index 08611c3..b6d2eb8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java @@ -47,7 +47,7 @@ public class FloatField extends ParamField implements TextFieldListener { public FloatField(RequestPanelListener requestPanelListener, String paramName) { super(requestPanelListener, paramName); field = new JTextField(); - ParamField.addChangeListener(this, field); + addChangeListener(this, field); this.add(field); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java index 3ece7bc..006c5e5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java @@ -50,13 +50,13 @@ public class FloatRangeField extends ParamField implements TextFieldListener { public FloatRangeField(RequestPanelListener requestPanelListener, String paramName) { super(requestPanelListener, paramName); fieldMin = new JTextField(); - fieldMin.setName(ParamField.MIN_SUFFIX); - ParamField.addChangeListener(this, fieldMin); + fieldMin.setName(MIN_SUFFIX); + addChangeListener(this, fieldMin); this.add(fieldMin); fieldMax = new JTextField(); - fieldMax.setName(ParamField.MAX_SUFFIX); - ParamField.addChangeListener(this, fieldMax); + fieldMax.setName(MAX_SUFFIX); + addChangeListener(this, fieldMax); this.add(fieldMax); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java index 3a250b8..c7400dd 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java @@ -42,7 +42,7 @@ public abstract class ParamField extends JPanel { private static final long serialVersionUID = 1L; /** The logger for the class ParamField. */ - static final Logger logger = Logger.getLogger(ParamField.class.getName()); + static final Logger LOGGER = Logger.getLogger(ParamField.class.getName()); /** The minimum width of the field. */ static final int MIN_FIELD_WIDTH = 30; @@ -88,11 +88,11 @@ public abstract class ParamField extends JPanel { private void buildParamField() { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - setMaximumSize(new Dimension(ParamField.MAX_FIELD_WIDTH, ParamField.FIELD_HEIGHT)); + setMaximumSize(new Dimension(MAX_FIELD_WIDTH, FIELD_HEIGHT)); String strLabel = paramName.replaceAll("_", " ").trim(); JLabel label = new JLabel(strLabel.substring(0, 1).toUpperCase() + strLabel.substring(1)); - label.setPreferredSize(new Dimension(ParamField.LABEL_WIDTH, ParamField.FIELD_HEIGHT)); + label.setPreferredSize(new Dimension(LABEL_WIDTH, FIELD_HEIGHT)); this.add(label); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java index 1e929d8..7908ab6 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java @@ -44,7 +44,7 @@ public class StringField extends ParamField implements TextFieldListener { public StringField(RequestPanelListener requestPanelListener, String paramName) { super(requestPanelListener, paramName); field = new JTextField(); - ParamField.addChangeListener(this, field); + addChangeListener(this, field); this.add(field); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java index 1936d1e..b2b76d4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java @@ -51,8 +51,7 @@ public class TargetClassField extends ParamField { public TargetClassField(RequestPanelListener requestPanelListener, String paramName) { super(requestPanelListener, paramName); comboBox = new JComboBox<>(TargetClass.values()); - comboBox.setPreferredSize( - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT)); + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @Override diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java index 4f24d42..fb8ee1f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java @@ -53,39 +53,6 @@ public class TargetNameField extends ParamField implements TextFieldListener { */ String lastContent; - /** - * This method is called each time the field is modified. A Runnable is used it is impossible to - * modify the comboBox from a DocumentEvent. - */ - Runnable updateComboBox = new Runnable() { - - @Override - public void run() { - String content = field.getText(); - if (!content.equals(lastContent)) { - if (content.length() >= 2) { - lastContent = content; - comboBox.removeAllItems(); - try { - for (String s : RequestCtrl.getTargetNames(content)) { - comboBox.addItem(s); - } - } catch (CantSendQueryException e) { - ParamField.logger.log(Level.WARNING, - "Can't get table names for the resolver", e); - } - comboBox.getEditor().setItem(content); - comboBox.showPopup(); - } - if (content.isEmpty()) { - requestPanelListener.onParameterRemoved(paramName); - } else { - requestPanelListener.onParameterChanged(paramName, content); - } - } - } - }; - /** * Method constructor @@ -96,26 +63,60 @@ public class TargetNameField extends ParamField implements TextFieldListener { public TargetNameField(RequestPanelListener requestPanelListener, String paramName) { super(requestPanelListener, paramName); comboBox = new JComboBox<>(); - comboBox.setPreferredSize( - new Dimension(ParamField.MIN_FIELD_WIDTH, ParamField.FIELD_HEIGHT)); - + comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.setEditable(true); field = (JTextField) comboBox.getEditor().getEditorComponent(); - ParamField.addChangeListener(this, field); + addChangeListener(this, field); this.add(comboBox); } public TargetNameField(String paraName) { - // @noformat this(new RequestPanelListener() { + @Override - public void onSendButtonClicked(String query) {/** no SendButtonClicked event, we just want the field */} + public void onSendButtonClicked(String query) { + /** No SendButtonClicked event, we just want the field itself. */ + } + @Override - public void onParameterRemoved(String paramName) {/** no ParameterRemoved event, we just want the field */} + public void onParameterRemoved(String paramName) { + /** No ParameterRemoved event, we just want the field itself. */ + } + @Override - public void onParameterChanged(String paramName, Object paramValue) {/** no ParameterChanged event, we just want the field */} + public void onParameterChanged(String paramName, Object paramValue) { + /** No ParameterChanged event, we just want the field itself. */ + } }, paraName); - // @format + } + + /** + * This method is called each time the field is modified. A Runnable is used it is impossible to + * modify the comboBox from a DocumentEvent. + */ + void updateComboBox() { + String content = field.getText(); + if (!content.equals(lastContent)) { + if (content.length() >= 2) { + lastContent = content; + comboBox.removeAllItems(); + try { + for (String s : RequestCtrl.getTargetNames(content)) { + comboBox.addItem(s); + } + } catch (CantSendQueryException e) { + LOGGER.log(Level.WARNING, + "Can't get table names for the resolver", e); + } + comboBox.getEditor().setItem(content); + comboBox.showPopup(); + } + if (content.isEmpty()) { + requestPanelListener.onParameterRemoved(paramName); + } else { + requestPanelListener.onParameterChanged(paramName, content); + } + } } /** @@ -123,7 +124,13 @@ public class TargetNameField extends ParamField implements TextFieldListener { */ @Override public void update(JTextField textField) { - SwingUtilities.invokeLater(updateComboBox); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateComboBox(); + } + }); } } \ No newline at end of file diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java index 8000681..6756c14 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java @@ -32,7 +32,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController; public class ResultPanelCtrl extends VOTableController implements ResultPanelListener { /** The logger for the class ResultPanelCtrl. */ - private static final Logger logger = Logger.getLogger(ResultPanelCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ResultPanelCtrl.class.getName()); private MainPanelCtrl mainPanelCtrl; @@ -50,7 +50,7 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis Files.copy(Paths.get(voTablePath), Paths.get(file.getAbsolutePath())); } catch (IOException e) { mainPanelCtrl.displayError("Can not save the file.", e); - logger.log(Level.WARNING, "Can not save the file.", e); + LOGGER.log(Level.WARNING, "Can not save the file.", e); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java index f50f874..2cc2d53 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java @@ -30,7 +30,7 @@ import eu.omp.irap.vespa.votable.controller.VOTableController; public class ServicesPanelCtrl extends VOTableController implements ServicesPanelListener { /** The logger for the class ServicesPanelCtrl. */ - private static final Logger logger = Logger.getLogger(ServicesPanelCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ServicesPanelCtrl.class.getName()); /** The name of the table selected by the user on the table list panel. */ private String selectedTableName; @@ -71,7 +71,7 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane selectedServiceURL = serviceURL; selectedTableName = tableName; mainPanelCtrl.getRequestPanelCtrl().updateQueryArea(); - logger.info( + LOGGER.info( "Selected table: " + selectedTableName + " - service: " + selectedServiceURL); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java index 5f80431..a2f8b65 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java @@ -37,7 +37,7 @@ public class ServicesPanelView extends VOTableView { /** The serial version UID. */ private static final long serialVersionUID = 1L; - private ServicesPanelListener viewListener; + ServicesPanelListener viewListener; private JButton serviceButton; diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java index d342376..9ba2c78 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java @@ -16,12 +16,6 @@ package eu.omp.irap.vespa.epntapclient.service; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import eu.omp.irap.vespa.votable.utils.StringJoiner; - /** * Defines the queries and the query patterns usually used in the application. * @@ -29,8 +23,6 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; */ public final class Queries { - public static final String RETURN_PARAMETERS = "target_name, target_class"; - private static final String SELECT = "SELECT DISTINCT short_name, res_title, " + "table_name, schema_name, ivoid, access_url "; @@ -52,29 +44,25 @@ public final class Queries { /** Query to get all TAP services. */ public static final String SELECT_ALL_TAP_SERVICES = - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY; + SELECT + FROM + WHERE_TAP + ORDER_BY; /** Query to get TAP services which implement the specified core. */ public static final String SELECT_ALL_TAP_SERVICES_WHERE_CORE = - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP - + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') " - + Queries.ORDER_BY; + SELECT + FROM + WHERE_TAP + + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') " + ORDER_BY; /** Query to get the TAP service with the specified ivoid. */ public static final String SELECT_ALL_TAP_SERVICES_WHERE_IVOID = - Queries.SELECT + Queries.FROM + Queries.WHERE_TAP - + "AND ivoid = '%s'"; + SELECT + FROM + WHERE_TAP + "AND ivoid = '%s'"; public static final String SELECT_TAP_SERVICES_WHERE_IVOID = - "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP - + "AND ivoid = '%s'"; + "SELECT DISTINCT %s " + FROM + WHERE_TAP + "AND ivoid = '%s'"; public static final String SELECT_TAP_SERVICES = - "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP; + "SELECT DISTINCT %s " + FROM + WHERE_TAP; public static final String SELECT_TAP_SERVICES_WHERE_SUBJECT = - "SELECT DISTINCT %s " + Queries.FROM + "NATURAL JOIN rr.res_subject " - + Queries.WHERE_TAP + "AND (%s)"; + "SELECT DISTINCT %s " + FROM + "NATURAL JOIN rr.res_subject " + WHERE_TAP + "AND (%s)"; public static final String SELECT_FROM = "SELECT DISTINCT %s FROM %s"; @@ -88,38 +76,4 @@ public final class Queries { private Queries() { } - /** - * The default query, with these parameters, respectively: max_rows, target_name, time_min, - * time_max, dataproduct_type, spectral_range_min, spectral_range_max. - * - * @param nbRow The maximum number of rows returned. - * @param tableName The name of the target table for the query. - * @param params A map of parameters, for the `WHERE` keywords. - * @return The literal string of the query. - */ - public static String getQuery(String tableName, Map params, int nbRow) { - StringJoiner addJoin = new StringJoiner(" AND "); - for (Map.Entry param : params.entrySet()) { - if (param.getValue() instanceof ArrayList) { - StringJoiner orJoin = new StringJoiner(" OR "); - @SuppressWarnings("unchecked") - List possibleValues = (List) param.getValue(); - for (String possibleValue : possibleValues) { - orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); - } - addJoin.add("(" + orJoin + ")"); - } else if (param.getValue() instanceof String) { - addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); - } else { - addJoin.add(param.getKey() + " = " + param.getValue().toString()); - } - } - String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; - - return "SELECT TOP " + nbRow + " " - + RETURN_PARAMETERS - + " " - + "FROM " + tableName + where; - } - } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java index 5fbd04a..82635e0 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java @@ -42,9 +42,6 @@ public class Service { private String updated; - private Service() { - } - Service(String ivoid) { this.ivoid = ivoid; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java index 8498186..94d35da 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java @@ -49,7 +49,7 @@ import eu.omp.irap.vespa.votable.utils.XMLUtils; public class VOResourceCtrl { /** The logger for the class VOResourceController. */ - private static final Logger logger = Logger.getLogger(VOResourceCtrl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(VOResourceCtrl.class.getName()); private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml"; @@ -72,7 +72,7 @@ public class VOResourceCtrl { public static List getVOResources(ServiceCore type) throws VOResourceException { List ivoidResources; - Map parameters = new HashMap(); + Map parameters = new HashMap<>(); parameters.put("keywords", "datamodel:\"" + type.toString() + "\""); parameters.put("max", String.valueOf(MAX_VORESOURCES)); @@ -82,14 +82,14 @@ public class VOResourceCtrl { } catch (CantSendQueryException e) { throw new CantGetVOResourceException(GET_VORESOURCE_URL, e); } - logger.info("Got resources: " + StringJoiner.join(ivoidResources)); + LOGGER.info("Got resources: " + StringJoiner.join(ivoidResources)); return ivoidResources; } public static List getVOResources(ServiceCore type, List keywords) throws CantGetVOResourceException { List ivoidResources; - Map parameters = new HashMap(); + Map parameters = new HashMap<>(); String subjects = StringJoiner.join(keywords); parameters.put("keywords", "datamodel:\"" + type.toString() + "\" subjects:\"" + subjects + "\""); @@ -101,23 +101,23 @@ public class VOResourceCtrl { } catch (CantSendQueryException e) { throw new CantGetVOResourceException(GET_VORESOURCE_URL, e); } - logger.info("Got resources: " + StringJoiner.join(ivoidResources)); + LOGGER.info("Got resources: " + StringJoiner.join(ivoidResources)); return ivoidResources; } public static Resource getVOresource(String identifier) throws VOResourceException { - Map parameters = new HashMap(); + Map parameters = new HashMap<>(); parameters.put("identifier", identifier); String voResourcePath; try { - logger.info("Trying to get VOResource '" + identifier + "'..."); + LOGGER.info("Trying to get VOResource '" + identifier + "'..."); String query = Network.buildQuery(GET_VORESOURCE_URL, parameters); voResourcePath = Network.saveQuery(query); } catch (CantSendQueryException e) { throw new CantGetVOResourceException(GET_VORESOURCE_URL, e); } - logger.info("VOResource downloaded in " + voResourcePath); + LOGGER.info("VOResource downloaded in " + voResourcePath); try { changeNamespaces(voResourcePath); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java index 657a629..0726527 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java @@ -43,6 +43,10 @@ public class VOResourceException extends Exception { public static class CantReadVOResourceException extends VOResourceException { + /** The serial version UID. */ + private static final long serialVersionUID = 1L; + + /** * @param voTablePath The path of the VOTable. * @param e The exception thrown. @@ -54,6 +58,10 @@ public class VOResourceException extends Exception { public static class CantGetVOResourceException extends VOResourceException { + /** The serial version UID. */ + private static final long serialVersionUID = 1L; + + /** * @param voTablePath The path of the VOTable. * @param e The exception thrown. @@ -65,6 +73,10 @@ public class VOResourceException extends Exception { public static class VOResourceIsNotValidException extends VOResourceException { + /** The serial version UID. */ + private static final long serialVersionUID = 1L; + + /** * @param voTablePath The path of the VOTable. * @param e The exception thrown. diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java index e01bf3d..4d6ad82 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java @@ -42,7 +42,7 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableData; public class EpnTapConnectionTest { /** The logger for the class Main. */ - private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EpnTapConnectionTest.class.getName()); /** The AMDA ivoid, for testing purposes. */ private static final String AMDA_IVOID = "ivo://cdpp/amda"; @@ -80,7 +80,7 @@ public class EpnTapConnectionTest { */ @Test public void getVOResourceTest() throws VOResourceException { - logger.info("getVOResourceTest"); + LOGGER.info("getVOResourceTest"); EpnTapConnection facade = new EpnTapConnection(); Resource resource = facade.getEPNVOresource(AMDA_IVOID); @@ -98,7 +98,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNVOResourcesTest() throws VOResourceException { - logger.info("getEPNVOResourcesTest"); + LOGGER.info("getEPNVOResourcesTest"); EpnTapConnection facade = new EpnTapConnection(); List resources = facade.getEPNVOResources(); @@ -129,7 +129,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException { - logger.info("getEPNVOResourcesWithKeywordsTest"); + LOGGER.info("getEPNVOResourcesWithKeywordsTest"); EpnTapConnection facade = new EpnTapConnection(); final List keywords = new ArrayList<>(); @@ -156,7 +156,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNServiceTest() throws CantGetVOTableException { - logger.info("getEPNServiceTest"); + LOGGER.info("getEPNServiceTest"); EpnTapConnection facade = new EpnTapConnection(); VOTABLE voTable = facade.getEPNService(AMDA_IVOID); @@ -178,7 +178,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNServiceWithAttributesTest() throws CantGetVOTableException { - logger.info("getEPNServiceWithAttributesTest"); + LOGGER.info("getEPNServiceWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); final List attributes = new ArrayList<>(); @@ -203,7 +203,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNServicesTest() throws CantGetVOTableException { - logger.info("getEPNServicesTest"); + LOGGER.info("getEPNServicesTest"); EpnTapConnection facade = new EpnTapConnection(); VOTABLE voTable = facade.getEPNServices(); @@ -226,7 +226,7 @@ public class EpnTapConnectionTest { @Test public void getEPNServicesWithAttributesTest() throws CantGetVOTableException { - logger.info("getEPNServicesWithAttributesTest"); + LOGGER.info("getEPNServicesWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); final List attributes = new ArrayList<>(); @@ -258,7 +258,7 @@ public class EpnTapConnectionTest { @Test public void getEPNServicesWithKeywordsAndAttributesTest() throws CantGetVOTableException, VOResourceException { - logger.info("getEPNServicesWithKeywordsAndAttributesTest"); + LOGGER.info("getEPNServicesWithKeywordsAndAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); final List keywords = new ArrayList<>(); @@ -293,7 +293,7 @@ public class EpnTapConnectionTest { */ @Test public void getEPNCoreTableNameTest() throws CantGetVOTableException { - logger.info("getEPNCoreTableNameTest"); + LOGGER.info("getEPNCoreTableNameTest"); EpnTapConnection facade = new EpnTapConnection(); String epnCoreTableName = facade.getEPNCoreTableName(AMDA_IVOID); @@ -308,7 +308,7 @@ public class EpnTapConnectionTest { */ @Test public void getTAPURLTest() throws CantGetVOTableException { - logger.info("getTAPURLTest"); + LOGGER.info("getTAPURLTest"); EpnTapConnection facade = new EpnTapConnection(); String tapURL = facade.getTAPURL("ivo://cdpp/amda"); @@ -325,7 +325,7 @@ public class EpnTapConnectionTest { */ @Test public void sendADQLQueryTest() throws CantGetVOTableException { - logger.info("sendADQLQueryTest"); + LOGGER.info("sendADQLQueryTest"); EpnTapConnection facade = new EpnTapConnection(); List granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL, @@ -351,7 +351,7 @@ public class EpnTapConnectionTest { */ @Test public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException { - logger.info("sendADQLQueryWithSchemaNameTest"); + LOGGER.info("sendADQLQueryWithSchemaNameTest"); EpnTapConnection facade = new EpnTapConnection(); List granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL, SERVICE_EPNCOREV2_TABLE_NAME, Query.GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL); -- libgit2 0.21.2