Subversion Repositories eFlore/Applications.coel

Rev

Rev 1262 | Rev 1319 | 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
 
1292 cyprien 60
	public void ajouter(String structureId, StructureAPersonne personnel) {
767 jpm 61
		String postDonneesEncodees = construirePost(structureId, personnel);
763 jpm 62
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
63
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
64
			@Override
65
			public void surReponse(JSONValue responseValue) {
66
				// Si la requête est un succès, reception d'une chaine
67
				if (responseValue.isString() != null) {
68
					Information info = new Information("ajout_structure_a_personne");
69
					info.setMessage(responseValue.isString().stringValue());
767 jpm 70
					vueARafraichir.rafraichir(info);
763 jpm 71
				} else {
72
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
231 jp_milcent 73
				}
763 jpm 74
			}
1292 cyprien 75
		});
231 jp_milcent 76
	}
77
 
767 jpm 78
	public void modifier(StructureAPersonne personnel) {
79
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
80
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
231 jp_milcent 81
 
767 jpm 82
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
83
 
84
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
85
			@Override
86
			public void surReponse(JSONValue responseValue) {
87
				Information info = new Information("modif_structure_a_personne");
88
				// Si la requête est un succès, reception d'une chaine
89
				if (responseValue.isString() != null) {
90
					info.setMessage(responseValue.isString().stringValue());
91
					vueARafraichir.rafraichir(info);
92
				} else {
93
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
231 jp_milcent 94
				}
767 jpm 95
			}
96
		});
231 jp_milcent 97
	}
98
 
767 jpm 99
	public void supprimer(String idStrAPer) {
100
		String[] parametres = {utilisateurId, idStrAPer};
101
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
102
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
103
			@Override
104
			public void surReponse(JSONValue responseValue) {
105
				if (responseValue.isString() != null) {
106
					Information info = new Information("suppression_structure_a_personne");
107
					info.setMessage(responseValue.isString().stringValue());
108
					vueARafraichir.rafraichir(info);
109
				} else {
110
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
231 jp_milcent 111
				}
767 jpm 112
			}
113
		});
231 jp_milcent 114
	}
602 jp_milcent 115
 
767 jpm 116
	private String construirePost(String structureId, StructureAPersonne personnel) {
602 jp_milcent 117
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
609 jp_milcent 118
		if (!personnel.getIdPersonne().equals("")) {
119
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
120
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
121
		}
611 jp_milcent 122
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
123
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +
602 jp_milcent 124
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
125
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
126
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
127
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
128
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
609 jp_milcent 129
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
602 jp_milcent 130
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
131
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
1210 cyprien 132
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
602 jp_milcent 133
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
134
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
135
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
136
			"";
137
		return postDonnees;
138
	}
208 jp_milcent 139
}