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