Subversion Repositories eFlore/Applications.coel

Rev

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

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