From cfbb6d0742bac8cb95ca1b865c7dfc0e2abfabbf Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 9 May 2016 14:54:05 +0200 Subject: [PATCH] Implement most of EpnTap facade methods. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java | 23 +++++++---------------- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java | 7 +++---- src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java | 11 +++++------ src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java | 69 ++++++++++++++++++++++++++++++++++++--------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java | 94 ++++++++++++++++++++++++++++++++++++++-------------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java | 36 ++++++++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java | 31 ++++++++++++++++++++----------- src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java | 2 +- 13 files changed, 587 insertions(+), 320 deletions(-) create mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java create mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java 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 df5c8a8..9f0a10d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -21,9 +21,9 @@ import java.util.Map; 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.VOTableException.CantDisplayVOTableException; -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException; +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; import eu.omp.irap.vespa.votable.controller.VOTableController; /** @@ -39,7 +39,7 @@ public class EpnTapController { /** The controller of the VOTable displaying the list of services. */ protected VOTableController servicesCtrl; - /** The controller of the VOTable displaying the list of services. */ + /** The controller of the VOTable displaying the result. */ protected VOTableController resultsCtrl; /** @@ -52,22 +52,13 @@ public class EpnTapController { * Method constructor, which initialize servicesController, resultsController and mainView. */ public EpnTapController() { - servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, "ADQL", - Queries.GET_EPN_TAP_SERVICES); - try { - servicesCtrl.readTable(); - } catch (CantDisplayVOTableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CantSendQueryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); + servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); } public String sendQuery(String query, String tableServiceURL) - throws CantDisplayVOTableException, CantSendQueryException { - resultsCtrl = new VOTableController(tableServiceURL, "ADQL", query); + throws CantGetVOTableException { + resultsCtrl = new VOTableController(tableServiceURL, query); resultsCtrl.readTable(); return resultsCtrl.getVOTablePath(); } 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 074cade..fd54de4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapFacade.java @@ -16,14 +16,25 @@ package eu.omp.irap.vespa.epntapclient; +import java.text.ParseException; import java.util.List; import java.util.Map; import java.util.logging.Logger; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceCtrl; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException; +import eu.omp.irap.vespa.epntapclient.granule.Granule; +import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl; +import eu.omp.irap.vespa.epntapclient.service.Queries; import eu.omp.irap.vespa.epntapclient.service.Service; +import eu.omp.irap.vespa.epntapclient.service.ServiceCore; +import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl; +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.Consts; +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; +import eu.omp.irap.vespa.votable.controller.VOTableController; +import eu.omp.irap.vespa.votable.votabledata.VOTableData; /** * @author N. Jourdane @@ -34,115 +45,115 @@ public class EpnTapFacade implements EpnTapInterface { private static final Logger logger = Logger.getLogger(EpnTapFacade.class.getName()); - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOResources() */ + // *** Resource *** + @Override - public List getEPNVOResources(Service.ServiceType serviceType) - throws VOResourceException { - return VOResourceCtrl.getVOResources(serviceType); + public Resource getEPNVOresource(String ivoid) throws VOResourceException { + return VOResourceCtrl.getVOresource(ivoid); } - /* - * @see - * eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOResources(java.util.List) - */ + // *** Resources *** + @Override - public List getEPNVOResources(Service.ServiceType serviceType, - Map keywords) - throws VOResourceException { - return VOResourceCtrl.getVOResources(serviceType, keywords); + public List getEPNVOResources() throws VOResourceException { + return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE); } - /* - * @see - * eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNVOresource(java.lang.String) - */ @Override - public Resource getEPNVOresource(String ivoid) { - return null; - // TODO Auto-generated method stub - + public List getEPNVOResources(Map keywords) + throws VOResourceException { + return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords); } - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices() */ - @Override - public void getEPNServices() { - // TODO Auto-generated method stub + // *** Service *** + public Service _getEPNService(String ivoid) throws CantGetVOTableException { + return ServiceCtrl.getServiceFromIvoid(ivoid); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices(java.util.List) - */ @Override - public void getEPNServices(List attributes) { - // TODO Auto-generated method stub - + public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException { + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid); + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); + ctrl.readTable(); + return ctrl.getVOTable(); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNServices(java.util.List, - * java.util.List) - */ @Override - public void getEPNServices(List keywords, List attributes) { - // TODO Auto-generated method stub - + public VOTABLE getEPNService(String ivoid, List attributes) + throws CantGetVOTableException { + // TODO process attributes + return getEPNService(ivoid); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNService(java.lang.String) - */ - @Override - public void getEPNService(String ivoID) { - // TODO Auto-generated method stub + // *** 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(); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNService(java.lang.String, - * java.util.List) - */ @Override - public void getEPNService(String ivoID, List attributes) { - // TODO Auto-generated method stub - + public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException { + // TODO process attributes + return getEPNServices(); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getEPNCoreTableName(java.lang. - * String) - */ @Override - public void getEPNCoreTableName(String service_ivoid) { - // TODO Auto-generated method stub - + public VOTABLE getEPNServices(List keywords, List attributes) + throws CantGetVOTableException { + // TODO process attributes and keywords + return getEPNServices(); } - /* @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#getTAPURL(java.lang.String) */ - @Override - public void getTAPURL(String service_ivoid) { - // TODO Auto-generated method stub + // *** Getters *** + @Override + public String getEPNCoreTableName(String ivoid) + throws CantGetVOTableException { + String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "table_name", + ivoid); + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); + ctrl.readTable(); + return (String) ctrl.getVOTableData().getCell(0, 0); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#sendADQLQuery(java.lang.String, - * java.lang.String) - */ @Override - public void sendADQLQuery(String TAPURL, String ADQLQuery) { - // TODO Auto-generated method stub - + public String getTAPURL(String ivoid) + throws CantGetVOTableException { + String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "access_url", + ivoid); + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); + ctrl.readTable(); + return (String) ctrl.getVOTableData().getCell(0, 0); } - /* - * @see eu.omp.irap.vespa.epntapclient.epnTapLib.EpnTapInterface#sendQuery(java.lang.String, - * java.lang.String, java.lang.String) - */ + // *** Queries *** + @Override - public void sendQuery(String TAPURL, String schema_name, String Query) { - // TODO Auto-generated method stub + public List sendADQLQuery(String tapURL, String adqlQuery) + throws CantGetVOTableException { + EpnTapController epnTapCtrl = new EpnTapController(); + epnTapCtrl.sendQuery(adqlQuery, tapURL); + VOTableData data = epnTapCtrl.getResultsController().getVOTableData(); + List granules; + try { + GranuleCtrl gc = new GranuleCtrl(data); + granules = gc.getGranulesFromVOTable(); + } catch (ParseException e) { + throw new CantGetVOTableException("Parsing error on a granule.", e); + } + return granules; + } + @Override + public List sendQuery(String tapURL, String schemaName, String query) { + // TODO TBC + return null; } } 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 8a629b7..43b95eb 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java @@ -19,76 +19,121 @@ package eu.omp.irap.vespa.epntapclient; import java.util.List; import java.util.Map; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException; -import eu.omp.irap.vespa.epntapclient.service.Service; +import eu.omp.irap.vespa.epntapclient.granule.Granule; +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; /** * @author N. Jourdane */ public interface EpnTapInterface { + // *** Resource *** + + /** returns the VOResource element of the service identified by the ivoID. */ + public Resource getEPNVOresource(String ivoid) throws VOResourceException; + + // *** Resources *** + /** returns a set of VOResource elements (one per EPN-TAP service) */ - List getEPNVOResources(Service.ServiceType serviceType) - throws VOResourceException; + public List getEPNVOResources() throws VOResourceException; /** * Returns a set of VOREsource elements (one per EPN-TAP service corresponding to the keywords). * The way keywords are defined is still to be defined. */ - List getEPNVOResources(Service.ServiceType serviceType, - Map keywords) throws VOResourceException; + public List getEPNVOResources(Map keywords) + throws VOResourceException; - /** returns the VOResource element of the service identified by the ivoID. */ - Resource getEPNVOresource(String ivoid) throws VOResourceException; + // *** Service *** + + /** + * returns a VOTable containing the attributes of the corresponding service (from a predefined + * list) + * + * @throws IllegalAccessException + * @throws CantGetXMLException + * @throws CantDisplayVOTableException + */ + public VOTABLE getEPNService(String ivoID) throws CantGetVOTableException; + + /** + * returns a VOTable containing the attributes of the corresponding service (from the list of + * attributes) + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException + */ + public VOTABLE getEPNService(String ivoID, List attributes) + throws CantGetVOTableException; + + // *** Services *** /** * returns a VOTable containing the list of EPN-TAP services and their attributes (from a * predefined list) + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void getEPNServices(); + public VOTABLE getEPNServices() throws CantGetVOTableException; /** * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list * of attributes) + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void getEPNServices(List attributes); + public VOTABLE getEPNServices(List attributes) throws CantGetVOTableException; /** * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and * their attributes (from the list of attributes) + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void getEPNServices(List keywords, List attributes); + public VOTABLE getEPNServices(List keywords, List attributes) + throws CantGetVOTableException; + + // *** Getters *** /** - * returns a VOTable containing the attributes of the corresponding service (from a predefined - * list) + * returns the name of the EPNCore Table related to a service. + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void getEPNService(String ivoID); + public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException; /** - * returns a VOTable containing the attributes of the corresponding service (from the list of - * attributes) + * returns the Access URL of an EPN-TAP Service. + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void getEPNService(String ivoID, List attributes); - - /** returns the name of the EPNCore Table related to a service. */ - void getEPNCoreTableName(String service_ivoid); + public String getTAPURL(String ivoid) throws CantGetVOTableException; - /** returns the Access URL of an EPN-TAP Service. */ - void getTAPURL(String service_ivoid); + // *** Queries *** /** * returns the list of granules which are compliant with the ADQL Query, in VOTable format . * TAPURL is build from elements taken in VOResource. "ADQLQuery" is created by the Client. It * is a full query containing the name of the EPNCore table, taken in VOResource. + * + * @throws CantGetXMLException + * @throws CantDisplayVOTableException */ - void sendADQLQuery(String TAPURL, String ADQLQuery); + public List sendADQLQuery(String tapURL, String adqlQuery) + throws CantGetVOTableException; /** * returns the list of granules which are compliant with the Query, in VOTable format. "Query" * is not an ADQL query. It is taken from a list of predefined queries. This list must be * created. */ - void sendQuery(String TAPURL, String schema_name, String Query); + public List sendQuery(String tapURL, String schemaName, String query); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java index 35ab31c..fcc5d5e 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/Granule.java @@ -35,67 +35,69 @@ public class Granule { public String targetClass; - public double timeMin; + public Double timeMin; - public double timeMax; + public Double timeMax; - public double timeSamplingStepMin; + public Double timeSamplingStepMin; - public double timeSamplingStepMax; + public Double timeSamplingStepMax; - public double timeExpMin; + public Double timeExpMin; - public double timeExpMax; + public Double timeExpMax; - public double spectralRangeMin; + public Double spectralRangeMin; - public double spectralRangeMax; + public Double spectralRangeMax; - public double spectralSamplingStepMin; + public Double spectralSamplingStepMin; - public double spectralSamplingStepMax; + public Double spectralSamplingStepMax; - public double spectralResolutionMin; + public Double spectralResolutionMin; - public double spectralResolutionMax; + public Double spectralResolutionMax; - public double c1Min; + public Double c1Min; - public double c1Max; + public Double c1Max; - public double c2Min; + public Double c2Min; - public double c2Max; + public Double c2Max; - public double c3Min; + public Double c3Min; - public double c3Max; + public Double c3Max; - public double c1ResolMin; + public String sRegion; - public double c1ResolMax; + public Double c1ResolMin; - public double c2ResolMin; + public Double c1ResolMax; - public double c2ResolMax; + public Double c2ResolMin; - public double c3ResolMin; + public Double c2ResolMax; - public double c3ResolMax; + public Double c3ResolMin; + + public Double c3ResolMax; public String spatialFrameType; - public double incidenceMin; + public Double incidenceMin; - public double incidenceMax; + public Double incidenceMax; - public double emergenceMin; + public Double emergenceMin; - public double emergenceMax; + public Double emergenceMax; - public double phaseMin; + public Double phaseMin; - public double phaseMax; + public Double phaseMax; public String instrumentHostName; @@ -103,7 +105,7 @@ public class Granule { public String measurementType; - public int processingLevel; + public Integer processingLevel; public Date creationDate; @@ -117,7 +119,7 @@ public class Granule { public String accessFormat; - public int accessEstsize; + public Integer accessEstsize; public String dataAccessUrl; @@ -137,39 +139,39 @@ public class Granule { public String bibReference; - public double ra; + public Double ra; - public double dec; + public Double dec; - public double solarLongitudeMin; + public Double solarLongitudeMin; - public double solarLongitudeMax; + public Double solarLongitudeMax; - public double localTimeMin; + public Double localTimeMin; - public double localTimeMax; + public Double localTimeMax; - public double targetDistanceMin; + public Double targetDistanceMin; - public double targetDistanceMax; + public Double targetDistanceMax; - public double targetTimeMin; + public Double targetTimeMin; - public double targetTimeMax; + public Double targetTimeMax; public String particleSpectralType; - public double particleSpectralRangeMin; + public Double particleSpectralRangeMin; - public double particleSpectralRangeMax; + public Double particleSpectralRangeMax; - public double particleSpectralSamplingStepMin; + public Double particleSpectralSamplingStepMin; - public double particleSpectralSamplingStepMax; + public Double particleSpectralSamplingStepMax; - public double particleSpectralResolutionMin; + public Double particleSpectralResolutionMin; - public double particleSpectralResolutionMax; + public Double particleSpectralResolutionMax; public String publisher; @@ -180,4 +182,52 @@ public class Granule { public String timeOrigin; public String timeScale; + + + private Granule() { + + } + + public Granule(String granuleUid) { + this.granuleUid = granuleUid; + } + + /** + * A Granule is valid if all mandatory parameters are filled. + * + * @return + */ + public boolean isValid() { + boolean valid = granuleUid != null && granuleGid != null && obsId != null; + valid = valid && dataproductType != null && targetName != null && targetClass != null; + valid = valid && timeMin != null && timeMax != null; + valid = valid && timeSamplingStepMin != null && timeSamplingStepMax != null; + valid = valid && timeExpMin != null && timeExpMax != null; + valid = valid && spectralRangeMin != null && spectralRangeMax != null; + valid = valid && timeSamplingStepMin != null && timeSamplingStepMax != null; + valid = valid && spectralResolutionMin != null && spectralResolutionMax != null; + valid = valid && c1Min != null && c1Max != null; + valid = valid && c2Min != null && c2Max != null; + valid = valid && c3Min != null && c3Max != null; + valid = valid && sRegion != null; + valid = valid && c1ResolMin != null && c1ResolMax != null; + valid = valid && c2ResolMin != null && c2ResolMax != null; + valid = valid && c3ResolMin != null && c3ResolMax != null; + valid = valid && spatialFrameType != null; + valid = valid && incidenceMin != null && incidenceMax != null; + valid = valid && emergenceMin != null && emergenceMax != null; + valid = valid && phaseMin != null && phaseMax != null; + valid = valid && instrumentHostName != null && instrumentName != null; + valid = valid && measurementType != null && processingLevel != null; + valid = valid && creationDate != null && modificationDate != null; + valid = valid && releaseDate != null && serviceTitle != null; + + return valid; + } + + @Override + public String toString() { + return granuleUid; + } + } 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 new file mode 100644 index 0000000..8a72683 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java @@ -0,0 +1,139 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.granule; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + +import eu.omp.irap.vespa.votable.utils.Debug; +import eu.omp.irap.vespa.votable.votabledata.VOTableData; + +/** + * @author N. Jourdane + */ +public class GranuleCtrl { + + /** The logger for the class GranuleCtrl. */ + private static final Logger logger = Logger.getLogger(GranuleCtrl.class.getName()); + + private VOTableData data; + + + public GranuleCtrl(VOTableData data) { + this.data = data; + } + + private String parseString(int rowId, GranuleEnum granuleEnum) { + return (String) data.getCell(rowId, granuleEnum.toString()); + } + + private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); + return sdf.parse((String) data.getCell(rowId, granuleEnum.toString())); + } + + private Double parseDouble(int rowId, GranuleEnum granuleEnum) { + Double d = (Double) data.getCell(rowId, granuleEnum.toString()); + return d == null ? Double.NaN : d; + } + + public Granule getGranuleFromVOTableRow(int rowId) throws ParseException { + + // TODO: parser colonne par colonne pour éviter de faire des comparer les noms de colone à + // chaque ligne. + Debug.writeObject("data", data); + + //@noformat + Granule g = new Granule(parseString(rowId, GranuleEnum.GRANULE_UID)); + g.granuleGid = parseString(rowId, GranuleEnum.GRANULE_GID); + g.obsId = parseString(rowId, GranuleEnum.OBS_ID); + g.dataproductType = parseString(rowId, GranuleEnum.DATAPRODUCT_TYPE); + g.targetName = parseString(rowId, GranuleEnum.TARGET_NAME); + g.targetClass = parseString(rowId, GranuleEnum.TARGET_CLASS); + g.timeMin = parseDouble(rowId, GranuleEnum.TIME_MIN); + g.timeMax = parseDouble(rowId, GranuleEnum.TIME_MAX); + g.timeSamplingStepMin = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MIN); + g.timeSamplingStepMax = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MAX); + g.timeExpMin = parseDouble(rowId, GranuleEnum.TIME_EXP_MIN); + g.timeExpMax = parseDouble(rowId, GranuleEnum.TIME_EXP_MAX); + g.spectralRangeMin = parseDouble(rowId, GranuleEnum.SPECTRAL_RANGE_MIN); + g.spectralRangeMax = parseDouble(rowId, GranuleEnum.SPECTRAL_RANGE_MAX); + g.timeSamplingStepMin = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MIN); + g.timeSamplingStepMax = parseDouble(rowId, GranuleEnum.TIME_SAMPLING_STEP_MAX); + g.spectralResolutionMin = parseDouble(rowId, GranuleEnum.SPECTRAL_RESOLUTION_MIN); + g.spectralResolutionMax = parseDouble(rowId, GranuleEnum.SPECTRAL_RESOLUTION_MAX); + g.c1Min = parseDouble(rowId, GranuleEnum.C1MIN); + g.c1Max = parseDouble(rowId, GranuleEnum.C1MAX); + g.c2Min = parseDouble(rowId, GranuleEnum.C2MIN); + g.c2Max = parseDouble(rowId, GranuleEnum.C2MAX); + g.c3Min = parseDouble(rowId, GranuleEnum.C3MIN); + g.c3Max = parseDouble(rowId, GranuleEnum.C3MAX); + g.sRegion = parseString(rowId, GranuleEnum.S_REGION); + g.c1ResolMin = parseDouble(rowId, GranuleEnum.C1_RESOL_MIN); + g.c1ResolMax = parseDouble(rowId, GranuleEnum.C1_RESOL_MAX); + g.c2ResolMin = parseDouble(rowId, GranuleEnum.C2_RESOL_MIN); + g.c2ResolMax = parseDouble(rowId, GranuleEnum.C2_RESOL_MAX); + g.c3ResolMin = parseDouble(rowId, GranuleEnum.C3_RESOL_MIN); + g.c3ResolMax = parseDouble(rowId, GranuleEnum.C3_RESOL_MAX); + g.spatialFrameType = parseString(rowId, GranuleEnum.SPATIAL_FRAME_TYPE); + g.incidenceMin = parseDouble(rowId, GranuleEnum.INCIDENCE_MIN); + g.incidenceMax = parseDouble(rowId, GranuleEnum.INCIDENCE_MAX); + g.emergenceMin = parseDouble(rowId, GranuleEnum.EMERGENCE_MIN); + g.emergenceMax = parseDouble(rowId, GranuleEnum.EMERGENCE_MAX); + g.phaseMin = parseDouble(rowId, GranuleEnum.PHASE_MIN); + g.phaseMax = parseDouble(rowId, GranuleEnum.PHASE_MAX); + g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME); + g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME); + g.measurementType = parseString(rowId, GranuleEnum.MEASUREMENT_TYPE); + g.processingLevel = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString()); + g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE); + g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ; + g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ; + g.serviceTitle = parseString(rowId, GranuleEnum.SERVICE_TITLE); + //@format + + if (!g.isValid()) { + System.out.println(data.getCell(rowId, "polar_radius")); + throw new IllegalArgumentException("One or more EPN parameter is null."); + } + return g; + } + + public static boolean isV2(VOTableData data) { + return !data.containsColumn("index"); + } + + public List getGranulesFromVOTable() throws ParseException { + Debug.writeObject("data", data); + + if (!GranuleCtrl.isV2(data)) { + throw new IllegalArgumentException( + "The EPN-CORE is not v2, which is the only suported version"); + } + List granules = new ArrayList<>(); + + for (int rowId = 0; rowId < data.getNbRows(); rowId++) { + granules.add(getGranuleFromVOTableRow(rowId)); + } + return granules; + } + +} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java index 71ea289..1b942d7 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/GUIController.java @@ -25,8 +25,7 @@ import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.EpnTapController; import eu.omp.irap.vespa.epntapclient.service.Queries; -import eu.omp.irap.vespa.votable.VOTableException.CantDisplayVOTableException; -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException; +import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; /** * @author N. Jourdane @@ -50,7 +49,7 @@ public class GUIController extends EpnTapController implements ViewListener { public GUIController() { super(); mainView = new EpnTapMainView(this); - mainView.getServicesPanel().fillTable(servicesCtrl.getColumns(), servicesCtrl.getData()); + mainView.getServicesPanel().fillTable(servicesCtrl.getVOTableData()); } public EpnTapMainView getView() { @@ -70,7 +69,7 @@ public class GUIController extends EpnTapController implements ViewListener { GUIController.logger.info("Sending query: " + query + " on " + selectedTableServiceURL); try { voTablePath = sendQuery(query, selectedTableServiceURL); - } catch (CantDisplayVOTableException | CantSendQueryException e) { + } catch (CantGetVOTableException e) { // TODO create exception mainView.displayError("Can not send query.", e.getMessage()); GUIController.logger.log(Level.WARNING, "Can not send query.", e); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java index ac6bac7..ad35dcc 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/ParamField.java @@ -42,9 +42,8 @@ import javax.swing.event.DocumentListener; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException; +import eu.omp.irap.vespa.votable.utils.CantSendQueryException; import eu.omp.irap.vespa.votable.utils.Network; /** @@ -427,15 +426,15 @@ public abstract class ParamField extends JPanel { * * @param begining The beginning of the target_name. * @return An array of Strings corresponding to the target names got. - * @throws CantSendQueryException If the resolver do not work. + * @throws CantSendQueryException + * @throws CantGetXMLException If the resolver do not work. */ static String[] getItems(String begining) throws CantSendQueryException { Map params = new HashMap<>(); params.put("q", "\"" + begining + "\""); - StringBuilder resolverResult = Network.sendQuery(ParamField.RESOLVER_URL, params); - - JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject(); + String query = Network.buildQuery(ParamField.RESOLVER_URL, params); + JsonObject root = Network.readJson(query); int count = Integer.parseInt(root.get("count").toString()); String[] targetNames = new String[count]; JsonArray hits = root.getAsJsonArray("hits"); 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 7f32685..2fd742c 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 @@ -29,42 +29,45 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; */ public final class Queries { - /** Query to get all EPN-TAP services. */ - public static final String GET_EPN_TAP_SERVICES = "SELECT short_name, " - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url " - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table " - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability " - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND " - + "intf_type='vs:paramhttp' AND " - + "detail_xpath='/capability/dataModel/@ivo-id' AND " - + "1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') " - + "ORDER BY short_name, table_name"; - - /** Query to get all EPN-TAP services. */ - public static final String GET_TAP_OBSCOR_SERVICES = "SELECT short_name, " - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url " - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table " - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability " - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND " - + "intf_type='vs:paramhttp' AND " - + "detail_xpath='/capability/dataModel/@ivo-id' AND " - + "1=ivo_nocasematch(detail_value, 'ivo://ivoa.net/std/ObsCore%') " - + "ORDER BY short_name, table_name"; - - /** Query to get all EPN-TAP services. */ - public static final String GET_TAP_SERVICES = "SELECT short_name, " - + "res_title AS schema_title, table_name, schema_name, ivoid, access_url " - + "FROM rr.resource NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table " - + "NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability " - + "WHERE standard_id='ivo://ivoa.net/std/tap' AND " + private static final String SELECT = "SELECT short_name, res_title AS schema_title, " + + "table_name, schema_name, ivoid, access_url "; + + private static final String FROM = "FROM rr.resource " + + "NATURAL JOIN rr.res_schema " + + "NATURAL JOIN rr.res_table " + + "NATURAL JOIN rr.interface " + + "NATURAL JOIN rr.res_detail " + + "NATURAL JOIN rr.capability "; + + private static final String ORDER_BY = "ORDER BY short_name, table_name"; + + private static final String WHERE_TAP = "WHERE " + + "standard_id='ivo://ivoa.net/std/tap' AND " + "intf_type='vs:paramhttp' AND " - + "detail_xpath='/capability/dataModel/@ivo-id' " - + "ORDER BY short_name, table_name"; + + "detail_xpath='/capability/dataModel/@ivo-id' "; + + //@noformat + + /** Query to get all TAP services. */ + public static final String GET_TAP_SERVICES = + Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY; + + /** Query to get TAP services which implement the specified core. */ + public static final String GET_TAP_SERVICES_WHERE_CORE = + Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') " + + Queries.ORDER_BY; + + /** 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' "; - /** Query to get all VO-resources which implements epn-tap core. */ - public static final String GET_VO_RESOURCES = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search?" - + "keywords=standardid:%22ivo://ivoa.net/std/TAP%22%20datamodel:%22EpnCore%22&max=100"; + public static final String GET_TAP_SERVICES_SELECT_WHERE_IVOID = + "SELECT %s " + Queries.FROM + Queries.WHERE_TAP + + "AND ivoid = '%s' "; + //@format /** Constructor to hide the implicit public one. */ private Queries() { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java index e4dffd0..5fbd04a 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Service.java @@ -23,7 +23,7 @@ public class Service { private String ivoid; - private String resTitle; + private String title; private String shortName; @@ -42,24 +42,6 @@ public class Service { private String updated; - public enum ServiceType { - - OBSCORE("obscore"), EPNCORE("epncore"); - - private String type = ""; - - - ServiceType(String type) { - this.type = type; - } - - @Override - public String toString() { - return type; - } - } - - private Service() { } @@ -68,86 +50,86 @@ public class Service { } public boolean isValid() { - boolean isValid = ivoid != null && resTitle != null && shortName != null; + boolean isValid = ivoid != null && title != null && shortName != null; isValid = isValid && type != null && description != null && creator != null; isValid = isValid && contentLevel != null && referenceURL != null && created != null; return isValid && updated != null; } - public String getIvoid() { - return ivoid; + public String getTitle() { + return title; } - public String getResTitle() { - return resTitle; + public void setTitle(String resTitle) { + title = resTitle; } public String getShortName() { return shortName; } - public String getType() { - return type; - } - - public String getDescription() { - return description; - } - - public String getCreator() { - return creator; - } - - public String getContentLevel() { - return contentLevel; - } - - public String getReferenceURL() { - return referenceURL; - } - - public String getCreated() { - return created; - } - - public String getUpdated() { - return updated; - } - - public void setTitle(String resTitle) { - this.resTitle = resTitle; - } - public void setShortName(String shortName) { this.shortName = shortName; } + public String getType() { + return type; + } + public void setType(String type) { this.type = type; } + public String getDescription() { + return description; + } + public void setDescription(String description) { this.description = description; } + public String getCreator() { + return creator; + } + public void setCreator(String creator) { this.creator = creator; } + public String getContentLevel() { + return contentLevel; + } + public void setContentLevel(String contentLevel) { this.contentLevel = contentLevel; } + public String getReferenceURL() { + return referenceURL; + } + public void setReferenceURL(String referenceURL) { this.referenceURL = referenceURL; } + public String getCreated() { + return created; + } + public void setCreated(String created) { this.created = created; } + public String getUpdated() { + return updated; + } + public void setUpdated(String updated) { this.updated = updated; } + public String getIvoid() { + return ivoid; + } + } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java new file mode 100644 index 0000000..4fdf87d --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCore.java @@ -0,0 +1,36 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.service; + +/** + * @author N. Jourdane + */ +public enum ServiceCore { + OBSCORE("ObsCore"), EPNCORE("EpnCore"); + + private String type; + + + ServiceCore(String type) { + this.type = type; + } + + @Override + public String toString() { + return type; + } +} 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 ae64e67..6199cf2 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 @@ -27,8 +27,11 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel; import eu.omp.irap.vespa.epntapclient.voresource.model.Creator; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.epntapclient.voresource.model.Type; -import eu.omp.irap.vespa.votable.data.VOTableData; +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; /** * @author N. Jourdane @@ -41,8 +44,7 @@ public class ServiceCtrl { public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; - public final Service getServiceFromResource(Service.ServiceType serviceType, - Resource resource) { + public final static Service getServiceFromResource(Resource resource) { Service service = new Service(resource.getIdentifier()); service.setTitle(resource.getTitle()); service.setShortName(resource.getShortName()); @@ -69,13 +71,7 @@ public class ServiceCtrl { return service; } - private static String XMLDateToString(XMLGregorianCalendar date) { - SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT); - return sdf.format(date.toGregorianCalendar().getTime()); - } - - public final List getServiceFromVOTableData(Service.ServiceType serviceType, - VOTableData data) { + public final static List getServicesFromVOTableData(VOTableData data) { List services = new ArrayList<>(); for (int i = 0; i < data.getNbRows(); i++) { Service service = new Service((String) data.getCell(i, "ivoid")); @@ -91,7 +87,20 @@ public class ServiceCtrl { // TODO: Convert date format services.add(service); } - return services; } + + public static Service getServiceFromIvoid(String ivoid) throws CantGetVOTableException { + // TODO: utiliser Resource plutôt que VOTable + String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid); + VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); + ctrl.readTable(); + List services = ServiceCtrl.getServicesFromVOTableData(ctrl.getVOTableData()); + return services.get(0); + } + + 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 c8a8942..598b3a7 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 @@ -14,11 +14,9 @@ * . */ -package eu.omp.irap.vespa.epntapclient.resource; +package eu.omp.irap.vespa.epntapclient.voresource; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -28,19 +26,18 @@ import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.stream.JsonReader; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.CantGetVOResourceException; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.CantReadVOResourceException; -import eu.omp.irap.vespa.epntapclient.resource.VOResourceException.VOResourceIsNotValidException; -import eu.omp.irap.vespa.epntapclient.service.Service.ServiceType; +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.VOResourceIsNotValidException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; -import eu.omp.irap.vespa.votable.VOTableException.CantSendQueryException; +import eu.omp.irap.vespa.votable.utils.CantSendQueryException; import eu.omp.irap.vespa.votable.utils.Network; import eu.omp.irap.vespa.votable.utils.StringJoiner; @@ -52,8 +49,6 @@ public class VOResourceCtrl { /** The logger for the class VOResourceController. */ private static final Logger logger = Logger.getLogger(VOResourceCtrl.class.getName()); - private static final String VORESOURCE_MODEL_PACKAGE = "eu.omp.irap.vespa.epntapclient.voresource.model"; - private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml"; 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 { private static final int MAX_VORESOURCES = 100; - public static List getVOResources(ServiceType type, Map keywords) + public static List getVOResources(ServiceCore type, Map keywords) throws VOResourceException { - return VOResourceCtrl - .getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type, keywords)); + List ivoids = VOResourceCtrl.getIvoidResources(type, keywords); + return VOResourceCtrl.getVOResourcesFromIvoids(ivoids); } - public static List getVOResources(ServiceType type) throws VOResourceException { - return VOResourceCtrl.getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type)); + public static List getVOResources(ServiceCore type) throws VOResourceException { + List ivoids = VOResourceCtrl.getIvoidResources(type); + return VOResourceCtrl.getVOResourcesFromIvoids(ivoids); } - public static List getIvoidResources(ServiceType type) throws VOResourceException { + public static List getIvoidResources(ServiceCore type) throws VOResourceException { return VOResourceCtrl.getIvoidResources(type, new HashMap()); } - public static List getIvoidResources(ServiceType type, Map keywords) - throws VOResourceException { + public static List getIvoidResources(ServiceCore type, Map keywords) + throws CantGetVOResourceException { List ivoidResources; keywords.put("datamodel", type.toString()); @@ -90,14 +86,13 @@ public class VOResourceCtrl { Map parameters = new HashMap(); parameters.put("keywords", keywordJoiner.toString()); parameters.put("max", String.valueOf(VOResourceCtrl.MAX_VORESOURCES)); + String query = Network.buildQuery(GET_IVOID_RESOURCES_URL, parameters); try { - String ivoidResourcesPath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL, - parameters); - ivoidResources = VOResourceCtrl.parseIvoidResources(ivoidResourcesPath); - } catch (CantSendQueryException e1) { - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1); - // TODO: pass the entire request. + ivoidResources = parseIvoidResources(Network.readJson(query)); + } catch (CantSendQueryException e) { + throw new CantGetVOResourceException(GET_VORESOURCE_URL, e); } + logger.info("Got resources: " + StringJoiner.join(ivoidResources)); return ivoidResources; } @@ -105,18 +100,35 @@ public class VOResourceCtrl { Map parameters = new HashMap(); parameters.put("identifier", identifier); String voResourcePath; - try { - voResourcePath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters); - } catch (CantSendQueryException e1) { - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1); - } + + // try { + // VOResourceCtrl.logger.info("Trying to get VOResource '" + identifier + "'..."); + // voResourcePath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters); + // } catch (CantSendQueryException e1) { + // throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1); + // } + // VOResourceCtrl.logger.info("VOResource downloaded in " + voResourcePath); + + voResourcePath = "/home/nathanael/resources/resourceModifJMG.xml"; + + // try { + // AlterXMLFile.renameNode(voResourcePath, "ri:Resource", "Resource"); + // AlterXMLFile.alterAttribute(voResourcePath, "Resource", "xsi:type", "-"); + // } catch (NoSuchElementException | IOException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } Resource voResource; - JAXBContext jc; try { - jc = JAXBContext.newInstance(VOResourceCtrl.VORESOURCE_MODEL_PACKAGE); + File inputStream = new File(voResourcePath); + + Source source = new StreamSource(inputStream); + JAXBContext jc = JAXBContext.newInstance(Resource.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); - voResource = (Resource) unmarshaller.unmarshal(new File(voResourcePath)); + voResource = unmarshaller.unmarshal(source, Resource.class).getValue(); + + // erreur sur : o = unmarshaller.unmarshal(f); } catch (JAXBException e) { throw new VOResourceIsNotValidException(voResourcePath, e); } @@ -133,17 +145,8 @@ public class VOResourceCtrl { return resources; } - private static List parseIvoidResources(String ivoidResourcesPath) - throws CantReadVOResourceException { - JsonReader reader; - try { - reader = new JsonReader(new FileReader(ivoidResourcesPath)); - } catch (FileNotFoundException e) { - throw new CantReadVOResourceException(ivoidResourcesPath, e); - } - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - JsonArray resources = root.get("resources").getAsJsonArray(); - + private static List parseIvoidResources(JsonObject getIvoidsResult) { + JsonArray resources = getIvoidsResult.get("resources").getAsJsonArray(); List ivoidResources = new ArrayList<>(); for (JsonElement e : resources) { ivoidResources.add(e.getAsJsonObject().get("identifier").getAsString()); 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 a65e490..2ea654c 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 @@ -14,7 +14,7 @@ * . */ -package eu.omp.irap.vespa.epntapclient.resource; +package eu.omp.irap.vespa.epntapclient.voresource; /** * @author N. Jourdane -- libgit2 0.21.2