Subversion Repositories eFlore/Applications.del

Rev

Rev 1062 | Rev 1131 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1062 Rev 1104
1
package org.tela_botanica.del.client.utils;
1
package org.tela_botanica.del.client.utils;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Date;
4
import java.util.Date;
5
import java.util.HashMap;
5
import java.util.HashMap;
6
import java.util.Iterator;
6
import java.util.Iterator;
7
import java.util.List;
7
import java.util.List;
8
 
8
 
9
import org.tela_botanica.del.client.cache.CacheClient;
9
import org.tela_botanica.del.client.cache.CacheClient;
10
import org.tela_botanica.del.client.modeles.Commentaire;
10
import org.tela_botanica.del.client.modeles.Commentaire;
11
import org.tela_botanica.del.client.modeles.Contributeur;
11
import org.tela_botanica.del.client.modeles.Contributeur;
12
import org.tela_botanica.del.client.modeles.Image;
12
import org.tela_botanica.del.client.modeles.Image;
13
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
13
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
14
import org.tela_botanica.del.client.modeles.InterventionForum;
14
import org.tela_botanica.del.client.modeles.InterventionForum;
15
import org.tela_botanica.del.client.modeles.Observation;
15
import org.tela_botanica.del.client.modeles.Observation;
16
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
16
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
17
import org.tela_botanica.del.client.modeles.PropositionDetermination;
17
import org.tela_botanica.del.client.modeles.PropositionDetermination;
18
import org.tela_botanica.del.client.modeles.Protocole;
18
import org.tela_botanica.del.client.modeles.Protocole;
19
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
19
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
20
import org.tela_botanica.del.client.modeles.Utilisateur;
20
import org.tela_botanica.del.client.modeles.Utilisateur;
21
import org.tela_botanica.del.client.modeles.VoteDetermination;
21
import org.tela_botanica.del.client.modeles.VoteDetermination;
22
import org.tela_botanica.del.client.modeles.VoteProtocole;
22
import org.tela_botanica.del.client.modeles.VoteProtocole;
23
 
23
 
24
import com.google.gwt.i18n.client.DateTimeFormat;
24
import com.google.gwt.i18n.client.DateTimeFormat;
25
import com.google.gwt.json.client.JSONArray;
25
import com.google.gwt.json.client.JSONArray;
26
import com.google.gwt.json.client.JSONObject;
26
import com.google.gwt.json.client.JSONObject;
27
import com.google.gwt.json.client.JSONParser;
27
import com.google.gwt.json.client.JSONParser;
28
import com.google.gwt.json.client.JSONValue;
28
import com.google.gwt.json.client.JSONValue;
-
 
29
import com.google.gwt.user.client.Window;
29
 
30
 
30
/**
31
/**
31
 * Centralisation des methodes de parsing du code JSON retourné par les
32
 * Centralisation des methodes de parsing du code JSON retourné par les
32
 * webservices
33
 * webservices
33
 * 
34
 * 
34
 * @author LIENS
35
 * @author LIENS
35
 * 
36
 * 
36
 */
37
 */
37
public class UtilitairesServiceResultat {
38
public class UtilitairesServiceResultat {
38
 
39
 
39
	/**
40
	/**
40
	 * Recupere un objet Image à partir du JSON
41
	 * Recupere un objet Image à partir du JSON
41
	 * 
42
	 * 
42
	 * @param imageJson
43
	 * @param imageJson
43
	 * @return
44
	 * @return
44
	 */
45
	 */
45
	public static Image parserImageJSON(JSONObject imageJson) {
46
	public static Image parserImageJSON(JSONObject imageJson) {
46
 
47
 
47
		Image image = new Image();
48
		Image image = new Image();
48
		String idImage = imageJson.get("id_image").isString().stringValue();
49
		String idImage = imageJson.get("id_image").isString().stringValue();
49
		image.setIdImage(idImage);
50
		image.setIdImage(idImage);
50
		image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "%s%.jpg");
51
		image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "%s%.jpg");
51
		image.setUrl("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "CRS.jpg");
52
		image.setUrl("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "CRS.jpg");
52
		image.setMiniature("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "XS.jpg");
53
		image.setMiniature("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "XS.jpg");
53
		image.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(imageJson, "mots_cles_texte")));
54
		image.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(imageJson, "mots_cles_texte")));
54
 
55
 
55
		return image;
56
		return image;
56
	}
57
	}
57
 
58
 
58
	/**
59
	/**
59
	 * Recupere un objet Observation à partir du JSON
60
	 * Recupere un objet Observation à partir du JSON
60
	 * 
61
	 * 
61
	 * @param imageJson
62
	 * @param imageJson
62
	 * @return
63
	 * @return
63
	 */
64
	 */
