New file |
0,0 → 1,121 |
package org.tela_botanica.client.modeles; |
|
import org.tela_botanica.client.Util; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.observation.ObservationModele; |
|
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
|
/** |
* DAO la liste des observations attachées a un observateur |
* @author David Delon |
* |
*/ |
public class ListeObservationAsynchroneDAO { |
|
|
|
|
/** |
* Le modèle associé au DAO |
*/ |
private ObservationModele observationModele = null ; |
|
public ListeObservationAsynchroneDAO(ObservationModele observationModele) |
{ |
|
this.observationModele=observationModele; |
} |
|
|
/** |
* Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant |
* à des critères données en paramètres |
* @param r le rafraichissable qui demande la mise à jour |
* @param criteres un tableau nom/valeur des critères pour les observations |
*/ |
public void obtenirListeObservation(final Rafraichissable r, String utilisateur, String[][] criteres) |
{ |
|
|
String requete = "" ; |
|
if(criteres != null) |
{ |
// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...) |
// ils contiennent limite et taille page |
|
for (int i = 0; i < criteres.length; i++) { |
|
if(!criteres[i][1].equals("")) |
{ |
if(i!= 0) |
{ |
requete += "&"; |
} |
requete += criteres[i][0]+"="+criteres[i][1] ; |
} |
} |
} |
|
|
|
// on envoie le get asynchrone |
HTTPRequest.asyncGet(observationModele.getConfig().getServiceBaseUrl()+"/InventoryObservationList/"+utilisateur+"/"+requete, new ResponseTextHandler() { |
|
|
// si tout se passe bien on reçoit une réponse JSON |
public void onCompletion(String responseText) { |
|
final ListeObservation observationData ; |
final JSONValue responseValue = JSONParser.parse(responseText); |
|
JSONArray reponse=null; |
|
// si c'est un tableau |
if ((reponse=responseValue.isArray()) != null) { |
|
JSONArray observation; |
final int taillemax = reponse.size(); |
|
observationData = new ListeObservation(taillemax); |
|
for (int i = 0; i < taillemax; i++) { |
|
if ((observation=reponse.get(i).isArray()) != null) { |
|
String transmis=((JSONString) observation.get(13)).stringValue(); |
String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString()); |
String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString()); |
String numeroNomenclatural=((JSONString) observation.get(3)).stringValue(); |
String numeroTaxonomique=((JSONString) observation.get(4)).stringValue(); |
String famille=Util.toCelString(((JSONString) observation .get(5)).toString()); |
String localite=Util.toCelString(((JSONString) observation .get(6)).toString()); |
String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString()); |
String station=Util.toCelString(((JSONString) observation .get(10)).toString()); |
String milieu=Util.toCelString(((JSONString) observation .get(11)).toString()); |
String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString()); |
String date=((JSONString) observation .get(8)).stringValue(); |
String numeroOrdre=((JSONString) observation.get(7)).stringValue(); |
|
Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclatural, numeroTaxonomique, famille, localite, lieudit, station, milieu, commentaire, date, numeroOrdre); |
|
observationData.put(obs.getNumeroOrdre(),obs); |
} |
|
} |
|
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est |
// le premier à les recevoir |
r.rafraichir(observationData,true); |
} |
} |
}); |
} |
|
} |