Subversion Repositories eFlore/Applications.del

Rev

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

Rev 2090 Rev 2102
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.LinkedHashMap;
7
import java.util.LinkedHashMap;
8
import java.util.List;
8
import java.util.List;
9
import java.util.Map;
9
import java.util.Map;
-
 
10
 
10
 
11
import org.tela_botanica.del.client.Del;
11
import org.tela_botanica.del.client.cache.CacheClient;
12
import org.tela_botanica.del.client.cache.CacheClient;
12
import org.tela_botanica.del.client.config.Config;
13
import org.tela_botanica.del.client.config.Config;
13
import org.tela_botanica.del.client.i18n.I18n;
14
import org.tela_botanica.del.client.i18n.I18n;
14
import org.tela_botanica.del.client.modeles.ActiviteUtilisateur;
15
import org.tela_botanica.del.client.modeles.ActiviteUtilisateur;
15
import org.tela_botanica.del.client.modeles.AuthInfo;
16
import org.tela_botanica.del.client.modeles.AuthInfo;
16
import org.tela_botanica.del.client.modeles.Commentaire;
17
import org.tela_botanica.del.client.modeles.Commentaire;
17
import org.tela_botanica.del.client.modeles.Contributeur;
18
import org.tela_botanica.del.client.modeles.Contributeur;
18
import org.tela_botanica.del.client.modeles.EvenementObs;
19
import org.tela_botanica.del.client.modeles.EvenementObs;
19
import org.tela_botanica.del.client.modeles.Image;
20
import org.tela_botanica.del.client.modeles.Image;
20
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
21
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
21
import org.tela_botanica.del.client.modeles.InterventionForum;
22
import org.tela_botanica.del.client.modeles.InterventionForum;
22
import org.tela_botanica.del.client.modeles.MotCle;
23
import org.tela_botanica.del.client.modeles.MotCle;
23
import org.tela_botanica.del.client.modeles.Observation;
24
import org.tela_botanica.del.client.modeles.Observation;
24
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
25
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
25
import org.tela_botanica.del.client.modeles.PropositionDetermination;
26
import org.tela_botanica.del.client.modeles.PropositionDetermination;
26
import org.tela_botanica.del.client.modeles.Protocole;
27
import org.tela_botanica.del.client.modeles.Protocole;
27
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
28
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
28
import org.tela_botanica.del.client.modeles.Utilisateur;
29
import org.tela_botanica.del.client.modeles.Utilisateur;
29
import org.tela_botanica.del.client.modeles.VoteDetermination;
30
import org.tela_botanica.del.client.modeles.VoteDetermination;
30
import org.tela_botanica.del.client.modeles.VoteProtocole;
31
import org.tela_botanica.del.client.modeles.VoteProtocole;
31
 
32
 
32
import com.google.gwt.core.shared.GWT;
33
import com.google.gwt.core.shared.GWT;
33
import com.google.gwt.user.client.Window;
-
 
34
import com.google.gwt.i18n.client.DateTimeFormat;
34
import com.google.gwt.i18n.client.DateTimeFormat;
35
import com.google.gwt.json.client.JSONArray;
35
import com.google.gwt.json.client.JSONArray;
36
import com.google.gwt.json.client.JSONNumber;
36
import com.google.gwt.json.client.JSONNumber;
37
import com.google.gwt.json.client.JSONObject;
37
import com.google.gwt.json.client.JSONObject;
38
import com.google.gwt.json.client.JSONParser;
38
import com.google.gwt.json.client.JSONParser;
39
import com.google.gwt.json.client.JSONString;
39
import com.google.gwt.json.client.JSONString;
40
import com.google.gwt.json.client.JSONValue;
40
import com.google.gwt.json.client.JSONValue;
41
 
41
 
42
/**
42
/**
43
 * Centralisation des methodes de parsing du code JSON retourné par les
43
 * Centralisation des methodes de parsing du code JSON retourné par les
44
 * webservices
44
 * webservices
45
 * 
45
 * 
46
 * @author LIENS
46
 * @author LIENS
47
 * 
47
 * 
48
 */
48
 */
49
public class UtilitairesServiceResultat {
49
public class UtilitairesServiceResultat {
50
 
50
 
51
	/**
51
	/**
52
	 * Recupere un objet Image à partir du JSON
52
	 * Recupere un objet Image à partir du JSON
53
	 * 
53
	 * 
54
	 * @param imageJson
54
	 * @param imageJson
55
	 * @return
55
	 * @return
56
	 */
56
	 */
57
	public static Image parserImageJSON(JSONObject imageJson) {
57
	public static Image parserImageJSON(JSONObject imageJson) {
58
 
58
 
59
		Image image = new Image();
59
		Image image = new Image();
60
		Config config = new Config();
60
		Config config = new Config();
61
		String urlImages = config.getUrl("images");
61
		String urlImages = config.getUrl("images");
62
		String idImage = imageJson.get("id_image").isString().stringValue();
62
		String idImage = imageJson.get("id_image").isString().stringValue();
63
		image.setIdImage(idImage);
63
		image.setIdImage(idImage);
64
		image.setUrlFormat(urlImages + getIdAvecPadding(idImage) + "%s%.jpg");
64
		image.setUrlFormat(urlImages + getIdAvecPadding(idImage) + "%s%.jpg");
65
		image.setUrl(urlImages + getIdAvecPadding(idImage) + "CRS.jpg");
65
		image.setUrl(urlImages + getIdAvecPadding(idImage) + "CRS.jpg");
66
		image.setMiniature(urlImages + getIdAvecPadding(idImage) + "XS.jpg");
66
		image.setMiniature(urlImages + getIdAvecPadding(idImage) + "XS.jpg");
67
		image.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(imageJson, "mots_cles_texte")));
67
		image.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(imageJson, "mots_cles_texte")));
68
 
68
 
69
		return image;
69
		return image;
70
	}
70
	}
71
 
71
 
72
	/**
72
	/**
73
	 * Recupere un objet Observation à partir du JSON
73
	 * Recupere un objet Observation à partir du JSON
74
	 * 
74
	 * 
75
	 * @param imageJson
75
	 * @param imageJson
76
	 * @return
76
	 * @return
77
	 */
77
	 */
