Subversion Repositories eFlore/Applications.cel

Rev

Rev 2695 | 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
 
2695 aurelien 7
import com.google.gwt.core.client.Callback;
54 david 8
import com.google.gwt.http.client.Request;
1918 aurelien 9
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
54 david 10
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.Response;
2695 aurelien 13
import com.google.gwt.http.client.URL;
54 david 14
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONParser;
16
import com.google.gwt.json.client.JSONString;
17
import com.google.gwt.json.client.JSONValue;
18
 
19
/**
20
 * DAO d'accès a une observation
21
 *
22
 * @author aurelien
23
 *
24
 */
25
public class ImageInformationRepartitionAsynchroneDAO {
26
 
27
	/**
28
	 * Le modele associé au DAO
29
	 */
30
	private ObservationModele observationModele = null;
31
 
32
	public ImageInformationRepartitionAsynchroneDAO(ObservationModele obs) {
33
		observationModele = obs;
34
	}
35
 
36
 
37
 
38
	/**
39
	 * Recherche Image repartition associee a un nom
40
	 * @param r
41
	 * @param identifiant
42
	 * @param numeroNomenclaturalSaisiObservation
43
	 */
44
 
1542 aurelien 45
	public void obtenirURLImage(final Rafraichissable r, String referentielTaxo, String numeroNomenclaturalSaisiObservation) {
54 david 46
 
1542 aurelien 47
		String referentielDefaut =  Configuration.getReferentielsDispos().get(0).getCode();
48
		referentielTaxo = (referentielTaxo != null && !referentielTaxo.isEmpty()) ? referentielTaxo : referentielDefaut;
54 david 49
 
50
		// on envoie le get asynchrone
1918 aurelien 51
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,Configuration.getServiceBaseUrl()
1542 aurelien 52
				+"/NameMap/"+referentielTaxo+"/"+numeroNomenclaturalSaisiObservation) ;
54 david 53
 
54
		try {
55
			rb.sendRequest(null, new RequestCallback() {
56
 
1293 aurelien 57
				@Override
54 david 58
				public void onError(Request request, Throwable exception) {
59
					// TODO Auto-generated method stub
60
 
61
				}
62
 
1293 aurelien 63
				@Override
54 david 64
				public void onResponseReceived(Request request,
65
						Response response) {
66
 
67
					JSONValue responseValue = JSONParser.parse(response.getText());
68
					JSONArray reponse;
69
					String urlImage=null;
70
 
71
					if ((reponse = responseValue.isArray()) != null) {
72
						// Url Image
73
						urlImage= ((JSONString)reponse.get(0)).stringValue();
74
					}
75
					else {
76
						urlImage="";
77
					}
78
 
79
					r.rafraichir(urlImage,true);
80
				}
81
			}) ;
82
 
83
		} catch (RequestException e) {
84
			// TODO Auto-generated catch block
85
			e.printStackTrace();
86
		}
87
	}
88
 
2695 aurelien 89
	public static void taxonEstPresentDansZoneGeo(String referentielTaxo, String numeroNomenclaturalSaisiObservation, String pays, String zoneGeo, final Callback<String, String> callback) {
90
		String referentielDefaut =  Configuration.getReferentielsDispos().get(0).getCode();
91
		referentielTaxo = (referentielTaxo != null && !referentielTaxo.isEmpty()) ? referentielTaxo : referentielDefaut;
92
 
93
		String url = Configuration.getServiceBaseUrl()+"/InventoryTaxonPresent/"+referentielTaxo+"/"+numeroNomenclaturalSaisiObservation+"?pays="+URL.encode(pays)+"&ce_zone_geo="+URL.encode(zoneGeo);
94
 
95
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, url) ;
96
		try {
97
			rb.sendRequest(null, new RequestCallback() {
54 david 98
 
2695 aurelien 99
				@Override
100
				public void onError(Request request, Throwable exception) {
101
					callback.onFailure(exception.getMessage());
102
				}
103
 
104
				@Override
105
				public void onResponseReceived(Request request,
106
						Response response) {
107
					final JSONValue responseValue = JSONParser
108
							.parse(response.getText());
109
 
110
					if (responseValue.isString() != null) {
111
						//Window.alert(response.getText()+responseValue.isString().stringValue());
112
						callback.onSuccess(responseValue.isString().stringValue());
113
					} else {
114
						callback.onFailure(response.getText());
115
					}
116
				}
117
			}) ;
118
 
119
		} catch (RequestException e) {
120
			callback.onFailure(e.getMessage());
121
		}
122
	}
54 david 123
 
124
}