1 | package com.ether; |
---|
2 | |
---|
3 | import com.ether.dao.ObservatoryDAO; |
---|
4 | import com.ether.dao.TapasRequestDAO; |
---|
5 | import com.ether.tapas.Los; |
---|
6 | import com.ether.tapas.Location; |
---|
7 | import com.ether.tapas.Observation; |
---|
8 | import com.ether.tapas.Observatory; |
---|
9 | import com.ether.tapas.Preference; |
---|
10 | import com.ether.tapas.Request; |
---|
11 | import com.ether.tapas.Tapas; |
---|
12 | import com.ether.tapas.TapasRequest; |
---|
13 | import com.ether.user.User; |
---|
14 | import org.apache.commons.logging.Log; |
---|
15 | import org.apache.commons.logging.LogFactory; |
---|
16 | import org.jdom.Attribute; |
---|
17 | import org.jdom.Document; |
---|
18 | import org.jdom.Element; |
---|
19 | import org.jdom.output.Format; |
---|
20 | import org.jdom.output.XMLOutputter; |
---|
21 | import org.jetbrains.annotations.NotNull; |
---|
22 | import org.jetbrains.annotations.Nullable; |
---|
23 | import org.springframework.beans.factory.annotation.Required; |
---|
24 | import org.springframework.transaction.annotation.Transactional; |
---|
25 | |
---|
26 | import java.io.FileOutputStream; |
---|
27 | import java.io.IOException; |
---|
28 | import java.text.ParseException; |
---|
29 | import java.text.SimpleDateFormat; |
---|
30 | import java.util.ArrayList; |
---|
31 | import java.util.Calendar; |
---|
32 | import java.util.Date; |
---|
33 | import java.util.Iterator; |
---|
34 | import java.util.List; |
---|
35 | import java.util.Properties; |
---|
36 | import java.util.StringTokenizer; |
---|
37 | |
---|
38 | //import java.sql.Date; |
---|
39 | |
---|
40 | /** |
---|
41 | * @author rboipsl |
---|
42 | * @date 2 mars 2012 |
---|
43 | */ |
---|
44 | public class TapasServiceImpl |
---|
45 | extends BackofficeServiceImpl |
---|
46 | implements TapasService |
---|
47 | { |
---|
48 | @Transactional(readOnly = true) |
---|
49 | public void createXMLRequest( @NotNull final Tapas fTapas, @NotNull final Properties prop ) |
---|
50 | throws ServiceException |
---|
51 | { |
---|
52 | final String servicePath = prop.getProperty( "service_path" ); |
---|
53 | //final String srcPath = prop.getProperty( "src_path" ); |
---|
54 | final String dataPath = prop.getProperty( "data_path" ); |
---|
55 | |
---|
56 | //final String fichier = servicePath + "/" + "request.xml"; |
---|
57 | final Element tapas = new Element( "tapas" ); |
---|
58 | final List<Element> listRequest = new ArrayList<Element>( fTapas.getRequests().size() ); |
---|
59 | |
---|
60 | //On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer |
---|
61 | final Document document = new Document( tapas ); |
---|
62 | |
---|
63 | //recuperation valeur id requete (bdd table tapas_request) |
---|
64 | fTapas.setId( "Ether_TAPAS_" + String.valueOf( getNumRequest() ) ); |
---|
65 | |
---|
66 | final Attribute id = new Attribute( "Id", fTapas.getId() ); |
---|
67 | tapas.setAttribute( id ); |
---|
68 | |
---|
69 | //a terme devient une boucle |
---|
70 | final List<Request> requests = fTapas.getRequests(); |
---|
71 | Request xRequest, nRequest; |
---|
72 | |
---|
73 | String iname; |
---|
74 | |
---|
75 | Iterator<Request> iter = requests.iterator(); |
---|
76 | |
---|
77 | int iii = requests.size(); |
---|
78 | int inr = 0; |
---|
79 | int indice = 1; |
---|
80 | //Request xRequest = iter.next(); |
---|
81 | String oneTransmission; |
---|
82 | |
---|
83 | while ( indice <= iii ) |
---|
84 | { |
---|
85 | nRequest = iter.next(); |
---|
86 | nRequest.setValid( 1 ); |
---|
87 | |
---|
88 | oneTransmission = nRequest.getPreference().getOneTransmission().getSecondValue(); |
---|
89 | |
---|
90 | if( oneTransmission.equalsIgnoreCase( "NO" ) ) |
---|
91 | { |
---|
92 | nRequest.setValid( -1 ); |
---|
93 | if( nRequest.getPreference().getH2oExtinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
94 | { |
---|
95 | requests.add( addNewRequest( nRequest, (iii+inr+1), "H2O") ); |
---|
96 | inr = inr + 1; |
---|
97 | iter = requests.iterator(); |
---|
98 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
99 | { |
---|
100 | nRequest = iter.next(); |
---|
101 | }*/ |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | if( nRequest.getPreference().getCh4Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
106 | { |
---|
107 | requests.add( addNewRequest( nRequest, (iii+inr+1), "CH4" ) ); |
---|
108 | inr = inr + 1; |
---|
109 | iter = requests.iterator(); |
---|
110 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
111 | { |
---|
112 | nRequest = iter.next(); |
---|
113 | }*/ |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | if( nRequest.getPreference().getCo2Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
118 | { |
---|
119 | requests.add( addNewRequest( nRequest, (iii+inr+1), "CO2" ) ); |
---|
120 | inr = inr + 1; |
---|
121 | iter = requests.iterator(); |
---|
122 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
123 | { |
---|
124 | nRequest = iter.next(); |
---|
125 | }*/ |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | if( nRequest.getPreference().getN2oExtinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
130 | { |
---|
131 | requests.add( addNewRequest( nRequest, (iii+inr+1), "N2O" ) ); |
---|
132 | inr = inr + 1; |
---|
133 | iter = requests.iterator(); |
---|
134 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
135 | { |
---|
136 | nRequest = iter.next(); |
---|
137 | }*/ |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | if( nRequest.getPreference().getO2Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
142 | { |
---|
143 | requests.add( addNewRequest( nRequest, (iii+inr+1), "O2" ) ); |
---|
144 | iter = requests.iterator(); |
---|
145 | inr = inr + 1; |
---|
146 | iter = requests.iterator(); |
---|
147 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
148 | { |
---|
149 | nRequest = iter.next(); |
---|
150 | }*/ |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | if( nRequest.getPreference().getO3Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) |
---|
155 | { |
---|
156 | requests.add( addNewRequest( nRequest, (iii+inr+1), "O3" ) ); |
---|
157 | iter = requests.iterator(); |
---|
158 | inr = inr + 1; |
---|
159 | iter = requests.iterator(); |
---|
160 | /*for ( int i=1 ; i <= (iii+inr) ; i++ ) |
---|
161 | { |
---|
162 | nRequest = iter.next(); |
---|
163 | }*/ |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | iter = requests.iterator(); |
---|
168 | indice=indice+1; |
---|
169 | for (int i = 1 ; i < indice ; i++) |
---|
170 | { |
---|
171 | nRequest = iter.next(); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | indice=1; |
---|
177 | |
---|
178 | //// |
---|
179 | for( final Request iRequest : requests ) |
---|
180 | { |
---|
181 | if (iRequest.getValid() != -1) { |
---|
182 | |
---|
183 | final Element request = new Element( "request" ); |
---|
184 | // Id de la request |
---|
185 | //final Attribute idR = new Attribute( "Id", (Long) iRequest.getId().toString() ); |
---|
186 | final Attribute idR = new Attribute( "Id", String.valueOf(indice) ); |
---|
187 | request.setAttribute( idR ); |
---|
188 | |
---|
189 | // PREFERENCES |
---|
190 | final Element preferences = new Element( "preferences" ); |
---|
191 | |
---|
192 | |
---|
193 | //format |
---|
194 | final Element format = new Element( "format" ); |
---|
195 | //final Attribute validF = new Attribute( "valid", iRequest.getPreference().getFormat().getFirstValue() ); |
---|
196 | final Attribute validF = new Attribute( "valid", "VO,ASCII,FITS,NETCDF" ); |
---|
197 | format.setAttribute( validF ); |
---|
198 | format.setText( iRequest.getPreference().getFormat().getSecondValue() ); |
---|
199 | preferences.addContent( format ); |
---|
200 | |
---|
201 | |
---|
202 | //rayleighExtinction |
---|
203 | final Element rayleighExtinction = new Element( "rayleigh_extinction" ); |
---|
204 | //final Attribute validR = new Attribute( "valid", iRequest.getPreference().getRayleighExtinction().getFirstValue() ); |
---|
205 | Attribute validR = new Attribute( "valid", "YES,NO" ); |
---|
206 | rayleighExtinction.setAttribute( validR ); |
---|
207 | rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue() ); |
---|
208 | preferences.addContent( rayleighExtinction ); |
---|
209 | |
---|
210 | //h2o |
---|
211 | final Element h2oe = new Element( "h2o_extinction" ); |
---|
212 | validR = new Attribute( "valid", "YES,NO" ); |
---|
213 | h2oe.setAttribute( validR ); |
---|
214 | h2oe.setText( iRequest.getPreference().getH2oExtinction().getSecondValue() ); |
---|
215 | preferences.addContent( h2oe ); |
---|
216 | |
---|
217 | |
---|
218 | //o3 |
---|
219 | final Element o3e = new Element( "o3_extinction" ); |
---|
220 | validR = new Attribute( "valid", "YES,NO" ); |
---|
221 | o3e.setAttribute( validR ); |
---|
222 | o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue() ); |
---|
223 | preferences.addContent( o3e ); |
---|
224 | |
---|
225 | //o2 |
---|
226 | final Element o2e = new Element( "o2_extinction" ); |
---|
227 | validR = new Attribute( "valid", "YES,NO" ); |
---|
228 | o2e.setAttribute( validR ); |
---|
229 | o2e.setText( iRequest.getPreference().getO2Extinction().getSecondValue() ); |
---|
230 | preferences.addContent( o2e ); |
---|
231 | |
---|
232 | |
---|
233 | //co2 |
---|
234 | final Element co2e = new Element( "co2_extinction" ); |
---|
235 | validR = new Attribute( "valid", "YES,NO" ); |
---|
236 | co2e.setAttribute( validR ); |
---|
237 | co2e.setText( iRequest.getPreference().getCo2Extinction().getSecondValue() ); |
---|
238 | preferences.addContent( co2e ); |
---|
239 | |
---|
240 | //ch4 |
---|
241 | final Element ch4e = new Element( "ch4_extinction" ); |
---|
242 | validR = new Attribute( "valid", "YES,NO" ); |
---|
243 | ch4e.setAttribute( validR ); |
---|
244 | ch4e.setText( iRequest.getPreference().getCh4Extinction().getSecondValue() ); |
---|
245 | preferences.addContent( ch4e ); |
---|
246 | |
---|
247 | //no2 |
---|
248 | final Element n2oe = new Element( "n2o_extinction" ); |
---|
249 | validR = new Attribute( "valid", "YES,NO" ); |
---|
250 | n2oe.setAttribute( validR ); |
---|
251 | n2oe.setText( iRequest.getPreference().getN2oExtinction().getSecondValue() ); |
---|
252 | preferences.addContent( n2oe ); |
---|
253 | |
---|
254 | |
---|
255 | request.addContent( preferences ); |
---|
256 | |
---|
257 | // OBSERVATORIES |
---|
258 | final Element observation = new Element( "observation" ); |
---|
259 | |
---|
260 | // date mesure |
---|
261 | final Element mdate = new Element( "date" ); |
---|
262 | final Calendar calendar = Calendar.getInstance(); |
---|
263 | |
---|
264 | calendar.setTimeInMillis( Long.valueOf( iRequest.getObservation().getDate() ) ); |
---|
265 | final String dateFormatFinal=DateHelper.formatDate( calendar.getTime(), DateHelper.DATE_UTC ); |
---|
266 | |
---|
267 | mdate.setText( dateFormatFinal ); |
---|
268 | |
---|
269 | //mdate.setText( iRequest.getObservation().getDate() ); |
---|
270 | observation.addContent( mdate ); |
---|
271 | |
---|
272 | //observatoire ou lieu libre en indiquant alt,lat,lon |
---|
273 | final Element observatory = new Element( "observatory" ); |
---|
274 | observation.addContent( observatory ); |
---|
275 | |
---|
276 | //recuperation des coordonnées de l'observatoire |
---|
277 | final Observatory obs; |
---|
278 | try |
---|
279 | { |
---|
280 | //obs = _observatoryDAO.selectByPrimaryKey( iRequest.getObservation().getObservatory().getId() ); |
---|
281 | obs = _observatoryDAO.getObservatoryByName( iRequest.getObservation().getObservatory().getName() ); |
---|
282 | } |
---|
283 | catch( PersistenceException e ) |
---|
284 | { |
---|
285 | throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); |
---|
286 | } |
---|
287 | |
---|
288 | ////// a tester //// |
---|
289 | |
---|
290 | final Element name = new Element( "name" ); |
---|
291 | |
---|
292 | final Element longitude = new Element( "longitude" ); |
---|
293 | validR = new Attribute( "min", "-180" ); |
---|
294 | longitude.setAttribute( validR ); |
---|
295 | validR = new Attribute( "max", "180" ); |
---|
296 | longitude.setAttribute( validR ); |
---|
297 | |
---|
298 | final Element latitude = new Element( "latitude" ); |
---|
299 | validR = new Attribute( "min", "-90" ); |
---|
300 | latitude.setAttribute( validR ); |
---|
301 | validR = new Attribute( "max", "90" ); |
---|
302 | latitude.setAttribute( validR ); |
---|
303 | |
---|
304 | final Element altitude = new Element( "altitude" ); |
---|
305 | validR = new Attribute( "min", "0" ); |
---|
306 | altitude.setAttribute( validR ); |
---|
307 | validR = new Attribute( "max", "10000" ); |
---|
308 | altitude.setAttribute( validR ); |
---|
309 | |
---|
310 | String shortName=""; |
---|
311 | |
---|
312 | if (null == obs) |
---|
313 | { |
---|
314 | //lieu libre |
---|
315 | name.setText(iRequest.getObservation().getLocation().getName()); |
---|
316 | altitude.setText( iRequest.getObservation().getLocation().getAltitude().toString() ); |
---|
317 | latitude.setText( iRequest.getObservation().getLocation().getLatitude().toString() ); |
---|
318 | longitude.setText( iRequest.getObservation().getLocation().getLongitude().toString() ); |
---|
319 | shortName = iRequest.getObservation().getLocation().getName(); |
---|
320 | } |
---|
321 | else { |
---|
322 | //observatoire connu de la bdd tapas |
---|
323 | name.setText( obs.getName() ); |
---|
324 | longitude.setText( obs.getLongitude().toString() ); |
---|
325 | latitude.setText( obs.getLatitude().toString() ); |
---|
326 | altitude.setText( obs.getAltitude().toString() ); |
---|
327 | shortName = obs.getShortName().toString(); |
---|
328 | } |
---|
329 | |
---|
330 | |
---|
331 | observatory.addContent( name ); |
---|
332 | observatory.addContent( latitude ); |
---|
333 | observatory.addContent( longitude ); |
---|
334 | observatory.addContent( altitude ); |
---|
335 | |
---|
336 | |
---|
337 | //los addN |
---|
338 | final Element los = new Element( "los" ); |
---|
339 | observation.addContent( los ); |
---|
340 | |
---|
341 | Los temp = iRequest.getObservation().getLos(); |
---|
342 | if ( !temp.getRaJ2000().equals( "" )) { |
---|
343 | final Element ra_j2000 = new Element( "ra_j2000" ); |
---|
344 | ra_j2000.setText( iRequest.getObservation().getLos().getRaJ2000() ); |
---|
345 | los.addContent( ra_j2000 ); |
---|
346 | } |
---|
347 | |
---|
348 | if ( !temp.getDecJ2000().equals( "" )) { |
---|
349 | final Element dec_j2000 = new Element( "dec_j2000" ); |
---|
350 | dec_j2000.setText( iRequest.getObservation().getLos().getDecJ2000() ); |
---|
351 | los.addContent( dec_j2000 ); |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | if ( !temp.getZenithAngle().equals("") ) { |
---|
356 | final Element zenith_angle = new Element( "zenith_angle" ); |
---|
357 | |
---|
358 | Attribute a1 = new Attribute( "min", "0" ); |
---|
359 | Attribute a2 = new Attribute( "max", "90" ); |
---|
360 | |
---|
361 | zenith_angle.setAttribute( a1 ); |
---|
362 | zenith_angle.setAttribute( a2 ); |
---|
363 | zenith_angle.setText( temp.getZenithAngle() ); |
---|
364 | |
---|
365 | los.addContent( zenith_angle ); |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | //instrument |
---|
370 | final Element instrument = new Element( "instrument" ); |
---|
371 | observation.addContent( instrument ); |
---|
372 | |
---|
373 | final Element spectral_choice = new Element( "spectral_choice" ); |
---|
374 | |
---|
375 | |
---|
376 | final String[] tabMess = iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue().split( "," ); |
---|
377 | |
---|
378 | String chValid = ""; |
---|
379 | int i; |
---|
380 | |
---|
381 | for( i = 0; i <= tabMess.length - 1; i++ ) //final String mess : tabMess ) |
---|
382 | { |
---|
383 | if( i == tabMess.length - 1 ) |
---|
384 | chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ); |
---|
385 | else chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ) + ","; |
---|
386 | } |
---|
387 | |
---|
388 | |
---|
389 | Attribute a3 = new Attribute( "valid", chValid ); |
---|
390 | |
---|
391 | spectral_choice.setAttribute( a3 ); |
---|
392 | final String message = EtherHelper.getMessage( "label.spectralUnit." + iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue(), null ); |
---|
393 | spectral_choice.setText( message ); |
---|
394 | instrument.addContent( spectral_choice ); |
---|
395 | |
---|
396 | final Element spectral_range = new Element( "spectral_range" ); |
---|
397 | spectral_range.setText( iRequest.getObservation().getInstrument().getSpectralRange() ); |
---|
398 | instrument.addContent( spectral_range ); |
---|
399 | |
---|
400 | |
---|
401 | // |
---|
402 | final Element ilsfChoice = new Element( "ilsf_choice" ); |
---|
403 | validR = new Attribute( "valid", iRequest.getObservation().getInstrument().getIlsfChoice().getFirstValue() ); |
---|
404 | ilsfChoice.setAttribute( validR ); |
---|
405 | //selectInstrumentalFunctions |
---|
406 | ilsfChoice.setText( String.valueOf( iRequest.getObservation().getInstrument().getIlsfChoice().getSecondValue() ) ); |
---|
407 | instrument.addContent( ilsfChoice ); |
---|
408 | |
---|
409 | |
---|
410 | final Element resolvingPower = new Element( "resolving_power" ); |
---|
411 | validR = new Attribute( "min", "0" ); |
---|
412 | resolvingPower.setAttribute( validR ); |
---|
413 | resolvingPower.setText( String.valueOf( iRequest.getObservation().getInstrument().getResolvingPower().getSecondValue() ) ); |
---|
414 | instrument.addContent( resolvingPower ); |
---|
415 | |
---|
416 | final Element samplingRatio = new Element( "sampling_ratio" ); |
---|
417 | validR = new Attribute( "min", "0" ); |
---|
418 | samplingRatio.setAttribute( validR ); |
---|
419 | samplingRatio.setText( String.valueOf( iRequest.getObservation().getInstrument().getSamplingRatio().getSecondValue() ) ); |
---|
420 | instrument.addContent( samplingRatio ); |
---|
421 | |
---|
422 | //berv correction |
---|
423 | //final Element bervCorr = new Element( "berv_correction" ); |
---|
424 | final Element bervCorr = new Element( "apply_berv" ); |
---|
425 | validR = new Attribute( "valid", "YES,NO" ); |
---|
426 | bervCorr.setAttribute( validR ); |
---|
427 | bervCorr.setText( iRequest.getPreference().getBervCorrection().getSecondValue() ); |
---|
428 | instrument.addContent( bervCorr ); |
---|
429 | |
---|
430 | |
---|
431 | request.addContent( observation ); |
---|
432 | |
---|
433 | //atmosphere |
---|
434 | final Element atmosphere = new Element( "atmosphere" ); |
---|
435 | request.addContent( atmosphere ); |
---|
436 | |
---|
437 | //reference |
---|
438 | final Element reference = new Element( "reference" ); |
---|
439 | validR = new Attribute( "valid", "0,1,2,3,4,5,6" ); |
---|
440 | reference.setAttribute( validR ); |
---|
441 | reference.setText( String.valueOf( iRequest.getAtmosphere().getReference().getSecondValue() ) ); |
---|
442 | atmosphere.addContent( reference ); |
---|
443 | |
---|
444 | |
---|
445 | String fileArletty = "", fileECMWF = ""; |
---|
446 | |
---|
447 | |
---|
448 | fileArletty = dataPath + "/" + createFileName( dateFormatFinal , "arletty", shortName ); |
---|
449 | fileECMWF = dataPath + "/" + createFileName( dateFormatFinal, "ecmwf", shortName ); |
---|
450 | |
---|
451 | final Element arlettyFile = new Element( "arletty_file" ); |
---|
452 | arlettyFile.setText( fileArletty ); |
---|
453 | atmosphere.addContent( arlettyFile ); |
---|
454 | |
---|
455 | final Element ecmwfFile = new Element( "ecmwf_file" ); |
---|
456 | ecmwfFile.setText( fileECMWF ); |
---|
457 | atmosphere.addContent( ecmwfFile ); |
---|
458 | |
---|
459 | listRequest.add( request ); |
---|
460 | |
---|
461 | indice=indice+1; |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | |
---|
466 | |
---|
467 | ////////// |
---|
468 | ///////// |
---|
469 | /*for( final Request iRequest : requests ) |
---|
470 | { |
---|
471 | final Element request = new Element( "request" ); |
---|
472 | // Id de la request |
---|
473 | final Attribute idR = new Attribute( "Id", iRequest.getId().toString() ); |
---|
474 | request.setAttribute( idR ); |
---|
475 | |
---|
476 | // PREFERENCES |
---|
477 | final Element preferences = new Element( "preferences" ); |
---|
478 | |
---|
479 | |
---|
480 | //format |
---|
481 | final Element format = new Element( "format" ); |
---|
482 | //final Attribute validF = new Attribute( "valid", iRequest.getPreference().getFormat().getFirstValue() ); |
---|
483 | final Attribute validF = new Attribute( "valid", "VO,ASCII,FITS,NETCDF" ); |
---|
484 | format.setAttribute( validF ); |
---|
485 | format.setText( iRequest.getPreference().getFormat().getSecondValue() ); |
---|
486 | preferences.addContent( format ); |
---|
487 | |
---|
488 | |
---|
489 | //rayleighExtinction |
---|
490 | final Element rayleighExtinction = new Element( "rayleigh_extinction" ); |
---|
491 | //final Attribute validR = new Attribute( "valid", iRequest.getPreference().getRayleighExtinction().getFirstValue() ); |
---|
492 | Attribute validR = new Attribute( "valid", "YES,NO" ); |
---|
493 | rayleighExtinction.setAttribute( validR ); |
---|
494 | rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue() ); |
---|
495 | preferences.addContent( rayleighExtinction ); |
---|
496 | |
---|
497 | //h2o |
---|
498 | final Element h2oe = new Element( "h2o_extinction" ); |
---|
499 | validR = new Attribute( "valid", "YES,NO" ); |
---|
500 | h2oe.setAttribute( validR ); |
---|
501 | h2oe.setText( iRequest.getPreference().getH2oExtinction().getSecondValue() ); |
---|
502 | preferences.addContent( h2oe ); |
---|
503 | |
---|
504 | |
---|
505 | //o3 |
---|
506 | final Element o3e = new Element( "o3_extinction" ); |
---|
507 | validR = new Attribute( "valid", "YES,NO" ); |
---|
508 | o3e.setAttribute( validR ); |
---|
509 | o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue() ); |
---|
510 | preferences.addContent( o3e ); |
---|
511 | |
---|
512 | //o2 |
---|
513 | final Element o2e = new Element( "o2_extinction" ); |
---|
514 | validR = new Attribute( "valid", "YES,NO" ); |
---|
515 | o2e.setAttribute( validR ); |
---|
516 | o2e.setText( iRequest.getPreference().getO2Extinction().getSecondValue() ); |
---|
517 | preferences.addContent( o2e ); |
---|
518 | |
---|
519 | |
---|
520 | //co2 |
---|
521 | final Element co2e = new Element( "co2_extinction" ); |
---|
522 | validR = new Attribute( "valid", "YES,NO" ); |
---|
523 | co2e.setAttribute( validR ); |
---|
524 | co2e.setText( iRequest.getPreference().getCo2Extinction().getSecondValue() ); |
---|
525 | preferences.addContent( co2e ); |
---|
526 | |
---|
527 | //ch4 |
---|
528 | final Element ch4e = new Element( "ch4_extinction" ); |
---|
529 | validR = new Attribute( "valid", "YES,NO" ); |
---|
530 | ch4e.setAttribute( validR ); |
---|
531 | ch4e.setText( iRequest.getPreference().getCh4Extinction().getSecondValue() ); |
---|
532 | preferences.addContent( ch4e ); |
---|
533 | |
---|
534 | //no2 |
---|
535 | final Element n2oe = new Element( "n2o_extinction" ); |
---|
536 | validR = new Attribute( "valid", "YES,NO" ); |
---|
537 | n2oe.setAttribute( validR ); |
---|
538 | n2oe.setText( iRequest.getPreference().getN2oExtinction().getSecondValue() ); |
---|
539 | preferences.addContent( n2oe ); |
---|
540 | |
---|
541 | |
---|
542 | request.addContent( preferences ); |
---|
543 | |
---|
544 | // OBSERVATORIES |
---|
545 | final Element observation = new Element( "observation" ); |
---|
546 | |
---|
547 | // date mesure |
---|
548 | final Element mdate = new Element( "date" ); |
---|
549 | final Calendar calendar = Calendar.getInstance(); |
---|
550 | |
---|
551 | calendar.setTimeInMillis( Long.valueOf( iRequest.getObservation().getDate() ) ); |
---|
552 | final String dateFormatFinal=DateHelper.formatDate( calendar.getTime(), DateHelper.DATE_UTC ); |
---|
553 | |
---|
554 | mdate.setText( dateFormatFinal ); |
---|
555 | |
---|
556 | // mdate.setText( iRequest.getObservation().getDate() ); |
---|
557 | observation.addContent( mdate ); |
---|
558 | |
---|
559 | //observatoire ou lieu libre en indiquant alt,lat,lon |
---|
560 | final Element observatory = new Element( "observatory" ); |
---|
561 | observation.addContent( observatory ); |
---|
562 | |
---|
563 | //recuperation des coordonnées de l'observatoire |
---|
564 | final Observatory obs; |
---|
565 | try |
---|
566 | { |
---|
567 | //obs = _observatoryDAO.selectByPrimaryKey( iRequest.getObservation().getObservatory().getId() ); |
---|
568 | obs = _observatoryDAO.getObservatoryByName( iRequest.getObservation().getObservatory().getName() ); |
---|
569 | } |
---|
570 | catch( PersistenceException e ) |
---|
571 | { |
---|
572 | throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); |
---|
573 | } |
---|
574 | |
---|
575 | ////// a tester //// |
---|
576 | |
---|
577 | final Element name = new Element( "name" ); |
---|
578 | |
---|
579 | final Element longitude = new Element( "longitude" ); |
---|
580 | validR = new Attribute( "min", "-180" ); |
---|
581 | longitude.setAttribute( validR ); |
---|
582 | validR = new Attribute( "max", "180" ); |
---|
583 | longitude.setAttribute( validR ); |
---|
584 | |
---|
585 | final Element latitude = new Element( "latitude" ); |
---|
586 | validR = new Attribute( "min", "-90" ); |
---|
587 | latitude.setAttribute( validR ); |
---|
588 | validR = new Attribute( "max", "90" ); |
---|
589 | latitude.setAttribute( validR ); |
---|
590 | |
---|
591 | final Element altitude = new Element( "altitude" ); |
---|
592 | validR = new Attribute( "min", "0" ); |
---|
593 | altitude.setAttribute( validR ); |
---|
594 | validR = new Attribute( "max", "10000" ); |
---|
595 | altitude.setAttribute( validR ); |
---|
596 | |
---|
597 | String shortName=""; |
---|
598 | |
---|
599 | if (null == obs) |
---|
600 | { |
---|
601 | //lieu libre |
---|
602 | name.setText(iRequest.getObservation().getLocation().getName()); |
---|
603 | altitude.setText( iRequest.getObservation().getLocation().getAltitude().toString() ); |
---|
604 | latitude.setText( iRequest.getObservation().getLocation().getLatitude().toString() ); |
---|
605 | longitude.setText( iRequest.getObservation().getLocation().getLongitude().toString() ); |
---|
606 | shortName = iRequest.getObservation().getLocation().getName(); |
---|
607 | } |
---|
608 | else { |
---|
609 | //observatoire connu de la bdd tapas |
---|
610 | name.setText( obs.getName() ); |
---|
611 | longitude.setText( obs.getLongitude().toString() ); |
---|
612 | latitude.setText( obs.getLatitude().toString() ); |
---|
613 | altitude.setText( obs.getAltitude().toString() ); |
---|
614 | shortName = obs.getShortName().toString(); |
---|
615 | } |
---|
616 | |
---|
617 | |
---|
618 | observatory.addContent( name ); |
---|
619 | observatory.addContent( latitude ); |
---|
620 | observatory.addContent( longitude ); |
---|
621 | observatory.addContent( altitude ); |
---|
622 | |
---|
623 | |
---|
624 | //los addN |
---|
625 | final Element los = new Element( "los" ); |
---|
626 | observation.addContent( los ); |
---|
627 | |
---|
628 | Los temp = iRequest.getObservation().getLos(); |
---|
629 | if ( !temp.getRaJ2000().equals( "" )) { |
---|
630 | final Element ra_j2000 = new Element( "ra_j2000" ); |
---|
631 | ra_j2000.setText( iRequest.getObservation().getLos().getRaJ2000() ); |
---|
632 | los.addContent( ra_j2000 ); |
---|
633 | } |
---|
634 | |
---|
635 | if ( !temp.getDecJ2000().equals( "" )) { |
---|
636 | final Element dec_j2000 = new Element( "dec_j2000" ); |
---|
637 | dec_j2000.setText( iRequest.getObservation().getLos().getDecJ2000() ); |
---|
638 | los.addContent( dec_j2000 ); |
---|
639 | } |
---|
640 | |
---|
641 | |
---|
642 | if ( !temp.getZenithAngle().equals("") ) { |
---|
643 | final Element zenith_angle = new Element( "zenith_angle" ); |
---|
644 | |
---|
645 | Attribute a1 = new Attribute( "min", "0" ); |
---|
646 | Attribute a2 = new Attribute( "max", "90" ); |
---|
647 | |
---|
648 | zenith_angle.setAttribute( a1 ); |
---|
649 | zenith_angle.setAttribute( a2 ); |
---|
650 | zenith_angle.setText( temp.getZenithAngle() ); |
---|
651 | |
---|
652 | los.addContent( zenith_angle ); |
---|
653 | } |
---|
654 | |
---|
655 | |
---|
656 | //instrument |
---|
657 | final Element instrument = new Element( "instrument" ); |
---|
658 | observation.addContent( instrument ); |
---|
659 | |
---|
660 | final Element spectral_choice = new Element( "spectral_choice" ); |
---|
661 | |
---|
662 | |
---|
663 | final String[] tabMess = iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue().split( "," ); |
---|
664 | |
---|
665 | String chValid = ""; |
---|
666 | int i; |
---|
667 | |
---|
668 | for( i = 0; i <= tabMess.length - 1; i++ ) //final String mess : tabMess ) |
---|
669 | { |
---|
670 | if( i == tabMess.length - 1 ) |
---|
671 | chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ); |
---|
672 | else chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ) + ","; |
---|
673 | } |
---|
674 | |
---|
675 | |
---|
676 | Attribute a3 = new Attribute( "valid", chValid ); |
---|
677 | |
---|
678 | spectral_choice.setAttribute( a3 ); |
---|
679 | final String message = EtherHelper.getMessage( "label.spectralUnit." + iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue(), null ); |
---|
680 | spectral_choice.setText( message ); |
---|
681 | instrument.addContent( spectral_choice ); |
---|
682 | |
---|
683 | final Element spectral_range = new Element( "spectral_range" ); |
---|
684 | spectral_range.setText( iRequest.getObservation().getInstrument().getSpectralRange() ); |
---|
685 | instrument.addContent( spectral_range ); |
---|
686 | |
---|
687 | |
---|
688 | // |
---|
689 | final Element ilsfChoice = new Element( "ilsf_choice" ); |
---|
690 | validR = new Attribute( "valid", iRequest.getObservation().getInstrument().getIlsfChoice().getFirstValue() ); |
---|
691 | ilsfChoice.setAttribute( validR ); |
---|
692 | //selectInstrumentalFunctions |
---|
693 | ilsfChoice.setText( String.valueOf( iRequest.getObservation().getInstrument().getIlsfChoice().getSecondValue() ) ); |
---|
694 | instrument.addContent( ilsfChoice ); |
---|
695 | |
---|
696 | |
---|
697 | final Element resolvingPower = new Element( "resolving_power" ); |
---|
698 | validR = new Attribute( "min", "0" ); |
---|
699 | resolvingPower.setAttribute( validR ); |
---|
700 | resolvingPower.setText( String.valueOf( iRequest.getObservation().getInstrument().getResolvingPower().getSecondValue() ) ); |
---|
701 | instrument.addContent( resolvingPower ); |
---|
702 | |
---|
703 | final Element samplingRatio = new Element( "sampling_ratio" ); |
---|
704 | validR = new Attribute( "min", "0" ); |
---|
705 | samplingRatio.setAttribute( validR ); |
---|
706 | samplingRatio.setText( String.valueOf( iRequest.getObservation().getInstrument().getSamplingRatio().getSecondValue() ) ); |
---|
707 | instrument.addContent( samplingRatio ); |
---|
708 | |
---|
709 | //berv correction |
---|
710 | //final Element bervCorr = new Element( "berv_correction" ); |
---|
711 | final Element bervCorr = new Element( "apply_berv" ); |
---|
712 | validR = new Attribute( "valid", "YES,NO" ); |
---|
713 | bervCorr.setAttribute( validR ); |
---|
714 | bervCorr.setText( iRequest.getPreference().getBervCorrection().getSecondValue() ); |
---|
715 | instrument.addContent( bervCorr ); |
---|
716 | |
---|
717 | |
---|
718 | request.addContent( observation ); |
---|
719 | |
---|
720 | //atmosphere |
---|
721 | final Element atmosphere = new Element( "atmosphere" ); |
---|
722 | request.addContent( atmosphere ); |
---|
723 | |
---|
724 | //reference |
---|
725 | final Element reference = new Element( "reference" ); |
---|
726 | validR = new Attribute( "valid", "0,1,2,3,4,5,6" ); |
---|
727 | reference.setAttribute( validR ); |
---|
728 | reference.setText( String.valueOf( iRequest.getAtmosphere().getReference().getSecondValue() ) ); |
---|
729 | atmosphere.addContent( reference ); |
---|
730 | |
---|
731 | |
---|
732 | String fileArletty = "", fileECMWF = ""; |
---|
733 | |
---|
734 | |
---|
735 | fileArletty = dataPath + "/" + createFileName( dateFormatFinal , "arletty", shortName ); |
---|
736 | fileECMWF = dataPath + "/" + createFileName( dateFormatFinal, "ecmwf", shortName ); |
---|
737 | |
---|
738 | final Element arlettyFile = new Element( "arletty_file" ); |
---|
739 | arlettyFile.setText( fileArletty ); |
---|
740 | atmosphere.addContent( arlettyFile ); |
---|
741 | |
---|
742 | final Element ecmwfFile = new Element( "ecmwf_file" ); |
---|
743 | ecmwfFile.setText( fileECMWF ); |
---|
744 | atmosphere.addContent( ecmwfFile ); |
---|
745 | |
---|
746 | listRequest.add( request ); |
---|
747 | }*/ |
---|
748 | |
---|
749 | |
---|
750 | |
---|
751 | |
---|
752 | ///// |
---|
753 | /////// |
---|
754 | |
---|
755 | |
---|
756 | |
---|
757 | tapas.addContent( listRequest ); |
---|
758 | |
---|
759 | String commandePath = servicePath + "/" + fTapas.getId(); |
---|
760 | createXMLFile( document, commandePath, prop ); |
---|
761 | } |
---|
762 | |
---|
763 | @Transactional(readOnly = true) |
---|
764 | public void createUserFtpDir( @NotNull final User user, @NotNull final Properties prop ) |
---|
765 | throws ServiceException |
---|
766 | { |
---|
767 | final String usersPath = prop.getProperty( "users_path" ); |
---|
768 | String commande = "mkdir -p " + usersPath + "/" + user.getEmail(); |
---|
769 | |
---|
770 | try |
---|
771 | { |
---|
772 | EtherHelper.execProcess( commande ); |
---|
773 | } |
---|
774 | catch( FormattedException e ) |
---|
775 | { |
---|
776 | } |
---|
777 | |
---|
778 | EtherHelper.pause( 4000 ); |
---|
779 | |
---|
780 | //commande = "chown -R "+prop.getProperty( "chown_user" )+" "+usersPath+"/"+user.getEmail(); |
---|
781 | commande = "chmod 777 -R " + usersPath + "/" + user.getEmail(); |
---|
782 | |
---|
783 | try |
---|
784 | { |
---|
785 | EtherHelper.execProcess( commande ); |
---|
786 | } |
---|
787 | catch( FormattedException e ) |
---|
788 | { |
---|
789 | } |
---|
790 | |
---|
791 | EtherHelper.pause( 4000 ); |
---|
792 | } |
---|
793 | |
---|
794 | public void createXMLFile( final Document document, final String commandePath, final Properties prop ) |
---|
795 | { |
---|
796 | try |
---|
797 | { |
---|
798 | //creation repertoire commande |
---|
799 | try |
---|
800 | { |
---|
801 | EtherHelper.execProcess( "mkdir -p " + commandePath ); |
---|
802 | } |
---|
803 | catch( FormattedException e ) |
---|
804 | { |
---|
805 | } |
---|
806 | |
---|
807 | EtherHelper.pause( 5000 ); |
---|
808 | |
---|
809 | |
---|
810 | /*try |
---|
811 | { |
---|
812 | EtherHelper.execProcess( "chown "+prop.getProperty( "chown_user" )+" "+commandePath); |
---|
813 | } |
---|
814 | catch( FormattedException e ) |
---|
815 | { |
---|
816 | |
---|
817 | } */ |
---|
818 | |
---|
819 | final String fichier = commandePath + "/" + "request.xml"; |
---|
820 | |
---|
821 | //On utilise ici un affichage classique avec getPrettyFormat() |
---|
822 | final XMLOutputter sortie = new XMLOutputter( Format.getPrettyFormat() ); |
---|
823 | //Remarquez qu'il suffit simplement de créer une instance de FileOutputStream |
---|
824 | //avec en argument le nom du fichier pour effectuer la sérialisation. |
---|
825 | sortie.output( document, new FileOutputStream( fichier ) ); |
---|
826 | |
---|
827 | /*try |
---|
828 | { |
---|
829 | EtherHelper.execProcess( "chmod 755 "+commandePath+"/"+"request.xml" ); |
---|
830 | } |
---|
831 | catch( FormattedException e ) |
---|
832 | { |
---|
833 | |
---|
834 | } |
---|
835 | |
---|
836 | EtherHelper.pause(7000); |
---|
837 | */ |
---|
838 | } |
---|
839 | catch( IOException ignored ) |
---|
840 | { |
---|
841 | } |
---|
842 | } |
---|
843 | |
---|
844 | // liste tous observatoires |
---|
845 | @Nullable |
---|
846 | @Transactional(readOnly = true) |
---|
847 | public List<Observatory> getAllObservatories() |
---|
848 | throws ServiceException |
---|
849 | { |
---|
850 | try |
---|
851 | { |
---|
852 | return _observatoryDAO.getAllObservatories(); |
---|
853 | } |
---|
854 | catch( PersistenceException e ) |
---|
855 | { |
---|
856 | throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); |
---|
857 | } |
---|
858 | } |
---|
859 | |
---|
860 | // recuperation infos observatoire avec l'id |
---|
861 | @Nullable |
---|
862 | @Transactional(readOnly = true) |
---|
863 | public Observatory getObservatoryById( @NotNull final long id ) |
---|
864 | throws ServiceException |
---|
865 | { |
---|
866 | try |
---|
867 | { |
---|
868 | return _observatoryDAO.getObservatoryById( id ); |
---|
869 | } |
---|
870 | catch( PersistenceException e ) |
---|
871 | { |
---|
872 | throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | // recuperation infos observatoire avec le nom |
---|
877 | @Nullable |
---|
878 | @Transactional(readOnly = true) |
---|
879 | public Observatory getObservatoryByName( @NotNull final String name ) |
---|
880 | throws ServiceException |
---|
881 | { |
---|
882 | try |
---|
883 | { |
---|
884 | return _observatoryDAO.getObservatoryByName( name ); |
---|
885 | } |
---|
886 | catch( PersistenceException e ) |
---|
887 | { |
---|
888 | throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); |
---|
889 | } |
---|
890 | } |
---|
891 | |
---|
892 | // recuperation infos observatoire avec le nom |
---|
893 | @Nullable |
---|
894 | @Transactional(readOnly = true) |
---|
895 | public Long getNumRequest() |
---|
896 | throws ServiceException |
---|
897 | { |
---|
898 | try |
---|
899 | { |
---|
900 | return _tapasRequestDAO.getNumRequest() + 1; |
---|
901 | } |
---|
902 | catch( PersistenceException e ) |
---|
903 | { |
---|
904 | throw new ServiceException( ServiceException.ServiceCode.REQUEST_NOT_FOUND, e ); |
---|
905 | } |
---|
906 | } |
---|
907 | |
---|
908 | /* public String findMeasureHour( String date ) |
---|
909 | { |
---|
910 | String heure; |
---|
911 | int val; |
---|
912 | |
---|
913 | |
---|
914 | val = Math.abs( Integer.parseInt( heure ) ); |
---|
915 | |
---|
916 | return heure; |
---|
917 | } */ |
---|
918 | |
---|
919 | public String createFileName( String date, String type, String nomCourt ) |
---|
920 | { |
---|
921 | String fileName = ""; |
---|
922 | |
---|
923 | String annee = date.substring( 0, 4 ); |
---|
924 | //String mois = String.valueOf( Integer.parseInt(date.substring(5,7))-1); |
---|
925 | String mois = date.substring( 5, 7 ); |
---|
926 | String heure = date.substring( 11, 13 ); |
---|
927 | String jour = date.substring( 8, 10 ); |
---|
928 | String ind = ""; |
---|
929 | |
---|
930 | Calendar cal = Calendar.getInstance(); |
---|
931 | |
---|
932 | try |
---|
933 | { |
---|
934 | Date dd = new SimpleDateFormat( "dd/MM/yyyy HH:mm:ss" ).parse( jour + "/" + mois + "/" + annee + " " + heure + ":00:00" ); |
---|
935 | cal.setTime( dd ); |
---|
936 | } |
---|
937 | catch( ParseException e ) |
---|
938 | { |
---|
939 | } |
---|
940 | |
---|
941 | int iheure = cal.get( Calendar.HOUR_OF_DAY );// + 2; |
---|
942 | |
---|
943 | if( iheure < 3 ) ind = "00"; |
---|
944 | else if( iheure >= 21 ) |
---|
945 | { |
---|
946 | ind = "00"; |
---|
947 | cal.add( Calendar.DAY_OF_MONTH, +1 ); |
---|
948 | } |
---|
949 | else if( Math.abs( 6 - iheure ) < 3 || iheure == 3 ) ind = "06"; |
---|
950 | else if( Math.abs( 12 - iheure ) < 3 || iheure == 9 ) ind = "12"; |
---|
951 | else if( Math.abs( 18 - iheure ) < 3 || iheure == 15 ) ind = "18"; |
---|
952 | |
---|
953 | //+1 sur le mois pour recuperer le numero correct du mois considere |
---|
954 | if( cal.get( Calendar.MONTH ) + 1 < 10 ) mois = "0" + String.valueOf( cal.get( Calendar.MONTH ) + 1 ); |
---|
955 | else mois = "" + String.valueOf( cal.get( Calendar.MONTH ) + 1 ); |
---|
956 | |
---|
957 | if( cal.get( Calendar.DAY_OF_MONTH ) < 10 ) jour = "0" + cal.get( Calendar.DAY_OF_MONTH ); |
---|
958 | else jour = "" + cal.get( Calendar.DAY_OF_MONTH ); |
---|
959 | |
---|
960 | annee = "" + cal.get( Calendar.YEAR ); |
---|
961 | |
---|
962 | //fileName = "/" + annee + "/" + mois + "/" + jour + "/" + nomCourt + "_" + annee + mois + jour + ind; |
---|
963 | fileName="/"+type+"/" + nomCourt + "_" + annee + mois + jour + ind; |
---|
964 | |
---|
965 | if( type == "arletty" ) fileName = fileName + ".arl"; |
---|
966 | else if( type == "ecmwf" ) fileName = fileName + "_qo3.txt"; |
---|
967 | |
---|
968 | return fileName; |
---|
969 | } |
---|
970 | |
---|
971 | public boolean execAppelQSub( final String repCommande, User user, Properties prop ) |
---|
972 | throws ServiceException |
---|
973 | { |
---|
974 | String commande = ""; |
---|
975 | String commandePath = prop.getProperty( "service_path" ) + "/" + repCommande + "/"; |
---|
976 | |
---|
977 | //copie run qsub dans repertoire commande |
---|
978 | commande = "cp " + prop.getProperty( "src_path" ) + "/" + prop.getProperty( "process_name" ) + " " + commandePath; |
---|
979 | |
---|
980 | try |
---|
981 | { |
---|
982 | EtherHelper.execProcess( commande ); |
---|
983 | } |
---|
984 | catch( FormattedException e ) |
---|
985 | { |
---|
986 | } |
---|
987 | |
---|
988 | EtherHelper.pause( 7000 ); |
---|
989 | |
---|
990 | //final String fichier = commandePath+"commande.txt"; |
---|
991 | |
---|
992 | /*commande="chown -R www:www "+commandePath; |
---|
993 | |
---|
994 | try |
---|
995 | { |
---|
996 | EtherHelper.execProcess( commande ); |
---|
997 | } |
---|
998 | catch( FormattedException e ) |
---|
999 | { |
---|
1000 | |
---|
1001 | }*/ |
---|
1002 | |
---|
1003 | EtherHelper.pause( 7000 ); |
---|
1004 | |
---|
1005 | commande = "chmod 777 -R " + commandePath; |
---|
1006 | |
---|
1007 | try |
---|
1008 | { |
---|
1009 | EtherHelper.execProcess( commande ); |
---|
1010 | } |
---|
1011 | catch( FormattedException e ) |
---|
1012 | { |
---|
1013 | } |
---|
1014 | |
---|
1015 | EtherHelper.pause( 7000 ); |
---|
1016 | |
---|
1017 | //execution qsub pour la commande en cours |
---|
1018 | commande = commandePath + "/" + prop.getProperty( "process_name" ) + " -f request.xml" + " -m " + user.getEmail(); |
---|
1019 | |
---|
1020 | /*PrintWriter out = null; |
---|
1021 | try |
---|
1022 | { |
---|
1023 | out = new PrintWriter(new FileWriter(fichier)); |
---|
1024 | out.println(commande); |
---|
1025 | out.close(); |
---|
1026 | } |
---|
1027 | catch( IOException e ) |
---|
1028 | { |
---|
1029 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
---|
1030 | } */ |
---|
1031 | |
---|
1032 | |
---|
1033 | /*commande = commandePath+"/"+prop.getProperty( "process_name" ); |
---|
1034 | commande = "cd "+commandePath;*/ |
---|
1035 | |
---|
1036 | try |
---|
1037 | { |
---|
1038 | EtherHelper.execProcess( commande ); |
---|
1039 | } |
---|
1040 | catch( FormattedException e ) |
---|
1041 | { |
---|
1042 | throw new ServiceException( ServiceException.ServiceCode.ERROR_PROCESS, e ); |
---|
1043 | } |
---|
1044 | |
---|
1045 | EtherHelper.pause( 7000 ); |
---|
1046 | |
---|
1047 | return true; |
---|
1048 | } |
---|
1049 | |
---|
1050 | @NotNull |
---|
1051 | @Transactional(rollbackFor = Exception.class) |
---|
1052 | public Long insertTapasRequest( @NotNull final User user ) |
---|
1053 | throws ServiceException |
---|
1054 | { |
---|
1055 | try |
---|
1056 | { |
---|
1057 | String dd = "1"; |
---|
1058 | |
---|
1059 | final TapasRequest ntp = new TapasRequest( user.getFirstName(), user.getLastName(), dd, _tapasRequestDAO.getNumRequest() + 1 ); |
---|
1060 | return _tapasRequestDAO.insert( ntp ); |
---|
1061 | } |
---|
1062 | catch( PersistenceException e ) |
---|
1063 | { |
---|
1064 | throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e ); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | |
---|
1068 | @Transactional(readOnly = true) |
---|
1069 | public void updateRequestGasTrace(Request iRequest, Pair<String, String> oldValuesCO2, Pair<String, String> oldValuesO2, Pair<String, String> oldValuesO3, Pair<String, String> oldValuesCH4, Pair<String, String> oldValuesN2O, Pair<String, String> oldValuesH20) |
---|
1070 | throws ServiceException |
---|
1071 | { |
---|
1072 | iRequest.getPreference().setCo2Extinction(oldValuesCO2); |
---|
1073 | iRequest.getPreference().setO2Extinction(oldValuesO2); |
---|
1074 | iRequest.getPreference().setO3Extinction(oldValuesO3); |
---|
1075 | iRequest.getPreference().setCh4Extinction(oldValuesCH4); |
---|
1076 | iRequest.getPreference().setN2oExtinction(oldValuesN2O); |
---|
1077 | iRequest.getPreference().setH2oExtinction(oldValuesH20); |
---|
1078 | } |
---|
1079 | |
---|
1080 | @Transactional(readOnly = true) |
---|
1081 | public Request addNewRequest( @NotNull Request iRequest, @NotNull int id, String specie) |
---|
1082 | throws ServiceException |
---|
1083 | { |
---|
1084 | Request cpRequest = new Request(); |
---|
1085 | cpRequest.setId( new Long(id) ); |
---|
1086 | |
---|
1087 | cpRequest.setPreference( new Preference() ); |
---|
1088 | |
---|
1089 | cpRequest.getPreference().setCo2Extinction( new Pair<String, String>("YES,NO","NO") ); |
---|
1090 | cpRequest.getPreference().setO2Extinction( new Pair<String, String>( "YES,NO", "NO" ) ); |
---|
1091 | cpRequest.getPreference().setO3Extinction( new Pair<String, String>( "YES,NO", "NO" ) ); |
---|
1092 | cpRequest.getPreference().setCh4Extinction( new Pair<String, String>( "YES,NO", "NO" ) ); |
---|
1093 | cpRequest.getPreference().setN2oExtinction( new Pair<String, String>( "YES,NO", "NO" ) ); |
---|
1094 | cpRequest.getPreference().setH2oExtinction( new Pair<String, String>( "YES,NO", "NO" ) ); |
---|
1095 | |
---|
1096 | |
---|
1097 | cpRequest.getPreference().setBervCorrection( iRequest.getPreference().getBervCorrection() ); |
---|
1098 | cpRequest.getPreference().setFormat( iRequest.getPreference().getFormat() ); |
---|
1099 | cpRequest.getPreference().setRayleighExtinction( iRequest.getPreference().getRayleighExtinction() ); |
---|
1100 | |
---|
1101 | |
---|
1102 | cpRequest.setAtmosphere( iRequest.getAtmosphere() ); |
---|
1103 | cpRequest.setObservation( iRequest.getObservation() ); |
---|
1104 | |
---|
1105 | if ( specie.equalsIgnoreCase("CO2") ) cpRequest.getPreference().setCo2Extinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1106 | if ( specie.equalsIgnoreCase("O2") ) cpRequest.getPreference().setO2Extinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1107 | if ( specie.equalsIgnoreCase("O3") ) cpRequest.getPreference().setO3Extinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1108 | if ( specie.equalsIgnoreCase("CH4") ) cpRequest.getPreference().setCh4Extinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1109 | if ( specie.equalsIgnoreCase("N2O") ) cpRequest.getPreference().setN2oExtinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1110 | if ( specie.equalsIgnoreCase("H2O") ) { |
---|
1111 | cpRequest.getPreference().setH2oExtinction( new Pair<String, String>( "YES,NO","YES" ) ); |
---|
1112 | } |
---|
1113 | |
---|
1114 | return cpRequest; |
---|
1115 | } |
---|
1116 | |
---|
1117 | @Required |
---|
1118 | public void setObservatoryDAO( final ObservatoryDAO observatoryDAO ) |
---|
1119 | { |
---|
1120 | _observatoryDAO = observatoryDAO; |
---|
1121 | } |
---|
1122 | |
---|
1123 | @Required |
---|
1124 | public void setTapasRequestDAO( final TapasRequestDAO tapasRequestDAO ) |
---|
1125 | { |
---|
1126 | _tapasRequestDAO = tapasRequestDAO; |
---|
1127 | } |
---|
1128 | |
---|
1129 | private static final Log LOGGER = LogFactory.getLog( TapasServiceImpl.class ); |
---|
1130 | |
---|
1131 | private ObservatoryDAO _observatoryDAO; |
---|
1132 | |
---|
1133 | private TapasRequestDAO _tapasRequestDAO; |
---|
1134 | } |
---|