Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 387 Rev 411
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import org.tela_botanica.client.Util;
3
import org.tela_botanica.client.Util;
-
 
4
import org.tela_botanica.client.image.ImageModele;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.observation.ObservationModele;
6
import org.tela_botanica.client.observation.ObservationModele;
6
 
7
 
7
import com.google.gwt.core.client.GWT;
8
import com.google.gwt.core.client.GWT;
8
import com.google.gwt.http.client.Request;
9
import com.google.gwt.http.client.Request;
9
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.Response;
13
import com.google.gwt.http.client.Response;
13
import com.google.gwt.http.client.URL;
14
import com.google.gwt.http.client.URL;
14
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONParser;
16
import com.google.gwt.json.client.JSONParser;
16
import com.google.gwt.json.client.JSONString;
17
import com.google.gwt.json.client.JSONString;
17
import com.google.gwt.json.client.JSONValue;
18
import com.google.gwt.json.client.JSONValue;
18
import com.google.gwt.user.client.Window;
19
import com.google.gwt.user.client.Window;
19
 
20
 
20
/**
21
/**
21
 * DAO la liste des observations attachées a un observateur.
22
 * DAO la liste des observations attachées a un observateur.
22
 * @author David Delon
23
 * @author David Delon
23
 * TODO : se servir de ObservationDAO pour la lecture unitaire
24
 * TODO : se servir de ObservationDAO pour la lecture unitaire
24
 *
25
 *
25
 */
26
 */
