Subversion Repositories eFlore/Applications.cel

Rev

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

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