Subversion Repositories eFlore/Applications.del

Rev

Rev 2101 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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