Subversion Repositories eFlore/Applications.coel

Rev

Rev 1219 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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