Subversion Repositories eFlore/Applications.cel

Rev

Rev 965 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
989 aurelien 1
package org.tela_botanica.client.modeles.dao;
65 david 2
 
3
import org.tela_botanica.client.interfaces.FournisseurListe;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
989 aurelien 5
import org.tela_botanica.client.modeles.objets.Configuration;
6
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
7
import org.tela_botanica.client.modeles.objets.ListeEntiteGeographiqueObservation;
65 david 8
import org.tela_botanica.client.observation.ObservationModele;
965 aurelien 9
import org.tela_botanica.client.util.Util;
65 david 10
 
965 aurelien 11
import com.google.gwt.core.client.GWT;
65 david 12
import com.google.gwt.http.client.Request;
13
import com.google.gwt.http.client.RequestBuilder;
14
import com.google.gwt.http.client.RequestCallback;
15
import com.google.gwt.http.client.RequestException;
16
import com.google.gwt.http.client.Response;
17
import com.google.gwt.json.client.JSONArray;
965 aurelien 18
import com.google.gwt.json.client.JSONObject;
65 david 19
import com.google.gwt.json.client.JSONParser;
20
import com.google.gwt.json.client.JSONString;
21
import com.google.gwt.json.client.JSONValue;
70 david 22
import com.google.gwt.user.client.Window;
65 david 23
 
24
/**
25
 * DAO la liste des communes.
26
 * @author David Delon
27
 *
28
 */
29
public class ListeEntiteGeographiqueObservationAsynchroneDAO  {
30
 
31
 
32
 
33
	/**
34
	 * Le modèle associé au DAO.
35
	 */
36
	private ObservationModele observationModele = null;
37
 
38
 
39
	/**
40
	 *  Constructeur.
41
	 * @param obs : Modele
42
	 */
43
 
44
	public ListeEntiteGeographiqueObservationAsynchroneDAO(final ObservationModele obs) {
45
		this.observationModele = obs;
46
	}
47
 
48
 
49
	/**
50
	 * Envoie une requete au serveur jrest pour obtenir les communes  correspondant
51
	 * à des critères données en paramètres.
52
	 * @param r le rafraichissable qui demande la mise à jour
53
	 * @param critere un string contenant le terme a rechercher
54
	 */
55
 
56
 
57
	public final void obtenirListeEntitesGeographiques(final Rafraichissable r, final String utilisateur) {
58
 
70 david 59
 
60
 
140 aurelien 61
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/InventoryLocationList/" + utilisateur);
65 david 62
 
70 david 63
 
65 david 64
		try {
65
 
66
			rb.sendRequest(null, new RequestCallback() {
67
 
68
				public void onError(final Request request, final Throwable exception) {
69
					// TODO Auto-generated method stub
70
 
71
				}
72
 
73
				public void onResponseReceived(final Request request,
74
						final Response response) {
75
 
70 david 76
 
65 david 77
					final ListeEntiteGeographiqueObservation listeEntiteGeographiqueObservation;
78
 
79
					final JSONValue responseValue = JSONParser.parse(response.getText());
80
 
81
					JSONArray reponse = null;
82
 
83
 
84
					// si c'est un tableau
85
					if ((reponse = responseValue.isArray()) != null) {
86
 
965 aurelien 87
						JSONObject entites;
65 david 88
						final int taillemax = reponse.size();
89
 
90
						listeEntiteGeographiqueObservation = new ListeEntiteGeographiqueObservation(taillemax);
91
 
92
						for (int i = 0; i < taillemax; i++) {
965 aurelien 93
							if ((entites = reponse.get(i).isObject()) != null) {
65 david 94
 
965 aurelien 95
								String idZoneGeo = Util.convertirChaineZoneGeoVersDepartement(((JSONString) entites.get("ce_zone_geo")).stringValue());
96
								String zoneGeo  = ((JSONString) entites.get("zone_geo")).stringValue();
97
								String lieuDit  = ((JSONString) entites.get("lieudit")).stringValue();
98
								String station  = ((JSONString) entites.get("station")).stringValue();
65 david 99
 
965 aurelien 100
								EntiteGeographiqueObservation ent = new EntiteGeographiqueObservation(idZoneGeo, zoneGeo, lieuDit, station);
140 aurelien 101
								listeEntiteGeographiqueObservation.put(ent);
65 david 102
							}
103
						}
104
					} else {
105
 
106
						listeEntiteGeographiqueObservation = new ListeEntiteGeographiqueObservation(0);
107
 
108
					}
109
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
110
					// le premier à les recevoir
111
 
112
					r.rafraichir(listeEntiteGeographiqueObservation, true);
113
 
114
				}
115
 
116
			});
117
 
118
		} catch (RequestException e) {
119
 
120
			e.printStackTrace();
121
		}
122
 
123
	}
124
}