64
	public static Observation parserObservationJSON(JSONObject observationJson) {
65
	public static Observation parserObservationJSON(JSONObject observationJson) {
65
 
66
 
66
		Observation observation = new Observation();
67
		Observation observation = new Observation();
67
		observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom") + " " + getValeurOuVide(observationJson, "auteur.nom"));
68
		observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom") + " " + getValeurOuVide(observationJson, "auteur.nom"));
68
		observation.setNomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
69
		observation.setNomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
69
		observation.setPrenomAuteur(getValeurOuVide(observationJson, "auteur.prenom"));
70
		observation.setPrenomAuteur(getValeurOuVide(observationJson, "auteur.prenom"));
70
		observation.setIdAuteur(getValeurOuVide(observationJson, "auteur.id"));
71
		observation.setIdAuteur(getValeurOuVide(observationJson, "auteur.id"));
71
		// TODO: renvoyer le courriel de l'auteur dans les obs
72
		// TODO: renvoyer le courriel de l'auteur dans les obs
72
		observation.setCourrielAuteur("");
73
		observation.setCourrielAuteur("");
73
		observation.setDateTransmission(getValeurOuVide(observationJson, "date_observation"));
74
		observation.setDateTransmission(getValeurOuVide(observationJson, "date_observation"));
74
		observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
75
		observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
75
		observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
76
		observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
76
		observation.setId(getValeurOuVide(observationJson, "id_observation"));
77
		observation.setId(getValeurOuVide(observationJson, "id_observation"));
77
		observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
78
		observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
78
		observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
79
		observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
79
 
80
 
80
		String nomRetenu = getValeurOuVide(observationJson, "determination.ns");
81
		String nomRetenu = getValeurOuVide(observationJson, "determination.ns");
81
		observation.setNomRetenu(getValeurOuVide(observationJson, "determination.ns"));
82
		observation.setNomRetenu(getValeurOuVide(observationJson, "determination.ns"));
82
		observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
83
		observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
83
		observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
84
		observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
84
		observation.setStation(getValeurOuVide(observationJson, "station"));
85
		observation.setStation(getValeurOuVide(observationJson, "station"));
85
		observation.setCommentaire(getValeurOuVide(observationJson, "commentaire"));
86
		observation.setCommentaire(getValeurOuVide(observationJson, "commentaire"));
86
		observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
87
		observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
87
		observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
88
		observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
88
		JSONValue propositions = observationJson.get("commentaires");
89
		JSONValue propositions = observationJson.get("commentaires");
89
 
90
 
90
		boolean creerPropositionAPartirObs = true;
91
		boolean creerPropositionAPartirObs = true;
91
 
92
 
92
		if (propositions != null && propositions.isObject() != null) {
93
		if (propositions != null && propositions.isObject() != null) {
93
			List<InterventionForum> interventions = parserInterventions(propositions.isObject());
94
			List<InterventionForum> interventions = parserInterventions(propositions.isObject());
94
			for (InterventionForum interventionForum : interventions) {
95
			for (InterventionForum interventionForum : interventions) {
95
				interventionForum.setObservation(observation);
96
				interventionForum.setObservation(observation);
96
				// Si une proposition avec le même nom retenu que l'observation
97
				// Si une proposition avec le même nom retenu que l'observation
97
				// est déjà présente,
98
				// est déjà présente,
98
				// alors il n'est pas nécessaire de créer la proposition
99
				// alors il n'est pas nécessaire de créer la proposition
99
				// "factice"
100
				// "factice"
100
				if (interventionForum instanceof PropositionDetermination) {
101
				if (interventionForum instanceof PropositionDetermination) {
101
					PropositionDetermination proposition = (PropositionDetermination) interventionForum;
102
					PropositionDetermination proposition = (PropositionDetermination) interventionForum;
102
					if (!nomRetenu.equals("") && proposition.getEspece().equals(nomRetenu)) {
103
					if (!nomRetenu.equals("") && proposition.getEspece().equals(nomRetenu)) {
103
						creerPropositionAPartirObs = false;
104
						creerPropositionAPartirObs = false;
104
					}
105
					}
105
				}
106
				}
106
			}
107
			}
107
			observation.setInterventionsForum(interventions);
108
			observation.setInterventionsForum(interventions);
108
		}
109
		}
109
 
110
 
110
		if (creerPropositionAPartirObs) {
111
		if (creerPropositionAPartirObs) {
111
			// Si elle est nécessaire, la proposition factice est ajoutée au
112
			// Si elle est nécessaire, la proposition factice est ajoutée au
112
			// début
113
			// début
113
			observation.getInterventionsForum().add(0, creerPropositionDeterminationAPartirObservation(observation));
114
			observation.getInterventionsForum().add(0, creerPropositionDeterminationAPartirObservation(observation));
114
		}
115
		}
115
		return observation;
116
		return observation;
116
	}
117
	}
117
 
118
 
118
	/**
119
	/**
119
	 * Créée une proposition de determination à partir d'une observation
120
	 * Créée une proposition de determination à partir d'une observation
120
	 * 
121
	 * 
121
	 * @param observation
122
	 * @param observation
122
	 * @return
123
	 * @return
123
	 */
124
	 */
124
	private static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation) {
125
	private static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation) {
125
 
126
 
126
		String utilisateurNom = observation.getNomAuteur();
127
		String utilisateurNom = observation.getNomAuteur();
127
		String utilisateurPrenom = observation.getPrenomAuteur();
128
		String utilisateurPrenom = observation.getPrenomAuteur();
128
 
129
 
129
		String utilisateurCourriel = observation.getCourrielAuteur();
130
		String utilisateurCourriel = observation.getCourrielAuteur();
130
		String utilisateurId = observation.getIdAuteur();
131
		String utilisateurId = observation.getIdAuteur();
131
		PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
132
		PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
132
		Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
133
		Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
133
		propositionDetermination.setContributeur(contributeur);
134
		propositionDetermination.setContributeur(contributeur);
134
		java.util.Date datePropDeter = parserDateObservation(observation.getDateReleve());
135
		java.util.Date datePropDeter = parserDateObservation(observation.getDateReleve());
135
		propositionDetermination.setDate(datePropDeter);
136
		propositionDetermination.setDate(datePropDeter);
136
		propositionDetermination.setEspece(observation.getNomRetenu());
137
		propositionDetermination.setEspece(observation.getNomRetenu());
137
 
138
 
138
		return propositionDetermination;
139
		return propositionDetermination;
139
	}
