Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 772 → Rev 773

/trunk/src/org/tela_botanica/client/modeles/ValeurListeAsyncDao.java
2,18 → 2,13
 
import java.util.HashMap;
 
import org.tela_botanica.client.http.JsonRestRequestBuilder;
import org.tela_botanica.client.http.JsonRestRequestCallback;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.util.UtilDAO;
 
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
 
23,72 → 18,40
private static final String SERVICE_NOM = "CoelValeurListe";
private Rafraichissable vueARafraichir = null;
public ValeurListeAsyncDao() {
// TODO Auto-generated constructor stub
}
public ValeurListeAsyncDao(Rafraichissable vueCourante) {
vueARafraichir = vueCourante;
}
public void obtenirListe(Integer cle) {
selectionner("id", cle, "*", "*");
selectionner("id", cle, null, null);
}
public void selectionner(String type, final Integer cleParent, String abv, String idValeur) {
if (ontologieCache.containsKey(cleParent)) {
if (ontologieCache.containsKey(cleParent)) {
vueARafraichir.rafraichir(ontologieCache.get(cleParent));
} else {
// Ajout des paramètres et données à selectionner dans l'URL
String[] parametres = new String[4];
parametres[0] = type;
parametres[1] = cleParent.toString();
parametres[2] = "*";
if (!type.equals("id")) {
parametres[2] = abv;
}
parametres[3] = idValeur;
RequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
try {
rb.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
public void onResponseReceived(Request request, Response response) {
final JSONValue responseValue = JSONParser.parse(response.getText());
// Si la requête est un succès, reception d'un tableau
if (responseValue.isObject() != null) {
try {
final JSONObject reponse = responseValue.isObject();
JSONString listeId = reponse.get("id").isString();
JSONArray listeValeurs = reponse.get("valeurs").isArray();
if (listeId != null) {
// Transformation du tableau JSON réponse en Liste
ValeurListe liste = new ValeurListe(listeId, listeValeurs);
// Stockage en cache
ontologieCache.put(cleParent, liste);
// et on met à jour le demandeur des données
vueARafraichir.rafraichir(liste);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
String paramAbv = (type.equals("id") ? null : abv);
String[] parametres = {type, cleParent.toString(), paramAbv, idValeur};
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue.isObject() != null) {
final JSONObject reponse = responseValue.isObject();
JSONString listeId = reponse.get("id").isString();
JSONArray listeValeurs = reponse.get("valeurs").isArray();
if (listeId != null) {
// Transformation du tableau JSON réponse en Liste
ValeurListe liste = new ValeurListe(listeId, listeValeurs);
// Stockage en cache
ontologieCache.put(cleParent, liste);
// et on met à jour le demandeur des données
vueARafraichir.rafraichir(liste);
}
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
});
}
}
}
}