Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 104 Rev 107
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.image.ImageModele;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.observation.ObservationModele;
6
import org.tela_botanica.client.observation.ObservationModele;
7
 
7
 
8
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.Request;
9
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.Response;
12
import com.google.gwt.http.client.Response;
13
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONParser;
15
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONString;
16
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.json.client.JSONValue;
17
import com.google.gwt.user.client.Window;
17
import com.google.gwt.user.client.Window;
18
 
18
 
19
public class LienImageAsynchroneDAO {
19
public class LienImageAsynchroneDAO {
20
 
20
 
21
	private ImageModele iModele = null ;
21
	private ImageModele iModele = null ;
22
	
22
	
23
	private ObservationModele oModele = null ;
23
	private ObservationModele oModele = null ;
24
	
24
	
25
	private Rafraichissable raf = null ;
25
	private Rafraichissable raf = null ;
26
	
26
	
27
	public LienImageAsynchroneDAO(ImageModele im) {
27
	public LienImageAsynchroneDAO(ImageModele im) {
28
		iModele = im;
28
		iModele = im;
29
	}
29
	}
30
	
30
	
31
	public LienImageAsynchroneDAO(ObservationModele om) {
31
	public LienImageAsynchroneDAO(ObservationModele om) {
32
		oModele = om;
32
		oModele = om;
33
	}
33
	}
34
 
34
 
35
	/**
35
	/**
36
	 * Setteur pour le modèle
36
	 * Setteur pour le modèle
37
	 * 
37
	 * 
38
	 * @param im
38
	 * @param im
39
	 *            le modèle à associer
39
	 *            le modèle à associer
40
	 */
40
	 */
41
	public void setIModele(ImageModele im) {
41
	public void setIModele(ImageModele im) {
42
		iModele = im;
42
		iModele = im;
43
	}
43
	}
44
	
44
	
45
	public void obtenirLiaisonsImagesObservations(Rafraichissable r,String id)
45
	public void obtenirLiaisonsImagesObservations(Rafraichissable r,String id)
46
	{
46
	{
47
		String paramGet = "&coi_ce_image="+id ;
47
		String paramGet = "&coi_ce_image="+id ;
48
		
48
		
49
		raf = r ;
49
		raf = r ;
50
		
50
		
51
		// et on envoie ça au serveur
51
		// et on envoie ça au serveur
52
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
52
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
53
				+ "/inventoryImageLink/" + iModele.getIdentifiant() + "/" + paramGet);
53
				+ "/inventoryImageLink/" + iModele.getIdentifiant() + "/" + paramGet);
54
			try {
54
			try {
55
				rb.sendRequest(null, new RequestCallback() {
55
				rb.sendRequest(null, new RequestCallback() {
56
	
56
	
57
					public void onError(Request request, Throwable exception) {
57
					public void onError(Request request, Throwable exception) {
58
						// TODO Auto-generated method stub
58
						// TODO Auto-generated method stub
59
	
59
	
60
					}
60
					}
61
	
61
	
62
					public void onResponseReceived(Request request,
62
					public void onResponseReceived(Request request,
63
							Response response) {
63
							Response response) {
64
	
64
	
65
						final ListeObservation observationData ;
65
						final ListeObservation observationData ;
66
						final JSONValue responseValue = JSONParser.parse(response.getText());
66
						final JSONValue responseValue = JSONParser.parse(response.getText());
67
									
67
									
68
						JSONArray reponse=null;
68
						JSONArray reponse=null;
69
						
69
						
70
						// si c'est un tableau
70
						// si c'est un tableau
71
						if ((reponse=responseValue.isArray()) != null) {
71
						if ((reponse=responseValue.isArray()) != null) {
72
							
72
							
73
							JSONArray observation;
73
							JSONArray observation;
74
							final int taillemax = reponse.size();
74
							final int taillemax = reponse.size();
75
							
75
							
76
							observationData = new ListeObservation(taillemax);
76
							observationData = new ListeObservation(taillemax);
77
							
77
							
78
							for (int i = 0; i < taillemax; i++) {
78
							for (int i = 0; i < taillemax; i++) {
79
								
79
								
80
								if ((observation=reponse.get(i).isArray()) != null) {								
80
								if ((observation=reponse.get(i).isArray()) != null) {								
81
									
81
									
82
									String transmis=((JSONString) observation.get(13)).stringValue();
82
									String transmis=((JSONString) observation.get(13)).stringValue();
83
									String identifiantLocalite=((JSONString) observation.get(14)).toString();
83
									String identifiantLocalite=((JSONString) observation.get(14)).toString();
84
									String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
84
									String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
85
									String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
85
									String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
86
									String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
86
									String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
87
									String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
87
									String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
88
									String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
88
									String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
89
									String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
89
									String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
90
									String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
90
									String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
91
									String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
91
									String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
92
									String station=Util.toCelString(((JSONString) observation .get(10)).toString());
92
									String station=Util.toCelString(((JSONString) observation .get(10)).toString());
93
									String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
93
									String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
94
									String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
94
									String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
95
									String date=((JSONString) observation .get(8)).stringValue();
95
									String date=((JSONString) observation .get(8)).stringValue();
96
									String numeroOrdre=((JSONString) observation.get(7)).stringValue();
96
									String numeroOrdre=((JSONString) observation.get(7)).stringValue();
97
									
97
									
98
									Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre);
98
									Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre);
99
				
99
				
100
									observationData.put(obs.getNumeroOrdre(),obs);
-
 
101
									
-
 
102
									
100
									observationData.put(obs.getNumeroOrdre(),obs);				
103
								}
-
 
104
					
101
								}		
105
							}
102
							}
106
						} else {
103
						} else {
107
							
104
							
108
							observationData = new ListeObservation(0) ;
105
							observationData = new ListeObservation(0) ;
109
						}
106
						}
110
											
107
											
111
						// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
108
						// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
112
						// le premier à les recevoir
109
						// le premier à les recevoir
113
						
110
						
114
						// TODO : ce n'est pas ici qu'on devrait le decider ..
111
						// TODO : ce n'est pas ici qu'on devrait le decider ..
115
						raf.rafraichir(observationData,true);	
112
						raf.rafraichir(observationData,true);	
116
					}
113
					}
117
				});
114
				});
118
	
115
	
119
			} catch (RequestException e) {
116
			} catch (RequestException e) {
120
				// TODO Auto-generated catch block
117
				// TODO Auto-generated catch block
121
				e.printStackTrace();
118
				e.printStackTrace();
122
			}
119
			}
