Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 127 Rev 210
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);				
100
									observationData.put(obs.getNumeroOrdre(),obs);				
101
								}		
101
								}		
102
							}
102
							}
103
						} else {
103
						} else {
104
							
104
							
105
							observationData = new ListeObservation(0) ;
105
							observationData = new ListeObservation(0) ;
106
						}
106
						}
107
											
107
											
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
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
109
						// le premier à les recevoir
109
						// le premier à les recevoir
110
						
110
						
111
						// TODO : ce n'est pas ici qu'on devrait le decider ..
111
						// TODO : ce n'est pas ici qu'on devrait le decider ..
112
						raf.rafraichir(observationData,true);	
112
						raf.rafraichir(observationData,true);	
113
					}
113
					}
114
				});
114
				});
115
	
115
	
116
			} catch (RequestException e) {
116
			} catch (RequestException e) {
117
				// TODO Auto-generated catch block
117
				// TODO Auto-generated catch block
118
				e.printStackTrace();
118
				e.printStackTrace();
119
			}
119
			}
120
	}
120
	}
121
	
121
	
122
	public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
122
	public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
123
	{
123
	{
124
		String paramGet = "&coi_ce_observation="+idObs ;
124
		String paramGet = "&coi_ce_observation="+idObs ;
125
		raf = r ;
125
		raf = r ;
126
 
126
 
127
		// et on envoie ça au serveur
127
		// et on envoie ça au serveur
128
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
128
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
129
				+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
129
				+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
130
			try {
130
			try {
131
				rb.sendRequest(null, new RequestCallback() {
131
				rb.sendRequest(null, new RequestCallback() {
132
	
132
	
133
					public void onError(Request request, Throwable exception) {
133
					public void onError(Request request, Throwable exception) {
134
						// TODO Auto-generated method stub
134
						// TODO Auto-generated method stub
135
	
135
	
136
					}
136
					}
137
	
137
	
138
					public void onResponseReceived(Request request,
138
					public void onResponseReceived(Request request,
139
							Response response) {
139
							Response response) {
140
	
140
	
141
						String baseUrl = Configuration.getImageBaseUrl() ;
141
						String baseUrl = Configuration.getImageBaseUrl() ;
142
						
142
						
143
						final JSONValue responseValue = JSONParser.parse(response
143
						final JSONValue responseValue = JSONParser.parse(response
144
								.getText());
144
								.getText());
145
						// si c'est un tableau
145
						// si c'est un tableau
146
						if (responseValue.isArray() != null) {
146
						if (responseValue.isArray() != null) {
147
 
147
 
148
							final JSONArray reponse = responseValue.isArray();
148
							final JSONArray reponse = responseValue.isArray();
149
							
149
							
150
							final int taillemax = reponse.size();
150
							final int taillemax = reponse.size();
151
							
151
							
152
							String imgTab[] = new String[taillemax] ;
152
							String imgTab[][] = new String[taillemax][3] ;
153
							
153
							
154
							for(int i = 0 ;i<taillemax ;i++)
154
							for(int i = 0 ;i<taillemax ;i++)
155
							{
155
							{
156
								
156
								
157
								final JSONArray reponseInt = reponse.get(i).isArray();
157
								final JSONArray reponseInt = reponse.get(i).isArray();
158
								String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
158
								String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
-
 
159
								String X = ((JSONString)reponseInt.get(1)).stringValue() ;
-
 
160
								String Y = ((JSONString)reponseInt.get(2)).stringValue() ;
159
								imgTab[i] = idImg ;
161
								imgTab[i][0] = idImg ;
-
 
162
								imgTab[i][1] = X ;
-
 
163
								imgTab[i][2] = Y ;
160
								
164
								
161
							}
165
							}
162
							
166
							
163
							raf.rafraichir(imgTab, false) ;
167
							raf.rafraichir(imgTab, false) ;
164
						}
168
						}
165
						else
169
						else
166
						{
170
						{
167
							String imgTab[] = new String[0] ;
171
							String imgTab[] = new String[0] ;
168
							raf.rafraichir(imgTab, false) ;
172
							raf.rafraichir(imgTab, false) ;
169
						}
173
						}
170
					}
174
					}
171
					
175
					
172
				});
176
				});
173
	
177
	
174
			} catch (RequestException e) {
178
			} catch (RequestException e) {
175
				// TODO Auto-generated catch block
179
				// TODO Auto-generated catch block
176
				e.printStackTrace();
180
				e.printStackTrace();
177
			}
181
			}
178
	}
182
	}
179
	
183
	
180
	public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
184
	public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
181
		
185
		
182
		String postData = "";
