Subversion Repositories eFlore/Applications.del

Rev

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

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