Subversion Repositories eFlore/Applications.coel

Rev

Rev 114 | Rev 238 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
106 aurelien 1
package org.tela_botanica.client.modeles;
2
 
230 aurelien 3
import org.tela_botanica.client.Modele;
106 aurelien 4
import org.tela_botanica.client.RegistreId;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
 
7
import com.extjs.gxt.ui.client.Registry;
8
import com.google.gwt.http.client.Request;
9
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.Response;
13
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONParser;
15
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.user.client.Window;
17
 
18
public class PublicationListeAsyncDao {
19
 
20
	private PublicationListe publications = null;
21
	private Rafraichissable rafraichissement = null;
22
 
23
	public PublicationListeAsyncDao(Rafraichissable r) {
24
 
25
		rafraichissement = r ;
26
	}
27
 
28
	public void obtenirListePublication() {
29
    	// Demande de toutes les structures
30
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
31
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelPublicationListe/");
32
 
33
		try {
34
			rb.sendRequest(null, new RequestCallback() {
35
 
36
				public void onError(Request request, Throwable exception) {
37
					// TODO Auto-generated method stub
38
 
39
				}
40
 
41
				public void onResponseReceived(Request request, Response response) {
114 jpm 42
					Boolean defaut = true;
43
					if (response.getText().length() != 0 && response.getText() != null) {
44
						final JSONValue responseValue = JSONParser.parse(response.getText());
106 aurelien 45
 
114 jpm 46
						// Si la requête est un succès, reception d'un tableau
47
						if (responseValue.isArray() != null) {
48
							final JSONArray reponse = responseValue.isArray();
49
							// Transformation du tableau JSON réponse en ListeInstitution
50
							publications = new PublicationListe(reponse);
51
							// et on met à jour le demandeur des données
52
							rafraichissement.rafraichir(publications);
53
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
54
							defaut = false;
55
						}
106 aurelien 56
					}
114 jpm 57
					if (defaut == true) {
106 aurelien 58
						publications = new PublicationListe(0);
59
						rafraichissement.rafraichir(publications);
60
					}
61
				}
62
			});
63
		} catch (RequestException e) {
64
			e.printStackTrace();
65
		}
66
	}
230 aurelien 67
 
68
	public void modifierPublication(final Rafraichissable r, String idUtilisateur, Publication pubAModifier) {
69
		// Demande de toutes les structures
70
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
71
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+"CoelPublicationListe/"+idUtilisateur);
106 aurelien 72
 
230 aurelien 73
		try {
74
			rb.sendRequest(pubAModifier.toReqString(), new RequestCallback() {
75
 
76
				public void onError(Request request, Throwable exception) {
77
					// TODO Auto-generated method stub
78
 
79
				}
80
 
81
				public void onResponseReceived(Request request, Response response) {
82
					Boolean defaut = true;
83
					if (response.getText().length() != 0 && response.getText() != null) {
84
						final JSONValue responseValue = JSONParser.parse(response.getText());
85
 
86
						// Si la requête est un succès, reception d'un tableau
87
						if (responseValue.isArray() != null) {
88
							final JSONArray reponse = responseValue.isArray();
89
							// Transformation du tableau JSON réponse en ListeInstitution
90
							publications = new PublicationListe(reponse);
91
							// et on met à jour le demandeur des données
92
							rafraichissement.rafraichir(publications);
93
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
94
							defaut = false;
95
						}
96
					}
97
					if (defaut == true) {
98
						publications = new PublicationListe(0);
99
						rafraichissement.rafraichir(publications);
100
					}
101
				}
102
			});
103
		} catch (RequestException e) {
104
			e.printStackTrace();
105
		}
106
	}
107
 
108
	public void ajouterPublication(Modele modele, String utilisateurId,
109
			Publication pubAModifier) {
110
		String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
111
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+"CoelPublicationListe/");
112
 
113
		try {
114
			rb.sendRequest(pubAModifier.toReqString()+"&id_utilisateur="+utilisateurId, new RequestCallback() {
115
 
116
				public void onError(Request request, Throwable exception) {
117
					// TODO Auto-generated method stub
118
 
119
				}
120
 
121
				public void onResponseReceived(Request request, Response response) {
122
					Boolean defaut = true;
123
					if (response.getText().length() != 0 && response.getText() != null) {
124
						final JSONValue responseValue = JSONParser.parse(response.getText());
125
 
126
						// Si la requête est un succès, reception d'un tableau
127
						if (responseValue.isArray() != null) {
128
							final JSONArray reponse = responseValue.isArray();
129
							// Transformation du tableau JSON réponse en ListeInstitution
130
							publications = new PublicationListe(reponse);
131
							// et on met à jour le demandeur des données
132
							rafraichissement.rafraichir(publications);
133
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
134
							defaut = false;
135
						}
136
					}
137
					if (defaut == true) {
138
						publications = new PublicationListe(0);
139
						rafraichissement.rafraichir(publications);
140
					}
141
				}
142
			});
143
		} catch (RequestException e) {
144
			e.printStackTrace();
145
		}
146
 
147
	}
148
 
106 aurelien 149
}