Commit 024489218bc7d58537de6038b8178c3d04db4da2

Authored by Nathanael Jourdane
1 parent fd1d4872
Exists in master

Improve service panel controller, add ServicesList class.

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java
... ... @@ -17,7 +17,6 @@
17 17 package eu.omp.irap.vespa.epntapclient;
18 18  
19 19 import java.util.List;
20   -import java.util.logging.Level;
21 20 import java.util.logging.Logger;
22 21  
23 22 import eu.omp.irap.vespa.epntapclient.service.Queries;
... ... @@ -64,17 +63,6 @@ public abstract class EpnTapController {
64 63 }
65 64  
66 65 /**
67   - * Display an error with the logger.
68   - *
69   - * @param message A small error message.
70   - * @param e The error.
71   - */
72   - @SuppressWarnings("static-method") // Because the method is overrided by a subclass.
73   - public void displayError(String message, Exception e) {
74   - LOGGER.log(Level.SEVERE, message, e);
75   - }
76   -
77   - /**
78 66 * @return The request controller.
79 67 */
80 68 public RequestCtrl getRequestCtrl() {
... ... @@ -104,29 +92,38 @@ public abstract class EpnTapController {
104 92  
105 93 /**
106 94 * Get the services from the XML path or the targetURL / query.
  95 + *
  96 + * @throws VOTableException Can not read the services.
107 97 */
108   - public void readServices() {
  98 + public void readServices() throws VOTableException {
109 99 // Here getServicesCtrl() is used instead of class field servicesCtrl to get the
110 100 // subclass field, since subclasses overrides getServicesCtrl().
111   - try {
112   - getServicesCtrl().readTable();
113   - } catch (VOTableException e) {
114   - displayError("Can not get services.", e);
115   - }
  101 + getServicesCtrl().readTable();
116 102 }
117 103  
118   - public void sendQuery(List<String> tableNames, List<String> servicesUrls) {
  104 + /**
  105 + * ...
  106 + *
  107 + * @param tableNames
  108 + * @param servicesUrls
  109 + * @throws VOTableException Can not update the VOTable.
  110 + * @throws EpnTapException The lists are empty.
  111 + */
  112 + public void sendQuery(List<String> tableNames, List<String> servicesUrls)
  113 + throws VOTableException, EpnTapException {
119 114 // Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl
120 115 // and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and
121 116 // getResultsCtrl().
122   - try {
123   - LOGGER.info("Sending queries on " + StringJoiner.join(servicesUrls));
124   - for (int i = 0; i < tableNames.size(); i++) {
125   - String query = getRequestCtrl().getQuery(tableNames.get(i));
126   - getResultsCtrl().updateVOTable(servicesUrls.get(i), query);
127   - }
128   - } catch (VOTableException e) {
129   - displayError("Can not update the VOTable.", e);
  117 + LOGGER.info("Sending query(ies) on " + StringJoiner.join(servicesUrls));
  118 + if (tableNames.isEmpty()) {
  119 + throw new EpnTapException("There is no service to query.");
  120 + } else if (tableNames.size() != servicesUrls.size()) {
  121 + throw new EpnTapException(
  122 + "list of tableNames and list of servicesUrls are not the same size.");
  123 + }
  124 + for (int i = 0; i < tableNames.size(); i++) {
  125 + String query = getRequestCtrl().getQuery(tableNames.get(i));
  126 + getResultsCtrl().updateVOTable(servicesUrls.get(i), query);
130 127 }
131 128  
132 129 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapException.java 0 โ†’ 100644
... ... @@ -0,0 +1,42 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public class EpnTapException extends Exception {
  23 +
  24 + /** The serial version UID. */
  25 + private static final long serialVersionUID = 1L;
  26 +
  27 +
  28 + /**
  29 + * @param message A message describing the error.
  30 + */
  31 + public EpnTapException(String message) {
  32 + super(message);
  33 + }
  34 +
  35 + /**
  36 + * @param message A message describing the error.
  37 + */
  38 + public EpnTapException(String message, Exception e) {
  39 + super(message, e);
  40 + }
  41 +
  42 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/ServicesList.java 0 โ†’ 100644
... ... @@ -0,0 +1,87 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient;
  18 +
  19 +import java.util.ArrayList;
  20 +import java.util.List;
  21 +import java.util.logging.Logger;
  22 +
  23 +import eu.omp.irap.vespa.votable.utils.StringJoiner;
  24 +
  25 +/**
  26 + * @author N. Jourdane
  27 + */
  28 +public class ServicesList {
  29 +
  30 + /** The logger for the class ServicesList. */
  31 + private static final Logger LOGGER = Logger.getLogger(ServicesList.class.getName());
  32 +
  33 + private List<String> customTableNames;
  34 +
  35 + private List<String> customTargetUrls;
  36 +
  37 + private List<String> selectedTableNames;
  38 +
  39 + private List<String> selectedTargetUrls;
  40 +
  41 +
  42 + /**
  43 + * Constructor of LightServicesList
  44 + */
  45 + public ServicesList() {
  46 + customTableNames = new ArrayList<>();
  47 + customTargetUrls = new ArrayList<>();
  48 + selectedTableNames = new ArrayList<>();
  49 + selectedTargetUrls = new ArrayList<>();
  50 + }
  51 +
  52 + /**
  53 + * @return the tableName
  54 + */
  55 + public List<String> getTableNames() {
  56 + List<String> tableNames = new ArrayList<>();
  57 + tableNames.addAll(selectedTableNames);
  58 + tableNames.addAll(customTableNames);
  59 + return tableNames;
  60 + }
  61 +
  62 + /**
  63 + * @return the targetUrl
  64 + */
  65 + public List<String> getTargetUrls() {
  66 + List<String> targetUrls = new ArrayList<>();
  67 + targetUrls.addAll(selectedTargetUrls);
  68 + targetUrls.addAll(customTargetUrls);
  69 + return targetUrls;
  70 + }
  71 +
  72 + public void updateCustomServices(List<String> customTableNamesToAdd,
  73 + List<String> customTargetUrlsToAdd) {
  74 + customTableNames = customTableNamesToAdd;
  75 + customTargetUrls = customTargetUrlsToAdd;
  76 + LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTableNames));
  77 + LOGGER.info("Updated custom services URLs: " + StringJoiner.join(customTargetUrls));
  78 + }
  79 +
  80 + public void updateSelectedServices(List<String> selectedTableNamesToAdd,
  81 + List<String> selectedTargetUrlsToAdd) {
  82 + selectedTableNames = selectedTableNamesToAdd;
  83 + selectedTargetUrls = selectedTargetUrlsToAdd;
  84 + LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTableNames));
  85 + LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedTargetUrls));
  86 + }
  87 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
... ... @@ -17,19 +17,26 @@
17 17 package eu.omp.irap.vespa.epntapclient.gui.mainpanel;
18 18  
19 19 import java.util.List;
  20 +import java.util.logging.Level;
  21 +import java.util.logging.Logger;
20 22  
21 23 import javax.swing.JOptionPane;
22 24  
23 25 import eu.omp.irap.vespa.epntapclient.EpnTapController;
  26 +import eu.omp.irap.vespa.epntapclient.EpnTapException;
24 27 import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl;
25 28 import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelCtrl;
26 29 import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl;
  30 +import eu.omp.irap.vespa.votable.controller.VOTableException;
27 31  
28 32 /**
29 33 * @author N. Jourdane
30 34 */
31 35 public class MainPanelCtrl extends EpnTapController implements MainPanelListener {
32 36  
  37 + /** The logger for the class MainPanelCtrl. */
  38 + private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName());
  39 +
33 40 /** The controller of the request panel. */
34 41 private RequestPanelCtrl requestPanelCtrl;
35 42  
... ... @@ -55,7 +62,7 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
55 62  
56 63 @Override
57 64 public void displayError(String message, Exception e) {
58   - super.displayError(message, e);
  65 + LOGGER.log(Level.SEVERE, message, e);
59 66 JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE);
60 67 }
61 68  
... ... @@ -85,7 +92,7 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
85 92  
86 93 @Override
87 94 public List<String> getTableNames() {
88   - return servicesPanelCtrl.getTablesNames();
  95 + return servicesPanelCtrl.getServices().getTableNames();
89 96 }
90 97  
91 98 /**
... ... @@ -97,13 +104,25 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
97 104  
98 105 @Override
99 106 public void readServices() {
100   - super.readServices();
  107 + try {
  108 + super.readServices();
  109 + } catch (VOTableException e) {
  110 + displayError("Can not read services.", e);
  111 + }
101 112 view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData());
102 113 }
103 114  
104 115 @Override
105 116 public void sendQuery() {
106   - sendQuery(servicesPanelCtrl.getTablesNames(), servicesPanelCtrl.getServicesUrls());
  117 + try {
  118 + List<String> tableNames = servicesPanelCtrl.getServices().getTableNames();
  119 + List<String> targetUrls = servicesPanelCtrl.getServices().getTargetUrls();
  120 + sendQuery(tableNames, targetUrls);
  121 + } catch (EpnTapException e) {
  122 + displayError("There is no service selected.", e);
  123 + } catch (VOTableException e) {
  124 + displayError("Can not update the VOTable.", e);
  125 + }
107 126 }
108 127  
109 128 @Override
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java
... ... @@ -24,6 +24,7 @@ import java.util.logging.Logger;
24 24  
25 25 import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener;
26 26 import eu.omp.irap.vespa.votable.controller.VOTableController;
  27 +import eu.omp.irap.vespa.votable.controller.VOTableException;
27 28 import eu.omp.irap.vespa.votable.utils.StringJoiner;
28 29  
29 30 /**
... ... @@ -71,8 +72,12 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis
71 72 }
72 73  
73 74 @Override
74   - public void updateVOTable(String newTargetURL, String newQuery)
75   - throws eu.omp.irap.vespa.votable.controller.VOTableException {
  75 + public void updateVOTable(String newTargetURL, String newQuery) {
  76 + try {
  77 + super.updateVOTable(newTargetURL, newQuery);
  78 + } catch (VOTableException e) {
  79 + listener.displayError("Can not update the VOTable.", e);
  80 + }
76 81 view.fillTable(voTableData);
77 82 }
78 83 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java
... ... @@ -19,14 +19,13 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
19 19 import java.util.ArrayList;
20 20 import java.util.Arrays;
21 21 import java.util.List;
22   -import java.util.logging.Logger;
23 22  
  23 +import eu.omp.irap.vespa.epntapclient.ServicesList;
24 24 import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener;
25 25 import eu.omp.irap.vespa.epntapclient.service.Queries;
26 26 import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
27 27 import eu.omp.irap.vespa.votable.Consts;
28 28 import eu.omp.irap.vespa.votable.controller.VOTableController;
29   -import eu.omp.irap.vespa.votable.utils.StringJoiner;
30 29  
31 30 /**
32 31 * @author N. Jourdane
... ... @@ -36,35 +35,17 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
36 35 /** The separator used between each services in the custom service text fields. */
37 36 private static final String CUSTOM_SERVICES_SEPARATOR = ";";
38 37  
39   - /** The logger for the class ServicesPanelCtrl. */
40   - private static final Logger LOGGER = Logger.getLogger(ServicesPanelCtrl.class.getName());
41   -
42 38 /** The position of the column displaying the services target URLs in the service table. */
43 39 private static final int SERVICE_URL_COLUMN_POSITION = 1;
44 40  
45 41 /** The position of the column displaying the table names in the service table. */
46 42 private static final int TABLE_NAME_COLUMN_POSITION = 4;
47 43  
48   - /** The list of services target Urls selected by the user on the service panel. */
49   - private List<String> customServicesUrls;
50   -
51   - /** The list of services table names selected by the user on the service panel. */
52   - private List<String> customTablesNames;
53   -
54 44 /** The listener of the main panel. */
55 45 private MainPanelListener listener;
56 46  
57 47 /** The list of services target Urls selected by the user on the service panel. */
58   - private List<String> selectedServicesUrls;
59   -
60   - /** The list of services table names selected by the user on the service panel. */
61   - private List<String> selectedTablesNames;
62   -
63   - /** The list of services target Urls selected by the user on the service panel. */
64   - private List<String> servicesUrls;
65   -
66   - /** The list of services table names selected by the user on the service panel. */
67   - private List<String> tablesNames;
  48 + private ServicesList services;
68 49  
69 50 /** The view of the services panel. */
70 51 private ServicesPanelView view;
... ... @@ -77,8 +58,7 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
77 58 */
78 59 public ServicesPanelCtrl(MainPanelListener listener) {
79 60 this.listener = listener;
80   - customTablesNames = new ArrayList<>();
81   - customServicesUrls = new ArrayList<>();
  61 + services = new ServicesList();
82 62 targetURL = Consts.DEFAULT_REGISTRY_URL;
83 63 query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE);
84 64 view = new ServicesPanelView(this);
... ... @@ -87,15 +67,8 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
87 67 /**
88 68 * @return The list of services target Urls selected by the user on the service panel.
89 69 */
90   - public List<String> getServicesUrls() {
91   - return servicesUrls;
92   - }
93   -
94   - /**
95   - * @return The list of services table names selected by the user on the service panel.
96   - */
97   - public List<String> getTablesNames() {
98   - return tablesNames;
  70 + public ServicesList getServices() {
  71 + return services;
99 72 }
100 73  
101 74 /**
... ... @@ -107,55 +80,29 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
107 80 }
108 81  
109 82 @Override
110   - public void onCustomServiceUpdated() {
111   - String customServiceUrl = view.getServiceUrlTextField().getText();
112   - String customTableName = view.getTableNameTextField().getText();
113   -
114   - if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) {
115   - List<String> newServicesUrls = new ArrayList<>();
116   - List<String> newTablesNames = new ArrayList<>();
117   -
118   - newServicesUrls
119   - .addAll(Arrays.asList(customServiceUrl.split(CUSTOM_SERVICES_SEPARATOR)));
120   - newTablesNames.addAll(Arrays.asList(customTableName.split(CUSTOM_SERVICES_SEPARATOR)));
121   -
122   - if (newServicesUrls.size() == newTablesNames.size()) {
123   - // TODO: regex to check valid url / table name
124   - customServicesUrls = newServicesUrls;
125   - customTablesNames = newTablesNames;
126   -
127   - servicesUrls = selectedServicesUrls;
128   - tablesNames = selectedTablesNames;
129   - servicesUrls.addAll(customServicesUrls);
130   - tablesNames.addAll(customTablesNames);
131   -
132   - LOGGER.info(
133   - "Updated custom services URLs: " + StringJoiner.join(customServicesUrls));
134   - LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTablesNames));
135   - }
136   - }
137   - }
138   -
139   - @Override
140 83 public void onRowsSelected() {
141   - List<String> newServicesUrls = new ArrayList<>();
142 84 List<String> newTablesNames = new ArrayList<>();
  85 + List<String> newServicesUrls = new ArrayList<>();
143 86  
144 87 for (int row : view.getSelectedRows()) {
145   - newServicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row));
146 88 newTablesNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row));
  89 + newServicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row));
147 90 }
  91 + services.updateSelectedServices(newTablesNames, newServicesUrls);
  92 + listener.updateQuery();
  93 + }
148 94  
149   - selectedServicesUrls = newServicesUrls;
150   - selectedTablesNames = newTablesNames;
151   -
152   - servicesUrls = customServicesUrls;
153   - tablesNames = customTablesNames;
154   - servicesUrls.addAll(selectedServicesUrls);
155   - tablesNames.addAll(customTablesNames);
156   -
  95 + @Override
  96 + public void onServiceUpdated() {
  97 + String tableName = view.getTableNameTextField().getText();
  98 + String targetUrl = view.getServiceUrlTextField().getText();
  99 + List<String> customTableNames = Arrays.asList(tableName.split(CUSTOM_SERVICES_SEPARATOR));
  100 + List<String> customServicesUrls = Arrays.asList(targetUrl.split(CUSTOM_SERVICES_SEPARATOR));
  101 +
  102 + if (!tableName.isEmpty() && !targetUrl.isEmpty()
  103 + && customTableNames.size() == customServicesUrls.size()) {
  104 + services.updateCustomServices(customTableNames, customServicesUrls);
  105 + }
157 106 listener.updateQuery();
158   - LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedServicesUrls));
159   - LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTablesNames));
160 107 }
161 108 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java
... ... @@ -23,5 +23,5 @@ import eu.omp.irap.vespa.votable.view.VOTableViewListener;
23 23 */
24 24 public interface ServicesPanelListener extends VOTableViewListener {
25 25  
26   - public void onCustomServiceUpdated();
  26 + public void onServiceUpdated();
27 27 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java
... ... @@ -61,17 +61,17 @@ public class ServicesPanelView extends VOTableView {
61 61  
62 62 @Override
63 63 public void changedUpdate(DocumentEvent e) {
64   - listener.onCustomServiceUpdated();
  64 + listener.onServiceUpdated();
65 65 }
66 66  
67 67 @Override
68 68 public void insertUpdate(DocumentEvent e) {
69   - listener.onCustomServiceUpdated();
  69 + listener.onServiceUpdated();
70 70 }
71 71  
72 72 @Override
73 73 public void removeUpdate(DocumentEvent e) {
74   - listener.onCustomServiceUpdated();
  74 + listener.onServiceUpdated();
75 75 }
76 76 });
77 77 }
... ...