Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 10 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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