| 12 |
ddelon |
1 |
package org.tela_botanica.client;
|
|
|
2 |
|
| 28 |
ddelon |
3 |
import com.google.gwt.http.client.URL;
|
|
|
4 |
import com.google.gwt.json.client.JSONArray;
|
|
|
5 |
import com.google.gwt.json.client.JSONParser;
|
|
|
6 |
import com.google.gwt.json.client.JSONString;
|
|
|
7 |
import com.google.gwt.json.client.JSONValue;
|
|
|
8 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
9 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
10 |
|
| 12 |
ddelon |
11 |
public class InventoryItem {
|
|
|
12 |
|
| 27 |
ddelon |
13 |
// TODO : Singleton ?
|
| 12 |
ddelon |
14 |
|
|
|
15 |
private String name=null;
|
|
|
16 |
private String nomenclaturalNumber=null;
|
|
|
17 |
private String location=null;
|
|
|
18 |
private String location_id=null;
|
|
|
19 |
private String date=null;
|
| 27 |
ddelon |
20 |
private String milieu=null;
|
| 12 |
ddelon |
21 |
private String comment=null;
|
| 13 |
ddelon |
22 |
private String ordre=null;
|
| 12 |
ddelon |
23 |
|
| 28 |
ddelon |
24 |
private Mediator mediator = null;
|
|
|
25 |
private String serviceBaseUrl = null;
|
| 27 |
ddelon |
26 |
|
| 12 |
ddelon |
27 |
|
| 28 |
ddelon |
28 |
|
| 27 |
ddelon |
29 |
// Constructeur
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
// Constructeur sur saisie
|
|
|
33 |
|
| 28 |
ddelon |
34 |
public InventoryItem(Mediator med) {
|
| 12 |
ddelon |
35 |
|
| 28 |
ddelon |
36 |
mediator=med;
|
|
|
37 |
|
|
|
38 |
serviceBaseUrl = mediator.getServiceBaseUrl();
|
|
|
39 |
|
|
|
40 |
|
| 27 |
ddelon |
41 |
}
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
// Alimentation contenu depuis saisie
|
|
|
45 |
|
|
|
46 |
public void setContent(String name,String nomenclaturalNumber, String location, String location_id, String date, String milieu, String comment,String ordre) {
|
|
|
47 |
|
| 12 |
ddelon |
48 |
|
|
|
49 |
this.name=name;
|
|
|
50 |
this.nomenclaturalNumber=nomenclaturalNumber;
|
|
|
51 |
|
|
|
52 |
// Suppresion indication departementale (on pourrait faire mieux !!)
|
|
|
53 |
int pos=location.indexOf(" (" );
|
|
|
54 |
if (pos>=0) {
|
|
|
55 |
this.location=location.substring(0,pos);
|
|
|
56 |
}
|
|
|
57 |
else {
|
|
|
58 |
this.location=location;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
this.location_id=location_id;
|
|
|
62 |
this.date=date;
|
| 27 |
ddelon |
63 |
this.milieu=milieu;
|
| 12 |
ddelon |
64 |
this.comment=comment;
|
| 13 |
ddelon |
65 |
this.ordre=ordre;
|
| 12 |
ddelon |
66 |
|
|
|
67 |
}
|
|
|
68 |
|
| 28 |
ddelon |
69 |
|
|
|
70 |
public boolean isValid() {
|
|
|
71 |
// TODO : controle date
|
|
|
72 |
|
|
|
73 |
if (name.compareTo("")==0) {
|
|
|
74 |
return false;
|
|
|
75 |
}
|
|
|
76 |
else {
|
|
|
77 |
return true;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
}
|
| 12 |
ddelon |
81 |
|
| 28 |
ddelon |
82 |
/**
|
|
|
83 |
* Lancement de la creation d'une ligne d'inventaire (appele par Mediator.onAddInventoryItem())
|
|
|
84 |
*
|
|
|
85 |
*/
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
public void addelement() {
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
if (isValid()) {
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
// Creation d'un nom faisant parti du referentiel : recherche du nom valide correspondant
|
| 27 |
ddelon |
95 |
|
| 28 |
ddelon |
96 |
if (nomenclaturalNumber !=null) {
|
|
|
97 |
|
|
|
98 |
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber,
|
|
|
99 |
new ResponseTextHandler() {
|
|
|
100 |
|
|
|
101 |
public void onCompletion(String strcomplete) {
|
|
|
102 |
|
|
|
103 |
JSONValue jsonValue = JSONParser.parse(strcomplete);
|
|
|
104 |
JSONArray jsonArray;
|
|
|
105 |
|
|
|
106 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
107 |
// Nom retenu, Num Nomen nom retenu, Num Taxon,
|
|
|
108 |
// Famille
|
|
|
109 |
addElement(name, nomenclaturalNumber,
|
|
|
110 |
Util.toCelString(((JSONString) jsonArray.get(0))
|
|
|
111 |
.toString()),
|
|
|
112 |
((JSONString) jsonArray.get(1))
|
|
|
113 |
.stringValue(),
|
|
|
114 |
((JSONString) jsonArray.get(2))
|
|
|
115 |
.stringValue(),
|
|
|
116 |
Util.toCelString(((JSONString) jsonArray.get(3))
|
|
|
117 |
.toString()),
|
|
|
118 |
location,location_id,date,milieu,comment);
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
});
|
|
|
123 |
}
|
|
|
124 |
// Saisie libre
|
|
|
125 |
else {
|
|
|
126 |
addElement(name, " ", " ", " ", " ", " ",location,location_id,date,milieu,comment);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
}
|
|
|
130 |
else {
|
|
|
131 |
// TODO : message d'erreur
|
|
|
132 |
return;
|
| 12 |
ddelon |
133 |
}
|
| 28 |
ddelon |
134 |
}
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* Ajoute effectif d'un element a l'inventaire (appel interne)
|
|
|
140 |
*
|
|
|
141 |
* @param nom_sel :
|
|
|
142 |
* nom selectionne
|
|
|
143 |
* @param num_nom_sel :
|
|
|
144 |
* numero nomenclatural nom selectionne
|
|
|
145 |
* @param nom_ret :
|
|
|
146 |
* nom retenu
|
|
|
147 |
* @param num_nom_ret :
|
|
|
148 |
* numero nomenclaturel nom retenu
|
|
|
149 |
* @param num_taxon :
|
|
|
150 |
* numero taxonomique
|
|
|
151 |
* @param famille :
|
|
|
152 |
* famille
|
|
|
153 |
*/
|
| 12 |
ddelon |
154 |
|
| 28 |
ddelon |
155 |
private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
|
|
|
156 |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) {
|
| 12 |
ddelon |
157 |
|
|
|
158 |
|
| 28 |
ddelon |
159 |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
|
|
|
160 |
+ mediator.getUser() + "&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel
|
|
|
161 |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret
|
|
|
162 |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat
|
|
|
163 |
+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment),
|
| 12 |
ddelon |
164 |
|
| 28 |
ddelon |
165 |
new ResponseTextHandler() {
|
|
|
166 |
|
|
|
167 |
public void onCompletion(String str) {
|
|
|
168 |
mediator.onInventoryUpdated(location);
|
|
|
169 |
}
|
|
|
170 |
});
|
| 12 |
ddelon |
171 |
}
|
|
|
172 |
|
| 28 |
ddelon |
173 |
|
| 12 |
ddelon |
174 |
|
| 28 |
ddelon |
175 |
/**
|
|
|
176 |
* Lancement de la mise a jour d'une ligne d'inventaire (appele par Mediator.onModifyInventoryItem())
|
|
|
177 |
*
|
|
|
178 |
*/
|
|
|
179 |
|
|
|
180 |
public void updateElement() {
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
if (isValid()) {
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
// Modification d'un nom faisant parti du referentiel : recherche du nom valide correspondant
|
|
|
187 |
|
|
|
188 |
if (nomenclaturalNumber !=null) {
|
|
|
189 |
|
|
|
190 |
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber,
|
|
|
191 |
new ResponseTextHandler() {
|
|
|
192 |
|
|
|
193 |
public void onCompletion(String strcomplete) {
|
|
|
194 |
|
|
|
195 |
JSONValue jsonValue = JSONParser.parse(strcomplete);
|
|
|
196 |
JSONArray jsonArray;
|
|
|
197 |
|
|
|
198 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
199 |
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
|
|
|
200 |
updateElement(ordre,name, nomenclaturalNumber,
|
|
|
201 |
Util.toCelString(((JSONString) jsonArray.get(0))
|
|
|
202 |
.toString()),
|
|
|
203 |
((JSONString) jsonArray.get(1))
|
|
|
204 |
.stringValue(),
|
|
|
205 |
((JSONString) jsonArray.get(2))
|
|
|
206 |
.stringValue(),
|
|
|
207 |
Util.toCelString(((JSONString) jsonArray.get(3))
|
|
|
208 |
.toString()),
|
|
|
209 |
location,location_id,date,milieu,comment);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
});
|
|
|
214 |
}
|
|
|
215 |
// Modification d'un nom ne faisant pas parti du referentiel (saisie libre)
|
|
|
216 |
else {
|
|
|
217 |
updateElement(ordre,name, " ", " ", " ", " ", " ",location,location_id,date,milieu,comment);
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
}
|
|
|
221 |
else {
|
|
|
222 |
// TODO : message d'erreur
|
|
|
223 |
return;
|
| 12 |
ddelon |
224 |
}
|
| 28 |
ddelon |
225 |
}
|
| 12 |
ddelon |
226 |
|
| 28 |
ddelon |
227 |
|
| 12 |
ddelon |
228 |
|
| 28 |
ddelon |
229 |
|
| 12 |
ddelon |
230 |
|
| 28 |
ddelon |
231 |
/**
|
|
|
232 |
* Modification effective d'un element de l'inventaire (appel interne)
|
|
|
233 |
*
|
|
|
234 |
* @param ordre : numero d'ordre
|
|
|
235 |
* @param nom_sel :
|
|
|
236 |
* nom selectionne
|
|
|
237 |
* @param num_nom_sel :
|
|
|
238 |
* numero nomenclatural nom selectionne
|
|
|
239 |
* @param nom_ret :
|
|
|
240 |
* nom retenu
|
|
|
241 |
* @param num_nom_ret :
|
|
|
242 |
* numero nomenclaturel nom retenu
|
|
|
243 |
* @param num_taxon :
|
|
|
244 |
* numero taxonomique
|
|
|
245 |
* @param famille :
|
|
|
246 |
* famille
|
|
|
247 |
*/
|
| 12 |
ddelon |
248 |
|
| 28 |
ddelon |
249 |
private void updateElement(String ordre, String nom_sel, String num_nom_sel, String nom_ret,
|
|
|
250 |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) {
|
| 12 |
ddelon |
251 |
|
|
|
252 |
|
| 28 |
ddelon |
253 |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + mediator.getUser() + "/" +ordre + "/",
|
|
|
254 |
"&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel
|
|
|
255 |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret
|
|
|
256 |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat
|
|
|
257 |
+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment),
|
| 13 |
ddelon |
258 |
|
| 28 |
ddelon |
259 |
new ResponseTextHandler() {
|
| 13 |
ddelon |
260 |
|
| 28 |
ddelon |
261 |
public void onCompletion(String str) {
|
|
|
262 |
mediator.onInventoryUpdated(location);
|
|
|
263 |
}
|
|
|
264 |
});
|
| 13 |
ddelon |
265 |
}
|
| 12 |
ddelon |
266 |
|
| 28 |
ddelon |
267 |
|
| 12 |
ddelon |
268 |
}
|