Subversion Repositories eFlore/Applications.cel

Rev

Rev 33 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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