Subversion Repositories eFlore/Applications.cel

Rev

Rev 989 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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