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 314da2e..123f205 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -17,7 +17,6 @@ package eu.omp.irap.vespa.epntapclient; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.service.Queries; @@ -64,17 +63,6 @@ public abstract class EpnTapController { } /** - * Display an error with the logger. - * - * @param message A small error message. - * @param e The error. - */ - @SuppressWarnings("static-method") // Because the method is overrided by a subclass. - public void displayError(String message, Exception e) { - LOGGER.log(Level.SEVERE, message, e); - } - - /** * @return The request controller. */ public RequestCtrl getRequestCtrl() { @@ -104,29 +92,38 @@ public abstract class EpnTapController { /** * Get the services from the XML path or the targetURL / query. + * + * @throws VOTableException Can not read the services. */ - public void readServices() { + public void readServices() throws VOTableException { // Here getServicesCtrl() is used instead of class field servicesCtrl to get the // subclass field, since subclasses overrides getServicesCtrl(). - try { - getServicesCtrl().readTable(); - } catch (VOTableException e) { - displayError("Can not get services.", e); - } + getServicesCtrl().readTable(); } - public void sendQuery(List tableNames, List servicesUrls) { + /** + * ... + * + * @param tableNames + * @param servicesUrls + * @throws VOTableException Can not update the VOTable. + * @throws EpnTapException The lists are empty. + */ + public void sendQuery(List tableNames, List servicesUrls) + throws VOTableException, EpnTapException { // Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl // and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and // getResultsCtrl(). - try { - LOGGER.info("Sending queries on " + StringJoiner.join(servicesUrls)); - for (int i = 0; i < tableNames.size(); i++) { - String query = getRequestCtrl().getQuery(tableNames.get(i)); - getResultsCtrl().updateVOTable(servicesUrls.get(i), query); - } - } catch (VOTableException e) { - displayError("Can not update the VOTable.", e); + LOGGER.info("Sending query(ies) on " + StringJoiner.join(servicesUrls)); + if (tableNames.isEmpty()) { + throw new EpnTapException("There is no service to query."); + } else if (tableNames.size() != servicesUrls.size()) { + throw new EpnTapException( + "list of tableNames and list of servicesUrls are not the same size."); + } + for (int i = 0; i < tableNames.size(); i++) { + String query = getRequestCtrl().getQuery(tableNames.get(i)); + getResultsCtrl().updateVOTable(servicesUrls.get(i), query); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapException.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapException.java new file mode 100644 index 0000000..42186f7 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapException.java @@ -0,0 +1,42 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient; + +/** + * @author N. Jourdane + */ +public class EpnTapException extends Exception { + + /** The serial version UID. */ + private static final long serialVersionUID = 1L; + + + /** + * @param message A message describing the error. + */ + public EpnTapException(String message) { + super(message); + } + + /** + * @param message A message describing the error. + */ + public EpnTapException(String message, Exception e) { + super(message, e); + } + +} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/ServicesList.java b/src/main/java/eu/omp/irap/vespa/epntapclient/ServicesList.java new file mode 100644 index 0000000..6ea81c4 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/ServicesList.java @@ -0,0 +1,87 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import eu.omp.irap.vespa.votable.utils.StringJoiner; + +/** + * @author N. Jourdane + */ +public class ServicesList { + + /** The logger for the class ServicesList. */ + private static final Logger LOGGER = Logger.getLogger(ServicesList.class.getName()); + + private List customTableNames; + + private List customTargetUrls; + + private List selectedTableNames; + + private List selectedTargetUrls; + + + /** + * Constructor of LightServicesList + */ + public ServicesList() { + customTableNames = new ArrayList<>(); + customTargetUrls = new ArrayList<>(); + selectedTableNames = new ArrayList<>(); + selectedTargetUrls = new ArrayList<>(); + } + + /** + * @return the tableName + */ + public List getTableNames() { + List tableNames = new ArrayList<>(); + tableNames.addAll(selectedTableNames); + tableNames.addAll(customTableNames); + return tableNames; + } + + /** + * @return the targetUrl + */ + public List getTargetUrls() { + List targetUrls = new ArrayList<>(); + targetUrls.addAll(selectedTargetUrls); + targetUrls.addAll(customTargetUrls); + return targetUrls; + } + + public void updateCustomServices(List customTableNamesToAdd, + List customTargetUrlsToAdd) { + customTableNames = customTableNamesToAdd; + customTargetUrls = customTargetUrlsToAdd; + LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTableNames)); + LOGGER.info("Updated custom services URLs: " + StringJoiner.join(customTargetUrls)); + } + + public void updateSelectedServices(List selectedTableNamesToAdd, + List selectedTargetUrlsToAdd) { + selectedTableNames = selectedTableNamesToAdd; + selectedTargetUrls = selectedTargetUrlsToAdd; + LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTableNames)); + LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedTargetUrls)); + } +} 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 d06aaea..6526a59 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 @@ -17,19 +17,26 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.JOptionPane; import eu.omp.irap.vespa.epntapclient.EpnTapController; +import eu.omp.irap.vespa.epntapclient.EpnTapException; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl; +import eu.omp.irap.vespa.votable.controller.VOTableException; /** * @author N. Jourdane */ public class MainPanelCtrl extends EpnTapController implements MainPanelListener { + /** The logger for the class MainPanelCtrl. */ + private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); + /** The controller of the request panel. */ private RequestPanelCtrl requestPanelCtrl; @@ -55,7 +62,7 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener @Override public void displayError(String message, Exception e) { - super.displayError(message, e); + LOGGER.log(Level.SEVERE, message, e); JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); } @@ -85,7 +92,7 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener @Override public List getTableNames() { - return servicesPanelCtrl.getTablesNames(); + return servicesPanelCtrl.getServices().getTableNames(); } /** @@ -97,13 +104,25 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener @Override public void readServices() { - super.readServices(); + try { + super.readServices(); + } catch (VOTableException e) { + displayError("Can not read services.", e); + } view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); } @Override public void sendQuery() { - sendQuery(servicesPanelCtrl.getTablesNames(), servicesPanelCtrl.getServicesUrls()); + try { + List tableNames = servicesPanelCtrl.getServices().getTableNames(); + List targetUrls = servicesPanelCtrl.getServices().getTargetUrls(); + sendQuery(tableNames, targetUrls); + } catch (EpnTapException e) { + displayError("There is no service selected.", e); + } catch (VOTableException e) { + displayError("Can not update the VOTable.", e); + } } @Override 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 770ff7b..cf30014 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 @@ -24,6 +24,7 @@ import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; import eu.omp.irap.vespa.votable.controller.VOTableController; +import eu.omp.irap.vespa.votable.controller.VOTableException; import eu.omp.irap.vespa.votable.utils.StringJoiner; /** @@ -71,8 +72,12 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis } @Override - public void updateVOTable(String newTargetURL, String newQuery) - throws eu.omp.irap.vespa.votable.controller.VOTableException { + public void updateVOTable(String newTargetURL, String newQuery) { + try { + super.updateVOTable(newTargetURL, newQuery); + } catch (VOTableException e) { + listener.displayError("Can not update the VOTable.", e); + } view.fillTable(voTableData); } } 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 dc733d3..2b9be9a 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 @@ -19,14 +19,13 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Logger; +import eu.omp.irap.vespa.epntapclient.ServicesList; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; import eu.omp.irap.vespa.epntapclient.service.Queries; import eu.omp.irap.vespa.epntapclient.service.ServiceCore; import eu.omp.irap.vespa.votable.Consts; import eu.omp.irap.vespa.votable.controller.VOTableController; -import eu.omp.irap.vespa.votable.utils.StringJoiner; /** * @author N. Jourdane @@ -36,35 +35,17 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane /** The separator used between each services in the custom service text fields. */ private static final String CUSTOM_SERVICES_SEPARATOR = ";"; - /** The logger for the class ServicesPanelCtrl. */ - private static final Logger LOGGER = Logger.getLogger(ServicesPanelCtrl.class.getName()); - /** The position of the column displaying the services target URLs in the service table. */ private static final int SERVICE_URL_COLUMN_POSITION = 1; /** The position of the column displaying the table names in the service table. */ private static final int TABLE_NAME_COLUMN_POSITION = 4; - /** The list of services target Urls selected by the user on the service panel. */ - private List customServicesUrls; - - /** The list of services table names selected by the user on the service panel. */ - private List customTablesNames; - /** The listener of the main panel. */ private MainPanelListener listener; /** The list of services target Urls selected by the user on the service panel. */ - private List selectedServicesUrls; - - /** The list of services table names selected by the user on the service panel. */ - private List selectedTablesNames; - - /** The list of services target Urls selected by the user on the service panel. */ - private List servicesUrls; - - /** The list of services table names selected by the user on the service panel. */ - private List tablesNames; + private ServicesList services; /** The view of the services panel. */ private ServicesPanelView view; @@ -77,8 +58,7 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane */ public ServicesPanelCtrl(MainPanelListener listener) { this.listener = listener; - customTablesNames = new ArrayList<>(); - customServicesUrls = new ArrayList<>(); + services = new ServicesList(); targetURL = Consts.DEFAULT_REGISTRY_URL; query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); view = new ServicesPanelView(this); @@ -87,15 +67,8 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane /** * @return The list of services target Urls selected by the user on the service panel. */ - public List getServicesUrls() { - return servicesUrls; - } - - /** - * @return The list of services table names selected by the user on the service panel. - */ - public List getTablesNames() { - return tablesNames; + public ServicesList getServices() { + return services; } /** @@ -107,55 +80,29 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane } @Override - public void onCustomServiceUpdated() { - String customServiceUrl = view.getServiceUrlTextField().getText(); - String customTableName = view.getTableNameTextField().getText(); - - if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) { - List newServicesUrls = new ArrayList<>(); - List newTablesNames = new ArrayList<>(); - - newServicesUrls - .addAll(Arrays.asList(customServiceUrl.split(CUSTOM_SERVICES_SEPARATOR))); - newTablesNames.addAll(Arrays.asList(customTableName.split(CUSTOM_SERVICES_SEPARATOR))); - - if (newServicesUrls.size() == newTablesNames.size()) { - // TODO: regex to check valid url / table name - customServicesUrls = newServicesUrls; - customTablesNames = newTablesNames; - - servicesUrls = selectedServicesUrls; - tablesNames = selectedTablesNames; - servicesUrls.addAll(customServicesUrls); - tablesNames.addAll(customTablesNames); - - LOGGER.info( - "Updated custom services URLs: " + StringJoiner.join(customServicesUrls)); - LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTablesNames)); - } - } - } - - @Override public void onRowsSelected() { - List newServicesUrls = new ArrayList<>(); List newTablesNames = new ArrayList<>(); + List newServicesUrls = new ArrayList<>(); for (int row : view.getSelectedRows()) { - newServicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row)); newTablesNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row)); + newServicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row)); } + services.updateSelectedServices(newTablesNames, newServicesUrls); + listener.updateQuery(); + } - selectedServicesUrls = newServicesUrls; - selectedTablesNames = newTablesNames; - - servicesUrls = customServicesUrls; - tablesNames = customTablesNames; - servicesUrls.addAll(selectedServicesUrls); - tablesNames.addAll(customTablesNames); - + @Override + public void onServiceUpdated() { + String tableName = view.getTableNameTextField().getText(); + String targetUrl = view.getServiceUrlTextField().getText(); + List customTableNames = Arrays.asList(tableName.split(CUSTOM_SERVICES_SEPARATOR)); + List customServicesUrls = Arrays.asList(targetUrl.split(CUSTOM_SERVICES_SEPARATOR)); + + if (!tableName.isEmpty() && !targetUrl.isEmpty() + && customTableNames.size() == customServicesUrls.size()) { + services.updateCustomServices(customTableNames, customServicesUrls); + } listener.updateQuery(); - LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedServicesUrls)); - LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTablesNames)); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java index 4e465f9..f9c2e62 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java @@ -23,5 +23,5 @@ import eu.omp.irap.vespa.votable.view.VOTableViewListener; */ public interface ServicesPanelListener extends VOTableViewListener { - public void onCustomServiceUpdated(); + public void onServiceUpdated(); } 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 68aa67c..a338651 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 @@ -61,17 +61,17 @@ public class ServicesPanelView extends VOTableView { @Override public void changedUpdate(DocumentEvent e) { - listener.onCustomServiceUpdated(); + listener.onServiceUpdated(); } @Override public void insertUpdate(DocumentEvent e) { - listener.onCustomServiceUpdated(); + listener.onServiceUpdated(); } @Override public void removeUpdate(DocumentEvent e) { - listener.onCustomServiceUpdated(); + listener.onServiceUpdated(); } }); } -- libgit2 0.21.2