Subversion Repositories eFlore/Applications.del

Rev

Rev 462 | Rev 773 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.client.modeles;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.tela_botanica.del.client.utils.UtilitairesServiceResultat;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;

public class ObservationServiceResultat {
        
        private List<Observation> observations;
        
        private int nbTotalObservationsPourLaRecherche;

        public ObservationServiceResultat(JSONValue retourJson) {
                //TODO ajouter vérifications plus précises
                double total = retourJson.isObject().get("total").isNumber().doubleValue();
                nbTotalObservationsPourLaRecherche = (int) total;
                JSONArray tableauObs = retourJson.isObject().get("contenu").isArray();
                
                observations = new ArrayList<Observation>();
                
                int nbResultats = tableauObs.size();
                for (int i = 0; i < nbResultats; i++) {
                        
                        JSONObject observationJson = tableauObs.get(i).isObject();
                        Observation observation = UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson);
                                                        
                        JSONArray tableauImagesObs = observationJson.get("images").isArray();
                        List<Image> imagesPourObs = new ArrayList<Image>();
                        
                        int nbImages = tableauImagesObs.size();
                        for (int j = 0; j < nbImages; j++) {
                                JSONObject imageJson = tableauImagesObs.get(j).isObject();
                                
                                Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
                                image.setObservation(observation);
                                imagesPourObs.add(image);
                        }
                        
                        observation.setImages(imagesPourObs);
                        observations.add(observation);
                }
        }

        public List<Observation> getObservations() {
                return observations;
        }

        public void setObservations(List<Observation> observations) {
                this.observations = observations;
        }

        public int getNbTotalObservationsPourLaRecherche() {
                return nbTotalObservationsPourLaRecherche;
        }

        public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
                this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
        }
}