Subversion Repositories eFlore/Applications.coel

Rev

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