From 4b3a296c62565448031374c8197028e5aaf92a5a Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Tue, 10 May 2016 10:54:34 +0200 Subject: [PATCH] Implement getServices() --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java | 35 +++++++++++++++++++++++------------ src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java | 9 +++++---- src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java | 1 - src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java | 3 +++ src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java | 18 +++++------------- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java index ab172db..28e0389 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java @@ -17,6 +17,7 @@ package eu.omp.irap.vespa.epntapclient; import java.text.ParseException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -83,7 +84,7 @@ public class EpnTapFacade implements EpnTapInterface { @Override public VOTABLE getEPNService(String ivoid, List attributes) throws CantGetVOTableException { - // TODO: 2 requêtes pour obtenir tableName et URL = pas super opti. + // TODO: optimiser le nombre de requêtes String tableName = getEPNCoreTableName(ivoid); String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes), tableName); VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query); @@ -94,25 +95,35 @@ public class EpnTapFacade implements EpnTapInterface { // *** Services *** @Override - public VOTABLE getEPNServices() throws CantGetVOTableException { - // TODO: CantDisplayVOTableException -> Pas le bon nom d'erreur, le pb n'est pas l'affichage - String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); - ctrl.readTable(); - return ctrl.getVOTable(); + public List getEPNServices() throws VOResourceException { + List voTables = new ArrayList<>(); + List ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE); + // TODO: optimiser le nombre de requêtes + for (String ivoid : ivoids) { + try { + String query = String.format(Queries.SELECT_ALL, getEPNCoreTableName(ivoid)); + VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query); + ctrl.readTable(); + voTables.add(ctrl.getVOTable()); + } catch (CantGetVOTableException e) { + logger.info("Can not get the service " + ivoid + ", skipping..."); + } + } + return voTables; } @Override - public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException { + public List getEPNServices(List attributes) + throws CantGetVOTableException, VOResourceException { // TODO process attributes - return getEPNServices(); + return null; } @Override - public VOTABLE getEPNServices(Map keywords, List attributes) - throws CantGetVOTableException { + public List getEPNServices(Map keywords, List attributes) + throws CantGetVOTableException, VOResourceException { // TODO process attributes and keywords - return getEPNServices(); + return null; } // *** Getters *** 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 ad586f8..f47b553 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java @@ -78,7 +78,7 @@ public interface EpnTapInterface { * @throws CantGetXMLException * @throws CantDisplayVOTableException */ - public VOTABLE getEPNServices() throws CantGetVOTableException; + public List getEPNServices() throws CantGetVOTableException, VOResourceException; /** * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list @@ -87,7 +87,8 @@ public interface EpnTapInterface { * @throws CantGetXMLException * @throws CantDisplayVOTableException */ - public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException; + public List getEPNServices(List attributes) + throws CantGetVOTableException, VOResourceException; /** * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and @@ -96,8 +97,8 @@ public interface EpnTapInterface { * @throws CantGetXMLException * @throws CantDisplayVOTableException */ - public VOTABLE getEPNServices(Map keywords, List attributes) - throws CantGetVOTableException; + public List getEPNServices(Map keywords, List attributes) + throws CantGetVOTableException, VOResourceException; // *** Getters *** 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 8a72683..2734603 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 @@ -111,7 +111,6 @@ public class GranuleCtrl { //@format if (!g.isValid()) { - System.out.println(data.getCell(rowId, "polar_radius")); throw new IllegalArgumentException("One or more EPN parameter is null."); } return g; 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 10d8540..e4d3599 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 @@ -70,6 +70,9 @@ public final class Queries { public static final String SELECT_FROM = "SELECT %s FROM %s"; + public static final String SELECT_ALL = + "SELECT * FROM %s"; + //@format /** Constructor to hide the implicit public one. */ diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java b/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java index 80d8fde..afcffbc 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.granule.Granule; -import eu.omp.irap.vespa.epntapclient.service.ServiceCore; 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; @@ -65,8 +64,6 @@ public class TestEpnTapFacade { String strKeywords = "[shortName=IKS]"; try { - facade.getEPNServices(); - System.out.println("\n*** 1. Resource ***\n"); Resource resource = VOResourceCtrl.getVOresource(TEST_RESOURCE_IVOID); @@ -75,10 +72,6 @@ public class TestEpnTapFacade { System.out.println("\n*** 2. Resources ***\n"); - List ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE); - System.out.println("2.0 getIvoidResources(ServiceCore.EPNCORE)\n\t" + - StringJoiner.join(ivoids)); - List resources = facade.getEPNVOResources(); System.out.println("2.1 getEPNVOResources()\n\t" + Debug.toJson(resources)); @@ -100,16 +93,15 @@ public class TestEpnTapFacade { System.out.println("\n*** 4. Services ***\n"); - VOTABLE epnServices = facade.getEPNServices(); + List epnServices = facade.getEPNServices(); System.out.println("4.1 getEPNServices()\n\t" + Debug.toJson(epnServices)); - VOTABLE epnServices2 = facade.getEPNServices(SERVICE_ATTRIBUTES); - System.out.println( - "4.2 getEPNServices(" + strServiceAttributes + ")\n\t" - + Debug.toJson(epnServices2)); + List epnServices2 = facade.getEPNServices(SERVICE_ATTRIBUTES); + System.out.println("4.2 getEPNServices(" + strServiceAttributes + ")\n\t" + + Debug.toJson(epnServices2)); - VOTABLE epnServices3 = facade.getEPNServices(KEYWORDS, SERVICE_ATTRIBUTES); + List epnServices3 = facade.getEPNServices(KEYWORDS, SERVICE_ATTRIBUTES); System.out.println("4.3 getEPNServices(" + strKeywords + ", " + strServiceAttributes + ")\n\t" + Debug.toJson(epnServices3)); -- libgit2 0.21.2