78
	public static Observation parserObservationJSON(JSONObject observationJson) {
78
	public static Observation parserObservationJSON(JSONObject observationJson) {
79
 
79
 
80
		Observation observation = new Observation();
80
		Observation observation = new Observation();
81
		observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom") + " " + getValeurOuVide(observationJson, "auteur.nom"));
81
		observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom") + " " + getValeurOuVide(observationJson, "auteur.nom"));
82
		observation.setNomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
82
		observation.setNomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
83
		observation.setPrenomAuteur(getValeurOuVide(observationJson, "auteur.prenom"));
83
		observation.setPrenomAuteur(getValeurOuVide(observationJson, "auteur.prenom"));
84
		observation.setIdAuteur(getValeurOuVide(observationJson, "auteur.id"));
84
		observation.setIdAuteur(getValeurOuVide(observationJson, "auteur.id"));
85
		// TODO: renvoyer le courriel de l'auteur dans les obs
85
		// TODO: renvoyer le courriel de l'auteur dans les obs
86
		observation.setCourrielAuteur(getValeurOuVide(observationJson, "auteur.courriel"));
86
		observation.setCourrielAuteur(getValeurOuVide(observationJson, "auteur.courriel"));
87
		observation.setDateTransmission(getValeurOuVide(observationJson, "date_transmission"));
87
		observation.setDateTransmission(getValeurOuVide(observationJson, "date_transmission"));
88
		observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
88
		observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
89
		observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
89
		observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
90
		observation.setId(getValeurOuVide(observationJson, "id_observation"));
90
		observation.setId(getValeurOuVide(observationJson, "id_observation"));
91
		observation.setPays(getValeurOuVide(observationJson, "pays"));
91
		observation.setPays(getValeurOuVide(observationJson, "pays"));
92
		observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
92
		observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
93
		observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
93
		observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
94
 
94
 
95
		String nomRetenu = getValeurOuVide(observationJson, "determination.ns");
95
		String nomRetenu = getValeurOuVide(observationJson, "determination.ns");
96
		// Pour afficher quelque chose de plus pertinent qu'un nom vide
96
		// Pour afficher quelque chose de plus pertinent qu'un nom vide
97
		// (il en existe parfois et cela fausse l'affichage)
97
		// (il en existe parfois et cela fausse l'affichage)
98
		if(nomRetenu.trim().isEmpty()) {
98
		if(nomRetenu.trim().isEmpty()) {
99
			nomRetenu = I18n.getVocabulary().indeterminee();
99
			nomRetenu = I18n.getVocabulary().indeterminee();
100
		}
100
		}
101
		observation.setNomRetenu(nomRetenu);
101
		observation.setNomRetenu(nomRetenu);
102
		observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
102
		observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
103
		observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
103
		observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
104
		observation.setStation(getValeurOuVide(observationJson, "station"));
104
		observation.setStation(getValeurOuVide(observationJson, "station"));
105
		observation.setCommentaire(getValeurOuVide(observationJson, "commentaire"));
105
		observation.setCommentaire(getValeurOuVide(observationJson, "commentaire"));
106
		observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
106
		observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
107
		observation.setReferentiel(getValeurOuVide(observationJson, "determination.referentiel"));
107
		observation.setReferentiel(getValeurOuVide(observationJson, "determination.referentiel"));
108
		String nbCom = getValeurOuVide(observationJson, "nb_commentaires");
108
		String nbCom = getValeurOuVide(observationJson, "nb_commentaires");
109
		nbCom = nbCom.equals("") ? "0" : nbCom;
109
		nbCom = nbCom.equals("") ? "0" : nbCom;
110
		observation.setNbCommentaires(nbCom);
110
		observation.setNbCommentaires(nbCom);
111
		observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
111
		observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
112
		JSONValue propositions = observationJson.get("commentaires");
112
		JSONValue propositions = observationJson.get("commentaires");
113
		
113
		
114
		JSONValue evenements = observationJson.get("evenements");
114
		JSONValue evenements = observationJson.get("evenements");
115
		List<EvenementObs> evenementsObs = new ArrayList<EvenementObs>();
115
		List<EvenementObs> evenementsObs = new ArrayList<EvenementObs>();
116
		if (evenements != null && evenements.isArray() != null) {
116
		if (evenements != null && evenements.isArray() != null) {
117
			JSONArray evenementsTab = evenements.isArray();
117
			JSONArray evenementsTab = evenements.isArray();
118
			for (int i = 0; i < evenementsTab.size(); i++) {
118
			for (int i = 0; i < evenementsTab.size(); i++) {
119
				String type = evenementsTab.get(i).isObject().get("type").isString().stringValue();
119
				String type = evenementsTab.get(i).isObject().get("type").isString().stringValue();
120
				String infosComplementaires = evenementsTab.get(i).isObject().get("infos_complementaires").isString().stringValue();
120
				String infosComplementaires = evenementsTab.get(i).isObject().get("infos_complementaires").isString().stringValue();
121
				EvenementObs evtObs = new EvenementObs(type, infosComplementaires);
121
				EvenementObs evtObs = new EvenementObs(type, infosComplementaires);
122
				evenementsObs.add(evtObs);
122
				evenementsObs.add(evtObs);
123
			}
123
			}
124
		}
124
		}
125
		observation.setEvenementsAssocies(evenementsObs);
125
		observation.setEvenementsAssocies(evenementsObs);
126
 
126
 
127
		boolean creerPropositionAPartirObs = true;
127
		boolean creerPropositionAPartirObs = true;
128
		boolean propositionInitialeExiste = false;
128
		boolean propositionInitialeExiste = false;
129
		PropositionDetermination propositionPotentiellementInitiale = null;
129
		PropositionDetermination propositionPotentiellementInitiale = null;
130
		if (propositions != null && propositions.isObject() != null) {
130
		if (propositions != null && propositions.isObject() != null) {
131
			List<InterventionForum> interventions = parserInterventions(propositions.isObject());
131
			List<InterventionForum> interventions = parserInterventions(propositions.isObject());
132
			
132
			
133
			for (InterventionForum interventionForum : interventions) {
133
			for (InterventionForum interventionForum : interventions) {
134
				interventionForum.setObservation(observation);
134
				interventionForum.setObservation(observation);
135
				if (interventionForum instanceof PropositionDetermination) {
135
				if (interventionForum instanceof PropositionDetermination) {
136
					PropositionDetermination proposition = (PropositionDetermination) interventionForum;
136
					PropositionDetermination proposition = (PropositionDetermination) interventionForum;
137
					// Si une proposition avec les même nums noms et référentiel que l'observation est déjà présente,
137
					// Si une proposition avec les même nums noms et référentiel que l'observation est déjà présente,
138
					// alors il n'est pas nécessaire de créer la proposition "factice"
138
					// alors il n'est pas nécessaire de créer la proposition "factice"
139
					if (especePropositionEtObservationCorrespondent(observation, proposition)) {	
139
					if (especePropositionEtObservationCorrespondent(observation, proposition)) {	
140
						creerPropositionAPartirObs = false;
140
						creerPropositionAPartirObs = false;
141
						// Si de plus les auteurs correspondent, alors nous avons affaire à la proposition initiale
141
						// Si de plus les auteurs correspondent, alors nous avons affaire à la proposition initiale
142
						if(proposition.getContributeur().getNomComplet().equals(observation.getAuteur())) {
142
						if(proposition.getContributeur().getNomComplet().equals(observation.getAuteur())) {
143
							propositionPotentiellementInitiale = proposition;
143
							propositionPotentiellementInitiale = proposition;
144
						}
144
						}
145
					}
145
					}
146
					
146
					
147
					if (proposition.estPropositionInitiale()) {
147
					if (proposition.estPropositionInitiale()) {
148
						propositionInitialeExiste = true;
148
						propositionInitialeExiste = true;
149
					}
149
					}
150
				}
150
				}
151
			}
151
			}
152
			observation.setInterventionsForum(interventions);
152
			observation.setInterventionsForum(interventions);
153
		}
153
		}
154
		
154
		
155
		if (!propositionInitialeExiste && propositionPotentiellementInitiale != null) {
155
		if (!propositionInitialeExiste && propositionPotentiellementInitiale != null) {
156
			// Ceci permet à la la proposition d'être mise en valeur différemment dans l'interface
156
			// Ceci permet à la la proposition d'être mise en valeur différemment dans l'interface
157
			propositionPotentiellementInitiale.setEstPropositionInitiale(true);
157
			propositionPotentiellementInitiale.setEstPropositionInitiale(true);
158
		}
158
		}
159
		 
159
		 
160
		if (creerPropositionAPartirObs) {
160
		if (creerPropositionAPartirObs) {
161
			// Si elle est nécessaire, la proposition factice est ajoutée au début
161
			// Si elle est nécessaire, la proposition factice est ajoutée au début
162
			observation.getInterventionsForum().add(0, creerPropositionDeterminationAPartirObservation(observation, propositionInitialeExiste));
162
			observation.getInterventionsForum().add(0, creerPropositionDeterminationAPartirObservation(observation, propositionInitialeExiste));
163
		}
163
		}
164
		return observation;
164
		return observation;
165
 
165
 
166
	}
166
	}
167
	
167
 
168
	public static boolean especePropositionEtObservationCorrespondent(Observation observation, PropositionDetermination proposition) {
168
	public static boolean especePropositionEtObservationCorrespondent(Observation observation, PropositionDetermination proposition) {
169
		boolean correspondent = false;
169
		boolean correspondent = false;
-
 
170
		String obsNN = observation.getNumNomenclatural();
-
 
171
		String obsRef = observation.getReferentiel();
-
 
172
		String propNN = proposition.getNumNomenclatural();
-
 
173
		String propRef = proposition.getReferentiel();
-
 
174
		boolean obnNNVide = obsNN == null || obsNN.isEmpty() || obsNN.equals("0");
-
 
175
		boolean propNNVide = propNN == null || propNN.isEmpty() || propNN.equals("0");
-
 
176
 
-
 
177
		/*Del.LogVersFirebug(
-
 
178
			"OBS NN: [" + obsNN
-
 
179
			+ "], OBS REF: [" + obsRef
-
 
180
			+ "], PROP NN: [" + propNN
-
 
181
			//+ "], PROP NS: [" + proposition.getEspece()
-
 
182
			+ "], PROP REF: [" + propRef
-
 
183
			+ "]"
-
 
184
		);*/
-
 
185
 
170
		// pas la peine de comparer deux choses pourraient éventuellement être vide 
186
		// @WARNING patch crado en raison d'une conception poucrave de cette appli cliente : la
-
 
187
		// présence d'une obs non liée à un référentiel, même si ce n'est pas celle qui est
171
		if(!observation.getNumNomenclatural().isEmpty() && !observation.getReferentiel().isEmpty()) {
188
		// actuellement retenue, entraînera une disparition de la proposition actuellement retenue;
-
 
189
		// mais ce n'est pas censé arriver, car à la première création d'une proposition, la
-
 
190
		// proposition initiale doit être matérialisée (j'ai bon ? pas sûr :P)
-
 
191
 
-
 
192
		// soit les NN sont à zéro ou null (proposition non liée) et dans ce cas on ne compare pas les référentiels
-
 
193
		if (propNNVide && obnNNVide) {
-
 
194
			correspondent = true;
172
			// Vérification si les num noms et référentiels correspondent
195
		} else { // soit on compare les NN et les référentiels
173
			correspondent = (observation.getNumNomenclatural().equals(proposition.getNumNomenclatural())) && (observation.getReferentiel().equals(proposition.getReferentiel()));
196
			correspondent = (obsNN.equals(propNN) && obsRef.equals(propRef));
174
		}
197
		}
175
		
198
 
176
		return correspondent;
199
		return correspondent;
177
	}
200
	}
