| Line 1... |
Line 1... |
| 1 |
package org.tela_botanica.del.client.modeles;
|
1 |
package org.tela_botanica.del.client.modeles;
|
| Line -... |
Line 2... |
| - |
|
2 |
|
| - |
|
3 |
import java.util.ArrayList;
|
| 2 |
|
4 |
import java.util.Date;
|
| Line -... |
Line 5... |
| - |
|
5 |
import java.util.List;
|
| - |
|
6 |
|
| - |
|
7 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
| - |
|
8 |
import com.google.gwt.json.client.JSONArray;
|
| - |
|
9 |
import com.google.gwt.json.client.JSONObject;
|
| 3 |
import java.util.List;
|
10 |
import com.google.gwt.json.client.JSONValue;
|
| Line 4... |
Line 11... |
| 4 |
|
11 |
|
| Line 5... |
Line 12... |
| 5 |
public class ObservationServiceResultat {
|
12 |
public class ObservationServiceResultat {
|
| Line -... |
Line 13... |
| - |
|
13 |
|
| - |
|
14 |
private List<Observation> observations;
|
| - |
|
15 |
|
| - |
|
16 |
private int nbTotalObservationsPourLaRecherche;
|
| - |
|
17 |
|
| - |
|
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());
|
| - |
|
34 |
observation.setDate(observationJson.get("date_observation").isString().stringValue());
|
| - |
|
35 |
observation.setFamille(observationJson.get("famille").isString().stringValue());
|
| - |
|
36 |
observation.setId(observationJson.get("id_observation").isString().stringValue());
|
| - |
|
37 |
observation.setLocalite(observationJson.get("ce_zone_geo").isString().stringValue());
|
| - |
|
38 |
observation.setNomRetenu(observationJson.get("nom_ret").isString().stringValue());
|
| - |
|
39 |
observation.setNumNomenclatural(observationJson.get("nom_ret_nn").isString().stringValue());
|
| - |
|
40 |
observation.setMotsClefs(parserMotsCles(observationJson.get("mots_cles_texte").isString().stringValue()));
|
| - |
|
41 |
|
| - |
|
42 |
PropositionDetermination propositionDetermination = new PropositionDetermination();
|
| - |
|
43 |
propositionDetermination.setContributeur(observationJson.get("prenom_utilisateur").isString().stringValue()+
|
| - |
|
44 |
" "+observationJson.get("nom_utilisateur").isString().stringValue());
|
| - |
|
45 |
java.util.Date datePropDeter = parserDateObservation(observationJson.get("date_observation").isString().stringValue());
|
| - |
|
46 |
propositionDetermination.setDate(datePropDeter);
|
| - |
|
47 |
propositionDetermination.setEspece(observationJson.get("nom_ret").isString().stringValue());
|
| - |
|
48 |
observation.addImageCelValidationData(propositionDetermination);
|
| - |
|
49 |
|
| - |
|
50 |
JSONArray tableauImagesObs = observationJson.get("images").isArray();
|
| - |
|
51 |
List<Image> imagesPourObs = new ArrayList<Image>();
|
| - |
|
52 |
|
| - |
|
53 |
int nbImages = tableauImagesObs.size();
|
| - |
|
54 |
for (int j = 0; j < nbImages; j++) {
|
| - |
|
55 |
JSONObject imageJson = tableauImagesObs.get(j).isObject();
|
| - |
|
56 |
Image image = new Image();
|
| - |
|
57 |
String idImage = "1"+imageJson.get("id_image").isString().stringValue();
|
| - |
|
58 |
image.setIdImage(idImage);
|
| - |
|
59 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"%s%.jpg");
|
| - |
|
60 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"CRS.jpg");
|
| - |
|
61 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:"+getIdAvecPadding(idImage)+"XS.jpg");
|
| - |
|
62 |
image.setObservation(observation);
|
| - |
|
63 |
imagesPourObs.add(image);
|
| - |
|
64 |
}
|
| - |
|
65 |
|
| 6 |
|
66 |
observation.setImages(imagesPourObs);
|
| 7 |
private List<Observation> observations;
|
67 |
observations.add(observation);
|
| 8 |
|
68 |
}
|
| Line 9... |
Line 69... |
| 9 |
private int nbTotalObservationsPourLaRecherche;
|
69 |
}
|
| Line 21... |
Line 81... |
| 21 |
}
|
81 |
}
|
| Line 22... |
Line 82... |
| 22 |
|
82 |
|
| 23 |
public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
|
83 |
public void setNbTotalObservationsPourLaRecherche(int nbTotalObservationsPourLaRecherche) {
|
| 24 |
this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
|
84 |
this.nbTotalObservationsPourLaRecherche = nbTotalObservationsPourLaRecherche;
|
| - |
|
85 |
}
|
| - |
|
86 |
|
| - |
|
87 |
private String getIdAvecPadding(String id) {
|
| - |
|
88 |
|
| - |
|
89 |
int maxZeros = 9 - id.length();
|
| - |
|
90 |
|
| - |
|
91 |
for (int i = 0; i < maxZeros; i++) {
|
| - |
|
92 |
id = "0" + id;
|
| - |
|
93 |
}
|
| - |
|
94 |
|
| - |
|
95 |
return id;
|
| - |
|
96 |
}
|
| - |
|
97 |
|
| - |
|
98 |
private Date parserDateObservation(String date) {
|
| - |
|
99 |
Date dateParsee = new Date();
|
| - |
|
100 |
DateTimeFormat formatDateObs = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
|
| - |
|
101 |
try{
|
| - |
|
102 |
dateParsee = formatDateObs.parse(date);
|
| - |
|
103 |
} catch (IllegalArgumentException e) {
|
| - |
|
104 |
dateParsee = new java.sql.Date(0);
|
| - |
|
105 |
}
|
| - |
|
106 |
return dateParsee;
|
| - |
|
107 |
}
|
| - |
|
108 |
|
| - |
|
109 |
private List<String> parserMotsCles(String motsClesTexte) {
|
| - |
|
110 |
String[] tabMotsCle = motsClesTexte.split(",");
|
| - |
|
111 |
List<String> motsClesParses = new ArrayList<String>();
|
| - |
|
112 |
for (int i = 0; i < tabMotsCle.length; i++) {
|
| - |
|
113 |
motsClesParses.add(tabMotsCle[i]);
|
| - |
|
114 |
}
|
| - |
|
115 |
|
| - |
|
116 |
return motsClesParses;
|
| Line 25... |
Line 117... |
| 25 |
}
|
117 |
}
|