1 |
package org.tela_botanica.client.modeles;
|
1 |
package org.tela_botanica.client.modeles;
|
2 |
|
2 |
|
3 |
import java.util.HashMap;
|
3 |
import java.util.HashMap;
|
4 |
|
4 |
|
5 |
import org.tela_botanica.client.Mediateur;
|
5 |
import org.tela_botanica.client.Mediateur;
|
6 |
import org.tela_botanica.client.RegistreId;
|
6 |
import org.tela_botanica.client.RegistreId;
|
7 |
import org.tela_botanica.client.http.JsonRestRequestBuilder;
|
7 |
import org.tela_botanica.client.http.JsonRestRequestBuilder;
|
8 |
import org.tela_botanica.client.http.JsonRestRequestCallback;
|
8 |
import org.tela_botanica.client.http.JsonRestRequestCallback;
|
9 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
9 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
10 |
import org.tela_botanica.client.util.UtilDAO;
|
10 |
import org.tela_botanica.client.util.UtilDAO;
|
11 |
import com.extjs.gxt.ui.client.Registry;
|
11 |
import com.extjs.gxt.ui.client.Registry;
|
12 |
import com.google.gwt.core.client.GWT;
|
12 |
import com.google.gwt.core.client.GWT;
|
13 |
import com.google.gwt.json.client.JSONArray;
|
13 |
import com.google.gwt.json.client.JSONArray;
|
14 |
import com.google.gwt.json.client.JSONValue;
|
14 |
import com.google.gwt.json.client.JSONValue;
|
15 |
|
15 |
|
16 |
public class PersonneAsyncDao {
|
16 |
public class PersonneAsyncDao {
|
17 |
private static final String SERVICE_NOM = "CoelPersonne";
|
17 |
private static final String SERVICE_NOM = "CoelPersonne";
|
18 |
|
18 |
|
19 |
private String utilisateurId = null;
|
19 |
private String utilisateurId = null;
|
20 |
private Rafraichissable vueARafraichir = null;
|
20 |
private Rafraichissable vueARafraichir = null;
|
21 |
|
21 |
|
22 |
public PersonneAsyncDao(Rafraichissable vue) {
|
22 |
public PersonneAsyncDao(Rafraichissable vue) {
|
23 |
vueARafraichir = vue;
|
23 |
vueARafraichir = vue;
|
24 |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
|
24 |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
|
25 |
}
|
25 |
}
|
26 |
|
26 |
|
27 |
public void selectionner(String personneId, String projetId, String nomComplet, final int pageCourante, final int nbElements) {
|
27 |
public void selectionner(String personneId, String projetId, String nomComplet, final int pageCourante, final int nbElements) {
|
28 |
String[] parametres = {personneId, projetId, nomComplet};
|
28 |
String[] parametres = {personneId, projetId, nomComplet};
|
29 |
|
29 |
|
30 |
HashMap<String, String> restrictions = new HashMap<String, String>();
|
30 |
HashMap<String, String> restrictions = new HashMap<String, String>();
|
31 |
restrictions.put("start", String.valueOf(pageCourante));
|
31 |
restrictions.put("start", String.valueOf(pageCourante));
|
32 |
if (nbElements != -1) {
|
32 |
if (nbElements != -1) {
|
33 |
restrictions.put("limit", String.valueOf(nbElements));
|
33 |
restrictions.put("limit", String.valueOf(nbElements));
|
34 |
}
|
34 |
}
|
35 |
|
35 |
|
36 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
|
36 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
|
37 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
37 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
38 |
@Override
|
38 |
@Override
|
39 |
public void surReponse(JSONValue responseValue) {
|
39 |
public void surReponse(JSONValue responseValue) {
|
40 |
// Si la requête est un succès, réception d'un tableau
|
40 |
// Si la requête est un succès, réception d'un tableau
|
41 |
if (responseValue.isArray() != null) {
|
41 |
if (responseValue.isArray() != null) {
|
42 |
final JSONArray reponse = responseValue.isArray();
|
42 |
final JSONArray reponse = responseValue.isArray();
|
43 |
|
43 |
|
44 |
// Transformation du tableau JSON réponse en ListeInstitution
|
44 |
// Transformation du tableau JSON réponse en ListeInstitution
|
45 |
Information info = new Information("liste_personne");
|
45 |
Information info = new Information("liste_personne");
|
46 |
PersonneListe personnes;
|
46 |
PersonneListe personnes;
|
47 |
if (reponse.get(0).isArray() != null) {
|
47 |
if (reponse.get(0).isArray() != null) {
|
48 |
personnes = new PersonneListe(reponse);
|
48 |
personnes = new PersonneListe(reponse);
|
49 |
} else {
|
49 |
} else {
|
50 |
personnes = new PersonneListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir);
|
50 |
personnes = new PersonneListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir);
|
51 |
}
|
51 |
}
|
52 |
personnes.setTaillePage(nbElements);
|
52 |
personnes.setTaillePage(nbElements);
|
53 |
personnes.setPageCourante(pageCourante);
|
53 |
personnes.setPageCourante(pageCourante);
|
54 |
info.setDonnee(0, personnes);
|
54 |
info.setDonnee(0, personnes);
|
55 |
|
55 |
|
56 |
// et on met à jour le demandeur des données
|
56 |
// et on met à jour le demandeur des données
|
57 |
vueARafraichir.rafraichir(info);
|
57 |
vueARafraichir.rafraichir(info);
|
58 |
} else {
|
58 |
} else {
|
59 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
|
59 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
|
60 |
}
|
60 |
}
|
61 |
}
|
61 |
}
|
62 |
});
|
62 |
});
|
63 |
}
|
63 |
}
|
64 |
|
64 |
|
65 |
public void ajouter(Personne personne) {
|
65 |
public void ajouter(Personne personne) {
|
66 |
String postDonneesEncodees = personne.obtenirChainePOST();
|
66 |
String postDonneesEncodees = personne.obtenirChainePOST();
|
67 |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId;
|
67 |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId;
|
68 |
|
68 |
|
69 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
|
69 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
|
70 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
70 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
71 |
@Override
|
71 |
@Override
|
72 |
public void surReponse(JSONValue responseValue) {
|
72 |
public void surReponse(JSONValue responseValue) {
|
73 |
if (responseValue.isString() != null) {
|
73 |
if (responseValue.isString() != null) {
|
74 |
Information info = new Information("ajout_personne");
|
74 |
Information info = new Information("ajout_personne");
|
75 |
info.setMessage(responseValue.isString().stringValue());
|
75 |
String structureIdOuMessage = responseValue.isString().stringValue();
|
- |
|
76 |
if (structureIdOuMessage.matches("^[0-9]+$")) {
|
- |
|
77 |
info.setDonnee(structureIdOuMessage);
|
- |
|
78 |
} else {
|
- |
|
79 |
info.setMessage(structureIdOuMessage);
|
- |
|
80 |
}
|
76 |
vueARafraichir.rafraichir(info);
|
81 |
vueARafraichir.rafraichir(info);
|
77 |
} else {
|
82 |
} else {
|
78 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
83 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
79 |
}
|
84 |
}
|
80 |
}
|
85 |
}
|
81 |
});
|
86 |
});
|
82 |
}
|
87 |
}
|
83 |
|
88 |
|
84 |
public void modifier(Personne personne) {
|
89 |
public void modifier(Personne personne) {
|
85 |
String postDonneesEncodees = personne.obtenirChainePOST();
|
90 |
String postDonneesEncodees = personne.obtenirChainePOST();
|
86 |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId;
|
91 |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId;
|
87 |
GWT.log(postDonneesEncodees, null);
|
92 |
GWT.log(postDonneesEncodees, null);
|
88 |
String[] parametres = {personne.getId()};
|
93 |
String[] parametres = {personne.getId()};
|
89 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
94 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
90 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
95 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
91 |
@Override
|
96 |
@Override
|
92 |
public void surReponse(JSONValue responseValue) {
|
97 |
public void surReponse(JSONValue responseValue) {
|
93 |
// Si la requête est un succès, reception d'une chaine
|
98 |
// Si la requête est un succès, reception d'une chaine
|
94 |
if (responseValue.isString() != null) {
|
99 |
if (responseValue.isString() != null) {
|
95 |
Information info = new Information("modification_personne");
|
100 |
Information info = new Information("modification_personne");
|
96 |
info.setMessage(responseValue.isString().stringValue());
|
101 |
info.setMessage(responseValue.isString().stringValue());
|
97 |
vueARafraichir.rafraichir(info);
|
102 |
vueARafraichir.rafraichir(info);
|
98 |
} else {
|
103 |
} else {
|
99 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
104 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
100 |
}
|
105 |
}
|
101 |
}
|
106 |
}
|
102 |
});
|
107 |
});
|
103 |
}
|
108 |
}
|
104 |
|
109 |
|
105 |
public void supprimer(String personnesId) {
|
110 |
public void supprimer(String personnesId) {
|
106 |
String[] parametres = {utilisateurId, personnesId};
|
111 |
String[] parametres = {utilisateurId, personnesId};
|
107 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
112 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
108 |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
|
113 |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
|
109 |
@Override
|
114 |
@Override
|
110 |
public void surReponse(JSONValue responseValue) {
|
115 |
public void surReponse(JSONValue responseValue) {
|
111 |
if (responseValue.isString() != null) {
|
116 |
if (responseValue.isString() != null) {
|
112 |
Information info = new Information("suppression_personne");
|
117 |
Information info = new Information("suppression_personne");
|
113 |
info.setMessage(responseValue.isString().stringValue());
|
118 |
info.setMessage(responseValue.isString().stringValue());
|
114 |
vueARafraichir.rafraichir(info);
|
119 |
vueARafraichir.rafraichir(info);
|
115 |
} else {
|
120 |
} else {
|
116 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
121 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
117 |
}
|
122 |
}
|
118 |
}
|
123 |
}
|
119 |
});
|
124 |
});
|
120 |
}
|
125 |
}
|
121 |
|
126 |
|
122 |
}
|
127 |
}
|