26
public class ListeObservationAsynchroneDAO {
27
public class ListeObservationAsynchroneDAO {
27
 
28
 
28
 
29
 
29
/**
30
/**
30
 * Le modèle associé au DAO.
31
 * Le modèle associé au DAO.
31
 */
32
 */
32
 private ObservationModele observationModele = null;
33
 private ObservationModele observationModele = null;
-
 
34
 
-
 
35
 private ImageModele imageModele = null;
33
 
36
 
34
 public ListeObservationAsynchroneDAO(final ObservationModele obs) {
37
 public ListeObservationAsynchroneDAO(final ObservationModele obs) {
35
  this.observationModele=obs;
38
  this.observationModele=obs;
36
 }
39
 }
-
 
40
 
-
 
41
 /**
-
 
42
  * Le modèle associé au DAO.
-
 
43
  */
-
 
44
 
-
 
45
  public ListeObservationAsynchroneDAO(final ImageModele img) {
-
 
46
	  this.imageModele = img;
-
 
47
  }
37
	
48
	
38
	
49
	
39
	/**
50
	/**
40
	 * Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant
51
	 * Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant
41
	 * à des critères données en paramètres
52
	 * à des critères données en paramètres
42
	 * @param r le rafraichissable qui demande la mise à jour
53
	 * @param r le rafraichissable qui demande la mise à jour
43
	 * @param criteres un tableau nom/valeur des critères pour les observations
54
	 * @param criteres un tableau nom/valeur des critères pour les observations
44
	 */
55
	 */
45
	public final void obtenirListeObservation(final Rafraichissable r, final String utilisateur, final String[][] criteres)
56
	public final void obtenirListeObservation(final Rafraichissable r, final String utilisateur, final String[][] criteres)
46
	{
57
	{
47
		
58
		
48
		
59
		
49
		String requete = "" ;
60
		String requete = "" ;
50
			
61
			
51
		if(criteres != null)
62
		if(criteres != null)
52
		{
63
		{
53
			// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
64
			// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
54
			// ils contiennent limite et taille page et autres filtres (communes , lieu dit etc ...)S
65
			// ils contiennent limite et taille page et autres filtres (communes , lieu dit etc ...)S
55
			
66
			
56
			for (int i = 0; i < criteres.length; i++) {
67
			for (int i = 0; i < criteres.length; i++) {
57
				
68
				
58
				if(criteres[i][1] != null && !criteres[i][1].equals(""))
69
				if(criteres[i][1] != null && !criteres[i][1].equals(""))
59
				{
70
				{
60
					if(i!= 0)
71
					if(i!= 0)
61
					{
72
					{
62
						requete += "&";
73
						requete += "&";
63
					}
74
					}
64
					requete += criteres[i][0]+"="+URL.encodeComponent(criteres[i][1]) ;
75
					requete += criteres[i][0]+"="+URL.encodeComponent(criteres[i][1]) ;
65
				}
76
				}
66
			}
77
			}
67
		}
78
		}
68
		
79
		
69
		// on envoie le get asynchrone
80
		// on envoie le get asynchrone
70
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,Configuration.getServiceBaseUrl()
81
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,Configuration.getServiceBaseUrl()
71
				+"/InventoryObservationList/"+utilisateur+"/"+requete) ;
82
				+"/InventoryObservationList/"+utilisateur+"/"+requete) ;
72
		
83
		
73
		try {
84
		try {
74
			rb.sendRequest(null, new RequestCallback() {
85
			rb.sendRequest(null, new RequestCallback() {
75
 
86
 
76
				public void onError(final Request request, final Throwable exception) {
87
				public void onError(final Request request, final Throwable exception) {
77
					// TODO Auto-generated method stub
88
					// TODO Auto-generated method stub
78
					
89
					
79
				}
90
				}
80
 
91
 
81
				public void onResponseReceived(final Request request,
92
				public void onResponseReceived(final Request request,
82
						final Response response) {
93
						final Response response) {
83
					
94
					
84
					final ListeObservation observationData ;
95
					final ListeObservation observationData ;
85
					final JSONValue responseValue = JSONParser.parse(response.getText());
96
					final JSONValue responseValue = JSONParser.parse(response.getText());
86
								
97
								
87
					JSONArray reponse=null;
98
					JSONArray reponse=null;
88
					
99
					
89
					// si c'est un tableau
100
					// si c'est un tableau
90
					if ((reponse=responseValue.isArray()) != null) {
101
					if ((reponse=responseValue.isArray()) != null) {
91
						
102
						
92
						JSONArray observation;
103
						JSONArray observation;
93
						final int taillemax = reponse.size();
104
						final int taillemax = reponse.size();
94
						
105
						
95
						observationData = new ListeObservation(taillemax);
106
						observationData = new ListeObservation(taillemax);
96
						
107
						
97
						for (int i = 0; i < taillemax; i++) {
108
						for (int i = 0; i < taillemax; i++) {
98
							
109
							
99
							if ((observation=reponse.get(i).isArray()) != null) {								
110
							if ((observation=reponse.get(i).isArray()) != null) {								
100
								
111
								
101
								String transmis=((JSONString) observation.get(13)).stringValue();
112
								String transmis=((JSONString) observation.get(13)).stringValue();
102
								String identifiantLocalite=((JSONString) observation.get(14)).toString();
113
								String identifiantLocalite=((JSONString) observation.get(14)).toString();
103
								String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
114
								String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
104
								String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
115
								String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
105
								String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
116
								String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
106
								String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
117
								String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
107
								String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
118
								String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
108
								String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
119
								String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
109
								String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
120
								String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
110
								String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
121
								String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
111
								String station=Util.toCelString(((JSONString) observation .get(10)).toString());
122
								String station=Util.toCelString(((JSONString) observation .get(10)).toString());
112
								String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
123
								String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
113
								String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
124
								String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
114
								String date=((JSONString) observation .get(8)).stringValue();
125
								String date=((JSONString) observation .get(8)).stringValue();
115
								String numeroOrdre=((JSONString) observation.get(7)).stringValue();
126
								String numeroOrdre=((JSONString) observation.get(7)).stringValue();
116
								String coordX=((JSONString) observation.get(15)).stringValue();
127
								String coordX=((JSONString) observation.get(15)).stringValue();
117
								String coordY=((JSONString) observation.get(16)).stringValue();
128
								String coordY=((JSONString) observation.get(16)).stringValue();
118
								String motsCles=((JSONString) observation.get(17)).stringValue();
129
								String motsCles=((JSONString) observation.get(17)).stringValue();
119
								
130
								
120
								Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre/*, motsCles*/);
131
								Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre/*, motsCles*/);
121
								obs.setCoordonneeX(coordX);
132
								obs.setCoordonneeX(coordX);
122
								obs.setCoordonneeY(coordY);
133
								obs.setCoordonneeY(coordY);
123
								obs.setMotsCles(motsCles);
134
								obs.setMotsCles(motsCles);
124
								observationData.put(obs.getNumeroOrdre(),obs);
135
								observationData.put(obs.getNumeroOrdre(),obs);
125
								
136
								
126
								
137
								
127
							}
138
							}
128
						}
139
						}
129
					} else {
140
					} else {
130
						
141
						
131
						observationData = new ListeObservation(0) ;
142
						observationData = new ListeObservation(0) ;
132
					}
143
					}
133
										
144
										
134
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
145
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
135
					// le premier à les recevoir
146
					// le premier à les recevoir
136
					
147
					
137
					// TODO : ce n'est pas ici qu'on devrait le decider ..
148
					// TODO : ce n'est pas ici qu'on devrait le decider ..
138
					r.rafraichir(observationData,true);	
149
					r.rafraichir(observationData,true);	
139
				}
150
				}
140
			}) ;
151
			}) ;
141
 
152
 
142
		} catch (RequestException e) {
153
		} catch (RequestException e) {
143
			// TODO Auto-generated catch block
154
			// TODO Auto-generated catch block
144
			e.printStackTrace();
155
			e.printStackTrace();
145
		}
156
		}
