Subversion Repositories eFlore/Applications.del

Rev

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

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