Subversion Repositories eFlore/Applications.coel

Rev

Rev 935 | Rev 1262 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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