Changeset 216 for ether_megapoli


Ignore:
Timestamp:
10/04/11 16:26:26 (13 years ago)
Author:
vmipsl
Message:

download

Location:
ether_megapoli/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/common/implementation/com/ether/DateHelper.java

    r89 r216  
    11package com.ether; 
     2 
     3import org.apache.commons.logging.Log; 
     4import org.apache.commons.logging.LogFactory; 
     5import org.jetbrains.annotations.Nullable; 
    26 
    37import java.text.DateFormat; 
     
    711import java.util.Date; 
    812import java.util.Locale; 
    9  
    10 import org.apache.commons.logging.Log; 
    11 import org.apache.commons.logging.LogFactory; 
    12 import org.jetbrains.annotations.Nullable; 
    1313 
    1414/** 
     
    132132 
    133133    @Nullable 
    134     public static Date parseDate( @Nullable final String date, final String format ) throws ParseException 
     134    public static Date parseDate( @Nullable final String date, final String format ) 
     135            throws ParseException 
    135136    { 
    136         if( date == null ) 
     137        if( date == null ) 
    137138            return null; 
    138139 
    139140        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat( format ); 
    140         return simpleDateFormat.parse(date); 
     141        return simpleDateFormat.parse( date ); 
    141142    } 
    142143 
    143144    private static final Log LOGGER = LogFactory.getLog( DateHelper.class ); 
    144      
     145 
    145146    public static final String FRENCH_DATE_PATTERN_SHORT = "dd/MM/yyyy"; 
     147    public static final String FRENCH_DATE_PATTERN = "dd/MM/yyyy HH:mm"; 
    146148    public static final String ENGLISH_DATE_PATTERN_SHORT = "yyyy-MM-dd"; 
    147149    public static final String ENGLISH_DATE_PATTERN = "yyyy-MM-dd HH:mm"; 
  • ether_megapoli/trunk/common/implementation/com/ether/EtherHelper.java

    r213 r216  
    55import org.jetbrains.annotations.Nullable; 
    66 
     7import java.io.BufferedWriter; 
     8import java.io.FileWriter; 
     9import java.io.IOException; 
    710import java.util.ArrayList; 
    811import java.util.List; 
     
    6366    // TODO : supprimer cette méthode et utiliser JSON pour récupérer pIdPIdList 
    6467    @Nullable 
    65     public static List<Pair<Integer, Integer>> extractpfIdPIdListFromString( @NotNull final String pfIdPIdArrayString ) 
     68    public static <T1 extends Object, T2 extends Object> List<Pair<T1, T2>> extractpfIdPIdListFromString( @NotNull final String pfIdPIdArrayString, @NotNull final Class<T1> T1Class, @NotNull final Class<T2> T2Class ) 
    6669    { 
    6770        if( pfIdPIdArrayString.isEmpty() ) 
     
    6972 
    7073        final String[] pfIDPIdArray = pfIdPIdArrayString.split( "," ); 
    71         final List<Pair<Integer, Integer>> pfIdPIdList = new ArrayList<Pair<Integer, Integer>>( pfIDPIdArray.length ); 
     74        final List<Pair<T1, T2>> pfIdPIdList = new ArrayList<Pair<T1, T2>>( pfIDPIdArray.length ); 
    7275        for( final String pfIdPId : pfIDPIdArray ) 
    7376        { 
    7477            final String[] pfIdPIdSplit = pfIdPId.split( "-" ); 
    75             final Pair<Integer, Integer> pfIdPIdPair = new Pair<Integer, Integer>(); 
    76             pfIdPIdPair.setFirstValue( Integer.valueOf( pfIdPIdSplit[0] ) ); 
    77             pfIdPIdPair.setSecondValue( Integer.valueOf( pfIdPIdSplit[1] ) ); 
     78            final Pair<T1, T2> pfIdPIdPair = new Pair<T1, T2>(); 
     79            if( T1Class.equals( String.class ) ) 
     80                pfIdPIdPair.setFirstValue( (T1) pfIdPIdSplit[0] ); 
     81            else 
     82                pfIdPIdPair.setFirstValue( (T1) Integer.valueOf( pfIdPIdSplit[0] ) ); 
     83 
     84            if( T2Class.equals( String.class ) ) 
     85                pfIdPIdPair.setSecondValue( (T2) pfIdPIdSplit[1] ); 
     86            else 
     87                pfIdPIdPair.setSecondValue( (T2) Integer.valueOf( pfIdPIdSplit[1] ) ); 
    7888            pfIdPIdList.add( pfIdPIdPair ); 
    7989        } 
     
    8191    } 
    8292 
     93    /** 
     94     * This method writes the text into the file filePath 
     95     * 
     96     * @param filePath 
     97     * @param text 
     98     */ 
     99    public static void writeInFile( @NotNull final String filePath, @NotNull final String text ) 
     100    { 
     101        try 
     102        { 
     103            final FileWriter fw = new FileWriter( filePath, true ); 
     104            final BufferedWriter output = new BufferedWriter( fw ); 
     105            output.write( text ); 
     106            output.flush(); 
     107            output.close(); 
     108        } 
     109        catch( IOException ioe ) 
     110        { 
     111            ioe.printStackTrace(); 
     112        } 
     113 
     114    } 
    83115 
    84116} 
  • ether_megapoli/trunk/web/src/com/ether/Controller.java

    r213 r216  
    88import com.medias.database.objects.Plateforme; 
    99import com.medias.megapoli.struts.forms.DatasForm; 
     10import com.medias.megapoli.trade.MesureAdapter; 
     11import com.medias.megapoli.trade.ValeurAdapter; 
    1012import com.medias.megapoli.utils.Requete; 
    1113import net.sf.json.JSONObject; 
    12 import org.apache.commons.lang.StringUtils; 
    1314import org.apache.commons.logging.Log; 
    1415import org.apache.commons.logging.LogFactory; 
     
    7980            throws ServiceException, WebException 
    8081    { 
    81         final List<Pair<Integer, Integer>> pfIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString ); 
     82        final List<Pair<String, String>> pfIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString, String.class, String.class ); 
    8283        if( null == pfIdPIdList ) 
    8384            throw new WebException( WebException.WebCode.PLATEFORM_OR_PARAMETER_IS_NULL, null ); 
    8485 
    85         final DatasForm datasForm = new DatasForm(); 
    86         datasForm.setOutput( FORMAT_DEFAULT ); 
    87         datasForm.setCompression( COMPRESSION_DEFAULT ); 
    88         final List<Integer> plateformIds = EtherHelper.getFirstValues( pfIdPIdList ); 
    89         final List<Integer> parameterIds = EtherHelper.getSecondValues( pfIdPIdList ); 
    90         final String plateformIdsString = StringUtils.join( plateformIds.iterator(), "," ); 
    91         final String parameterIdsString = StringUtils.join( parameterIds.iterator(), "," ); 
    92  
    93         final Calendar calendar = Calendar.getInstance(); 
    94         String formatedDateBegin = null; 
    95         String formatedDateEnd = null; 
    96         if( null != dateBegin && null != dateEnd && !"false".equals( dateBegin ) && !"false".equals( dateEnd ) ) 
    97             try 
    98             { 
    99                 calendar.setTimeInMillis( Long.valueOf( dateBegin ) ); 
    100                 formatedDateBegin = DateHelper.formatDate( calendar.getTime(), DateHelper.FRENCH_DATE_PATTERN_SHORT ); 
    101                 calendar.setTimeInMillis( Long.valueOf( dateEnd ) ); 
    102                 formatedDateEnd = DateHelper.formatDate( calendar.getTime(), DateHelper.FRENCH_DATE_PATTERN_SHORT ); 
    103             } 
    104             catch( Exception e ) 
    105             { 
    106                 throw new WebException( WebException.WebCode.INVALID_DATE, e ); 
    107             } 
    108  
    109         final String datesString = StringUtils.join( new String[]{formatedDateBegin, formatedDateEnd}, "," ); 
    110  
    111         datasForm.setListePlats( plateformIdsString ); 
    112         datasForm.setListeParams( parameterIdsString ); 
    113         datasForm.setListeDates( datesString ); 
     86        final DatasForm dataForm = createDataForm( dateBegin, dateEnd, pfIdPIdList ); 
    11487 
    11588        final XMLOutputter outXml = new XMLOutputter(); 
    116         final Document docXml = Requete.toXml( datasForm, personne ); 
     89        final Document docXml = Requete.toXml( dataForm, personne ); 
    11790        final String requete = outXml.outputString( docXml ); 
    11891        try 
     
    12699            conn.setUseCaches( false ); 
    127100            conn.setRequestProperty( "content-type", "application/x-www-form-urlencoded" ); 
     101 
    128102            // Envoi de la requête 
    129103            final DataOutputStream out = new DataOutputStream( conn.getOutputStream() ); 
     
    143117                } 
    144118                else System.out.println( "REPONSE :" + aLine ); 
    145  
    146119            } 
    147120        } 
     
    170143    } 
    171144 
     145    /** 
     146     * This method create a dataForms to simulate and use the struts actions "DataAccessAction" and "DataSubmitAction" 
     147     * 
     148     * @param dateBegin 
     149     * @param dateEnd 
     150     * @param pfIdPIdList 
     151     * @return 
     152     * @throws WebException 
     153     */ 
     154    @NotNull 
     155    private DatasForm createDataForm( final String dateBegin, final String dateEnd, final List<Pair<String, String>> pfIdPIdList ) 
     156            throws WebException 
     157    { 
     158        final DatasForm dataForm = new DatasForm(); 
     159 
     160        // Plateforms and parameters 
     161        final List<String> plateformIds = EtherHelper.getFirstValues( pfIdPIdList ); 
     162        final List<String> parameterIds = EtherHelper.getSecondValues( pfIdPIdList ); 
     163        dataForm.setSelectPlats( plateformIds.toArray( new String[plateformIds.size()] ) ); 
     164        dataForm.setSelectParams( parameterIds.toArray( new String[parameterIds.size()] ) ); 
     165 
     166        // Localisations 
     167        final MesureAdapter mAdapter = new MesureAdapter(); 
     168        mAdapter.loadLocsFromDatabase( dataForm ); 
     169 
     170        // Dates 
     171        final Calendar calendar = Calendar.getInstance(); 
     172        String formatedDateBegin = null; 
     173        String formatedDateEnd = null; 
     174        if( null != dateBegin && null != dateEnd && !"false".equals( dateBegin ) && !"false".equals( dateEnd ) ) 
     175        { 
     176            try 
     177            { 
     178                calendar.setTimeInMillis( Long.valueOf( dateBegin ) ); 
     179                formatedDateBegin = DateHelper.formatDate( calendar.getTime(), DateHelper.FRENCH_DATE_PATTERN ); 
     180                calendar.setTimeInMillis( Long.valueOf( dateEnd ) ); 
     181                formatedDateEnd = DateHelper.formatDate( calendar.getTime(), DateHelper.FRENCH_DATE_PATTERN ); 
     182                dataForm.setDateDeb( formatedDateBegin ); 
     183                dataForm.setDateFin( formatedDateEnd ); 
     184            } 
     185            catch( Exception e ) 
     186            { 
     187                throw new WebException( WebException.WebCode.INVALID_DATE, e ); 
     188            } 
     189        } 
     190        else 
     191            mAdapter.loadDatesFromDatabase( dataForm ); 
     192 
     193        // Fill dataForm 
     194        final ValeurAdapter vAdapter = new ValeurAdapter(); 
     195        vAdapter.loadCountFromDatabase( dataForm ); 
     196        dataForm.setListeCoords( dataForm.getLatMin() + "," + dataForm.getLatMax() + "," + dataForm.getLonMin() + "," + dataForm.getLonMax() ); 
     197        dataForm.setListeDates( dataForm.getDateDeb() + "," + dataForm.getDateFin() ); 
     198 
     199        return dataForm; 
     200    } 
     201 
    172202    private List<JSONObject> getJSONAxeTypesForFixedPlateforms() 
    173203    { 
  • ether_megapoli/trunk/web/src/com/ether/ControllerPlot.java

    r213 r216  
    22 
    33import com.medias.Context; 
     4import gov.noaa.pmel.util.SoTValue; 
    45import org.apache.commons.logging.Log; 
    56import org.apache.commons.logging.LogFactory; 
     
    6566            // TODO : utiliser JSON pour récupérer pIdPIdList 
    6667            final String pIdPIdArrayString = request.getParameter( ParameterConstants.PARAMETER_PFID_PID_LIST ); 
    67             final List<Pair<Integer, Integer>> pIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString ); 
     68            final List<Pair<Integer, Integer>> pIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString, Integer.class, Integer.class ); 
    6869            if( null == pIdPIdList ) 
    6970            { 
Note: See TracChangeset for help on using the changeset viewer.