git_sitools_idoc / sitools-idoc / hesiod / javaExt / src / fr / ias / sitools / resources / vo / SimpleSpectralAccessResource.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.resources.vo; |
20 |
|
21 |
import fr.ias.sitools.vo.ssa.SimpleSpectralAccessProtocolLibrary; |
22 |
import fr.cnes.sitools.common.resource.SitoolsParameterizedResource; |
23 |
import fr.cnes.sitools.dataset.DataSetApplication; |
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
import java.util.logging.Logger; |
27 |
import org.restlet.data.Disposition; |
28 |
import org.restlet.data.MediaType; |
29 |
import org.restlet.data.Status; |
30 |
import org.restlet.ext.wadl.DocumentationInfo; |
31 |
import org.restlet.ext.wadl.MethodInfo; |
32 |
import org.restlet.ext.wadl.ParameterInfo; |
33 |
import org.restlet.ext.wadl.ParameterStyle; |
34 |
import org.restlet.ext.wadl.RepresentationInfo; |
35 |
import org.restlet.representation.Representation; |
36 |
import org.restlet.representation.Variant; |
37 |
import org.restlet.resource.Get; |
38 |
|
39 |
/**
|
40 |
* Queries the dataset and retrieves the result using the Simple Image Access Protocol.
|
41 |
* @see SimpleImageAccessResourcePlugin the plugin
|
42 |
* @see SimpleSpectralAccessProtocolLibrary the library that we use for SIAP.
|
43 |
* @author Jean-Christophe Malapert <jean-christophe.malapert@cnes.fr>
|
44 |
*/
|
45 |
public class SimpleSpectralAccessResource extends SitoolsParameterizedResource { |
46 |
|
47 |
/**
|
48 |
* Logger.
|
49 |
*/
|
50 |
private static final Logger LOG = Logger.getLogger(SimpleSpectralAccessResource.class.getName()); |
51 |
|
52 |
/**
|
53 |
* Initialize.
|
54 |
*/
|
55 |
@Override
|
56 |
public final void doInit() { |
57 |
super.doInit();
|
58 |
} |
59 |
|
60 |
/**
|
61 |
* Returns the supported representation.
|
62 |
*
|
63 |
* @param variant variant
|
64 |
* @return XML mediaType
|
65 |
*/
|
66 |
@Override
|
67 |
protected final Representation head(final Variant variant) { |
68 |
final Representation repr = super.head(); |
69 |
repr.setMediaType(MediaType.TEXT_XML); |
70 |
return repr;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Returns the VOTable response.
|
75 |
*
|
76 |
* @return VOTable response
|
77 |
*/
|
78 |
@Get
|
79 |
public final Representation getVOResponse() { |
80 |
LOG.finest(String.format("SSA : %s", getRequest())); |
81 |
final SimpleSpectralAccessProtocolLibrary sia = new SimpleSpectralAccessProtocolLibrary((DataSetApplication) this.getApplication(), |
82 |
this.getModel(), this.getRequest(), this.getContext()); |
83 |
final Representation rep = sia.getResponse();
|
84 |
if (fileName != null && !"".equals(fileName)) { |
85 |
final Disposition disp = new Disposition(Disposition.TYPE_ATTACHMENT); |
86 |
disp.setFilename(fileName); |
87 |
rep.setDisposition(disp); |
88 |
} |
89 |
return rep;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Describes SITools2 in the WADL.
|
94 |
*/
|
95 |
@Override
|
96 |
public final void sitoolsDescribe() { |
97 |
setName("Simple Spectral Access Protocol");
|
98 |
setDescription("This class implements the Simple Spectral Access Protocol for Virtual Observatory. "
|
99 |
+ "See http://ivoa.net web site for information about this protocol.");
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Describe GET method in the WADL.
|
104 |
*
|
105 |
* @param info information
|
106 |
*/
|
107 |
@Override
|
108 |
protected final void describeGet(final MethodInfo info) { |
109 |
this.addInfo(info);
|
110 |
info.setIdentifier("SimpleSpectralAccessProtocol");
|
111 |
info.setDocumentation("Interoperability service to distribute spectrum through the Simple Spectral Access Protocol");
|
112 |
|
113 |
final List<ParameterInfo> parametersInfo = new ArrayList<ParameterInfo>(); |
114 |
parametersInfo.add(new ParameterInfo("POS", true, "string", ParameterStyle.QUERY, |
115 |
"Box Central position (decimal degree) in ICRS such as RA,DEC."));
|
116 |
parametersInfo.add(new ParameterInfo("SIZE", true, "string", ParameterStyle.QUERY, |
117 |
"Size of the box in decimal degree such as width,height or width."));
|
118 |
info.getRequest().setParameters(parametersInfo); |
119 |
|
120 |
info.getResponse().getStatuses().add(Status.SUCCESS_OK); |
121 |
|
122 |
final DocumentationInfo documentation = new DocumentationInfo(); |
123 |
documentation.setTitle("SIAP");
|
124 |
documentation.setTextContent("Simple Spectral Access Protocol");
|
125 |
|
126 |
final List<RepresentationInfo> representationsInfo = new ArrayList<RepresentationInfo>(); |
127 |
final RepresentationInfo representationInfo = new RepresentationInfo(MediaType.TEXT_XML); |
128 |
representationInfo.setDocumentation(documentation); |
129 |
representationsInfo.add(representationInfo); |
130 |
info.getResponse().setRepresentations(representationsInfo); |
131 |
} |
132 |
} |