Subversion Repositories eFlore/Applications.del

Rev

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

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