1,5 → 1,13 |
package org.tela_botanica.client; |
|
import com.google.gwt.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
|
public class InventoryItem { |
|
// TODO : Singleton ? |
13,15 → 21,23 |
private String comment=null; |
private String ordre=null; |
|
private Mediator mediator = null; |
private String serviceBaseUrl = null; |
|
|
|
// Constructeur |
|
|
// Constructeur sur saisie |
|
public InventoryItem() { |
public InventoryItem(Mediator med) { |
|
mediator=med; |
|
serviceBaseUrl = mediator.getServiceBaseUrl(); |
|
|
} |
|
|
50,45 → 66,203 |
|
} |
|
|
public boolean isValid() { |
// TODO : controle date |
|
if (name.compareTo("")==0) { |
return false; |
} |
else { |
return true; |
} |
|
} |
|
/** |
* Lancement de la creation d'une ligne d'inventaire (appele par Mediator.onAddInventoryItem()) |
* |
*/ |
|
|
public void addelement() { |
|
|
if (isValid()) { |
|
|
// Creation d'un nom faisant parti du referentiel : recherche du nom valide correspondant |
|
public String getLocation() { |
return location; |
if (nomenclaturalNumber !=null) { |
|
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber, |
new ResponseTextHandler() { |
|
public void onCompletion(String strcomplete) { |
|
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
|
if ((jsonArray = jsonValue.isArray()) != null) { |
// Nom retenu, Num Nomen nom retenu, Num Taxon, |
// Famille |
addElement(name, nomenclaturalNumber, |
Util.toCelString(((JSONString) jsonArray.get(0)) |
.toString()), |
((JSONString) jsonArray.get(1)) |
.stringValue(), |
((JSONString) jsonArray.get(2)) |
.stringValue(), |
Util.toCelString(((JSONString) jsonArray.get(3)) |
.toString()), |
location,location_id,date,milieu,comment); |
} |
} |
|
}); |
} |
// Saisie libre |
else { |
addElement(name, " ", " ", " ", " ", " ",location,location_id,date,milieu,comment); |
} |
|
} |
else { |
// TODO : message d'erreur |
return; |
} |
} |
|
|
|
/** |
* Ajoute effectif d'un element a l'inventaire (appel interne) |
* |
* @param nom_sel : |
* nom selectionne |
* @param num_nom_sel : |
* numero nomenclatural nom selectionne |
* @param nom_ret : |
* nom retenu |
* @param num_nom_ret : |
* numero nomenclaturel nom retenu |
* @param num_taxon : |
* numero taxonomique |
* @param famille : |
* famille |
*/ |
|
private void addElement(String nom_sel, String num_nom_sel, String nom_ret, |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) { |
|
public String getLocation_id() { |
return location_id; |
} |
|
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant=" |
+ mediator.getUser() + "&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat |
+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment), |
|
public String getName() { |
return name; |
new ResponseTextHandler() { |
|
public void onCompletion(String str) { |
mediator.onInventoryUpdated(location); |
} |
}); |
} |
|
|
|
public String getNomenclaturalNumber() { |
return nomenclaturalNumber; |
/** |
* Lancement de la mise a jour d'une ligne d'inventaire (appele par Mediator.onModifyInventoryItem()) |
* |
*/ |
|
public void updateElement() { |
|
|
if (isValid()) { |
|
|
// Modification d'un nom faisant parti du referentiel : recherche du nom valide correspondant |
|
if (nomenclaturalNumber !=null) { |
|
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber, |
new ResponseTextHandler() { |
|
public void onCompletion(String strcomplete) { |
|
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
|
if ((jsonArray = jsonValue.isArray()) != null) { |
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille |
updateElement(ordre,name, nomenclaturalNumber, |
Util.toCelString(((JSONString) jsonArray.get(0)) |
.toString()), |
((JSONString) jsonArray.get(1)) |
.stringValue(), |
((JSONString) jsonArray.get(2)) |
.stringValue(), |
Util.toCelString(((JSONString) jsonArray.get(3)) |
.toString()), |
location,location_id,date,milieu,comment); |
} |
} |
|
}); |
} |
// Modification d'un nom ne faisant pas parti du referentiel (saisie libre) |
else { |
updateElement(ordre,name, " ", " ", " ", " ", " ",location,location_id,date,milieu,comment); |
} |
|
} |
else { |
// TODO : message d'erreur |
return; |
} |
} |
|
|
|
public String getComment() { |
return comment; |
} |
|
|
/** |
* Modification effective d'un element de l'inventaire (appel interne) |
* |
* @param ordre : numero d'ordre |
* @param nom_sel : |
* nom selectionne |
* @param num_nom_sel : |
* numero nomenclatural nom selectionne |
* @param nom_ret : |
* nom retenu |
* @param num_nom_ret : |
* numero nomenclaturel nom retenu |
* @param num_taxon : |
* numero taxonomique |
* @param famille : |
* famille |
*/ |
|
public String getMilieu() { |
return milieu; |
} |
private void updateElement(String ordre, String nom_sel, String num_nom_sel, String nom_ret, |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) { |
|
|
public String getDate() { |
return date; |
} |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + mediator.getUser() + "/" +ordre + "/", |
"&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat |
+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment), |
|
new ResponseTextHandler() { |
|
public String getOrdre() { |
return ordre; |
public void onCompletion(String str) { |
mediator.onInventoryUpdated(location); |
} |
}); |
} |
|
|
} |