Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 9 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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