Subversion Repositories eFlore/Applications.coel

Rev

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

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