Subversion Repositories eFlore/Applications.del

Rev

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

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