123
	}
120
	}
124
	
121
	
125
	public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
122
	public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
126
	{
123
	{
127
		String paramGet = "&coi_ce_observation="+idObs ;
124
		String paramGet = "&coi_ce_observation="+idObs ;
128
		raf = r ;
125
		raf = r ;
129
 
126
 
130
		// et on envoie ça au serveur
127
		// et on envoie ça au serveur
131
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
128
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
132
				+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
129
				+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
133
			try {
130
			try {
134
				rb.sendRequest(null, new RequestCallback() {
131
				rb.sendRequest(null, new RequestCallback() {
135
	
132
	
136
					public void onError(Request request, Throwable exception) {
133
					public void onError(Request request, Throwable exception) {
137
						// TODO Auto-generated method stub
134
						// TODO Auto-generated method stub
138
	
135
	
139
					}
136
					}
140
	
137
	
141
					public void onResponseReceived(Request request,
138
					public void onResponseReceived(Request request,
142
							Response response) {
139
							Response response) {
143
	
140
	
144
						String baseUrl = Configuration.getImageBaseUrl() ;
141
						String baseUrl = Configuration.getImageBaseUrl() ;
145
						
142
						
146
						final JSONValue responseValue = JSONParser.parse(response
143
						final JSONValue responseValue = JSONParser.parse(response
147
								.getText());
144
								.getText());
148
						// si c'est un tableau
145
						// si c'est un tableau
149
						if (responseValue.isArray() != null) {
146
						if (responseValue.isArray() != null) {
150
 
147
 
151
							final JSONArray reponse = responseValue.isArray();
148
							final JSONArray reponse = responseValue.isArray();
152
							
149
							
153
							final int taillemax = reponse.size();
150
							final int taillemax = reponse.size();
154
							
151
							
155
							String imgTab[] = new String[taillemax] ;
152
							String imgTab[] = new String[taillemax] ;
156
							
153
							
157
							for(int i = 0 ;i<taillemax ;i++)
154
							for(int i = 0 ;i<taillemax ;i++)
158
							{
155
							{
159
								
156
								
160
								final JSONArray reponseInt = reponse.get(i).isArray();
157
								final JSONArray reponseInt = reponse.get(i).isArray();
161
								String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
158
								String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
162
								imgTab[i] = idImg ;
159
								imgTab[i] = idImg ;
163
								
160
								
164
							}
161
							}
165
							
162
							
166
							raf.rafraichir(imgTab, false) ;
163
							raf.rafraichir(imgTab, false) ;
167
						}
164
						}
168
						else
165
						else
169
						{
166
						{
170
							String imgTab[] = new String[0] ;
167
							String imgTab[] = new String[0] ;
171
							raf.rafraichir(imgTab, false) ;
168
							raf.rafraichir(imgTab, false) ;
172
						}
169
						}
173
					}
170
					}
174
					
171
					
175
				});
172
				});
176
	
173
	
177
			} catch (RequestException e) {
174
			} catch (RequestException e) {
178
				// TODO Auto-generated catch block
175
				// TODO Auto-generated catch block
179
				e.printStackTrace();
176
				e.printStackTrace();
180
			}
177
			}
181
	}
178
	}
182
	
179
	
