Subversion Repositories eFlore/Applications.cel

Rev

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

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