From e669c5d39fadbbc38773a6d289339874d336c53a Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 18 May 2016 18:17:41 +0200 Subject: [PATCH] Improve Javadoc. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java | 27 ++++++++++++++------------- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java | 8 ++++---- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java | 38 +++++++++++++++++++------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java | 6 +++--- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java | 16 ++++++++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java | 16 ++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java | 38 ++++++++++++++++++++++++++------------ src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java | 51 ++++++++++++++++++++++++++++++++++++++++----------- src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java | 17 ++++++++++++----- src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java | 38 +++++++++++++++++++------------------- 11 files changed, 231 insertions(+), 101 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java index 4dc6f2b..6ad0143 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java @@ -29,8 +29,9 @@ import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl; import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; -import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; import eu.omp.irap.vespa.votable.controller.VOTableController; +import eu.omp.irap.vespa.votable.controller.VOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException.CantReadVOTableException; import eu.omp.irap.vespa.votable.utils.StringJoiner; import eu.omp.irap.vespa.votable.votabledata.VOTableData; @@ -50,7 +51,7 @@ public class EpnTapConnection implements EpnTapInterface { @Override public List getEPNVOResources() throws VOResourceException { - List ivoids = VOResourceCtrl.getVOResources(ServiceCore.EPNCORE); + List ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE); return VOResourceCtrl.getVOResources(ivoids); } @@ -64,14 +65,14 @@ public class EpnTapConnection implements EpnTapInterface { // *** Service *** @Override - public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException { + public VOTABLE getEPNService(String ivoid) throws VOTableException { String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_IVOID, ivoid); return ServiceCtrl.getVoTable(query); } @Override public VOTABLE getEPNService(String ivoid, List attributes) - throws CantGetVOTableException { + throws VOTableException { String select = StringJoiner.join(attributes); String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, select, ivoid); return ServiceCtrl.getVoTable(query); @@ -80,14 +81,14 @@ public class EpnTapConnection implements EpnTapInterface { // *** Services *** @Override - public VOTABLE getEPNServices() throws CantGetVOTableException { + public VOTABLE getEPNServices() throws VOTableException { String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); return ServiceCtrl.getVoTable(query); } @Override - public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException { + public VOTABLE getEPNServices(List attributes) throws VOTableException { String select = StringJoiner.join(attributes); String query = String.format(Queries.SELECT_TAP_SERVICES, select); return ServiceCtrl.getVoTable(query); @@ -95,7 +96,7 @@ public class EpnTapConnection implements EpnTapInterface { @Override public VOTABLE getEPNServices(List keywords, List attributes) - throws CantGetVOTableException { + throws VOTableException { attributes.add("res_subject"); String select = StringJoiner.join(attributes); List whereList = new ArrayList<>(); @@ -110,12 +111,12 @@ public class EpnTapConnection implements EpnTapInterface { // *** Getters *** @Override - public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException { + public String getEPNCoreTableName(String ivoid) throws VOTableException { return (String) ServiceCtrl.getParameter(ivoid, "table_name"); } @Override - public String getTAPURL(String ivoid) throws CantGetVOTableException { + public String getTAPURL(String ivoid) throws VOTableException { return (String) ServiceCtrl.getParameter(ivoid, "access_url"); } @@ -123,7 +124,7 @@ public class EpnTapConnection implements EpnTapInterface { @Override public List sendADQLQuery(String tapURL, String adqlQuery) - throws CantGetVOTableException { + throws VOTableException { VOTableController voTableCtrl = new VOTableController(tapURL, adqlQuery); voTableCtrl.readTable(); VOTableData data = voTableCtrl.getVOTableData(); @@ -133,14 +134,14 @@ public class EpnTapConnection implements EpnTapInterface { GranuleCtrl gc = new GranuleCtrl(data); granules = gc.getGranules(); } catch (ParseException e) { - throw new CantGetVOTableException("Parsing error on a granule.", e); + throw new CantReadVOTableException("Parsing error on a granule.", e); } return granules; } @Override public List sendQuery(String tapURL, String schemaName, Query enumeratedQuery) - throws CantGetVOTableException { + throws VOTableException { String query = String.format(enumeratedQuery.toString(), schemaName); VOTableController voTableCtrl = new VOTableController(tapURL, query); voTableCtrl.readTable(); @@ -151,7 +152,7 @@ public class EpnTapConnection implements EpnTapInterface { GranuleCtrl gc = new GranuleCtrl(data); granules = gc.getGranules(); } catch (ParseException e) { - throw new CantGetVOTableException("Parsing error on a granule.", e); + throw new CantReadVOTableException("Parsing error on a granule.", e); } return granules; } 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 fdbddc3..226e382 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -22,7 +22,7 @@ import java.util.logging.Logger; 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.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException; import eu.omp.irap.vespa.votable.controller.VOTableController; /** @@ -66,7 +66,7 @@ public class EpnTapController { public void readServices() { try { servicesCtrl.readTable(); - } catch (CantGetVOTableException e) { + } catch (VOTableException e) { displayError("Can not get services.", e); } } @@ -87,10 +87,10 @@ public class EpnTapController { * * @param query An ADQL query to send. * @param tableServiceURL the URL of the service. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ public void sendQuery(String query, String tableServiceURL) - throws CantGetVOTableException { + throws VOTableException { resultsCtrl = new VOTableController(tableServiceURL, query); resultsCtrl.readTable(); voTablePath = resultsCtrl.getVOTablePath(); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java index 7f2a530..22388e5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java @@ -23,7 +23,7 @@ import eu.omp.irap.vespa.epntapclient.granule.GranuleEnum; import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; -import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException; /** * @author N. Jourdane @@ -74,9 +74,9 @@ public interface EpnTapInterface { * * @param ivoid The ivoid of the service to get. * @return A VOTable containing the service. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException; + public VOTABLE getEPNService(String ivoid) throws VOTableException; /** * Returns a VOTable containing the attributes of the corresponding service (from the list of @@ -86,10 +86,10 @@ public interface EpnTapInterface { * @param attributes A list of attributes, which are the column names to get. * @return A VOTable containing the service. * @see GranuleEnum The EpnTapv2 column names. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ public VOTABLE getEPNService(String ivoid, List attributes) - throws CantGetVOTableException; + throws VOTableException; // *** Services *** @@ -98,9 +98,9 @@ public interface EpnTapInterface { * predefined list). * * @return A VOTable containing the services. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public VOTABLE getEPNServices() throws CantGetVOTableException; + public VOTABLE getEPNServices() throws VOTableException; /** * Returns a VOTable containing the list of EPN-TAP services and their attributes (from the list @@ -108,9 +108,9 @@ public interface EpnTapInterface { * * @param attributes A list of attributes, which are the column names to get. * @return A VOTable containing the services. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException; + public VOTABLE getEPNServices(List attributes) throws VOTableException; /** * Returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and @@ -120,10 +120,10 @@ public interface EpnTapInterface { * rr.res_subject of a registry. * @param attributes A list of attributes, which are the column names to get. * @return A VOTable containing the services. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ public VOTABLE getEPNServices(List keywords, List attributes) - throws CantGetVOTableException; + throws VOTableException; // *** Getters *** @@ -132,18 +132,18 @@ public interface EpnTapInterface { * * @param ivoid The ivoid of the service. * @return The table name of the service, used usually in the 'FROM' keyword in a ADQL query. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException; + public String getEPNCoreTableName(String ivoid) throws VOTableException; /** * Returns the Access URL of an EPN-TAP Service. * * @param ivoid the ivoid of the service. * @return The target URL of the service, used usually to process requests on it. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public String getTAPURL(String ivoid) throws CantGetVOTableException; + public String getTAPURL(String ivoid) throws VOTableException; // *** Queries *** @@ -155,10 +155,10 @@ public interface EpnTapInterface { * @param tapURL The URL of the service. * @param adqlQuery The ADQL query. * @return A list of Granules resulting the query. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ public List sendADQLQuery(String tapURL, String adqlQuery) - throws CantGetVOTableException; + throws VOTableException; /** * Returns the list of granules which are compliant with the Query, in VOTable format. "Query" @@ -169,8 +169,8 @@ public interface EpnTapInterface { * @param schemaName The name of the service schema. * @param query The query, from a list a predefined queries. * @return A list of granules resulting the query. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ public List sendQuery(String tapURL, String schemaName, Query query) - throws CantGetVOTableException; + throws VOTableException; } 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 82f7319..ec5475a 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 @@ -25,7 +25,7 @@ import eu.omp.irap.vespa.epntapclient.EpnTapController; 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.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException; /** * @author N. Jourdane @@ -62,7 +62,7 @@ public class MainPanelCtrl extends EpnTapController { public void readServices() { try { servicesPanelCtrl.readTable(); - } catch (CantGetVOTableException e) { + } catch (VOTableException e) { displayError("Can not get services.", e); } view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); @@ -79,7 +79,7 @@ public class MainPanelCtrl extends EpnTapController { try { resultPanelCtrl.updateVOTable(serviceURL, query); view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); - } catch (CantGetVOTableException e) { + } catch (VOTableException e) { displayError("Can not send the query.", e); LOGGER.log(Level.WARNING, "Can not send query.", e); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java index 0d667d8..d8437e1 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java @@ -49,8 +49,7 @@ public class ResultPanelView extends VOTableView { * Method constructor which customize the result panel, but don't build it from scratch since * VOTableView is already created by ResultController. * - * @param mainView The main view of the application. - * @param voTableView The generic view of the VOTable panel. + * @param listener The listener of the result view. */ public ResultPanelView(ResultPanelListener listener) { super(); @@ -58,6 +57,9 @@ public class ResultPanelView extends VOTableView { buildResultPanel(); } + /** + * Build the panel and add graphical elements to it. + */ public void buildResultPanel() { JPanel statusBar = new JPanel(); statusBar.setLayout(new BorderLayout()); @@ -67,6 +69,11 @@ public class ResultPanelView extends VOTableView { add(statusBar, BorderLayout.SOUTH); } + /** + * Returns the info label, create it if doesn't exist. + * + * @return The info label. + */ public JLabel getInfoLabel() { return infoLabel == null ? new JLabel() : infoLabel; } @@ -78,6 +85,11 @@ public class ResultPanelView extends VOTableView { infoLabel.setText(infoText); } + /** + * Returns the button to save the VOTable, create it if doesn't exist. + * + * @return The button to save the VOTable. + */ public JButton getFileButton() { if (fileButton == null) { fileButton = new JButton("Get File"); 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 1389315..1f28162 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 @@ -32,8 +32,10 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane /** The logger for the class ServicesPanelCtrl. */ private static final Logger LOGGER = Logger.getLogger(ServicesPanelCtrl.class.getName()); + /** The controller of the main panel. */ private MainPanelCtrl mainPanelCtrl; + /** The view of the services panel. */ private ServicesPanelView view; /** The name of the table selected by the user on the table list panel. */ @@ -43,6 +45,11 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane private String selectedServiceURL; + /** + * Constructor of ServicesPanelCtrl + * + * @param mainPanelCtrl The controller of the main panel. + */ public ServicesPanelCtrl(MainPanelCtrl mainPanelCtrl) { this.mainPanelCtrl = mainPanelCtrl; targetURL = Consts.DEFAULT_REGISTRY_URL; @@ -50,14 +57,23 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane view = new ServicesPanelView(this); } + /** + * @return The view of the services panel. + */ public ServicesPanelView getView() { return view; } + /** + * @return The table name of the service selected by the user on the services table list. + */ public String getSelectedTableName() { return selectedTableName; } + /** + * @return The access URL of the service selected by the user on the services table list. + */ public String getSelectedServiceURL() { return selectedServiceURL; } 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 e71bd37..3804aba 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 @@ -23,10 +23,17 @@ package eu.omp.irap.vespa.epntapclient.service; */ public final class Queries { - private static final String SELECT = "SELECT DISTINCT ivoid, access_url, res_title, " + /** + * The default SELECT keyword content of the query, which select standard service column names. + */ + private static final String SELECT_SERVICE = "SELECT DISTINCT ivoid, access_url, res_title, " + "short_name, table_name, content_type, res_description, creator_seq, content_level, " + "reference_url, created, updated "; + /** The default SELECT keyword */ + private static final String SELECT = "SELECT DISTINCT "; + + /** The default FROM keyword content of the query, which links all required tables. */ private static final String FROM = "FROM rr.resource " + "NATURAL JOIN rr.res_schema " + "NATURAL JOIN rr.res_table " @@ -34,8 +41,10 @@ public final class Queries { + "NATURAL JOIN rr.res_detail " + "NATURAL JOIN rr.capability "; + /** The default ORDER BY keyword content of the query. */ private static final String ORDER_BY = "ORDER BY short_name, table_name"; + /** The default WHERE keyword content of the query, in order to get only TAP services. */ private static final String WHERE_TAP = "WHERE " + "standard_id='ivo://ivoa.net/std/tap' AND " + "intf_type='vs:paramhttp' AND " @@ -45,29 +54,34 @@ public final class Queries { /** Query to get all TAP services. */ public static final String SELECT_ALL_TAP_SERVICES = - SELECT + FROM + WHERE_TAP + ORDER_BY; + SELECT_SERVICE + FROM + WHERE_TAP + ORDER_BY; + + /** Query to get the specified columns (%s #1) of all TAP services. */ + public static final String SELECT_TAP_SERVICES = + SELECT + "%s " + FROM + WHERE_TAP; - /** Query to get TAP services which implement the specified core. */ + /** Query to get TAP services which implement the specified core (%s #1). */ public static final String SELECT_ALL_TAP_SERVICES_WHERE_CORE = - SELECT + FROM + WHERE_TAP + SELECT_SERVICE + 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. */ + /** Query to get the TAP service with the specified ivoid (%s #1). */ public static final String SELECT_ALL_TAP_SERVICES_WHERE_IVOID = - SELECT + FROM + WHERE_TAP + "AND ivoid = '%s'"; + SELECT_SERVICE + FROM + WHERE_TAP + "AND ivoid = '%s'"; + /** Query to get the specified column names (%s #1) of TAP service with the specified ivoid (%s #2). */ public static final String SELECT_TAP_SERVICES_WHERE_IVOID = - "SELECT DISTINCT %s " + FROM + WHERE_TAP + "AND ivoid = '%s'"; - - public static final String SELECT_TAP_SERVICES = - "SELECT DISTINCT %s " + FROM + WHERE_TAP; + SELECT + "%s " + FROM + WHERE_TAP + "AND ivoid = '%s'"; + /** Query to get the specified column names (%s #1) of TAP service with the specified subject (%s #2). */ public static final String SELECT_TAP_SERVICES_WHERE_SUBJECT = - "SELECT DISTINCT %s " + FROM + "NATURAL JOIN rr.res_subject " + WHERE_TAP + "AND (%s)"; + SELECT + "%s " + FROM + "NATURAL JOIN rr.res_subject " + WHERE_TAP + "AND (%s)"; + /** Query to get the specified column names (%s #1) of any table. */ public static final String SELECT_FROM = - "SELECT DISTINCT %s FROM %s"; + SELECT + "%s FROM %s"; + /** Query to select all columns of any table. */ public static final String SELECT_ALL = "SELECT DISTINCT * FROM %s"; //@format diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java index 3278698..dd172dd 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java @@ -30,7 +30,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.Type; import eu.omp.irap.vespa.epntapclient.votable.model.Table; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; import eu.omp.irap.vespa.votable.Consts; -import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException; import eu.omp.irap.vespa.votable.controller.VOTableController; import eu.omp.irap.vespa.votable.utils.StringJoiner; import eu.omp.irap.vespa.votable.votabledata.VOTableData; @@ -111,9 +111,9 @@ public class ServiceCtrl { /** * @param query The query to get the service. * @return The VOTableData - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public static VOTableData getVoTableData(String query) throws CantGetVOTableException { + public static VOTableData getVoTableData(String query) throws VOTableException { return getVoTableData(getVoTable(query)); } @@ -122,9 +122,9 @@ public class ServiceCtrl { * * @param voTable The VOTable parsed. * @return The corresponding VOTableData. - * @throws CantGetVOTableException Can not get the VOTable. + * @throws VOTableException Can not get the VOTable. */ - public static VOTableData getVoTableData(VOTABLE voTable) throws CantGetVOTableException { + public static VOTableData getVoTableData(VOTABLE voTable) throws VOTableException { VOTableController.checkVOTable(voTable); Table table = (Table) voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0); @@ -133,29 +133,58 @@ public class ServiceCtrl { return dataParser.getData(); } - public static VOTABLE getVoTable(String query) throws CantGetVOTableException { + /** + * @param query The query. + * @return The VOTable resulting the query. + * @throws VOTableException Can not get the VOTable. + */ + public static VOTABLE getVoTable(String query) throws VOTableException { VOTableController voTableCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); voTableCtrl.readTable(); return voTableCtrl.getVOTable(); } + /** + * @param ivoid The ivoid of the service. + * @param parameters The parameters to get, separated by commas. + * @return A map of resulting the request. + * @throws VOTableException Can not get the VOTable. + */ public static Map getParameters(String ivoid, String parameters) - throws CantGetVOTableException { + throws VOTableException { String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, parameters, ivoid); return getVoTableData(query).getRowMap(0); } + /** + * @param ivoid The ivoid of the service. + * @param parameters A list of parameters to get. + * @return A map of resulting the request. + * @throws VOTableException Can not get the VOTable. + */ public static Map getParameters(String ivoid, List parameters) - throws CantGetVOTableException { + throws VOTableException { return getParameters(ivoid, StringJoiner.join(parameters)); } - public static Object getParameter(String ivoid, String parameters) - throws CantGetVOTableException { - String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, parameters, ivoid); + /** + * @param ivoid The ivoid of the service. + * @param parameter The unique parameter to get. + * @return The value of the parameter. + * @throws VOTableException Can not get the VOTable. + */ + public static Object getParameter(String ivoid, String parameter) + throws VOTableException { + String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, parameter, ivoid); return getVoTableData(query).getCell(0, 0); } + /** + * Convert a date from XMLGregorianCalendar to a string literal. + * + * @param date The date to convert + * @return The serialized date. + */ private static String xmlDateToString(XMLGregorianCalendar date) { SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT); return sdf.format(date.toGregorianCalendar().getTime()); 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 94d35da..d024ed2 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 @@ -36,6 +36,7 @@ import com.google.gson.JsonObject; import eu.omp.irap.vespa.epntapclient.service.ServiceCore; import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException.CantGetVOResourceException; +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException.CantReadVOResourceException; import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException.VOResourceIsNotValidException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.votable.utils.CantSendQueryException; @@ -51,30 +52,44 @@ public class VOResourceCtrl { /** The logger for the class VOResourceController. */ private static final Logger LOGGER = Logger.getLogger(VOResourceCtrl.class.getName()); + /** The URL used to get the resources in VOResource (XML) format. */ private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml"; + /** The URL used to get the resources in JSON format. */ private static final String GET_JSONRESOURCES_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search"; + /** The maximum number of resulting resources. */ private static final int MAX_VORESOURCES = 100; + /** The new schema location, since one in the dowloaded VOResource is not compliant. */ private static final String SCHEMA_LOCATION = "http://www.ivoa.net/xml/RegistryInterface/v1.0 " + "http://www.ivoa.net/xml/RegistryInterface/v1.0 " + "http://www.ivoa.net/xml/VODataService/v1.1 " + "http://www.ivoa.net/xml/TAPRegExt/v1.0"; + /** The URL of the VS namespace, since it is not present in the dowloaded VOResource. */ private static final String NAMESPACE_VS = "http://www.ivoa.net/xml/TAPRegExt/v1.0"; + /** The URL of the TR namespace, since it is not present in the dowloaded VOResource. */ private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; + /** Private constructor to hide the default public one. */ private VOResourceCtrl() { } - public static List getVOResources(ServiceCore type) throws VOResourceException { + /** + * Get the list of ivoIDs of all resources which implements the specified core. + * + * @param core The service core (ie. ObsCore, EpnCore, etc.) + * @return A list of ivoIDs + * @throws VOResourceException Can not get the VOResource. + */ + public static List getIvoidResources(ServiceCore core) throws VOResourceException { List ivoidResources; Map parameters = new HashMap<>(); - parameters.put("keywords", "datamodel:\"" + type.toString() + "\""); + parameters.put("keywords", "datamodel:\"" + core.toString() + "\""); parameters.put("max", String.valueOf(MAX_VORESOURCES)); String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); try { @@ -86,13 +101,23 @@ public class VOResourceCtrl { return ivoidResources; } - public static List getVOResources(ServiceCore type, List keywords) + /** + * Get the list of ivoIDs of all resources which implements the specified core and match with + * the keywords. + * + * @param core The service core (ie. ObsCore, EpnCore, etc.) + * @param keywords A list of keywords to filter the result. The keywords are the subjects of the + * resources, for example, 'Space plasmas'. + * @return A list of ivoIDs + * @throws CantGetVOResourceException Can not get the VOResource. + */ + public static List getVOResources(ServiceCore core, List keywords) throws CantGetVOResourceException { List ivoidResources; Map parameters = new HashMap<>(); String subjects = StringJoiner.join(keywords); parameters.put("keywords", - "datamodel:\"" + type.toString() + "\" subjects:\"" + subjects + "\""); + "datamodel:\"" + core.toString() + "\" subjects:\"" + subjects + "\""); parameters.put("max", String.valueOf(MAX_VORESOURCES)); String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); @@ -105,6 +130,13 @@ public class VOResourceCtrl { return ivoidResources; } + /** + * Get a resource from its identifier. + * + * @param identifier The resource identifier. + * @return The returned resource. + * @throws VOResourceException Can not get the VOResource. + */ public static Resource getVOresource(String identifier) throws VOResourceException { Map parameters = new HashMap<>(); parameters.put("identifier", identifier); @@ -122,7 +154,7 @@ public class VOResourceCtrl { try { changeNamespaces(voResourcePath); } catch (IOException e) { - throw new VOResourceException("The VOResource file can not be modified.", e); + throw new CantReadVOResourceException("The VOResource file can not be modified.", e); } Resource voResource; @@ -140,14 +172,13 @@ public class VOResourceCtrl { return voResource; } - private static void changeNamespaces(String voResourcePath) throws IOException { - Map attributes = new HashMap<>(); - attributes.put("xsi:schemaLocation", SCHEMA_LOCATION); - attributes.put("xmlns:vs", NAMESPACE_VS); - attributes.put("xmlns:tr", NAMESPACE_TR); - XMLUtils.changeRootAttributes(voResourcePath, attributes); - } - + /** + * Get a list of Resources from a list of ivoid. + * + * @param ivoidResources A list of ivoIds + * @return A list of Resources corresponding to the ivoIDs. + * @throws VOResourceException Can not get the VOResource. + */ public static List getVOResources(List ivoidResources) throws VOResourceException { List resources = new ArrayList<>(); @@ -157,6 +188,26 @@ public class VOResourceCtrl { return resources; } + /** + * Change the namespaces of the VOResource to make the XML file valid against its XSD. + * + * @param voResourcePath The file path of the VOResource. + * @throws IOException Can not read or write on the VOResource file. + */ + private static void changeNamespaces(String voResourcePath) throws IOException { + Map attributes = new HashMap<>(); + attributes.put("xsi:schemaLocation", SCHEMA_LOCATION); + attributes.put("xmlns:vs", NAMESPACE_VS); + attributes.put("xmlns:tr", NAMESPACE_TR); + XMLUtils.changeRootAttributes(voResourcePath, attributes); + } + + /** + * Parse a JSON query result and returns a list of ivoid. + * + * @param getIvoidsResult The JSON object result a query. See {@link #GET_JSONRESOURCES_URL}. + * @return A list of ivoIDs. + */ private static List parseIvoidResources(JsonObject getIvoidsResult) { JsonArray resources = getIvoidsResult.get("resources").getAsJsonArray(); List ivoidResources = new ArrayList<>(); 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 0726527..f5550ea 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 @@ -17,11 +17,13 @@ package eu.omp.irap.vespa.epntapclient.voresource; /** + * The general abstract class for all exceptions concerning the VOResources. + * * @author N. Jourdane */ -public class VOResourceException extends Exception { +public abstract class VOResourceException extends Exception { - /** */ + /** The serial version UID. */ private static final long serialVersionUID = 1L; @@ -41,6 +43,7 @@ public class VOResourceException extends Exception { } + /** An exception thrown when we can not read the VOResource. */ public static class CantReadVOResourceException extends VOResourceException { /** The serial version UID. */ @@ -48,7 +51,7 @@ public class VOResourceException extends Exception { /** - * @param voTablePath The path of the VOTable. + * @param voResourcePath The path of the VOResource. * @param e The exception thrown. */ public CantReadVOResourceException(String voResourcePath, Exception e) { @@ -56,6 +59,7 @@ public class VOResourceException extends Exception { } } + /** An exception thrown when we can not get the VOResource, ie. an error in the query. */ public static class CantGetVOResourceException extends VOResourceException { /** The serial version UID. */ @@ -63,7 +67,7 @@ public class VOResourceException extends Exception { /** - * @param voTablePath The path of the VOTable. + * @param voResourceRequest The path of the VOResource. * @param e The exception thrown. */ public CantGetVOResourceException(String voResourceRequest, Exception e) { @@ -71,6 +75,9 @@ public class VOResourceException extends Exception { } } + /** + * An exception thrown when the VOResource is not valid, ie. it don't have the expected body. + */ public static class VOResourceIsNotValidException extends VOResourceException { /** The serial version UID. */ @@ -78,7 +85,7 @@ public class VOResourceException extends Exception { /** - * @param voTablePath The path of the VOTable. + * @param voResourcePath The path of the VOResource. * @param e The exception thrown. */ public VOResourceIsNotValidException(String voResourcePath, Exception e) { 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 acaf4ce..465dfb0 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl; import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; -import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableException; import eu.omp.irap.vespa.votable.votabledata.VOTableData; /** @@ -153,10 +153,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNService(String)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test - public void getEPNServiceTest() throws CantGetVOTableException { + public void getEPNServiceTest() throws VOTableException { LOGGER.info("getEPNServiceTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -175,10 +175,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNService(String, List)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test - public void getEPNServiceWithAttributesTest() throws CantGetVOTableException { + public void getEPNServiceWithAttributesTest() throws VOTableException { LOGGER.info("getEPNServiceWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -200,10 +200,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNServices()}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test - public void getEPNServicesTest() throws CantGetVOTableException { + public void getEPNServicesTest() throws VOTableException { LOGGER.info("getEPNServicesTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -234,11 +234,11 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNServices(List)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test public void getEPNServicesWithAttributesTest() - throws CantGetVOTableException { + throws VOTableException { LOGGER.info("getEPNServicesWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -265,12 +265,12 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNServices(List, List)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. * @throws VOResourceException Can not get the VOresource. */ @Test public void getEPNServicesWithKeywordsAndAttributesTest() - throws CantGetVOTableException, VOResourceException { + throws VOTableException, VOResourceException { LOGGER.info("getEPNServicesWithKeywordsAndAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -302,10 +302,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getEPNCoreTableName(String)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test - public void getEPNCoreTableNameTest() throws CantGetVOTableException { + public void getEPNCoreTableNameTest() throws VOTableException { LOGGER.info("getEPNCoreTableNameTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -317,10 +317,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#getTAPURL(String)}. * - * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + * @throws VOTableException Can not get the VOTable corresponding to the service. */ @Test - public void getTAPURLTest() throws CantGetVOTableException { + public void getTAPURLTest() throws VOTableException { LOGGER.info("getTAPURLTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -334,10 +334,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#sendADQLQuery(String, String)}. * - * @throws CantGetVOTableException Can not get the VOTable resulting the query. + * @throws VOTableException Can not get the VOTable resulting the query. */ @Test - public void sendADQLQueryTest() throws CantGetVOTableException { + public void sendADQLQueryTest() throws VOTableException { LOGGER.info("sendADQLQueryTest"); EpnTapConnection facade = new EpnTapConnection(); @@ -360,10 +360,10 @@ public class EpnTapConnectionTest { /** * Unit test for the class {@link EpnTapConnection#sendQuery(String, String, Query)}. * - * @throws CantGetVOTableException Can not get the VOTable resulting the query. + * @throws VOTableException Can not get the VOTable resulting the query. */ @Test - public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException { + public void sendADQLQueryWithSchemaNameTest() throws VOTableException { LOGGER.info("sendADQLQueryWithSchemaNameTest"); EpnTapConnection facade = new EpnTapConnection(); List granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL, -- libgit2 0.21.2