183
	public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
180
	public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
184
		
181
		
185
		String postData = "";
182
		String postData = "";
186
		
183
		
187
		postData += "&coi_ce_image="+idsImages ;
184
		postData += "&coi_ce_image="+idsImages ;
188
		postData += "&coi_ce_observation="+idsObs ;
185
		postData += "&coi_ce_observation="+idsObs ;
189
		postData += "&identifiant="+iModele.getIdentifiant() ;
186
		postData += "&identifiant="+iModele.getIdentifiant() ;
190
 
187
 
191
		// et on envoie ça au serveur
188
		// et on envoie ça au serveur
192
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
189
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
193
				+ "/inventoryImageLink/");
190
				+ "/inventoryImageLink/");
194
		
191
		
195
		if(Window.confirm("Lier les images "+idsImages+" aux observations "+idsObs+" ?"))
192
		if(Window.confirm("Lier les images "+idsImages+" aux observations "+idsObs+" ?"))
196
		{
193
		{
197
			try {
194
			try {
198
				rb.sendRequest(postData, new RequestCallback() {
195
				rb.sendRequest(postData, new RequestCallback() {
199
	
196
	
200
					public void onError(Request request, Throwable exception) {
197
					public void onError(Request request, Throwable exception) {
201
						// TODO Auto-generated method stub
198
						// TODO Auto-generated method stub
202
	
199
	
203
					}
200
					}
204
	
201
	
205
					public void onResponseReceived(Request request,
202
					public void onResponseReceived(Request request,
206
							Response response) {
203
							Response response) {
207
	
204
	
208
						// quand la requête est éxecutée on le signale au modèle
205
						// quand la requête est éxecutée on le signale au modèle
209
						// poru qu'il mette à jour les données
206
						// poru qu'il mette à jour les données
210
						// et en notifie le médiateur
207
						// et en notifie le médiateur
211
					//	iModele.requeteTerminee();
208
					//	iModele.requeteTerminee();
212
	
209
	
213
					}
210
					}
214
				});
211
				});
215
	
212
	
216
			} catch (RequestException e) {
213
			} catch (RequestException e) {
217
				// TODO Auto-generated catch block
214
				// TODO Auto-generated catch block
218
				e.printStackTrace();
215
				e.printStackTrace();
219
			}
216
			}
220
		}
217
		}
221
	}
218
	}
222
 
219
 
223
	public void supprimerLienImageObservation(String idImg, String idObs) {
220
	public void supprimerLienImageObservation(String idImg, String idObs) {
224
		
221
		
225
		String postData = "";
222
		String postData = "";
226
		
223
		
227
		postData += "&action=DELETE" ;
224
		postData += "&action=DELETE" ;
228
		String identifiant = "" ;
225
		String identifiant = "" ;
229
		
226
		
230
		if(iModele == null) {
227
		if(iModele == null) {
231
			identifiant = oModele.getIdentifiant() ;  ;
228
			identifiant = oModele.getIdentifiant() ;  ;
232
		}
229
		}
233
		else
230
		else
234
		{
231
		{
235
			identifiant = iModele.getIdentifiant() ;
232
			identifiant = iModele.getIdentifiant() ;
236
		}
233
		}
237
 
234
 
238
		// et on envoie ça au serveur
235
		// et on envoie ça au serveur
239
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
236
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
240
				+ "/inventoryImageLink/"+identifiant+"/"+idImg+"/"+idObs);
237
				+ "/inventoryImageLink/"+identifiant+"/"+idImg+"/"+idObs);
241
		
238
		
242
			try {
239
			try {
243
				rb.sendRequest(postData, new RequestCallback() {
240
				rb.sendRequest(postData, new RequestCallback() {
244
	
241
	
245
					public void onError(Request request, Throwable exception) {
242
					public void onError(Request request, Throwable exception) {
246
						// TODO Auto-generated method stub
243
						// TODO Auto-generated method stub
247
	
244
	
248
					}
245
					}
249
	
246
	
250
					public void onResponseReceived(Request request,
247
					public void onResponseReceived(Request request,
251
							Response response) {
248
							Response response) {
252
	
249
	
253
						// quand la requête est éxecutée on le signale au modèle
250
						// quand la requête est éxecutée on le signale au modèle
254
						// poru qu'il mette à jour les données
251
						// poru qu'il mette à jour les données
255
						// et en notifie le médiateur
252
						// et en notifie le médiateur
256
					//	iModele.requeteTerminee();
253
					//	iModele.requeteTerminee();
257
	
254
	
258
					}
255
					}
259
				});
256
				});
260
	
257
	
261
			} catch (RequestException e) {
258
			} catch (RequestException e) {
262
				// TODO Auto-generated catch block
259
				// TODO Auto-generated catch block
263
				e.printStackTrace();
260
				e.printStackTrace();
264
			}
261
			}
265
	}
262
	}
266
}
263
}