Changeset 470 for tapas/service


Ignore:
Timestamp:
04/06/12 17:01:41 (12 years ago)
Author:
rboipsl
Message:

debut dev creation experiment file names

Location:
tapas/service
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tapas/service/implementation/com/ether/TapasServiceImpl.java

    r466 r470  
    66import com.ether.tapas.Request; 
    77import com.ether.tapas.Tapas; 
     8import com.ether.user.User; 
    89import org.apache.commons.logging.Log; 
    910import org.apache.commons.logging.LogFactory; 
     
    1819import org.springframework.transaction.annotation.Transactional; 
    1920 
     21 
     22import java.io.File; 
     23import java.io.FileInputStream; 
    2024import java.io.FileOutputStream; 
     25import java.io.IOException; 
     26import java.lang.reflect.Array; 
    2127import java.util.List; 
     28import java.util.Properties; 
    2229 
    2330/** 
     
    3037{ 
    3138    @Transactional(readOnly = true) 
    32     public void createXMLRequest( @NotNull final Tapas fTapas ) 
     39    public void createXMLRequest( @NotNull final Tapas fTapas, @NotNull final User user ) 
    3340            throws ServiceException 
    3441    { 
     
    6774            final Attribute validF = new Attribute( "valid", "ACII,FITS,NETCDF" ); 
    6875            format.setAttribute( validF ); 
    69             format.setText( iRequest.getPreference().getFormat().getSecondValue()); 
     76            format.setText( iRequest.getPreference().getFormat().getSecondValue() ); 
    7077            preferences.addContent( format ); 
    7178 
     
    7582            Attribute validR = new Attribute( "valid", "YES,NO" ); 
    7683            rayleighExtinction.setAttribute( validR ); 
    77             rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue()); 
     84            rayleighExtinction.setText( iRequest.getPreference().getRayleighExtinction().getSecondValue() ); 
    7885            preferences.addContent( rayleighExtinction ); 
    7986 
    8087            //h2o 
    8188            final Element h2oe = new Element( "h2o_extinction" ); 
    82             validR = new Attribute( "valid", "YES,NO"); 
     89            validR = new Attribute( "valid", "YES,NO" ); 
    8390            h2oe.setAttribute( validR ); 
    8491            h2oe.setText( iRequest.getPreference().getH2oExtinction().getSecondValue() ); 
     
    8794            //o2 
    8895            final Element o2e = new Element( "o2_extinction" ); 
    89             validR = new Attribute( "valid", "YES,NO"); 
     96            validR = new Attribute( "valid", "YES,NO" ); 
    9097            o2e.setAttribute( validR ); 
    9198            o2e.setText( iRequest.getPreference().getO2Extinction().getSecondValue() ); 
     
    94101            //o3 
    95102            final Element o3e = new Element( "o3_extinction" ); 
    96             validR = new Attribute( "valid", "YES,NO"); 
     103            validR = new Attribute( "valid", "YES,NO" ); 
    97104            o3e.setAttribute( validR ); 
    98             o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue()); 
     105            o3e.setText( iRequest.getPreference().getO3Extinction().getSecondValue() ); 
    99106            preferences.addContent( o3e ); 
    100107 
    101108            //co2 
    102109            final Element co2e = new Element( "co2_extinction" ); 
    103             validR = new Attribute( "valid", "YES,NO"); 
     110            validR = new Attribute( "valid", "YES,NO" ); 
    104111            co2e.setAttribute( validR ); 
    105112            co2e.setText( iRequest.getPreference().getCo2Extinction().getSecondValue() ); 
     
    116123            // date mesure 
    117124            final Element mdate = new Element( "date" ); 
    118             mdate.setText( iRequest.getObservation().getDate()); 
     125            mdate.setText( iRequest.getObservation().getDate() ); 
    119126 
    120127            observation.addContent( mdate ); 
     
    131138            catch( PersistenceException e ) 
    132139            { 
    133                 throw new ServiceException(ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND,e); 
     140                throw new ServiceException( ServiceException.ServiceCode.OBSERVATORY_NOT_FOUND, e ); 
    134141            } 
    135142 
    136143 
    137144            final Element name = new Element( "name" ); 
    138             name.setText(obs.getName()); 
     145            name.setText( obs.getName() ); 
    139146            observatory.addContent( name ); 
    140147 
     
    148155 
    149156            final Element altitude = new Element( "altitude" ); 
    150             altitude.setText( obs.getAltitude().toString()); 
     157            altitude.setText( obs.getAltitude().toString() ); 
    151158            observatory.addContent( altitude ); 
    152  
    153159 
    154160 
     
    161167            los.addContent( ra_j2000 ); 
    162168 
    163             final Element dec_j2000  = new Element( "dec_j2000" ); 
     169            final Element dec_j2000 = new Element( "dec_j2000" ); 
    164170            dec_j2000.setText( iRequest.getObservation().getLos().getDecJ2000() ); 
    165171            los.addContent( dec_j2000 ); 
     
    173179            zenith_angle.setAttribute( a2 ); 
    174180 
    175             zenith_angle.setText( iRequest.getObservation().getLos().getZenithAngle()); 
     181            zenith_angle.setText( iRequest.getObservation().getLos().getZenithAngle() ); 
    176182 
    177183            los.addContent( zenith_angle ); 
     
    183189 
    184190            final Element spectral_choice = new Element( "spectral_choice" ); 
    185             Attribute a3 = new Attribute( "valid", iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue()); 
     191 
     192 
     193            final String[] tabMess = iRequest.getObservation().getInstrument().getSpectralChoice().getFirstValue().split( "," ); 
     194 
     195            String chValid = ""; 
     196            int i; 
     197 
     198            for( i = 0; i <= tabMess.length - 1; i++ ) //final String mess : tabMess ) 
     199            { 
     200 
     201                if( i == tabMess.length - 1 ) 
     202                    chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ); 
     203                else chValid += EtherHelper.getMessage( "label.spectralUnit." + tabMess[i], null ) + ","; 
     204            } 
     205 
     206 
     207            Attribute a3 = new Attribute( "valid", chValid ); 
     208 
    186209            spectral_choice.setAttribute( a3 ); 
    187             spectral_choice.setText( iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue()); 
     210            final String message = EtherHelper.getMessage( "label.spectralUnit." + iRequest.getObservation().getInstrument().getSpectralChoice().getSecondValue(), null ); 
     211            spectral_choice.setText( message ); 
    188212            instrument.addContent( spectral_choice ); 
    189213 
    190  
     214            final Element spectral_range = new Element( "spectral_range" ); 
     215            spectral_range.setText( iRequest.getObservation().getInstrument().getSpectralRange() ); 
     216            instrument.addContent( spectral_range ); 
     217 
     218 
     219            // 
     220            final Element ilsfChoice = new Element( "ilsfChoice" ); 
     221            validR = new Attribute( "valid", iRequest.getObservation().getInstrument().getIlsfChoice().getFirstValue() ); 
     222            ilsfChoice.setAttribute( validR ); 
     223            //selectInstrumentalFunctions 
     224            ilsfChoice.setText( String.valueOf( iRequest.getObservation().getInstrument().getIlsfChoice().getSecondValue() ) ); 
     225            instrument.addContent( ilsfChoice ); 
     226 
     227 
     228            final Element resolvingPower = new Element( "resolving_power" ); 
     229            validR = new Attribute( "min", "0" ); 
     230            resolvingPower.setAttribute( validR ); 
     231            resolvingPower.setText( String.valueOf( iRequest.getObservation().getInstrument().getResolvingPower().getSecondValue() ) ); 
     232            instrument.addContent( resolvingPower ); 
     233 
     234            final Element samplingRatio = new Element( "sampling_ratio" ); 
     235            validR = new Attribute( "min", "0" ); 
     236            samplingRatio.setAttribute( validR ); 
     237            samplingRatio.setText( String.valueOf( iRequest.getObservation().getInstrument().getSamplingRatio().getSecondValue() ) ); 
     238            instrument.addContent( samplingRatio ); 
    191239 
    192240            request.addContent( observation ); 
     241 
     242            //atmosphere 
     243            final Element atmosphere = new Element( "atmosphere" ); 
     244            request.addContent( atmosphere ); 
     245 
     246            //reference 
     247            final Element reference = new Element( "reference" ); 
     248            validR = new Attribute( "valid", "0,1,2,3,4,5,6" ); 
     249            reference.setAttribute( validR ); 
     250            reference.setText( String.valueOf( iRequest.getAtmosphere().getReference().getSecondValue() ) ); 
     251            atmosphere.addContent( reference ); 
     252 
     253            final Properties prop = new Properties(); 
     254            try 
     255            { 
     256                prop.load( new FileInputStream( "/home_local/workspace/tapas.properties" ) ); 
     257            } 
     258            catch( IOException e ) 
     259            { 
     260                throw new ServiceException( ServiceException.ServiceCode.PROPERTIES_FILE_NOT_FOUND, e ); 
     261            } 
     262 
     263            final String rootPath = prop.getProperty( "root_file_path" ); 
     264            final String userPath = ""; 
     265 
     266 
     267            String fileArletty = "", fileECMWF = ""; 
     268            fileArletty = rootPath + "/" + user.getLastName() + "/" + createFileName( iRequest.getObservation().getDate(), "arletty" ); 
     269            fileECMWF = rootPath + "/" + user.getLastName() + "/" + createFileName( iRequest.getObservation().getDate(), "ecmwf" ); 
     270 
     271 
     272            final Element arlettyFile = new Element( "arletty_file" ); 
     273            arlettyFile.setText( fileArletty ); 
     274            atmosphere.addContent( arlettyFile ); 
     275 
     276            final Element ecmwfFile = new Element( "ecmwf_file" ); 
     277            ecmwfFile.setText( fileECMWF ); 
     278            atmosphere.addContent( ecmwfFile ); 
     279 
    193280 
    194281            //creer le nom des fichiers input ECMW F + ARLETTY à partir du nom court de l'observatoire 
     
    203290        createXMLFile( fichier, document ); 
    204291    } 
     292 
     293 
     294 /*   public String findMeasureHour( String date ) 
     295    { 
     296        String heure; 
     297        int val; 
     298 
     299 
     300        val = Math.abs( Integer.parseInt( heure ) ); 
     301 
     302        return heure; 
     303    }                    */ 
     304 
     305    public String createFileName( String date, String type ) 
     306    { 
     307 
     308        String fileName = "test_"+type+"_"+date+".txt"; 
     309 
     310 
     311        /*String heure = date.substring( 4, 6 ); 
     312 
     313        int iheure = Math.abs( Integer.parseInt( heure ) ); 
     314 
     315 
     316        if( iheure < 3) ind = "00"; 
     317        else if ( iheure >= 21) { 
     318            ind = "00"; 
     319        } 
     320        else if( Math.abs(6-iheure) < 3) ind = "06"; 
     321        else if( Math.abs(12 - iheure) < 3) ind = "12"; 
     322        else if( Math.abs(18 - iheure) < 3 ) ind = "18"; 
     323 
     324 
     325        if( type == "arletty" ) fileName = "arletty_" + date + ".txt"; 
     326        else if( type == "ecmwf" ) fileName = "ecmwf_" + date + ".txt"; 
     327        */ 
     328 
     329 
     330        return fileName; 
     331    } 
     332 
    205333 
    206334    public void createXMLFile( final String fichier, final Document document ) 
  • tapas/service/interface/com/ether/ServiceException.java

    r419 r470  
    2424        OBSERVATORY_NOT_FOUND, 
    2525        USER_NOT_FOUND, 
     26        PROPERTIES_FILE_NOT_FOUND; 
    2627    } 
    2728} 
  • tapas/service/interface/com/ether/TapasService.java

    r466 r470  
    33import com.ether.tapas.Observatory; 
    44import com.ether.tapas.Tapas; 
     5import com.ether.user.User; 
    56import org.jdom.Document; 
    67import org.jetbrains.annotations.NotNull; 
     
    1718{ 
    1819 
    19     public void createXMLRequest( @NotNull final Tapas tapas ) 
     20    public void createXMLRequest( @NotNull final Tapas tapas, @NotNull final User user ) 
    2021            throws ServiceException; 
    2122 
     
    2829    public Long getNumRequest() throws ServiceException; 
    2930 
     31    public String createFileName(String date, String type) throws ServiceException; 
     32 
    3033} 
Note: See TracChangeset for help on using the changeset viewer.