Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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