Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 12 Rev 33
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
/**
3
/**
4
 * Modele DAO, specifique, permettant la validation, l'acces aux donnees distantes et la présentation des donnees en retour
4
 * Modele DAO, specifique, permettant la validation, l'acces aux donnees distantes et la présentation des donnees en retour
5
 * 
5
 * 
6
 */
6
 */
7
 
7
 
8
import org.tela_botanica.client.CarnetEnLigneModele;
8
import org.tela_botanica.client.CarnetEnLigneModele;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
-
 
10
 
-
 
11
import com.google.gwt.http.client.Request;
-
 
12
import com.google.gwt.http.client.RequestBuilder;
-
 
13
import com.google.gwt.http.client.RequestCallback;
-
 
14
import com.google.gwt.http.client.RequestException;
10
 
15
import com.google.gwt.http.client.Response;
11
import com.google.gwt.json.client.JSONArray;
16
import com.google.gwt.json.client.JSONArray;
12
import com.google.gwt.json.client.JSONBoolean;
17
import com.google.gwt.json.client.JSONBoolean;
13
import com.google.gwt.json.client.JSONParser;
18
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONString;
19
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONValue;
20
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.user.client.HTTPRequest;
21
import com.google.gwt.user.client.HTTPRequest;
17
import com.google.gwt.user.client.ResponseTextHandler;
22
import com.google.gwt.user.client.ResponseTextHandler;
18
 
23
 
19
public class UtilisateurAsynchroneDAO {
24
public class UtilisateurAsynchroneDAO {
20
 
25
 
21
	
26
	
22
	
27
	
23
	
28
	
24
	/**
29
	/**
25
	 * Le modèle associé au DAO
30
	 * Le modèle associé au DAO
26
	 */
31
	 */
27
	private CarnetEnLigneModele carnetEnLigneModele = null ;
32
	private CarnetEnLigneModele carnetEnLigneModele = null ;
28
	
33
	
29
	/**
34
	/**
30
	 * Constructeur 
35
	 * Constructeur 
31
	 */
36
	 */
32
	
37
	
33
	public UtilisateurAsynchroneDAO(CarnetEnLigneModele carnetEnLigneModele) {
38
	public UtilisateurAsynchroneDAO(CarnetEnLigneModele carnetEnLigneModele) {
34
		
39
		
35
		this.carnetEnLigneModele=carnetEnLigneModele;
40
		this.carnetEnLigneModele=carnetEnLigneModele;
36
		
41
		
37
	}
42
	}
38
	
43
	
39
	
44
	
40
	
45
	
41
	
46
	
42
	/**
47
	/**
43
	 * Methode de classe d'appel du service gestion identification 
48
	 * Methode de classe d'appel du service gestion identification 
44
	 * @param baseURL : URL du service
49
	 * @param baseURL : URL du service
45
	 * @param retour : methode appelle en retour d'appel
50
	 * @param retour : methode appelle en retour d'appel
46
	 */
51
	 */
47
	
52
	
48
	public void getEtatUtilisateur(final Rafraichissable r) {
53
	public void getEtatUtilisateur(final Rafraichissable r) {
49
 
54
 
50
		// Recherche identifiant utilisateur identifie
55
		// Recherche identifiant utilisateur identifie
51
 
56
 
-
 
57
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/") ;
-
 
58
		
-
 
59
		try {
-
 
60
			
52
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/", new ResponseTextHandler() {
61
			rb.sendRequest(null, new RequestCallback() {
53
 
-
 
54
			public void onCompletion(String str) {
-
 
55
				JSONValue jsonValue = JSONParser.parse(str);
-
 
56
				JSONArray jsonArray;
-
 
57
				if ((jsonArray = jsonValue.isArray()) != null) {
-
 
58
					String identifiant = ((JSONString) jsonArray.get(0))
62
 
59
							.stringValue(); // Identifiant utilisateur ou
-
 
60
											// identifiant de session si non
-
 
61
											// identifie
-
 
62
					boolean identifie = ((JSONBoolean) jsonArray.get(1))
-
 
63
							.booleanValue(); // Drapeau leve si utilisateur
-
 
-
 
63
				public void onError(Request request, Throwable exception) {
64
												// deja identifie
64
					// TODO Auto-generated method stub
65
					r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
66
				}
-
 
-
 
65
					
-
 
66
				}
-
 
67
 
-
 
68
				public void onResponseReceived(Request request,
-
 
69
						Response response) {
-
 
70
					
-
 
71
					JSONValue jsonValue = JSONParser.parse(response.getText());
-
 
72
					JSONArray jsonArray;
-
 
73
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
74
						String identifiant = ((JSONString) jsonArray.get(0))
-
 
75
								.stringValue(); // Identifiant utilisateur ou
-
 
76
												// identifiant de session si non
-
 
77
												// identifie
-
 
78
						boolean identifie = ((JSONBoolean) jsonArray.get(1))
-
 
79
								.booleanValue(); // Drapeau leve si utilisateur
-
 
80
													// deja identifie
-
 
81
						r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
82
					}			
-
 
83
				}			
-
 
84
			}) ;
-
 
85
			
-
 
86
			
-
 
87
		} catch (RequestException e) {
67
			}
88
			
68
		});
89
			
69
 
90
		}
70
	}
