1 |
779bac69
|
Marc NICOLAS
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
package fr.cnes.sitools.astro.vo.conesearch;
|
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.RangeValidation;
|
25 |
|
|
import fr.cnes.sitools.extensions.common.StatusValidation;
|
26 |
|
|
import fr.cnes.sitools.extensions.common.Validation;
|
27 |
|
|
import java.util.ArrayList;
|
28 |
|
|
import java.util.Collections;
|
29 |
|
|
import java.util.HashMap;
|
30 |
|
|
import java.util.List;
|
31 |
|
|
import java.util.Map;
|
32 |
|
|
import java.util.Map.Entry;
|
33 |
|
|
import java.util.Set;
|
34 |
|
|
import java.util.logging.Level;
|
35 |
|
|
import java.util.logging.Logger;
|
36 |
|
|
import net.ivoa.xml.votable.v1.Info;
|
37 |
|
|
import org.restlet.Context;
|
38 |
|
|
import org.restlet.Request;
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
public class ConeSearchInputParameters implements ConeSearchDataModelInterface {
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
private static final Logger LOG = Logger.getLogger(ConeSearchInputParameters.class.getName());
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
private static final int DEFAULT_VERBOSITY_MODE = 0;
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
private transient int verb = DEFAULT_VERBOSITY_MODE;
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
private final transient Map dataModel = new HashMap();
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
private final transient Request request;
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
private final transient Context context;
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
private final transient DataSetApplication datasetApp;
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
private transient double rightAscension;
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
private transient double declination;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
private transient double radius;
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
public ConeSearchInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal,
|
99 |
|
|
final double maxSr, final boolean verbosity, final int verbVal) {
|
100 |
|
|
this.datasetApp = datasetAppVal;
|
101 |
|
|
this.context = contextVal;
|
102 |
|
|
this.request = requestVal;
|
103 |
|
|
final String raInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.RA);
|
104 |
|
|
final String decInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.DEC);
|
105 |
|
|
final String srInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.SR);
|
106 |
|
|
final String verbInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.VERB);
|
107 |
|
|
if(raInput == null && decInput == null && srInput == null){
|
108 |
|
|
Info info = new Info();
|
109 |
|
|
info.setName("QUERY_STATUS");
|
110 |
|
|
info.setValueAttribute("ERROR");
|
111 |
|
|
info.setValue("RA, DEC and SR must be not null");
|
112 |
|
|
final List<Info> listInfos = new ArrayList<Info>();
|
113 |
|
|
listInfos.add(info);
|
114 |
|
|
this.dataModel.put("infos", listInfos);
|
115 |
|
|
}else{
|
116 |
|
|
checkInputParameters(raInput, decInput, srInput, maxSr, verbInput, verbosity, verbVal);
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
private void checkInputParameters(final String raInput, final String decInput, final String srInput, final double maxSr,
|
132 |
|
|
final String verbInput, final boolean verbosity, final int verbVal) {
|
133 |
|
|
final List<Info> infos = new ArrayList<Info>();
|
134 |
|
|
final Map<String, String> validationMap = new HashMap<String, String>();
|
135 |
|
|
validationMap.put(ConeSearchProtocolLibrary.RA, raInput);
|
136 |
|
|
validationMap.put(ConeSearchProtocolLibrary.DEC, decInput);
|
137 |
|
|
validationMap.put(ConeSearchProtocolLibrary.SR, srInput);
|
138 |
|
|
validationMap.put(ConeSearchProtocolLibrary.VERB, verbInput);
|
139 |
|
|
validationMap.put(ConeSearchProtocolLibrary.VERBOSITY, String.valueOf(verbosity));
|
140 |
|
|
Validation validation = new InputsValidation(validationMap);
|
141 |
|
|
validation = new RangeValidation(validation, ConeSearchProtocolLibrary.RA, ConeSearchProtocolLibrary.RA_MIN, ConeSearchProtocolLibrary.RA_MAX);
|
142 |
|
|
validation = new RangeValidation(validation, ConeSearchProtocolLibrary.DEC, ConeSearchProtocolLibrary.DEC_MIN, ConeSearchProtocolLibrary.DEC_MAX);
|
143 |
|
|
validation = new RangeValidation(validation, ConeSearchProtocolLibrary.SR, 0, maxSr);
|
144 |
|
|
validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERBOSITY);
|
145 |
|
|
validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERB, String.valueOf(verbVal));
|
146 |
|
|
final StatusValidation status = validation.validate();
|
147 |
|
|
if (status.isValid()) {
|
148 |
|
|
final Map<String, String> input = validation.getMap();
|
149 |
|
|
this.rightAscension = Double.valueOf(input.get(ConeSearchProtocolLibrary.RA));
|
150 |
|
|
this.declination = Double.valueOf(input.get(ConeSearchProtocolLibrary.DEC));
|
151 |
|
|
this.radius = Double.valueOf(input.get(ConeSearchProtocolLibrary.SR));
|
152 |
|
|
this.verb = Integer.valueOf(input.get(ConeSearchProtocolLibrary.VERB));
|
153 |
|
|
} else {
|
154 |
|
|
Info infoError = new Info();
|
155 |
|
|
infoError.setName("QUERY_STATUS");
|
156 |
|
|
infoError.setValueAttribute("ERROR");
|
157 |
|
|
infos.add(infoError);
|
158 |
|
|
final Map<String, String> errors = status.getMessages();
|
159 |
|
|
final Set<Entry<String, String>> entries = errors.entrySet();
|
160 |
|
|
for (Entry<String, String> entry : entries) {
|
161 |
|
|
final Info info = new Info();
|
162 |
|
|
info.setID(entry.getKey());
|
163 |
|
|
info.setName("Error in " + entry.getKey());
|
164 |
|
|
info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
|
165 |
|
|
infos.add(info);
|
166 |
|
|
LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
if (!infos.isEmpty()) {
|
170 |
|
|
this.dataModel.put("infos", infos);
|
171 |
|
|
}
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
public final double getRa() {
|
180 |
|
|
return this.rightAscension;
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
public final double getDec() {
|
189 |
|
|
return this.declination;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
public final double getSr() {
|
198 |
|
|
return this.radius;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
public final int getVerb() {
|
207 |
|
|
return this.verb;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
@Override
|
211 |
|
|
public final Map getDataModel() {
|
212 |
|
|
return Collections.unmodifiableMap(this.dataModel);
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
public final Request getRequest() {
|
221 |
|
|
return this.request;
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
public final Context getContext() {
|
230 |
|
|
return this.context;
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
public final DataSetApplication getDatasetApplication() {
|
239 |
|
|
return this.datasetApp;
|
240 |
|
|
}
|
241 |
|
|
} |