178
	
-
 
179
 
201
 
180
	/**
202
	/**
181
	 * Créée une proposition de determination à partir d'une observation
203
	 * Créée une proposition de determination à partir d'une observation
182
	 * 
204
	 * 
183
	 * @param observation
205
	 * @param observation
184
	 * @return
206
	 * @return
185
	 */
207
	 */
186
	private static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation, boolean propositionInitialeExiste) {
208
	private static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation, boolean propositionInitialeExiste) {
187
 
209
 
188
		String utilisateurNom = observation.getNomAuteur();
210
		String utilisateurNom = observation.getNomAuteur();
189
		String utilisateurPrenom = observation.getPrenomAuteur();
211
		String utilisateurPrenom = observation.getPrenomAuteur();
190
 
212
 
191
		String utilisateurCourriel = observation.getCourrielAuteur();
213
		String utilisateurCourriel = observation.getCourrielAuteur();
192
		String utilisateurId = observation.getIdAuteur();
214
		String utilisateurId = observation.getIdAuteur();
193
		PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
215
		PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
194
		Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
216
		Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
195
		propositionDetermination.setContributeur(contributeur);
217
		propositionDetermination.setContributeur(contributeur);
196
		java.util.Date datePropDeter = parserDateObservation(observation.getDateTransmission());
218
		java.util.Date datePropDeter = parserDateObservation(observation.getDateTransmission());
197
		propositionDetermination.setDate(datePropDeter);
219
		propositionDetermination.setDate(datePropDeter);
198
		
220
		
199
		propositionDetermination.setEspece(observation.getNomRetenu());
221
		propositionDetermination.setEspece(observation.getNomRetenu());
200
		propositionDetermination.setNumNomenclatural(observation.getNumNomenclatural());
222
		propositionDetermination.setNumNomenclatural(observation.getNumNomenclatural());
201
		propositionDetermination.setReferentiel(observation.getReferentiel());
223
		propositionDetermination.setReferentiel(observation.getReferentiel());
202
		if (!propositionInitialeExiste) {
224
		if (!propositionInitialeExiste) {
203
			propositionDetermination.setEstPropositionInitiale(true);
225
			propositionDetermination.setEstPropositionInitiale(true);
204
		}
226
		}
205
		
227
		
206
 
228
 
207
		return propositionDetermination;
229
		return propositionDetermination;
208
	}
230
	}
209
 
231
 
210
	/**
232
	/**
211
	 * Recupere une liste de commentaires à partir du JSON
233
	 * Recupere une liste de commentaires à partir du JSON
212
	 * 
234
	 * 
213
	 * @param imageJson
235
	 * @param imageJson
214
	 * @return
236
	 * @return
215
	 */
237
	 */
216
	public static List<Commentaire> parserCommentaires(JSONObject commentaires) {
238
	public static List<Commentaire> parserCommentaires(JSONObject commentaires) {
217
		List<InterventionForum> interventionForums = parserInterventions(commentaires);
239
		List<InterventionForum> interventionForums = parserInterventions(commentaires);
218
		List<Commentaire> commentairesListe = new ArrayList<Commentaire>();
240
		List<Commentaire> commentairesListe = new ArrayList<Commentaire>();
219
		for (InterventionForum interventionForum : interventionForums) {
241
		for (InterventionForum interventionForum : interventionForums) {
220
			if (interventionForum instanceof Commentaire) {
242
			if (interventionForum instanceof Commentaire) {
221
				commentairesListe.add((Commentaire) interventionForum);
243
				commentairesListe.add((Commentaire) interventionForum);
222
			}
244
			}
223
		}
245
		}
224
		return commentairesListe;
246
		return commentairesListe;
225
 
247
 
226
	}
248
	}
227
 
249
 
228
	/**
250
	/**
229
	 * Recupere une liste d'interventions à partir du JSON
251
	 * Recupere une liste d'interventions à partir du JSON
230
	 * 
252
	 * 
231
	 * @param imageJson
253
	 * @param imageJson
232
	 * @return
254
	 * @return
233
	 */
255
	 */
234
	public static List<InterventionForum> parserInterventions(JSONObject interventions) {
256
	public static List<InterventionForum> parserInterventions(JSONObject interventions) {
235
		HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
257
		HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
236
 
258
 
237
		List<InterventionForum> retour = new ArrayList<InterventionForum>();
259
		List<InterventionForum> retour = new ArrayList<InterventionForum>();
238
 
260
 
239
		// parcourir les interventions et en faire un tableau
261
		// parcourir les interventions et en faire un tableau
240
		if (interventions == null) {
262
		if (interventions == null) {
241
			return retour;
263
			return retour;
242
		}
264
		}
243
		Iterator<String> itInterventions = interventions.keySet().iterator();
265
		Iterator<String> itInterventions = interventions.keySet().iterator();
244
		while (itInterventions.hasNext()) {
266
		while (itInterventions.hasNext()) {
245
			JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
267
			JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
246
			String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
268
			String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
247
 
269
 
248
			String id = getValeurOuVide(jsonIntervention, "id_commentaire");
270
			String id = getValeurOuVide(jsonIntervention, "id_commentaire");
249
			String idParent = getValeurOuVide(jsonIntervention, "id_parent");
271
			String idParent = getValeurOuVide(jsonIntervention, "id_parent");
250
			String texte = getValeurOuVide(jsonIntervention, "texte");
272
			String texte = getValeurOuVide(jsonIntervention, "texte");
251
 
273
 
252
			String idUtilisateur = getValeurOuVide(jsonIntervention, "auteur.id");
274
			String idUtilisateur = getValeurOuVide(jsonIntervention, "auteur.id");
253
			String nom = getValeurOuVide(jsonIntervention, "auteur.nom");
275
			String nom = getValeurOuVide(jsonIntervention, "auteur.nom");
254
			String prenom = getValeurOuVide(jsonIntervention, "auteur.prenom");
276
			String prenom = getValeurOuVide(jsonIntervention, "auteur.prenom");
255
			String courriel = getValeurOuVide(jsonIntervention, "auteur.courriel");
277
			String courriel = getValeurOuVide(jsonIntervention, "auteur.courriel");
256
			Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
278
			Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
257
			
279
			
258
			Date date = parserDateObservation(getValeurOuVide(jsonIntervention, "date"));
280
			Date date = parserDateObservation(getValeurOuVide(jsonIntervention, "date"));
259
 
281
 
260
			if (!nomSel.equals("")) {
282
			if (!nomSel.equals("")) {
261
				String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
283
				String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
262
				String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
284
				String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
263
				String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
285
				String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
264
				String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
286
				String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
265
				String famille = getValeurOuVide(jsonIntervention, "famille");
287
				String famille = getValeurOuVide(jsonIntervention, "famille");
266
				String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
288
				String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
267
				
289
				
268
				String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
290
				String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
269
 
291
 
270
				PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
292
				PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
271
				String proposition_initiale = getValeurOuVide(jsonIntervention, "proposition_initiale");
293
				String proposition_initiale = getValeurOuVide(jsonIntervention, "proposition_initiale");
272
				if (proposition_initiale != null && proposition_initiale.equals("1")) {
294
				if (proposition_initiale != null && proposition_initiale.equals("1")) {
273
					intervention.setEstPropositionInitiale(true);
295
					intervention.setEstPropositionInitiale(true);
274
				}
296
				}
275
				
297
				
276
				String proposition_retenue = getValeurOuVide(jsonIntervention, "proposition_retenue");
298
				String proposition_retenue = getValeurOuVide(jsonIntervention, "proposition_retenue");
277
				if (proposition_retenue != null && proposition_retenue.equals("1")) {
299
				if (proposition_retenue != null && proposition_retenue.equals("1")) {
278
					intervention.setEstPropositionRetenue(true);
300
					intervention.setEstPropositionRetenue(true);
279
				}
301
				}
280
				
302
				
281
				intervention.setEspece(nom_sel);
303
				intervention.setEspece(nom_sel);
282
 
304
 
283
				if (!nbCommentaires.equals("")) {
305
				if (!nbCommentaires.equals("")) {
284
					int nbComm = Integer.parseInt(nbCommentaires);
306
					int nbComm = Integer.parseInt(nbCommentaires);
285
					intervention.setNbCommentaires(nbComm);
307
					intervention.setNbCommentaires(nbComm);
286
				}
308
				}
287
 
309
 
288
				if (nom_sel_nn != null && !nom_sel_nn.equals("")) {
310
				if (nom_sel_nn != null && !nom_sel_nn.equals("")) {
289
					intervention.setNumNomenclatural(nom_sel_nn);
311
					intervention.setNumNomenclatural(nom_sel_nn);
290
				}
312
				}
291
				
313
				
292
				if(nom_referentiel != null && !nom_referentiel.equals("")) {
314
				if(nom_referentiel != null && !nom_referentiel.equals("")) {
293
					intervention.setReferentiel(nom_referentiel);
315
					intervention.setReferentiel(nom_referentiel);
294
				}
316
				}
295
				
317
				
296
				if (!idParent.equals("")) {
318
				if (!idParent.equals("")) {
297
					intervention.setIdParent(idParent);
319
					intervention.setIdParent(idParent);
298
				}
320
				}
299
 
321
 
300
				if (jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
322
				if (jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
301
					intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject()));
323
					intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject()));
302
				}
324
				}
303
 
325
 
304
				intervention.setDate(date);
326
				intervention.setDate(date);
305
				interventionsNonTypees.put(intervention.getId(), intervention);
327
				interventionsNonTypees.put(intervention.getId(), intervention);
306
 
328
 
307
			} else {
329
			} else {
308
				Commentaire intervention = new Commentaire(contributeur, date, texte);
330
				Commentaire intervention = new Commentaire(contributeur, date, texte);
309
				intervention.setId(id);
331
				intervention.setId(id);
310
				intervention.setDate(date);
332
				intervention.setDate(date);
311
				interventionsNonTypees.put(intervention.getId(), intervention);
333
				interventionsNonTypees.put(intervention.getId(), intervention);
312
				if (!idParent.equals("")) {
334
				if (!idParent.equals("")) {
313
					intervention.setIdParent(idParent);
335
					intervention.setIdParent(idParent);
314
				}
336
				}
315
			}
337
			}
