Subversion Repositories eFlore/Applications.del

Rev

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

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