Commit cfbb6d0742bac8cb95ca1b865c7dfc0e2abfabbf

Authored by Nathanael Jourdane
1 parent 260c559f
Exists in master

Implement most of EpnTap facade methods.

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java
... ... @@ -21,9 +21,9 @@ import java.util.Map;
21 21 import java.util.logging.Logger;
22 22  
23 23 import eu.omp.irap.vespa.epntapclient.service.Queries;
  24 +import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
24 25 import eu.omp.irap.vespa.votable.Consts;
25   -import eu.omp.irap.vespa.votable.VOTableException.CantDisplayVOTableException;
26   -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException;
  26 +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
27 27 import eu.omp.irap.vespa.votable.controller.VOTableController;
28 28  
29 29 /**
... ... @@ -39,7 +39,7 @@ public class EpnTapController {
39 39 /** The controller of the VOTable displaying the list of services. */
40 40 protected VOTableController servicesCtrl;
41 41  
42   - /** The controller of the VOTable displaying the list of services. */
  42 + /** The controller of the VOTable displaying the result. */
43 43 protected VOTableController resultsCtrl;
44 44  
45 45 /**
... ... @@ -52,22 +52,13 @@ public class EpnTapController {
52 52 * Method constructor, which initialize servicesController, resultsController and mainView.
53 53 */
54 54 public EpnTapController() {
55   - servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, "ADQL",
56   - Queries.GET_EPN_TAP_SERVICES);
57   - try {
58   - servicesCtrl.readTable();
59   - } catch (CantDisplayVOTableException e) {
60   - // TODO Auto-generated catch block
61   - e.printStackTrace();
62   - } catch (CantSendQueryException e) {
63   - // TODO Auto-generated catch block
64   - e.printStackTrace();
65   - }
  55 + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE);
  56 + servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
