Changeset 389 for tapas/service


Ignore:
Timestamp:
03/02/12 18:07:28 (12 years ago)
Author:
rboipsl
Message:
 
Location:
tapas/service
Files:
7 edited
1 copied

Legend:

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

    r384 r389  
    55import org.apache.commons.logging.Log; 
    66import org.apache.commons.logging.LogFactory; 
     7import org.jdom.*; 
     8import org.jdom.output.Format; 
     9import org.jdom.output.XMLOutputter; 
    710import org.jetbrains.annotations.NotNull; 
    811import org.jetbrains.annotations.Nullable; 
     
    1013import org.springframework.transaction.annotation.Transactional; 
    1114 
     15import java.io.FileOutputStream; 
    1216import java.util.List; 
     17import java.util.prefs.Preferences; 
    1318 
    1419/** 
    15  * @author vmipsl 
    16  * @date 07 mar 2011 
     20 * @author rboipsl 
     21 * @date 2 mars 2012 
    1722 */ 
    1823public class TapasServiceImpl 
    1924        implements TapasService 
    2025{ 
     26 
     27    public void createXMLRequest() 
     28 
     29    { 
     30        String idF = "Ether_TAPAS_0000001"; 
     31        String idRF = "1"; 
     32        String validFF = "ASCII"; 
     33        String validRF = "YES"; 
     34 
     35        String xvalidFF = "ASCII,FITS,NETCDF"; 
     36        String xvalidRF = "YES,NO"; 
     37        String fichier = "request1.xml"; 
     38 
     39        final Element racine = new Element( "tapas" ); 
     40        final Element request = new Element( "request" ); 
     41        final Element preferences = new Element( "preferences" ); 
     42        final Element format = new Element( "format" ); 
     43        final Element rayleighExtinction = new Element( "rayleigh_extinction" ); 
     44 
     45        //On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer 
     46        final Document document = new Document( racine ); 
     47 
     48        final Attribute id = new Attribute( "Id", idF ); 
     49        racine.setAttribute( id ); 
     50 
     51        final Attribute idR = new Attribute( "Id", idRF ); 
     52        request.setAttribute( idR ); 
     53 
     54        racine.addContent( request ); 
     55        request.addContent( preferences ); 
     56 
     57        final Attribute validF = new Attribute( "valid", xvalidFF ); 
     58        format.setAttribute( validF ); 
     59        format.setText( validFF ); 
     60 
     61        final Attribute validR = new Attribute( "valid", xvalidRF ); 
     62        rayleighExtinction.setAttribute( validR ); 
     63        rayleighExtinction.setText( validRF ); 
     64 
     65        createXMLFile( fichier, document ); 
     66    } 
     67 
     68 
     69    public void createXMLFile( final String fichier, final Document document ) 
     70    { 
     71        try 
     72        { 
     73            //On utilise ici un affichage classique avec getPrettyFormat() 
     74            final XMLOutputter sortie = new XMLOutputter( Format.getPrettyFormat() ); 
     75            //Remarquez qu'il suffit simplement de créer une instance de FileOutputStream 
     76            //avec en argument le nom du fichier pour effectuer la sérialisation. 
     77            sortie.output( document, new FileOutputStream( fichier ) ); 
     78        } 
     79        catch( java.io.IOException ignored ) 
     80        { 
     81        } 
     82    } 
     83 
     84 
    2185    @Nullable 
    2286    @Transactional(readOnly = true) 
     
    83147    private PlateformDAO _plateformDAO; 
    84148    private ParameterDAO _parameterDAO; 
     149 
    85150} 
  • tapas/service/implementation/service-context.xml

    r384 r389  
    44<beans> 
    55        <bean id="tapasServiceTarget" class="com.ether.TapasServiceImpl"> 
    6                 <property name="plateformDAO" ref="refPlateformDAO" /> 
    7                 <property name="parameterDAO" ref="refParameterDAO" /> 
     6                <!--<property name="plateformDAO" ref="refPlateformDAO" /> 
     7                <property name="parameterDAO" ref="refParameterDAO" />--> 
    88        </bean> 
    99 
  • tapas/service/implementation/service-context_test.xml

    r388 r389  
    33 
    44<beans> 
    5         <bean id="tapasServiceTarget" class="com.ether.TapasServiceImpl"> 
    6                 <property name="plateformDAO" ref="refPlateformDAO" /> 
    7                 <property name="parameterDAO" ref="refParameterDAO" /> 
     5        <bean id="tapasService" class="com.ether.TapasServiceImpl"> 
     6                <!--<property name="plateformDAO" ref="refPlateformDAO" /> 
     7                <property name="parameterDAO" ref="refParameterDAO" />--> 
    88        </bean> 
    99 
    10         <bean id="tapasService" parent="transactionProxy"> 
    11                 <property name="target"> 
    12                         <ref bean="tapasServiceTarget" /> 
    13                 </property> 
    14                 <property name="transactionAttributeSource"> 
    15                         <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" /> 
    16                 </property> 
    17         </bean> 
    1810 
    1911</beans> 
  • tapas/service/interface/com/ether/TapasService.java

    r384 r389  
    11package com.ether; 
    22 
     3import org.jdom.Document; 
    34import org.jetbrains.annotations.NotNull; 
    45import org.jetbrains.annotations.Nullable; 
     
    1314        extends Service 
    1415{ 
     16 
     17    public void createXMLRequest(); 
     18 
     19    public void createXMLFile( final String fichier, final Document document ); 
     20 
    1521        @Nullable 
    1622        List<Plateform> getAllPlateforms() throws ServiceException; 
  • tapas/service/test/com/ether/EtherTest.java

    r376 r389  
    22 
    33import org.jetbrains.annotations.NotNull; 
     4import org.junit.Assert; 
     5import org.junit.Test; 
    46 
    57import javax.imageio.ImageIO; 
     
    911import java.io.File; 
    1012import java.io.Serializable; 
     13import java.text.DateFormat; 
    1114import java.text.ParseException; 
     15import java.text.SimpleDateFormat; 
     16import java.util.Calendar; 
     17import java.util.Date; 
    1218 
    1319/** 
     
    1622 */ 
    1723public class EtherTest 
     24        extends ServiceEtherTest 
    1825{ 
     26    @Test 
     27    public void testCreateXML() 
     28            throws Exception 
     29    { 
     30 
     31        getService().createXMLRequest(); 
     32 
     33    } 
     34 
     35 
    1936    @NotNull 
    2037    protected double[] createDataArray( @NotNull final Integer size, @NotNull final Integer begin ) 
  • tapas/service/test/com/ether/OtherTest.java

    r376 r389  
    2020{ 
    2121    @Test 
    22     public void testDatesMoisPlusUn() 
     22    public void testCreateXML() 
    2323            throws Exception 
    2424    { 
     25 
    2526        final DateFormat shortDateFormat = new SimpleDateFormat( "MMyyyy" ); 
    2627        final DateFormat completDateFormat = new SimpleDateFormat( "dd-MM-yyyy" ); 
     
    3738    } 
    3839 
    39     @Test 
    40     public void testDates() 
    41             throws Exception 
    42     { 
    43         List<Date> dates = new ArrayList<Date>(); 
    44         final DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" ); 
    4540 
    46         dates.add( dateFormat.parse( "2007-01-01" ) ); 
    47         dates.add( dateFormat.parse( "2007-01-02" ) ); 
    4841 
    49         final DateFormat shortFormat = new SimpleDateFormat( "yyyy" ); 
    50         Set<String> shortDates = new HashSet<String>(); 
    51         for ( final Date aDate : dates ) 
    52         { 
    53             shortDates.add( shortFormat.format( aDate ) ); 
    54         } 
    55     } 
    5642} 
  • tapas/service/test/com/ether/ServiceEtherTest.java

    r384 r389  
    1010    public ServiceEtherTest() 
    1111    { 
    12         super( "etherService" ); 
     12        super( "tapasService" ); 
    1313    } 
    1414 
  • tapas/service/test/com/ether/ServiceTestHelper.java

    r376 r389  
    1919    { 
    2020                return new String[] {  
    21                                 "classpath:dao-context.xml", 
    22                                 "classpath:service-context.xml", 
    23                                 "classpath:hibernate_test.cfg.xml", }; 
     21//                              "classpath:dao-context.xml", 
     22                                "classpath:service-context_test.xml", 
     23//                              "classpath:hibernate_test.cfg.xml", 
     24        }; 
    2425    } 
    2526 
Note: See TracChangeset for help on using the changeset viewer.