Commit 4b3a296c62565448031374c8197028e5aaf92a5a

Authored by Nathanael Jourdane
1 parent 1240d52f
Exists in master

Implement getServices()

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java
... ... @@ -17,6 +17,7 @@
17 17 package eu.omp.irap.vespa.epntapclient;
18 18  
19 19 import java.text.ParseException;
  20 +import java.util.ArrayList;
20 21 import java.util.List;
21 22 import java.util.Map;
22 23 import java.util.logging.Logger;
... ... @@ -83,7 +84,7 @@ public class EpnTapFacade implements EpnTapInterface {
83 84 @Override
84 85 public VOTABLE getEPNService(String ivoid, List<String> attributes)
85 86 throws CantGetVOTableException {
86   - // TODO: 2 requêtes pour obtenir tableName et URL = pas super opti.
  87 + // TODO: optimiser le nombre de requêtes
87 88 String tableName = getEPNCoreTableName(ivoid);
88 89 String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes), tableName);
89 90 VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);
... ... @@ -94,25 +95,35 @@ public class EpnTapFacade implements EpnTapInterface {
94 95 // *** Services ***
95 96  
96 97 @Override
97   - public VOTABLE getEPNServices() throws CantGetVOTableException {
98   - // TODO: CantDisplayVOTableException -> Pas le bon nom d'erreur, le pb n'est pas l'affichage
99   - String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE);
100   - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
101   - ctrl.readTable();
102   - return ctrl.getVOTable();
  98 + public List<VOTABLE> getEPNServices() throws VOResourceException {
  99 + List<VOTABLE> voTables = new ArrayList<>();
  100 + List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);
  101 + // TODO: optimiser le nombre de requêtes
  102 + for (String ivoid : ivoids) {
  103 + try {
  104 + String query = String.format(Queries.SELECT_ALL, getEPNCoreTableName(ivoid));
  105 + VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);
  106 + ctrl.readTable();
  107 + voTables.add(ctrl.getVOTable());
  108 + } catch (CantGetVOTableException e) {
  109 + logger.info("Can not get the service " + ivoid + ", skipping...");
  110 + }
  111 + }
  112 + return voTables;
103 113 }
104 114  
105 115 @Override
106   - public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException {
  116 + public List<VOTABLE> getEPNServices(List<String> attributes)
  117 + throws CantGetVOTableException, VOResourceException {
107 118 // TODO process attributes
108   - return getEPNServices();
  119 + return null;
109 120 }
110 121  
111 122 @Override
112   - public VOTABLE getEPNServices(Map<String, String> keywords, List<String> attributes)
113   - throws CantGetVOTableException {
  123 + public List<VOTABLE> getEPNServices(Map<String, String> keywords, List<String> attributes)
  124 + throws CantGetVOTableException, VOResourceException {
114 125 // TODO process attributes and keywords
115   - return getEPNServices();
  126 + return null;
116 127 }
117 128  
118 129 // *** Getters ***
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java
... ... @@ -78,7 +78,7 @@ public interface EpnTapInterface {
78 78 * @throws CantGetXMLException
79 79 * @throws CantDisplayVOTableException
80 80 */
81   - public VOTABLE getEPNServices() throws CantGetVOTableException;
  81 + public List<VOTABLE> getEPNServices() throws CantGetVOTableException, VOResourceException;
82 82  
83 83 /**
84 84 * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list
... ... @@ -87,7 +87,8 @@ public interface EpnTapInterface {
87 87 * @throws CantGetXMLException
88 88 * @throws CantDisplayVOTableException
89 89 */
90   - public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException;
  90 + public List<VOTABLE> getEPNServices(List<String> attributes)
  91 + throws CantGetVOTableException, VOResourceException;
91 92  
92 93 /**
93 94 * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and
... ... @@ -96,8 +97,8 @@ public interface EpnTapInterface {
96 97 * @throws CantGetXMLException
97 98 * @throws CantDisplayVOTableException
98 99 */
99   - public VOTABLE getEPNServices(Map<String, String> keywords, List<String> attributes)
100   - throws CantGetVOTableException;
  100 + public List<VOTABLE> getEPNServices(Map<String, String> keywords, List<String> attributes)
  101 + throws CantGetVOTableException, VOResourceException;
101 102  
102 103 // *** Getters ***
103 104  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java
... ... @@ -111,7 +111,6 @@ public class GranuleCtrl {
111 111 //@format
112 112  
113 113 if (!g.isValid()) {
114   - System.out.println(data.getCell(rowId, "polar_radius"));
115 114 throw new IllegalArgumentException("One or more EPN parameter is null.");
116 115 }
117 116 return g;
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
... ... @@ -70,6 +70,9 @@ public final class Queries {
70 70 public static final String SELECT_FROM =
71 71 "SELECT %s FROM %s";
72 72  
  73 + public static final String SELECT_ALL =
  74 + "SELECT * FROM %s";
  75 +
73 76 //@format
74 77  
75 78 /** Constructor to hide the implicit public one. */
... ...
src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java
... ... @@ -23,7 +23,6 @@ import java.util.Map;
23 23 import java.util.logging.Logger;
24 24  
25 25 import eu.omp.irap.vespa.epntapclient.granule.Granule;
26   -import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
27 26 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl;
28 27 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
29 28 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
... ... @@ -65,8 +64,6 @@ public class TestEpnTapFacade {
65 64 String strKeywords = "[shortName=IKS]";
66 65  
67 66 try {
68   - facade.getEPNServices();
69   -
70 67 System.out.println("\n*** 1. Resource ***\n");
71 68  
72 69 Resource resource = VOResourceCtrl.getVOresource(TEST_RESOURCE_IVOID);
... ... @@ -75,10 +72,6 @@ public class TestEpnTapFacade {
75 72  
76 73 System.out.println("\n*** 2. Resources ***\n");
77 74  
78   - List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);
79   - System.out.println("2.0 getIvoidResources(ServiceCore.EPNCORE)\n\t" +
80   - StringJoiner.join(ivoids));
81   -
82 75 List<Resource> resources = facade.getEPNVOResources();
83 76 System.out.println("2.1 getEPNVOResources()\n\t"
84 77 + Debug.toJson(resources));
... ... @@ -100,16 +93,15 @@ public class TestEpnTapFacade {
100 93  
101 94 System.out.println("\n*** 4. Services ***\n");
102 95  
103   - VOTABLE epnServices = facade.getEPNServices();
  96 + List<VOTABLE> epnServices = facade.getEPNServices();
104 97 System.out.println("4.1 getEPNServices()\n\t"
105 98 + Debug.toJson(epnServices));
106 99  
107   - VOTABLE epnServices2 = facade.getEPNServices(SERVICE_ATTRIBUTES);
108   - System.out.println(
109   - "4.2 getEPNServices(" + strServiceAttributes + ")\n\t"
110   - + Debug.toJson(epnServices2));
  100 + List<VOTABLE> epnServices2 = facade.getEPNServices(SERVICE_ATTRIBUTES);
  101 + System.out.println("4.2 getEPNServices(" + strServiceAttributes + ")\n\t"
  102 + + Debug.toJson(epnServices2));
111 103  
112   - VOTABLE epnServices3 = facade.getEPNServices(KEYWORDS, SERVICE_ATTRIBUTES);
  104 + List<VOTABLE> epnServices3 = facade.getEPNServices(KEYWORDS, SERVICE_ATTRIBUTES);
113 105 System.out.println("4.3 getEPNServices(" + strKeywords + ", "
114 106 + strServiceAttributes + ")\n\t"
115 107 + Debug.toJson(epnServices3));
... ...