| 359 | benjamin | 1 | package org.tela_botanica.del.client.modeles;
 | 
        
           |  |  | 2 |   | 
        
           | 392 | aurelien | 3 | import java.util.ArrayList;
 | 
        
           |  |  | 4 | import java.util.Date;
 | 
        
           | 359 | benjamin | 5 | import java.util.List;
 | 
        
           |  |  | 6 |   | 
        
           | 500 | aurelien | 7 | import org.tela_botanica.del.client.utils.UtilitairesServiceResultat;
 | 
        
           |  |  | 8 |   | 
        
           | 392 | aurelien | 9 | import com.google.gwt.i18n.client.DateTimeFormat;
 | 
        
           |  |  | 10 | import com.google.gwt.json.client.JSONArray;
 | 
        
           |  |  | 11 | import com.google.gwt.json.client.JSONObject;
 | 
        
           |  |  | 12 | import com.google.gwt.json.client.JSONValue;
 | 
        
           | 769 | aurelien | 13 | import com.google.gwt.user.client.Window;
 | 
        
           | 392 | aurelien | 14 |   | 
        
           | 359 | benjamin | 15 | public class ObservationServiceResultat {
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | 	private List<Observation> observations;
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | 	private int nbTotalObservationsPourLaRecherche;
 | 
        
           |  |  | 20 |   | 
        
           | 392 | aurelien | 21 | 	public ObservationServiceResultat(JSONValue retourJson) {
 | 
        
           |  |  | 22 | 		//TODO ajouter vérifications plus précises
 | 
        
           | 769 | aurelien | 23 | 		double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
 | 
        
           | 392 | aurelien | 24 | 		nbTotalObservationsPourLaRecherche = (int) total;
 | 
        
           | 769 | aurelien | 25 | 		JSONObject tableauObs = retourJson.isObject().get("resultats").isObject();
 | 
        
           | 392 | aurelien | 26 |   | 
        
           |  |  | 27 | 		observations = new ArrayList<Observation>();
 | 
        
           |  |  | 28 |   | 
        
           | 802 | aurelien | 29 | 		if(tableauObs != null) {
 | 
        
           |  |  | 30 | 			java.util.Iterator<String> it = tableauObs.keySet().iterator();
 | 
        
           |  |  | 31 | 			while (it.hasNext()) {
 | 
        
           | 500 | aurelien | 32 |   | 
        
           | 802 | aurelien | 33 | 				JSONObject observationJson = tableauObs.get(it.next()).isObject();
 | 
        
           |  |  | 34 | 				Observation observation = UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson);
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | 				JSONArray tableauImagesObs = observationJson.get("images").isArray();
 | 
        
           |  |  | 37 | 				List<Image> imagesPourObs = new ArrayList<Image>();
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 | 				int nbImages = tableauImagesObs.size();
 | 
        
           |  |  | 40 | 				for (int j = 0; j < nbImages; j++) {
 | 
        
           |  |  | 41 | 					JSONObject imageJson = tableauImagesObs.get(j).isObject();
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 | 					Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
 | 
        
           |  |  | 44 | 					image.setObservation(observation);
 | 
        
           |  |  | 45 | 					imagesPourObs.add(image);
 | 
        
           |  |  | 46 | 				}
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 | 				observation.setImages(imagesPourObs);
 | 
        
           |  |  | 49 | 				observations.add(observation);
 | 
        
           | 392 | aurelien | 50 | 			}
 | 
        
           |  |  | 51 | 		}
 | 
        
           |  |  | 52 | 	}
 | 
        
           |  |  | 53 |   | 
        
           | 359 | benjamin | 54 | 	public List<Observation> getObservations() {
 | 
        
           |  |  | 55 | 		return observations;
 | 
        
           |  |  | 56 | 	}
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | 	public void setObservations(List<Observation> observations) {
 | 
        
           |  |  | 59 | 		this.observations = observations;
 | 
        
           |  |  | 60 | 	}
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 | 	public int getNbTotalObservationsPourLaRecherche() {
 | 
        
           |  |  | 63 | 		return nbTotalObservationsPourLaRecherche;
 | 
        
           |  |  | 64 | 	}
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 | 	public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
 | 
        
           |  |  | 67 | 		this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
 | 
        
           |  |  | 68 | 	}
 | 
        
           |  |  | 69 | }
 |