316
		}
338
		}
317
 
339
 
318
		Iterator<String> itIntervention = interventionsNonTypees.keySet().iterator();
340
		Iterator<String> itIntervention = interventionsNonTypees.keySet().iterator();
319
		while (itIntervention.hasNext()) {
341
		while (itIntervention.hasNext()) {
320
			String id = itIntervention.next();
342
			String id = itIntervention.next();
321
			InterventionForum intervention = interventionsNonTypees.get(id);
343
			InterventionForum intervention = interventionsNonTypees.get(id);
322
			String idParent = intervention.getIdParent();
344
			String idParent = intervention.getIdParent();
323
			if (idParent != null && !idParent.equals("") && !idParent.equals("0") && interventionsNonTypees.containsKey(idParent)) {
345
			if (idParent != null && !idParent.equals("") && !idParent.equals("0") && interventionsNonTypees.containsKey(idParent)) {
324
				InterventionForum parent = interventionsNonTypees.get(idParent);
346
				InterventionForum parent = interventionsNonTypees.get(idParent);
325
				intervention.setParent(parent);
347
				intervention.setParent(parent);
326
				parent.ajouterCommentaire((Commentaire) intervention);
348
				parent.ajouterCommentaire((Commentaire) intervention);
327
			} else {
349
			} else {
328
				retour.add(intervention);
350
				retour.add(intervention);
329
			}
351
			}
330
		}
352
		}
331
 
353
 
332
		return retour;
354
		return retour;
333
	}
355
	}
334
 
356
 
335
	/**
357
	/**
336
	 * Recupere une liste de commentaires à partir du JSON
358
	 * Recupere une liste de commentaires à partir du JSON
337
	 * 
359
	 * 
338
	 * @param imageJson
360
	 * @param imageJson
339
	 * @return
361
	 * @return
340
	 */
362
	 */
341
	public static String convertirEtParserRetourAjoutCommentaire(String retour) {
363
	public static String convertirEtParserRetourAjoutCommentaire(String retour) {
342
		JSONObject retourJson = JSONParser.parseStrict(retour).isObject();
364
		JSONObject retourJson = JSONParser.parseStrict(retour).isObject();
343
		return parserRetourAjoutCommentaire(retourJson);
365
		return parserRetourAjoutCommentaire(retourJson);
344
	}
366
	}
345
 
367
 
346
	/**
368
	/**
347
	 * Recupere une liste de commentaires à partir d'un objet JSON
369
	 * Recupere une liste de commentaires à partir d'un objet JSON
348
	 * 
370
	 * 
349
	 * @param imageJson
371
	 * @param imageJson
350
	 * @return
372
	 * @return
351
	 */
373
	 */
352
	public static String parserRetourAjoutCommentaire(JSONObject retour) {
374
	public static String parserRetourAjoutCommentaire(JSONObject retour) {
353
		String id = "";
375
		String id = "";
354
		if (retour != null) {
376
		if (retour != null) {
355
			id = getValeurOuVide(retour, "id_commentaire");
377
			id = getValeurOuVide(retour, "id_commentaire");
356
		}
378
		}
357
		return id;
379
		return id;
358
	}
380
	}
359
 
381
 
360
	public static String getValeurOuVide(JSONObject objet, String index) {
382
	public static String getValeurOuVide(JSONObject objet, String index) {
361
		return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
383
		return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
362
	}
384
	}
363
 
385
 
364
	/**
386
	/**
365
	 * Recupere une liste de votes sur une determination à partir du JSON
387
	 * Recupere une liste de votes sur une determination à partir du JSON
366
	 * 
388
	 * 
367
	 * @param imageJson
389
	 * @param imageJson
368
	 * @return
390
	 * @return
369
	 */
391
	 */
370
	public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString) {
392
	public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString) {
371
 
393
 
372
		HashMap<String, VoteDetermination> retour = null;
394
		HashMap<String, VoteDetermination> retour = null;
373
 
395
 
374
		JSONObject votes = JSONParser.parseStrict(votesString).isObject();
396
		JSONObject votes = JSONParser.parseStrict(votesString).isObject();
375
		if (votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
397
		if (votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
376
			JSONObject resultat = votes.get("resultats").isObject();
398
			JSONObject resultat = votes.get("resultats").isObject();
377
			retour = parserVotesDetermination(resultat);
399
			retour = parserVotesDetermination(resultat);
378
		}
400
		}
379
		return retour;
401
		return retour;
380
	}
402
	}
381
 
403
 
382
	/**
404
	/**
383
	 * Recupere une liste de votes sur une determination à partir d'un objet
405
	 * Recupere une liste de votes sur une determination à partir d'un objet
384
	 * JSON
406
	 * JSON
385
	 * 
407
	 * 
386
	 * @param imageJson
408
	 * @param imageJson
387
	 * @return
409
	 * @return
388
	 */
410
	 */
389
	public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes) {
411
	public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes) {
390
		HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
412
		HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
391
		java.util.Iterator<String> itVotes = votes.keySet().iterator();
413
		java.util.Iterator<String> itVotes = votes.keySet().iterator();
392
		while (itVotes.hasNext()) {
414
		while (itVotes.hasNext()) {
393
			JSONObject vote = votes.get(itVotes.next()).isObject();
415
			JSONObject vote = votes.get(itVotes.next()).isObject();
394
			VoteDetermination vd = new VoteDetermination();
416
			VoteDetermination vd = new VoteDetermination();
395
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
417
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
396
			vd.setDate(parserDateObservation(getValeurOuVide(vote, "date")));
418
			vd.setDate(parserDateObservation(getValeurOuVide(vote, "date")));
397
			vd.setId(getValeurOuVide(vote, "vote.id"));
419
			vd.setId(getValeurOuVide(vote, "vote.id"));
398
			vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
420
			vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
399
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
421
			vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
400
 
422
 
401
			if (vote.get("auteur.nom") != null && vote.get("auteur.nom") != null && vote.get("auteur.courriel") != null) {
423
			if (vote.get("auteur.nom") != null && vote.get("auteur.nom") != null && vote.get("auteur.courriel") != null) {
402
				Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"), getValeurOuVide(vote, "auteur.nom"), getValeurOuVide(vote, "auteur.prenom"), getValeurOuVide(vote, "auteur.courriel"));
424
				Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"), getValeurOuVide(vote, "auteur.nom"), getValeurOuVide(vote, "auteur.prenom"), getValeurOuVide(vote, "auteur.courriel"));
403
				vd.setAuteur(auteur);
425
				vd.setAuteur(auteur);
404
			}
426
			}
405
 
427
 
406
			votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
428
			votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
407
		}
429
		}
408
		return votesDetermination;
430
		return votesDetermination;
409
	}
