Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
989 aurelien 1
package org.tela_botanica.client.modeles.dao;
54 david 2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
989 aurelien 4
import org.tela_botanica.client.modeles.objets.Configuration;
54 david 5
import org.tela_botanica.client.observation.ObservationModele;
6
 
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONValue;
16
 
17
/**
18
 * DAO d'accès a une observation
19
 *
20
 * @author aurelien
21
 *
22
 */
23
public class ImageGeneriqueVueAsynchroneDAO {
24
 
25
	/**
26
	 * Le modele associé au DAO
27
	 */
28
	private ObservationModele observationModele = null;
29
 
30
	public ImageGeneriqueVueAsynchroneDAO(ObservationModele obs) {
31
		observationModele = obs;
32
	}
33
 
34
 
35
 
36
	/**
347 david 37
	 * Recherche Image  associee a un nom
54 david 38
	 * @param r
39
	 * @param identifiant
40
	 * @param numeroNomenclaturalSaisiObservation
41
	 */
42
 
43
	public void obtenirURLImage(final Rafraichissable r, String numeroNomenclaturalSaisiObservation) {
44
 
45
 
46
 
47
		// on envoie le get asynchrone
971 aurelien 48
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,Configuration.getServiceBaseUrl()
54 david 49
				+"/NameImage/"+numeroNomenclaturalSaisiObservation) ;
50
 
51
		try {
52
			rb.sendRequest(null, new RequestCallback() {
53
 
54
				public void onError(Request request, Throwable exception) {
55
					// TODO Auto-generated method stub
56
 
57
				}
58
 
59
				public void onResponseReceived(Request request,
60
						Response response) {
61
 
62
					JSONValue responseValue = JSONParser.parse(response.getText());
63
					JSONArray reponse;
64
					String urlImage=null;
347 david 65
					String urlImageMax=null;
54 david 66
 
67
					if ((reponse = responseValue.isArray()) != null) {
68
						// Url Image
69
						urlImage= ((JSONString)reponse.get(0)).stringValue();
347 david 70
						urlImageMax= ((JSONString)reponse.get(1)).stringValue();
54 david 71
					}
72
					else {
73
						urlImage="";
347 david 74
						urlImageMax="";
54 david 75
					}
76
 
347 david 77
					r.rafraichir(new String[]{urlImage,urlImageMax},true);
54 david 78
				}
79
			}) ;
80
 
81
		} catch (RequestException e) {
82
			// TODO Auto-generated catch block
83
			e.printStackTrace();
84
		}
85
	}
86
 
87
 
88
 
89
}