359 |
benjamin |
1 |
package org.tela_botanica.del.client.modeles;
|
|
|
2 |
|
392 |
aurelien |
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Date;
|
359 |
benjamin |
5 |
import java.util.List;
|
|
|
6 |
|
392 |
aurelien |
7 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
8 |
import com.google.gwt.json.client.JSONArray;
|
|
|
9 |
import com.google.gwt.json.client.JSONObject;
|
|
|
10 |
import com.google.gwt.json.client.JSONValue;
|
|
|
11 |
|
359 |
benjamin |
12 |
public class ObservationServiceResultat {
|
|
|
13 |
|
|
|
14 |
private List<Observation> observations;
|
|
|
15 |
|
|
|
16 |
private int nbTotalObservationsPourLaRecherche;
|
|
|
17 |
|
392 |
aurelien |
18 |
public ObservationServiceResultat(JSONValue retourJson) {
|
|
|
19 |
//TODO ajouter vérifications plus précises
|
|
|
20 |
double total = retourJson.isObject().get("total").isNumber().doubleValue();
|
|
|
21 |
nbTotalObservationsPourLaRecherche = (int) total;
|
|
|
22 |
JSONArray tableauObs = retourJson.isObject().get("contenu").isArray();
|
|
|
23 |
|
|
|
24 |
observations = new ArrayList<Observation>();
|
|
|
25 |
|
|
|
26 |
int nbResultats = tableauObs.size();
|
|
|
27 |
for (int i = 0; i < nbResultats; i++) {
|
|
|
28 |
|
|
|
29 |
JSONObject observationJson = tableauObs.get(i).isObject();
|
|
|
30 |
Observation observation = new Observation();
|
|
|
31 |
|
|
|
32 |
observation.setAuteur(observationJson.get("prenom_utilisateur").isString().stringValue()+
|
|
|
33 |
" "+observationJson.get("nom_utilisateur").isString().stringValue());
|
449 |
gduche |
34 |
observation.setDateReleve(observationJson.get("date_observation").isString().stringValue());
|
|
|
35 |
observation.setDateTransmission(observationJson.get("date_transmission").isString().stringValue());
|
392 |
aurelien |
36 |
observation.setFamille(observationJson.get("famille").isString().stringValue());
|
|
|
37 |
observation.setId(observationJson.get("id_observation").isString().stringValue());
|
462 |
aurelien |
38 |
observation.setIdLocalite(observationJson.get("ce_zone_geo").isString().stringValue());
|
|
|
39 |
observation.setLocalite(observationJson.get("zone_geo").isString().stringValue());
|
447 |
gduche |
40 |
observation.setLieuDit(observationJson.get("lieudit").isString().stringValue());
|
|
|
41 |
observation.setMilieu(observationJson.get("milieu").isString().stringValue());
|
392 |
aurelien |
42 |
observation.setNomRetenu(observationJson.get("nom_ret").isString().stringValue());
|
447 |
gduche |
43 |
observation.setCommentaire(observationJson.get("commentaire").isString().stringValue());
|
|
|
44 |
observation.ajouterMotsClef(observationJson.get("mots_cles_texte").isString().stringValue());
|
392 |
aurelien |
45 |
observation.setNumNomenclatural(observationJson.get("nom_ret_nn").isString().stringValue());
|
|
|
46 |
observation.setMotsClefs(parserMotsCles(observationJson.get("mots_cles_texte").isString().stringValue()));
|
|
|
47 |
|
|
|
48 |
PropositionDetermination propositionDetermination = new PropositionDetermination();
|
|
|
49 |
propositionDetermination.setContributeur(observationJson.get("prenom_utilisateur").isString().stringValue()+
|
|
|
50 |
" "+observationJson.get("nom_utilisateur").isString().stringValue());
|
|
|
51 |
java.util.Date datePropDeter = parserDateObservation(observationJson.get("date_observation").isString().stringValue());
|
|
|
52 |
propositionDetermination.setDate(datePropDeter);
|
|
|
53 |
propositionDetermination.setEspece(observationJson.get("nom_ret").isString().stringValue());
|
|
|
54 |
observation.addImageCelValidationData(propositionDetermination);
|
|
|
55 |
|
|
|
56 |
JSONArray tableauImagesObs = observationJson.get("images").isArray();
|
|
|
57 |
List<Image> imagesPourObs = new ArrayList<Image>();
|
|
|
58 |
|
|
|
59 |
int nbImages = tableauImagesObs.size();
|
|
|
60 |
for (int j = 0; j < nbImages; j++) {
|
|
|
61 |
JSONObject imageJson = tableauImagesObs.get(j).isObject();
|
|
|
62 |
Image image = new Image();
|
|
|
63 |
String idImage = "1"+imageJson.get("id_image").isString().stringValue();
|
|
|
64 |
image.setIdImage(idImage);
|
|
|
65 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"%s%.jpg");
|
|
|
66 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"CRS.jpg");
|
|
|
67 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"XS.jpg");
|
|
|
68 |
image.setObservation(observation);
|
|
|
69 |
imagesPourObs.add(image);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
observation.setImages(imagesPourObs);
|
|
|
73 |
observations.add(observation);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
359 |
benjamin |
77 |
public List<Observation> getObservations() {
|
|
|
78 |
return observations;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public void setObservations(List<Observation> observations) {
|
|
|
82 |
this.observations = observations;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public int getNbTotalObservationsPourLaRecherche() {
|
|
|
86 |
return nbTotalObservationsPourLaRecherche;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
|
|
|
90 |
this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
|
|
|
91 |
}
|
392 |
aurelien |
92 |
|
|
|
93 |
private String getIdAvecPadding(String id) {
|
359 |
benjamin |
94 |
|
392 |
aurelien |
95 |
int maxZeros = 9 - id.length();
|
|
|
96 |
|
|
|
97 |
for (int i = 0; i < maxZeros; i++) {
|
|
|
98 |
id = "0" + id;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
return id;
|
|
|
102 |
}
|
359 |
benjamin |
103 |
|
392 |
aurelien |
104 |
private Date parserDateObservation(String date) {
|
|
|
105 |
Date dateParsee = new Date();
|
|
|
106 |
DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
107 |
try{
|
|
|
108 |
dateParsee = formatDateObs.parse(date);
|
|
|
109 |
} catch (IllegalArgumentException e) {
|
|
|
110 |
dateParsee = new java.sql.Date(0);
|
|
|
111 |
}
|
|
|
112 |
return dateParsee;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
private List<String> parserMotsCles(String motsClesTexte) {
|
|
|
116 |
String[] tabMotsCle = motsClesTexte.split(",");
|
|
|
117 |
List<String> motsClesParses = new ArrayList<String>();
|
|
|
118 |
for (int i = 0; i < tabMotsCle.length; i++) {
|
|
|
119 |
motsClesParses.add(tabMotsCle[i]);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
return motsClesParses;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
|
359 |
benjamin |
126 |
}
|