Project

General

Profile

Download (19.8 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / sitools-idoc / hesiod / javaExt / src / fr / ias / sitools / vo / ssa / SimpleSpectralAccessProtocolLibrary.java @ 779bac69

1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.ias.sitools.vo.ssa;
20

    
21
import fr.cnes.sitools.astro.representation.VOTableRepresentation;
22
import fr.cnes.sitools.dataset.DataSetApplication;
23
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
24
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.Collections;
27
import java.util.List;
28
import java.util.Map;
29
import java.util.logging.Level;
30
import java.util.logging.Logger;
31
import net.ivoa.xml.votable.v1.DataType;
32
import org.restlet.Context;
33
import org.restlet.Request;
34

    
35
/**
36
 *
37
 * @author malapert
38
 */
39
public class SimpleSpectralAccessProtocolLibrary {
40

    
41
  /**
42
   * Logger.
43
   */
44
  private static final Logger LOG = Logger.getLogger(SimpleSpectralAccessProtocolLibrary.class.getName());
45

    
46
  /**
47
   *
48
   */
49
  public static final String DICTIONARY = "PARAM_Dictionary";
50
  /**
51
   *
52
   */
53
  public static final String INTERSECT = "INTERSECT";
54
  /**
55
   *
56
   */
57
  public static final String POS = "POS";
58
  /**
59
   *
60
   */
61
  public static final String VERB = "VERB";
62
  /**
63
   *
64
   */
65
  public static final String SIZE = "SIZE";
66
  /**
67
   *
68
   */
69
  public static final String FORMAT = "FORMAT";
70
  /**
71
   *
72
   */
73
  public static final String RA_COL = "COLUMN_RA";
74
  /**
75
   *
76
   */
77
  public static final String DEC_COL = "COLUMN_DEC";
78
  /**
79
   *
80
   */
81
  public static final List REQUIRED_UCD_CONCEPTS = Arrays.asList("VOX:Image_Title",
82
                                                    "POS_EQ_RA_MAIN",
83
                                                    "POS_EQ_DEC_MAIN",
84
                                                    /*"VOX:Image_Naxes",
85
                                                    "VOX:Image_Naxis",
86
                                                    "VOX:Image_Scale",
87
                                                    "VOX:Image_Format",*/
88
                                                    "VOX:Image_AccessReference",
89
                                                    "TIME_MAIN",
90
                                                    "BAND_MAIN");
91
  /**
92
   *
93
   */
94
  public static final String RESPONSIBLE_PARTY = "Responsible party";
95
  /**
96
   *
97
   */
98
  public static final String SERVICE_NAME = "Image service";
99
  /**
100
   *
101
   */
102
  public static final String DESCRIPTION = "Description";
103
  /**
104
   *
105
   */
106
  public static final String INSTRUMENT = "Instrument";
107
  /**
108
   *
109
   */
110
  public static final String WAVEBAND = "Waveband Coverage";
111
  /**
112
   *
113
   */
114
  public static final String COVERAGE = "Spatial Coverage";
115
  /**
116
   *
117
   */
118
  public static final String TEMPORAL = "Temporal Coverage";
119
  /**
120
   *
121
   */
122
  public static final String MAX_QUERY_SIZE = "Max query size";
123
  /**
124
   *
125
   */
126
  public static final String MAX_IMAGE_SIZE = "Max image size";
127
  /**
128
   *
129
   */
130
  public static final String MAX_FILE_SIZE = "Max file size";
131
  /**
132
   *
133
   */
134
  public static final String MAX_RECORDS = "Max records";
135
  /**
136
   * spoly column from pgsphere.
137
   */
138
  
139
  // ********************************************   RAJOUTER POUR SSAP   ***********************************
140
  public static final String SERVICE_PROTOCOL = "SERVICE PROTOCOL";
141
  
142
  public static final String TIME = "TIME";
143
  
144
  public static final String BAND = "BAND";
145
  
146
  
147
  //--------------------------------------------------------------------------------------------------------
148
  public static final String GEO_ATTRIBUT = "geoAttribut";
149
  private transient DataSetApplication datasetApp;
150
  private transient ResourceModel resourceModel;
151
  private transient Request request;
152
  private transient Context context;
153

    
154
  /**
155
   * Maximum value of the declination axis.
156
   */
157
  public static final double MAX_VALUE_FOR_DECLINATION = 90.0;
158
  /**
159
   * Minimum value of the declination axis.
160
   */  
161
  public static final double MIN_VALUE_FOR_DECLINATION = -90.0;
162
  /**
163
   * Maximum value of the right ascension axis.
164
   */  
165
  public static final double MAX_VALUE_FOR_RIGHT_ASCENSION = 360.0;
166
  /**
167
   * Minimum value of the right ascension axis.
168
   */  
169
  public static final double MIN_VALUE_FOR_RIGHT_ASCENSION = 0.0;
170
  /**
171
   *
172
   */
173
  public enum Intersect {
174

    
175
    /**
176
     *
177
     */
178
    COVERS, /* The candidate image covers or includes the entire ROI */
179
    /**
180
     *
181
     */
182
    ENCLOSED, /* The candidate image is entirely enclosed by the ROI */
183
    /**
184
     *
185
     */
186
    CENTER, /* The candidate image overlaps the center of the ROI */
187
    /**
188
     *
189
     */
190
    OVERLAPS /* The candidate image overlaps some part of the ROI */
191

    
192
  };
193

    
194
  /**
195
   *
196
   */
197
  public enum SpectrumService {
198

    
199
    /**
200
     *
201
     */
202
    POINTED_SPECTRAL_ARCHIVE("Spectral Archive Service"),
203
    SPECTRAL_CUTOUT_SERVICE("Spectral Cutout Service"),
204
    SPECTRAL_MOSAICING_SERVICE("Spectral Mosaicing Service"),
205
    SPECTRAL_EXTRACTION_SERVICE("Spectral Extraction Service");
206
    public final String serviceName;
207

    
208
    SpectrumService(String serviceName) {
209
      this.serviceName = serviceName;
210
    }
211

    
212
    /**
213
     *
214
     * @return
215
     */
216
    public final String getServiceName() {
217
      return this.serviceName;
218
    }
219
  }
220

    
221
  /**
222
   *
223
   */
224
  public enum ImageGenerationParameters {
225

    
226
    /**
227
     *
228
     */
229
    NAXIS,
230
    /**
231
     *
232
     */
233
    CFRAME,
234
    /**
235
     *
236
     */
237
    EQUINOX,
238
    /**
239
     *
240
     */
241
    CRPIX,
242
    /**
243
     *
244
     */
245
    CRVAL,
246
    /**
247
     *
248
     */
249
    CDELT,
250
    /**
251
     *
252
     */
253
    ROTANG,
254
    /**
255
     *
256
     */
257
    PROJ
258
  };
259

    
260
  /**
261
   *
262
   */
263
  public enum Verb {
264

    
265
    /**
266
     *
267
     */
268
    VERBOSITY_0(0), /* The output table should contain only the minimum columns required */
269
    /**
270
     *
271
     */
272
    VERBOSITY_1(1), /* In addition to level 0, the output table should contain columns sufficient for uniquely describing the image */
273
    /**
274
     *
275
     */
276
    VERBOSITY_2(2), /*  In addition to level 1, the output table should contain, if possible, columns that contain values for all parameters supported as query constraints */
277
    /**
278
     *
279
     */
280
    VERBOSITY_3(3); /* The output table should return as much information about the images as possible. A table metadata query automatically implies the highest level of verbosity */
281

    
282
    /**
283
     *
284
     */
285
    public final int verbosityMode;
286

    
287
    Verb(final int verbosityMode) {
288
      this.verbosityMode = verbosityMode;
289
    }
290

    
291
    /**
292
     *
293
     * @return
294
     */
295
    public final int getVerbosityMode() {
296
      return this.verbosityMode;
297
    }
298
  }
299

    
300
  /**
301
   * List of format for internet browser.
302
   */
303
  public enum GraphicBrowser {
304

    
305
    /**
306
     * JPEG format.
307
     */
308
    JPEG("image/jpeg"),
309
    /**
310
     * PNG format.
311
     */
312
    PNG("image/png"),
313
    /**
314
     * GIF format.
315
     */
316
    GIF("image/gif");
317
    /**
318
     * Format.
319
     */
320
    private final String format;
321

    
322
    /**
323
     * new Instance of Graphic browser.
324
     *
325
     * @param format Format name.
326
     */
327
    GraphicBrowser(final String format) {
328
      this.format = format;
329
    }
330

    
331
    /**
332
     * Get Format Name.
333
     *
334
     * @return Returns format name.
335
     */
336
    public String getFormat() {
337
      return format;
338
    }
339

    
340
    /**
341
     * Check if val is a graphic format.
342
     *
343
     * @param val Format.
344
     * @return Returns True when val is contained in the list of Graphic format otherwise False.
345
     */
346
    public static boolean contains(final String val) {
347
      for (GraphicBrowser it : GraphicBrowser.values()) {
348
        if (it.getFormat().equals(val)) {
349
          return true;
350
        }
351
      }
352
      return false;
353
    }
354
  }
355

    
356
  /**
357
   * List of supported format.
358
   */
359
  public enum ParamStandardFormat {
360

    
361
    /**
362
     * All format.
363
     */
364
    ALL("ALL", new ArrayList<String>()),
365
    /**
366
     * Graphic format.
367
     */
368
    GRAPHIC("GRAPHIC", new ArrayList<String>()),
369
    /**
370
     * METADATA format.
371
     */
372
    METADATA("METADATA", new ArrayList<String>()),
373
    /**
374
     * GRAPHIC Format.
375
     */
376
    GRAPHIC_ALL("GRAPHIC-ALL", new ArrayList<String>());
377
    /**
378
     * format.
379
     */
380
    private final String format;
381
    /**
382
     * All formats.
383
     */
384
    private List<String> formats;
385

    
386
    /**
387
     * New instance of Standard Format.
388
     *
389
     * @param val format name.
390
     * @param formats values for this format name.
391
     */
392
    ParamStandardFormat(final String val, final List<String> formats) {
393
      this.format = val;
394
      this.formats = formats;
395
    }
396

    
397
    /**
398
     * Get the format name.
399
     *
400
     * @return Returns the format name.
401
     */
402
    public String getFormatName() {
403
      return format;
404
    }
405

    
406
    /**
407
     * Get the list of format.
408
     *
409
     * @return Returns the list of format for a format name.
410
     */
411
    public List<String> getFormats() {
412
      return Collections.unmodifiableList(formats);
413
    }
414

    
415
    /**
416
     * Add a format to the format name.
417
     *
418
     * @param val new supported format value.
419
     */
420
    private void addFormat(final String val) {
421
      this.formats.add(val);
422
    }
423

    
424
    /**
425
     * Set the list of format for a format name.
426
     *
427
     * @param val Set a list of formats for a format name.
428
     */
429
    private void setFormat(final List<String> val) {
430
      this.formats.addAll(val);
431
    }
432

    
433
    /**
434
     * Add a format value for a format name.
435
     *
436
     * @param format format Name.
437
     * @param specialValue Value for a format name.
438
     */
439
    private static void addFormat(final String format, final ParamStandardFormat specialValue) {
440
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
441
        if (it.equals(specialValue) && !ParamStandardFormat.hasFormat(format)) {
442
          it.addFormat(format);
443
        }
444
      }
445
    }
446

    
447
    /**
448
     * Set a list of format for a format name.
449
     *
450
     * @param format Format name.
451
     * @param specialValue List of format.
452
     */
453
    private static void setFormat(final List<String> format, final ParamStandardFormat specialValue) {
454
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
455
        if (it.equals(specialValue)) {
456
          it.setFormat(format);
457
        }
458
      }
459
    }
460

    
461
    /**
462
     * Get the list of supported format for a format name.
463
     *
464
     * @param format Format name.
465
     * @return Returns the list of supported formats.
466
     */
467
    public static List<String> getFormats(final ParamStandardFormat format) {
468
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
469
        if (it.equals(format)) {
470
          return it.getFormats();
471
        }
472
      }
473
      throw new IllegalAccessError();
474
    }
