Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 258 Rev 266
Line 49... Line 49...
49
					} else {
49
					} else {
50
						final JSONValue responseValue = JSONParser
50
						final JSONValue responseValue = JSONParser
51
								.parse(response.getText());
51
								.parse(response.getText());
Line 52... Line 52...
52
 
52
 
-
 
53
						if (responseValue.isObject() != null) {
-
 
54
							EntiteGeographiqueObservation infos;
-
 
55
							String idLocalite = "";
-
 
56
							String nomCommune = "";
53
						if (responseValue.isObject() != null) {
57
							
-
 
58
							JSONObject resultat = responseValue.isObject();
-
 
59
							if(resultat != null && resultat.containsKey("geonames")) {
54
							JSONObject resultat = responseValue.isObject();
60
								if(resultat.get("geonames").isArray() != null) {
55
							JSONArray tableauCommune = resultat.get("geonames")
61
									JSONArray tableauCommune = resultat.get("geonames")
-
 
62
									.isArray();
-
 
63
									if(tableauCommune.get(0) != null) {
56
									.isArray();
64
										if(tableauCommune.get(0).isObject() != null) {
57
							JSONObject objetCommune = tableauCommune.get(0)
65
											JSONObject objetCommune = tableauCommune.get(0)
58
									.isObject();
66
											.isObject();
59
 
67
											
60
							/*String valeurCommune = objetCommune.get("name")
68
											if(objetCommune.containsKey("name")) {
61
									.isString().stringValue();
69
												if(objetCommune.get("name").isString() != null)  {
62
							r.rafraichir(valeurCommune, false);*/
-
 
63
							
70
													nomCommune = objetCommune.get(
64
							String pays = objetCommune.get("countryName").isString()
71
													"name").isString().stringValue();
-
 
72
												}
65
							.stringValue();
73
											}
66
							
74
											
67
							if(!pays.equals("France")){
75
											if(objetCommune.containsKey("adminCode2")) {
-
 
76
												if(objetCommune.get("adminCode2").isString() != null)  {
-
 
77
													idLocalite = objetCommune.get(
68
								r.rafraichir("Aucune commune française n'a été trouvée à cet emplacement", false);
78
													"adminCode2").isString().stringValue();
-
 
79
												}
-
 
80
											}
-
 
81
										}
-
 
82
									}
69
								return;
83
								}
70
							}
-
 
71
								
-
 
72
							Double newLng = objetCommune.get("lng").isNumber()
-
 
73
							.doubleValue();
-
 
74
							Double newLat = objetCommune.get("lat").isNumber()
-
 
75
									.doubleValue();
-
 
76
							String nomCommune = objetCommune.get(
-
 
Line 77... Line 84...
77
									"name").isString().stringValue();
84
							}
78
							
85
							
79
							String idLocalite = objetCommune.get(
-
 
80
							"adminCode2").isString().stringValue();
86
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
Line 81... Line 87...
81
		
87
							infos.setLat(""+lat);
82
							Object[] infos = { lat, lng, idLocalite, nomCommune, newLat, newLng};
88
							infos.setLon(""+lng);
83
		
89
		
84
							r.rafraichir(infos, false);
90
							r.rafraichir(infos, false);
Line 123... Line 129...
123
					} else {
129
					} else {
124
						final JSONValue responseValue = JSONParser
130
						final JSONValue responseValue = JSONParser
125
								.parse(response.getText());
131
								.parse(response.getText());
Line 126... Line 132...
126
 
132
 
-
 
133
						if (responseValue.isObject() != null) {
-
 
134
							
-
 
135
							EntiteGeographiqueObservation infos;
-
 
136
							String idLocalite = "";
-
 
137
							String nomCommune = "";
-
 
138
							Double lng = 0.0;
Line 127... Line 139...
127
						if (responseValue.isObject() != null) {
139
							Double lat = 0.0;
-
 
140
 
-
 
141
							JSONObject resultat = responseValue.isObject();
-
 
142
							
128
 
143
							if(resultat != null && resultat.containsKey("postalCodes")) {
129
							JSONObject resultat = responseValue.isObject();
144
								if(resultat.get("postalCodes").isArray() != null) {
130
							JSONArray tableauCommune = resultat.get(
-
 
131
									"postalCodes").isArray();
145
									JSONArray tableauCommune = resultat.get("postalCodes")
-
 
146
									.isArray();
132
 
147
									if(tableauCommune.get(0) != null) {
133
							if (tableauCommune.get(0) != null) {
148
										if(tableauCommune.get(0).isObject() != null) {
134
								JSONObject objetCommune = tableauCommune.get(0)
149
											JSONObject objetCommune = tableauCommune.get(0)
-
 
150
											.isObject();
135
										.isObject();
151
											
-
 
152
											if(objetCommune.containsKey("lng")) {
136
 
153
												if(objetCommune.get("lng").isNumber() != null)  {
-
 
154
													lng = objetCommune.get(
-
 
155
													"lng").isNumber().doubleValue();
-
 
156
												}
137
								Double lng = objetCommune.get("lng").isNumber()
157
											}
138
										.doubleValue();
158
											
139
								Double lat = objetCommune.get("lat").isNumber()
159
											if(objetCommune.containsKey("lat")) {
140
										.doubleValue();
160
												if(objetCommune.get("lat").isNumber() != null)  {
-
 
161
													lat = objetCommune.get(
-
 
162
													"lat").isNumber().doubleValue();
141
								String nomCommune = objetCommune.get(
163
												}
-
 
164
											}
-
 
165
											
142
										"placeName").isString().stringValue();
166
											if(objetCommune.containsKey("adminCode2")) {
143
								
167
												if(objetCommune.get("adminCode2").isString() != null)  {
-
 
168
													idLocalite = objetCommune.get(
-
 
169
													"adminCode2").isString().stringValue();
144
								String idLocalite = objetCommune.get(
170
												}
-
 
171
											}
-
 
172
											
145
								"adminCode2").isString().stringValue();
173
											if(objetCommune.containsKey("placeName")) {
146
 
-
 
147
								Object[] infos = { lat, lng, idLocalite, nomCommune};
-
 
148
 
174
												if(objetCommune.get("placeName").isString() != null)  {
-
 
175
													nomCommune = objetCommune.get(
-
 
176
													"placeName").isString().stringValue();
-
 
177
												}
-
 
178
											}
-
 
179
										}
149
 
180
									}
-
 
181
								}
-
 
182
							}
-
 
183
							
-
 
184
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
-
 
185
							infos.setLat(""+lat);
-
 
186
							infos.setLon(""+lng);
150
								r.rafraichir(infos, false);
187
		
151
							}
188
							r.rafraichir(infos, false);
152
						}
189
						}
153
					}
190
					}
154
				}
191
				}