146
	}
157
	}
147
	
158
	
148
	public void modifierEnMasse(final Rafraichissable r, String identifiant,
159
	public void modifierEnMasse(final Rafraichissable r, String identifiant,
149
			final Observation obs) {
160
			final Observation obs) {
150
 
161
 
151
				RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/InventoryObservationList/" + identifiant + "/" + obs.getNumeroOrdre()+ "/") ;
162
				RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/InventoryObservationList/" + identifiant + "/" + obs.getNumeroOrdre()+ "/") ;
152
				
163
				
153
				String postData = "identifiant="
164
				String postData = "identifiant="
154
					+ identifiant ;
165
					+ identifiant ;
155
				if(obs.getNomSaisi() != null) {
166
				if(obs.getNomSaisi() != null) {
156
					postData += "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi());
167
					postData += "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi());
157
				}
168
				}
158
				if(obs.getNumeroNomenclaturalSaisi() != null) {
169
				if(obs.getNumeroNomenclaturalSaisi() != null) {
159
					postData += "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi();
170
					postData += "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi();
160
				}
171
				}
161
				
172
				
162
				if(obs.getIdentifiantLocalite() != null) {
173
				if(obs.getIdentifiantLocalite() != null) {
163
					postData += "&id_location=" + obs.getIdentifiantLocalite();
174
					postData += "&id_location=" + obs.getIdentifiantLocalite();
164
				}
175
				}
165
				
176
				
166
				if(obs.getLocalite() != null) {
177
				if(obs.getLocalite() != null) {
167
					postData += "&location=" + URL.encodeComponent(obs.getLocalite()); 
178
					postData += "&location=" + URL.encodeComponent(obs.getLocalite()); 
168
				}
179
				}
169
				
180
				
170
				if(obs.getDate() != null) {
181
				if(obs.getDate() != null) {
171
					postData += "&date_observation=" +  obs.getDate();
182
					postData += "&date_observation=" +  obs.getDate();
172
				}
183
				}
173
				
184
				
174
				if(obs.getLieudit() != null) {
185
				if(obs.getLieudit() != null) {
175
					postData += "&lieudit="+ URL.encodeComponent(obs.getLieudit()); 
186
					postData += "&lieudit="+ URL.encodeComponent(obs.getLieudit()); 
176
				}
187
				}
177
				
188
				
178
				if(obs.getStation() != null) {
189
				if(obs.getStation() != null) {
179
					postData += "&station="+ URL.encodeComponent(obs.getStation());
190
					postData += "&station="+ URL.encodeComponent(obs.getStation());
180
				}
191
				}
181
				
192
				
182
				if(obs.getMilieu() != null) {
193
				if(obs.getMilieu() != null) {
183
					postData += "&milieu="+ URL.encodeComponent(obs.getMilieu());
194
					postData += "&milieu="+ URL.encodeComponent(obs.getMilieu());
184
				}
195
				}
185
				
196
				
186
				if(obs.getCommentaire() != null) {
197
				if(obs.getCommentaire() != null) {
187
					postData += "&commentaire="+URL.encodeComponent(""+obs.getCommentaire());
198
					postData += "&commentaire="+obs.getCommentaire();
188
				}
199
				}
189
				
200
				
190
				if(obs.getCoordonneeX() != null ) {
201
				if(obs.getCoordonneeX() != null ) {
191
					postData += "&coord_x="+URL.encodeComponent(""+obs.getCoordonneeX());
202
					postData += "&coord_x="+URL.encodeComponent(""+obs.getCoordonneeX());
192
				}
203
				}
193
				
204
				
194
				if(obs.getCoordonneeY() != null) {
205
				if(obs.getCoordonneeY() != null) {
195
					postData += "&coord_y="+URL.encodeComponent(""+obs.getCoordonneeY());
206
					postData += "&coord_y="+URL.encodeComponent(""+obs.getCoordonneeY());
196
				}
207
				}
197
 
208
 
198
				try {
209
				try {
199
					
210
					
200
					rb.sendRequest(postData, new RequestCallback() {
211
					rb.sendRequest(postData, new RequestCallback() {
201
 
212
 
202
						public void onError(Request request, Throwable exception) {
213
						public void onError(Request request, Throwable exception) {
203
							// TODO Auto-generated method stub
214
							// TODO Auto-generated method stub
204
							
215
							
205
						}
216
						}
206
 
217
 
207
						public void onResponseReceived(Request request,
218
						public void onResponseReceived(Request request,
208
								Response response) {
219
								Response response) {
209
							
-
 
-
 
220
							if(observationModele != null) {
210
							observationModele.obtenirListeObservation(r);
221
								observationModele.obtenirListeObservation(r);
211
							
222
							}
212
						}
223
						}
213
						
224
						
214
						
225
						
215
					}) ;
226
					}) ;
216
					
227
					
217
				} catch (RequestException e) {
228
				} catch (RequestException e) {
218
					
229
					
219
			}
230
			}
220
		
231
		
221
	}
232
	}
