Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1918 → Rev 2568

/trunk/src/org/tela_botanica/client/modeles/dao/ListeReferentielLocaliteAsynchroneDAO.java/ListeReferentielCommuneAsynchroneDAO.java
5,8 → 5,8
import org.tela_botanica.client.interfaces.FournisseurListe;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.ListeReferentielCommune;
import org.tela_botanica.client.modeles.objets.ReferentielCommune;
import org.tela_botanica.client.modeles.objets.ListeReferentielLocalite;
import org.tela_botanica.client.modeles.objets.ReferentielLocalite;
import org.tela_botanica.client.observation.ObservationModele;
 
import com.google.gwt.http.client.Request;
21,11 → 21,11
import com.google.gwt.json.client.JSONValue;
 
/**
* DAO la liste des communes. Utilisation d'un cache pour eviter les requetes inutiles
* DAO la liste des localites. Utilisation d'un cache pour eviter les requetes inutiles
* @author David Delon
*
*/
public class ListeReferentielCommuneAsynchroneDAO implements FournisseurListe {
public class ListeReferentielLocaliteAsynchroneDAO implements FournisseurListe {
 
41,7 → 41,7
*
*/
private HashMap<String,ListeReferentielCommune> cache = new HashMap();
private HashMap<String,ListeReferentielLocalite> cache = new HashMap();
50,13 → 50,13
* @param obs : Modele
*/
public ListeReferentielCommuneAsynchroneDAO(final ObservationModele obs) {
public ListeReferentielLocaliteAsynchroneDAO(final ObservationModele obs) {
this.observationModele = obs;
}
/**
* Envoie une requete au serveur jrest pour obtenir les communes correspondant
* Envoie une requete au serveur jrest pour obtenir les localites correspondant
* à des critères données en paramètres.
* @param r le rafraichissable qui demande la mise à jour
* @param critere un string contenant le terme a rechercher
67,12 → 67,12
public final void obtenirListeDonnees(final Rafraichissable r, final String critere) {
ListeReferentielCommune referentielCommuneDataFromCache=null;
ListeReferentielLocalite referentielLocaliteDataFromCache=null;
// En cache ?
if ((referentielCommuneDataFromCache=getFromCache(critere))!=null) {
r.rafraichir(referentielCommuneDataFromCache,true);
if ((referentielLocaliteDataFromCache=getFromCache(critere))!=null) {
r.rafraichir(referentielLocaliteDataFromCache,true);
}
else {
91,7 → 91,7
public void onResponseReceived(final Request request,
final Response response) {
final ListeReferentielCommune referentielCommuneData;
final ListeReferentielLocalite referentielLocaliteData;
final JSONValue responseValue = JSONParser.parse(response.getText());
JSONArray reponse = null;
98,24 → 98,24
// si c'est un tableau
if ((reponse = responseValue.isArray()) != null) {
JSONArray communes;
JSONArray localites;
final int taillemax = reponse.size();
referentielCommuneData = new ListeReferentielCommune(taillemax);
referentielLocaliteData = new ListeReferentielLocalite(taillemax);
for (int i = 0; i < taillemax; i++) {
if ((communes = reponse.get(i).isArray()) != null) {
String commune = ((JSONString) communes.get(0)).stringValue();
String departement = ((JSONString) communes.get(1)).stringValue();
ReferentielCommune com = new ReferentielCommune(commune, departement);
referentielCommuneData.put(com.getCommune() + com.getDepartement(), com);
if ((localites = reponse.get(i).isArray()) != null) {
String localite = ((JSONString) localites.get(0)).stringValue();
String departement = ((JSONString) localites.get(1)).stringValue();
ReferentielLocalite com = new ReferentielLocalite(localite, departement);
referentielLocaliteData.put(com.getLocalite() + com.getCodeLocalite(), com);
}
}
} else {
referentielCommuneData = new ListeReferentielCommune(0);
referentielLocaliteData = new ListeReferentielLocalite(0);
}
addToCache(critere, referentielCommuneData);
r.rafraichir(referentielCommuneData, true);
addToCache(critere, referentielLocaliteData);
r.rafraichir(referentielLocaliteData, true);
}
136,11 → 136,11
// TODO Auto-generated method stub
}
private void addToCache(String query, ListeReferentielCommune result) {
private void addToCache(String query, ListeReferentielLocalite result) {
cache.put(query.toLowerCase(),result);
}
 
private ListeReferentielCommune getFromCache (String query) {
private ListeReferentielLocalite getFromCache (String query) {
return cache.get(query.toLowerCase());
}
}