Subversion Repositories eFlore/Archives.cel-v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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