Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 29 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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