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;
|
1918 |
aurelien |
8 |
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
|
54 |
david |
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 |
|
1542 |
aurelien |
43 |
public void obtenirURLImage(final Rafraichissable r, String referentielTaxo, String numeroNomenclaturalSaisiObservation) {
|
|
|
44 |
String referentielDefaut = Configuration.getReferentielsDispos().get(0).getCode();
|
|
|
45 |
referentielTaxo = (referentielTaxo != null && !referentielTaxo.isEmpty()) ? referentielTaxo : referentielDefaut;
|
54 |
david |
46 |
|
|
|
47 |
// on envoie le get asynchrone
|
1918 |
aurelien |
48 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,Configuration.getServiceBaseUrl()
|
1542 |
aurelien |
49 |
+"/NameImage/"+referentielTaxo+"/"+numeroNomenclaturalSaisiObservation) ;
|
54 |
david |
50 |
|
|
|
51 |
try {
|
|
|
52 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
53 |
|
1293 |
aurelien |
54 |
@Override
|
54 |
david |
55 |
public void onError(Request request, Throwable exception) {
|
|
|
56 |
// TODO Auto-generated method stub
|
|
|
57 |
|
|
|
58 |
}
|
|
|
59 |
|
1293 |
aurelien |
60 |
@Override
|
54 |
david |
61 |
public void onResponseReceived(Request request,
|
|
|
62 |
Response response) {
|
|
|
63 |
|
1958 |
aurelien |
64 |
try {
|
|
|
65 |
JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
66 |
JSONArray reponse;
|
|
|
67 |
String urlImage=null;
|
|
|
68 |
String urlImageMax=null;
|
|
|
69 |
|
|
|
70 |
if ((reponse = responseValue.isArray()) != null) {
|
|
|
71 |
// Url Image
|
|
|
72 |
urlImage= ((JSONString)reponse.get(0)).stringValue();
|
|
|
73 |
urlImageMax= ((JSONString)reponse.get(1)).stringValue();
|
|
|
74 |
}
|
|
|
75 |
else {
|
|
|
76 |
urlImage="";
|
|
|
77 |
urlImageMax="";
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
r.rafraichir(new String[]{urlImage,urlImageMax},true);
|
|
|
81 |
} catch (Exception e) {
|
|
|
82 |
// TODO: handle exception
|
54 |
david |
83 |
}
|
|
|
84 |
}
|
|
|
85 |
}) ;
|
|
|
86 |
|
|
|
87 |
} catch (RequestException e) {
|
|
|
88 |
// TODO Auto-generated catch block
|
|
|
89 |
e.printStackTrace();
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
}
|