Commit 80e3b8268a696e60adddb3880e302adb20028c22
1 parent
73698991
Exists in
master
BugFix: Deal with remote resources instead of local ones.
Showing
3 changed files
with
35 additions
and
19 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
@@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
17 | package eu.omp.irap.vespa.epntapclient.voresource; | 17 | package eu.omp.irap.vespa.epntapclient.voresource; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | +import java.io.IOException; | ||
20 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
21 | import java.util.HashMap; | 22 | import java.util.HashMap; |
22 | import java.util.List; | 23 | import java.util.List; |
@@ -40,6 +41,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; | @@ -40,6 +41,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; | ||
40 | import eu.omp.irap.vespa.votable.utils.CantSendQueryException; | 41 | import eu.omp.irap.vespa.votable.utils.CantSendQueryException; |
41 | import eu.omp.irap.vespa.votable.utils.Network; | 42 | import eu.omp.irap.vespa.votable.utils.Network; |
42 | import eu.omp.irap.vespa.votable.utils.StringJoiner; | 43 | import eu.omp.irap.vespa.votable.utils.StringJoiner; |
44 | +import eu.omp.irap.vespa.votable.utils.XMLUtils; | ||
43 | 45 | ||
44 | /** | 46 | /** |
45 | * @author N. Jourdane | 47 | * @author N. Jourdane |
@@ -55,6 +57,15 @@ public class VOResourceCtrl { | @@ -55,6 +57,15 @@ public class VOResourceCtrl { | ||
55 | 57 | ||
56 | private static final int MAX_VORESOURCES = 100; | 58 | private static final int MAX_VORESOURCES = 100; |
57 | 59 | ||
60 | + private static final String SCHEMA_LOCATION = "http://www.ivoa.net/xml/RegistryInterface/v1.0 " | ||
61 | + + "http://www.ivoa.net/xml/RegistryInterface/v1.0 " | ||
62 | + + "http://www.ivoa.net/xml/VODataService/v1.1 " | ||
63 | + + "http://www.ivoa.net/xml/TAPRegExt/v1.0"; | ||
64 | + | ||
65 | + private static final String NAMESPACE_VS = "http://www.ivoa.net/xml/TAPRegExt/v1.0"; | ||
66 | + | ||
67 | + private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; | ||
68 | + | ||
58 | 69 | ||
59 | public static List<Resource> getVOResources(ServiceCore type, Map<String, String> keywords) | 70 | public static List<Resource> getVOResources(ServiceCore type, Map<String, String> keywords) |
60 | throws VOResourceException { | 71 | throws VOResourceException { |
@@ -101,23 +112,20 @@ public class VOResourceCtrl { | @@ -101,23 +112,20 @@ public class VOResourceCtrl { | ||
101 | parameters.put("identifier", identifier); | 112 | parameters.put("identifier", identifier); |
102 | String voResourcePath; | 113 | String voResourcePath; |
103 | 114 | ||
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"; | 115 | + try { |
116 | + VOResourceCtrl.logger.info("Trying to get VOResource '" + identifier + "'..."); | ||
117 | + String query = Network.buildQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters); | ||
118 | + voResourcePath = Network.saveQuery(query); | ||
119 | + } catch (CantSendQueryException e) { | ||
120 | + throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e); | ||
121 | + } | ||
122 | + VOResourceCtrl.logger.info("VOResource downloaded in " + voResourcePath); | ||
113 | 123 | ||
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 | - // } | 124 | + try { |
125 | + changeNamespaces(voResourcePath); | ||
126 | + } catch (IOException e) { | ||
127 | + throw new VOResourceException("The VOResource file can not be modified.", e); | ||
128 | + } | ||
121 | 129 | ||
122 | Resource voResource; | 130 | Resource voResource; |
123 | try { | 131 | try { |
@@ -136,6 +144,14 @@ public class VOResourceCtrl { | @@ -136,6 +144,14 @@ public class VOResourceCtrl { | ||
136 | return voResource; | 144 | return voResource; |
137 | } | 145 | } |
138 | 146 | ||
147 | + private static void changeNamespaces(String voResourcePath) throws IOException { | ||
148 | + Map<String, String> attributes = new HashMap<>(); | ||
149 | + attributes.put("xsi:schemaLocation", SCHEMA_LOCATION); | ||
150 | + attributes.put("xmlns:vs", NAMESPACE_VS); | ||
151 | + attributes.put("xmlns:tr", NAMESPACE_TR); | ||
152 | + XMLUtils.changeRootAttributes(voResourcePath, attributes); | ||
153 | + } | ||
154 | + | ||
139 | public static List<Resource> getVOResourcesFromIvoids(List<String> ivoidResources) | 155 | public static List<Resource> getVOResourcesFromIvoids(List<String> ivoidResources) |
140 | throws VOResourceException { | 156 | throws VOResourceException { |
141 | List<Resource> resources = new ArrayList<>(); | 157 | List<Resource> resources = new ArrayList<>(); |
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceException.java
@@ -19,7 +19,7 @@ package eu.omp.irap.vespa.epntapclient.voresource; | @@ -19,7 +19,7 @@ package eu.omp.irap.vespa.epntapclient.voresource; | ||
19 | /** | 19 | /** |
20 | * @author N. Jourdane | 20 | * @author N. Jourdane |
21 | */ | 21 | */ |
22 | -public abstract class VOResourceException extends Exception { | 22 | +public class VOResourceException extends Exception { |
23 | 23 | ||
24 | /** */ | 24 | /** */ |
25 | private static final long serialVersionUID = 1L; | 25 | private static final long serialVersionUID = 1L; |
src/test/java/eu/omp/irap/vespa/epntapclient/TestEpnTapFacade.java
@@ -94,7 +94,7 @@ public class TestEpnTapFacade { | @@ -94,7 +94,7 @@ public class TestEpnTapFacade { | ||
94 | System.out.println("\n*** 4. Services ***\n"); | 94 | System.out.println("\n*** 4. Services ***\n"); |
95 | 95 | ||
96 | VOTABLE epnServices = facade.getEPNServices(); | 96 | VOTABLE epnServices = facade.getEPNServices(); |
97 | - System.out.println("4.1 getEPNService()\n\t" | 97 | + System.out.println("4.1 getEPNServices()\n\t" |
98 | + Debug.toJson(epnServices)); | 98 | + Debug.toJson(epnServices)); |
99 | 99 | ||
100 | VOTABLE epnServices2 = facade.getEPNServices(attributes); | 100 | VOTABLE epnServices2 = facade.getEPNServices(attributes); |
@@ -123,7 +123,7 @@ public class TestEpnTapFacade { | @@ -123,7 +123,7 @@ public class TestEpnTapFacade { | ||
123 | 123 | ||
124 | List<Granule> granules2 = facade.sendQuery(TEST_SERVICE_URL, TEST_SCHEMA_NAME, | 124 | List<Granule> granules2 = facade.sendQuery(TEST_SERVICE_URL, TEST_SCHEMA_NAME, |
125 | TEST_ADQL_QUERY); | 125 | TEST_ADQL_QUERY); |
126 | - System.out.println("6.2 sendADQLQuery(\"" + TEST_SERVICE_URL + "\", \"" | 126 | + System.out.println("6.2 sendQuery(\"" + TEST_SERVICE_URL + "\", \"" |
127 | + TEST_SCHEMA_NAME + "\", \"" + TEST_ADQL_QUERY + "\")\n\t" | 127 | + TEST_SCHEMA_NAME + "\", \"" + TEST_ADQL_QUERY + "\")\n\t" |
128 | + Debug.toJson(granules2)); | 128 | + Debug.toJson(granules2)); |
129 | 129 |