Subversion Repositories eFlore/Applications.del

Rev

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

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