91
	}
71
 
92
 
72
 
93
 
73
 
94
 
74
	public void deconnecterUtilisateur(final Rafraichissable r, String user) {
95
	public void deconnecterUtilisateur(final Rafraichissable r, String user) {
75
 
96
 
-
 
97
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user) ;
-
 
98
		
-
 
99
		try {
76
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user    ,
100
			
-
 
101
			rb.sendRequest(null, new RequestCallback() {
-
 
102
 
-
 
103
				public void onError(Request request, Throwable exception) {
-
 
104
					// TODO Auto-generated method stub
-
 
105
					
77
				new ResponseTextHandler() {
106
				}
-
 
107
 
-
 
108
				public void onResponseReceived(Request request,
-
 
109
						Response response) {
-
 
110
					
-
 
111
					JSONValue jsonValue = JSONParser.parse(response.getText());
-
 
112
					JSONArray jsonArray;
-
 
113
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
114
						String identifiant = ((JSONString) jsonArray.get(0))
-
 
115
						.stringValue(); // Identifiant utilisateur ou
-
 
116
										// identifiant de session si non
-
 
117
										// identifie
-
 
118
						boolean identifie = ((JSONBoolean) jsonArray.get(1))
78
 
119
						.booleanValue(); // Drapeau leve si utilisateur
79
					public void onCompletion(String str) {
120
											// deja identifie
80
						
-
 
81
							JSONValue jsonValue = JSONParser.parse(str);
-
 
82
							JSONArray jsonArray;
-
 
83
							if ((jsonArray = jsonValue.isArray()) != null) {
-
 
84
								String identifiant = ((JSONString) jsonArray.get(0))
121
						
85
								.stringValue(); // Identifiant utilisateur ou
-
 
86
												// identifiant de session si non
-
 
-
 
122
					r.rafraichir(new Utilisateur(identifiant, identifie),true);
87
												// identifie
123
					}				
88
								boolean identifie = ((JSONBoolean) jsonArray.get(1))
124
				}			
89
								.booleanValue(); // Drapeau leve si utilisateur
125
				
90
													// deja identifie
126
			}) ;
91
								
127
			
92
							r.rafraichir(new Utilisateur(identifiant, identifie),true);
128
		} catch (RequestException e) {
93
							}
129
			
94
					}
130
			
95
		});
131
		}
96
	}
132
	}
97
 
133
 
98
 
134
 
99
 
135
 
100
	public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
136
	public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
-
 
137
		
-
 
138
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password) ;
-
 
139
		
-
 
140
		try {
-
 
141
			
-
 
142
			rb.sendRequest(null, new RequestCallback() {
101
 
143
 
102
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password ,
144
				public void onError(Request request, Throwable exception) {
-
 
145
					// TODO Auto-generated method stub
-
 
146
					
103
				new ResponseTextHandler() {
147
				}
-
 
148
 
104
 
149
				public void onResponseReceived(Request request,
105
					public void onCompletion(String str) {
150
						Response response) {
106
			
151
					
-
 
152
					JSONValue jsonValue = JSONParser.parse(response.getText());
-
 
153
					JSONArray jsonArray;
-
 
154
					
-
 
155
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
156
						String identifiant = ((JSONString) jsonArray.get(0))
-
 
157
						.stringValue(); // Identifiant utilisateur ou
-
 
158
										// identifiant de session si non
-
 
159
										// identifie
-
 
160
						boolean identifie = ((JSONBoolean) jsonArray.get(1))
107
						JSONValue jsonValue = JSONParser.parse(str);
-
 
108
						JSONArray jsonArray;
-
 
109
						
-
 
110
						if ((jsonArray = jsonValue.isArray()) != null) {
-
 
111
							String identifiant = ((JSONString) jsonArray.get(0))
-
 
112
							.stringValue(); // Identifiant utilisateur ou
-
 
113
											// identifiant de session si non
-
 
114
											// identifie
-
 
115
							boolean identifie = ((JSONBoolean) jsonArray.get(1))
-
 
116
							.booleanValue(); // Drapeau leve si utilisateur
-
 
117
												// deja identifie
-
 
118
							
-
 
119
 
-
 
120
							r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
-
 
161
						.booleanValue(); // Drapeau leve si utilisateur
-
 
162
											// deja identifie
-
 
163
						
-
 
164
 
-
 
165
						r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
166
					}				
-
 
167
				}
-
 
168
				
-
 
169
				
-
 
170
			}) ;
-
 
171
			
121
						}
172
		} catch (RequestException e) {
122
					}
173
			
123
				});
174
			e.printStackTrace() ;
124
 
175
		}
125
	}
176
	}
126
 
177
 
127
 
178
 
128
 
179
 
129
 
180
 
130
}
181
}