475

    
476
    /**
477
     * Get the list of supported format for a format name.
478
     *
479
     * @param format Format name.
480
     * @return Returns the list of supported formats.
481
     */
482
    public static List<String> getFormats(final String format) {
483
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
484
        if (it.getFormatName().equals(format)) {
485
          return it.getFormats();
486
        }
487
      }
488
      throw new IllegalAccessError();
489
    }
490

    
491
    /**
492
     * Get Format names.
493
     *
494
     * @return Returns format names.
495
     */
496
    public static List<String> getCtes() {
497
      final List<String> formats = new ArrayList<String>();
498
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
499
        formats.add(it.getFormatName());
500
      }
501
      return formats;
502
    }
503

    
504
    /**
505
     * Test if format is included in the list of formats.
506
     *
507
     * @param format format to test
508
     * @return Returns true when the format is included in the list otherwise false.
509
     */
510
    public static boolean hasFormat(final String format) {
511
      for (ParamStandardFormat it : ParamStandardFormat.values()) {
512
        if (it.getFormats().contains(format)) {
513
          return true;
514
        }
515
      }
516
      return false;
517
    }
518
  };
519

    
520
  /**
521
   *
522
   */
523
  public enum ParamStandardInput {
524

    
525
    /**
526
     *
527
     */
528
    POS("POS", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
529
    "The position of the region of interest, expressed as the right-ascension and declination of the field center, in decimal degrees using the ICRS coordinate system. A comma should delimit the two values; embedded whitespace is not permitted.", null, DataType.DOUBLE),
530
    
531
    /**
532
     *
533
     */
534
    SIZE("SIZE", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
535
    "The coordinate angular size of the region given in decimal degrees. The region may be specified using either one or two values. If only one value is given it applies to both coordinate axes. If two values are given the first value is the angular width in degrees of the right-ascension axis of the region, and the second value is the angular width in degrees of the declination axis.", null, DataType.DOUBLE),
536
    /**
537
     * 
538
     */
539
    TIME("TIME",Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),"zefzefze",null,DataType.DOUBLE),
