| Line 20... |
Line 20... |
| 20 |
import com.google.gwt.json.client.JSONObject;
|
20 |
import com.google.gwt.json.client.JSONObject;
|
| 21 |
import com.google.gwt.json.client.JSONParser;
|
21 |
import com.google.gwt.json.client.JSONParser;
|
| 22 |
import com.google.gwt.json.client.JSONValue;
|
22 |
import com.google.gwt.json.client.JSONValue;
|
| Line 23... |
Line 23... |
| 23 |
|
23 |
|
| 24 |
public class UtilitairesServiceResultat {
|
24 |
public class UtilitairesServiceResultat {
|
| 25 |
|
25 |
|
| 26 |
public static Image parserImageJSON (JSONObject imageJson) {
|
26 |
public static Image parserImageJSON(JSONObject imageJson) {
|
| 27 |
|
27 |
|
| 28 |
Image image = new Image();
|
28 |
Image image = new Image();
|
| 29 |
String idImage = imageJson.get("id_image").isString().stringValue();
|
29 |
String idImage = imageJson.get("id_image").isString().stringValue();
|
| 30 |
image.setIdImage(idImage);
|
30 |
image.setIdImage(idImage);
|
| 31 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"%s%.jpg");
|
31 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "%s%.jpg");
|
| 32 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"CRS.jpg");
|
32 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "CRS.jpg");
|
| 33 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"XS.jpg");
|
33 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:" + getIdAvecPadding(idImage) + "XS.jpg");
|
| 34 |
|
34 |
|
| 35 |
return image;
|
35 |
return image;
|
| 36 |
}
|
36 |
}
|
| 37 |
|
37 |
|
| 38 |
public static Observation parserObservationEtCreerPropositionDetermination(JSONObject observationJson) {
|
38 |
public static Observation parserObservationEtCreerPropositionDetermination(JSONObject observationJson) {
|
| 39 |
Observation observation = parserObservationJSON(observationJson);
|
39 |
Observation observation = parserObservationJSON(observationJson);
|
| 40 |
return observation;
|
40 |
return observation;
|
| 41 |
}
|
41 |
}
|
| 42 |
|
42 |
|
| 43 |
public static Observation parserObservationJSON(JSONObject observationJson) {
|
43 |
public static Observation parserObservationJSON(JSONObject observationJson) {
|
| 44 |
|
44 |
|
| 45 |
Observation observation = new Observation();
|
45 |
Observation observation = new Observation();
|
| 46 |
observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom")+
|
- |
|
| 47 |
" "+getValeurOuVide(observationJson,"auteur.nom"));
|
46 |
observation.setAuteur(getValeurOuVide(observationJson, "auteur.prenom") + " " + getValeurOuVide(observationJson, "auteur.nom"));
|
| 48 |
observation.setNomAuteur(getValeurOuVide(observationJson,"auteur.nom"));
|
47 |
observation.setNomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
|
| 49 |
observation.setPrenomAuteur(getValeurOuVide(observationJson,"auteur.nom"));
|
48 |
observation.setPrenomAuteur(getValeurOuVide(observationJson, "auteur.nom"));
|
| 50 |
observation.setIdAuteur(getValeurOuVide(observationJson,"auteur.id"));
|
49 |
observation.setIdAuteur(getValeurOuVide(observationJson, "auteur.id"));
|
| 51 |
//TODO: renvoyer le courriel de l'auteur dans les obs
|
50 |
// TODO: renvoyer le courriel de l'auteur dans les obs
|
| 52 |
observation.setCourrielAuteur("");
|
51 |
observation.setCourrielAuteur("");
|
| 53 |
observation.setDateTransmission(getValeurOuVide(observationJson,"date_observation"));
|
52 |
observation.setDateTransmission(getValeurOuVide(observationJson, "date_observation"));
|
| 54 |
observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
|
53 |
observation.setDateReleve(getValeurOuVide(observationJson, "date_observation"));
|
| 55 |
observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
|
54 |
observation.setFamille(getValeurOuVide(observationJson, "determination.famille"));
|
| 56 |
observation.setId(getValeurOuVide(observationJson, "id_observation"));
|
55 |
observation.setId(getValeurOuVide(observationJson, "id_observation"));
|
| 57 |
observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
|
56 |
observation.setIdLocalite(getValeurOuVide(observationJson, "id_zone_geo"));
|
| 58 |
observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
|
57 |
observation.setLocalite(getValeurOuVide(observationJson, "zone_geo"));
|
| 59 |
observation.setNomRetenu(getValeurOuVide(observationJson, "determination.ns"));
|
58 |
observation.setNomRetenu(getValeurOuVide(observationJson, "determination.ns"));
|
| 60 |
observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
|
59 |
observation.setMilieu(getValeurOuVide(observationJson, "milieu"));
|
| 61 |
observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
|
60 |
observation.setLieuDit(getValeurOuVide(observationJson, "lieudit"));
|
| 62 |
observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
|
61 |
observation.setNumNomenclatural(getValeurOuVide(observationJson, "determination.nn"));
|
| 63 |
//TODO: renvoyer les mots clés des observations
|
62 |
// TODO: renvoyer les mots clés des observations
|
| - |
|
63 |
// observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson,
|
| 64 |
//observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
|
64 |
// "mots_cles_texte")));
|
| 65 |
JSONValue propositions = observationJson.get("commentaires");
|
65 |
JSONValue propositions = observationJson.get("commentaires");
|
| 66 |
|
66 |
|
| 67 |
if(propositions != null && propositions.isObject() != null) {
|
67 |
if (propositions != null && propositions.isObject() != null) {
|
| 68 |
List<InterventionForum> interventions = parserInterventions(propositions.isObject(), observation);
|
68 |
List<InterventionForum> interventions = parserInterventions(propositions.isObject(), observation);
|
| 69 |
observation.setInterventionsForum(interventions);
|
69 |
observation.setInterventionsForum(interventions);
|
| 70 |
} else {
|
70 |
} else {
|
| 71 |
observation.ajouterPropositionDetermination(creerPropositionDeterminationAPartirObservation(observation));
|
71 |
observation.ajouterPropositionDetermination(creerPropositionDeterminationAPartirObservation(observation));
|
| 72 |
}
|
72 |
}
|
| 73 |
return observation;
|
73 |
return observation;
|
| 74 |
}
|
74 |
}
|
| - |
|
75 |
|
| - |
|
76 |
public static List<Commentaire> parserCommentaires(JSONObject commentaires, Observation observation) {
|
| - |
|
77 |
List<InterventionForum> interventionForums = parserInterventions(commentaires, observation);
|
| - |
|
78 |
List<Commentaire> commentairesListe = new ArrayList<Commentaire>();
|
| - |
|
79 |
for (InterventionForum interventionForum : interventionForums) {
|
| - |
|
80 |
if (interventionForum instanceof Commentaire) {
|
| - |
|
81 |
commentairesListe.add((Commentaire) interventionForum);
|
| - |
|
82 |
}
|
| - |
|
83 |
}
|
| - |
|
84 |
return commentairesListe;
|
| - |
|
85 |
|
| - |
|
86 |
}
|
| 75 |
|
87 |
|
| 76 |
public static List<InterventionForum> parserInterventions(JSONObject interventions, Observation observation) {
|
88 |
public static List<InterventionForum> parserInterventions(JSONObject interventions, Observation observation) {
|
| - |
|
89 |
HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
|
| - |
|
90 |
|
| Line 77... |
Line 91... |
| 77 |
HashMap<String, InterventionForum> interventionsNonTypees = new HashMap<String, InterventionForum>();
|
91 |
List<InterventionForum> retour = new ArrayList<InterventionForum>();
|
| - |
|
92 |
|
| - |
|
93 |
// parcourir les interventions et en faire un tableau
|
| - |
|
94 |
if(interventions==null){
|
| 78 |
|
95 |
return retour;
|
| 79 |
//parcourir les interventions et en faire un tableau
|
96 |
}
|
| 80 |
Iterator<String> itInterventions = interventions.keySet().iterator();
|
97 |
Iterator<String> itInterventions = interventions.keySet().iterator();
|
| 81 |
while (itInterventions.hasNext()) {
|
98 |
while (itInterventions.hasNext()) {
|
| 82 |
JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
|
99 |
JSONObject jsonIntervention = interventions.get(itInterventions.next()).isObject();
|
| 83 |
String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
|
100 |
String nomSel = getValeurOuVide(jsonIntervention, "nom_sel");
|
| 84 |
|
101 |
|
| 85 |
String id = getValeurOuVide(jsonIntervention, "id_commentaire");
|
102 |
String id = getValeurOuVide(jsonIntervention, "id_commentaire");
|
| 86 |
String idParent = getValeurOuVide(jsonIntervention, "ce_commentaire_parent");
|
103 |
String idParent = getValeurOuVide(jsonIntervention, "ce_commentaire_parent");
|
| 87 |
String texte = getValeurOuVide(jsonIntervention, "texte");
|
104 |
String texte = getValeurOuVide(jsonIntervention, "texte");
|
| 88 |
|
105 |
|
| 89 |
String idUtilisateur = getValeurOuVide(jsonIntervention, "ce_utilisateur");
|
106 |
String idUtilisateur = getValeurOuVide(jsonIntervention, "ce_utilisateur");
|
| 90 |
String nom = getValeurOuVide(jsonIntervention, "utilisateur_nom");
|
107 |
String nom = getValeurOuVide(jsonIntervention, "utilisateur_nom");
|
| 91 |
String prenom = getValeurOuVide(jsonIntervention, "utilisateur_prenom");
|
108 |
String prenom = getValeurOuVide(jsonIntervention, "utilisateur_prenom");
|
| 92 |
String courriel = getValeurOuVide(jsonIntervention, "utilisateur_courriel");
|
109 |
String courriel = getValeurOuVide(jsonIntervention, "utilisateur_courriel");
|
| 93 |
Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
|
110 |
Contributeur contributeur = new Contributeur(idUtilisateur, nom, prenom, courriel);
|
| 94 |
|
111 |
|
| 95 |
//TODO : parser date
|
112 |
// TODO : parser date
|
| 96 |
Date date = new Date();
|
113 |
Date date = new Date();
|
| 97 |
|
114 |
|
| 98 |
if (!nomSel.equals("")) {
|
115 |
if (!nomSel.equals("")) {
|
| 99 |
String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
|
116 |
String nom_sel = getValeurOuVide(jsonIntervention, "nom_sel");
|
| 100 |
String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
|
117 |
String nom_sel_nn = getValeurOuVide(jsonIntervention, "nom_sel_nn");
|
| 101 |
String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
|
118 |
String nom_ret = getValeurOuVide(jsonIntervention, "nom_ret");
|
| 102 |
String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
|
119 |
String nom_ret_nn = getValeurOuVide(jsonIntervention, "nom_ret_nn");
|
| 103 |
String famille = getValeurOuVide(jsonIntervention, "famille");
|
120 |
String famille = getValeurOuVide(jsonIntervention, "famille");
|
| 104 |
String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
|
121 |
String nom_referentiel = getValeurOuVide(jsonIntervention, "nom_referentiel");
|
| 105 |
|
122 |
|
| 106 |
String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
|
123 |
String nbCommentaires = getValeurOuVide(jsonIntervention, "nb_commentaires");
|
| 107 |
|
124 |
|
| 108 |
PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
|
125 |
PropositionDetermination intervention = new PropositionDetermination(id, contributeur, texte);
|
| 109 |
intervention.setObservation(observation);
|
126 |
intervention.setObservation(observation);
|
| 110 |
intervention.setEspece(nom_sel);
|
127 |
intervention.setEspece(nom_sel);
|
| 111 |
|
128 |
|
| 112 |
if(!nbCommentaires.equals("")) {
|
129 |
if (!nbCommentaires.equals("")) {
|
| 113 |
intervention.setNbCommentaires(Integer.parseInt(nbCommentaires));
|
130 |
intervention.setNbCommentaires(Integer.parseInt(nbCommentaires));
|
| 114 |
}
|
131 |
}
|
| 115 |
|
132 |
|
| 116 |
if (!idParent.equals("")) {
|
133 |
if (!idParent.equals("")) {
|
| 117 |
intervention.setIdParent(idParent);
|
134 |
intervention.setIdParent(idParent);
|
| 118 |
}
|
135 |
}
|
| 119 |
|
136 |
|
| 120 |
if(jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
|
137 |
if (jsonIntervention.get("votes") != null && jsonIntervention.get("votes").isObject() != null) {
|
| 121 |
intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject(), intervention));
|
138 |
intervention.setVotesDeterminations(parserVotesDetermination(jsonIntervention.get("votes").isObject(), intervention));
|
| 122 |
}
|
139 |
}
|
| 123 |
|
140 |
|
| 124 |
intervention.setDate(date);
|
- |
|
| 125 |
interventionsNonTypees.put(intervention.getId(), intervention);
|
141 |
intervention.setDate(date);
|
| 126 |
|
142 |
interventionsNonTypees.put(intervention.getId(), intervention);
|
| 127 |
|
143 |
|
| 128 |
} else {
|
144 |
} else {
|
| 129 |
Commentaire intervention = new Commentaire(contributeur, date, texte);
|
145 |
Commentaire intervention = new Commentaire(contributeur, date, texte);
|
| 130 |
intervention.setId(id);
|
146 |
intervention.setId(id);
|
| Line 144... |
Line 160... |
| 144 |
if (idParent != null && !idParent.equals("") && !idParent.equals("0")) {
|
160 |
if (idParent != null && !idParent.equals("") && !idParent.equals("0")) {
|
| 145 |
InterventionForum parent = interventionsNonTypees.get(idParent);
|
161 |
InterventionForum parent = interventionsNonTypees.get(idParent);
|
| 146 |
intervention.setParent(parent);
|
162 |
intervention.setParent(parent);
|
| 147 |
}
|
163 |
}
|
| 148 |
}
|
164 |
}
|
| - |
|
165 |
|
| Line 149... |
Line -... |
| 149 |
|
- |
|
| 150 |
List<InterventionForum> retour = new ArrayList<InterventionForum>();
|
166 |
|
| 151 |
retour.addAll(interventionsNonTypees.values());
|
167 |
retour.addAll(interventionsNonTypees.values());
|
| 152 |
return retour;
|
168 |
return retour;
|
| 153 |
}
|
169 |
}
|
| 154 |
|
170 |
|
| 155 |
public static String parserRetourAjoutCommentaire(JSONObject retour) {
|
171 |
public static String parserRetourAjoutCommentaire(JSONObject retour) {
|
| 156 |
String id = "";
|
172 |
String id = "";
|
| 157 |
if(retour != null) {
|
173 |
if (retour != null) {
|
| 158 |
id = getValeurOuVide(retour, "id_commentaire");
|
174 |
id = getValeurOuVide(retour, "id_commentaire");
|
| 159 |
}
|
175 |
}
|
| 160 |
return id;
|
176 |
return id;
|
| 161 |
}
|
177 |
}
|
| 162 |
|
178 |
|
| 163 |
public static String getValeurOuVide(JSONObject objet, String index) {
|
179 |
public static String getValeurOuVide(JSONObject objet, String index) {
|
| 164 |
return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
|
180 |
return (objet.get(index) != null && objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
|
| 165 |
}
|
181 |
}
|
| 166 |
|
182 |
|
| 167 |
public static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation) {
|
183 |
public static PropositionDetermination creerPropositionDeterminationAPartirObservation(Observation observation) {
|
| 168 |
|
184 |
|
| 169 |
String utilisateurNom = observation.getNomAuteur();
|
185 |
String utilisateurNom = observation.getNomAuteur();
|
| 170 |
String utilisateurPrenom = observation.getPrenomAuteur();
|
186 |
String utilisateurPrenom = observation.getPrenomAuteur();
|
| 171 |
String utilisateurCourriel = observation.getCourrielAuteur();
|
187 |
String utilisateurCourriel = observation.getCourrielAuteur();
|
| 172 |
String utilisateurId = observation.getIdAuteur();
|
188 |
String utilisateurId = observation.getIdAuteur();
|
| 173 |
PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
|
189 |
PropositionDetermination propositionDetermination = new PropositionDetermination(observation);
|
| 174 |
Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
|
190 |
Contributeur contributeur = new Contributeur(utilisateurId, utilisateurNom, utilisateurPrenom, utilisateurCourriel);
|
| 175 |
propositionDetermination.setContributeur(contributeur);
|
191 |
propositionDetermination.setContributeur(contributeur);
|
| 176 |
java.util.Date datePropDeter = parserDateObservation(observation.getDateReleve());
|
192 |
java.util.Date datePropDeter = parserDateObservation(observation.getDateReleve());
|
| 177 |
propositionDetermination.setDate(datePropDeter);
|
193 |
propositionDetermination.setDate(datePropDeter);
|
| 178 |
propositionDetermination.setEspece(observation.getNomRetenu());
|
194 |
propositionDetermination.setEspece(observation.getNomRetenu());
|
| 179 |
|
195 |
|
| 180 |
return propositionDetermination;
|
196 |
return propositionDetermination;
|
| 181 |
}
|
197 |
}
|
| 182 |
|
198 |
|
| Line 183... |
Line 199... |
| 183 |
public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString, PropositionDetermination proposition) {
|
199 |
public static HashMap<String, VoteDetermination> parserRetourListeVotesDetermination(String votesString, PropositionDetermination proposition) {
|
| 184 |
|
200 |
|
| 185 |
HashMap<String, VoteDetermination> retour = null;
|
201 |
HashMap<String, VoteDetermination> retour = null;
|
| 186 |
|
202 |
|
| 187 |
JSONObject votes = JSONParser.parseStrict(votesString).isObject();
|
203 |
JSONObject votes = JSONParser.parseStrict(votesString).isObject();
|
| 188 |
if(votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
|
204 |
if (votes != null && votes.get("resultats") != null && votes.get("resultats").isObject() != null) {
|
| 189 |
JSONObject resultat = votes.get("resultats").isObject();
|
205 |
JSONObject resultat = votes.get("resultats").isObject();
|
| 190 |
retour = parserVotesDetermination(resultat, proposition);
|
206 |
retour = parserVotesDetermination(resultat, proposition);
|
| 191 |
}
|
207 |
}
|
| 192 |
return retour;
|
208 |
return retour;
|
| 193 |
}
|
209 |
}
|
| 194 |
|
210 |
|
| 195 |
public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes, PropositionDetermination proposition) {
|
211 |
public static HashMap<String, VoteDetermination> parserVotesDetermination(JSONObject votes, PropositionDetermination proposition) {
|
| 196 |
HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
|
212 |
HashMap<String, VoteDetermination> votesDetermination = new HashMap<String, VoteDetermination>();
|
| 197 |
java.util.Iterator<String> itVotes = votes.keySet().iterator();
|
213 |
java.util.Iterator<String> itVotes = votes.keySet().iterator();
|
| Line 202... |
Line 218... |
| 202 |
vd.setDate(new Date());
|
218 |
vd.setDate(new Date());
|
| 203 |
vd.setId(getValeurOuVide(vote, "vote.id"));
|
219 |
vd.setId(getValeurOuVide(vote, "vote.id"));
|
| 204 |
vd.setPropositionDetermination(proposition);
|
220 |
vd.setPropositionDetermination(proposition);
|
| 205 |
vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
|
221 |
vd.setVote(Integer.parseInt(getValeurOuVide(vote, "vote")));
|
| 206 |
vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
|
222 |
vd.setContributeur(getValeurOuVide(vote, "auteur.id"));
|
| 207 |
|
223 |
|
| 208 |
if(vote.get("auteur.nom") != null &&
|
- |
|
| 209 |
vote.get("auteur.nom") != null &&
|
- |
|
| 210 |
vote.get("auteur.courriel") != null) {
|
224 |
if (vote.get("auteur.nom") != null && vote.get("auteur.nom") != null && vote.get("auteur.courriel") != null) {
|
| 211 |
Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"),
|
225 |
Contributeur auteur = new Contributeur(getValeurOuVide(vote, "auteur.id"), getValeurOuVide(vote, "auteur.nom"), getValeurOuVide(vote, "auteur.prenom"), getValeurOuVide(vote, "auteur.courriel"));
|
| 212 |
getValeurOuVide(vote, "auteur.nom"),
|
- |
|
| 213 |
getValeurOuVide(vote, "auteur.prenom"),
|
- |
|
| 214 |
getValeurOuVide(vote, "auteur.courriel"));
|
- |
|
| 215 |
vd.setAuteur(auteur);
|
226 |
vd.setAuteur(auteur);
|
| 216 |
}
|
227 |
}
|
| 217 |
|
228 |
|
| 218 |
votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
|
229 |
votesDetermination.put(getValeurOuVide(vote, "auteur.id"), vd);
|
| 219 |
}
|
230 |
}
|
| 220 |
return votesDetermination;
|
231 |
return votesDetermination;
|
| 221 |
}
|
232 |
}
|
| 222 |
|
233 |
|
| 223 |
public static HashMap<String, HashMap<String,VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
|
234 |
public static HashMap<String, HashMap<String, VoteProtocole>> parserVotesProtocoles(JSONObject votes) {
|
| 224 |
|
235 |
|
| 225 |
HashMap<String, HashMap<String,VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String,VoteProtocole>>();
|
236 |
HashMap<String, HashMap<String, VoteProtocole>> votesProtocoles = new HashMap<String, HashMap<String, VoteProtocole>>();
|
| 226 |
java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
|
237 |
java.util.Iterator<String> itProtocoles = votes.keySet().iterator();
|
| 227 |
while(itProtocoles.hasNext()) {
|
238 |
while (itProtocoles.hasNext()) {
|
| 228 |
JSONObject protocole = votes.get(itProtocoles.next()).isObject();
|
239 |
JSONObject protocole = votes.get(itProtocoles.next()).isObject();
|
| 229 |
JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
|
240 |
JSONObject votesPourCeProtocoles = protocole.get("votes").isObject();
|
| 230 |
String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
|
241 |
String idProtocoleVote = protocole.get("protocole.id").isString().stringValue();
|
| 231 |
java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
|
242 |
java.util.Iterator<String> itVotes = votesPourCeProtocoles.keySet().iterator();
|
| 232 |
while(itVotes.hasNext()) {
|
243 |
while (itVotes.hasNext()) {
|
| 233 |
JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
|
244 |
JSONObject voteEnCours = votesPourCeProtocoles.get(itVotes.next()).isObject();
|
| 234 |
VoteProtocole vd = new VoteProtocole();
|
245 |
VoteProtocole vd = new VoteProtocole();
|
| 235 |
vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
|
246 |
vd.setContributeur(voteEnCours.get("auteur.id").isString().stringValue());
|
| 236 |
// TODO récupérer la date du vote et la parser
|
247 |
// TODO récupérer la date du vote et la parser
|
| 237 |
vd.setDate(new Date());
|
248 |
vd.setDate(new Date());
|
| 238 |
int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
|
249 |
int valeurVote = Integer.parseInt(voteEnCours.get("vote").isString().stringValue());
|
| 239 |
vd.setVote(valeurVote);
|
250 |
vd.setVote(valeurVote);
|
| 240 |
if(!votesProtocoles.containsKey(idProtocoleVote)) {
|
251 |
if (!votesProtocoles.containsKey(idProtocoleVote)) {
|
| 241 |
votesProtocoles.put(idProtocoleVote, new HashMap<String,VoteProtocole>());
|
252 |
votesProtocoles.put(idProtocoleVote, new HashMap<String, VoteProtocole>());
|
| 242 |
}
|
253 |
}
|
| 243 |
votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
|
254 |
votesProtocoles.get(idProtocoleVote).put(vd.getContributeur(), vd);
|
| 244 |
}
|
255 |
}
|
| 245 |
}
|
256 |
}
|
| 246 |
|
257 |
|
| 247 |
return votesProtocoles;
|
258 |
return votesProtocoles;
|
| 248 |
}
|
259 |
}
|
| 249 |
|
260 |
|
| 250 |
public static Date parserDateObservation(String date) {
|
261 |
public static Date parserDateObservation(String date) {
|
| 251 |
Date dateParsee = new Date();
|
262 |
Date dateParsee = new Date();
|
| 252 |
DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
|
263 |
DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
|
| 253 |
try{
|
264 |
try {
|
| 254 |
dateParsee = formatDateObs.parse(date);
|
265 |
dateParsee = formatDateObs.parse(date);
|
| 255 |
} catch (IllegalArgumentException e) {
|
266 |
} catch (IllegalArgumentException e) {
|
| 256 |
dateParsee = new java.sql.Date(0);
|
267 |
dateParsee = new java.sql.Date(0);
|
| 257 |
}
|
268 |
}
|
| 258 |
return dateParsee;
|
269 |
return dateParsee;
|
| 259 |
}
|
270 |
}
|
| 260 |
|
271 |
|
| 261 |
public static List<String> parserMotsCles(String motsClesTexte) {
|
272 |
public static List<String> parserMotsCles(String motsClesTexte) {
|
| 262 |
String[] tabMotsCle = motsClesTexte.split(",");
|
273 |
String[] tabMotsCle = motsClesTexte.split(",");
|
| 263 |
List<String> motsClesParses = new ArrayList<String>();
|
274 |
List<String> motsClesParses = new ArrayList<String>();
|
| 264 |
for (int i = 0; i < tabMotsCle.length; i++) {
|
275 |
for (int i = 0; i < tabMotsCle.length; i++) {
|
| 265 |
motsClesParses.add(tabMotsCle[i]);
|
276 |
motsClesParses.add(tabMotsCle[i]);
|
| 266 |
}
|
277 |
}
|
| 267 |
|
278 |
|
| 268 |
return motsClesParses;
|
279 |
return motsClesParses;
|
| 269 |
}
|
280 |
}
|
| 270 |
|
281 |
|
| 271 |
public static String getIdAvecPadding(String id) {
|
282 |
public static String getIdAvecPadding(String id) {
|
| 272 |
int maxZeros = 9 - id.length();
|
283 |
int maxZeros = 9 - id.length();
|
| 273 |
for (int i = 0; i < maxZeros; i++) {
|
284 |
for (int i = 0; i < maxZeros; i++) {
|
| 274 |
id = "0" + id;
|
285 |
id = "0" + id;
|
| 275 |
}
|
286 |
}
|
| 276 |
return id;
|
287 |
return id;
|
| 277 |
}
|
288 |
}
|
| 278 |
|
289 |
|
| 279 |
public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
|
290 |
public static Utilisateur parserUtilisateurJson(JSONValue valeurJson) {
|
| 280 |
|
291 |
|
| 281 |
JSONObject utilisateurJson = valeurJson.isObject();
|
292 |
JSONObject utilisateurJson = valeurJson.isObject();
|
| 282 |
boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
|
293 |
boolean connecteUtilisateur = utilisateurJson.get("connecte").isBoolean().booleanValue();
|
| 283 |
String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
|
294 |
String idUtilisateur = utilisateurJson.get("id_utilisateur").isString().stringValue();
|
| 284 |
|
295 |
|
| 285 |
Utilisateur utilisateur;
|
296 |
Utilisateur utilisateur;
|
| 286 |
|
297 |
|
| 287 |
if(connecteUtilisateur) {
|
298 |
if (connecteUtilisateur) {
|
| 288 |
String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
|
299 |
String courrielUtilisateur = utilisateurJson.get("courriel").isString().stringValue();
|
| 289 |
String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
|
300 |
String nomUtilisateur = utilisateurJson.get("nom").isString().stringValue();
|
| 290 |
String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
|
301 |
String prenomUtilisateur = utilisateurJson.get("prenom").isString().stringValue();
|
| 291 |
|
302 |
|
| 292 |
utilisateur = new Utilisateur(idUtilisateur, prenomUtilisateur, nomUtilisateur, courrielUtilisateur);
|
303 |
utilisateur = new Utilisateur(idUtilisateur, prenomUtilisateur, nomUtilisateur, courrielUtilisateur);
|
| 293 |
} else {
|
304 |
} else {
|
| 294 |
utilisateur = new Utilisateur(idUtilisateur);
|
305 |
utilisateur = new Utilisateur(idUtilisateur);
|
| 295 |
}
|
306 |
}
|
| 296 |
|
307 |
|
| 297 |
return utilisateur;
|
308 |
return utilisateur;
|
| 298 |
}
|
309 |
}
|
| 299 |
}
|
310 |
}
|