Commit 80e3b8268a696e60adddb3880e302adb20028c22

Authored by Nathanael Jourdane
1 parent 73698991
Exists in master

BugFix: Deal with remote resources instead of local ones.

src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
... ... @@ -17,6 +17,7 @@
17 17 package eu.omp.irap.vespa.epntapclient.voresource;
18 18  
19 19 import java.io.File;
  20 +import java.io.IOException;
20 21 import java.util.ArrayList;
21 22 import java.util.HashMap;
22 23 import java.util.List;
... ... @@ -40,6 +41,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
40 41 import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
41 42 import eu.omp.irap.vespa.votable.utils.Network;
42 43 import eu.omp.irap.vespa.votable.utils.StringJoiner;
  44 +import eu.omp.irap.vespa.votable.utils.XMLUtils;
43 45  
44 46 /**
45 47 * @author N. Jourdane
... ... @@ -55,6 +57,15 @@ public class VOResourceCtrl {
55 57  
56 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 70 public static List<Resource> getVOResources(ServiceCore type, Map<String, String> keywords)
60 71 throws VOResourceException {
... ... @@ -101,23 +112,20 @@ public class VOResourceCtrl {
101 112 parameters.put("identifier", identifier);
102 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 130 Resource voResource;
123 131 try {
... ... @@ -136,6 +144,14 @@ public class VOResourceCtrl {
136 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 155 public static List<Resource> getVOResourcesFromIvoids(List<String> ivoidResources)
140 156 throws VOResourceException {
141 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 19 /**
20 20 * @author N. Jourdane
21 21 */
22   -public abstract class VOResourceException extends Exception {
  22 +public class VOResourceException extends Exception {
23 23  
24 24 /** */
25 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 94 System.out.println("\n*** 4. Services ***\n");
95 95  
96 96 VOTABLE epnServices = facade.getEPNServices();
97   - System.out.println("4.1 getEPNService()\n\t"
  97 + System.out.println("4.1 getEPNServices()\n\t"
98 98 + Debug.toJson(epnServices));
99 99  
100 100 VOTABLE epnServices2 = facade.getEPNServices(attributes);
... ... @@ -123,7 +123,7 @@ public class TestEpnTapFacade {
123 123  
124 124 List<Granule> granules2 = facade.sendQuery(TEST_SERVICE_URL, TEST_SCHEMA_NAME,
125 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 127 + TEST_SCHEMA_NAME + "\", \"" + TEST_ADQL_QUERY + "\")\n\t"
128 128 + Debug.toJson(granules2));
129 129  
... ...