Subversion Repositories eFlore/Applications.cel

Rev

Rev 143 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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