5 |
aperonnet |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.image.ImageModele;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
94 |
jpm |
5 |
import org.tela_botanica.client.observation.ObservationModele;
|
5 |
aperonnet |
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;
|
94 |
jpm |
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;
|
5 |
aperonnet |
16 |
import com.google.gwt.user.client.Window;
|
|
|
17 |
|
|
|
18 |
public class LienImageAsynchroneDAO {
|
|
|
19 |
|
|
|
20 |
private ImageModele iModele = null ;
|
|
|
21 |
|
94 |
jpm |
22 |
private ObservationModele oModele = null ;
|
|
|
23 |
|
|
|
24 |
private Rafraichissable raf = null ;
|
|
|
25 |
|
5 |
aperonnet |
26 |
public LienImageAsynchroneDAO(ImageModele im) {
|
|
|
27 |
iModele = im;
|
|
|
28 |
}
|
94 |
jpm |
29 |
|
|
|
30 |
public LienImageAsynchroneDAO(ObservationModele om) {
|
|
|
31 |
oModele = om;
|
|
|
32 |
}
|
5 |
aperonnet |
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Setteur pour le modèle
|
|
|
36 |
*
|
|
|
37 |
* @param im
|
|
|
38 |
* le modèle à associer
|
|
|
39 |
*/
|
|
|
40 |
public void setIModele(ImageModele im) {
|
|
|
41 |
iModele = im;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public void obtenirLiaisonsImagesObservations(Rafraichissable r,String id)
|
|
|
45 |
{
|
|
|
46 |
String paramGet = "&coi_ce_image="+id ;
|
|
|
47 |
|
|
|
48 |
// et on envoie ça au serveur
|
|
|
49 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, iModele
|
|
|
50 |
.getConfig().getServiceBaseUrl()
|
|
|
51 |
+ "/inventoryImageLink/" + iModele.getIdentifiant() + "/" + paramGet);
|
62 |
jpm |
52 |
try {
|
|
|
53 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
54 |
|
|
|
55 |
public void onError(Request request, Throwable exception) {
|
|
|
56 |
// TODO Auto-generated method stub
|
|
|
57 |
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public void onResponseReceived(Request request,
|
|
|
61 |
Response response) {
|
|
|
62 |
|
81 |
jpm |
63 |
Window.alert(response.getText()) ;
|
62 |
jpm |
64 |
|
|
|
65 |
}
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
} catch (RequestException e) {
|
|
|
69 |
// TODO Auto-generated catch block
|
|
|
70 |
e.printStackTrace();
|
|
|
71 |
}
|
5 |
aperonnet |
72 |
}
|
|
|
73 |
|
94 |
jpm |
74 |
public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
|
|
|
75 |
{
|
|
|
76 |
String paramGet = "&coi_ce_observation="+idObs ;
|
|
|
77 |
raf = r ;
|
|
|
78 |
|
|
|
79 |
// et on envoie ça au serveur
|
|
|
80 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, oModele
|
|
|
81 |
.getConfig().getServiceBaseUrl()
|
|
|
82 |
+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
|
|
|
83 |
try {
|
|
|
84 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
85 |
|
|
|
86 |
public void onError(Request request, Throwable exception) {
|
|
|
87 |
// TODO Auto-generated method stub
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
public void onResponseReceived(Request request,
|
|
|
92 |
Response response) {
|
|
|
93 |
|
|
|
94 |
String baseUrl = "http://162.38.234.9/Documents/images_serveur/";
|
|
|
95 |
|
|
|
96 |
final JSONValue responseValue = JSONParser.parse(response
|
|
|
97 |
.getText());
|
|
|
98 |
// si c'est un tableau
|
|
|
99 |
if (responseValue.isArray() != null) {
|
|
|
100 |
|
|
|
101 |
final JSONArray reponse = responseValue.isArray();
|
|
|
102 |
|
|
|
103 |
final int taillemax = reponse.size();
|
|
|
104 |
|
|
|
105 |
String urlTab[] = new String[taillemax] ;
|
|
|
106 |
|
|
|
107 |
for(int i = 0 ;i<taillemax ;i++)
|
|
|
108 |
{
|
|
|
109 |
|
|
|
110 |
final JSONArray reponseInt = reponse.get(i).isArray();
|
|
|
111 |
String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
|
|
|
112 |
|
|
|
113 |
int maxZeros = 9 - idImg.length();
|
|
|
114 |
|
|
|
115 |
for (int j = 0; j < maxZeros; j++) {
|
|
|
116 |
idImg = "0" + idImg;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
String dossierNv1 = idImg.substring(0, 3);
|
|
|
120 |
String dossierNv2 = idImg.substring(3, 6);
|
|
|
121 |
String fichierNv = idImg.substring(6, 9);
|
|
|
122 |
|
|
|
123 |
String nomFichier = dossierNv1 + "_" + dossierNv2 + "_" + fichierNv;
|
|
|
124 |
|
|
|
125 |
String[] infosFichier = { nomFichier, dossierNv1, dossierNv2 };
|
|
|
126 |
|
|
|
127 |
String url_img = baseUrl + infosFichier[1] + "/" + infosFichier[2] + "/M/"
|
|
|
128 |
+ infosFichier[0] + "_M.jpg";
|
|
|
129 |
|
|
|
130 |
urlTab[i]= url_img ;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
raf.rafraichir(urlTab, false) ;
|
|
|
134 |
}
|
|
|
135 |
else
|
|
|
136 |
{
|
|
|
137 |
String urlTab[] = new String[0] ;
|
|
|
138 |
raf.rafraichir(urlTab, false) ;
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
});
|
|
|
143 |
|
|
|
144 |
} catch (RequestException e) {
|
|
|
145 |
// TODO Auto-generated catch block
|
|
|
146 |
e.printStackTrace();
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
5 |
aperonnet |
150 |
public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
|
|
|
151 |
|
|
|
152 |
String postData = "";
|
|
|
153 |
|
|
|
154 |
postData += "&coi_ce_image="+idsImages ;
|
|
|
155 |
postData += "&coi_ce_observation="+idsObs ;
|
|
|
156 |
postData += "&identifiant="+iModele.getIdentifiant() ;
|
|
|
157 |
|
|
|
158 |
// et on envoie ça au serveur
|
|
|
159 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, iModele
|
|
|
160 |
.getConfig().getServiceBaseUrl()
|
|
|
161 |
+ "/inventoryImageLink/");
|
62 |
jpm |
162 |
|
|
|
163 |
if(Window.confirm("Lier les images "+idsImages+" aux observations "+idsObs+" ?"))
|
|
|
164 |
{
|
|
|
165 |
try {
|
|
|
166 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
167 |
|
|
|
168 |
public void onError(Request request, Throwable exception) {
|
|
|
169 |
// TODO Auto-generated method stub
|
|
|
170 |
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
public void onResponseReceived(Request request,
|
|
|
174 |
Response response) {
|
|
|
175 |
|
|
|
176 |
// quand la requête est éxecutée on le signale au modèle
|
|
|
177 |
// poru qu'il mette à jour les données
|
|
|
178 |
// et en notifie le médiateur
|
|
|
179 |
// iModele.requeteTerminee();
|
|
|
180 |
|
|
|
181 |
}
|
|
|
182 |
});
|
|
|
183 |
|
|
|
184 |
} catch (RequestException e) {
|
|
|
185 |
// TODO Auto-generated catch block
|
|
|
186 |
e.printStackTrace();
|
|
|
187 |
}
|
5 |
aperonnet |
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|