Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 27 Rev 28
1
package org.tela_botanica.client;
1
package org.tela_botanica.client;
-
 
2
 
-
 
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;
2
 
10
 
3
public class InventoryItem {
11
public class InventoryItem {
4
 
12
 
5
	// TODO : Singleton ?
13
	// TODO : Singleton ?
6
	
14
	
7
	private String name=null;
15
	private String name=null;
8
	private String nomenclaturalNumber=null;
16
	private String nomenclaturalNumber=null;
9
	private String location=null;
17
	private String location=null;
10
	private String location_id=null;
18
	private String location_id=null;
11
	private String date=null;
19
	private String date=null;
12
	private String milieu=null;
20
	private String milieu=null;
13
	private String comment=null;
21
	private String comment=null;
14
	private String ordre=null;
22
	private String ordre=null;
-
 
23
 
-
 
24
	private Mediator mediator = null;
-
 
25
	private String serviceBaseUrl = null;
15
 
26
 
16
 
27
	
17
	
28
	
18
//	 Constructeur  
29
//	 Constructeur  
19
	
30
	
20
	
31
	
21
	// Constructeur sur saisie 
32
	// Constructeur sur saisie 
22
	
33
	
-
 
34
	public InventoryItem(Mediator med) {
-
 
35
 
-
 
36
			mediator=med;
-
 
37
			
-
 
38
			serviceBaseUrl = mediator.getServiceBaseUrl();
23
	public InventoryItem() {
39
			
24
 
40
		
25
	}
41
	}
26
 
42
 
27
	
43
	
28
	// Alimentation contenu depuis saisie
44
	// Alimentation contenu depuis saisie
29
	
45
	
30
	public void setContent(String name,String nomenclaturalNumber, String location, String location_id, String date, String milieu, String comment,String ordre) {
46
	public void setContent(String name,String nomenclaturalNumber, String location, String location_id, String date, String milieu, String comment,String ordre) {
31
 
47
 
32
		
48
		
33
		this.name=name;
49
		this.name=name;
34
		this.nomenclaturalNumber=nomenclaturalNumber;
50
		this.nomenclaturalNumber=nomenclaturalNumber;
35
 
51
 
36
	 // Suppresion indication departementale (on pourrait faire mieux !!)
52
	 // Suppresion indication departementale (on pourrait faire mieux !!)
37
		int pos=location.indexOf(" (" );
53
		int pos=location.indexOf(" (" );
38
	    if (pos>=0) {
54
	    if (pos>=0) {
39
	    	this.location=location.substring(0,pos);
55
	    	this.location=location.substring(0,pos);
40
	    }
56
	    }
41
		else {
57
		else {
42
			 this.location=location;
58
			 this.location=location;
43
		}
59
		}
44
		 
60
		 
45
		this.location_id=location_id;
61
		this.location_id=location_id;
46
		this.date=date;
62
		this.date=date;
47
		this.milieu=milieu;
63
		this.milieu=milieu;
48
		this.comment=comment;
64
		this.comment=comment;
49
		this.ordre=ordre;
65
		this.ordre=ordre;
50
		
66
		
51
	}
67
	}
52
 
68
 
-
 
69
	
-
 
70
	public boolean isValid() {
53
 
71
		// TODO : controle date
54
 
72
		
55
	public String getLocation() {
73
	    if (name.compareTo("")==0) {
-
 
74
	    	return false;
-
 
75
	    }
-
 
76
	    else {
-
 
77
	    	return true;
-
 
78
	    }
56
		return location;
79
		
-
 
80
	}
-
 
81
 
-
 
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
-
 
95
 
57
	}
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
			
58
 
129
		}
59
 
130
	else {
60
	public String getLocation_id() {
-
 
61
		return location_id;
-
 
62
	}
-
 
63
 
-
 
64
 
131
		// TODO : message d'erreur
-
 
132
		return;
65
	public String getName() {
133
	}
66
		return name;
134
	}
-
 
135
	
-
 
136
	
-
 
137
	
-
 
138
	/**
-
 
139
	 * Ajoute effectif d'un element a l'inventaire (appel interne)
-
 
140
	 * 
67
	}
141
	 * @param nom_sel :
-
 
142
	 *            nom selectionne
-
 
143
	 * @param num_nom_sel :
-
 
144
	 *            numero nomenclatural nom selectionne
68
 
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
	 */
-
 
154
 
-
 
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) {
-
 
157
 
-
 
158
 
-
 
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),
-
 
164
 
-
 
165
		new ResponseTextHandler() {
-
 
166
 
-
 
167
			public void onCompletion(String str) {
69
 
168
					mediator.onInventoryUpdated(location);
-
 
169
			}
-
 
170
		});
70
	public String getNomenclaturalNumber() {
171
	}
71
		return nomenclaturalNumber;
172
 
72
	}
173
	
-
 
174
 
-
 
175
	/**
73
 
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
	
74
 
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 {
75
	public String getComment() {
217
					updateElement(ordre,name, " ", " ", " ", " ", " ",location,location_id,date,milieu,comment);
76
		return comment;
218
				}
77
	}
-
 
78
 
-
 
79
 
-
 
80
	public String getMilieu() {
-
 
81
		return milieu;
219
			
-
 
220
		}
-
 
221
	else {
-
 
222
		// TODO : message d'erreur
-
 
223
		return;
-
 
224
	}
-
 
225
	}
-
 
226
 
-
 
227
	
-
 
228
 
82
	}
229
	
-
 
230
 
83
 
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
	 */
-
 
248
 
-
 
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) {
-
 
251
 
-
 
252
 
-
 
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
84
 
257
				+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment),
-
 
258
 
85
	public String getDate() {
259
		new ResponseTextHandler() {
86
		return date;
260
 
87
	}
261
			public void onCompletion(String str) {
88
 
262
				mediator.onInventoryUpdated(location);
89
 
263
			}
90
	public String getOrdre() {
264
		});
91
		return ordre;
265
	}
92
	}
266
	
93
	
267
	
94
}
268
}