9 |
ddelon |
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 |
|
|
|
9 |
import org.tela_botanica.client.Util;
|
|
|
10 |
import org.tela_botanica.client.interfaces.iRetourObservation;
|
|
|
11 |
|
|
|
12 |
import com.google.gwt.http.client.URL;
|
|
|
13 |
import com.google.gwt.json.client.JSONArray;
|
|
|
14 |
import com.google.gwt.json.client.JSONNumber;
|
|
|
15 |
import com.google.gwt.json.client.JSONParser;
|
|
|
16 |
import com.google.gwt.json.client.JSONString;
|
|
|
17 |
import com.google.gwt.json.client.JSONValue;
|
|
|
18 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
19 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
20 |
|
|
|
21 |
public class ObservationAsynchroneDAO {
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Constructeur
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
public ObservationAsynchroneDAO() {
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
// TODO Classe Filtre pour les parametres ?
|
|
|
37 |
|
|
|
38 |
public void getNombreObservation(String baseURL, final iRetourObservation retour, String identifiant, String identifiantLocalite, String localite, String annee, String mois, String jour, String lieudit, String rechercheLibre) {
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant + "/" + identifiantLocalite + "/" + URL.encodeComponent(localite) + "/" + annee + "/" + mois + "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/" + URL.encodeComponent(lieudit),
|
|
|
42 |
new ResponseTextHandler() {
|
|
|
43 |
|
|
|
44 |
public void onCompletion(String str) {
|
|
|
45 |
|
|
|
46 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
47 |
JSONNumber jsonNumber;
|
|
|
48 |
if ((jsonNumber = jsonValue.isNumber()) != null) {
|
|
|
49 |
retour.onRetour(new Observation((int) jsonNumber.getValue()));
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
});
|
|
|
53 |
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
public void getListeObservation(String baseURL,final iRetourObservation retour, String identifiant, String identifiantLocalite, String localite, String annee, String mois, String jour, String lieudit, String rechercheLibre, int debut, int longueur)
|
|
|
59 |
{
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant + "/" + identifiantLocalite + "/" + URL.encodeComponent(localite) +"/" + annee + "/" + mois + "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/" + URL.encodeComponent(lieudit) + "/"
|
|
|
63 |
+ debut + "/" + longueur ,
|
|
|
64 |
|
|
|
65 |
new ResponseTextHandler() {
|
|
|
66 |
|
|
|
67 |
public void onCompletion(String str) {
|
|
|
68 |
|
|
|
69 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
70 |
JSONArray jsonArray;
|
|
|
71 |
JSONArray jsonArrayNested;
|
|
|
72 |
|
|
|
73 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
74 |
|
|
|
75 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
76 |
|
|
|
77 |
int arraySize = jsonArray.size();
|
|
|
78 |
|
|
|
79 |
Observation[] listeObservation=new Observation[arraySize];
|
|
|
80 |
|
|
|
81 |
for (int i = 0; i < arraySize; i++) {
|
|
|
82 |
|
|
|
83 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
84 |
|
|
|
85 |
String transmis=((JSONString) jsonArrayNested.get(13)).stringValue();
|
|
|
86 |
String nomSaisi=Util.toCelString(((JSONString) jsonArrayNested.get(0)).toString());
|
|
|
87 |
String nomRetenu=Util.toCelString(((JSONString) jsonArrayNested.get(2)).toString());
|
|
|
88 |
String numeroNomenclatural=((JSONString) jsonArrayNested.get(3)).stringValue();
|
|
|
89 |
String numeroTaxonomique=((JSONString) jsonArrayNested.get(4)).stringValue();
|
|
|
90 |
String famille=Util.toCelString(((JSONString) jsonArrayNested .get(5)).toString());
|
|
|
91 |
String localite=Util.toCelString(((JSONString) jsonArrayNested .get(6)).toString());
|
|
|
92 |
String lieudit=Util.toCelString(((JSONString) jsonArrayNested .get(9)).toString());
|
|
|
93 |
String station=Util.toCelString(((JSONString) jsonArrayNested .get(10)).toString());
|
|
|
94 |
String milieu=Util.toCelString(((JSONString) jsonArrayNested .get(11)).toString());
|
|
|
95 |
String commentaire=Util.toCelString(((JSONString) jsonArrayNested .get(12)).toString());
|
|
|
96 |
String date=((JSONString) jsonArrayNested .get(8)).stringValue();
|
|
|
97 |
String numeroOrdre=((JSONString) jsonArrayNested.get(7)).stringValue();
|
|
|
98 |
|
|
|
99 |
listeObservation[i]=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclatural, numeroTaxonomique, famille, localite, lieudit, station, milieu, commentaire, date, numeroOrdre);
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
retour.onRetour(new Observation(listeObservation));
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
});
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
}
|