540
    /**
541
     * 
542
     */
543
    BAND("BAND",Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),"zefzefze",null,DataType.DOUBLE),
544
    /**
545
     *
546
     */
547
    INTERSECT("INTERSECT", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
548
    "A parameter that indicates how matched images should intersect the region of interest", Intersect.OVERLAPS.name(), DataType.CHAR),
549
    /**
550
     *
551
     */
552
    FORMAT("FORMAT", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
553
    "indicate the desired format or formats of the images referenced by the output table", "ALL", DataType.CHAR),
554
    /**
555
     *
556
     */
557
    VERB("VERB", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
558
    "This parameter indicates the desired level of information to be returned in the output table, particularly the number of columns to be returned to describe each image.", null, DataType.INT);
559
    /**
560
     *
561
     */
562
    //NAXIS("NAXIS", Arrays.asList(SpectrumService.POINTED_SPECTRAL_ARCHIVE),
563
    //"The size of the output image in pixels. This is a vector-valued quantity, expressed as \"NAXIS=<width>,<height>\". If only one value is given it applies to both image axes", null, DataType.INT),
564
    /**
565
     *
566
     */
567
    //CFRAME("CFRAME", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
568
    //"The coordinate system reference frame, selected from ICRS, FK5, FK4, ECL, GAL, and SGAL (these abbreviations follow CDS Aladin). Default: ICRS. ", "ICRS", DataType.CHAR),
