Subversion Repositories eFlore/Applications.cel

Rev

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