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;
|
|
|
13 |
|
359 |
benjamin |
14 |
public class ObservationServiceResultat {
|
|
|
15 |
|
|
|
16 |
private List<Observation> observations;
|
|
|
17 |
|
|
|
18 |
private int nbTotalObservationsPourLaRecherche;
|
|
|
19 |
|
392 |
aurelien |
20 |
public ObservationServiceResultat(JSONValue retourJson) {
|
|
|
21 |
//TODO ajouter vérifications plus précises
|
|
|
22 |
double total = retourJson.isObject().get("total").isNumber().doubleValue();
|
|
|
23 |
nbTotalObservationsPourLaRecherche = (int) total;
|
|
|
24 |
JSONArray tableauObs = retourJson.isObject().get("contenu").isArray();
|
|
|
25 |
|
|
|
26 |
observations = new ArrayList<Observation>();
|
|
|
27 |
|
|
|
28 |
int nbResultats = tableauObs.size();
|
|
|
29 |
for (int i = 0; i < nbResultats; i++) {
|
|
|
30 |
|
|
|
31 |
JSONObject observationJson = tableauObs.get(i).isObject();
|
500 |
aurelien |
32 |
Observation observation = UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson);
|
|
|
33 |
|
392 |
aurelien |
34 |
JSONArray tableauImagesObs = observationJson.get("images").isArray();
|
|
|
35 |
List<Image> imagesPourObs = new ArrayList<Image>();
|
|
|
36 |
|
|
|
37 |
int nbImages = tableauImagesObs.size();
|
|
|
38 |
for (int j = 0; j < nbImages; j++) {
|
|
|
39 |
JSONObject imageJson = tableauImagesObs.get(j).isObject();
|
500 |
aurelien |
40 |
|
|
|
41 |
Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
|
|
|
42 |
image.setObservation(observation);
|
392 |
aurelien |
43 |
imagesPourObs.add(image);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
observation.setImages(imagesPourObs);
|
|
|
47 |
observations.add(observation);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
359 |
benjamin |
51 |
public List<Observation> getObservations() {
|
|
|
52 |
return observations;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public void setObservations(List<Observation> observations) {
|
|
|
56 |
this.observations = observations;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public int getNbTotalObservationsPourLaRecherche() {
|
|
|
60 |
return nbTotalObservationsPourLaRecherche;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
|
|
|
64 |
this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
|
|
|
65 |
}
|
|
|
66 |
}
|