76,73 → 76,71 |
} |
|
else { |
|
|
|
|
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/LocationSearch/" + URL.encodeComponent(critere)); |
|
try { |
|
rb.sendRequest(null, new RequestCallback() { |
|
@Override |
public void onError(final Request request, final Throwable exception) { |
// TODO Auto-generated method stub |
|
} |
|
@Override |
public void onResponseReceived(final Request request, |
final Response response) { |
|
final ListeReferentielCommune referentielCommuneData; |
final JSONValue responseValue = JSONParser.parse(response.getText()); |
JSONArray reponse = null; |
|
// si c'est un tableau |
if ((reponse = responseValue.isArray()) != null) { |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/LocationSearch/" + URL.encodeComponent(critere)); |
try { |
|
rb.sendRequest(null, new RequestCallback() { |
|
@Override |
public void onError(final Request request, final Throwable exception) { |
// TODO Auto-generated method stub |
|
JSONArray communes; |
final int taillemax = reponse.size(); |
} |
|
@Override |
public void onResponseReceived(final Request request, |
final Response response) { |
|
referentielCommuneData = new ListeReferentielCommune(taillemax); |
final ListeReferentielCommune referentielCommuneData; |
final JSONValue responseValue = JSONParser.parse(response.getText()); |
JSONArray reponse = null; |
|
// si c'est un tableau |
if ((reponse = responseValue.isArray()) != null) { |
|
JSONArray communes; |
final int taillemax = reponse.size(); |
|
referentielCommuneData = new ListeReferentielCommune(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); |
} |
} |
} else { |
referentielCommuneData = new ListeReferentielCommune(0); |
} |
addToCache(critere, referentielCommuneData); |
r.rafraichir(referentielCommuneData, true); |
|
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); |
} |
} |
} else { |
referentielCommuneData = new ListeReferentielCommune(0); |
} |
addToCache(critere, referentielCommuneData); |
r.rafraichir(referentielCommuneData, true); |
} |
|
} |
}); |
|
}); |
|
} catch (RequestException e) { |
|
e.printStackTrace(); |
} |
|
} catch (RequestException e) { |
e.printStackTrace(); |
} |
} // Fin else si pas de cache |
|
} |
|
private void addToCache(String query, ListeReferentielCommune result) { |
cache.put(query.toLowerCase(),result); |
} |
/** |
* Fonction à implémenter dans le futur, lors de l'utilisation de plusieurs |
* référentiels de localité |
*/ |
@Override |
public void obtenirListeDonnees(Rafraichissable r, String referentiel, String critere) { |
// TODO Auto-generated method stub |
} |
|
private void addToCache(String query, ListeReferentielCommune result) { |
cache.put(query.toLowerCase(),result); |
} |
|
private ListeReferentielCommune getFromCache (String query) { |
return cache.get(query.toLowerCase()); |
} |
|
|
|
private ListeReferentielCommune getFromCache (String query) { |
return cache.get(query.toLowerCase()); |
} |
} |