Subversion Repositories eFlore/Archives.cel-v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9 ddelon 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
 
8
import org.tela_botanica.client.interfaces.iRetourUtilisateur;
9
 
10
import com.google.gwt.json.client.JSONArray;
11
import com.google.gwt.json.client.JSONBoolean;
12
import com.google.gwt.json.client.JSONParser;
13
import com.google.gwt.json.client.JSONString;
14
import com.google.gwt.json.client.JSONValue;
15
import com.google.gwt.user.client.HTTPRequest;
16
import com.google.gwt.user.client.ResponseTextHandler;
17
 
18
public class UtilisateurAsynchroneDAO {
19
 
20
 
21
 
22
	/**
23
	 * Constructeur
24
	 */
25
 
26
	public UtilisateurAsynchroneDAO() {
27
	}
28
 
29
 
30
 
31
	/**
32
	 * Methode de classe d'appel du service gestion identification
33
	 * @param baseURL : URL du service
34
	 * @param retour : methode appelle en retour d'appel
35
	 */
36
 
37
	public void getUtilisateur(String baseURL, final iRetourUtilisateur retour) {
38
 
39
		// Recherche identifiant utilisateur identifie
40
 
41
		HTTPRequest.asyncGet(baseURL + "/User/", new ResponseTextHandler() {
42
 
43
			public void onCompletion(String str) {
44
				JSONValue jsonValue = JSONParser.parse(str);
45
				JSONArray jsonArray;
46
				if ((jsonArray = jsonValue.isArray()) != null) {
47
					String identifiant = ((JSONString) jsonArray.get(0))
48
							.stringValue(); // Identifiant utilisateur ou
49
											// identifiant de session si non
50
											// identifie
51
					boolean identifie = ((JSONBoolean) jsonArray.get(1))
52
							.booleanValue(); // Drapeau leve si utilisateur
53
												// deja identifie
54
					retour.onRetour(new Utilisateur(identifiant, identifie));
55
				}
56
			}
57
		});
58
 
59
	}
60
 
61
 
62
 
63
	public void deconnecterUtilisateur(String baseURL, final iRetourUtilisateur retour, String user) {
64
 
65
		HTTPRequest.asyncGet(baseURL + "/User/" + user    ,
66
				new ResponseTextHandler() {
67
 
68
					public void onCompletion(String str) {
69
 
70
							JSONValue jsonValue = JSONParser.parse(str);
71
							JSONArray jsonArray;
72
							if ((jsonArray = jsonValue.isArray()) != null) {
73
								String identifiant = ((JSONString) jsonArray.get(0))
74
								.stringValue(); // Identifiant utilisateur ou
75
												// identifiant de session si non
76
												// identifie
77
								boolean identifie = ((JSONBoolean) jsonArray.get(1))
78
								.booleanValue(); // Drapeau leve si utilisateur
79
													// deja identifie
80
 
81
 
82
							retour.onRetour(new Utilisateur(identifiant, identifie));
83
							}
84
					}
85
		});
86
	}
87
 
88
 
89
 
90
	public void connecteUtilisateur(String baseURL,final iRetourUtilisateur retour, String login, String password) {
91
 
92
		HTTPRequest.asyncGet(baseURL + "/User/" + login + "/" + password ,
93
				new ResponseTextHandler() {
94
 
95
					public void onCompletion(String str) {
96
 
97
						JSONValue jsonValue = JSONParser.parse(str);
98
						JSONArray jsonArray;
99
 
100
						if ((jsonArray = jsonValue.isArray()) != null) {
101
							String identifiant = ((JSONString) jsonArray.get(0))
102
							.stringValue(); // Identifiant utilisateur ou
103
											// identifiant de session si non
104
											// identifie
105
							boolean identifie = ((JSONBoolean) jsonArray.get(1))
106
							.booleanValue(); // Drapeau leve si utilisateur
107
												// deja identifie
108
 
109
 
110
						retour.onRetour(new Utilisateur(identifiant, identifie));
111
						}
112
					}
113
				});
114
 
115
	}
116
 
117
}