Subversion Repositories eFlore/Applications.cel

Rev

Rev 12 | 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
 
33 jpm 57
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/") ;
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
81
						r.rafraichir(new Utilisateur(identifiant, identifie),true);
82
					}
83
				}
84
			}) ;
85
 
86
 
87
		} catch (RequestException e) {
88
 
89
 
90
		}
2 aperonnet 91
	}
92
 
93
 
12 david 94
 
95
	public void deconnecterUtilisateur(final Rafraichissable r, String user) {
96
 
33 jpm 97
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user) ;
98
 
99
		try {
100
 
101
			rb.sendRequest(null, new RequestCallback() {
2 aperonnet 102
 
33 jpm 103
				public void onError(Request request, Throwable exception) {
104
					// TODO Auto-generated method stub
105
 
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))
119
						.booleanValue(); // Drapeau leve si utilisateur
120
											// deja identifie
12 david 121
 
33 jpm 122
					r.rafraichir(new Utilisateur(identifiant, identifie),true);
123
					}
124
				}
125
 
126
			}) ;
127
 
128
		} catch (RequestException e) {
129
 
130
 
131
		}
2 aperonnet 132
	}
133
 
134
 
12 david 135
 
136
	public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
33 jpm 137
 
138
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password) ;
139
 
140
		try {
141
 
142
			rb.sendRequest(null, new RequestCallback() {
12 david 143
 
33 jpm 144
				public void onError(Request request, Throwable exception) {
145
					// TODO Auto-generated method stub
146
 
147
				}
2 aperonnet 148
 
33 jpm 149
				public void onResponseReceived(Request request,
150
						Response response) {
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))
161
						.booleanValue(); // Drapeau leve si utilisateur
162
											// deja identifie
12 david 163
 
2 aperonnet 164
 
33 jpm 165
						r.rafraichir(new Utilisateur(identifiant, identifie),true);
166
					}
167
				}
168
 
169
 
170
			}) ;
171
 
172
		} catch (RequestException e) {
173
 
174
			e.printStackTrace() ;
175
		}
2 aperonnet 176
	}
177
 
12 david 178
 
179
 
180
 
2 aperonnet 181
}