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