Changeset 216 for ether_megapoli
- Timestamp:
- 10/04/11 16:26:26 (13 years ago)
- Location:
- ether_megapoli/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/common/implementation/com/ether/DateHelper.java
r89 r216 1 1 package com.ether; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.jetbrains.annotations.Nullable; 2 6 3 7 import java.text.DateFormat; … … 7 11 import java.util.Date; 8 12 import java.util.Locale; 9 10 import org.apache.commons.logging.Log;11 import org.apache.commons.logging.LogFactory;12 import org.jetbrains.annotations.Nullable;13 13 14 14 /** … … 132 132 133 133 @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 135 136 { 136 137 if( date == null ) 137 138 return null; 138 139 139 140 final SimpleDateFormat simpleDateFormat = new SimpleDateFormat( format ); 140 return simpleDateFormat.parse( date);141 return simpleDateFormat.parse( date ); 141 142 } 142 143 143 144 private static final Log LOGGER = LogFactory.getLog( DateHelper.class ); 144 145 145 146 public static final String FRENCH_DATE_PATTERN_SHORT = "dd/MM/yyyy"; 147 public static final String FRENCH_DATE_PATTERN = "dd/MM/yyyy HH:mm"; 146 148 public static final String ENGLISH_DATE_PATTERN_SHORT = "yyyy-MM-dd"; 147 149 public static final String ENGLISH_DATE_PATTERN = "yyyy-MM-dd HH:mm"; -
ether_megapoli/trunk/common/implementation/com/ether/EtherHelper.java
r213 r216 5 5 import org.jetbrains.annotations.Nullable; 6 6 7 import java.io.BufferedWriter; 8 import java.io.FileWriter; 9 import java.io.IOException; 7 10 import java.util.ArrayList; 8 11 import java.util.List; … … 63 66 // TODO : supprimer cette méthode et utiliser JSON pour récupérer pIdPIdList 64 67 @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 ) 66 69 { 67 70 if( pfIdPIdArrayString.isEmpty() ) … … 69 72 70 73 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 ); 72 75 for( final String pfIdPId : pfIDPIdArray ) 73 76 { 74 77 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] ) ); 78 88 pfIdPIdList.add( pfIdPIdPair ); 79 89 } … … 81 91 } 82 92 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 } 83 115 84 116 } -
ether_megapoli/trunk/web/src/com/ether/Controller.java
r213 r216 8 8 import com.medias.database.objects.Plateforme; 9 9 import com.medias.megapoli.struts.forms.DatasForm; 10 import com.medias.megapoli.trade.MesureAdapter; 11 import com.medias.megapoli.trade.ValeurAdapter; 10 12 import com.medias.megapoli.utils.Requete; 11 13 import net.sf.json.JSONObject; 12 import org.apache.commons.lang.StringUtils;13 14 import org.apache.commons.logging.Log; 14 15 import org.apache.commons.logging.LogFactory; … … 79 80 throws ServiceException, WebException 80 81 { 81 final List<Pair< Integer, Integer>> pfIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString);82 final List<Pair<String, String>> pfIdPIdList = EtherHelper.extractpfIdPIdListFromString( pIdPIdArrayString, String.class, String.class ); 82 83 if( null == pfIdPIdList ) 83 84 throw new WebException( WebException.WebCode.PLATEFORM_OR_PARAMETER_IS_NULL, null ); 84 85 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 ); 114 87 115 88 final XMLOutputter outXml = new XMLOutputter(); 116 final Document docXml = Requete.toXml( data sForm, personne );89 final Document docXml = Requete.toXml( dataForm, personne ); 117 90 final String requete = outXml.outputString( docXml ); 118 91 try … … 126 99 conn.setUseCaches( false ); 127 100 conn.setRequestProperty( "content-type", "application/x-www-form-urlencoded" ); 101 128 102 // Envoi de la requête 129 103 final DataOutputStream out = new DataOutputStream( conn.getOutputStream() ); … … 143 117 } 144 118 else System.out.println( "REPONSE :" + aLine ); 145 146 119 } 147 120 } … … 170 143 } 171 144 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 172 202 private List<JSONObject> getJSONAxeTypesForFixedPlateforms() 173 203 { -
ether_megapoli/trunk/web/src/com/ether/ControllerPlot.java
r213 r216 2 2 3 3 import com.medias.Context; 4 import gov.noaa.pmel.util.SoTValue; 4 5 import org.apache.commons.logging.Log; 5 6 import org.apache.commons.logging.LogFactory; … … 65 66 // TODO : utiliser JSON pour récupérer pIdPIdList 66 67 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 ); 68 69 if( null == pIdPIdList ) 69 70 {
Note: See TracChangeset
for help on using the changeset viewer.