140
	}
140
 
141
 
141
	/**
142
	/**
142
	 * Recupere une liste de commentaires à partir du JSON
143
	 * Recupere une liste de commentaires à partir du JSON
143
	 * 
144
	 * 
144
	 * @param imageJson
145
	 * @param imageJson
145
	 * @return
146
	 * @return
146
	 */
147
	 */
147
	public static List<Commentaire> parserCommentaires(JSONObject commentaires) {
148
	public static List<Commentaire> parserCommentaires(JSONObject commentaires) {
148
		List<InterventionForum> interventionForums = parserInterventions(commentaires);
149
		List<InterventionForum> interventionForums = parserInterventions(commentaires);
149
		List<Commentaire> commentairesListe = new ArrayList<Commentaire>();
150
		List<Commentaire> commentairesListe = new ArrayList<Commentaire>();
150
		for (InterventionForum interventionForum : interventionForums) {
151
		for (InterventionForum interventionForum : interventionForums) {
151
			if (interventionForum instanceof Commentaire) {
152
			if (interventionForum instanceof Commentaire) {
152
				commentairesListe.add((Commentaire) interventionForum);
153
				commentairesListe.add((Commentaire) interventionForum);
153
			}
154
			}
154
		}
155
		}
155
		return commentairesListe;
156
		return commentairesListe;
156
 
157
 
157
	}
158
	}
158
 
159
 
159
	/**
160
	/**
160
	 * Recupere une liste d'interventions à partir du JSON
161
	 * Recupere une liste d'interventions à partir du JSON
161
	 * 
162
	 * 
162
	 * @param imageJson
163
	 * @param imageJson
163
	 * @return
164
	 * @return
164
	 */
165
	 */
165
	public static List<InterventionForum> parserInterventions(JSONObject interventions) {
166
	public static List<InterventionForum> parserInterventions(JSONObject interventions) {
166
		HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
167
		HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
167
 
168
 
168
		List<InterventionForum> retour = new ArrayList<InterventionForum>();
169
		List<InterventionForum> retour = new ArrayList<InterventionForum>();
169
 
170
 
170
		// parcourir les interventions et en faire un tableau
171
		// parcourir les interventions et en faire un tableau
171
		if (interventions == null) {
172
		if (interventions == null) {
172
			return retour;
173
			return retour;
173
		}
174
		}
174
		Iterator<String> itInterventions = interventions.keySet().iterator();
175
		Iterator<String> itInterventions = interventions.keySet().iterator();
175
		while (itInterventions.hasNext()) {
176
		while (itInterventions.hasNext()) {
176
			JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
177
			JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
177
			String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
178
			String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
178
 
179
 
179
			String id = getValeurOuVide(jsonIntervention, "id_commentaire");
180
			String id = getValeurOuVide(jsonIntervention, "id_commentaire");
180
			String idParent = getValeurOuVide(jsonIntervention, "id_parent");
181
			String idParent = getValeurOuVide(jsonIntervention, "id_parent");
181
			String texte = getValeurOuVide(jsonIntervention, "texte");
182
			String texte = getValeurOuVide(jsonIntervention, "texte");
182
 
183
 
183
			String idUtilisateur = getValeurOuVide(jsonIntervention, "auteur.id");
184
			String idUtilisateur = getValeurOuVide(jsonIntervention, "auteur.id");
184
			String nom = getValeurOuVide(jsonIntervention, "auteur.nom");
185
			String nom = getValeurOuVide(jsonIntervention, "auteur.nom");
185
			String prenom = getValeurOuVide(jsonIntervention, "auteur.prenom");
186
			String prenom = getValeurOuVide(jsonIntervention, "auteur.prenom");
186
			String courriel = getValeurOuVide(jsonIntervention, "auteur.courriel");
187
			String courriel = getValeurOuVide(jsonIntervention, "auteur.courriel");
187
			Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
188
			Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
188
 
189
 
189
			Date date = parserDateObservation(getValeurOuVide(jsonIntervention, "date"));
190
			Date date = parserDateObservation(getValeurOuVide(jsonIntervention, "date"));
190
 
191
 
191
			if (!nomSel.equals("")) {
192
			if (!nomSel.equals("")) {
192
				String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
193
				String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
193
				String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
194
				String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
194
				String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
195
				String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
195
				String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
196
				String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
196
				String famille = getValeurOuVide(jsonIntervention, "famille");
197
				String famille = getValeurOuVide(jsonIntervention, "famille");
197
				String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
198
				String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
198
 
199
 
199
				String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
200
				String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
200
 
201
 
201
				PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
202
				PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
202
				// intervention.setObservation(observation);
203
				// intervention.setObservation(observation);
203
				intervention.setEspece(nom_sel);
204
				intervention.setEspece(nom_sel);
204
 
205
 
205
				if (!nbCommentaires.equals("")) {
206
				if (!nbCommentaires.equals("")) {
206
					int nbComm = Integer.parseInt(nbCommentaires);
207
					int nbComm = Integer.parseInt(nbCommentaires);
207
					// if (!texte.equals("")) {
208
					// if (!texte.equals("")) {
208
					// nbComm++;
209
					// nbComm++;
209
					// }
210
					// }
210
					intervention.setNbCommentaires(nbComm);
211
					intervention.setNbCommentaires(nbComm);
211
				}
212
				}
-
 
213
 
-
 
214
				if (nom_ret_nn != null && !nom_ret_nn.equals("")) {
-
 
215
					intervention.setNumNomenclatural(nom_ret_nn);
-
 
216
				}
212
 
217
				
213
				if (!idParent.equals("")) {
218
				if (!idParent.equals("")) {
214
					intervention.setIdParent(idParent);
219
					intervention.setIdParent(idParent);
215
				}
220
				}
216
 
221
 
217
				if (jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
222
				if (jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
218
					intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject()));
223
					intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject()));
219
				}
224
				}
220
 
225
 
221
				intervention.setDate(date);
226
				intervention.setDate(date);
222
				interventionsNonTypees.put(intervention.getId(), intervention);
227
				interventionsNonTypees.put(intervention.getId(), intervention);
223
 
228
 
224
			} else {
229
			} else {
225
				Commentaire intervention = new Commentaire(contributeur, date, texte);
230
				Commentaire intervention = new Commentaire(contributeur, date, texte);
226
				intervention.setId(id);
231
				intervention.setId(id);
227
				intervention.setDate(date);
232
				intervention.setDate(date);
228
				interventionsNonTypees.put(intervention.getId(), intervention);
233
				interventionsNonTypees.put(intervention.getId(), intervention);
229
				if (!idParent.equals("")) {
234
				if (!idParent.equals("")) {
230
					intervention.setIdParent(idParent);
235
					intervention.setIdParent(idParent);
231
				}
236
				}
232
			}
237
			}
