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