Subversion Repositories eFlore/Archives.cel-v2

Rev

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