Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 114 Rev 230
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.RegistreId;
4
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
6
 
6
import com.extjs.gxt.ui.client.Registry;
7
import com.extjs.gxt.ui.client.Registry;
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.http.client.Response;
12
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONValue;
15
import com.google.gwt.json.client.JSONValue;
15
import com.google.gwt.user.client.Window;
16
import com.google.gwt.user.client.Window;
16
 
17
 
17
public class PublicationListeAsyncDao {
18
public class PublicationListeAsyncDao {
18
 
19
 
19
	private PublicationListe publications = null;
20
	private PublicationListe publications = null;
20
	private Rafraichissable rafraichissement = null;
21
	private Rafraichissable rafraichissement = null;
21
	
22
	
22
	public PublicationListeAsyncDao(Rafraichissable r) {
23
	public PublicationListeAsyncDao(Rafraichissable r) {
23
		
24
		
24
		rafraichissement = r ;
25
		rafraichissement = r ;
25
	}
26
	}
26
 
27
 
27
	public void obtenirListePublication() {
28
	public void obtenirListePublication() {
28
    	// Demande de toutes les structures
29
    	// Demande de toutes les structures
29
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
30
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
30
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelPublicationListe/");
31
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelPublicationListe/");
31
 
32
 
32
		try {
33
		try {
33
			rb.sendRequest(null, new RequestCallback() {
34
			rb.sendRequest(null, new RequestCallback() {
34
 
35
 
35
				public void onError(Request request, Throwable exception) {
36
				public void onError(Request request, Throwable exception) {
36
					// TODO Auto-generated method stub
37
					// TODO Auto-generated method stub
37
 
38
 
38
				}
39
				}
39
 
40
 
40
				public void onResponseReceived(Request request, Response response) {
41
				public void onResponseReceived(Request request, Response response) {
41
					Boolean defaut = true;
42
					Boolean defaut = true;
42
					if (response.getText().length() != 0 && response.getText() != null) {
43
					if (response.getText().length() != 0 && response.getText() != null) {
43
						final JSONValue responseValue = JSONParser.parse(response.getText());
44
						final JSONValue responseValue = JSONParser.parse(response.getText());
44
						
45
						
45
						// Si la requête est un succès, reception d'un tableau
46
						// Si la requête est un succès, reception d'un tableau
46
						if (responseValue.isArray() != null) {
47
						if (responseValue.isArray() != null) {
47
							final JSONArray reponse = responseValue.isArray();
48
							final JSONArray reponse = responseValue.isArray();
48
							// Transformation du tableau JSON réponse en ListeInstitution
49
							// Transformation du tableau JSON réponse en ListeInstitution
49
							publications = new PublicationListe(reponse);
50
							publications = new PublicationListe(reponse);
50
							// et on met à jour le demandeur des données
51
							// et on met à jour le demandeur des données
51
							rafraichissement.rafraichir(publications);
52
							rafraichissement.rafraichir(publications);
52
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
53
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
53
							defaut = false;
54
							defaut = false;
54
						}
55
						}
55
					}
56
					}
56
					if (defaut == true) {
57
					if (defaut == true) {
57
						publications = new PublicationListe(0);
58
						publications = new PublicationListe(0);
58
						rafraichissement.rafraichir(publications);
59
						rafraichissement.rafraichir(publications);
59
					}
60
					}
60
				}
61
				}
61
			});
62
			});
62
		} catch (RequestException e) {
63
		} catch (RequestException e) {
63
			e.printStackTrace();
64
			e.printStackTrace();
64
		}
65
		}
65
	}
66
	}
-
 
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);
-
 
72
 
-
 
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
	}
66
 
148
 
67
}
149
}