233
		}
238
		}
234
 
239
 
235
		Iterator<String> itIntervention = interventionsNonTypees.keySet().iterator();
240
		Iterator<String> itIntervention = interventionsNonTypees.keySet().iterator();
236
		while (itIntervention.hasNext()) {
241
		while (itIntervention.hasNext()) {
237
			String id = itIntervention.next();
242
			String id = itIntervention.next();
238
			InterventionForum intervention = interventionsNonTypees.get(id);
243
			InterventionForum intervention = interventionsNonTypees.get(id);
239
			String idParent = intervention.getIdParent();
244
			String idParent = intervention.getIdParent();
240
			if (idParent != null && !idParent.equals("") && !idParent.equals("0") && interventionsNonTypees.containsKey(idParent)) {
245
			if (idParent != null && !idParent.equals("") && !idParent.equals("0") && interventionsNonTypees.containsKey(idParent)) {
241
				InterventionForum parent = interventionsNonTypees.get(idParent);
246
				InterventionForum parent = interventionsNonTypees.get(idParent);
242
				intervention.setParent(parent);
247
				intervention.setParent(parent);
243
				parent.ajouterCommentaire((Commentaire) intervention);
248
				parent.ajouterCommentaire((Commentaire) intervention);
244
			} else {
249
			} else {
245
				retour.add(intervention);
250
				retour.add(intervention);
246
			}
251
			}
247
		}
252
		}
248
 
253
 
249
		return retour;
254
		return retour;
250
	}
255
	}
251
 
256
 
252
	/**
257
	/**
253
	 * Recupere une liste de commentaires à partir du JSON
258
	 * Recupere une liste de commentaires à partir du JSON
254
	 * 
259
	 * 
255
	 * @param imageJson
260
	 * @param imageJson
256
	 * @return
261
	 * @return
257
	 */
262
	 */
258
	public static String convertirEtParserRetourAjoutCommentaire(String retour) {
263
	public static String convertirEtParserRetourAjoutCommentaire(String retour) {
259
		JSONObject retourJson = JSONParser.parseStrict(retour).isObject();
264
		JSONObject retourJson = JSONParser.parseStrict(retour).isObject();
260
		return parserRetourAjoutCommentaire(retourJson);
265
		return parserRetourAjoutCommentaire(retourJson);
261
	}
266
	}
262
 
267
 
263
	/**
268
	/**
264
	 * Recupere une liste de commentaires à partir d'un objet JSON
269
	 * Recupere une liste de commentaires à partir d'un objet JSON
265
	 * 
270
	 * 
266
	 * @param imageJson
271
	 * @param imageJson
267
	 * @return
272
	 * @return
268
	 */
273
	 */
269
	public static String parserRetourAjoutCommentaire(JSONObject retour) {
274
	public static String parserRetourAjoutCommentaire(JSONObject retour) {
270
		String id = "";
275
		String id = "";
271
		if (retour != null) {
276
		if (retour != null) {
272
			id = getValeurOuVide(retour, "id_commentaire");
277
			id = getValeurOuVide(retour, "id_commentaire");
273
		}
278
		}
274
		return id;
279
		return id;
275
	}
280
	}
276
 
281
 
277
	public static String getValeurOuVide(JSONObject objet, String index) {
282
	public static String getValeurOuVide(JSONObject objet, String index) {
278
		return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
283
		return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
279
	}
284
	}
280
 
285
 
281
	/**
286
	/**
282
	 * Recupere une liste de votes sur une determination à partir du JSON
287
	 * Recupere une liste de votes sur une determination à partir du JSON
283
	 * 
288
	 * 
284
	 * @param imageJson
289
	 * @param imageJson
285
	 * @return
290
	 * @return
286
	 */
291
	 */