569
    /**
570
     *
571
     */
572
    //EQUINOX("EQUINOX", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
573
    //"Epoch of the mean equator and equinox for the specified coordinate system reference frame (CFRAME). Not required for ICRS. Default: B1950 for FK4, otherwise J2000.", "J2000", DataType.CHAR),
574
    /**
575
     *
576
     */
577
    //CRPIX("CRPIX", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
578
    //"The coordinates of the reference pixel, expressed in the pixel coordinates of the output image, with [1,1] being the center of the first pixel of the first row of the image. This is a vector-valued quantity; if only one value is given it applies to both image axes. Default: the image center.", null, DataType.DOUBLE),
579
    /**
580
     *
581
     */
582
    //CRVAL("CRVAL", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
583
    //"The world coordinates relative to CFRAME at the reference pixel. This is a vector-valued quantity; both array values are required. Default: the region center coordinates (POS) at the center of the image, transformed to the output coordinate system reference frame if other than ICRS. If CRPIX is specified to be other than the image center the corresponding CRVAL can be computed, but should be specified explicitly by the client.", null, DataType.DOUBLE),
584
    /**
585
     *
586
     */
587
    //CDELT("CDELT", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
588
    //"The scale of the output image in decimal degrees per pixel. A negative value implies an axis flip. Since the default image orientation is N up and E to the left, the default sign of CDELT is [-1,1].", null, DataType.DOUBLE),
