Subversion Repositories eFlore/Applications.cel

Rev

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

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