| 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 |
|
| 12 |
david |
8 |
import org.tela_botanica.client.CarnetEnLigneModele;
|
|
|
9 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
| 2 |
aperonnet |
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 |
|
| 12 |
david |
21 |
|
|
|
22 |
|
|
|
23 |
|
| 2 |
aperonnet |
24 |
/**
|
| 12 |
david |
25 |
* Le modèle associé au DAO
|
| 2 |
aperonnet |
26 |
*/
|
| 12 |
david |
27 |
private CarnetEnLigneModele carnetEnLigneModele = null ;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Constructeur
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
public UtilisateurAsynchroneDAO(CarnetEnLigneModele carnetEnLigneModele) {
|
|
|
34 |
|
|
|
35 |
this.carnetEnLigneModele=carnetEnLigneModele;
|
|
|
36 |
|
| 2 |
aperonnet |
37 |
}
|
| 12 |
david |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
| 2 |
aperonnet |
42 |
/**
|
| 12 |
david |
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
|
| 2 |
aperonnet |
46 |
*/
|
| 12 |
david |
47 |
|
|
|
48 |
public void getEtatUtilisateur(final Rafraichissable r) {
|
| 5 |
aperonnet |
49 |
|
| 2 |
aperonnet |
50 |
// Recherche identifiant utilisateur identifie
|
|
|
51 |
|
| 12 |
david |
52 |
HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/", new ResponseTextHandler() {
|
| 2 |
aperonnet |
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
|
| 12 |
david |
60 |
// identifiant de session si non
|
|
|
61 |
// identifie
|
| 2 |
aperonnet |
62 |
boolean identifie = ((JSONBoolean) jsonArray.get(1))
|
|
|
63 |
.booleanValue(); // Drapeau leve si utilisateur
|
| 12 |
david |
64 |
// deja identifie
|
|
|
65 |
r.rafraichir(new Utilisateur(identifiant, identifie),true);
|
| 2 |
aperonnet |
66 |
}
|
|
|
67 |
}
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
| 12 |
david |
73 |
|
|
|
74 |
public void deconnecterUtilisateur(final Rafraichissable r, String user) {
|
|
|
75 |
|
|
|
76 |
HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user ,
|
| 2 |
aperonnet |
77 |
new ResponseTextHandler() {
|
|
|
78 |
|
|
|
79 |
public void onCompletion(String str) {
|
| 12 |
david |
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 |
|
|
|
92 |
r.rafraichir(new Utilisateur(identifiant, identifie),true);
|
|
|
93 |
}
|
| 2 |
aperonnet |
94 |
}
|
| 12 |
david |
95 |
});
|
| 2 |
aperonnet |
96 |
}
|
|
|
97 |
|
|
|
98 |
|
| 12 |
david |
99 |
|
|
|
100 |
public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
|
|
|
101 |
|
|
|
102 |
HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password ,
|
| 2 |
aperonnet |
103 |
new ResponseTextHandler() {
|
|
|
104 |
|
|
|
105 |
public void onCompletion(String str) {
|
| 12 |
david |
106 |
|
| 2 |
aperonnet |
107 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
108 |
JSONArray jsonArray;
|
| 12 |
david |
109 |
|
| 2 |
aperonnet |
110 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
111 |
String identifiant = ((JSONString) jsonArray.get(0))
|
| 12 |
david |
112 |
.stringValue(); // Identifiant utilisateur ou
|
|
|
113 |
// identifiant de session si non
|
|
|
114 |
// identifie
|
| 2 |
aperonnet |
115 |
boolean identifie = ((JSONBoolean) jsonArray.get(1))
|
| 12 |
david |
116 |
.booleanValue(); // Drapeau leve si utilisateur
|
|
|
117 |
// deja identifie
|
|
|
118 |
|
| 2 |
aperonnet |
119 |
|
| 12 |
david |
120 |
r.rafraichir(new Utilisateur(identifiant, identifie),true);
|
| 2 |
aperonnet |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
});
|
|
|
124 |
|
|
|
125 |
}
|
|
|
126 |
|
| 12 |
david |
127 |
|
|
|
128 |
|
|
|
129 |
|
| 2 |
aperonnet |
130 |
}
|