Subversion Repositories eFlore/Applications.coel

Rev

Rev 277 | Rev 711 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 277 Rev 707
Line 1... Line 1...
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
Line 2... Line -...
2
 
-
 
3
import org.tela_botanica.client.Modele;
2
 
-
 
3
import org.tela_botanica.client.RegistreId;
-
 
4
import org.tela_botanica.client.http.JsonRestRequestBuilder;
4
import org.tela_botanica.client.RegistreId;
5
import org.tela_botanica.client.http.JsonRestRequestCallback;
Line 5... Line 6...
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
6
 
7
 
7
import com.extjs.gxt.ui.client.Registry;
8
import com.extjs.gxt.ui.client.Registry;
Line 13... Line 14...
13
import com.google.gwt.http.client.Response;
14
import com.google.gwt.http.client.Response;
14
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONObject;
16
import com.google.gwt.json.client.JSONObject;
16
import com.google.gwt.json.client.JSONParser;
17
import com.google.gwt.json.client.JSONParser;
17
import com.google.gwt.json.client.JSONValue;
18
import com.google.gwt.json.client.JSONValue;
18
import com.google.gwt.user.client.Window;
-
 
Line 19... Line 19...
19
 
19
 
20
public class PublicationAsyncDao {
20
public class PublicationAsyncDao {
Line 21... Line 21...
21
	private static final String SERVICE_NOM = "CoelPublication";
21
	private static final String SERVICE_NOM = "CoelPublication";
22
	
22
	
Line 23... Line 23...
23
	private PublicationListe publications = null;
23
	private PublicationListe publications = null;
24
	private Rafraichissable rafraichissement = null;
-
 
25
	
24
	private Rafraichissable vueARafraichir = null;
26
	public PublicationAsyncDao(Rafraichissable r) {
25
	
Line 27... Line 26...
27
		
26
	public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
28
		rafraichissement = r ;
27
		vueARafraichir = vueARafraichirCourrante ;
29
	}
28
	}
30
 
-
 
31
	public void obtenirListePublication() {
-
 
32
    	// Demande de toutes les structures
29
 
33
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
30
	public void selectionnerPublication(final String publicationId, String projetId, String nomComplet) {
34
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+SERVICE_NOM+"/");
-
 
35
 
31
		// Ajout des paramètres et données à selectionner dans l'URL
36
		try {
32
		final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() + 
37
			rb.sendRequest(null, new RequestCallback() {
-
 
38
 
33
			SERVICE_NOM + "/" +
Line -... Line 34...
-
 
34
			(projetId == null ? "*" : projetId) + "/" +
-
 
35
			(publicationId == null ? "*" : publicationId) + "/" +
39
				public void onError(Request request, Throwable exception) {
36
			(nomComplet == null ? "*" : nomComplet) + "/" +
40
					// TODO Auto-generated method stub
37
			"";
41
 
38
 
42
				}
39
		JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
43
 
-
 
44
				public void onResponseReceived(Request request, Response response) {
40
		
45
					Boolean defaut = true;
41
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
46
					if (response.getText().length() != 0 && response.getText() != null) {
42
			@Override
47
						final JSONValue responseValue = JSONParser.parse(response.getText());
43
			public void surReponse(JSONValue responseValue) {
48
						
44
				if (responseValue != null) {
49
						// Si la requête est un succès, reception d'un tableau
45
					// Si la requête est un succès, reception d'un objet ou d'un tableau
50
						if (responseValue.isObject() != null) {
46
					if (responseValue.isObject() != null) {
-
 
47
						final JSONObject reponse = responseValue.isObject();
-
 
48
						// Transformation du tableau JSON réponse en ListeInstitution
51
							final JSONObject reponse = responseValue.isObject();
49
						Publication publication = new Publication(reponse);
52
							// Transformation du tableau JSON réponse en ListeInstitution
50
						// et on met à jour le demandeur des données
53
							publications = new PublicationListe(reponse);
51
						vueARafraichir.rafraichir(publication);
-
 
52
					} else if (responseValue.isArray() != null) {
54
							// et on met à jour le demandeur des données
53
						final JSONArray reponse = responseValue.isArray();
-
 
54
						PublicationListe publications = new PublicationListe(reponse);
-
 
55
						vueARafraichir.rafraichir(publications);
55
							rafraichissement.rafraichir(publications);
56
					} else {
56
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
57
						GWT.log(url+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
57
							defaut = false;
58
					}
58
						}
59
				} else {
59
					}
60
					// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
60
					if (defaut == true) {
61
					if (publicationId == null) {
61
						publications = new PublicationListe(0);
-
 
62
						rafraichissement.rafraichir(publications);
-
 
63
					}
62
						PublicationListe publications = new PublicationListe(0);
64
				}
63
						vueARafraichir.rafraichir(publications);								
Line 65... Line 64...
65
			});
64
					}
66
		} catch (RequestException e) {
65
				}
67
			e.printStackTrace();
66
			}
Line 90... Line 89...
90
						if (responseValue.isArray() != null) {
89
						if (responseValue.isArray() != null) {
91
							final JSONObject reponse = responseValue.isObject();
90
							final JSONObject reponse = responseValue.isObject();
92
							// Transformation du tableau JSON réponse en ListeInstitution
91
							// Transformation du tableau JSON réponse en ListeInstitution
93
							publications = new PublicationListe(reponse);
92
							publications = new PublicationListe(reponse);
94
							// et on met à jour le demandeur des données
93
							// et on met à jour le demandeur des données
95
							rafraichissement.rafraichir(publications);
94
							vueARafraichir.rafraichir(publications);
96
							// 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
97
							defaut = false;
96
							defaut = false;
98
						}
97
						}
99
					}
98
					}
100
					if (defaut == true) {
99
					if (defaut == true) {
101
						publications = new PublicationListe(0);
100
						publications = new PublicationListe(0);
102
						rafraichissement.rafraichir(publications);
101
						vueARafraichir.rafraichir(publications);
103
					}
102
					}
104
				}
103
				}
