Subversion Repositories eFlore/Applications.del

Rev

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

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