Changeset 389


Ignore:
Timestamp:
03/02/12 18:07:28 (12 years ago)
Author:
rboipsl
Message:
 
Location:
tapas
Files:
1 added
11 edited
2 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 
  • tapas/web/init.jsp

    r388 r389  
    77 
    88    <tiles:put name="insertCss" type="string"></tiles:put> 
    9     <tiles:put name="insertJsOrJsp" type="string"></tiles:put> 
     9    <tiles:put name="insertJsOrJsp" type="string"> 
     10        <ether:htmlJsp jspFile="init_script"></ether:htmlJsp> 
     11    </tiles:put> 
    1012 
    11     <tiles:put name="title" type="string"><spring:message code="app.title"/> - <spring:message code="title.home"/></tiles:put> 
     13    <tiles:put name="title" type="string"><spring:message code="app.title"/> - <spring:message 
     14            code="title.home"/></tiles:put> 
    1215    <tiles:put name="nav" type="string"><a href=""><spring:message code="label.home"/></a></tiles:put> 
    1316 
     
    1821    <tiles:put name="body" type="string"> 
    1922 
    20         CONTENU INIT 
     23        <div id="formulaire"> 
     24 
     25        </div> 
     26 
     27        <script type="text/javascript"> 
     28            var initTexts = $A( "" ); 
     29 
     30            initTexts["label.submitButton"] = '<spring:message code="label.submitButton"/>'; 
     31 
     32 
     33            var interfaceInit = new InterfaceInit(); 
     34        </script> 
    2135 
    2236    </tiles:put> 
  • tapas/web/init_script.jsp

    r388 r389  
    1 <%@ page import="com.ether.Context" %> 
     1<script type="text/javascript"> 
     2    var InterfaceInit = Class.create( { 
    23 
    3 <script type="text/javascript"> 
    4 var InterfaceTemplate = Class.create( { 
     4        initialize: function() 
     5        { 
     6            /** *********** CONTAINERS *********** **/ 
     7            this.containerForm = $( "#formulaire" ); 
    58 
    6     initialize: function() 
    7     { 
    8         /** *********** CONTAINERS *********** **/ 
    9         this.containerTools = $( "#tools" ); 
    10         this.containerLogin = $( "#loginModule" ); 
    11         this.containerMenuData = $( "#menuData" ); 
     9            this.createForm(); 
    1210 
    13         /** *********** VARIABLES *********** **/ 
    14         this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>; 
    15         this.path = "<%=request.getContextPath()%>"; 
    16         setPath( this.path ); 
    17         this.webmaster = "<%=Context.getWebmaster(request)%>"; 
    18         this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>"; 
    19         <%--this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;--%> 
     11        }, 
    2012 
    21         /** ************ CREATE ************ **/ 
    22 //        this.createLogin(); 
    23         this.createTools(); 
    24         this.createMenuData(); 
    25         this.updateLoginOrLogout(); 
    26     }, 
     13        // CREATES ******************************************************** 
     14        createForm: function() 
     15        { 
     16            // Create button elements 
     17            this.input1 = $( document.createElement( "input" ) ); 
     18            var input2 = $( document.createElement( "input" ) ); 
    2719 
    28     // CREATES ******************************************************** 
    29     createTools: function() 
    30     { 
    31         var mailButton = new Button( {value:templateTexts["label.mail"], parent:this.containerTools, id:"button_mail", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickMail, this )} ); 
     20            this.input1.attr( {id:"1"} ); 
     21            this.containerForm.append( this.input1 ); 
    3222 
    33         var valueLanguage = templateTexts["label.language.fr"]; 
    34         if( this.isLanguageFr ) 
    35             valueLanguage = templateTexts["label.language.en"]; 
     23            input2.attr( {id:"2"} ); 
     24            this.containerForm.append( input2 ); 
    3625 
    37         var languageButton = new Button( {value:valueLanguage, parent:this.containerTools, id:"button_language", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} ); 
    38         var homeButton = new Button( {value:templateTexts["label.home"], parent:this.containerTools, id:"button_home", className: "red_button", classNameText:"red_button_text", onClick:this.onClickHome} ); 
    39     }, 
     26            var submitButton = new Button( {value:initTexts["label.submitButton"], parent:this.containerForm, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); 
    4027 
    41     createLogin: function() 
    42     { 
    43         this.loginModule = new LoginButton( {parent:this.containerLogin, urlLogin:"project?methodName=login", urlLogout:"project?methodName=logout", isNeededInscription:true, callbackInscription:jQuery.proxy( this.onClickInscription, this ), anotherOnClickLogin:this.updateLoginOrLogout, anotherOnClickLogout:this.updateLoginOrLogout } ); 
    44         this.loginModule.setJSONUser( this.jSONUser ); 
    45         this.loginModule.display(); 
    46         setLoginModule( this.loginModule ); 
    47     }, 
     28        }, 
    4829 
    49     createMenuData: function() 
    50     { 
    51         this.containerMenuData.empty(); 
    5230 
    53         var ulData = $( document.createElement( "ul" ) ); 
    54         this.containerMenuData.append( ulData ); 
     31        // REQUESTS ******************************************************** 
     32        requestCreateXML: function() 
     33        { 
     34//            alert(this.input1.val()+' - '+$("#2").val()); 
     35            $.ajax( { 
     36                url: "project?methodName=createUserRequest&input1="+this.input1.val()+"&input2="+$("#2").val(), 
     37                success:jQuery.proxy( this.handleCreateXML, this ) 
     38            } ); 
     39        }, 
    5540 
    56         var liExtract = $( document.createElement( "li" ) ); 
    57         liExtract.append( '<a onclick=\'javascript:neededLogin("/DataAccess.do")\'><span>' + templateTexts["data.access.extract.short"] + '</span></a>' ); 
    58         ulData.append( liExtract ); 
     41        // HANDLES ******************************************************** = retours ajax 
     42        handleCreateXML: function( result ) 
     43        { 
     44//            alert("XML créé"); 
     45            var bob = jQuery.parseJSON( result ).result; 
     46            alert(bob); 
    5947 
    60         var liDownload = $( document.createElement( "li" ) ); 
    61         liDownload.append( '<a onclick=\'javascript:neededLogin("/PrepareTree.do")\'><span>' + templateTexts["data.upload.short"] + '</span></a>' ); 
    62         ulData.append( liDownload ); 
    63     }, 
     48        }, 
    6449 
    65     // REQUESTS ******************************************************** 
    6650 
    67     // EVENTS ******************************************************** 
    68     onClickHome: function() 
    69     { 
    70         document.location.href = "index.jsp"; 
    71     }, 
     51        // EVENTS ******************************************************** 
    7252 
    73     onClickLanguage: function() 
    74     { 
    75         if( this.isLanguageFr ) 
    76             document.location.href = this.path + "/English.do?requestUri=" + this.relativePageUri; 
    77         else 
    78             document.location.href = this.path + "/French.do?requestUri=" + this.relativePageUri; 
    79     }, 
     53        onClickSubmit: function() 
     54        { 
     55            this.requestCreateXML(); 
     56        } 
    8057 
    81     onClickMail: function() 
    82     { 
    83         document.location.href = "mailto:" + this.webmaster + "?subject=[TAPAS]"; 
    84     }, 
    8558 
    86     onClickInscription: function() 
    87     { 
    88         var dataProtocol = "resources/jsp/dataProtocol_fr.jsp"; 
    89         if( !this.isLanguageFr ) 
    90             dataProtocol = "resources/jsp/dataProtocol_en.jsp"; 
     59    } ); 
    9160 
    92         var $dialog = $( '<div></div>' ) 
    93                 .load( dataProtocol ) 
    94                 .dialog( { 
    95                              autoOpen: false, 
    96                              title: loginTexts["login.inscription"], 
    97                              height: 800, 
    98                              width: 750 
    99                          } ); 
    100         $dialog.dialog( 'open' ); 
    10161 
    102         // TODO : see with $dialog.ready() to manage buttons 
    103     }, 
    104  
    105     updateLoginOrLogout: function() 
    106     { 
    107         <%--if( "<%=UserRole.ADMINISTRATOR%>" == getJSONUserRole() )--%> 
    108             <%--$( "#button_bo" ).show();--%> 
    109         <%--else--%> 
    110             <%--$( "#button_bo" ).hide();--%> 
    111     } 
    112  
    113 } ); 
    114  
    115 /** ******************************* **/ 
    116 /** *********** ACCOUNT *********** **/ 
    117 /** ******************************* **/ 
    118 function onClickAcceptDataProtocol() 
    119 { 
    120     if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) 
    121     { 
    122         showErrorAccount( null, templateTexts["login.dataProtocolFields"] ); 
    123         return; 
    124     } 
    125  
    126     if( $( "#checkboxUser" ).attr( 'checked' ) ) 
    127         createAccount(); 
    128     else 
    129         showErrorAccount( null, templateTexts["login.dataProtocolAccept"] ); 
    130 } 
    131  
    132 function createAccount() 
    133 { 
    134     var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); 
    135     var request = $.ajax( { 
    136         url: "project?methodName=createAccount&" + parametersUrl, 
    137         success:handleCreateAccount, 
    138         error: showErrorAccount 
    139     } ); 
    140 } 
    141  
    142 function handleCreateAccount() 
    143 { 
    144     $( "#infosAccount" ).hide(); 
    145     $( "#infosAccount" ).removeClass( "containerErrors" ); 
    146     $( "#infosAccount" ).addClass( "containerInfos" ); 
    147     $( "#infosAccount" ).html( templateTexts["login.dataProtocol.account"] ); 
    148     $( "#infosAccount" ).show(); 
    149 } 
    150  
    151 function showErrorAccount( result, text ) 
    152 { 
    153     $( "#infosAccount" ).hide(); 
    154     $( "#infosAccount" ).removeClass( "containerInfos" ); 
    155     $( "#infosAccount" ).addClass( "containerErrors" ); 
    156     if( null != result ) 
    157         $( "#infosAccount" ).html( templateTexts[result.responseText] ); 
    158     else 
    159         $( "#infosAccount" ).html( text ); 
    160  
    161     $( "#infosAccount" ).show(); 
    162 } 
    16362</script> 
  • tapas/web/src/com/ether/Controller.java

    r384 r389  
    22 
    33import com.ether.annotation.ControllerMethod; 
     4import com.ether.annotation.Mandatory; 
     5import com.ether.annotation.ParamName; 
     6import net.sf.json.JSONObject; 
    47import org.apache.commons.logging.Log; 
    58import org.apache.commons.logging.LogFactory; 
     
    811 
    912import java.util.HashMap; 
     13import java.util.List; 
    1014import java.util.Map; 
    1115 
     
    1721        extends ControllerEther 
    1822{ 
     23 
    1924    /** *********************************************************** **/ 
    2025    /** *********************** VIEWS ***************************** **/ 
    21     /** *********************************************************** **/ 
     26    /** 
     27     * ********************************************************** * 
     28     */ 
    2229    @ControllerMethod(view = VIEW_INIT) 
    2330    public Map<String, Object> home() 
     
    2734    } 
    2835 
     36 
    2937    /** *********************************************************** **/ 
    3038    /** *********************** CALLS ***************************** **/ 
    31     /** *********************************************************** **/ 
     39    /** 
     40     * ********************************************************** * 
     41     */ 
    3242 
     43    @ControllerMethod(jsonResult = true) 
     44    public JSONObject createUserRequest( @ParamName("input1") final String input1, @ParamName("input2") final String input2 ) 
     45            throws ServiceException 
     46    { 
     47 
     48        //appel a createxml 
     49        _tapasService.createXMLRequest(); 
     50 
     51 
     52        final JSONObject result = new JSONObject(); 
     53        result.put( "result","SUCCESS" ); 
     54        return result; 
     55    } 
    3356 
    3457 
  • tapas/web/src/messages_en.properties

    r384 r389  
    5656logo.kinetics.alt=Chemical Kinetics Database 
    5757logo.links.alt=Links 
     58 
     59 
     60label.submitButton=RUN 
  • tapas/web/src/messages_fr.properties

    r384 r389  
    5757logo.links.alt=Liens 
    5858 
     59 
     60label.submitButton=COURIR 
     61 
Note: See TracChangeset for help on using the changeset viewer.