Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2557 → Rev 2558

/trunk/src/org/tela_botanica/client/modeles/dao/InformationCommuneDAO.java
20,6 → 20,10
 
private final String NOM_SERVICE = "CoordSearch";
private final String CODE_PAYS = "FR";
// Ce DAO peut être fréquemment sollicité lors de l'utilisation de la carte
// et peut empiler beaucoup de longues requête, ceci permet donc de les annuler facilement
private static Request requeteEnCours = null;
 
Rafraichissable r = null;
 
28,7 → 32,9
}
 
public void obtenirCommunePlusProche(final Rafraichissable r, final double lng,
final double lat) {
final double lat) {
annulerRequeteEnCours();
 
String adresseAppel = Configuration.getServiceBaseUrl() + "/"
+ NOM_SERVICE + "/" + URL.encode("" + lat) + "/"
36,11 → 42,12
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, adresseAppel);
 
try {
rb.sendRequest(null, new RequestCallback() {
requeteEnCours = rb.sendRequest(null, new RequestCallback() {
 
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
requeteEnCours = null;
}
 
@Override
50,6 → 57,7
EntiteGeographiqueObservation infos;
String idLocalite = "";
String nomCommune = "";
String pays = "";
 
if (response.getStatusCode() == Response.SC_BAD_REQUEST) {
Window.alert("Requete mal formée");
75,9 → 83,13
nomCommune = objectRetour.get("nom").isString().stringValue();
}
if(objectRetour.get("code_insee").isString() != null) {
idLocalite = objectRetour.get("code_insee").isString().stringValue().substring(0, 2);
if(objectRetour.get("code_zone").isString() != null) {
idLocalite = objectRetour.get("code_zone").isString().stringValue().substring(0, 2);
}
if(objectRetour.get("code_pays").isString() != null) {
pays = objectRetour.get("code_pays").isString().stringValue();
}
}
}
84,6 → 96,7
infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
infos.setLat(""+lat);
infos.setLon(""+lng);
infos.setPays(pays);
 
r.rafraichir(infos, false);
}
94,11 → 107,13
}
 
public void obtenirInfosCommune(final Rafraichissable r,
String valeurCommune, String codePostal) {
String valeurCommune, String codeLoc) {
codePostal = codePostal.replaceAll("000null", "*");
codePostal = codePostal.replaceAll("\"", "");
annulerRequeteEnCours();
codeLoc = codeLoc.replaceAll("000null", "*");
codeLoc = codeLoc.replaceAll("\"", "");
valeurCommune = valeurCommune.split(" \\([0-9][0-9]\\)")[0];
valeurCommune = valeurCommune.replaceAll("000null", "*");
valeurCommune = valeurCommune.replaceAll("\"", "");
105,13 → 120,23
String adresseAppel = Configuration.getServiceBaseUrl() + "/"
+ NOM_SERVICE + "/*/*/" + URL.encode(valeurCommune) + "/"
+ URL.encode(codePostal) + "/"
+ URL.encode(CODE_PAYS);
+ NOM_SERVICE + "/*/*/" + URL.encode(valeurCommune) + "/";
if(!codeLoc.trim().isEmpty()) {
// Cas du code de département ou postal
if(Util.estUnNombre(codeLoc)) {
adresseAppel += URL.encode(codeLoc)+"/"+URL.encode(CODE_PAYS);
} else {
//cas du code pays
adresseAppel += "*/"+URL.encode(codeLoc);
}
}
 
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, adresseAppel);
 
try {
rb.sendRequest(null, new RequestCallback() {
requeteEnCours = rb.sendRequest(null, new RequestCallback() {
 
@Override
public void onError(Request request, Throwable exception) {
137,13 → 162,15
JSONObject objectRetour = responseValue.isObject();
String nomCommune = Util.getValeurJsonOuVide(objectRetour, "nom");
String idLocalite = Util.getValeurJsonOuVide(objectRetour, "code_insee");
String idLocalite = Util.getValeurJsonOuVide(objectRetour, "code_zone");
lat = Util.jsonNonNull(objectRetour,"lat") ? objectRetour.get("lat").isNumber().doubleValue(): 0.0;
lng = Util.jsonNonNull(objectRetour,"lng") ? objectRetour.get("lng").isNumber().doubleValue(): 0.0;
String pays = Util.getValeurJsonOuVide(objectRetour, "code_pays");
infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
infos.setLat(""+lat);
infos.setLon(""+lng);
infos.setPays(pays);
r.rafraichir(infos, false);
} else {
164,4 → 191,11
Window.alert(e.getMessage());
}
}
public static void annulerRequeteEnCours() {
if(requeteEnCours != null) {
requeteEnCours.cancel();
requeteEnCours = null;
}
}
}
/trunk/src/org/tela_botanica/client/modeles/objets/EntiteGeographiqueObservation.java
14,6 → 14,7
private String station=null;
private String lat=null;
private String lon=null;
private String pays=null;
private int zoom = 0; // si zoom <= 0, on l'ignore lors du rafraîchissement
 
public EntiteGeographiqueObservation() {
35,6 → 36,14
this.lieuDit = lieuDit;
this.station = station;
}
public void setPays(String pays) {
this.pays = pays;
}
public String getPays() {
return pays;
}
 
public void setLat(String la) {
lat = la;