Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1 → Rev 2

/trunk/src/org/tela_botanica/client/modeles/ObservationAsynchroneDAO.java
New file
0,0 → 1,112
package org.tela_botanica.client.modeles;
 
/**
* Modele DAO, specifique, permettant la validation, l'acces aux donnees distantes et la présentation des donnees en retour
*
*/
 
import org.tela_botanica.client.Util;
import org.tela_botanica.client.interfaces.iRetourObservation;
 
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
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;
 
public class ObservationAsynchroneDAO {
 
/**
* Constructeur
*/
public ObservationAsynchroneDAO() {
}
public void getNombreObservation(String baseURL, final iRetourObservation retour, String identifiant, String identifiantLocalite, String localite, String annee, String mois, String jour, String lieudit, String rechercheLibre) {
 
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant + "/" + identifiantLocalite + "/" + URL.encodeComponent(localite) + "/" + annee + "/" + mois + "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/" + URL.encodeComponent(lieudit),
new ResponseTextHandler() {
 
public void onCompletion(String str) {
 
JSONValue jsonValue = JSONParser.parse(str);
JSONNumber jsonNumber;
if ((jsonNumber = jsonValue.isNumber()) != null) {
retour.onRetour(new Observation((int) jsonNumber.getValue()));
}
}
});
 
}
 
 
 
public void getListeObservation(String baseURL,final iRetourObservation retour, String identifiant, String identifiantLocalite, String localite, String annee, String mois, String jour, String lieudit, String rechercheLibre, int debut, int longueur)
{
 
HTTPRequest.asyncGet(baseURL + "/InventoryItemList/" + identifiant + "/" + identifiantLocalite + "/" + URL.encodeComponent(localite) +"/" + annee + "/" + mois + "/" + jour + "/" + URL.encodeComponent(rechercheLibre) + "/" + URL.encodeComponent(lieudit) + "/"
+ debut + "/" + longueur ,
new ResponseTextHandler() {
public void onCompletion(String str) {
 
JSONValue jsonValue = JSONParser.parse(str);
JSONArray jsonArray;
JSONArray jsonArrayNested;
if ((jsonArray = jsonValue.isArray()) != null) {
if ((jsonArray = jsonValue.isArray()) != null) {
int arraySize = jsonArray.size();
Observation[] listeObservation=new Observation[arraySize];
for (int i = 0; i < arraySize; i++) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
String transmis=((JSONString) jsonArrayNested.get(13)).stringValue();
String nomSaisi=Util.toCelString(((JSONString) jsonArrayNested.get(0)).toString());
String nomRetenu=Util.toCelString(((JSONString) jsonArrayNested.get(2)).toString());
String numeroNomenclatural=((JSONString) jsonArrayNested.get(3)).stringValue();
String numeroTaxonomique=((JSONString) jsonArrayNested.get(4)).stringValue();
String famille=Util.toCelString(((JSONString) jsonArrayNested .get(5)).toString());
String localite=Util.toCelString(((JSONString) jsonArrayNested .get(6)).toString());
String lieudit=Util.toCelString(((JSONString) jsonArrayNested .get(9)).toString());
String station=Util.toCelString(((JSONString) jsonArrayNested .get(10)).toString());
String milieu=Util.toCelString(((JSONString) jsonArrayNested .get(11)).toString());
String commentaire=Util.toCelString(((JSONString) jsonArrayNested .get(12)).toString());
String date=((JSONString) jsonArrayNested .get(8)).stringValue();
String numeroOrdre=((JSONString) jsonArrayNested.get(7)).stringValue();
listeObservation[i]=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclatural, numeroTaxonomique, famille, localite, lieudit, station, milieu, commentaire, date, numeroOrdre);
}
}
retour.onRetour(new Observation(listeObservation));
}
}
}
});
}
 
 
 
 
}