2 |
aperonnet |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Modele DAO, specifique, permettant la validation, l'acces aux donnees distantes et la présentation des donnees en retour
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
import org.tela_botanica.client.Util;
|
|
|
9 |
import org.tela_botanica.client.interfaces.iRetourObservation;
|
|
|
10 |
|
|
|
11 |
import com.google.gwt.http.client.URL;
|
|
|
12 |
import com.google.gwt.json.client.JSONArray;
|
|
|
13 |
import com.google.gwt.json.client.JSONNumber;
|
|
|
14 |
import com.google.gwt.json.client.JSONParser;
|
|
|
15 |
import com.google.gwt.json.client.JSONString;
|
|
|
16 |
import com.google.gwt.json.client.JSONValue;
|
|
|
17 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
18 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
19 |
|
|
|
20 |
public class ObservationAsynchroneDAO {
|
|
|
21 |
|
|
|
22 |
/**
|
5 |
aperonnet |
23 |
* Constructeur
|
2 |
aperonnet |
24 |
*/
|
5 |
aperonnet |
25 |
|
|
|
26 |
public ObservationAsynchroneDAO() {
|
|
|
27 |
|
2 |
aperonnet |
28 |
}
|
|
|
29 |
|
5 |
aperonnet |
30 |
public void getNombreObservation(String baseURL,
|
|
|
31 |
final iRetourObservation retour, String identifiant,
|
|
|
32 |
String identifiantLocalite, String localite, String annee,
|
|
|
33 |
String mois, String jour, String lieudit, String rechercheLibre) {
|
2 |
aperonnet |
34 |
|
5 |
aperonnet |
35 |
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant
|
|
|
36 |
+ "/" + identifiantLocalite + "/"
|
|
|
37 |
+ URL.encodeComponent(localite) + "/" + annee + "/" + mois
|
|
|
38 |
+ "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/"
|
|
|
39 |
+ URL.encodeComponent(lieudit), new ResponseTextHandler() {
|
2 |
aperonnet |
40 |
|
5 |
aperonnet |
41 |
public void onCompletion(String str) {
|
2 |
aperonnet |
42 |
|
5 |
aperonnet |
43 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
44 |
JSONNumber jsonNumber;
|
|
|
45 |
if ((jsonNumber = jsonValue.isNumber()) != null) {
|
|
|
46 |
retour
|
|
|
47 |
.onRetour(new Observation((int) jsonNumber
|
|
|
48 |
.getValue()));
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
});
|
2 |
aperonnet |
52 |
|
5 |
aperonnet |
53 |
}
|
2 |
aperonnet |
54 |
|
5 |
aperonnet |
55 |
public void getListeObservation(String baseURL,
|
|
|
56 |
final iRetourObservation retour, String identifiant,
|
|
|
57 |
String identifiantLocalite, String localite, String annee,
|
|
|
58 |
String mois, String jour, String lieudit, String rechercheLibre,
|
|
|
59 |
int debut, int longueur) {
|
2 |
aperonnet |
60 |
|
5 |
aperonnet |
61 |
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant
|
|
|
62 |
+ "/" + identifiantLocalite + "/"
|
|
|
63 |
+ URL.encodeComponent(localite) + "/" + annee + "/" + mois
|
|
|
64 |
+ "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/"
|
|
|
65 |
+ URL.encodeComponent(lieudit) + "/" + debut + "/" + longueur,
|
2 |
aperonnet |
66 |
|
5 |
aperonnet |
67 |
new ResponseTextHandler() {
|
2 |
aperonnet |
68 |
|
5 |
aperonnet |
69 |
public void onCompletion(String str) {
|
|
|
70 |
|
|
|
71 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
72 |
JSONArray jsonArray;
|
|
|
73 |
JSONArray jsonArrayNested;
|
|
|
74 |
|
|
|
75 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
76 |
|
2 |
aperonnet |
77 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
5 |
aperonnet |
78 |
|
|
|
79 |
int arraySize = jsonArray.size();
|
|
|
80 |
|
|
|
81 |
Observation[] listeObservation = new Observation[arraySize];
|
|
|
82 |
|
|
|
83 |
for (int i = 0; i < arraySize; i++) {
|
|
|
84 |
|
|
|
85 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
86 |
|
|
|
87 |
String transmis = ((JSONString) jsonArrayNested
|
|
|
88 |
.get(13)).stringValue();
|
|
|
89 |
String nomSaisi = Util
|
|
|
90 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
91 |
.get(0)).toString());
|
|
|
92 |
String nomRetenu = Util
|
|
|
93 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
94 |
.get(2)).toString());
|
|
|
95 |
String numeroNomenclatural = ((JSONString) jsonArrayNested
|
|
|
96 |
.get(3)).stringValue();
|
|
|
97 |
String numeroTaxonomique = ((JSONString) jsonArrayNested
|
|
|
98 |
.get(4)).stringValue();
|
|
|
99 |
String famille = Util
|
|
|
100 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
101 |
.get(5)).toString());
|
|
|
102 |
String localite = Util
|
|
|
103 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
104 |
.get(6)).toString());
|
|
|
105 |
String lieudit = Util
|
|
|
106 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
107 |
.get(9)).toString());
|
|
|
108 |
String station = Util
|
|
|
109 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
110 |
.get(10)).toString());
|
|
|
111 |
String milieu = Util
|
|
|
112 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
113 |
.get(11)).toString());
|
|
|
114 |
String commentaire = Util
|
|
|
115 |
.toCelString(((JSONString) jsonArrayNested
|
|
|
116 |
.get(12)).toString());
|
|
|
117 |
String date = ((JSONString) jsonArrayNested
|
|
|
118 |
.get(8)).stringValue();
|
|
|
119 |
String numeroOrdre = ((JSONString) jsonArrayNested
|
|
|
120 |
.get(7)).stringValue();
|
|
|
121 |
|
|
|
122 |
listeObservation[i] = new Observation(transmis,
|
|
|
123 |
nomSaisi, nomRetenu,
|
|
|
124 |
numeroNomenclatural, numeroTaxonomique,
|
|
|
125 |
famille, localite, lieudit, station,
|
|
|
126 |
milieu, commentaire, date, numeroOrdre);
|
2 |
aperonnet |
127 |
}
|
5 |
aperonnet |
128 |
}
|
|
|
129 |
retour.onRetour(new Observation(listeObservation));
|
|
|
130 |
|
2 |
aperonnet |
131 |
}
|
5 |
aperonnet |
132 |
|
2 |
aperonnet |
133 |
}
|
5 |
aperonnet |
134 |
}
|
2 |
aperonnet |
135 |
|
5 |
aperonnet |
136 |
});
|
2 |
aperonnet |
137 |
|
5 |
aperonnet |
138 |
}
|
2 |
aperonnet |
139 |
|
|
|
140 |
}
|