Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 935 Rev 1210
1
package org.tela_botanica.client.modeles.structure;
1
package org.tela_botanica.client.modeles.structure;
2
 
2
 
3
import org.tela_botanica.client.Mediateur;
3
import org.tela_botanica.client.Mediateur;
4
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.RegistreId;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.Information;
8
import org.tela_botanica.client.modeles.Information;
-
 
9
import org.tela_botanica.client.util.Debug;
9
import org.tela_botanica.client.util.UtilDAO;
10
import org.tela_botanica.client.util.UtilDAO;
10
 
11
 
11
import com.extjs.gxt.ui.client.Registry;
12
import com.extjs.gxt.ui.client.Registry;
12
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.http.client.URL;
14
import com.google.gwt.http.client.URL;
14
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONArray;
15
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.json.client.JSONValue;
16
 
17
 
17
public class StructureAPersonneAsyncDao {
18
public class StructureAPersonneAsyncDao {
18
	private static final String SERVICE_NOM = "CoelStructureAPersonne";
19
	private static final String SERVICE_NOM = "CoelStructureAPersonne";
19
 
20
 
20
	private String utilisateurId = null;
21
	private String utilisateurId = null;
21
	private Rafraichissable vueARafraichir = null;
22
	private Rafraichissable vueARafraichir = null;
22
 
23
 
23
	public StructureAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
24
	public StructureAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
24
		vueARafraichir = vueARafraichirCourrante;
25
		vueARafraichir = vueARafraichirCourrante;
25
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
26
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
26
	}
27
	}
27
	
28
	
28
	public void selectionner(final String structureId, final String roleId) {
29
	public void selectionner(final String structureId, final String roleId) {
29
		String[] parametres = {structureId, roleId};
30
		String[] parametres = {structureId, roleId};
30
		
31
		
31
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
32
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
32
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
33
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
33
			@Override
34
			@Override
34
			public void surReponse(JSONValue responseValue) {
35
			public void surReponse(JSONValue responseValue) {
35
				Information info = new Information("liste_structure_a_personne");
36
				Information info = new Information("liste_structure_a_personne");
36
				if (responseValue != null) {
37
				if (responseValue != null) {
37
					// Si la requête est un succès, reception d'un tableau
38
					// Si la requête est un succès, reception d'un tableau
38
					if (responseValue.isArray() != null) {
39
					if (responseValue.isArray() != null) {
39
						final JSONArray reponse = responseValue.isArray();
40
						final JSONArray reponse = responseValue.isArray();
40
						// Transformation du tableau JSON réponse en ListeInstitution
41
						// Transformation du tableau JSON réponse en ListeInstitution
41
						StructureAPersonneListe personnel = new StructureAPersonneListe(reponse);
42
						StructureAPersonneListe personnel = new StructureAPersonneListe(reponse);
42
						info.setDonnee(0, personnel);
43
						info.setDonnee(0, personnel);
43
						// et on met à jour le demandeur des données
44
						// et on met à jour le demandeur des données
44
						vueARafraichir.rafraichir(info);
45
						vueARafraichir.rafraichir(info);
45
					} else {
46
					} else {
46
						GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un talbeau JSON et vaut : "+responseValue.toString(), null);
47
						GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un talbeau JSON et vaut : "+responseValue.toString(), null);
47
					}
48
					}
48
				} else {
49
				} else {
49
					if (structureId == null) {
50
					if (structureId == null) {
50
						// Dans le cas, où nous demandons toutes les relations Structure à Personne et qu'il n'y en a pas, nous retournons un message d'information
51
						// Dans le cas, où nous demandons toutes les relations Structure à Personne et qu'il n'y en a pas, nous retournons un message d'information
51
						info.setMessage("Aucun personnel");
52
						info.setMessage("Aucun personnel");
52
						vueARafraichir.rafraichir(info);
53
						vueARafraichir.rafraichir(info);
53
					}
54
					}
54
				}
55
				}
55
			}
56
			}
56
		});
57
		});
57
	}
58
	}
58
 
59
 
