Subversion Repositories eFlore/Applications.coel

Rev

Rev 1255 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1255 Rev 1311
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
		String postDonneesEncodees = construirePost(structureId, personnel);
61
		String postDonneesEncodees = construirePost(structureId, personnel);
62
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
62
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
63
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
63
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
64
			@Override
64
			@Override
65
			public void surReponse(JSONValue responseValue) {							
65
			public void surReponse(JSONValue responseValue) {							
66
				// 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
67
				if (responseValue.isString() != null) {
67
				if (responseValue.isString() != null) {
68
					Information info = new Information("ajout_structure_a_personne");
68
					Information info = new Information("ajout_structure_a_personne");
69
					info.setMessage(responseValue.isString().stringValue());
69
					info.setMessage(responseValue.isString().stringValue());
70
					vueARafraichir.rafraichir(info);
70
					vueARafraichir.rafraichir(info);
71
				} else {
71
				} else {
72
					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);
73
				}
73
				}
74
			}
74
			}
75
		});		
75
		});		
76
	}
76
	}
77
	
77
	
78
	public void modifier(StructureAPersonne personnel) {
78
	public void modifier(StructureAPersonne personnel) {
79
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
79
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
80
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
80
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
81
		
81
		
82
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
82
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
83
		
83
		
84
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
84
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
85
			@Override
85
			@Override
86
			public void surReponse(JSONValue responseValue) {
86
			public void surReponse(JSONValue responseValue) {
87
				Information info = new Information("modif_structure_a_personne");
87
				Information info = new Information("modif_structure_a_personne");
88
				// 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
89
				if (responseValue.isString() != null) {
89
				if (responseValue.isString() != null) {
90
					info.setMessage(responseValue.isString().stringValue());
90
					info.setMessage(responseValue.isString().stringValue());
91
					vueARafraichir.rafraichir(info);
91
					vueARafraichir.rafraichir(info);
92
				} else {
92
				} else {
93
					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);
94
				}
94
				}
95
			}
95
			}
96
		});
96
		});
97
	}
97
	}
98
	
98
	
99
	public void supprimer(String idStrAPer) {
99
	public void supprimer(String idStrAPer) {
100
		String[] parametres = {utilisateurId, idStrAPer};
100
		String[] parametres = {utilisateurId, idStrAPer};
101
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
101
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
102
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
102
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
103
			@Override
103
			@Override
104
			public void surReponse(JSONValue responseValue) {
104
			public void surReponse(JSONValue responseValue) {
105
				if (responseValue.isString() != null) {
105
				if (responseValue.isString() != null) {
106
					Information info = new Information("suppression_structure_a_personne");
106
					Information info = new Information("suppression_structure_a_personne");
107
					info.setMessage(responseValue.isString().stringValue());
107
					info.setMessage(responseValue.isString().stringValue());
108
					vueARafraichir.rafraichir(info);
108
					vueARafraichir.rafraichir(info);
109
				} else {
109
				} else {
110
					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);
111
				}
111
				}
112
			}
112
			}
113
		});
113
		});
114
	}
114
	}
115
	
115
	
116
	private String construirePost(String structureId, StructureAPersonne personnel) {
116
	private String construirePost(String structureId, StructureAPersonne personnel) {
117
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
117
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
118
		if (!personnel.getIdPersonne().equals("")) {
118
		if (!personnel.getIdPersonne().equals("")) {
119
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
119
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
120
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
120
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
121
		}
121
		}
122
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
122
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
123
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
123
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
124
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
124
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
125
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
125
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
126
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
126
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
127
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
127
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
128
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
128
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
129
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
129
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
130
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
130
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
131
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
131
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
132
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
132
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
133
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
133
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
134
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
134
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
135
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
135
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
-
 
136
			"&cp_ce_deces=" + URL.encodeComponent(personnel.getDeces()) +
136
			"";
137
			"";
137
		return postDonnees;
138
		return postDonnees;
138
	}
139
	}
139
}
140
}