Line 1... |
Line 1... |
1 |
package org.tela_botanica.del.client.utils;
|
1 |
package org.tela_botanica.del.client.utils;
|
Line 2... |
Line 2... |
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;
|
Line -... |
Line 7... |
- |
|
7 |
import java.util.List;
|
6 |
import java.util.List;
|
8 |
|
7 |
|
9 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
8 |
import org.tela_botanica.del.client.modeles.Contributeur;
|
10 |
import org.tela_botanica.del.client.modeles.Contributeur;
|
9 |
import org.tela_botanica.del.client.modeles.Image;
|
11 |
import org.tela_botanica.del.client.modeles.Image;
|
10 |
import org.tela_botanica.del.client.modeles.InterventionForum;
|
12 |
import org.tela_botanica.del.client.modeles.InterventionForum;
|
Line 15... |
Line 17... |
15 |
import org.tela_botanica.del.client.modeles.VoteProtocole;
|
17 |
import org.tela_botanica.del.client.modeles.VoteProtocole;
|
Line 16... |
Line 18... |
16 |
|
18 |
|
17 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
19 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
18 |
import com.google.gwt.json.client.JSONObject;
|
20 |
import com.google.gwt.json.client.JSONObject;
|
- |
|
21 |
import com.google.gwt.json.client.JSONValue;
|
Line 19... |
Line 22... |
19 |
import com.google.gwt.json.client.JSONValue;
|
22 |
import com.google.gwt.user.client.Window;
|
Line 20... |
Line 23... |
20 |
|
23 |
|
Line 60... |
Line 63... |
60 |
//TODO: renvoyer les mots clés des observations
|
63 |
//TODO: renvoyer les mots clés des observations
|
61 |
//observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
|
64 |
//observation.setMotsClefs(parserMotsCles(UtilitairesServiceResultat.getValeurOuVide(observationJson, "mots_cles_texte")));
|
62 |
//TODO: renvoyer les commentaires des obs
|
65 |
//TODO: renvoyer les commentaires des obs
|
63 |
//observation.setCommentaire(UtilitairesServiceResultat.getValeurOuVide(observationJson, "commentaire"));
|
66 |
//observation.setCommentaire(UtilitairesServiceResultat.getValeurOuVide(observationJson, "commentaire"));
|
64 |
JSONValue propositions = observationJson.get("commentaires");
|
67 |
JSONValue propositions = observationJson.get("commentaires");
|
65 |
|
68 |
|
66 |
if(propositions != null && propositions.isObject() != null) {
|
69 |
if(propositions != null && propositions.isObject() != null) {
|
67 |
observation.setInterventionsForum(parserInterventions(propositions.isObject(), observation));
|
70 |
List<InterventionForum> interventions = hierarchiserInterventions(parserInterventions(propositions.isObject(), observation));
|
- |
|
71 |
observation.setInterventionsForum(interventions);
|
68 |
} else {
|
72 |
} else {
|
69 |
observation.ajouterPropositionDetermination(creerPropositionDeterminationAPartirObservation(observation));
|
73 |
observation.ajouterPropositionDetermination(creerPropositionDeterminationAPartirObservation(observation));
|
70 |
}
|
74 |
}
|
71 |
return observation;
|
75 |
return observation;
|
72 |
}
|
76 |
}
|
Line -... |
Line 77... |
- |
|
77 |
|
- |
|
78 |
public static List<InterventionForum> hierarchiserInterventions(HashMap<String, InterventionForum> interventions) {
|
- |
|
79 |
//TODO : gérer l'arborescence
|
- |
|
80 |
List<InterventionForum> interventionsHierarchisees = new ArrayList<InterventionForum>();
|
- |
|
81 |
interventionsHierarchisees.addAll(interventions.values());
|
- |
|
82 |
return interventionsHierarchisees;
|
- |
|
83 |
//Iterator<String> it = interventions.
|
- |
|
84 |
//return interventionsHierarchisees;
|
- |
|
85 |
}
|
73 |
|
86 |
|
74 |
public static String getValeurOuVide(JSONObject objet, String index) {
|
87 |
public static String getValeurOuVide(JSONObject objet, String index) {
|
75 |
return (objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
|
88 |
return (objet.get(index).isString() != null) ? objet.get(index).isString().stringValue() : "";
|
Line 76... |
Line 89... |
76 |
}
|
89 |
}
|
Line 88... |
Line 101... |
88 |
propositionDetermination.setEspece(observation.getNomRetenu());
|
101 |
propositionDetermination.setEspece(observation.getNomRetenu());
|
Line 89... |
Line 102... |
89 |
|
102 |
|
90 |
return propositionDetermination;
|
103 |
return propositionDetermination;
|
Line 91... |
Line 104... |
91 |
}
|
104 |
}
|
92 |
|
105 |
|
Line 93... |
Line 106... |
93 |
public static List<InterventionForum> parserInterventions(JSONObject interventions, Observation observation) {
|
106 |
public static HashMap<String, InterventionForum> parserInterventions(JSONObject interventions, Observation observation) {
|
Line 94... |
Line 107... |
94 |
List<InterventionForum> listeInterventions = new ArrayList<InterventionForum>();
|
107 |
HashMap<String, InterventionForum> listeInterventions = new HashMap<String, InterventionForum>();
|
95 |
|
108 |
|
96 |
boolean propositionDeterminationCreee = false;
|
109 |
boolean propositionDeterminationCreee = false;
|
97 |
|
110 |
|
- |
|
111 |
java.util.Iterator<String> itInterventions = interventions.keySet().iterator();
|
98 |
java.util.Iterator<String> itInterventions = interventions.keySet().iterator();
|
112 |
while (itInterventions.hasNext()) {
|
99 |
while (itInterventions.hasNext()) {
|
113 |
JSONObject intervention = interventions.get(itInterventions.next()).isObject();
|
100 |
JSONObject intervention = interventions.get(itInterventions.next()).isObject();
|
114 |
String nomSel = getValeurOuVide(intervention, "nom_sel");
|
101 |
String nomSel = getValeurOuVide(intervention, "nom_sel");
|
115 |
String idIntervention = intervention.get("id_commentaire").isString().stringValue();
|
102 |
if(!nomSel.equals("")) {
|
116 |
if(!nomSel.equals("")) {
|
Line 109... |
Line 123... |
109 |
propDeter.setEspece(nomSel);
|
123 |
propDeter.setEspece(nomSel);
|
110 |
propDeter.setId(getValeurOuVide(intervention, "id_commentaire"));
|
124 |
propDeter.setId(getValeurOuVide(intervention, "id_commentaire"));
|
111 |
if(intervention.get("votes") != null && intervention.get("votes").isObject() != null) {
|
125 |
if(intervention.get("votes") != null && intervention.get("votes").isObject() != null) {
|
112 |
propDeter.setVotesDeterminations(parserVotesDetermination(intervention.get("votes").isObject(), propDeter));
|
126 |
propDeter.setVotesDeterminations(parserVotesDetermination(intervention.get("votes").isObject(), propDeter));
|
113 |
}
|
127 |
}
|
114 |
listeInterventions.add(propDeter);
|
128 |
listeInterventions.put(idIntervention, propDeter);
|
Line 115... |
Line 129... |
115 |
|
129 |
|
116 |
String idContributeur = getValeurOuVide(intervention, "ce_utilisateur");
|
130 |
String idContributeur = getValeurOuVide(intervention, "ce_utilisateur");
|
117 |
if(nomSel.equals(observation.getNomRetenu()) && idContributeur.equals(observation.getIdAuteur())) {
|
131 |
if(nomSel.equals(observation.getNomRetenu()) && idContributeur.equals(observation.getIdAuteur())) {
|
118 |
propositionDeterminationCreee = true;
|
132 |
propositionDeterminationCreee = true;
|
- |
|
133 |
}
|
- |
|
134 |
} else {
|
- |
|
135 |
|
- |
|
136 |
//C'est un commentaire seul
|
- |
|
137 |
String texte = intervention.get("texte").isString().stringValue();
|
- |
|
138 |
texte = intervention.get("id_commentaire").isString().stringValue() + texte;
|
- |
|
139 |
String nom = intervention.get("utilisateur_nom").isString().stringValue();
|
- |
|
140 |
String prenom = intervention.get("utilisateur_prenom").isString().stringValue();
|
- |
|
141 |
String courriel = intervention.get("utilisateur_courriel").isString().stringValue();
|
- |
|
142 |
Contributeur contributeur = new Contributeur(nom, prenom, courriel);
|
- |
|
143 |
|
- |
|
144 |
//TODO : parser date commentaire
|
- |
|
145 |
Commentaire commentaire = new Commentaire(contributeur, new Date(), texte);
|
119 |
}
|
146 |
listeInterventions.put(idIntervention, commentaire);
|
120 |
}
|
147 |
}
|
Line 121... |
Line 148... |
121 |
}
|
148 |
}
|
122 |
|
149 |
|
123 |
if(!propositionDeterminationCreee) {
|
150 |
if(!propositionDeterminationCreee) {
|
124 |
PropositionDetermination determinationOriginale = creerPropositionDeterminationAPartirObservation(observation);
|
151 |
PropositionDetermination determinationOriginale = creerPropositionDeterminationAPartirObservation(observation);
|
125 |
listeInterventions.add(0, determinationOriginale);
|
152 |
listeInterventions.put("0", determinationOriginale);
|
126 |
}
|
153 |
}
|
Line 127... |
Line 154... |
127 |
return listeInterventions;
|
154 |
return listeInterventions;
|