431
	}
410
 
432
 
411
	/**
433
	/**
412
	 * Recupere une liste de votes sur des images à partir d'un objet JSON
434
	 * Recupere une liste de votes sur des images à partir d'un objet JSON
413
	 * 
435
	 * 
414
	 * @param imageJson
436
	 * @param imageJson
415
	 * @return
437
	 * @return
416
	 */
438
	 */
417
	public static HashMap<String, HashMap<String, VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
439
	public static HashMap<String, HashMap<String, VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
418
 
440
 
419
		HashMap<String, HashMap<String, VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String, VoteProtocole>>();
441
		HashMap<String, HashMap<String, VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String, VoteProtocole>>();
420
		java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
442
		java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
421
		while (itProtocoles.hasNext()) {
443
		while (itProtocoles.hasNext()) {
422
			JSONObject protocole = votes.get(itProtocoles.next()).isObject();
444
			JSONObject protocole = votes.get(itProtocoles.next()).isObject();
423
			JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
445
			JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
424
			String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
446
			String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
425
			java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
447
			java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
426
			while (itVotes.hasNext()) {
448
			while (itVotes.hasNext()) {
427
				JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
449
				JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
428
				VoteProtocole vd = new VoteProtocole();
450
				VoteProtocole vd = new VoteProtocole();
429
				vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
451
				vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
430
				vd.setId(voteEnCours.get("vote.id").isString().stringValue());
452
				vd.setId(voteEnCours.get("vote.id").isString().stringValue());
431
				// TODO récupérer la date du vote et la parser
453
				// TODO récupérer la date du vote et la parser
432
				vd.setDate(parserDateObservation(getValeurOuVide(voteEnCours, "date")));
454
				vd.setDate(parserDateObservation(getValeurOuVide(voteEnCours, "date")));
433
				int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
455
				int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
434
				vd.setVote(valeurVote);
456
				vd.setVote(valeurVote);
435
				if (!votesProtocoles.containsKey(idProtocoleVote)) {
457
				if (!votesProtocoles.containsKey(idProtocoleVote)) {
436
					votesProtocoles.put(idProtocoleVote, new HashMap<String, VoteProtocole>());
458
					votesProtocoles.put(idProtocoleVote, new HashMap<String, VoteProtocole>());
437
				}
459
				}
438
				// un seul vote par utilisateur - garde le premier pour être cohérent avec commun/Stats (PHP)
460
				// un seul vote par utilisateur - garde le premier pour être cohérent avec commun/Stats (PHP)
439
				if (! votesProtocoles.get(idProtocoleVote).containsKey(vd.getContributeur())) {
461
				if (! votesProtocoles.get(idProtocoleVote).containsKey(vd.getContributeur())) {
440
					votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
462
					votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
441
				}
463
				}
442
			}
464
			}
443
		}
465
		}
444
 
466
 
445
		return votesProtocoles;
467
		return votesProtocoles;
446
	}
468
	}
447
 
469
 
448
	/**
470
	/**
449
	 * Recupere une date à partir du JSON
471
	 * Recupere une date à partir du JSON
450
	 * 
472
	 * 
451
	 * @param imageJson
473
	 * @param imageJson
452
	 * @return
474
	 * @return
453
	 */
475
	 */
454
	public static Date parserDateObservation(String date) {
476
	public static Date parserDateObservation(String date) {
455
		Date dateParsee = new Date();
477
		Date dateParsee = new Date();
456
		DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
478
		DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
457
		try {
479
		try {
458
			dateParsee = formatDateObs.parse(date);
480
			dateParsee = formatDateObs.parse(date);
459
		} catch (IllegalArgumentException e) {
481
		} catch (IllegalArgumentException e) {
460
			dateParsee = new java.sql.Date(0);
482
			dateParsee = new java.sql.Date(0);
461
		}
483
		}
462
		return dateParsee;
484
		return dateParsee;
463
	}
485
	}
464
 
486
 
465
	/**
487
	/**
466
	 * Recupere des mots-clefs à partir du JSON
488
	 * Recupere des mots-clefs à partir du JSON
467
	 * 
489
	 * 
468
	 * @param imageJson
490
	 * @param imageJson
469
	 * @return
491
	 * @return
470
	 */
492
	 */
471
	public static List<String> parserMotsCles(String motsClesTexte) {
493
	public static List<String> parserMotsCles(String motsClesTexte) {
472
		String[] tabMotsCle = motsClesTexte.split(",");
494
		String[] tabMotsCle = motsClesTexte.split(",");
473
		List<String> motsClesParses = new ArrayList<String>();
495
		List<String> motsClesParses = new ArrayList<String>();
474
		for (int i = 0; i < tabMotsCle.length; i++) {
496
		for (int i = 0; i < tabMotsCle.length; i++) {
475
			motsClesParses.add(tabMotsCle[i].trim());
497
			motsClesParses.add(tabMotsCle[i].trim());
476
		}
498
		}
477
 
499
 
478
		return motsClesParses;
500
		return motsClesParses;
479
	}
501
	}
480
 
502
 
481
	public static String getIdAvecPadding(String id) {
503
	public static String getIdAvecPadding(String id) {
482
		int maxZeros = 9 - id.length();
504
		int maxZeros = 9 - id.length();
483
		for (int i = 0; i < maxZeros; i++) {
505
		for (int i = 0; i < maxZeros; i++) {
484
			id = "0" + id;
506
			id = "0" + id;
485
		}
507
		}
486
		return id;
508
		return id;
487
	}
509
	}
488
 
510
 
489
	/**
511
	/**
490
	 * Recupere un utilisateur à partir du JSON
512
	 * Recupere un utilisateur à partir du JSON
491
	 * 
513
	 * 
492
	 * @param imageJson
514
	 * @param imageJson
493
	 * @return
515
	 * @return
494
	 */
516
	 */
495
	public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
517
	public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
496
		JSONObject utilisateurJson = valeurJson.isObject();
518
		JSONObject utilisateurJson = valeurJson.isObject();
497
		boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
519
		boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
498
		String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
520
		String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
499
		String sessionId = utilisateurJson.get("session_id").isString().stringValue();
521
		String sessionId = utilisateurJson.get("session_id").isString().stringValue();
500
		GWT.log(valeurJson.toString());
522
		GWT.log(valeurJson.toString());
501
		
523
		
502
		Utilisateur utilisateur;
524
		Utilisateur utilisateur;
503
		if (connecteUtilisateur) {
525
		if (connecteUtilisateur) {
504
			String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
526
			String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
505
			String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
527
			String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
506
			String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
528
			String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
507
			
529
			
508
			String adminNiveau = "";
530
			String adminNiveau = "";
509
			if (utilisateurJson.get("admin").isString() != null) {
531
			if (utilisateurJson.get("admin").isString() != null) {
510
				adminNiveau = utilisateurJson.get("admin").isString().stringValue();
532
				adminNiveau = utilisateurJson.get("admin").isString().stringValue();
511
			}
533
			}
512
			
534
			
513
			String nbEvtsUtilisateur = utilisateurJson.get("nb_evenements").isString().stringValue();
535
			String nbEvtsUtilisateur = utilisateurJson.get("nb_evenements").isString().stringValue();
514
			String dateDerniereConsultationEvts = utilisateurJson.get("date_derniere_consultation_evenements").isString().stringValue();
536
			String dateDerniereConsultationEvts = utilisateurJson.get("date_derniere_consultation_evenements").isString().stringValue();
515
 
537
 
516
			utilisateur = new Utilisateur(sessionId, idUtilisateur, prenomUtilisateur, nomUtilisateur, 
538
			utilisateur = new Utilisateur(sessionId, idUtilisateur, prenomUtilisateur, nomUtilisateur, 
517
				courrielUtilisateur, adminNiveau);
539
				courrielUtilisateur, adminNiveau);
518
			
540
			
519
			ActiviteUtilisateur activite = new ActiviteUtilisateur();
541
			ActiviteUtilisateur activite = new ActiviteUtilisateur();
520
			activite.setNbEvenements(nbEvtsUtilisateur);
542
			activite.setNbEvenements(nbEvtsUtilisateur);
521
			activite.setDateDerniereConsultationEvenements(dateDerniereConsultationEvts);
543
			activite.setDateDerniereConsultationEvenements(dateDerniereConsultationEvts);
522
			
544
			
523
			utilisateur.setActivite(activite);
545
			utilisateur.setActivite(activite);
524
		} else {
546
		} else {
525
			utilisateur = new Utilisateur(sessionId, idUtilisateur);
547
			utilisateur = new Utilisateur(sessionId, idUtilisateur);
526
		}
548
		}
