Subversion Repositories eFlore/Applications.del

Rev

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

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