59
	public void ajouter(String structureId, StructureAPersonne personnel) {
60
	public void ajouter(String structureId, StructureAPersonne personnel) {
-
 
61
		
-
 
62
Debug.log("<<<< BEGIN StructureAPersonneAsyncDao.ajouter()");		
-
 
63
 
-
 
64
Debug.log("<<<< StructureAPersonneAsyncDao.ajouter(), personnel="+personnel.toString());	
-
 
65
		
60
		String postDonneesEncodees = construirePost(structureId, personnel);
66
		String postDonneesEncodees = construirePost(structureId, personnel);
61
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
67
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
62
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
68
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
63
			@Override
69
			@Override
64
			public void surReponse(JSONValue responseValue) {							
70
			public void surReponse(JSONValue responseValue) {							
65
				// Si la requête est un succès, reception d'une chaine
71
				// Si la requête est un succès, reception d'une chaine
66
				if (responseValue.isString() != null) {
72
				if (responseValue.isString() != null) {
67
					Information info = new Information("ajout_structure_a_personne");
73
					Information info = new Information("ajout_structure_a_personne");
68
					info.setMessage(responseValue.isString().stringValue());
74
					info.setMessage(responseValue.isString().stringValue());
69
					vueARafraichir.rafraichir(info);
75
					vueARafraichir.rafraichir(info);
70
				} else {
76
				} else {
71
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
77
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
72
				}
78
				}
73
			}
79
			}
74
		});
80
		});
-
 
81
		
-
 
82
Debug.log("<<<< END StructureAPersonneAsyncDao.supprimer()");
-
 
83
		
75
	}
84
	}
76
	
85
	
77
	public void modifier(StructureAPersonne personnel) {
86
	public void modifier(StructureAPersonne personnel) {
78
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
87
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
79
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
88
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
80
		
89
		
81
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
90
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
82
		
91
		
83
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
92
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
84
			@Override
93
			@Override
85
			public void surReponse(JSONValue responseValue) {
94
			public void surReponse(JSONValue responseValue) {
86
				Information info = new Information("modif_structure_a_personne");
95
				Information info = new Information("modif_structure_a_personne");
87
				// Si la requête est un succès, reception d'une chaine
96
				// Si la requête est un succès, reception d'une chaine
88
				if (responseValue.isString() != null) {
97
				if (responseValue.isString() != null) {
89
					info.setMessage(responseValue.isString().stringValue());
98
					info.setMessage(responseValue.isString().stringValue());
90
					vueARafraichir.rafraichir(info);
99
					vueARafraichir.rafraichir(info);
91
				} else {
100
				} else {
92
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
101
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
93
				}
102
				}
94
			}
103
			}
95
		});
104
		});
96
	}
105
	}
97
	
106
	
98
	public void supprimer(String idStrAPer) {
107
	public void supprimer(String idStrAPer) {
99
		String[] parametres = {utilisateurId, idStrAPer};
108
		String[] parametres = {utilisateurId, idStrAPer};
100
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
109
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
101
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
110
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
102
			@Override
111
			@Override
103
			public void surReponse(JSONValue responseValue) {
112
			public void surReponse(JSONValue responseValue) {
104
				if (responseValue.isString() != null) {
113
				if (responseValue.isString() != null) {
105
					Information info = new Information("suppression_structure_a_personne");
114
					Information info = new Information("suppression_structure_a_personne");
106
					info.setMessage(responseValue.isString().stringValue());
115
					info.setMessage(responseValue.isString().stringValue());
107
					vueARafraichir.rafraichir(info);
116
					vueARafraichir.rafraichir(info);
108
				} else {
117
				} else {
109
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
118
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
110
				}
119
				}
111
			}
120
			}
112
		});
121
		});
113
	}
122
	}
114
	
123
	
115
	private String construirePost(String structureId, StructureAPersonne personnel) {
124
	private String construirePost(String structureId, StructureAPersonne personnel) {
116
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
125
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
117
		if (!personnel.getIdPersonne().equals("")) {
126
		if (!personnel.getIdPersonne().equals("")) {
118
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
127
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
119
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
128
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
120
		}
129
		}
121
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
130
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
122
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
131
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
123
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
132
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
124
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
133
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
125
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
134
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
126
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
135
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
127
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
136
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
128
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
137
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
129
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
138
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
130
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
139
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
-
 
140
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
131
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
141
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
132
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
142
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
133
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
143
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
134
			"";
144
			"";
135
		return postDonnees;
145
		return postDonnees;
136
	}
146
	}
137
}
147
}