Subversion Repositories eFlore/Applications.cel

Rev

Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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