Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 155 → Rev 156

/trunk/src/org/tela_botanica/client/modeles/StructureListeAsyncDao.java
File deleted
/trunk/src/org/tela_botanica/client/modeles/StructureAsyncDao.java
13,11 → 13,83
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
 
public class StructureAsyncDao {
 
public void selectionner(final Rafraichissable r, String idUtilisateur, final String idStr) {
// Ajout des paramètres et données à selectionner dans l'URL
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() +
"CoelStructureListe/" +
(idStr == null ? "" : idStr) +
"";
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
try {
rb.sendRequest(null, new RequestCallback() {
 
public void onError(Request request, Throwable exception) {
// Gestion des exceptions déclenchées par l'exécution de la requête
GWT.log("Erreur à l'exécution du service CoelStructureListe (selection)", exception);
Info.display("Erreur de Requête", "Une erreur s'est produite lors de l'exécution de la requête.");
}
public void onErrorHTTP(Request request, Response reponse) {
// Gestion des erreurs HTTP renvoyé par Apache ou JRest
Information info = new Information("erreur_jrest", JSONParser.parse(reponse.getText()).isArray());
GWT.log("Erreur JREST - Code "+reponse.getStatusCode()+"\n"+info.getMessages().toString(), null);
Info.display("Erreur JREST - Code "+reponse.getStatusCode(), info.toString());
}
public void onResponseReceived(Request request, Response response) {
// Si le code de réponse HTTP ne vaut pas 200 OK, on lance le mécanise d'erreur HTTP
if (response.getStatusCode() != 200) {
onErrorHTTP(request, response);
} else {
if (response.getText().length() != 0 && response.getText() != null) {
final JSONValue responseValue = JSONParser.parse(response.getText());
// Si la requête est un succès, reception d'un objet ou d'un tableau
if (responseValue.isObject() != null) {
final JSONObject reponse = responseValue.isObject();
// Transformation du tableau JSON réponse en ListeInstitution
Structure structure = new Structure(reponse);
Information info = new Information("selection_structure", structure);
r.rafraichir(info);
} else if (responseValue.isArray() != null) {
final JSONArray reponse = responseValue.isArray();
// Transformation du tableau JSON réponse en ListeInstitution
StructureListe structures = new StructureListe(reponse);
// et on met à jour le demandeur des données
r.rafraichir(structures);
} else {
GWT.log(url+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
}
} else {
if (idStr == null) {
// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
StructureListe structures = new StructureListe(0);
r.rafraichir(structures);
} else {
GWT.log(url, null);
if (response.getText().length() == 0) {
GWT.log("\tLa réponse a une taille de 0", null);
}
if (response.getText() == null) {
GWT.log("\tLa réponse vaul null", null);
}
}
}
}
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
public void ajouter(final Rafraichissable r, String utilisateurId, final Structure str) {
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() +
"CoelStructureListe/";
52,7 → 124,7
 
public void onError(Request request, Throwable exception) {
// Gestion des exceptions déclenchées par l'exécution de la requête
GWT.log("Erreur à l'exécution du service CoelStructureListe", exception);
GWT.log("Erreur à l'exécution du service CoelStructureListe (ajout)", exception);
Info.display("Erreur de Requête", "Une erreur s'est produite lors de l'exécution de la requête.");
}
114,8 → 186,9
rb.sendRequest(postDonnees, new RequestCallback() {
 
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
// Gestion des exceptions déclenchées par l'exécution de la requête
GWT.log("Erreur à l'exécution du service CoelStructureListe (suppression)", exception);
Info.display("Erreur de Requête", "Une erreur s'est produite lors de l'exécution de la requête.");
}
 
public void onErrorHTTP(Request request, Response reponse) {
133,7 → 206,7
if (response.getText().length() != 0 && response.getText() != null) {
final JSONValue responseValue = JSONParser.parse(response.getText());
// Si la requête est un succès, reception d'un tableau
// Si la requête est un succès, reception d'une chaine
if (responseValue.isString() != null) {
Information info = new Information("suppression_structure", responseValue.isString().stringValue());
r.rafraichir(info);
/trunk/src/org/tela_botanica/client/modeles/Information.java
8,10 → 8,15
private String type = null;
private ArrayList<String> messages = null;
 
private ArrayList<Object> donnees = null;
public Information() {
messages = new ArrayList<String>();
}
 
public Information(String t) {
type = t;
}
public Information(String t, String m) {
messages = new ArrayList<String>();
29,6 → 34,13
type = t;
}
 
public Information(String t, Object o) {
donnees = new ArrayList<Object>();
donnees.add(o);
type = t;
}
 
public void setType(String t) {
type = t;
}
46,12 → 58,25
public ArrayList<String> getMessages() {
return messages;
}
public void setDonnee(Object objet) {
donnees.add(objet);
}
public Object getDonnee(int index) {
return donnees.get(index);
}
public ArrayList<Object> getDonnees() {
return donnees;
}
 
public String toString() {
String chaine = new String();
for(int i = 0 ; i < messages.size() ; i++) {
// GXT ne prend pas en compte /n ou /r/n...
chaine += getMessage(i)+"\n";
if (messages != null) {
for(int i = 0 ; i < messages.size() ; i++) {
// GXT ne prend pas en compte /n ou /r/n...
chaine += getMessage(i)+"\n";
}
}
return chaine;
}
/trunk/src/org/tela_botanica/client/modeles/Structure.java
1,8 → 1,10
package org.tela_botanica.client.modeles;
 
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
 
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.json.client.JSONObject;
 
public class Structure extends aDonnee {
125,13 → 127,21
return (String) renvoyerValeurCorrecte("adresse_02");
}
 
public String getDateFondation() {
return (String) renvoyerValeurCorrecte("date_fondation");
public Date getDateFondation() {
return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").parse((String) renvoyerValeurCorrecte("date_fondation"));
}
public void setDateFondation(Date dateFondation) {
if (dateFondation != null) {
DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(dateFondation);
this.set("date_fondation", dateFondation.toString());
}
}
public void setDateFondation(String dateFondation) {
this.set("date_fondation", dateFondation);
if (dateFondation != null) {
this.set("date_fondation", dateFondation);
}
}
public String getCodePostal() {
return (String) renvoyerValeurCorrecte("code_postal");
}
/trunk/src/org/tela_botanica/client/modeles/StructureListe.java
38,17 → 38,17
* Constructeur pour une liste d'institutions
* @param dates
*/
public StructureListe(JSONArray institutions)
public StructureListe(JSONArray structures)
{
super(institutions.size()) ;
final int taillemax = institutions.size();
super(structures.size()) ;
final int taillemax = structures.size();
for (int i = 0; i < taillemax; i++) {
JSONObject institutionCourante = institutions.get(i).isObject() ;
JSONObject structureCourante = structures.get(i).isObject() ;
if (institutionCourante != null) {
Structure institution = new Structure(institutionCourante);
this.put(institution.getId(), institution);
if (structureCourante != null) {
Structure structure = new Structure(structureCourante);
this.put(structure.getId(), structure);
}
}
}