1 |
779bac69
|
Marc NICOLAS
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
package fr.ias.sitools.vo.ssa;
|
20 |
|
|
|
21 |
|
|
import fr.cnes.sitools.dataset.DataSetApplication;
|
22 |
|
|
import fr.cnes.sitools.extensions.common.InputsValidation;
|
23 |
|
|
import fr.cnes.sitools.extensions.common.NotNullAndNotEmptyValidation;
|
24 |
|
|
import fr.cnes.sitools.extensions.common.NumberArrayValidation;
|
25 |
|
|
import fr.cnes.sitools.extensions.common.NumberValidation;
|
26 |
|
|
import fr.cnes.sitools.extensions.common.SpatialGeoValidation;
|
27 |
|
|
import fr.cnes.sitools.extensions.common.StatusValidation;
|
28 |
|
|
import fr.cnes.sitools.extensions.common.Validation;
|
29 |
|
|
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
|
30 |
|
|
import fr.cnes.sitools.util.Util;
|
31 |
|
|
import fr.ias.sitools.validation.vo.TimeValidation;
|
32 |
|
|
import java.util.ArrayList;
|
33 |
|
|
import java.util.Collections;
|
34 |
|
|
import java.util.HashMap;
|
35 |
|
|
import java.util.List;
|
36 |
|
|
import java.util.Map;
|
37 |
|
|
import java.util.Set;
|
38 |
|
|
import java.util.logging.Level;
|
39 |
|
|
import java.util.logging.Logger;
|
40 |
|
|
import net.ivoa.xml.votable.v1.AnyTEXT;
|
41 |
|
|
import net.ivoa.xml.votable.v1.DataType;
|
42 |
|
|
import net.ivoa.xml.votable.v1.Info;
|
43 |
|
|
import net.ivoa.xml.votable.v1.Option;
|
44 |
|
|
import net.ivoa.xml.votable.v1.Param;
|
45 |
|
|
import net.ivoa.xml.votable.v1.Values;
|
46 |
|
|
import org.restlet.Context;
|
47 |
|
|
import org.restlet.Request;
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
public class SimpleSpectralAccessInputParameters implements DataModelInterface {
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
private static final Logger LOG = Logger.getLogger(SimpleSpectralAccessInputParameters.class.getName());
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
private transient double ra = 0.0;
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
private transient double dec = 0.0;
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
private transient double[] size;
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
private transient String[] time;
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
private transient double[] band;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
private transient int verb = 0;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
private final transient Map dataModel = new HashMap();
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
private final transient Request request;
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
private final transient Context context;
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
private final transient DataSetApplication datasetApp;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
private final transient ResourceModel resourceModel;
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
public SimpleSpectralAccessInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal, final ResourceModel resourceModelVal) {
|
113 |
|
|
this.datasetApp = datasetAppVal;
|
114 |
|
|
this.context = contextVal;
|
115 |
|
|
this.request = requestVal;
|
116 |
|
|
this.resourceModel = resourceModelVal;
|
117 |
|
|
final String posInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.POS);
|
118 |
|
|
final String sizeInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.SIZE);
|
119 |
|
|
final String format = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.FORMAT);
|
120 |
|
|
final String intersect = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.INTERSECT);
|
121 |
|
|
final String verbosity = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.VERB);
|
122 |
|
|
final String timeInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.TIME);
|
123 |
|
|
final String bandInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleSpectralAccessProtocolLibrary.BAND);
|
124 |
|
|
|
125 |
|
|
if(posInput == null && sizeInput == null){
|
126 |
|
|
final Info info = new Info();
|
127 |
|
|
final List<Info> listInfos = new ArrayList<Info>();
|
128 |
|
|
info.setName("QUERY_STATUS");
|
129 |
|
|
info.setValueAttribute("ERROR");
|
130 |
|
|
listInfos.add(info);
|
131 |
|
|
this.dataModel.put("infos", listInfos);
|
132 |
|
|
}else{
|
133 |
|
|
if (Util.isSet(format) && format.equals(SimpleSpectralAccessProtocolLibrary.ParamStandardFormat.METADATA.name())) {
|
134 |
|
|
fillMetadataFormat();
|
135 |
|
|
} else {
|
136 |
|
|
checkInputParameters(posInput, sizeInput, timeInput, bandInput);
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
private void fillMetadataFormat() {
|
145 |
|
|
|
146 |
|
|
this.dataModel.put("description", this.resourceModel.getParameterByName(SimpleSpectralAccessProtocolLibrary.DESCRIPTION).getValue());
|
147 |
|
|
|
148 |
|
|
final List<Info> listInfos = new ArrayList<Info>();
|
149 |
|
|
Info info = new Info();
|
150 |
|
|
info.setName("QUERY_STATUS");
|
151 |
|
|
info.setValueAttribute("OK");
|
152 |
|
|
info = new Info();
|
153 |
|
|
listInfos.add(info);
|
154 |
|
|
info.setName("SERVICE_PROTOCOL");
|
155 |
|
|
info.setValue("1.1");
|
156 |
|
|
info.setValueAttribute("SSAP");
|
157 |
|
|
listInfos.add(info);
|
158 |
|
|
|
159 |
|
|
this.dataModel.put("infos", listInfos);
|
160 |
|
|
|
161 |
|
|
final List<Param> listParam = new ArrayList<Param>();
|
162 |
|
|
Param param = new Param();
|
163 |
|
|
param.setName("INPUT:POS");
|
164 |
|
|
param.setValue("0,0");
|
165 |
|
|
param.setDatatype(DataType.DOUBLE);
|
166 |
|
|
AnyTEXT anyText = new AnyTEXT();
|
167 |
|
|
anyText.getContent().add("Search Position in the form ra,dec where ra and dec are given in decimal degrees in the ICRS coordinate system.");
|
168 |
|
|
param.setDESCRIPTION(anyText);
|
169 |
|
|
listParam.add(param);
|
170 |
|
|
|
171 |
|
|
param = new Param();
|
172 |
|
|
param.setName("INPUT:SIZE");
|
173 |
|
|
param.setValue("0.05");
|
174 |
|
|
param.setDatatype(DataType.DOUBLE);
|
175 |
|
|
anyText = new AnyTEXT();
|
176 |
|
|
anyText.getContent().add("Size of search region in the RA and Dec directions.");
|
177 |
|
|
param.setDESCRIPTION(anyText);
|
178 |
|
|
listParam.add(param);
|
179 |
|
|
|
180 |
|
|
param = new Param();
|
181 |
|
|
param.setName("INPUT:FORMAT");
|
182 |
|
|
param.setValue(SimpleSpectralAccessProtocolLibrary.ParamStandardFormat.ALL.name());
|
183 |
|
|
param.setDatatype(DataType.CHAR);
|
184 |
|
|
param.setArraysize("*");
|
185 |
|
|
anyText = new AnyTEXT();
|
186 |
|
|
anyText.getContent().add("Requested format of images.");
|
187 |
|
|
param.setDESCRIPTION(anyText);
|
188 |
|
|
final List<String> formatList = SimpleSpectralAccessProtocolLibrary.ParamStandardFormat.getCtes();
|
189 |
|
|
final Values values = new Values();
|
190 |
|
|
for (String formatIter : formatList) {
|
191 |
|
|
final Option option = new Option();
|
192 |
|
|
option.setValue(formatIter);
|
193 |
|
|
values.getOPTION().add(option);
|
194 |
|
|
}
|
195 |
|
|
param.setVALUES(values);
|
196 |
|
|
|
197 |
|
|
listParam.add(param);
|
198 |
|
|
|
199 |
|
|
param = new Param();
|
200 |
|
|
param.setName("INPUT:INTERSECT");
|
201 |
|
|
param.setValue(this.resourceModel.getParameterByName(SimpleSpectralAccessProtocolLibrary.INTERSECT).getValue());
|
202 |
|
|
param.setDatatype(DataType.CHAR);
|
203 |
|
|
anyText = new AnyTEXT();
|
204 |
|
|
anyText.getContent().add("Choice of overlap with requested region.");
|
205 |
|
|
param.setDESCRIPTION(anyText);
|
206 |
|
|
listParam.add(param);
|
207 |
|
|
|
208 |
|
|
param = new Param();
|
209 |
|
|
param.setName("INPUT:VERB");
|
210 |
|
|
param.setValue(this.resourceModel.getParameterByName(SimpleSpectralAccessProtocolLibrary.VERB).getValue());
|
211 |
|
|
param.setDatatype(DataType.INT);
|
212 |
|
|
anyText = new AnyTEXT();
|
213 |
|
|
anyText.getContent().add("Verbosity level, controlling the number of columns returned.");
|
214 |
|
|
param.setDESCRIPTION(anyText);
|
215 |
|
|
listParam.add(param);
|
216 |
|
|
|
217 |
|
|
dataModel.put("params", listParam);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
private void checkInputParameters(final String posInput, final String sizeInput, final String timeInput, final String bandInput) {
|
226 |
|
|
final List<Info> infos = new ArrayList<Info>();
|
227 |
|
|
final Map<String, String> validationMap = new HashMap<String, String>();
|
228 |
|
|
validationMap.put(SimpleSpectralAccessProtocolLibrary.POS, posInput);
|
229 |
|
|
validationMap.put(SimpleSpectralAccessProtocolLibrary.SIZE, sizeInput);
|
230 |
|
|
validationMap.put(SimpleSpectralAccessProtocolLibrary.TIME, timeInput);
|
231 |
|
|
validationMap.put(SimpleSpectralAccessProtocolLibrary.BAND, bandInput);
|
232 |
|
|
Validation validation = new InputsValidation(validationMap);
|
233 |
|
|
validation = new NotNullAndNotEmptyValidation(validation, SimpleSpectralAccessProtocolLibrary.POS);
|
234 |
|
|
validation = new NotNullAndNotEmptyValidation(validation, SimpleSpectralAccessProtocolLibrary.SIZE);
|
235 |
|
|
|
236 |
|
|
if(timeInput!= null){
|
237 |
|
|
validation = new TimeValidation(validation, SimpleSpectralAccessProtocolLibrary.TIME, timeInput);
|
238 |
|
|
}
|
239 |
|
|
if(bandInput != null){
|
240 |
|
|
validation = new NumberArrayValidation(validation, SimpleSpectralAccessProtocolLibrary.BAND, ",");
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
if(validation.validate().isValid()){
|
244 |
|
|
validation = new SpatialGeoValidation(validation, SimpleSpectralAccessProtocolLibrary.POS, 0, 1, new double[]{0.0, 360.0}, new double[]{-90.0, 90.0});
|
245 |
|
|
|
246 |
|
|
validation = new NumberValidation(validation, SimpleSpectralAccessProtocolLibrary.SIZE, true);
|
247 |
|
|
|
248 |
|
|
}
|
249 |
|
|
StatusValidation status = validation.validate();
|
250 |
|
|
if (status.isValid()) {
|
251 |
|
|
final String pos = validation.getMap().get(SimpleSpectralAccessProtocolLibrary.POS);
|
252 |
|
|
final String[] arrayPos = pos.split(",");
|
253 |
|
|
|
254 |
|
|
this.ra = Double.valueOf(arrayPos[0]);
|
255 |
|
|
this.dec = Double.valueOf(arrayPos[1]);
|
256 |
|
|
|
257 |
|
|
final String size = validation.getMap().get(SimpleSpectralAccessProtocolLibrary.SIZE);
|
258 |
|
|
final String[] arraySize = size.split(",");
|
259 |
|
|
if(arraySize.length == 1) {
|
260 |
|
|
this.size = new double[1];
|
261 |
|
|
this.size[0] = Double.valueOf(arraySize[0]);
|
262 |
|
|
} else {
|
263 |
|
|
this.size = new double[2];
|
264 |
|
|
this.size[0] = Double.valueOf(arraySize[0]);
|
265 |
|
|
this.size[1] = Double.valueOf(arraySize[1]);
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
if(timeInput!= null){
|
269 |
|
|
final String time = timeInput;
|
270 |
|
|
|
271 |
|
|
final String[] arrayTime = time.split(",");
|
272 |
|
|
if(arrayTime.length == 1) {
|
273 |
|
|
this.time = new String[1];
|
274 |
|
|
this.time[0] = arrayTime[0];
|
275 |
|
|
} else {
|
276 |
|
|
this.time = new String[2];
|
277 |
|
|
this.time[0] = arrayTime[0];
|
278 |
|
|
this.time[1] = arrayTime[1];
|
279 |
|
|
}
|
280 |
|
|
}
|
281 |
|
|
if(bandInput!= null){
|
282 |
|
|
final String band = bandInput;
|
283 |
|
|
final String[] arrayBand = band.split(",");
|
284 |
|
|
if(arrayBand.length == 1) {
|
285 |
|
|
this.band = new double[1];
|
286 |
|
|
this.band[0] = Double.valueOf(arrayBand[0]);
|
287 |
|
|
} else {
|
288 |
|
|
this.band = new double[2];
|
289 |
|
|
this.band[0] = Double.valueOf(arrayBand[0]);
|
290 |
|
|
this.band[1] = Double.valueOf(arrayBand[1]);
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
} else {
|
296 |
|
|
Info info = new Info();
|
297 |
|
|
info.setName("QUERY_STATUS");
|
298 |
|
|
info.setValueAttribute("ERROR");
|
299 |
|
|
infos.add(info);
|
300 |
|
|
final Map<String, String> errors = status.getMessages();
|
301 |
|
|
final Set<Map.Entry<String, String>> entries = errors.entrySet();
|
302 |
|
|
for (Map.Entry<String, String> entry : entries) {
|
303 |
|
|
info = new Info();
|
304 |
|
|
info.setID(entry.getKey());
|
305 |
|
|
info.setName("Error in " + entry.getKey());
|
306 |
|
|
info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
|
307 |
|
|
infos.add(info);
|
308 |
|
|
LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
if (!infos.isEmpty()) {
|
314 |
|
|
this.dataModel.put("infos", infos);
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
|
|
|
318 |
|
|
@Override
|
319 |
|
|
public final Map getDataModel() {
|
320 |
|
|
return Collections.unmodifiableMap(this.dataModel);
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
public final double getRa() {
|
329 |
|
|
return this.ra;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
public final double getDec() {
|
338 |
|
|
return this.dec;
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
public final double[] getSize() {
|
347 |
|
|
final double[] copySize = new double[this.size.length];
|
348 |
|
|
System.arraycopy(this.size, 0, copySize, 0, this.size.length);
|
349 |
|
|
return copySize;
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
public final Request getRequest() {
|
358 |
|
|
return this.request;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
public final Context getContext() {
|
367 |
|
|
return this.context;
|
368 |
|
|
}
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
public final DataSetApplication getDatasetApplication() {
|
376 |
|
|
return this.datasetApp;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
public final int getVerb() {
|
384 |
|
|
return this.verb;
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
public final String[] getTime() {
|
388 |
|
|
final String[] copyTime = new String[this.time.length];
|
389 |
|
|
System.arraycopy(this.time, 0, copyTime, 0,this.time.length);
|
390 |
|
|
return copyTime;
|
391 |
|
|
}
|
392 |
|
|
public final double[] getBand() {
|
393 |
|
|
final double[] copyBand = new double[this.band.length];
|
394 |
|
|
System.arraycopy(this.band, 0, copyBand, 0, this.band.length);
|
395 |
|
|
return copyBand;
|
396 |
|
|
}
|
397 |
|
|
} |