Subversion Repositories eFlore/Applications.coel

Rev

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

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