Commit 94e1b3b56d68214e390711785b048e58f6a3e1fb

Authored by Nathanael Jourdane
1 parent 4bcbd19f
Exists in master

VOResouceCtrl now need a service type.

src/main/java/eu/omp/irap/vespa/epntapclient/lib/resource/VOResourceCtrl.java
@@ -38,10 +38,11 @@ import com.google.gson.stream.JsonReader; @@ -38,10 +38,11 @@ import com.google.gson.stream.JsonReader;
38 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.CantGetVOResourceException; 38 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.CantGetVOResourceException;
39 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.CantReadVOResourceException; 39 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.CantReadVOResourceException;
40 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.VOResourceIsNotValidException; 40 import eu.omp.irap.vespa.epntapclient.lib.resource.VOResourceException.VOResourceIsNotValidException;
  41 +import eu.omp.irap.vespa.epntapclient.service.Service.ServiceType;
41 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; 42 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
42 -import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantSendQueryException; 43 +import eu.omp.irap.vespa.epntapclient.votable.VOTableException.CantSendQueryException;
43 import eu.omp.irap.vespa.epntapclient.votable.utils.Network; 44 import eu.omp.irap.vespa.epntapclient.votable.utils.Network;
44 -import eu.omp.irap.vespa.epntapclient.votable.utils.Strings.StringJoiner; 45 +import eu.omp.irap.vespa.epntapclient.votable.utils.StringJoiner;
45 46
46 /** 47 /**
47 * @author N. Jourdane 48 * @author N. Jourdane
@@ -59,18 +60,45 @@ public class VOResourceCtrl { @@ -59,18 +60,45 @@ public class VOResourceCtrl {
59 60
60 private static final int MAX_VORESOURCES = 100; 61 private static final int MAX_VORESOURCES = 100;
61 62
62 - private static final String VORESOURCES_STANDARDID = "ivo://ivoa.net/std/TAP";  
63 63
64 - private static final String VORESOURCES_DATAMODEL = "EpnCore"; 64 + public static List<Resource> getVOResources(ServiceType type, Map<String, String> keywords)
  65 + throws VOResourceException {
  66 + return VOResourceCtrl
  67 + .getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type, keywords));
  68 + }
65 69
  70 + public static List<Resource> getVOResources(ServiceType type) throws VOResourceException {
  71 + return VOResourceCtrl.getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(type));
  72 + }
66 73
67 - public static List<Resource> getVOResources(Map<String, String> keywords)  
68 - throws VOResourceException {  
69 - return VOResourceCtrl.getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources(keywords)); 74 + public static List<String> getIvoidResources(ServiceType type) throws VOResourceException {
  75 + return VOResourceCtrl.getIvoidResources(type, new HashMap());
70 } 76 }
71 77
72 - public static List<Resource> getVOResources() throws VOResourceException {  
73 - return VOResourceCtrl.getVOResourcesFromIvoids(VOResourceCtrl.getIvoidResources()); 78 + public static List<String> getIvoidResources(ServiceType type, Map<String, String> keywords)
  79 + throws VOResourceException {
  80 + List<String> ivoidResources;
  81 +
  82 + keywords.put("datamodel", type.toString());
  83 + // standardid="ivo://ivoa.net/std/TAP" is not necessary
  84 +
  85 + StringJoiner keywordJoiner = new StringJoiner(" ");
  86 + for (Map.Entry<String, String> keyword : keywords.entrySet()) {
  87 + keywordJoiner.add(keyword.getKey() + ":\"" + keyword.getValue() + "\"");
  88 + }
  89 +
  90 + Map<String, String> parameters = new HashMap();
  91 + parameters.put("keywords", keywordJoiner.toString());
  92 + parameters.put("max", String.valueOf(VOResourceCtrl.MAX_VORESOURCES));
  93 + 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.
  100 + }
  101 + return ivoidResources;
74 } 102 }
75 103
76 public static Resource getVOresource(String identifier) throws VOResourceException { 104 public static Resource getVOresource(String identifier) throws VOResourceException {
@@ -105,36 +133,6 @@ public class VOResourceCtrl { @@ -105,36 +133,6 @@ public class VOResourceCtrl {
105 return resources; 133 return resources;
106 } 134 }
107 135
108 - public static List<String> getIvoidResources() throws VOResourceException {  
109 - return VOResourceCtrl.getIvoidResources(new HashMap());  
110 - }  
111 -  
112 - public static List<String> getIvoidResources(Map<String, String> keywords)  
113 - throws VOResourceException {  
114 - List<String> ivoidResources;  
115 -  
116 - keywords.put("standardid", VOResourceCtrl.VORESOURCES_STANDARDID);  
117 - keywords.put("datamodel", VOResourceCtrl.VORESOURCES_DATAMODEL);  
118 -  
119 - StringJoiner keywordJoiner = new StringJoiner(" ");  
120 - for (Map.Entry<String, String> keyword : keywords.entrySet()) {  
121 - keywordJoiner.add(keyword.getKey() + ":\"" + keyword.getValue() + "\"");  
122 - }  
123 -  
124 - Map<String, String> parameters = new HashMap();  
125 - parameters.put("keywords", keywordJoiner.toString());  
126 - parameters.put("max", String.valueOf(VOResourceCtrl.MAX_VORESOURCES));  
127 - try {  
128 - String ivoidResourcesPath = Network.saveQuery(VOResourceCtrl.GET_VORESOURCE_URL,  
129 - parameters);  
130 - ivoidResources = VOResourceCtrl.parseIvoidResources(ivoidResourcesPath);  
131 - } catch (CantSendQueryException e1) {  
132 - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e1);  
133 - // TODO: pass the entire request.  
134 - }  
135 - return ivoidResources;  
136 - }  
137 -  
138 private static List<String> parseIvoidResources(String ivoidResourcesPath) 136 private static List<String> parseIvoidResources(String ivoidResourcesPath)
139 throws CantReadVOResourceException { 137 throws CantReadVOResourceException {
140 JsonReader reader; 138 JsonReader reader;