66 57 }
67 58  
68 59 public String sendQuery(String query, String tableServiceURL)
69   - throws CantDisplayVOTableException, CantSendQueryException {
70   - resultsCtrl = new VOTableController(tableServiceURL, "ADQL", query);
  60 + throws CantGetVOTableException {
  61 + resultsCtrl = new VOTableController(tableServiceURL, query);
71 62 resultsCtrl.readTable();
72 63 return resultsCtrl.getVOTablePath();
73 64 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java
... ... @@ -16,14 +16,25 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient;
18 18  
  19 +import java.text.ParseException;
19 20 import java.util.List;
20 21 import java.util.Map;
21 22 import java.util.logging.Logger;
22 23  
23   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceCtrl;
24   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException;
  24 +import eu.omp.irap.vespa.epntapclient.granule.Granule;
  25 +import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl;
  26 +import eu.omp.irap.vespa.epntapclient.service.Queries;
25 27 import eu.omp.irap.vespa.epntapclient.service.Service;
  28 +import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
  29 +import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl;
  30 +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl;
  31 +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
26 32 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
  33 +import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
  34 +import eu.omp.irap.vespa.votable.Consts;
  35 +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
  36 +import eu.omp.irap.vespa.votable.controller.VOTableController;
  37 +import eu.omp.irap.vespa.votable.votabledata.VOTableData;
27 38  
28 39 /**
29 40 * @author N. Jourdane
... ... @@ -34,115 +45,115 @@ public class EpnTapFacade implements EpnTapInterface {
34 45 private static final Logger logger = Logger.getLogger(EpnTapFacade.class.getName());
35 46  
36 47  
37   - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOResources() */
  48 + // *** Resource ***
  49 +
38 50 @Override
39   - public List<Resource> getEPNVOResources(Service.ServiceType serviceType)
40   - throws VOResourceException {
41   - return VOResourceCtrl.getVOResources(serviceType);
  51 + public Resource getEPNVOresource(String ivoid) throws VOResourceException {
  52 + return VOResourceCtrl.getVOresource(ivoid);
42 53 }
43 54  
44   - /*
45   - * @see
46   - * eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOResources(java.util.List)
47   - */
  55 + // *** Resources ***
  56 +
48 57 @Override
49   - public List<Resource> getEPNVOResources(Service.ServiceType serviceType,
50   - Map<String, String> keywords)
51   - throws VOResourceException {
52   - return VOResourceCtrl.getVOResources(serviceType, keywords);
  58 + public List<Resource> getEPNVOResources() throws VOResourceException {
  59 + return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE);
53 60 }
54 61  
55   - /*
56   - * @see
57   - * eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOresource(java.lang.String)
58   - */
59 62 @Override
60   - public Resource getEPNVOresource(String ivoid) {
61   - return null;
62   - // TODO Auto-generated method stub
63   -
  63 + public List<Resource> getEPNVOResources(Map<String, String> keywords)
  64 + throws VOResourceException {
  65 + return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords);
64 66 }
65 67  
66   - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices() */
67   - @Override
68   - public void getEPNServices() {
69   - // TODO Auto-generated method stub
  68 + // *** Service ***
70 69  
  70 + public Service _getEPNService(String ivoid) throws CantGetVOTableException {
  71 + return ServiceCtrl.getServiceFromIvoid(ivoid);
71 72 }
72 73  
73   - /*
74   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices(java.util.List)
75   - */
76 74 @Override
77   - public void getEPNServices(List<String> attributes) {
78   - // TODO Auto-generated method stub
79   -
  75 + public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException {
  76 + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid);
  77 + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  78 + ctrl.readTable();
  79 + return ctrl.getVOTable();
80 80 }
81 81  
82   - /*
83   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices(java.util.List,
84   - * java.util.List)
85   - */
86 82 @Override
87   - public void getEPNServices(List<String> keywords, List<String> attributes) {
88   - // TODO Auto-generated method stub
89   -
  83 + public VOTABLE getEPNService(String ivoid, List<String> attributes)
  84 + throws CantGetVOTableException {
  85 + // TODO process attributes
  86 + return getEPNService(ivoid);
90 87 }
91 88  
92   - /*
93   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNService(java.lang.String)
94   - */
95   - @Override
96   - public void getEPNService(String ivoID) {
97   - // TODO Auto-generated method stub
  89 + // *** Services ***
98 90  
  91 + @Override
  92 + public VOTABLE getEPNServices() throws CantGetVOTableException {
  93 + // TODO: CantDisplayVOTableException -> Pas le bon nom d'erreur, le pb n'est pas l'affichage
  94 + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE);
  95 + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  96 + ctrl.readTable();
  97 + return ctrl.getVOTable();
99 98 }
100 99  
101   - /*
102   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNService(java.lang.String,
103   - * java.util.List)
104   - */
105 100 @Override
106   - public void getEPNService(String ivoID, List<String> attributes) {
107   - // TODO Auto-generated method stub
108   -
  101 + public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException {
  102 + // TODO process attributes
  103 + return getEPNServices();
109 104 }
110 105  
111   - /*
112   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNCoreTableName(java.lang.
113   - * String)
114   - */
115 106 @Override
116   - public void getEPNCoreTableName(String service_ivoid) {
117   - // TODO Auto-generated method stub
118   -
  107 + public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
  108 + throws CantGetVOTableException {
  109 + // TODO process attributes and keywords
  110 + return getEPNServices();
119 111 }
120 112  
121   - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getTAPURL(java.lang.String) */
122   - @Override
123   - public void getTAPURL(String service_ivoid) {
124   - // TODO Auto-generated method stub
  113 + // *** Getters ***
125 114  
  115 + @Override
  116 + public String getEPNCoreTableName(String ivoid)
  117 + throws CantGetVOTableException {
  118 + String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "table_name",
  119 + ivoid);
  120 + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  121 + ctrl.readTable();
  122 + return (String) ctrl.getVOTableData().getCell(0, 0);
126 123 }
127 124  
128   - /*
129   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#sendADQLQuery(java.lang.String,
130   - * java.lang.String)
131   - */
132 125 @Override
133   - public void sendADQLQuery(String TAPURL, String ADQLQuery) {
134   - // TODO Auto-generated method stub
135   -
  126 + public String getTAPURL(String ivoid)
  127 + throws CantGetVOTableException {
  128 + String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "access_url",
  129 + ivoid);
  130 + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  131 + ctrl.readTable();
  132 + return (String) ctrl.getVOTableData().getCell(0, 0);
136 133 }
137 134  
138   - /*
139   - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#sendQuery(java.lang.String,
140   - * java.lang.String, java.lang.String)
141   - */
  135 + // *** Queries ***
  136 +
142 137 @Override
143   - public void sendQuery(String TAPURL, String schema_name, String Query) {
144   - // TODO Auto-generated method stub
  138 + public List<Granule> sendADQLQuery(String tapURL, String adqlQuery)
  139 + throws CantGetVOTableException {
  140 + EpnTapController epnTapCtrl = new EpnTapController();
  141 + epnTapCtrl.sendQuery(adqlQuery, tapURL);
  142 + VOTableData data = epnTapCtrl.getResultsController().getVOTableData();
  143 + List<Granule> granules;
  144 + try {
  145 + GranuleCtrl gc = new GranuleCtrl(data);
  146 + granules = gc.getGranulesFromVOTable();
  147 + } catch (ParseException e) {
  148 + throw new CantGetVOTableException("Parsing error on a granule.", e);
  149 + }
  150 + return granules;
  151 + }
145 152  
  153 + @Override
  154 + public List<Granule> sendQuery(String tapURL, String schemaName, String query) {
  155 + // TODO TBC
  156 + return null;
146 157 }
147 158  
148 159 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java
... ... @@ -19,76 +19,121 @@ package eu.omp.irap.vespa.epntapclient;
19 19 import java.util.List;
20 20 import java.util.Map;
21 21  
22   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException;
23   -import eu.omp.irap.vespa.epntapclient.service.Service;
  22 +import eu.omp.irap.vespa.epntapclient.granule.Granule;
  23 +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
24 24 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
  25 +import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
  26 +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
25 27  
26 28 /**
27 29 * @author N. Jourdane
28 30 */
29 31 public interface EpnTapInterface {
30 32  
  33 + // *** Resource ***
  34 +
  35 + /** returns the VOResource element of the service identified by the ivoID. */
  36 + public Resource getEPNVOresource(String ivoid) throws VOResourceException;
  37 +
  38 + // *** Resources ***
  39 +
31 40 /** returns a set of VOResource elements (one per EPN-TAP service) */
32   - List<Resource> getEPNVOResources(Service.ServiceType serviceType)
33   - throws VOResourceException;
  41 + public List<Resource> getEPNVOResources() throws VOResourceException;
34 42  
35 43 /**
36 44 * Returns a set of VOREsource elements (one per EPN-TAP service corresponding to the keywords).
37 45 * The way keywords are defined is still to be defined.
38 46 */
39   - List<Resource> getEPNVOResources(Service.ServiceType serviceType,
40   - Map<String, String> keywords) throws VOResourceException;
  47 + public List<Resource> getEPNVOResources(Map<String, String> keywords)
  48 + throws VOResourceException;
41 49  
42   - /** returns the VOResource element of the service identified by the ivoID. */
43   - Resource getEPNVOresource(String ivoid) throws VOResourceException;
  50 + // *** Service ***
  51 +
  52 + /**
  53 + * returns a VOTable containing the attributes of the corresponding service (from a predefined
  54 + * list)
  55 + *
  56 + * @throws IllegalAccessException
  57 + * @throws CantGetXMLException
  58 + * @throws CantDisplayVOTableException
  59 + */
  60 + public VOTABLE getEPNService(String ivoID) throws CantGetVOTableException;
  61 +
  62 + /**
  63 + * returns a VOTable containing the attributes of the corresponding service (from the list of
  64 + * attributes)
  65 + *
  66 + * @throws CantGetXMLException
  67 + * @throws CantDisplayVOTableException
  68 + */
  69 + public VOTABLE getEPNService(String ivoID, List<String> attributes)
  70 + throws CantGetVOTableException;
  71 +
  72 + // *** Services ***
44 73  
45 74 /**
46 75 * returns a VOTable containing the list of EPN-TAP services and their attributes (from a
47 76 * predefined list)
  77 + *
  78 + * @throws CantGetXMLException
  79 + * @throws CantDisplayVOTableException
48 80 */
49   - void getEPNServices();
  81 + public VOTABLE getEPNServices() throws CantGetVOTableException;
50 82  
51 83 /**
52 84 * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list
53 85 * of attributes)
  86 + *
  87 + * @throws CantGetXMLException
  88 + * @throws CantDisplayVOTableException
54 89 */
55   - void getEPNServices(List<String> attributes);
  90 + public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException;
56 91  
57 92 /**
58 93 * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and
59 94 * their attributes (from the list of attributes)
  95 + *
  96 + * @throws CantGetXMLException
  97 + * @throws CantDisplayVOTableException
60 98 */
61   - void getEPNServices(List<String> keywords, List<String> attributes);
  99 + public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
  100 + throws CantGetVOTableException;
  101 +
  102 + // *** Getters ***
62 103  
63 104 /**
64   - * returns a VOTable containing the attributes of the corresponding service (from a predefined
65   - * list)
  105 + * returns the name of the EPNCore Table related to a service.
  106 + *
  107 + * @throws CantGetXMLException
  108 + * @throws CantDisplayVOTableException
66 109 */
67   - void getEPNService(String ivoID);
  110 + public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException;
68 111  
69 112 /**
70   - * returns a VOTable containing the attributes of the corresponding service (from the list of
71   - * attributes)
  113 + * returns the Access URL of an EPN-TAP Service.
  114 + *
  115 + * @throws CantGetXMLException
  116 + * @throws CantDisplayVOTableException
72 117 */
73   - void getEPNService(String ivoID, List<String> attributes);
74   -
75   - /** returns the name of the EPNCore Table related to a service. */
76   - void getEPNCoreTableName(String service_ivoid);
  118 + public String getTAPURL(String ivoid) throws CantGetVOTableException;
77 119  
78   - /** returns the Access URL of an EPN-TAP Service. */
79   - void getTAPURL(String service_ivoid);
  120 + // *** Queries ***
80 121  
81 122 /**
82 123 * returns the list of granules which are compliant with the ADQL Query, in VOTable format .
83 124 * TAPURL is build from elements taken in VOResource. "ADQLQuery" is created by the Client. It
84 125 * is a full query containing the name of the EPNCore table, taken in VOResource.
  126 + *
  127 + * @throws CantGetXMLException
  128 + * @throws CantDisplayVOTableException
85 129 */
86   - void sendADQLQuery(String TAPURL, String ADQLQuery);
  130 + public List<Granule> sendADQLQuery(String tapURL, String adqlQuery)
  131 + throws CantGetVOTableException;
87 132  
88 133 /**
89 134 * returns the list of granules which are compliant with the Query, in VOTable format. "Query"
90 135 * is not an ADQL query. It is taken from a list of predefined queries. This list must be
91 136 * created.
92 137 */
93   - void sendQuery(String TAPURL, String schema_name, String Query);
  138 + public List<Granule> sendQuery(String tapURL, String schemaName, String query);
94 139 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java
... ... @@ -35,67 +35,69 @@ public class Granule {
35 35  
36 36 public String targetClass;
37 37  
38   - public double timeMin;
  38 + public Double timeMin;
39 39  
40   - public double timeMax;
  40 + public Double timeMax;
41 41  
42   - public double timeSamplingStepMin;
  42 + public Double timeSamplingStepMin;
43 43  
44   - public double timeSamplingStepMax;
  44 + public Double timeSamplingStepMax;
45 45  
46   - public double timeExpMin;
  46 + public Double timeExpMin;
47 47  
48   - public double timeExpMax;
  48 + public Double timeExpMax;
49 49  
50   - public double spectralRangeMin;
  50 + public Double spectralRangeMin;
51 51  
52   - public double spectralRangeMax;
  52 + public Double spectralRangeMax;
53 53  
54   - public double spectralSamplingStepMin;
  54 + public Double spectralSamplingStepMin;
55 55  
56   - public double spectralSamplingStepMax;
  56 + public Double spectralSamplingStepMax;
57 57  
58   - public double spectralResolutionMin;
  58 + public Double spectralResolutionMin;
59 59  
60   - public double spectralResolutionMax;
  60 + public Double spectralResolutionMax;
61 61  
62   - public double c1Min;
  62 + public Double c1Min;
63 63  
64   - public double c1Max;
  64 + public Double c1Max;
65 65  
66   - public double c2Min;
  66 + public Double c2Min;
67 67  
68   - public double c2Max;
  68 + public Double c2Max;
69 69  
70   - public double c3Min;
  70 + public Double c3Min;
71 71  
72   - public double c3Max;
  72 + public Double c3Max;
73 73  
74   - public double c1ResolMin;
  74 + public String sRegion;
75 75  
76   - public double c1ResolMax;
  76 + public Double c1ResolMin;
77 77  
78   - public double c2ResolMin;
  78 + public Double c1ResolMax;
79 79  
80   - public double c2ResolMax;
  80 + public Double c2ResolMin;
81 81  
82   - public double c3ResolMin;
  82 + public Double c2ResolMax;
83 83  
84   - public double c3ResolMax;
  84 + public Double c3ResolMin;
  85 +
  86 + public Double c3ResolMax;
85 87  
86 88 public String spatialFrameType;
87 89  
88   - public double incidenceMin;
  90 + public Double incidenceMin;
89 91  
90   - public double incidenceMax;
  92 + public Double incidenceMax;
91 93  
92   - public double emergenceMin;
  94 + public Double emergenceMin;
93 95  
94   - public double emergenceMax;
  96 + public Double emergenceMax;
95 97  
96   - public double phaseMin;
  98 + public Double phaseMin;
97 99  
98   - public double phaseMax;
  100 + public Double phaseMax;
99 101  
100 102 public String instrumentHostName;
101 103  
... ... @@ -103,7 +105,7 @@ public class Granule {
103 105  
104 106 public String measurementType;
105 107  
106   - public int processingLevel;
  108 + public Integer processingLevel;
107 109  
108 110 public Date creationDate;
109 111  
... ... @@ -117,7 +119,7 @@ public class Granule {
117 119  
118 120 public String accessFormat;
119 121  
120   - public int accessEstsize;
  122 + public Integer accessEstsize;
121 123  
122 124 public String dataAccessUrl;
123 125  
... ... @@ -137,39 +139,39 @@ public class Granule {
137 139  
138 140 public String bibReference;
139 141  
140   - public double ra;
  142 + public Double ra;
141 143  
142   - public double dec;
  144 + public Double dec;
143 145  
144   - public double solarLongitudeMin;
  146 + public Double solarLongitudeMin;
145 147  
146   - public double solarLongitudeMax;
  148 + public Double solarLongitudeMax;
147 149  
148   - public double localTimeMin;
  150 + public Double localTimeMin;
149 151  
150   - public double localTimeMax;
  152 + public Double localTimeMax;
151 153  
152   - public double targetDistanceMin;
  154 + public Double targetDistanceMin;
153 155  
154   - public double targetDistanceMax;
  156 + public Double targetDistanceMax;
155 157  
156   - public double targetTimeMin;
  158 + public Double targetTimeMin;
157 159  
158   - public double targetTimeMax;
  160 + public Double targetTimeMax;
159 161  
160 162 public String particleSpectralType;
161 163  
162   - public double particleSpectralRangeMin;
  164 + public Double particleSpectralRangeMin;
163 165  
164   - public double particleSpectralRangeMax;
  166 + public Double particleSpectralRangeMax;
165 167  
166   - public double particleSpectralSamplingStepMin;
  168 + public Double particleSpectralSamplingStepMin;
167 169  
168   - public double particleSpectralSamplingStepMax;
  170 + public Double particleSpectralSamplingStepMax;
169 171  
170   - public double particleSpectralResolutionMin;
  172 + public Double particleSpectralResolutionMin;
171 173  
172   - public double particleSpectralResolutionMax;
  174 + public Double particleSpectralResolutionMax;
173 175  
174 176 public String publisher;
175 177  
... ... @@ -180,4 +182,52 @@ public class Granule {
180 182 public String timeOrigin;
181 183  
182 184 public String timeScale;
  185 +
  186 +
  187 + private Granule() {
  188 +
  189 + }
  190 +
  191 + public Granule(String granuleUid) {
  192 + this.granuleUid = granuleUid;
  193 + }
  194 +
  195 + /**
  196 + * A Granule is valid if all mandatory parameters are filled.
  197 + *
  198 + * @return
  199 + */
  200 + public boolean isValid() {
  201 + boolean valid = granuleUid != null && granuleGid != null && obsId != null;
  202 + valid = valid && dataproductType != null && targetName != null && targetClass != null;
  203 + valid = valid && timeMin != null && timeMax != null;
  204 + valid = valid && timeSamplingStepMin != null && timeSamplingStepMax != null;
  205 + valid = valid && timeExpMin != null && timeExpMax != null;
  206 + valid = valid && spectralRangeMin != null && spectralRangeMax != null;
  207 + valid = valid && timeSamplingStepMin != null && timeSamplingStepMax != null;
  208 + valid = valid && spectralResolutionMin != null && spectralResolutionMax != null;
  209 + valid = valid && c1Min != null && c1Max != null;
  210 + valid = valid && c2Min != null && c2Max != null;
  211 + valid = valid && c3Min != null && c3Max != null;
  212 + valid = valid && sRegion != null;
  213 + valid = valid && c1ResolMin != null && c1ResolMax != null;
  214 + valid = valid && c2ResolMin != null && c2ResolMax != null;
  215 + valid = valid && c3ResolMin != null && c3ResolMax != null;
  216 + valid = valid && spatialFrameType != null;
  217 + valid = valid && incidenceMin != null && incidenceMax != null;
  218 + valid = valid && emergenceMin != null && emergenceMax != null;
  219 + valid = valid && phaseMin != null && phaseMax != null;
  220 + valid = valid && instrumentHostName != null && instrumentName != null;
  221 + valid = valid && measurementType != null && processingLevel != null;
  222 + valid = valid && creationDate != null && modificationDate != null;
  223 + valid = valid && releaseDate != null && serviceTitle != null;
  224 +
  225 + return valid;
  226 + }
  227 +
  228 + @Override
  229 + public String toString() {
  230 + return granuleUid;
  231 + }
  232 +
183 233 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java 0 โ†’ 100644
... ... @@ -0,0 +1,139 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.granule;
  18 +
  19 +import java.text.ParseException;
  20 +import java.text.SimpleDateFormat;
  21 +import java.util.ArrayList;
  22 +import java.util.Date;
  23 +import java.util.List;
  24 +import java.util.logging.Logger;
  25 +
  26 +import eu.omp.irap.vespa.votable.utils.Debug;
  27 +import eu.omp.irap.vespa.votable.votabledata.VOTableData;
  28 +
  29 +/**
  30 + * @author N. Jourdane
  31 + */
  32 +public class GranuleCtrl {
  33 +
  34 + /** The logger for the class GranuleCtrl. */
  35 + private static final Logger logger = Logger.getLogger(GranuleCtrl.class.getName());
  36 +
  37 + private VOTableData data;
  38 +
  39 +
  40 + public GranuleCtrl(VOTableData data) {
  41 + this.data = data;
  42 + }
  43 +
  44 + private String parseString(int rowId, GranuleEnum granuleEnum) {
  45 + return (String) data.getCell(rowId, granuleEnum.toString());
  46 + }
  47 +
  48 + private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException {
  49 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
  50 + return sdf.parse((String) data.getCell(rowId, granuleEnum.toString()));
  51 + }
  52 +
  53 + private Double parseDouble(int rowId, GranuleEnum granuleEnum) {
  54 + Double d = (Double) data.getCell(rowId, granuleEnum.toString());
  55 + return d == null ? Double.NaN : d;
  56 + }
  57 +
  58 + public Granule getGranuleFromVOTableRow(int rowId) throws ParseException {
  59 +
  60 + // TODO: parser colonne par colonne pour รฉviter de faire des comparer les noms de colone ร 
  61 + // chaque ligne.
  62 + Debug.writeObject("data", data);
  63 +
  64 + //@noformat
  65 + Granule g = new Granule(parseString(rowId, GranuleEnum.GRANULE_UID));
  66 + g.granuleGid = parseString(rowId, GranuleEnum.GRANULE_GID);
  67 + g.obsId = parseString(rowId, GranuleEnum.OBS_ID);
  68 + g.dataproductType = parseString(rowId, GranuleEnum.DATAPRODUCT_TYPE);
  69 + g.targetName = parseString(rowId, GranuleEnum.TARGET_NAME);
  70 + g.targetClass = parseString(rowId, GranuleEnum.TARGET_CLASS);
  71 + g.timeMin = parseDouble(rowId, GranuleEnum.TIME_MIN);
  72 + g.timeMax = parseDouble(rowId, GranuleEnum.TIME_MAX);
  73 + g.timeSamplingStepMin = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MIN);
  74 + g.timeSamplingStepMax = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MAX);
  75 + g.timeExpMin = parseDouble(rowId, GranuleEnum.TIME_EXP_MIN);
  76 + g.timeExpMax = parseDouble(rowId, GranuleEnum.TIME_EXP_MAX);
  77 + g.spectralRangeMin = parseDouble(rowId, GranuleEnum.SPECTRAL_RANGE_MIN);
  78 + g.spectralRangeMax = parseDouble(rowId, GranuleEnum.SPECTRAL_RANGE_MAX);
  79 + g.timeSamplingStepMin = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MIN);
  80 + g.timeSamplingStepMax = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MAX);
  81 + g.spectralResolutionMin = parseDouble(rowId, GranuleEnum.SPECTRAL_RESOLUTION_MIN);
  82 + g.spectralResolutionMax = parseDouble(rowId, GranuleEnum.SPECTRAL_RESOLUTION_MAX);
  83 + g.c1Min = parseDouble(rowId, GranuleEnum.C1MIN);
  84 + g.c1Max = parseDouble(rowId, GranuleEnum.C1MAX);
  85 + g.c2Min = parseDouble(rowId, GranuleEnum.C2MIN);
  86 + g.c2Max = parseDouble(rowId, GranuleEnum.C2MAX);
  87 + g.c3Min = parseDouble(rowId, GranuleEnum.C3MIN);
  88 + g.c3Max = parseDouble(rowId, GranuleEnum.C3MAX);
  89 + g.sRegion = parseString(rowId, GranuleEnum.S_REGION);
  90 + g.c1ResolMin = parseDouble(rowId, GranuleEnum.C1_RESOL_MIN);
  91 + g.c1ResolMax = parseDouble(rowId, GranuleEnum.C1_RESOL_MAX);
  92 + g.c2ResolMin = parseDouble(rowId, GranuleEnum.C2_RESOL_MIN);
  93 + g.c2ResolMax = parseDouble(rowId, GranuleEnum.C2_RESOL_MAX);
  94 + g.c3ResolMin = parseDouble(rowId, GranuleEnum.C3_RESOL_MIN);
  95 + g.c3ResolMax = parseDouble(rowId, GranuleEnum.C3_RESOL_MAX);
  96 + g.spatialFrameType = parseString(rowId, GranuleEnum.SPATIAL_FRAME_TYPE);
  97 + g.incidenceMin = parseDouble(rowId, GranuleEnum.INCIDENCE_MIN);
  98 + g.incidenceMax = parseDouble(rowId, GranuleEnum.INCIDENCE_MAX);
  99 + g.emergenceMin = parseDouble(rowId, GranuleEnum.EMERGENCE_MIN);
  100 + g.emergenceMax = parseDouble(rowId, GranuleEnum.EMERGENCE_MAX);
  101 + g.phaseMin = parseDouble(rowId, GranuleEnum.PHASE_MIN);
  102 + g.phaseMax = parseDouble(rowId, GranuleEnum.PHASE_MAX);
  103 + g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME);
  104 + g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME);
  105 + g.measurementType = parseString(rowId, GranuleEnum.MEASUREMENT_TYPE);
  106 + g.processingLevel = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString());
  107 + g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE);
  108 + g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ;
  109 + g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ;
  110 + g.serviceTitle = parseString(rowId, GranuleEnum.SERVICE_TITLE);
  111 + //@format
  112 +
  113 + if (!g.isValid()) {
  114 + System.out.println(data.getCell(rowId, "polar_radius"));
  115 + throw new IllegalArgumentException("One or more EPN parameter is null.");
  116 + }
  117 + return g;
  118 + }
  119 +
  120 + public static boolean isV2(VOTableData data) {
  121 + return !data.containsColumn("index");
  122 + }
  123 +
  124 + public List<Granule> getGranulesFromVOTable() throws ParseException {
  125 + Debug.writeObject("data", data);
  126 +
  127 + if (!GranuleCtrl.isV2(data)) {
  128 + throw new IllegalArgumentException(
  129 + "The EPN-CORE is not v2, which is the only suported version");
  130 + }
  131 + List<Granule> granules = new ArrayList<>();
  132 +
  133 + for (int rowId = 0; rowId < data.getNbRows(); rowId++) {
  134 + granules.add(getGranuleFromVOTableRow(rowId));
  135 + }
  136 + return granules;
  137 + }
  138 +
  139 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java
... ... @@ -25,8 +25,7 @@ import java.util.logging.Logger;
25 25  
26 26 import eu.omp.irap.vespa.epntapclient.EpnTapController;
27 27 import eu.omp.irap.vespa.epntapclient.service.Queries;
28   -import eu.omp.irap.vespa.votable.VOTableException.CantDisplayVOTableException;
29   -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException;
  28 +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
30 29  
31 30 /**
32 31 * @author N. Jourdane
... ... @@ -50,7 +49,7 @@ public class GUIController extends EpnTapController implements ViewListener {
50 49 public GUIController() {
51 50 super();
52 51 mainView = new EpnTapMainView(this);
53   - mainView.getServicesPanel().fillTable(servicesCtrl.getColumns(), servicesCtrl.getData());
  52 + mainView.getServicesPanel().fillTable(servicesCtrl.getVOTableData());
54 53 }
55 54  
56 55 public EpnTapMainView getView() {
... ... @@ -70,7 +69,7 @@ public class GUIController extends EpnTapController implements ViewListener {
70 69 GUIController.logger.info("Sending query: " + query + " on " + selectedTableServiceURL);
71 70 try {
72 71 voTablePath = sendQuery(query, selectedTableServiceURL);
73   - } catch (CantDisplayVOTableException | CantSendQueryException e) {
  72 + } catch (CantGetVOTableException e) {
74 73 // TODO create exception
75 74 mainView.displayError("Can not send query.", e.getMessage());
76 75 GUIController.logger.log(Level.WARNING, "Can not send query.", e);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java
... ... @@ -42,9 +42,8 @@ import javax.swing.event.DocumentListener;
42 42  
43 43 import com.google.gson.JsonArray;
44 44 import com.google.gson.JsonObject;
45   -import com.google.gson.JsonParser;
46 45  
47   -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException;
  46 +import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
48 47 import eu.omp.irap.vespa.votable.utils.Network;
49 48  
50 49 /**
... ... @@ -427,15 +426,15 @@ public abstract class ParamField extends JPanel {
427 426 *
428 427 * @param begining The beginning of the target_name.
429 428 * @return An array of Strings corresponding to the target names got.
430   - * @throws CantSendQueryException If the resolver do not work.
  429 + * @throws CantSendQueryException
  430 + * @throws CantGetXMLException If the resolver do not work.
431 431 */
432 432 static String[] getItems(String begining) throws CantSendQueryException {
433 433 Map<String, String> params = new HashMap<>();
434 434 params.put("q", "\"" + begining + "\"");
435 435  
436   - StringBuilder resolverResult = Network.sendQuery(ParamField.RESOLVER_URL, params);
437   -
438   - JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject();
  436 + String query = Network.buildQuery(ParamField.RESOLVER_URL, params);
  437 + JsonObject root = Network.readJson(query);
439 438 int count = Integer.parseInt(root.get("count").toString());
440 439 String[] targetNames = new String[count];
441 440 JsonArray hits = root.getAsJsonArray("hits");
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
... ... @@ -29,42 +29,45 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner;
29 29 */
30 30 public final class Queries {
31 31  
32   - /** Query to get all EPN-TAP services. */
33   - public static final String GET_EPN_TAP_SERVICES = "SELECT short_name, "
34   - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url "
35   - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table "
36   - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability "
37   - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND "
38   - + "intf_type='vs:paramhttp' AND "
39   - + "detail_xpath='/capability/dataModel/@ivo-id' AND "
40   - + "1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') "
41   - + "ORDER BY short_name, table_name";
42   -
43   - /** Query to get all EPN-TAP services. */
44   - public static final String GET_TAP_OBSCOR_SERVICES = "SELECT short_name, "
45   - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url "
46   - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table "
47   - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability "
48   - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND "
49   - + "intf_type='vs:paramhttp' AND "
50   - + "detail_xpath='/capability/dataModel/@ivo-id' AND "
51   - + "1=ivo_nocasematch(detail_value, 'ivo://ivoa.net/std/ObsCore%') "
52   - + "ORDER BY short_name, table_name";
53   -
54   - /** Query to get all EPN-TAP services. */
55   - public static final String GET_TAP_SERVICES = "SELECT short_name, "
56   - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url "
57   - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table "
58   - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability "
59   - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND "
  32 + private static final String SELECT = "SELECT short_name, res_title AS schema_title, "
  33 + + "table_name, schema_name, ivoid, access_url ";
  34 +
  35 + private static final String FROM = "FROM rr.resource "
  36 + + "NATURAL JOIN rr.res_schema "
  37 + + "NATURAL JOIN rr.res_table "
  38 + + "NATURAL JOIN rr.interface "
  39 + + "NATURAL JOIN rr.res_detail "
  40 + + "NATURAL JOIN rr.capability ";
  41 +
  42 + private static final String ORDER_BY = "ORDER BY short_name, table_name";
  43 +
  44 + private static final String WHERE_TAP = "WHERE "
  45 + + "standard_id='ivo://ivoa.net/std/tap' AND "
60 46 + "intf_type='vs:paramhttp' AND "
61   - + "detail_xpath='/capability/dataModel/@ivo-id' "
62   - + "ORDER BY short_name, table_name";
  47 + + "detail_xpath='/capability/dataModel/@ivo-id' ";
  48 +
  49 + //@noformat
  50 +
  51 + /** Query to get all TAP services. */
  52 + public static final String GET_TAP_SERVICES =
  53 + Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY;
  54 +
  55 + /** Query to get TAP services which implement the specified core. */
  56 + public static final String GET_TAP_SERVICES_WHERE_CORE =
  57 + Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
  58 + + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') "
  59 + + Queries.ORDER_BY;
  60 +
  61 + /** Query to get the TAP service with the specified ivoid. */
  62 + public static final String GET_TAP_SERVICES_WHERE_IVOID =
  63 + Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
  64 + + "AND ivoid = '%s' ";
63 65  
64   - /** Query to get all VO-resources which implements epn-tap core. */
65   - public static final String GET_VO_RESOURCES = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search?"
66   - + "keywords=standardid:%22ivo://ivoa.net/std/TAP%22%20datamodel:%22EpnCore%22&max=100";
  66 + public static final String GET_TAP_SERVICES_SELECT_WHERE_IVOID =
  67 + "SELECT %s " + Queries.FROM + Queries.WHERE_TAP
  68 + + "AND ivoid = '%s' ";
67 69  
  70 + //@format
68 71  
69 72 /** Constructor to hide the implicit public one. */
70 73 private Queries() {
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java
... ... @@ -23,7 +23,7 @@ public class Service {
23 23  
24 24 private String ivoid;
25 25  
26   - private String resTitle;
  26 + private String title;
27 27  
28 28 private String shortName;
29 29  
... ... @@ -42,24 +42,6 @@ public class Service {
42 42 private String updated;
43 43  
44 44  
45   - public enum ServiceType {
46   -
47   - OBSCORE("obscore"), EPNCORE("epncore");
48   -
49   - private String type = "";
50   -
51   -
52   - ServiceType(String type) {
53   - this.type = type;
54   - }
55   -
56   - @Override
57   - public String toString() {
58   - return type;
59   - }
60   - }
61   -
62   -
63 45 private Service() {
64 46 }
65 47  
... ... @@ -68,86 +50,86 @@ public class Service {
68 50 }
69 51  
70 52 public boolean isValid() {
71   - boolean isValid = ivoid != null && resTitle != null && shortName != null;
  53 + boolean isValid = ivoid != null && title != null && shortName != null;
72 54 isValid = isValid && type != null && description != null && creator != null;
73 55 isValid = isValid && contentLevel != null && referenceURL != null && created != null;
74 56 return isValid && updated != null;
75 57 }
76 58  
77   - public String getIvoid() {
78   - return ivoid;
  59 + public String getTitle() {
  60 + return title;
79 61 }
80 62  
81   - public String getResTitle() {
82   - return resTitle;
  63 + public void setTitle(String resTitle) {
  64 + title = resTitle;
83 65 }
84 66  
85 67 public String getShortName() {
86 68 return shortName;
87 69 }
88 70  
89   - public String getType() {
90   - return type;
91   - }
92   -
93   - public String getDescription() {
94   - return description;
95   - }
96   -
97   - public String getCreator() {
98   - return creator;
99   - }
100   -
101   - public String getContentLevel() {
102   - return contentLevel;
103   - }
104   -
105   - public String getReferenceURL() {
106   - return referenceURL;
107   - }
108   -
109   - public String getCreated() {
110   - return created;
111   - }
112   -
113   - public String getUpdated() {
114   - return updated;
115   - }
116   -
117   - public void setTitle(String resTitle) {
118   - this.resTitle = resTitle;
119   - }
120   -
121 71 public void setShortName(String shortName) {
122 72 this.shortName = shortName;
123 73 }
124 74  
  75 + public String getType() {
  76 + return type;
  77 + }
  78 +
125 79 public void setType(String type) {
126 80 this.type = type;
127 81 }
128 82  
  83 + public String getDescription() {
  84 + return description;
  85 + }
  86 +
129 87 public void setDescription(String description) {
130 88 this.description = description;
131 89 }
132 90  
  91 + public String getCreator() {
  92 + return creator;
  93 + }
  94 +
133 95 public void setCreator(String creator) {
134 96 this.creator = creator;
135 97 }
136 98  
  99 + public String getContentLevel() {
  100 + return contentLevel;
  101 + }
  102 +
137 103 public void setContentLevel(String contentLevel) {
138 104 this.contentLevel = contentLevel;
139 105 }
140 106  
  107 + public String getReferenceURL() {
  108 + return referenceURL;
  109 + }
  110 +
141 111 public void setReferenceURL(String referenceURL) {
142 112 this.referenceURL = referenceURL;
143 113 }
144 114  
  115 + public String getCreated() {
  116 + return created;
  117 + }
  118 +
145 119 public void setCreated(String created) {
146 120 this.created = created;
147 121 }
148 122  
  123 + public String getUpdated() {
  124 + return updated;
  125 + }
  126 +
149 127 public void setUpdated(String updated) {
150 128 this.updated = updated;
151 129 }
152 130  
  131 + public String getIvoid() {
  132 + return ivoid;
  133 + }
  134 +
153 135 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java 0 โ†’ 100644
... ... @@ -0,0 +1,36 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.service;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public enum ServiceCore {
  23 + OBSCORE("ObsCore"), EPNCORE("EpnCore");
  24 +
  25 + private String type;
  26 +
  27 +
  28 + ServiceCore(String type) {
  29 + this.type = type;
  30 + }
  31 +
  32 + @Override
  33 + public String toString() {
  34 + return type;
  35 + }
  36 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java
... ... @@ -27,8 +27,11 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel;
27 27 import eu.omp.irap.vespa.epntapclient.voresource.model.Creator;
28 28 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
29 29 import eu.omp.irap.vespa.epntapclient.voresource.model.Type;
30   -import eu.omp.irap.vespa.votable.data.VOTableData;
  30 +import eu.omp.irap.vespa.votable.Consts;
  31 +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
  32 +import eu.omp.irap.vespa.votable.controller.VOTableController;
31 33 import eu.omp.irap.vespa.votable.utils.StringJoiner;
  34 +import eu.omp.irap.vespa.votable.votabledata.VOTableData;
32 35  
33 36 /**
34 37 * @author N. Jourdane
... ... @@ -41,8 +44,7 @@ public class ServiceCtrl {
41 44 public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
42 45  
43 46  
44   - public final Service getServiceFromResource(Service.ServiceType serviceType,
45   - Resource resource) {
  47 + public final static Service getServiceFromResource(Resource resource) {
46 48 Service service = new Service(resource.getIdentifier());
47 49 service.setTitle(resource.getTitle());
48 50 service.setShortName(resource.getShortName());
... ... @@ -69,13 +71,7 @@ public class ServiceCtrl {
69 71 return service;
70 72 }
71 73  
72   - private static String XMLDateToString(XMLGregorianCalendar date) {
73   - SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT);
74   - return sdf.format(date.toGregorianCalendar().getTime());
75   - }
76   -
77   - public final List<Service> getServiceFromVOTableData(Service.ServiceType serviceType,
78   - VOTableData data) {
  74 + public final static List<Service> getServicesFromVOTableData(VOTableData data) {
79 75 List<Service> services = new ArrayList<>();
80 76 for (int i = 0; i < data.getNbRows(); i++) {
81 77 Service service = new Service((String) data.getCell(i, "ivoid"));
... ... @@ -91,7 +87,20 @@ public class ServiceCtrl {
91 87 // TODO: Convert date format
92 88 services.add(service);
93 89 }
94   -
95 90 return services;
96 91 }
  92 +
  93 + public static Service getServiceFromIvoid(String ivoid) throws CantGetVOTableException {
  94 + // TODO: utiliser Resource plutรดt que VOTable
  95 + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid);
  96 + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  97 + ctrl.readTable();
  98 + List<Service> services = ServiceCtrl.getServicesFromVOTableData(ctrl.getVOTableData());
  99 + return services.get(0);
  100 + }
  101 +
  102 + private static String XMLDateToString(XMLGregorianCalendar date) {
  103 + SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT);
  104 + return sdf.format(date.toGregorianCalendar().getTime());
  105 + }
97 106 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
... ... @@ -14,11 +14,9 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.resource;
  17 +package eu.omp.irap.vespa.epntapclient.voresource;
18 18  
19 19 import java.io.File;
20   -import java.io.FileNotFoundException;
21   -import java.io.FileReader;
22 20 import java.util.ArrayList;
23 21 import java.util.HashMap;
24 22 import java.util.List;
... ... @@ -28,19 +26,18 @@ import java.util.logging.Logger;
28 26 import javax.xml.bind.JAXBContext;
29 27 import javax.xml.bind.JAXBException;
30 28 import javax.xml.bind.Unmarshaller;
  29 +import javax.xml.transform.Source;
  30 +import javax.xml.transform.stream.StreamSource;
31 31  
32 32 import com.google.gson.JsonArray;
33 33 import com.google.gson.JsonElement;
34 34 import com.google.gson.JsonObject;
35   -import com.google.gson.JsonParser;
36   -import com.google.gson.stream.JsonReader;
37 35  
38   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.CantGetVOResourceException;
39   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.CantReadVOResourceException;
40   -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.VOResourceIsNotValidException;
41   -import eu.omp.irap.vespa.epntapclient.service.Service.ServiceType;
  36 +import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
  37 +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException.CantGetVOResourceException;
  38 +import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException.VOResourceIsNotValidException;
42 39 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
43   -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException;
  40 +import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
44 41 import eu.omp.irap.vespa.votable.utils.Network;
45 42 import eu.omp.irap.vespa.votable.utils.StringJoiner;
46 43  
... ... @@ -52,8 +49,6 @@ public class VOResourceCtrl {
52 49 /** The logger for the class VOResourceController. */
53 50 private static final Logger logger = Logger.getLogger(VOResourceCtrl.class.getName());
54 51  
55   - private static final String VORESOURCE_MODEL_PACKAGE = "eu.omp.irap.vespa.epntapclient.voresource.model";
56   -
57 52 private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml";
58 53  
59 54 private static final String GET_IVOID_RESOURCES_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search";
... ... @@ -61,22 +56,23 @@ public class VOResourceCtrl {
61 56 private static final int MAX_VORESOURCES = 100;
62 57  
63 58  
64   - public static List<Resource> getVOResources(ServiceType type, Map<String, String> keywords)
  59 + public static List<Resource> getVOResources(ServiceCore type, Map<String, String> keywords)
65 60 throws VOResourceException {
66   - return VOResourceCtrl
67   - .getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type, keywords));
  61 + List<String> ivoids = VOResourceCtrl.getIvoidResources(type, keywords);
  62 + return VOResourceCtrl.getVOResourcesFromIvoids(ivoids);
68 63 }
69 64  
70   - public static List<Resource> getVOResources(ServiceType type) throws VOResourceException {
71   - return VOResourceCtrl.getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type));
  65 + public static List<Resource> getVOResources(ServiceCore type) throws VOResourceException {
  66 + List<String> ivoids = VOResourceCtrl.getIvoidResources(type);
  67 + return VOResourceCtrl.getVOResourcesFromIvoids(ivoids);
72 68 }
73 69  
74   - public static List<String> getIvoidResources(ServiceType type) throws VOResourceException {
  70 + public static List<String> getIvoidResources(ServiceCore type) throws VOResourceException {
75 71 return VOResourceCtrl.getIvoidResources(type, new HashMap());
76 72 }
77 73  
78   - public static List<String> getIvoidResources(ServiceType type, Map<String, String> keywords)
79   - throws VOResourceException {
  74 + public static List<String> getIvoidResources(ServiceCore type, Map<String, String> keywords)
  75 + throws CantGetVOResourceException {
80 76 List<String> ivoidResources;
81 77  
82 78 keywords.put("datamodel", type.toString());
... ... @@ -90,14 +86,13 @@ public class VOResourceCtrl {
90 86 Map<String, String> parameters = new HashMap();
91 87 parameters.put("keywords", keywordJoiner.toString());
92 88 parameters.put("max", String.valueOf(VOResourceCtrl.MAX_VORESOURCES));
  89 + String query = Network.buildQuery(GET_IVOID_RESOURCES_URL, parameters);
93 90 try {
94   - String ivoidResourcesPath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL,
95   - parameters);
96   - ivoidResources = VOResourceCtrl.parseIvoidResources(ivoidResourcesPath);
97   - } catch (CantSendQueryException e1) {
98   - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1);
99   - // TODO: pass the entire request.
  91 + ivoidResources = parseIvoidResources(Network.readJson(query));
  92 + } catch (CantSendQueryException e) {
  93 + throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
100 94 }
  95 + logger.info("Got resources: " + StringJoiner.join(ivoidResources));
101 96 return ivoidResources;
102 97 }
103 98  
... ... @@ -105,18 +100,35 @@ public class VOResourceCtrl {
105 100 Map<String, String> parameters = new HashMap();
106 101 parameters.put("identifier", identifier);
107 102 String voResourcePath;
108   - try {
109   - voResourcePath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters);
110   - } catch (CantSendQueryException e1) {
111   - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1);
112   - }
  103 +
  104 + // try {
  105 + // VOResourceCtrl.logger.info("Trying to get VOResource '" + identifier + "'...");
  106 + // voResourcePath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters);
  107 + // } catch (CantSendQueryException e1) {
  108 + // throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1);
  109 + // }
  110 + // VOResourceCtrl.logger.info("VOResource downloaded in " + voResourcePath);
  111 +
  112 + voResourcePath = "/home/nathanael/resources/resourceModifJMG.xml";
  113 +
  114 + // try {
  115 + // AlterXMLFile.renameNode(voResourcePath, "ri:Resource", "Resource");
  116 + // AlterXMLFile.alterAttribute(voResourcePath, "Resource", "xsi:type", "-");
  117 + // } catch (NoSuchElementException | IOException e1) {
  118 + // // TODO Auto-generated catch block
  119 + // e1.printStackTrace();
  120 + // }
113 121  
114 122 Resource voResource;
115   - JAXBContext jc;
116 123 try {
117   - jc = JAXBContext.newInstance(VOResourceCtrl.VORESOURCE_MODEL_PACKAGE);
  124 + File inputStream = new File(voResourcePath);
  125 +
  126 + Source source = new StreamSource(inputStream);
  127 + JAXBContext jc = JAXBContext.newInstance(Resource.class);
118 128 Unmarshaller unmarshaller = jc.createUnmarshaller();
119   - voResource = (Resource) unmarshaller.unmarshal(new File(voResourcePath));
  129 + voResource = unmarshaller.unmarshal(source, Resource.class).getValue();
  130 +
  131 + // erreur sur : o = unmarshaller.unmarshal(f);
120 132 } catch (JAXBException e) {
121 133 throw new VOResourceIsNotValidException(voResourcePath, e);
122 134 }
... ... @@ -133,17 +145,8 @@ public class VOResourceCtrl {
133 145 return resources;
134 146 }
135 147  
136   - private static List<String> parseIvoidResources(String ivoidResourcesPath)
137   - throws CantReadVOResourceException {
138   - JsonReader reader;
139   - try {
140   - reader = new JsonReader(new FileReader(ivoidResourcesPath));
141   - } catch (FileNotFoundException e) {
142   - throw new CantReadVOResourceException(ivoidResourcesPath, e);
143   - }
144   - JsonObject root = new JsonParser().parse(reader).getAsJsonObject();
145   - JsonArray resources = root.get("resources").getAsJsonArray();
146   -
  148 + private static List<String> parseIvoidResources(JsonObject getIvoidsResult) {
  149 + JsonArray resources = getIvoidsResult.get("resources").getAsJsonArray();
147 150 List<String> ivoidResources = new ArrayList<>();
148 151 for (JsonElement e : resources) {
149 152 ivoidResources.add(e.getAsJsonObject().get("identifier").getAsString());
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java
... ... @@ -14,7 +14,7 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.resource;
  17 +package eu.omp.irap.vespa.epntapclient.voresource;
18 18  
19 19 /**
20 20 * @author N. Jourdane
... ...