186
		String postData = "";
183
		
187
		
184
		postData += "&coi_ce_image="+idsImages ;
188
		postData += "&coi_ce_image="+idsImages ;
185
		postData += "&coi_ce_observation="+idsObs ;
189
		postData += "&coi_ce_observation="+idsObs ;
186
		postData += "&identifiant="+iModele.getIdentifiant() ;
190
		postData += "&identifiant="+iModele.getIdentifiant() ;
187
 
191
 
188
		// et on envoie ça au serveur
192
		// et on envoie ça au serveur
189
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
193
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
190
				+ "/inventoryImageLink/");
194
				+ "/inventoryImageLink/");
191
		
-
 
192
		if(Window.confirm("Lier les images "+idsImages+" aux observations "+idsObs+" ?"))
-
 
193
		{
-
 
194
			try {
195
		try {
195
				rb.sendRequest(postData, new RequestCallback() {
196
			rb.sendRequest(postData, new RequestCallback() {
196
	
197
 
197
					public void onError(Request request, Throwable exception) {
198
				public void onError(Request request, Throwable exception) {
198
						// TODO Auto-generated method stub
199
					// TODO Auto-generated method stub
199
	
200
 
200
					}
201
				}
201
	
202
 
202
					public void onResponseReceived(Request request,
203
				public void onResponseReceived(Request request,
203
							Response response) {
204
						Response response) {
204
	
205
 
205
						// quand la requête est éxecutée on le signale au modèle
206
					// quand la requête est éxecutée on le signale au modèle
206
						// poru qu'il mette à jour les données
207
					// pour qu'il mette à jour les données
207
						// et en notifie le médiateur
208
					// et en notifie le médiateur
208
					//	iModele.requeteTerminee();
209
					//iModele.requeteTerminee();
209
	
210
 
210
					}
211
				}
211
				});
212
			});
212
	
213
 
213
			} catch (RequestException e) {
214
		} catch (RequestException e) {
214
				// TODO Auto-generated catch block
215
			// TODO Auto-generated catch block
215
				e.printStackTrace();
216
			e.printStackTrace();
216
			}
-
 
217
		}
217
		}
218
	}
218
	}
219
 
219
 
220
	public void supprimerLienImageObservation(String idImg, String idObs) {
220
	public void supprimerLienImageObservation(String idImg, String idObs) {
221
		
221
		
222
		String postData = "";
222
		String postData = "";
223
		
223
		
224
		postData += "&action=DELETE" ;
224
		postData += "&action=DELETE" ;
225
		String identifiant = "" ;
225
		String identifiant = "" ;
226
		
226
		
227
		if(iModele == null) {
227
		if(iModele == null) {
228
			identifiant = oModele.getIdentifiant() ;  ;
228
			identifiant = oModele.getIdentifiant() ;  ;
229
		}
229
		}
230
		else
230
		else
231
		{
231
		{
232
			identifiant = iModele.getIdentifiant() ;
232
			identifiant = iModele.getIdentifiant() ;
233
		}
233
		}
234
 
234
 
235
		// et on envoie ça au serveur
235
		// et on envoie ça au serveur
236
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
236
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
237
				+ "/inventoryImageLink/"+identifiant+"/"+idImg+"/"+idObs);
237
				+ "/inventoryImageLink/"+identifiant+"/"+idImg+"/"+idObs);
238
		
238
		
239
			try {
239
			try {
240
				rb.sendRequest(postData, new RequestCallback() {
240
				rb.sendRequest(postData, new RequestCallback() {
241
	
241
	
242
					public void onError(Request request, Throwable exception) {
242
					public void onError(Request request, Throwable exception) {
243
						// TODO Auto-generated method stub
243
						// TODO Auto-generated method stub
244
	
244
	
245
					}
245
					}
246
	
246
	
247
					public void onResponseReceived(Request request,
247
					public void onResponseReceived(Request request,
248
							Response response) {
248
							Response response) {
249
	
249
	
250
						// 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
251
						// poru qu'il mette à jour les données
251
						// poru qu'il mette à jour les données
252
						// et en notifie le médiateur
252
						// et en notifie le médiateur
253
					//	iModele.requeteTerminee();
253
					//	iModele.requeteTerminee();
254
	
254
	
255
					}
255
					}
256
				});
256
				});
257
	
257
	
258
			} catch (RequestException e) {
258
			} catch (RequestException e) {
259
				// TODO Auto-generated catch block
259
				// TODO Auto-generated catch block
260
				e.printStackTrace();
260
				e.printStackTrace();
261
			}
261
			}
262
	}
262
	}
263
}
263
}