589
    /**
590
     *
591
     */
592
    //ROTANG("ROTANG", Arrays.asList(SpectrumService.IMAGE_CUTOUT_SERVICE, SpectrumService.IMAGE_MOSAICING_SERVICE),
593
    //"The rotation angle of the image in degrees relative to CFRAME (an image which is unrotated in one reference frame may be rotated in another). This is the rotation of the WCS declination or latitude axis with respect to the second axis of the image, measured in the counterclockwise direction (as for FITS WCS, which is in turn based on the old AIPS convention). Default: 0 (no rotation).", "0", DataType.DOUBLE),
594
    
595
    
596
    private String inputParameterName;
597
    private List<SpectrumService> supportedImageService;
598
    private String description;
599
    private String defaultValue;
600
    private DataType dataType;
601

    
602
    ParamStandardInput(final String inputParameterName, final List<SpectrumService> supportedImageService, final String description, final String defaultValue, final DataType dataType) {
603
      this.inputParameterName = inputParameterName;
604
      this.supportedImageService = supportedImageService;
605
      this.description = description;
606
      this.defaultValue = defaultValue;
607
      this.dataType = dataType;
608
    }
609

    
610
    /**
611
     *
612
     * @return
613
     */
614
    public final String getInputParameterName() {
615
      return this.inputParameterName;
616
    }
617

    
618
    /**
619
     *
620
     * @return
621
     */
622
    public final List<SpectrumService> getSupportedImageService() {
623
      return Collections.unmodifiableList(this.supportedImageService);
624
    }
625

    
626
    /**
627
     *
628
     * @return
629
     */
630
    public final String getDescription() {
631
      return this.description;
632
    }
633

    
634
    /**
635
     *
636
     * @return
637
     */
638
    public final String getDefaultValue() {
639
      return this.defaultValue;
640
    }
641

    
642
    /**
643
     *
644
     * @return
645
     */
646
    public final DataType getDataType() {
647
      return this.dataType;
648
    }
649
  };
650
  //public enum ImageFormat{}//public enum ImageFormat{}//public enum ImageFormat{}//public enum ImageFormat{}
651

    
652
  /**
653
   * Constructor.
654
   *
655
   * @param datasetApp Dataset Application
656
   * @param resourceModel Data model
657
   * @param request Request
658
   * @param context Context
659
   */
660
  public SimpleSpectralAccessProtocolLibrary(final DataSetApplication datasetApp, final ResourceModel resourceModel, final Request request, final Context context) {
661
    this.datasetApp = datasetApp;
662
    this.resourceModel = resourceModel;
663
    this.request = request;
664
    this.context = context;
665
  }
666

    
667
  /**
668
   * Fill data Model that will be used in the template.
669
   *
670
   * @return data model for the template
671
   */
672
  private Map fillDataModel() {
673
    // init
674
    Map dataModel;
675

    
676
    // Handling input parameters
677
    final DataModelInterface inputParameters = new SimpleSpectralAccessInputParameters(datasetApp, request, this.context, this.resourceModel);
678
      
679
    // data model response
680
    if (inputParameters.getDataModel().containsKey("infos")) {
681
      dataModel = inputParameters.getDataModel();
682
    } else {
683
      final SimpleSpectralAccessDataModelInterface response = new SimpleSpectralAccessResponse((SimpleSpectralAccessInputParameters) inputParameters, resourceModel);
684
      dataModel = response.getDataModel();
685
    }
686
    return dataModel;
687
  }
688

    
689
  /**
690
   * VOTable response.
691
   *
692
   * @return VOTable response
693
   */
694
  public final VOTableRepresentation getResponse() {
695
    final Map dataModel = fillDataModel();
696
    return new VOTableRepresentation(dataModel);
697
  }  
698
}