Subversion Repositories eFlore/Applications.cel

Rev

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

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