287
	public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString) {
292
	public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString) {
288
 
293
 
289
		HashMap<String, VoteDetermination> retour = null;
294
		HashMap<String, VoteDetermination> retour = null;
290
 
295
 
291
		JSONObject votes = JSONParser.parseStrict(votesString).isObject();
296
		JSONObject votes = JSONParser.parseStrict(votesString).isObject();
292
		if (votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
297
		if (votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
293
			JSONObject resultat = votes.get("resultats").isObject();
298
			JSONObject resultat = votes.get("resultats").isObject();
294
			retour = parserVotesDetermination(resultat);
299
			retour = parserVotesDetermination(resultat);
295
		}
300
		}
296
		return retour;
301
		return retour;
297
	}
302
	}
298
 
303
 
299
	/**
304
	/**
300
	 * Recupere une liste de votes sur une determination à partir d'un objet
305
	 * Recupere une liste de votes sur une determination à partir d'un objet
301
	 * JSON
306
	 * JSON
302
	 * 
307
	 * 
303
	 * @param imageJson
308
	 * @param imageJson
304
	 * @return
309
	 * @return
305
	 */
310
	 */
306
	public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes) {
311
	public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes) {
307
		HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
312
		HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
308
		java.util.Iterator<String> itVotes = votes.keySet().iterator();
313
		java.util.Iterator<String> itVotes = votes.keySet().iterator();
309
		while (itVotes.hasNext()) {
314
		while (itVotes.hasNext()) {
310
			JSONObject vote = votes.get(itVotes.next()).isObject();
315
			JSONObject vote = votes.get(itVotes.next()).isObject();
311
			VoteDetermination vd = new VoteDetermination();
316
			VoteDetermination vd = new VoteDetermination();
312
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
317
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
313
			vd.setDate(parserDateObservation(getValeurOuVide(vote, "date")));
318
			vd.setDate(parserDateObservation(getValeurOuVide(vote, "date")));
314
			vd.setId(getValeurOuVide(vote, "vote.id"));
319
			vd.setId(getValeurOuVide(vote, "vote.id"));
315
			vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
320
			vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
316
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
321
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
317
 
322
 
318
			if (vote.get("auteur.nom") != null && vote.get("auteur.nom") != null && vote.get("auteur.courriel") != null) {
323
			if (vote.get("auteur.nom") != null && vote.get("auteur.nom") != null && vote.get("auteur.courriel") != null) {
319
				Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"), getValeurOuVide(vote, "auteur.nom"), getValeurOuVide(vote, "auteur.prenom"), getValeurOuVide(vote, "auteur.courriel"));
324
				Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"), getValeurOuVide(vote, "auteur.nom"), getValeurOuVide(vote, "auteur.prenom"), getValeurOuVide(vote, "auteur.courriel"));
320
				vd.setAuteur(auteur);
325
				vd.setAuteur(auteur);
321
			}
326
			}
322
 
327
 
323
			votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
328
			votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
324
		}
329
		}
325
		return votesDetermination;
330
		return votesDetermination;
326
	}
331
	}
327
 
332
 
328
	/**
333
	/**
329
	 * Recupere une liste de votes sur des images à partir d'un objet JSON
334
	 * Recupere une liste de votes sur des images à partir d'un objet JSON
330
	 * 
335
	 * 
331
	 * @param imageJson
336
	 * @param imageJson
332
	 * @return
337
	 * @return
333
	 */
338
	 */
334
	public static HashMap<String, HashMap<String, VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
339
	public static HashMap<String, HashMap<String, VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
335
 
340
 
336
		HashMap<String, HashMap<String, VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String, VoteProtocole>>();
341
		HashMap<String, HashMap<String, VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String, VoteProtocole>>();
337
		java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
342
		java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
338
		while (itProtocoles.hasNext()) {
343
		while (itProtocoles.hasNext()) {
339
			JSONObject protocole = votes.get(itProtocoles.next()).isObject();
344
			JSONObject protocole = votes.get(itProtocoles.next()).isObject();
340
			JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
345
			JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
341
			String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
346
			String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
342
			java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
347
			java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
343
			while (itVotes.hasNext()) {
348
			while (itVotes.hasNext()) {
344
				JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
349
				JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
345
				VoteProtocole vd = new VoteProtocole();
350
				VoteProtocole vd = new VoteProtocole();
346
				vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
351
				vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
347
				// TODO récupérer la date du vote et la parser
352
				// TODO récupérer la date du vote et la parser
348
				vd.setDate(parserDateObservation(getValeurOuVide(voteEnCours, "date")));
353
				vd.setDate(parserDateObservation(getValeurOuVide(voteEnCours, "date")));
349
				int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
354
				int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
350
				vd.setVote(valeurVote);
355
				vd.setVote(valeurVote);
351
				if (!votesProtocoles.containsKey(idProtocoleVote)) {
356
				if (!votesProtocoles.containsKey(idProtocoleVote)) {
352
					votesProtocoles.put(idProtocoleVote, new HashMap<String, VoteProtocole>());
357
					votesProtocoles.put(idProtocoleVote, new HashMap<String, VoteProtocole>());
353
				}
358
				}
354
				votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
359
				votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
355
			}
360
			}
356
		}
361
		}
357
 
362
 
358
		return votesProtocoles;
363
		return votesProtocoles;
359
	}
364
	}
360
 
365
 