105
			});
104
			});
106
		} catch (RequestException e) {
105
		} catch (RequestException e) {
107
			e.printStackTrace();
106
			e.printStackTrace();
Line 129... Line 128...
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
							vueARafraichir.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
						vueARafraichir.rafraichir(publications);
142
					}
141
					}
143
				}
142
				}
144
			});
143
			});
145
		} catch (RequestException e) {
144
		} catch (RequestException e) {
146
			e.printStackTrace();
145
			e.printStackTrace();
Line 170... Line 169...
170
						if (responseValue.isObject() != null) {
169
						if (responseValue.isObject() != null) {
171
							final JSONObject reponse = responseValue.isObject();
170
							final JSONObject reponse = responseValue.isObject();
172
							// Transformation du tableau JSON réponse en ListeInstitution
171
							// Transformation du tableau JSON réponse en ListeInstitution
173
							publications = new PublicationListe(reponse);
172
							publications = new PublicationListe(reponse);
174
							// et on met à jour le demandeur des données
173
							// et on met à jour le demandeur des données
175
							rafraichissement.rafraichir(publications);
174
							vueARafraichir.rafraichir(publications);
176
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
175
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
177
							defaut = false;
176
							defaut = false;
178
						}
177
						}
179
					}
178
					}
180
					if (defaut == true) {
179
					if (defaut == true) {
181
						publications = new PublicationListe(0);
180
						publications = new PublicationListe(0);
182
						rafraichissement.rafraichir(publications);
181
						vueARafraichir.rafraichir(publications);
183
					}
182
					}
184
				}
183
				}
185
			});
184
			});
186
		} catch (RequestException e) {
185
		} catch (RequestException e) {
187
			e.printStackTrace();
186
			e.printStackTrace();