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 598b3a7..5b4482c 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 @@ -17,6 +17,7 @@ package eu.omp.irap.vespa.epntapclient.voresource; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -40,6 +41,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.votable.utils.CantSendQueryException; import eu.omp.irap.vespa.votable.utils.Network; import eu.omp.irap.vespa.votable.utils.StringJoiner; +import eu.omp.irap.vespa.votable.utils.XMLUtils; /** * @author N. Jourdane @@ -55,6 +57,15 @@ public class VOResourceCtrl { private static final int MAX_VORESOURCES = 100; + private static final String SCHEMA_LOCATION = "http://www.ivoa.net/xml/RegistryInterface/v1.0 " + + "http://www.ivoa.net/xml/RegistryInterface/v1.0 " + + "http://www.ivoa.net/xml/VODataService/v1.1 " + + "http://www.ivoa.net/xml/TAPRegExt/v1.0"; + + private static final String NAMESPACE_VS = "http://www.ivoa.net/xml/TAPRegExt/v1.0"; + + private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; + public static List getVOResources(ServiceCore type, Map keywords) throws VOResourceException { @@ -101,23 +112,20 @@ public class VOResourceCtrl { parameters.put("identifier", identifier); String voResourcePath; - // 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 { + VOResourceCtrl.logger.info("Trying to get VOResource '" + identifier + "'..."); + String query = Network.buildQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters); + voResourcePath = Network.saveQuery(query); + } catch (CantSendQueryException e) { + throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e); + } + VOResourceCtrl.logger.info("VOResource downloaded in " + voResourcePath); - // try { - // AlterXMLFile.renameNode(voResourcePath, "ri:Resource", "Resource"); - // AlterXMLFile.alterAttribute(voResourcePath, "Resource", "xsi:type", "-"); - // } catch (NoSuchElementException | IOException e1) { - // // TODO Auto-generated catch block - // e1.printStackTrace(); - // } + try { + changeNamespaces(voResourcePath); + } catch (IOException e) { + throw new VOResourceException("The VOResource file can not be modified.", e); + } Resource voResource; try { @@ -136,6 +144,14 @@ public class VOResourceCtrl { return voResource; } + private static void changeNamespaces(String voResourcePath) throws IOException { + Map attributes = new HashMap<>(); + attributes.put("xsi:schemaLocation", SCHEMA_LOCATION); + attributes.put("xmlns:vs", NAMESPACE_VS); + attributes.put("xmlns:tr", NAMESPACE_TR); + XMLUtils.changeRootAttributes(voResourcePath, attributes); + } + public static List getVOResourcesFromIvoids(List ivoidResources) throws VOResourceException { List resources = new ArrayList<>(); 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 2ea654c..657a629 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 @@ -19,7 +19,7 @@ package eu.omp.irap.vespa.epntapclient.voresource; /** * @author N. Jourdane */ -public abstract class VOResourceException extends Exception { +public class VOResourceException extends Exception { /** */ private static final long serialVersionUID = 1L; diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java b/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java index 2f037a9..c3d32ec 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java @@ -94,7 +94,7 @@ public class TestEpnTapFacade { System.out.println("\n*** 4. Services ***\n"); VOTABLE epnServices = facade.getEPNServices(); - System.out.println("4.1 getEPNService()\n\t" + System.out.println("4.1 getEPNServices()\n\t" + Debug.toJson(epnServices)); VOTABLE epnServices2 = facade.getEPNServices(attributes); @@ -123,7 +123,7 @@ public class TestEpnTapFacade { List granules2 = facade.sendQuery(TEST_SERVICE_URL, TEST_SCHEMA_NAME, TEST_ADQL_QUERY); - System.out.println("6.2 sendADQLQuery(\"" + TEST_SERVICE_URL + "\", \"" + System.out.println("6.2 sendQuery(\"" + TEST_SERVICE_URL + "\", \"" + TEST_SCHEMA_NAME + "\", \"" + TEST_ADQL_QUERY + "\")\n\t" + Debug.toJson(granules2)); -- libgit2 0.21.2