Rev 2033 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.modeles.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.ListeChampsEtendus;
import org.tela_botanica.client.modeles.objets.ListeGroupesChampsEtendus;
import org.tela_botanica.client.modeles.objets.ListeReferentielPerso;
import org.tela_botanica.client.observation.ObservationModele;
import com.google.gwt.http.client.Request;
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
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.http.client.URL;
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.JSONValue;
public class ListeReferentielChampsEtendusDAO {
/**
* Cache
*
*/
private HashMap<String,ListeReferentielPerso> cache = new HashMap();
public ListeReferentielChampsEtendusDAO(ObservationModele obs) {
}
public void obtenirListeNomsChampsEtendus(final Rafraichissable r, String recherche) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/NomsChampsEtendus/cle"+
"?recherche="+URL.encode(recherche));
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
ListeChampsEtendus labelCles = new ListeChampsEtendus(response.getText());
r.rafraichir(labelCles, true);
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
public void obtenirListeValeursChampEtendu(final Rafraichissable r, String cle, String recherche) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/NomsChampsEtendus/valeur"+
"?cle="+URL.encode(cle)+"&recherche="+URL.encode(recherche));
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
ArrayList<String> valeurs = new ArrayList<String>();
final JSONValue responseValue = JSONParser.parse(response.getText());
JSONArray reponse = null;
if ((reponse = responseValue.isArray()) != null) {
for(int i = 0; i < reponse.size(); i++) {
valeurs.add(reponse.get(i).isString().stringValue());
}
}
r.rafraichir(valeurs, true);
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
public void obtenirGroupesChampsEtendus(final Rafraichissable r) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/GroupesChampsEtendus/");
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
ListeGroupesChampsEtendus valeurs = new ListeGroupesChampsEtendus(response.getText());
r.rafraichir(valeurs, true);
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
}