361
	/**
366
	/**
362
	 * Recupere une date à partir du JSON
367
	 * Recupere une date à partir du JSON
363
	 * 
368
	 * 
364
	 * @param imageJson
369
	 * @param imageJson
365
	 * @return
370
	 * @return
366
	 */
371
	 */
367
	public static Date parserDateObservation(String date) {
372
	public static Date parserDateObservation(String date) {
368
		Date dateParsee = new Date();
373
		Date dateParsee = new Date();
369
		DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
374
		DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
370
		try {
375
		try {
371
			dateParsee = formatDateObs.parse(date);
376
			dateParsee = formatDateObs.parse(date);
372
		} catch (IllegalArgumentException e) {
377
		} catch (IllegalArgumentException e) {
373
			dateParsee = new java.sql.Date(0);
378
			dateParsee = new java.sql.Date(0);
374
		}
379
		}
375
		return dateParsee;
380
		return dateParsee;
376
	}
381
	}
377
 
382
 
378
	/**
383
	/**
379
	 * Recupere des mots-clefs à partir du JSON
384
	 * Recupere des mots-clefs à partir du JSON
380
	 * 
385
	 * 
381
	 * @param imageJson
386
	 * @param imageJson
382
	 * @return
387
	 * @return
383
	 */
388
	 */
384
	public static List<String> parserMotsCles(String motsClesTexte) {
389
	public static List<String> parserMotsCles(String motsClesTexte) {
385
		String[] tabMotsCle = motsClesTexte.split(",");
390
		String[] tabMotsCle = motsClesTexte.split(",");
386
		List<String> motsClesParses = new ArrayList<String>();
391
		List<String> motsClesParses = new ArrayList<String>();
387
		for (int i = 0; i < tabMotsCle.length; i++) {
392
		for (int i = 0; i < tabMotsCle.length; i++) {
388
			motsClesParses.add(tabMotsCle[i].trim());
393
			motsClesParses.add(tabMotsCle[i].trim());
389
		}
394
		}
390
 
395
 
391
		return motsClesParses;
396
		return motsClesParses;
392
	}
397
	}
393
 
398
 
394
	public static String getIdAvecPadding(String id) {
399
	public static String getIdAvecPadding(String id) {
395
		int maxZeros = 9 - id.length();
400
		int maxZeros = 9 - id.length();
396
		for (int i = 0; i < maxZeros; i++) {
401
		for (int i = 0; i < maxZeros; i++) {
397
			id = "0" + id;
402
			id = "0" + id;
398
		}
403
		}
399
		return id;
404
		return id;
400
	}
405
	}
401
 
406
 
402
	/**
407
	/**
403
	 * Recupere un utilisateur à partir du JSON
408
	 * Recupere un utilisateur à partir du JSON
404
	 * 
409
	 * 
405
	 * @param imageJson
410
	 * @param imageJson
406
	 * @return
411
	 * @return
407
	 */
412
	 */
408
	public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
413
	public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
409
 
414
 
410
		JSONObject utilisateurJson = valeurJson.isObject();
415
		JSONObject utilisateurJson = valeurJson.isObject();
411
		boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
416
		boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
412
		String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
417
		String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
413
 
418
 
414
		Utilisateur utilisateur;
419
		Utilisateur utilisateur;
415
 
420
 
416
		if (connecteUtilisateur) {
421
		if (connecteUtilisateur) {
417
			String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
422
			String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
418
			String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
423
			String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
419
			String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
424
			String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
420
 
425
 
421
			utilisateur = new Utilisateur(idUtilisateur, prenomUtilisateur, nomUtilisateur, courrielUtilisateur);
426
			utilisateur = new Utilisateur(idUtilisateur, prenomUtilisateur, nomUtilisateur, courrielUtilisateur);
422
		} else {
427
		} else {
423
			utilisateur = new Utilisateur(idUtilisateur);
428
			utilisateur = new Utilisateur(idUtilisateur);
424
		}
429
		}
425
 
430
 
426
		return utilisateur;
431
		return utilisateur;
427
	}
432
	}
428
 
433
 
429
	/**
434
	/**
430
	 * Retourne un objet {@link ProtocoleServiceResultat} à partir d'un objet
435
	 * Retourne un objet {@link ProtocoleServiceResultat} à partir d'un objet
431
	 * JSON
436
	 * JSON
432
	 * 
437
	 * 
433
	 * @param retourJson
438
	 * @param retourJson
434
	 * @return
439
	 * @return
435
	 */
440
	 */
