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 |
|
769 |
aurelien |
29 |
java.util.Iterator<String> it = tableauObs.keySet().iterator();
|
|
|
30 |
while (it.hasNext()) {
|
392 |
aurelien |
31 |
|
769 |
aurelien |
32 |
JSONObject observationJson = tableauObs.get(it.next()).isObject();
|
500 |
aurelien |
33 |
Observation observation = UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson);
|
|
|
34 |
|
392 |
aurelien |
35 |
JSONArray tableauImagesObs = observationJson.get("images").isArray();
|
|
|
36 |
List<Image> imagesPourObs = new ArrayList<Image>();
|
|
|
37 |
|
|
|
38 |
int nbImages = tableauImagesObs.size();
|
|
|
39 |
for (int j = 0; j < nbImages; j++) {
|
|
|
40 |
JSONObject imageJson = tableauImagesObs.get(j).isObject();
|
500 |
aurelien |
41 |
|
|
|
42 |
Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
|
|
|
43 |
image.setObservation(observation);
|
392 |
aurelien |
44 |
imagesPourObs.add(image);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
observation.setImages(imagesPourObs);
|
|
|
48 |
observations.add(observation);
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
359 |
benjamin |
52 |
public List<Observation> getObservations() {
|
|
|
53 |
return observations;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public void setObservations(List<Observation> observations) {
|
|
|
57 |
this.observations = observations;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public int getNbTotalObservationsPourLaRecherche() {
|
|
|
61 |
return nbTotalObservationsPourLaRecherche;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
|
|
|
65 |
this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
|
|
|
66 |
}
|
|
|
67 |
}
|