527
		return utilisateur;
549
		return utilisateur;
528
	}
550
	}
529
 
551
 
530
	/**
552
	/**
531
	 * Recupere des informations d'authentification à partir du JSON renvoyé par les
553
	 * Recupere des informations d'authentification à partir du JSON renvoyé par les
532
	 * services Auth de l'annuaire (SSO)
554
	 * services Auth de l'annuaire (SSO)
533
	 * 
555
	 * 
534
	 * @param valeurJson
556
	 * @param valeurJson
535
	 * @return AuthInfo
557
	 * @return AuthInfo
536
	 */
558
	 */
537
	public static AuthInfo parserAuthJson(JSONValue valeurJson) {
559
	public static AuthInfo parserAuthJson(JSONValue valeurJson) {
538
		AuthInfo authInfo = new AuthInfo();
560
		AuthInfo authInfo = new AuthInfo();
539
		JSONObject authJson = valeurJson.isObject();
561
		JSONObject authJson = valeurJson.isObject();
540
 
562
 
541
		JSONValue erreurJSON = authJson.get("error");
563
		JSONValue erreurJSON = authJson.get("error");
542
		// test si erreur
564
		// test si erreur
543
		if (erreurJSON != null) {
565
		if (erreurJSON != null) {
544
			JSONString erreur = erreurJSON.isString();
566
			JSONString erreur = erreurJSON.isString();
545
			if (erreur != null) {
567
			if (erreur != null) {
546
				authInfo.error = erreur.stringValue();
568
				authInfo.error = erreur.stringValue();
547
			} else {
569
			} else {
548
				authInfo.error = "erreur d'authentification";
570
				authInfo.error = "erreur d'authentification";
549
			}
571
			}
550
		} else {
572
		} else {
551
			boolean session = authJson.get("session").isBoolean().booleanValue();
573
			boolean session = authJson.get("session").isBoolean().booleanValue();
552
			authInfo.session = session;
574
			authInfo.session = session;
553
			// test si session ouverte
575
			// test si session ouverte
554
			if (session) {
576
			if (session) {
555
				JSONValue tokenJson = authJson.get("token");
577
				JSONValue tokenJson = authJson.get("token");
556
				String token = null;
578
				String token = null;
557
				// protection paranoïaque
579
				// protection paranoïaque
558
				if (tokenJson != null) {
580
				if (tokenJson != null) {
559
					JSONString tokenString = tokenJson.isString();
581
					JSONString tokenString = tokenJson.isString();
560
					if (tokenString != null) {
582
					if (tokenString != null) {
561
						token = tokenString.stringValue();
583
						token = tokenString.stringValue();
562
					}
584
					}
563
				}
585
				}
564
				String tokenId = authJson.get("token_id").isString().stringValue();
586
				String tokenId = authJson.get("token_id").isString().stringValue();
565
				int duration = (int) authJson.get("duration").isNumber().doubleValue();
587
				int duration = (int) authJson.get("duration").isNumber().doubleValue();
566
				JSONValue lastModifJson = authJson.get("last_modif");
588
				JSONValue lastModifJson = authJson.get("last_modif");
567
 
589
 
568
				authInfo.token = token;
590
				authInfo.token = token;
569
				authInfo.tokenId = tokenId;
591
				authInfo.tokenId = tokenId;
570
				authInfo.duration = duration;
592
				authInfo.duration = duration;
571
				// test si lastModif est null
593
				// test si lastModif est null
572
				if (lastModifJson != null) {
594
				if (lastModifJson != null) {
573
					JSONNumber lastModif = lastModifJson.isNumber();
595
					JSONNumber lastModif = lastModifJson.isNumber();
574
					if (lastModif != null) {
596
					if (lastModif != null) {
575
						authInfo.lastModif = (int) lastModif.doubleValue();
597
						authInfo.lastModif = (int) lastModif.doubleValue();
576
					}
598
					}
577
				}
599
				}
578
			}
600
			}
579
		}
601
		}
580
		//GWT.log(valeurJson.toString());
602
		//GWT.log(valeurJson.toString());
581
		
603
		
582
		return authInfo;
604
		return authInfo;
583
	}
605
	}
584
	
606
	
585
	/**
607
	/**
586
	 * Recupere un utilisateur à partir du JSON
608
	 * Recupere un utilisateur à partir du JSON
587
	 * 
609
	 * 
588
	 * @param imageJson
610
	 * @param imageJson
589
	 * @return
611
	 * @return
590
	 */
612
	 */
591
	public static HashMap<String, String> parserPreferencesUtilisateur(JSONValue valeurJson) {
613
	public static HashMap<String, String> parserPreferencesUtilisateur(JSONValue valeurJson) {
592
		
614
		
593
		JSONObject utilisateurJson = valeurJson.isObject();
615
		JSONObject utilisateurJson = valeurJson.isObject();
594
		HashMap<String, String> preferences = new HashMap<String, String>();
616
		HashMap<String, String> preferences = new HashMap<String, String>();
595
		JSONObject preferencesJson = utilisateurJson.get("preferences").isObject();
617
		JSONObject preferencesJson = utilisateurJson.get("preferences").isObject();
596
		
618
		
597
		java.util.Iterator<String> it = preferencesJson.keySet().iterator();
619
		java.util.Iterator<String> it = preferencesJson.keySet().iterator();
598
		while (it.hasNext()) {
620
		while (it.hasNext()) {
599
			String cle = it.next();
621
			String cle = it.next();
600
			preferences.put(cle, preferencesJson.get(cle).isString().stringValue());
622
			preferences.put(cle, preferencesJson.get(cle).isString().stringValue());
601
		}
623
		}
602
		return preferences;
624
		return preferences;
603
	}
625
	}
604
 
626
 
605
	/**
627
	/**
606
	 * Retourne un objet {@link ProtocoleServiceResultat} à partir d'un objet
628
	 * Retourne un objet {@link ProtocoleServiceResultat} à partir d'un objet
607
	 * JSON
629
	 * JSON
608
	 * 
630
	 * 
609
	 * @param retourJson
631
	 * @param retourJson
610
	 * @return
632
	 * @return
611
	 */
633
	 */
