Subversion Repositories eFlore/Archives.cel-v2

Rev

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