222
 
233
 
223
	/**
234
	/**
224
	 * Supprime les observations possédant les identifiants données
235
	 * Supprime les observations possédant les identifiants données
225
	 * @param r le rafraichissable à avertir de la mise à jour
236
	 * @param r le rafraichissable à avertir de la mise à jour
226
	 * @param identifiant l'identifiant utilisateur
237
	 * @param identifiant l'identifiant utilisateur
227
	 * @param numerosOrdre les numéros d'ordre des observations séparés par des virgules
238
	 * @param numerosOrdre les numéros d'ordre des observations séparés par des virgules
228
	 */
239
	 */
229
	public void supprimerListeObservation(Rafraichissable r, String identifiant, String numerosOrdre) {
240
	public void supprimerListeObservation(Rafraichissable r, String identifiant, String numerosOrdre) {
230
		
241
		
231
		String postData = "";
242
		String postData = "";
232
		postData += "&action=DELETE";
243
		postData += "&action=DELETE";
233
 
244
 
234
		// on envoie un post avec l'id de l'image à supprimer
245
		// on envoie un post avec l'id de l'image à supprimer
235
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, 
246
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, 
236
				Configuration.getServiceBaseUrl()
247
				Configuration.getServiceBaseUrl()
237
				+ "/inventoryObservationList/"
248
				+ "/inventoryObservationList/"
238
				+ identifiant
249
				+ identifiant
239
				+ "/"
250
				+ "/"
240
				+ numerosOrdre);
251
				+ numerosOrdre);
241
 
252
 
242
		try {
253
		try {
243
			rb.sendRequest(postData, new RequestCallback() {
254
			rb.sendRequest(postData, new RequestCallback() {
244
 
255
 
245
				public void onError(Request request, Throwable exception) {
256
				public void onError(Request request, Throwable exception) {
246
					// TODO Auto-generated method stub
257
					// TODO Auto-generated method stub
247
 
258
 
248
				}
259
				}
249
 
260
 
250
				public void onResponseReceived(Request request,
261
				public void onResponseReceived(Request request,
251
						Response response) {
262
						Response response) {
252
 
263
 
253
					if (response.getText().equals("OK")) {
264
					if (response.getText().equals("OK")) {
254
						
265
						
255
 
266
 
256
					} else {
267
					} else {
257
						com.google.gwt.user.client.Window
268
						com.google.gwt.user.client.Window
258
								.alert("Problème lors de la mise à jour des données");
269
								.alert("Problème lors de la mise à jour des données");
259
						return ;
270
						return ;
260
					}
271
					}
261
				}
272
				}
262
 
273
 
263
			});
274
			});
264
			
275
			
265
			r.rafraichir("OK", true) ;
276
			r.rafraichir("OK", true) ;
266
 
277
 
267
		} catch (RequestException e) {
278
		} catch (RequestException e) {
268
			// TODO Auto-generated catch block
279
			// TODO Auto-generated catch block
269
			e.printStackTrace();
280
			e.printStackTrace();
270
		}
281
		}
271
		
282
		
272
	}
283
	}
273
	
284
	
274
}
285
}