612
	public static ProtocoleServiceResultat parserProtocoleServiceResultat(JSONValue retourJson) {
634
	public static ProtocoleServiceResultat parserProtocoleServiceResultat(JSONValue retourJson) {
613
		List<Protocole> protocoles = new ArrayList<Protocole>();
635
		List<Protocole> protocoles = new ArrayList<Protocole>();
614
		JSONObject tableauProto = retourJson.isObject().get("resultats").isObject();
636
		JSONObject tableauProto = retourJson.isObject().get("resultats").isObject();
615
 
637
 
616
		if (tableauProto != null) {
638
		if (tableauProto != null) {
617
			java.util.Iterator<String> it = tableauProto.keySet().iterator();
639
			java.util.Iterator<String> it = tableauProto.keySet().iterator();
618
			while (it.hasNext()) {
640
			while (it.hasNext()) {
619
 
641
 
620
				JSONObject protocoleJSON = tableauProto.get(it.next()).isObject();
642
				JSONObject protocoleJSON = tableauProto.get(it.next()).isObject();
621
				Protocole protocole = new Protocole();
643
				Protocole protocole = new Protocole();
622
				String idProtocole = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.id");
644
				String idProtocole = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.id");
623
				protocole.setId(Integer.parseInt(idProtocole));	
645
				protocole.setId(Integer.parseInt(idProtocole));	
624
				String doitEtreIdentifiePourVoter = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.identifie");
646
				String doitEtreIdentifiePourVoter = UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.identifie");
625
				boolean boolDoitEtreIdentifie = doitEtreIdentifiePourVoter.equals("1") ? true : false;
647
				boolean boolDoitEtreIdentifie = doitEtreIdentifiePourVoter.equals("1") ? true : false;
626
				protocole.setDoitEtreIdentifiePourVoter(boolDoitEtreIdentifie);
648
				protocole.setDoitEtreIdentifiePourVoter(boolDoitEtreIdentifie);
627
				protocole.setNom(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.intitule"));
649
				protocole.setNom(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.intitule"));
628
				protocole.setDescription(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.descriptif"));
650
				protocole.setDescription(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.descriptif"));
629
				protocole.setTag(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.tag"));
651
				protocole.setTag(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.tag"));
630
				protocole.setMotsClesProtocole(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.mots_cles"));
652
				protocole.setMotsClesProtocole(UtilitairesServiceResultat.getValeurOuVide(protocoleJSON, "protocole.mots_cles"));
631
				protocoles.add(protocole);
653
				protocoles.add(protocole);
632
			}
654
			}
633
		}
655
		}
634
 
656
 
635
		return new ProtocoleServiceResultat(protocoles);
657
		return new ProtocoleServiceResultat(protocoles);
636
	}
658
	}
637
 
659
 
638
	/**
660
	/**
639
	 * Retourne un objet {@link ImageServiceResultat} à partir du JSON
661
	 * Retourne un objet {@link ImageServiceResultat} à partir du JSON
640
	 * 
662
	 * 
641
	 * @param retourJson
663
	 * @param retourJson
642
	 * @return
664
	 * @return
643
	 */
665
	 */
644
	public static ImageServiceResultat parserImageServiceResultat(JSONValue retourJson) {
666
	public static ImageServiceResultat parserImageServiceResultat(JSONValue retourJson) {
645
 
667
 
646
		ImageServiceResultat imageServiceResultat = new ImageServiceResultat();
668
		ImageServiceResultat imageServiceResultat = new ImageServiceResultat();
647
		int nbTotalImagesPourLaRecherche;
669
		int nbTotalImagesPourLaRecherche;
648
 
670
 
649
		List<Image> images = new ArrayList<Image>();
671
		List<Image> images = new ArrayList<Image>();
650
		// TODO ajouter vérifications plus précises
672
		// TODO ajouter vérifications plus précises
651
		if (retourJson.isObject().get("entete") != null) {
673
		if (retourJson.isObject().get("entete") != null) {
652
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
674
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
653
			nbTotalImagesPourLaRecherche = (int) total;
675
			nbTotalImagesPourLaRecherche = (int) total;
654
			// ATTENTION : "resultats" devrait contenir un array car il garantit l'ordre ce qui est important pour
676
			// ATTENTION : "resultats" devrait contenir un array car il garantit l'ordre ce qui est important pour
655
			// résultat de recherche. Migration progressive des ws pour qu'ils retourne un array et non un objet.
677
			// résultat de recherche. Migration progressive des ws pour qu'ils retourne un array et non un objet.
656
			if (retourJson.isObject().get("resultats").isObject() != null) {
678
			if (retourJson.isObject().get("resultats").isObject() != null) {
657
				// TODO : supprimer cette condition quand tous les ws seront migrés vers array.
679
				// TODO : supprimer cette condition quand tous les ws seront migrés vers array.
658
				JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
680
				JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
659
				if (tableauImg != null) {
681
				if (tableauImg != null) {
660
					java.util.Iterator<String> it = tableauImg.keySet().iterator();
682
					java.util.Iterator<String> it = tableauImg.keySet().iterator();
661
					while (it.hasNext()) {
683
					while (it.hasNext()) {
662
						JSONObject imageJson = tableauImg.get(it.next()).isObject();
684
						JSONObject imageJson = tableauImg.get(it.next()).isObject();
663
						Image image = parserRetourImage(imageJson);
685
						Image image = parserRetourImage(imageJson);
664
						images.add(image);
686
						images.add(image);
665
					}
687
					}
666
				}
688
				}
667
			} else if (retourJson.isObject().get("resultats").isArray() != null) {
689
			} else if (retourJson.isObject().get("resultats").isArray() != null) {
668
				JSONArray tableauImg = retourJson.isObject().get("resultats").isArray();
690
				JSONArray tableauImg = retourJson.isObject().get("resultats").isArray();
669
				if (tableauImg != null) {
691
				if (tableauImg != null) {
670
					int nbInfosImagesRetournees = (int) tableauImg.size();
692
					int nbInfosImagesRetournees = (int) tableauImg.size();
671
					for (int i = 0; i < nbInfosImagesRetournees; i++) {
693
					for (int i = 0; i < nbInfosImagesRetournees; i++) {
672
						JSONObject imageJson = tableauImg.get(i).isObject();
694
						JSONObject imageJson = tableauImg.get(i).isObject();
673
						Image image = parserRetourImage(imageJson);
695
						Image image = parserRetourImage(imageJson);
674
						images.add(image);
696
						images.add(image);
675
					}
697
					}
676
				}
698
				}
677
			}
699
			}
678
		} else {
700
		} else {
679
			JSONArray tableauImg = retourJson.isObject().get("images").isArray();
701
			JSONArray tableauImg = retourJson.isObject().get("images").isArray();
680
			nbTotalImagesPourLaRecherche = (int) tableauImg.size();
702
			nbTotalImagesPourLaRecherche = (int) tableauImg.size();
681
			for (int i = 0; i < nbTotalImagesPourLaRecherche; i++) {
703
			for (int i = 0; i < nbTotalImagesPourLaRecherche; i++) {
682
				JSONObject imageJson = tableauImg.get(i).isObject();
704
				JSONObject imageJson = tableauImg.get(i).isObject();
683
				Image image = parserRetourImage(imageJson);
705
				Image image = parserRetourImage(imageJson);
684
				images.add(image);
706
				images.add(image);
685
			}
707
			}
686
		}
708
		}
687
 
709
 
688
		imageServiceResultat.setImages(images);
710
		imageServiceResultat.setImages(images);
689
		imageServiceResultat.setNbTotalImagesPourLaRecherche(nbTotalImagesPourLaRecherche);
711
		imageServiceResultat.setNbTotalImagesPourLaRecherche(nbTotalImagesPourLaRecherche);
690
 
712
 
691
		return imageServiceResultat;
713
		return imageServiceResultat;
692
 
714
 
693
	}
715
	}
694
 
716
 
695
	/**
717
	/**
696
	 * Retourne un objet {@link Image} à partir du JSON
718
	 * Retourne un objet {@link Image} à partir du JSON
697
	 * 
719
	 * 
698
	 * @param retourJson
720
	 * @param retourJson
699
	 * @return
721
	 * @return
700
	 */
722
	 */
701
	public static Image parserRetourImage(JSONObject imageJson) {
723
	public static Image parserRetourImage(JSONObject imageJson) {
702
		Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
724
		Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
703
 
725
 
704
		if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
726
		if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
705
			JSONObject observationJson = imageJson.get("observation").isObject();
727
			JSONObject observationJson = imageJson.get("observation").isObject();
706
			image.setObservation(UtilitairesServiceResultat.parserObservationJSON(observationJson));
728
			image.setObservation(UtilitairesServiceResultat.parserObservationJSON(observationJson));
707
		}
729
		}
708
 
730
 
709
		if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
731
		if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
710
			JSONObject votes = imageJson.get("protocoles_votes").isObject();
732
			JSONObject votes = imageJson.get("protocoles_votes").isObject();
711
			image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
733
			image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
712
		}
734
		}
713
 
735
 
714
		return image;
736
		return image;
715
	}
737
	}
716
 
738
 
717
	/**
739
	/**
718
	 * Retourne un objet {@link ObservationServiceResultat} à partir du JSON
740
	 * Retourne un objet {@link ObservationServiceResultat} à partir du JSON
719
	 * 
741
	 * 
720
	 * @param retourJson
742
	 * @param retourJson
721
	 * @return
743
	 * @return
722
	 */
744
	 */
723
	public static ObservationServiceResultat parserObservationServiceResultat(JSONValue retourJson) {
745
	public static ObservationServiceResultat parserObservationServiceResultat(JSONValue retourJson) {
724
 
746
 
725
		ObservationServiceResultat observationServiceResultat = new ObservationServiceResultat();
747
		ObservationServiceResultat observationServiceResultat = new ObservationServiceResultat();
726
 
748
 
727
		List<Observation> observations = new ArrayList<Observation>();
749
		List<Observation> observations = new ArrayList<Observation>();
728
		int nbTotalObservationsPourLaRecherche = 0;
750
		int nbTotalObservationsPourLaRecherche = 0;
729
 
751
 
730
		if (retourJson.isObject().get("entete") != null) {
752
		if (retourJson.isObject().get("entete") != null) {
731
			// TODO ajouter vérifications plus précises
753
			// TODO ajouter vérifications plus précises
732
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
754
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
733
			nbTotalObservationsPourLaRecherche = (int) total;
755
			nbTotalObservationsPourLaRecherche = (int) total;
734
			JSONArray tableauObs = retourJson.isObject().get("resultats").isArray();
756
			JSONArray tableauObs = retourJson.isObject().get("resultats").isArray();
735
 
757
 
736
			if (tableauObs != null) {
758
			if (tableauObs != null) {
737
				for(int i = 0; i < tableauObs.size(); i++) {
759
				for(int i = 0; i < tableauObs.size(); i++) {
738
					JSONObject observationJson = tableauObs.get(i).isObject();
760
					JSONObject observationJson = tableauObs.get(i).isObject();
739
					Observation observation = analyserObservation(observationJson);
761
					Observation observation = analyserObservation(observationJson);
740
					observations.add(observation);
762
					observations.add(observation);
741
				}
763
				}
742
			}
764
			}
743
		} else {
765
		} else {
744
			JSONObject observationJson = retourJson.isObject();
766
			JSONObject observationJson = retourJson.isObject();
745
			Observation observation = analyserObservation(observationJson);
767
			Observation observation = analyserObservation(observationJson);
746
			observations.add(observation);
768
			observations.add(observation);
747
			CacheClient.getInstance().setObservationCourante(observation);
769
			CacheClient.getInstance().setObservationCourante(observation);
748
		}
770
		}
749
 
771
 
750
		observationServiceResultat.setObservations(observations);
772
		observationServiceResultat.setObservations(observations);
751
		observationServiceResultat.setNbTotalObservationsPourLaRecherche(nbTotalObservationsPourLaRecherche);
773
		observationServiceResultat.setNbTotalObservationsPourLaRecherche(nbTotalObservationsPourLaRecherche);
752
 
774
 
753
		return observationServiceResultat;
775
		return observationServiceResultat;
754
	}
776
	}
755
 
777
 
756
	/**
778
	/**
757
	 * Retourne un objet {@link Observation} avec ses {@link Image} associées à
779
	 * Retourne un objet {@link Observation} avec ses {@link Image} associées à
758
	 * partir du JSON
780
	 * partir du JSON
759
	 * 
781
	 * 
760
	 * @param retourJson
782
	 * @param retourJson
761
	 * @return
783
	 * @return
762
	 */
784
	 */
763
	private static Observation analyserObservation(JSONObject observationJson) {
785
	private static Observation analyserObservation(JSONObject observationJson) {
764
		Observation observation = UtilitairesServiceResultat.parserObservationJSON(observationJson);
786
		Observation observation = UtilitairesServiceResultat.parserObservationJSON(observationJson);
765
		JSONArray tableauImagesObs = observationJson.get("images").isArray();
787
		JSONArray tableauImagesObs = observationJson.get("images").isArray();
766
		List<Image> imagesPourObs = new ArrayList<Image>();
788
		List<Image> imagesPourObs = new ArrayList<Image>();
767
 
789
 
768
		int nbImages = tableauImagesObs.size();
790
		int nbImages = tableauImagesObs.size();
769
		for (int j = 0; j < nbImages; j++) {
791
		for (int j = 0; j < nbImages; j++) {
770
			JSONObject imageJson = tableauImagesObs.get(j).isObject();
792
			JSONObject imageJson = tableauImagesObs.get(j).isObject();
771
 
793
 
772
			Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
794
			Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
773
			if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
795
			if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
774
				JSONObject votes = imageJson.get("protocoles_votes").isObject();
796
				JSONObject votes = imageJson.get("protocoles_votes").isObject();
775
				image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
797
				image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
776
			}
798
			}
777
			image.setObservation(observation);
799
			image.setObservation(observation);
778
			imagesPourObs.add(image);
800
			imagesPourObs.add(image);
779
		}
801
		}
780
 
802
 
781
		observation.setImages(imagesPourObs);
803
		observation.setImages(imagesPourObs);
782
 
804
 
783
		return observation;
805
		return observation;
784
	}
806
	}
785
 
807
 
786
	public static List<MotCle> parserRetourListeMotsClesImage(JSONObject retourJson) {
808
	public static List<MotCle> parserRetourListeMotsClesImage(JSONObject retourJson) {
787
		List<MotCle> motsCles = new ArrayList<MotCle>();
809
		List<MotCle> motsCles = new ArrayList<MotCle>();
788
		JSONObject tableauMc = retourJson;
810
		JSONObject tableauMc = retourJson;
789
		if (tableauMc != null) {
811
		if (tableauMc != null) {
790
			java.util.Iterator<String> it = tableauMc.keySet().iterator();
812
			java.util.Iterator<String> it = tableauMc.keySet().iterator();
791
			while (it.hasNext()) {
813
			while (it.hasNext()) {
792
				JSONObject mc = tableauMc.get(it.next()).isObject();
814
				JSONObject mc = tableauMc.get(it.next()).isObject();
793
				MotCle motCle = new MotCle(getValeurOuVide(mc, "id_mot_cle"), getValeurOuVide(mc, "image"), getValeurOuVide(mc, "mot_cle"));
815
				MotCle motCle = new MotCle(getValeurOuVide(mc, "id_mot_cle"), getValeurOuVide(mc, "image"), getValeurOuVide(mc, "mot_cle"));
794
				motsCles.add(motCle);
816
				motsCles.add(motCle);
795
			}
817
			}
796
		}
818
		}
797
		return motsCles;
819
		return motsCles;
798
	}
820
	}
799
 
821
 
800
	public static String parserRetourAjoutVoteProtocole(JSONObject retour) {
822
	public static String parserRetourAjoutVoteProtocole(JSONObject retour) {
801
		String id = "";
823
		String id = "";
802
		if (retour != null) {
824
		if (retour != null) {
803
			id = getValeurOuVide(retour, "id_vote");
825
			id = getValeurOuVide(retour, "id_vote");
804
		}
826
		}
805
		return id;
827
		return id;
806
	}
828
	}
807
 
829
 
808
	public static Map<String, String> parserListePays(JSONValue retourJson) {
830
	public static Map<String, String> parserListePays(JSONValue retourJson) {
809
		Map<String, String> listePays = new LinkedHashMap<String, String>();
831
		Map<String, String> listePays = new LinkedHashMap<String, String>();
810
		JSONArray tableauPays = retourJson.isArray();
832
		JSONArray tableauPays = retourJson.isArray();
811
		int nbPays = (int) tableauPays.size();
833
		int nbPays = (int) tableauPays.size();
812
		for (int i = 0; i < nbPays; i++) {
834
		for (int i = 0; i < nbPays; i++) {
813
			JSONObject pays = tableauPays.get(i).isObject();
835
			JSONObject pays = tableauPays.get(i).isObject();
814
			listePays.put(pays.get("code_iso_3166_1").isString().stringValue(), pays.get("nom_fr").isString().stringValue());
836
			listePays.put(pays.get("code_iso_3166_1").isString().stringValue(), pays.get("nom_fr").isString().stringValue());
815
		}
837
		}
816
		return listePays;
838
		return listePays;
817
	}
839
	}
818
 
840
 
819
	public static ActiviteUtilisateur parserActiviteUtilisateurJson(JSONValue valeurJson) {
841
	public static ActiviteUtilisateur parserActiviteUtilisateurJson(JSONValue valeurJson) {
820
		
842
		
821
		JSONObject activiteJson = valeurJson.isObject();
843
		JSONObject activiteJson = valeurJson.isObject();
822
		
844
		
823
		String nbEvtsUtilisateur = activiteJson.get("nb_evenements").isString().stringValue();
845
		String nbEvtsUtilisateur = activiteJson.get("nb_evenements").isString().stringValue();
824
		String dateDerniereConsultationEvts = activiteJson.get("date_derniere_consultation_evenements").isString().stringValue();
846
		String dateDerniereConsultationEvts = activiteJson.get("date_derniere_consultation_evenements").isString().stringValue();
825
 
847
 
826
		ActiviteUtilisateur activite = new ActiviteUtilisateur();
848
		ActiviteUtilisateur activite = new ActiviteUtilisateur();
827
		activite.setNbEvenements(nbEvtsUtilisateur);
849
		activite.setNbEvenements(nbEvtsUtilisateur);
828
		activite.setDateDerniereConsultationEvenements(dateDerniereConsultationEvts);
850
		activite.setDateDerniereConsultationEvenements(dateDerniereConsultationEvts);
829
		
851
		
830
		return activite;
852
		return activite;
831
	}
853
	}
832
}
854
}