Subversion Repositories eFlore/Applications.cel

Rev

Rev 2558 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2558 Rev 2568
Line 14... Line 14...
14
import com.google.gwt.json.client.JSONObject;
14
import com.google.gwt.json.client.JSONObject;
15
import com.google.gwt.json.client.JSONParser;
15
import com.google.gwt.json.client.JSONParser;
16
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.json.client.JSONValue;
17
import com.google.gwt.user.client.Window;
17
import com.google.gwt.user.client.Window;
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
public class InformationCommuneDAO {
19
public class InformationLocaliteDAO {
20
 
20
 
Line 21... Line 21...
21
	private final String NOM_SERVICE = "CoordSearch";
21
	private final String NOM_SERVICE = "CoordSearch";
22
	private final String CODE_PAYS = "FR";
22
	private final String CODE_PAYS = "FR";
23
	
23
	
Line 24... Line 24...
24
	// Ce DAO peut être fréquemment sollicité lors de l'utilisation de la carte
24
	// Ce DAO peut être fréquemment sollicité lors de l'utilisation de la carte
Line 25... Line 25...
25
	// et peut empiler beaucoup de longues requête, ceci permet donc de les annuler facilement
25
	// et peut empiler beaucoup de longues requête, ceci permet donc de les annuler facilement
26
	private static Request requeteEnCours = null;
26
	private static Request requeteEnCours = null;
27
 
27
 
Line 28... Line 28...
28
	Rafraichissable r = null;
28
	Rafraichissable r = null;
29
 
29
 
Line 30... Line 30...
30
	public InformationCommuneDAO(Rafraichissable r) {
30
	public InformationLocaliteDAO(Rafraichissable r) {
Line 31... Line 31...
31
		this.r = r;
31
		this.r = r;
32
	}
32
	}
33
 
-
 
34
	public void obtenirCommunePlusProche(final Rafraichissable r, final double lng,
33
 
Line 35... Line 34...
35
			final double lat) {	
34
	public void obtenirLocalitePlusProche(final Rafraichissable r, final double lng,
36
		
35
			final double lat) {	
Line 54... Line 53...
54
				public void onResponseReceived(Request request,
53
				public void onResponseReceived(Request request,
55
						Response response) {
54
						Response response) {
Line 56... Line 55...
56
					
55
					
57
					EntiteGeographiqueObservation infos;
56
					EntiteGeographiqueObservation infos;
58
					String idLocalite = "";
57
					String idLocalite = "";
59
					String nomCommune = "";
58
					String nomLocalite = "";
Line 60... Line 59...
60
					String pays = "";
59
					String pays = "";
61
 
60
 
62
					if (response.getStatusCode() == Response.SC_BAD_REQUEST) {
61
					if (response.getStatusCode() == Response.SC_BAD_REQUEST) {
Line 63... Line 62...
63
						Window.alert("Requete mal formée");
62
						Window.alert("Requete mal formée");
Line 64... Line 63...
64
					} else {
63
					} else {
65
						
64
						
66
						if(response.getText().equals("")) {
65
						if(response.getText().equals("")) {
Line 67... Line 66...
67
 
66
 
68
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
67
							infos = new EntiteGeographiqueObservation(idLocalite, nomLocalite, null, null);
Line 78... Line 77...
78
						if (responseValue.isObject() != null) {
77
						if (responseValue.isObject() != null) {
Line 79... Line 78...
79
							
78
							
Line 80... Line 79...
80
							JSONObject objectRetour = responseValue.isObject();
79
							JSONObject objectRetour = responseValue.isObject();
81
							
80
							
82
							if(objectRetour.get("nom").isString() != null) {
81
							if(objectRetour.get("nom").isString() != null) {
Line 83... Line 82...
83
								nomCommune = objectRetour.get("nom").isString().stringValue();
82
								nomLocalite = objectRetour.get("nom").isString().stringValue();
84
							}
83
							}
85
							
84
							
Line 91... Line 90...
91
								pays = objectRetour.get("code_pays").isString().stringValue();
90
								pays = objectRetour.get("code_pays").isString().stringValue();
92
							}
91
							}
93
						}
92
						}
94
					}
93
					}
Line 95... Line 94...
95
					
94
					
96
					infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
95
					infos = new EntiteGeographiqueObservation(idLocalite, nomLocalite, null, null);
97
					infos.setLat(""+lat);
96
					infos.setLat(""+lat);
98
					infos.setLon(""+lng);
97
					infos.setLon(""+lng);
Line 99... Line 98...
99
					infos.setPays(pays);
98
					infos.setPays(pays);
Line 104... Line 103...
104
		} catch (RequestException e) {
103
		} catch (RequestException e) {
105
			Window.alert(e.getMessage());
104
			Window.alert(e.getMessage());
106
		}
105
		}
107
	}
106
	}
Line 108... Line 107...
108
 
107
 
109
	public void obtenirInfosCommune(final Rafraichissable r,
108
	public void obtenirInfosLocalite(final Rafraichissable r,
Line 110... Line 109...
110
			String valeurCommune, String codeLoc) {
109
			String valeurLocalite, String codeLoc) {
Line 111... Line 110...
111
		
110
		
112
		annulerRequeteEnCours();
111
		annulerRequeteEnCours();
Line 113... Line 112...
113
		
112
		
114
		codeLoc = codeLoc.replaceAll("000null", "*");
113
		codeLoc = codeLoc.replaceAll("000null", "*");
115
		codeLoc = codeLoc.replaceAll("\"", "");
114
		codeLoc = codeLoc.replaceAll("\"", "");
Line 116... Line 115...
116
		
115
		
117
		valeurCommune = valeurCommune.split(" \\([0-9][0-9]\\)")[0];
116
		valeurLocalite = valeurLocalite.split(" \\([0-9][0-9]\\)")[0];
Line 118... Line 117...
118
		valeurCommune = valeurCommune.replaceAll("000null", "*");
117
		valeurLocalite = valeurLocalite.replaceAll("000null", "*");
119
		valeurCommune = valeurCommune.replaceAll("\"", "");
118
		valeurLocalite = valeurLocalite.replaceAll("\"", "");
120
		
119
		
121
		
120
		
122
		String adresseAppel = Configuration.getServiceBaseUrl() + "/"
121
		String adresseAppel = Configuration.getServiceBaseUrl() + "/"
123
				+ NOM_SERVICE + "/*/*/" + URL.encode(valeurCommune) + "/";
122
				+ NOM_SERVICE+"?zone="+ URL.encode(valeurLocalite);
124
		
123
		
125
		if(!codeLoc.trim().isEmpty()) {
124
		if(!codeLoc.trim().isEmpty()) {
Line 126... Line 125...
126
			// Cas du code de département ou postal
125
			// Cas du code de département ou postal
Line 127... Line 126...
127
			if(Util.estUnNombre(codeLoc)) {
126
			if(Util.estUnNombre(codeLoc)) {
Line 159... Line 158...
159
							Double lng = 0.0;
158
							Double lng = 0.0;
160
							Double lat = 0.0;
159
							Double lat = 0.0;
Line 161... Line 160...
161
								
160
								
Line 162... Line 161...
162
							JSONObject objectRetour = responseValue.isObject();
161
							JSONObject objectRetour = responseValue.isObject();
163
							
162
							
164
							String nomCommune = Util.getValeurJsonOuVide(objectRetour, "nom");
163
							String nomLocalite = Util.getValeurJsonOuVide(objectRetour, "nom");
165
							String idLocalite = Util.getValeurJsonOuVide(objectRetour, "code_zone");
164
							String idLocalite = Util.getValeurJsonOuVide(objectRetour, "code_zone");
166
							lat = Util.jsonNonNull(objectRetour,"lat") ? objectRetour.get("lat").isNumber().doubleValue(): 0.0;
165
							lat = Util.jsonNonNull(objectRetour,"lat") ? objectRetour.get("lat").isNumber().doubleValue(): 0.0;
Line 167... Line 166...
167
							lng = Util.jsonNonNull(objectRetour,"lng") ? objectRetour.get("lng").isNumber().doubleValue(): 0.0;
166
							lng = Util.jsonNonNull(objectRetour,"lng") ? objectRetour.get("lng").isNumber().doubleValue(): 0.0;
168
							String pays = Util.getValeurJsonOuVide(objectRetour, "code_pays");
167
							String pays = Util.getValeurJsonOuVide(objectRetour, "code_pays");
169
							
168
							
170
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
169
							infos = new EntiteGeographiqueObservation(idLocalite, nomLocalite, null, null);
Line 171... Line 170...
171
							infos.setLat(""+lat);
170
							infos.setLat(""+lat);
172
							infos.setLon(""+lng);
171
							infos.setLon(""+lng);
173
							infos.setPays(pays);
172
							infos.setPays(pays);
174
							
173
							
175
							r.rafraichir(infos, false);
174
							r.rafraichir(infos, false);
Line 176... Line 175...
176
						} else {
175
						} else {
177
							EntiteGeographiqueObservation infos;
176
							EntiteGeographiqueObservation infos;
178
							String idLocalite = "";
177
							String idLocalite = "";
Line 179... Line 178...
179
							String nomCommune = "";
178
							String nomLocalite = "";
180
 
179