436
	public static ProtocoleServiceResultat parserProtocoleServiceResultat(JSONValue retourJson) {
441
	public static ProtocoleServiceResultat parserProtocoleServiceResultat(JSONValue retourJson) {
437
		List<Protocole> protocoles = new ArrayList<Protocole>();
442
		List<Protocole> protocoles = new ArrayList<Protocole>();
438
		JSONObject tableauProto = retourJson.isObject().get("resultats").isObject();
443
		JSONObject tableauProto = retourJson.isObject().get("resultats").isObject();
439
 
444
 
440
		if (tableauProto != null) {
445
		if (tableauProto != null) {
441
			java.util.Iterator<String> it = tableauProto.keySet().iterator();
446
			java.util.Iterator<String> it = tableauProto.keySet().iterator();
442
			while (it.hasNext()) {
447
			while (it.hasNext()) {
443
 
448
 
444
				JSONObject protocoleJSON = tableauProto.get(it.next()).isObject();
449
				JSONObject protocoleJSON = tableauProto.get(it.next()).isObject();
445
				Protocole protocole = new Protocole();
450
				Protocole protocole = new Protocole();
446
				String idProtocole = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.id");
451
				String idProtocole = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.id");
447
				protocole.setId(Integer.parseInt(idProtocole));
452
				protocole.setId(Integer.parseInt(idProtocole));
448
				protocole.setNom(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.intitule"));
453
				protocole.setNom(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.intitule"));
449
				protocole.setDescription(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.descriptif"));
454
				protocole.setDescription(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.descriptif"));
450
				protocoles.add(protocole);
455
				protocoles.add(protocole);
451
			}
456
			}
452
		}
457
		}
453
 
458
 
454
		return new ProtocoleServiceResultat(protocoles);
459
		return new ProtocoleServiceResultat(protocoles);
455
	}
460
	}
456
 
461
 
457
	/**
462
	/**
458
	 * Retourne un objet {@link ImageServiceResultat} à partir du JSON
463
	 * Retourne un objet {@link ImageServiceResultat} à partir du JSON
459
	 * 
464
	 * 
460
	 * @param retourJson
465
	 * @param retourJson
461
	 * @return
466
	 * @return
462
	 */
467
	 */
463
	public static ImageServiceResultat parserImageServiceResultat(JSONValue retourJson) {
468
	public static ImageServiceResultat parserImageServiceResultat(JSONValue retourJson) {
464
 
469
 
465
		ImageServiceResultat imageServiceResultat = new ImageServiceResultat();
470
		ImageServiceResultat imageServiceResultat = new ImageServiceResultat();
466
		int nbTotalImagesPourLaRecherche;
471
		int nbTotalImagesPourLaRecherche;
467
 
472
 
468
		List<Image> images = new ArrayList<Image>();
473
		List<Image> images = new ArrayList<Image>();
469
		// TODO ajouter vérifications plus précises
474
		// TODO ajouter vérifications plus précises
470
		if (retourJson.isObject().get("entete") != null) {
475
		if (retourJson.isObject().get("entete") != null) {
471
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
476
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
472
			nbTotalImagesPourLaRecherche = (int) total;
477
			nbTotalImagesPourLaRecherche = (int) total;
473
			JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
478
			JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
474
			if (tableauImg != null) {
479
			if (tableauImg != null) {
475
				java.util.Iterator<String> it = tableauImg.keySet().iterator();
480
				java.util.Iterator<String> it = tableauImg.keySet().iterator();
476
				while (it.hasNext()) {
481
				while (it.hasNext()) {
477
					JSONObject imageJson = tableauImg.get(it.next()).isObject();
482
					JSONObject imageJson = tableauImg.get(it.next()).isObject();
478
					Image image = parserRetourImage(imageJson);
483
					Image image = parserRetourImage(imageJson);
479
					images.add(image);
484
					images.add(image);
480
				}
485
				}
481
			}
486
			}
482
 
487
 
483
		} else {
488
		} else {
484
			JSONArray tableauImg = retourJson.isObject().get("images").isArray();
489
			JSONArray tableauImg = retourJson.isObject().get("images").isArray();
485
			nbTotalImagesPourLaRecherche = (int) tableauImg.size();
490
			nbTotalImagesPourLaRecherche = (int) tableauImg.size();
486
			for (int i = 0; i < nbTotalImagesPourLaRecherche; i++) {
491
			for (int i = 0; i < nbTotalImagesPourLaRecherche; i++) {
487
				JSONObject imageJson = tableauImg.get(i).isObject();
492
				JSONObject imageJson = tableauImg.get(i).isObject();
488
				Image image = parserRetourImage(imageJson);
493
				Image image = parserRetourImage(imageJson);
489
				images.add(image);
494
				images.add(image);
490
			}
495
			}
491
		}
496
		}
492
 
497
 
493
		imageServiceResultat.setImages(images);
498
		imageServiceResultat.setImages(images);
494
		imageServiceResultat.setNbTotalImagesPourLaRecherche(nbTotalImagesPourLaRecherche);
499
		imageServiceResultat.setNbTotalImagesPourLaRecherche(nbTotalImagesPourLaRecherche);
495
 
500
 
496
		return imageServiceResultat;
501
		return imageServiceResultat;
497
 
502
 
498
	}
503
	}
499
 
504
 
500
	/**
505
	/**
501
	 * Retourne un objet {@link Image} à partir du JSON
506
	 * Retourne un objet {@link Image} à partir du JSON
502
	 * 
507
	 * 
503
	 * @param retourJson
508
	 * @param retourJson
504
	 * @return
509
	 * @return
505
	 */
510
	 */
506
	public static Image parserRetourImage(JSONObject imageJson) {
511
	public static Image parserRetourImage(JSONObject imageJson) {
507
		Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
512
		Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
508
 
513
 
509
		if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
514
		if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
510
			JSONObject observationJson = imageJson.get("observation").isObject();
515
			JSONObject observationJson = imageJson.get("observation").isObject();
511
			image.setObservation(UtilitairesServiceResultat.parserObservationJSON(observationJson));
516
			image.setObservation(UtilitairesServiceResultat.parserObservationJSON(observationJson));
512
		}
517
		}
513
 
518
 
514
		if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
519
		if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
515
			JSONObject votes = imageJson.get("protocoles_votes").isObject();
520
			JSONObject votes = imageJson.get("protocoles_votes").isObject();
516
			image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
521
			image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
517
		}
522
		}
518
 
523
 
519
		return image;
524
		return image;
520
	}
525
	}
