package com.ether; import com.ether.dao.ObservatoryDAO; import com.ether.dao.TapasRequestDAO; import com.ether.tapas.Los; import com.ether.tapas.Location; import com.ether.tapas.Observation; import com.ether.tapas.Observatory; import com.ether.tapas.Preference; import com.ether.tapas.Request; import com.ether.tapas.Tapas; import com.ether.tapas.TapasRequest; import com.ether.user.User; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Required; import org.springframework.transaction.annotation.Transactional; import java.io.FileOutputStream; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; //import java.sql.Date; /** * @author rboipsl * @date 2 mars 2012 */ public class TapasServiceImpl extends BackofficeServiceImpl implements TapasService { @Transactional(readOnly = true) public void createXMLRequest( @NotNull final Tapas fTapas, @NotNull final Properties prop ) throws ServiceException { final String servicePath = prop.getProperty( "service_path" ); //final String srcPath = prop.getProperty( "src_path" ); final String dataPath = prop.getProperty( "data_path" ); //final String fichier = servicePath + "/" + "request.xml"; final Element tapas = new Element( "tapas" ); final List listRequest = new ArrayList( fTapas.getRequests().size() ); //On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer final Document document = new Document( tapas ); //recuperation valeur id requete (bdd table tapas_request) fTapas.setId( "Ether_TAPAS_" + String.valueOf( getNumRequest() ) ); final Attribute id = new Attribute( "Id", fTapas.getId() ); tapas.setAttribute( id ); //a terme devient une boucle final List requests = fTapas.getRequests(); Request xRequest, nRequest; String iname; Iterator iter = requests.iterator(); int iii = requests.size(); int inr = 0; int indice = 1; //Request xRequest = iter.next(); String oneTransmission; while ( indice <= iii ) { nRequest = iter.next(); nRequest.setValid( 1 ); oneTransmission = nRequest.getPreference().getOneTransmission().getSecondValue(); if( oneTransmission.equalsIgnoreCase( "NO" ) ) { nRequest.setValid( -1 ); if( nRequest.getPreference().getH2oExtinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "H2O") ); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } if( nRequest.getPreference().getCh4Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "CH4" ) ); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } if( nRequest.getPreference().getCo2Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "CO2" ) ); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } if( nRequest.getPreference().getN2oExtinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "N2O" ) ); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } if( nRequest.getPreference().getO2Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "O2" ) ); iter = requests.iterator(); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } if( nRequest.getPreference().getO3Extinction().getSecondValue().equalsIgnoreCase( "Yes" ) ) { requests.add( addNewRequest( nRequest, (iii+inr+1), "O3" ) ); iter = requests.iterator(); inr = inr + 1; iter = requests.iterator(); /*for ( int i=1 ; i <= (iii+inr) ; i++ ) { nRequest = iter.next(); }*/ } } iter = requests.iterator(); indice=indice+1; for (int i = 1 ; i < indice ; i++) { nRequest = iter.next(); } } indice=1; //// for( final Request iRequest : requests ) { if (iRequest.getValid() != -1) { final Element request = new Element( "request" ); // Id de la request //final Attribute idR = new Attribute( "Id", (Long) iRequest.getId().toString() ); final Attribute idR = new Attribute( "Id", String.valueOf(indice) ); request.setAttribute( idR ); // PREFERENCES final Element preferences = new Element( "preferences" ); //format final Element format = new Element( "format" ); //final Attribute validF = new Attribute( "valid", iRequest.getPreference().getFormat().getFirstValue() ); final Attribute validF = new Attribute( "valid", "VO,ASCII,FITS,NETCDF" ); format.setAttribute( validF ); format.setText( iRequest.getPreference().getFormat().getSecondValue() ); preferences.addContent( format ); //rayleighExtinction final Element rayleighExtinction = new Element( "rayleigh_extinction" ); //final Attribute validR = new Attribute( "valid", iRequest.getPreference().getRayleighExtinction().getFirstValue() ); Attribute validR = new Attribute( "valid", "YES,NO" ); rayleighExtinction.setAttribute( validR ); rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue() ); preferences.addContent( rayleighExtinction ); //h2o final Element h2oe = new Element( "h2o_extinction" ); validR = new Attribute( "valid", "YES,NO" ); h2oe.setAttribute( validR ); h2oe.setText( iRequest.getPreference().getH2oExtinction().getSecondValue() ); preferences.addContent( h2oe ); //o3 final Element o3e = new Element( "o3_extinction" ); validR = new Attribute( "valid", "YES,NO" ); o3e.setAttribute( validR ); o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue() ); preferences.addContent( o3e ); //o2 final Element o2e = new Element( "o2_extinction" ); validR = new Attribute( "valid", "YES,NO" ); o2e.setAttribute( validR ); o2e.setText( iRequest.getPreference().getO2Extinction().getSecondValue() ); preferences.addContent( o2e ); //co2 final Element co2e = new Element( "co2_extinction" ); validR = new Attribute( "valid", "YES,NO" ); co2e.setAttribute( validR ); co2e.setText( iRequest.getPreference().getCo2Extinction().getSecondValue() ); preferences.addContent( co2e ); //ch4 final Element ch4e = new Element( "ch4_extinction" ); validR = new Attribute( "valid", "YES,NO" ); ch4e.setAttribute( validR ); ch4e.setText( iRequest.getPreference().getCh4Extinction().getSecondValue() ); preferences.addContent( ch4e ); //no2 final Element n2oe = new Element( "n2o_extinction" ); validR = new Attribute( "valid", "YES,NO" ); n2oe.setAttribute( validR ); n2oe.setText( iRequest.getPreference().getN2oExtinction().getSecondValue() ); preferences.addContent( n2oe ); request.addContent( preferences ); // OBSERVATORIES final Element observation = new Element( "observation" ); // date mesure final Element mdate = new Element( "date" ); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis( Long.valueOf( iRequest.getObservation().getDate() ) ); final String dateFormatFinal=DateHelper.formatDate( calendar.getTime(), DateHelper.DATE_UTC ); mdate.setText( dateFormatFinal ); //mdate.setText( iRequest.getObservation().getDate() ); observation.addContent( mdate ); //observatoire ou lieu libre en indiquant alt,lat,lon final Element observatory = new Element( "observatory" ); observation.addContent( observatory ); //recuperation des coordonnées de l'observatoire final Observatory obs; try { //obs = _observatoryDAO.selectByPrimaryKey( iRequest.getObservation().getObservatory().getId() ); obs = _observatoryDAO.getObservatoryByName( iRequest.getObservation().getObservatory().getName() ); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); } ////// a tester //// final Element name = new Element( "name" ); final Element longitude = new Element( "longitude" ); validR = new Attribute( "min", "-180" ); longitude.setAttribute( validR ); validR = new Attribute( "max", "180" ); longitude.setAttribute( validR ); final Element latitude = new Element( "latitude" ); validR = new Attribute( "min", "-90" ); latitude.setAttribute( validR ); validR = new Attribute( "max", "90" ); latitude.setAttribute( validR ); final Element altitude = new Element( "altitude" ); validR = new Attribute( "min", "0" ); altitude.setAttribute( validR ); validR = new Attribute( "max", "10000" ); altitude.setAttribute( validR ); String shortName=""; if (null == obs) { //lieu libre name.setText(iRequest.getObservation().getLocation().getName()); altitude.setText( iRequest.getObservation().getLocation().getAltitude().toString() ); latitude.setText( iRequest.getObservation().getLocation().getLatitude().toString() ); longitude.setText( iRequest.getObservation().getLocation().getLongitude().toString() ); shortName = iRequest.getObservation().getLocation().getName(); } else { //observatoire connu de la bdd tapas name.setText( obs.getName() ); longitude.setText( obs.getLongitude().toString() ); latitude.setText( obs.getLatitude().toString() ); altitude.setText( obs.getAltitude().toString() ); shortName = obs.getShortName().toString(); } observatory.addContent( name ); observatory.addContent( latitude ); observatory.addContent( longitude ); observatory.addContent( altitude ); //los addN final Element los = new Element( "los" ); observation.addContent( los ); Los temp = iRequest.getObservation().getLos(); if ( !temp.getRaJ2000().equals( "" )) { final Element ra_j2000 = new Element( "ra_j2000" ); ra_j2000.setText( iRequest.getObservation().getLos().getRaJ2000() ); los.addContent( ra_j2000 ); } if ( !temp.getDecJ2000().equals( "" )) { final Element dec_j2000 = new Element( "dec_j2000" ); dec_j2000.setText( iRequest.getObservation().getLos().getDecJ2000() ); los.addContent( dec_j2000 ); } if ( !temp.getZenithAngle().equals("") ) { final Element zenith_angle = new Element( "zenith_angle" ); Attribute a1 = new Attribute( "min", "0" ); Attribute a2 = new Attribute( "max", "90" ); zenith_angle.setAttribute( a1 ); zenith_angle.setAttribute( a2 ); zenith_angle.setText( temp.getZenithAngle() ); los.addContent( zenith_angle ); } //instrument final Element instrument = new Element( "instrument" ); observation.addContent( instrument ); final Element spectral_choice = new Element( "spectral_choice" ); final String[] tabMess = iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue().split( "," ); String chValid = ""; int i; for( i = 0; i <= tabMess.length - 1; i++ ) //final String mess : tabMess ) { if( i == tabMess.length - 1 ) chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ); else chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ) + ","; } Attribute a3 = new Attribute( "valid", chValid ); spectral_choice.setAttribute( a3 ); final String message = EtherHelper.getMessage( "label.spectralUnit." + iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue(), null ); spectral_choice.setText( message ); instrument.addContent( spectral_choice ); final Element spectral_range = new Element( "spectral_range" ); spectral_range.setText( iRequest.getObservation().getInstrument().getSpectralRange() ); instrument.addContent( spectral_range ); // final Element ilsfChoice = new Element( "ilsf_choice" ); validR = new Attribute( "valid", iRequest.getObservation().getInstrument().getIlsfChoice().getFirstValue() ); ilsfChoice.setAttribute( validR ); //selectInstrumentalFunctions ilsfChoice.setText( String.valueOf( iRequest.getObservation().getInstrument().getIlsfChoice().getSecondValue() ) ); instrument.addContent( ilsfChoice ); final Element resolvingPower = new Element( "resolving_power" ); validR = new Attribute( "min", "0" ); resolvingPower.setAttribute( validR ); resolvingPower.setText( String.valueOf( iRequest.getObservation().getInstrument().getResolvingPower().getSecondValue() ) ); instrument.addContent( resolvingPower ); final Element samplingRatio = new Element( "sampling_ratio" ); validR = new Attribute( "min", "0" ); samplingRatio.setAttribute( validR ); samplingRatio.setText( String.valueOf( iRequest.getObservation().getInstrument().getSamplingRatio().getSecondValue() ) ); instrument.addContent( samplingRatio ); //berv correction //final Element bervCorr = new Element( "berv_correction" ); final Element bervCorr = new Element( "apply_berv" ); validR = new Attribute( "valid", "YES,NO" ); bervCorr.setAttribute( validR ); bervCorr.setText( iRequest.getPreference().getBervCorrection().getSecondValue() ); instrument.addContent( bervCorr ); request.addContent( observation ); //atmosphere final Element atmosphere = new Element( "atmosphere" ); request.addContent( atmosphere ); //reference final Element reference = new Element( "reference" ); validR = new Attribute( "valid", "0,1,2,3,4,5,6" ); reference.setAttribute( validR ); reference.setText( String.valueOf( iRequest.getAtmosphere().getReference().getSecondValue() ) ); atmosphere.addContent( reference ); String fileArletty = "", fileECMWF = ""; fileArletty = dataPath + "/" + createFileName( dateFormatFinal , "arletty", shortName ); fileECMWF = dataPath + "/" + createFileName( dateFormatFinal, "ecmwf", shortName ); final Element arlettyFile = new Element( "arletty_file" ); arlettyFile.setText( fileArletty ); atmosphere.addContent( arlettyFile ); final Element ecmwfFile = new Element( "ecmwf_file" ); ecmwfFile.setText( fileECMWF ); atmosphere.addContent( ecmwfFile ); listRequest.add( request ); indice=indice+1; } } ////////// ///////// /*for( final Request iRequest : requests ) { final Element request = new Element( "request" ); // Id de la request final Attribute idR = new Attribute( "Id", iRequest.getId().toString() ); request.setAttribute( idR ); // PREFERENCES final Element preferences = new Element( "preferences" ); //format final Element format = new Element( "format" ); //final Attribute validF = new Attribute( "valid", iRequest.getPreference().getFormat().getFirstValue() ); final Attribute validF = new Attribute( "valid", "VO,ASCII,FITS,NETCDF" ); format.setAttribute( validF ); format.setText( iRequest.getPreference().getFormat().getSecondValue() ); preferences.addContent( format ); //rayleighExtinction final Element rayleighExtinction = new Element( "rayleigh_extinction" ); //final Attribute validR = new Attribute( "valid", iRequest.getPreference().getRayleighExtinction().getFirstValue() ); Attribute validR = new Attribute( "valid", "YES,NO" ); rayleighExtinction.setAttribute( validR ); rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue() ); preferences.addContent( rayleighExtinction ); //h2o final Element h2oe = new Element( "h2o_extinction" ); validR = new Attribute( "valid", "YES,NO" ); h2oe.setAttribute( validR ); h2oe.setText( iRequest.getPreference().getH2oExtinction().getSecondValue() ); preferences.addContent( h2oe ); //o3 final Element o3e = new Element( "o3_extinction" ); validR = new Attribute( "valid", "YES,NO" ); o3e.setAttribute( validR ); o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue() ); preferences.addContent( o3e ); //o2 final Element o2e = new Element( "o2_extinction" ); validR = new Attribute( "valid", "YES,NO" ); o2e.setAttribute( validR ); o2e.setText( iRequest.getPreference().getO2Extinction().getSecondValue() ); preferences.addContent( o2e ); //co2 final Element co2e = new Element( "co2_extinction" ); validR = new Attribute( "valid", "YES,NO" ); co2e.setAttribute( validR ); co2e.setText( iRequest.getPreference().getCo2Extinction().getSecondValue() ); preferences.addContent( co2e ); //ch4 final Element ch4e = new Element( "ch4_extinction" ); validR = new Attribute( "valid", "YES,NO" ); ch4e.setAttribute( validR ); ch4e.setText( iRequest.getPreference().getCh4Extinction().getSecondValue() ); preferences.addContent( ch4e ); //no2 final Element n2oe = new Element( "n2o_extinction" ); validR = new Attribute( "valid", "YES,NO" ); n2oe.setAttribute( validR ); n2oe.setText( iRequest.getPreference().getN2oExtinction().getSecondValue() ); preferences.addContent( n2oe ); request.addContent( preferences ); // OBSERVATORIES final Element observation = new Element( "observation" ); // date mesure final Element mdate = new Element( "date" ); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis( Long.valueOf( iRequest.getObservation().getDate() ) ); final String dateFormatFinal=DateHelper.formatDate( calendar.getTime(), DateHelper.DATE_UTC ); mdate.setText( dateFormatFinal ); // mdate.setText( iRequest.getObservation().getDate() ); observation.addContent( mdate ); //observatoire ou lieu libre en indiquant alt,lat,lon final Element observatory = new Element( "observatory" ); observation.addContent( observatory ); //recuperation des coordonnées de l'observatoire final Observatory obs; try { //obs = _observatoryDAO.selectByPrimaryKey( iRequest.getObservation().getObservatory().getId() ); obs = _observatoryDAO.getObservatoryByName( iRequest.getObservation().getObservatory().getName() ); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); } ////// a tester //// final Element name = new Element( "name" ); final Element longitude = new Element( "longitude" ); validR = new Attribute( "min", "-180" ); longitude.setAttribute( validR ); validR = new Attribute( "max", "180" ); longitude.setAttribute( validR ); final Element latitude = new Element( "latitude" ); validR = new Attribute( "min", "-90" ); latitude.setAttribute( validR ); validR = new Attribute( "max", "90" ); latitude.setAttribute( validR ); final Element altitude = new Element( "altitude" ); validR = new Attribute( "min", "0" ); altitude.setAttribute( validR ); validR = new Attribute( "max", "10000" ); altitude.setAttribute( validR ); String shortName=""; if (null == obs) { //lieu libre name.setText(iRequest.getObservation().getLocation().getName()); altitude.setText( iRequest.getObservation().getLocation().getAltitude().toString() ); latitude.setText( iRequest.getObservation().getLocation().getLatitude().toString() ); longitude.setText( iRequest.getObservation().getLocation().getLongitude().toString() ); shortName = iRequest.getObservation().getLocation().getName(); } else { //observatoire connu de la bdd tapas name.setText( obs.getName() ); longitude.setText( obs.getLongitude().toString() ); latitude.setText( obs.getLatitude().toString() ); altitude.setText( obs.getAltitude().toString() ); shortName = obs.getShortName().toString(); } observatory.addContent( name ); observatory.addContent( latitude ); observatory.addContent( longitude ); observatory.addContent( altitude ); //los addN final Element los = new Element( "los" ); observation.addContent( los ); Los temp = iRequest.getObservation().getLos(); if ( !temp.getRaJ2000().equals( "" )) { final Element ra_j2000 = new Element( "ra_j2000" ); ra_j2000.setText( iRequest.getObservation().getLos().getRaJ2000() ); los.addContent( ra_j2000 ); } if ( !temp.getDecJ2000().equals( "" )) { final Element dec_j2000 = new Element( "dec_j2000" ); dec_j2000.setText( iRequest.getObservation().getLos().getDecJ2000() ); los.addContent( dec_j2000 ); } if ( !temp.getZenithAngle().equals("") ) { final Element zenith_angle = new Element( "zenith_angle" ); Attribute a1 = new Attribute( "min", "0" ); Attribute a2 = new Attribute( "max", "90" ); zenith_angle.setAttribute( a1 ); zenith_angle.setAttribute( a2 ); zenith_angle.setText( temp.getZenithAngle() ); los.addContent( zenith_angle ); } //instrument final Element instrument = new Element( "instrument" ); observation.addContent( instrument ); final Element spectral_choice = new Element( "spectral_choice" ); final String[] tabMess = iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue().split( "," ); String chValid = ""; int i; for( i = 0; i <= tabMess.length - 1; i++ ) //final String mess : tabMess ) { if( i == tabMess.length - 1 ) chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ); else chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ) + ","; } Attribute a3 = new Attribute( "valid", chValid ); spectral_choice.setAttribute( a3 ); final String message = EtherHelper.getMessage( "label.spectralUnit." + iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue(), null ); spectral_choice.setText( message ); instrument.addContent( spectral_choice ); final Element spectral_range = new Element( "spectral_range" ); spectral_range.setText( iRequest.getObservation().getInstrument().getSpectralRange() ); instrument.addContent( spectral_range ); // final Element ilsfChoice = new Element( "ilsf_choice" ); validR = new Attribute( "valid", iRequest.getObservation().getInstrument().getIlsfChoice().getFirstValue() ); ilsfChoice.setAttribute( validR ); //selectInstrumentalFunctions ilsfChoice.setText( String.valueOf( iRequest.getObservation().getInstrument().getIlsfChoice().getSecondValue() ) ); instrument.addContent( ilsfChoice ); final Element resolvingPower = new Element( "resolving_power" ); validR = new Attribute( "min", "0" ); resolvingPower.setAttribute( validR ); resolvingPower.setText( String.valueOf( iRequest.getObservation().getInstrument().getResolvingPower().getSecondValue() ) ); instrument.addContent( resolvingPower ); final Element samplingRatio = new Element( "sampling_ratio" ); validR = new Attribute( "min", "0" ); samplingRatio.setAttribute( validR ); samplingRatio.setText( String.valueOf( iRequest.getObservation().getInstrument().getSamplingRatio().getSecondValue() ) ); instrument.addContent( samplingRatio ); //berv correction //final Element bervCorr = new Element( "berv_correction" ); final Element bervCorr = new Element( "apply_berv" ); validR = new Attribute( "valid", "YES,NO" ); bervCorr.setAttribute( validR ); bervCorr.setText( iRequest.getPreference().getBervCorrection().getSecondValue() ); instrument.addContent( bervCorr ); request.addContent( observation ); //atmosphere final Element atmosphere = new Element( "atmosphere" ); request.addContent( atmosphere ); //reference final Element reference = new Element( "reference" ); validR = new Attribute( "valid", "0,1,2,3,4,5,6" ); reference.setAttribute( validR ); reference.setText( String.valueOf( iRequest.getAtmosphere().getReference().getSecondValue() ) ); atmosphere.addContent( reference ); String fileArletty = "", fileECMWF = ""; fileArletty = dataPath + "/" + createFileName( dateFormatFinal , "arletty", shortName ); fileECMWF = dataPath + "/" + createFileName( dateFormatFinal, "ecmwf", shortName ); final Element arlettyFile = new Element( "arletty_file" ); arlettyFile.setText( fileArletty ); atmosphere.addContent( arlettyFile ); final Element ecmwfFile = new Element( "ecmwf_file" ); ecmwfFile.setText( fileECMWF ); atmosphere.addContent( ecmwfFile ); listRequest.add( request ); }*/ ///// /////// tapas.addContent( listRequest ); String commandePath = servicePath + "/" + fTapas.getId(); createXMLFile( document, commandePath, prop ); } @Transactional(readOnly = true) public void createUserFtpDir( @NotNull final User user, @NotNull final Properties prop ) throws ServiceException { final String usersPath = prop.getProperty( "users_path" ); String commande = "mkdir -p " + usersPath + "/" + user.getEmail(); try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { } EtherHelper.pause( 4000 ); //commande = "chown -R "+prop.getProperty( "chown_user" )+" "+usersPath+"/"+user.getEmail(); commande = "chmod 777 -R " + usersPath + "/" + user.getEmail(); try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { } EtherHelper.pause( 4000 ); } public void createXMLFile( final Document document, final String commandePath, final Properties prop ) { try { //creation repertoire commande try { EtherHelper.execProcess( "mkdir -p " + commandePath ); } catch( FormattedException e ) { } EtherHelper.pause( 5000 ); /*try { EtherHelper.execProcess( "chown "+prop.getProperty( "chown_user" )+" "+commandePath); } catch( FormattedException e ) { } */ final String fichier = commandePath + "/" + "request.xml"; //On utilise ici un affichage classique avec getPrettyFormat() final XMLOutputter sortie = new XMLOutputter( Format.getPrettyFormat() ); //Remarquez qu'il suffit simplement de créer une instance de FileOutputStream //avec en argument le nom du fichier pour effectuer la sérialisation. sortie.output( document, new FileOutputStream( fichier ) ); /*try { EtherHelper.execProcess( "chmod 755 "+commandePath+"/"+"request.xml" ); } catch( FormattedException e ) { } EtherHelper.pause(7000); */ } catch( IOException ignored ) { } } // liste tous observatoires @Nullable @Transactional(readOnly = true) public List getAllObservatories() throws ServiceException { try { return _observatoryDAO.getAllObservatories(); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); } } // recuperation infos observatoire avec l'id @Nullable @Transactional(readOnly = true) public Observatory getObservatoryById( @NotNull final long id ) throws ServiceException { try { return _observatoryDAO.getObservatoryById( id ); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); } } // recuperation infos observatoire avec le nom @Nullable @Transactional(readOnly = true) public Observatory getObservatoryByName( @NotNull final String name ) throws ServiceException { try { return _observatoryDAO.getObservatoryByName( name ); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); } } // recuperation infos observatoire avec le nom @Nullable @Transactional(readOnly = true) public Long getNumRequest() throws ServiceException { try { return _tapasRequestDAO.getNumRequest() + 1; } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.REQUEST_NOT_FOUND, e ); } } /* public String findMeasureHour( String date ) { String heure; int val; val = Math.abs( Integer.parseInt( heure ) ); return heure; } */ public String createFileName( String date, String type, String nomCourt ) { String fileName = ""; String annee = date.substring( 0, 4 ); //String mois = String.valueOf( Integer.parseInt(date.substring(5,7))-1); String mois = date.substring( 5, 7 ); String heure = date.substring( 11, 13 ); String jour = date.substring( 8, 10 ); String ind = ""; Calendar cal = Calendar.getInstance(); try { Date dd = new SimpleDateFormat( "dd/MM/yyyy HH:mm:ss" ).parse( jour + "/" + mois + "/" + annee + " " + heure + ":00:00" ); cal.setTime( dd ); } catch( ParseException e ) { } int iheure = cal.get( Calendar.HOUR_OF_DAY );// + 2; if( iheure < 3 ) ind = "00"; else if( iheure >= 21 ) { ind = "00"; cal.add( Calendar.DAY_OF_MONTH, +1 ); } else if( Math.abs( 6 - iheure ) < 3 || iheure == 3 ) ind = "06"; else if( Math.abs( 12 - iheure ) < 3 || iheure == 9 ) ind = "12"; else if( Math.abs( 18 - iheure ) < 3 || iheure == 15 ) ind = "18"; //+1 sur le mois pour recuperer le numero correct du mois considere if( cal.get( Calendar.MONTH ) + 1 < 10 ) mois = "0" + String.valueOf( cal.get( Calendar.MONTH ) + 1 ); else mois = "" + String.valueOf( cal.get( Calendar.MONTH ) + 1 ); if( cal.get( Calendar.DAY_OF_MONTH ) < 10 ) jour = "0" + cal.get( Calendar.DAY_OF_MONTH ); else jour = "" + cal.get( Calendar.DAY_OF_MONTH ); annee = "" + cal.get( Calendar.YEAR ); //fileName = "/" + annee + "/" + mois + "/" + jour + "/" + nomCourt + "_" + annee + mois + jour + ind; fileName="/"+type+"/" + nomCourt + "_" + annee + mois + jour + ind; if( type == "arletty" ) fileName = fileName + ".arl"; else if( type == "ecmwf" ) fileName = fileName + "_qo3.txt"; return fileName; } public boolean execAppelQSub( final String repCommande, User user, Properties prop ) throws ServiceException { String commande = ""; String commandePath = prop.getProperty( "service_path" ) + "/" + repCommande + "/"; //copie run qsub dans repertoire commande commande = "cp " + prop.getProperty( "src_path" ) + "/" + prop.getProperty( "process_name" ) + " " + commandePath; try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { } EtherHelper.pause( 7000 ); //final String fichier = commandePath+"commande.txt"; /*commande="chown -R www:www "+commandePath; try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { }*/ EtherHelper.pause( 7000 ); commande = "chmod 777 -R " + commandePath; try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { } EtherHelper.pause( 7000 ); //execution qsub pour la commande en cours commande = commandePath + "/" + prop.getProperty( "process_name" ) + " -f request.xml" + " -m " + user.getEmail(); /*PrintWriter out = null; try { out = new PrintWriter(new FileWriter(fichier)); out.println(commande); out.close(); } catch( IOException e ) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } */ /*commande = commandePath+"/"+prop.getProperty( "process_name" ); commande = "cd "+commandePath;*/ try { EtherHelper.execProcess( commande ); } catch( FormattedException e ) { throw new ServiceException( ServiceException.ServiceCode.ERROR_PROCESS, e ); } EtherHelper.pause( 7000 ); return true; } @NotNull @Transactional(rollbackFor = Exception.class) public Long insertTapasRequest( @NotNull final User user ) throws ServiceException { try { String dd = "1"; final TapasRequest ntp = new TapasRequest( user.getFirstName(), user.getLastName(), dd, _tapasRequestDAO.getNumRequest() + 1 ); return _tapasRequestDAO.insert( ntp ); } catch( PersistenceException e ) { throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e ); } } @Transactional(readOnly = true) public void updateRequestGasTrace(Request iRequest, Pair oldValuesCO2, Pair oldValuesO2, Pair oldValuesO3, Pair oldValuesCH4, Pair oldValuesN2O, Pair oldValuesH20) throws ServiceException { iRequest.getPreference().setCo2Extinction(oldValuesCO2); iRequest.getPreference().setO2Extinction(oldValuesO2); iRequest.getPreference().setO3Extinction(oldValuesO3); iRequest.getPreference().setCh4Extinction(oldValuesCH4); iRequest.getPreference().setN2oExtinction(oldValuesN2O); iRequest.getPreference().setH2oExtinction(oldValuesH20); } @Transactional(readOnly = true) public Request addNewRequest( @NotNull Request iRequest, @NotNull int id, String specie) throws ServiceException { Request cpRequest = new Request(); cpRequest.setId( new Long(id) ); cpRequest.setPreference( new Preference() ); cpRequest.getPreference().setCo2Extinction( new Pair("YES,NO","NO") ); cpRequest.getPreference().setO2Extinction( new Pair( "YES,NO", "NO" ) ); cpRequest.getPreference().setO3Extinction( new Pair( "YES,NO", "NO" ) ); cpRequest.getPreference().setCh4Extinction( new Pair( "YES,NO", "NO" ) ); cpRequest.getPreference().setN2oExtinction( new Pair( "YES,NO", "NO" ) ); cpRequest.getPreference().setH2oExtinction( new Pair( "YES,NO", "NO" ) ); cpRequest.getPreference().setBervCorrection( iRequest.getPreference().getBervCorrection() ); cpRequest.getPreference().setFormat( iRequest.getPreference().getFormat() ); cpRequest.getPreference().setRayleighExtinction( iRequest.getPreference().getRayleighExtinction() ); cpRequest.setAtmosphere( iRequest.getAtmosphere() ); cpRequest.setObservation( iRequest.getObservation() ); if ( specie.equalsIgnoreCase("CO2") ) cpRequest.getPreference().setCo2Extinction( new Pair( "YES,NO","YES" ) ); if ( specie.equalsIgnoreCase("O2") ) cpRequest.getPreference().setO2Extinction( new Pair( "YES,NO","YES" ) ); if ( specie.equalsIgnoreCase("O3") ) cpRequest.getPreference().setO3Extinction( new Pair( "YES,NO","YES" ) ); if ( specie.equalsIgnoreCase("CH4") ) cpRequest.getPreference().setCh4Extinction( new Pair( "YES,NO","YES" ) ); if ( specie.equalsIgnoreCase("N2O") ) cpRequest.getPreference().setN2oExtinction( new Pair( "YES,NO","YES" ) ); if ( specie.equalsIgnoreCase("H2O") ) { cpRequest.getPreference().setH2oExtinction( new Pair( "YES,NO","YES" ) ); } return cpRequest; } @Required public void setObservatoryDAO( final ObservatoryDAO observatoryDAO ) { _observatoryDAO = observatoryDAO; } @Required public void setTapasRequestDAO( final TapasRequestDAO tapasRequestDAO ) { _tapasRequestDAO = tapasRequestDAO; } private static final Log LOGGER = LogFactory.getLog( TapasServiceImpl.class ); private ObservatoryDAO _observatoryDAO; private TapasRequestDAO _tapasRequestDAO; }