From 9144ee77c543d71dfec1cec43fb1e86e70adc0ce Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 9 May 2016 18:38:10 +0200 Subject: [PATCH] Implement Service filter. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java | 11 ++++++++--- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java | 7 +++++-- src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java | 35 ++++++++++++++++++++++------------- 4 files changed, 36 insertions(+), 19 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 fd54de4..ab172db 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java @@ -34,6 +34,7 @@ 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.VOTableController; +import eu.omp.irap.vespa.votable.utils.StringJoiner; import eu.omp.irap.vespa.votable.votabledata.VOTableData; /** @@ -82,8 +83,12 @@ public class EpnTapFacade implements EpnTapInterface { @Override public VOTABLE getEPNService(String ivoid, List attributes) throws CantGetVOTableException { - // TODO process attributes - return getEPNService(ivoid); + // TODO: 2 requĂȘtes pour obtenir tableName et URL = pas super opti. + String tableName = getEPNCoreTableName(ivoid); + String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes), tableName); + VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query); + ctrl.readTable(); + return ctrl.getVOTable(); } // *** Services *** @@ -104,7 +109,7 @@ public class EpnTapFacade implements EpnTapInterface { } @Override - public VOTABLE getEPNServices(List keywords, List attributes) + public VOTABLE getEPNServices(Map keywords, List attributes) throws CantGetVOTableException { // TODO process attributes and keywords return getEPNServices(); 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 43b95eb..ad586f8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java @@ -96,7 +96,7 @@ public interface EpnTapInterface { * @throws CantGetXMLException * @throws CantDisplayVOTableException */ - public VOTABLE getEPNServices(List keywords, List attributes) + public VOTABLE getEPNServices(Map keywords, List attributes) throws CantGetVOTableException; // *** Getters *** 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 2fd742c..10d8540 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 @@ -61,11 +61,14 @@ public final class Queries { /** Query to get the TAP service with the specified ivoid. */ public static final String GET_TAP_SERVICES_WHERE_IVOID = Queries.SELECT + Queries.FROM + Queries.WHERE_TAP - + "AND ivoid = '%s' "; + + "AND ivoid = '%s'"; public static final String GET_TAP_SERVICES_SELECT_WHERE_IVOID = "SELECT %s " + Queries.FROM + Queries.WHERE_TAP - + "AND ivoid = '%s' "; + + "AND ivoid = '%s'"; + + public static final String SELECT_FROM = + "SELECT %s FROM %s"; //@format 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 be2d7a5..80d8fde 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java @@ -54,6 +54,16 @@ public class TestEpnTapFacade { public static void main(String[] args) { EpnTapFacade facade = new EpnTapFacade(); + final List SERVICE_ATTRIBUTES = new ArrayList<>(); + SERVICE_ATTRIBUTES.add("target_name"); + SERVICE_ATTRIBUTES.add("time_min"); + SERVICE_ATTRIBUTES.add("time_max"); + String strServiceAttributes = "[" + StringJoiner.join(SERVICE_ATTRIBUTES) + "]"; + + final Map KEYWORDS = new HashMap<>(); + KEYWORDS.put("shortName", "IKS"); + String strKeywords = "[shortName=IKS]"; + try { facade.getEPNServices(); @@ -73,10 +83,8 @@ public class TestEpnTapFacade { System.out.println("2.1 getEPNVOResources()\n\t" + Debug.toJson(resources)); - Map keywords = new HashMap<>(); - keywords.put("shortName", "IKS"); - List resources2 = facade.getEPNVOResources(keywords); - System.out.println("2.2 getEPNVOResources(keywords)\n\t" + List resources2 = facade.getEPNVOResources(KEYWORDS); + System.out.println("2.2 getEPNVOResources(" + strKeywords + ")\n\t" + Debug.toJson(resources2)); System.out.println("\n*** 3. Service ***\n"); @@ -85,10 +93,9 @@ public class TestEpnTapFacade { System.out.println("3.1 getEPNService(\"" + TEST_SERVICE_IVOID + "\")\n\t" + Debug.toJson(epnService)); - List attributes = new ArrayList<>(); - attributes.add("s_region"); - VOTABLE epnService2 = facade.getEPNService(TEST_SERVICE_IVOID, attributes); - System.out.println("3.2 getEPNService(\"" + TEST_SERVICE_IVOID + "\", \"s_region\")\n\t" + VOTABLE epnService2 = facade.getEPNService(TEST_SERVICE_IVOID, SERVICE_ATTRIBUTES); + System.out.println("3.2 getEPNService(\"" + TEST_SERVICE_IVOID + "\", " + + strServiceAttributes + ")\n\t" + Debug.toJson(epnService2)); System.out.println("\n*** 4. Services ***\n"); @@ -97,12 +104,14 @@ public class TestEpnTapFacade { System.out.println("4.1 getEPNServices()\n\t" + Debug.toJson(epnServices)); - VOTABLE epnServices2 = facade.getEPNServices(attributes); - System.out.println("4.2 getEPNService(\"s_region\")\n\t" - + Debug.toJson(epnServices2)); + VOTABLE epnServices2 = facade.getEPNServices(SERVICE_ATTRIBUTES); + System.out.println( + "4.2 getEPNServices(" + strServiceAttributes + ")\n\t" + + Debug.toJson(epnServices2)); - VOTABLE epnServices3 = facade.getEPNService(TEST_SERVICE_IVOID, attributes); - System.out.println("4.3 getEPNService(\"" + TEST_SERVICE_IVOID + "\", \"s_region\")\n\t" + VOTABLE epnServices3 = facade.getEPNServices(KEYWORDS, SERVICE_ATTRIBUTES); + System.out.println("4.3 getEPNServices(" + strKeywords + ", " + + strServiceAttributes + ")\n\t" + Debug.toJson(epnServices3)); System.out.println("\n*** 5. Getters***\n"); -- libgit2 0.21.2