Subversion Repositories eFlore/Applications.cel

Rev

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

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