521
 
526
 
522
	/**
527
	/**
523
	 * Retourne un objet {@link ObservationServiceResultat} à partir du JSON
528
	 * Retourne un objet {@link ObservationServiceResultat} à partir du JSON
524
	 * 
529
	 * 
525
	 * @param retourJson
530
	 * @param retourJson
526
	 * @return
531
	 * @return
527
	 */
532
	 */
528
	public static ObservationServiceResultat parserObservationServiceResultat(JSONValue retourJson) {
533
	public static ObservationServiceResultat parserObservationServiceResultat(JSONValue retourJson) {
529
 
534
 
530
		ObservationServiceResultat observationServiceResultat = new ObservationServiceResultat();
535
		ObservationServiceResultat observationServiceResultat = new ObservationServiceResultat();
531
 
536
 
532
		List<Observation> observations = new ArrayList<Observation>();
537
		List<Observation> observations = new ArrayList<Observation>();
533
		int nbTotalObservationsPourLaRecherche = 0;
538
		int nbTotalObservationsPourLaRecherche = 0;
534
 
539
 
535
		if (retourJson.isObject().get("entete") != null) {
540
		if (retourJson.isObject().get("entete") != null) {
536
			// TODO ajouter vérifications plus précises
541
			// TODO ajouter vérifications plus précises
537
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
542
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
538
			nbTotalObservationsPourLaRecherche = (int) total;
543
			nbTotalObservationsPourLaRecherche = (int) total;
539
			JSONObject tableauObs = retourJson.isObject().get("resultats").isObject();
544
			JSONObject tableauObs = retourJson.isObject().get("resultats").isObject();
540
 
545
 
541
			if (tableauObs != null) {
546
			if (tableauObs != null) {
542
				java.util.Iterator<String> it = tableauObs.keySet().iterator();
547
				java.util.Iterator<String> it = tableauObs.keySet().iterator();
543
				while (it.hasNext()) {
548
				while (it.hasNext()) {
544
					JSONObject observationJson = tableauObs.get(it.next()).isObject();
549
					JSONObject observationJson = tableauObs.get(it.next()).isObject();
545
					Observation observation = analyserObservation(observationJson);
550
					Observation observation = analyserObservation(observationJson);
546
					observations.add(observation);
551
					observations.add(observation);
547
				}
552
				}
548
			}
553
			}
549
		} else {
554
		} else {
550
			JSONObject observationJson = retourJson.isObject();
555
			JSONObject observationJson = retourJson.isObject();
551
			Observation observation = analyserObservation(observationJson);
556
			Observation observation = analyserObservation(observationJson);
552
			observations.add(observation);
557
			observations.add(observation);
553
			CacheClient.getInstance().setObservationCourante(observation);
558
			CacheClient.getInstance().setObservationCourante(observation);
554
		}
559
		}
555
 
560
 
556
		observationServiceResultat.setObservations(observations);
561
		observationServiceResultat.setObservations(observations);
557
		observationServiceResultat.setNbTotalObservationsPourLaRecherche(nbTotalObservationsPourLaRecherche);
562
		observationServiceResultat.setNbTotalObservationsPourLaRecherche(nbTotalObservationsPourLaRecherche);
558
 
563
 
559
		return observationServiceResultat;
564
		return observationServiceResultat;
560
	}
565
	}
561
 
566
 
562
	/**
567
	/**
563
	 * Retourne un objet {@link Observation} avec ses {@link Image} associées à
568
	 * Retourne un objet {@link Observation} avec ses {@link Image} associées à
564
	 * partir du JSON
569
	 * partir du JSON
565
	 * 
570
	 * 
566
	 * @param retourJson
571
	 * @param retourJson
567
	 * @return
572
	 * @return
568
	 */
573
	 */
569
	private static Observation analyserObservation(JSONObject observationJson) {
574
	private static Observation analyserObservation(JSONObject observationJson) {
570
		Observation observation = UtilitairesServiceResultat.parserObservationJSON(observationJson);
575
		Observation observation = UtilitairesServiceResultat.parserObservationJSON(observationJson);
571
		JSONArray tableauImagesObs = observationJson.get("images").isArray();
576
		JSONArray tableauImagesObs = observationJson.get("images").isArray();
572
		List<Image> imagesPourObs = new ArrayList<Image>();
577
		List<Image> imagesPourObs = new ArrayList<Image>();
573
 
578
 
574
		int nbImages = tableauImagesObs.size();
579
		int nbImages = tableauImagesObs.size();
575
		for (int j = 0; j < nbImages; j++) {
580
		for (int j = 0; j < nbImages; j++) {
576
			JSONObject imageJson = tableauImagesObs.get(j).isObject();
581
			JSONObject imageJson = tableauImagesObs.get(j).isObject();
577
 
582
 
578
			Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
583
			Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
579
			if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
584
			if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
580
				JSONObject votes = imageJson.get("protocoles_votes").isObject();
585
				JSONObject votes = imageJson.get("protocoles_votes").isObject();
581
				image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
586
				image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
582
			}
587
			}
583
			image.setObservation(observation);
588
			image.setObservation(observation);
584
			imagesPourObs.add(image);
589
			imagesPourObs.add(image);
585
		}
590
		}
586
 
591
 
587
		observation.setImages(imagesPourObs);
592
		observation.setImages(imagesPourObs);
588
 
593
 
589
		return observation;
594
		return observation;
590
	}
595
	}
591
 
596
 
592
}
597
}