Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1513 Rev 1764
1
package org.tela_botanica.client.modeles.structure;
1
package org.tela_botanica.client.modeles.structure;
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
4
 
4
 
5
import org.tela_botanica.client.Mediateur;
5
import org.tela_botanica.client.Mediateur;
6
import org.tela_botanica.client.RegistreId;
6
import org.tela_botanica.client.RegistreId;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
8
import org.tela_botanica.client.http.JsonRestRequestCallback;
8
import org.tela_botanica.client.http.JsonRestRequestCallback;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.Information;
11
import org.tela_botanica.client.synchronisation.Reponse;
11
import org.tela_botanica.client.synchronisation.Reponse;
12
import org.tela_botanica.client.util.Debug;
12
import org.tela_botanica.client.util.Debug;
13
import org.tela_botanica.client.util.UtilDAO;
13
import org.tela_botanica.client.util.UtilDAO;
14
 
14
 
15
import com.extjs.gxt.ui.client.Registry;
15
import com.extjs.gxt.ui.client.Registry;
16
import com.google.gwt.core.client.GWT;
16
import com.google.gwt.core.client.GWT;
17
import com.google.gwt.http.client.URL;
17
import com.google.gwt.http.client.URL;
18
import com.google.gwt.json.client.JSONArray;
18
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONObject;
19
import com.google.gwt.json.client.JSONObject;
20
import com.google.gwt.json.client.JSONValue;
20
import com.google.gwt.json.client.JSONValue;
21
 
21
 
22
public class StructureAPersonneAsyncDao {
22
public class StructureAPersonneAsyncDao {
23
	private static final String SERVICE_NOM = "CoelStructureAPersonne";
23
	private static final String SERVICE_NOM = "CoelStructureAPersonne";
24
 
24
 
25
	private String utilisateurId = null;
25
	private String utilisateurId = null;
26
	private Rafraichissable vueARafraichir = null;
26
	private Rafraichissable vueARafraichir = null;
27
 
27
 
28
	public StructureAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
28
	public StructureAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
29
		if (Mediateur.DEBUG) System.out.println("|| StructureAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
29
		if (Mediateur.DEBUG) System.out.println("|| StructureAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
30
		vueARafraichir = vueARafraichirCourrante;
30
		vueARafraichir = vueARafraichirCourrante;
31
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
31
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
32
	}
32
	}
33
 
33
 
34
	
34
	
35
	public void selectionner(final boolean paginationProgressive, final String structureId, final String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
35
	public void selectionner(final boolean paginationProgressive, final String structureId, final String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
36
 
36
 
37
		String[] parametres = {structureId, roleId};
37
		String[] parametres = {structureId, roleId};
38
		
38
		
39
		HashMap<String, String> restrictions = new HashMap<String, String>();
39
		HashMap<String, String> restrictions = new HashMap<String, String>();
40
		
40
		
41
		if (nbElements != -1)	{
41
		if (nbElements != -1)	{
42
			restrictions.put("limit", String.valueOf(nbElements));
42
			restrictions.put("limit", String.valueOf(nbElements));
43
		}
43
		}
44
		
44
		
45
		restrictions.put("orderby", "cp_nom");
45
		restrictions.put("orderby", "cp_nom");
46
 
46
 
47
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
47
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
48
		if (paginationProgressive) {
48
		if (paginationProgressive) {
49
 
49
 
50
			/** DEFINITION DU TUPLE DE DEPART **/
50
			/** DEFINITION DU TUPLE DE DEPART **/
51
			restrictions.put("start", String.valueOf(start));
51
			restrictions.put("start", String.valueOf(start));
52
			
52
			
53
			/** CONSTRUCTION DE LA REQUETE **/
53
			/** CONSTRUCTION DE LA REQUETE **/
54
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
54
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
55
 
55
 
56
    		/** ENVOI DE LA REQUETE **/
56
    		/** ENVOI DE LA REQUETE **/
57
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
57
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
58
    		{
58
    		{
59
    			/** RECEPTION DE LA REPONSE **/
59
    			/** RECEPTION DE LA REPONSE **/
60
    			public void surReponse(JSONValue responseValue)
60
    			public void surReponse(JSONValue responseValue)
61
    			{
61
    			{
62
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
62
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
63
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
63
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
64
					if (seqId != null)	{
64
					if (seqId != null)	{
65
						if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour au sequenceur");
65
						if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour au sequenceur");
66
						Reponse reponseRequete = new Reponse(responseValue, seqId);
66
						Reponse reponseRequete = new Reponse(responseValue, seqId);
67
						vueARafraichir.rafraichir(reponseRequete);
67
						vueARafraichir.rafraichir(reponseRequete);
68
					}
68
					}
69
					else	{
69
					else	{
70
						if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
70
						if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
71
						vueARafraichir.rafraichir(responseValue);
71
						vueARafraichir.rafraichir(responseValue);
72
					}
72
					}
73
    			}
73
    			}
74
    		});
74
    		});
75
		}
75
		}
76
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
76
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
77
		else {
77
		else {
78
			
78
			
79
			/** DEFINITION DU TUPLE DE DEPART **/
79
			/** DEFINITION DU TUPLE DE DEPART **/
80
			restrictions.put("start", String.valueOf(start*nbElements));
80
			restrictions.put("start", String.valueOf(start*nbElements));
81
			
81
			
82
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
82
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
83
 
83
 
84
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
84
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
85
				@Override
85
				@Override
86
				public void surReponse(JSONValue responseValue) {
86
				public void surReponse(JSONValue responseValue) {
87
					
87
					
88
					Information info = new Information("liste_structure_a_personne");
88
					Information info = new Information("liste_structure_a_personne");
89
 
89
 
90
					if (responseValue != null) {
90
					if (responseValue != null) {
91
 
91
 
92
						JSONObject responseObject = responseValue.isObject();
92
						JSONObject responseObject = responseValue.isObject();
93
 
93
 
94
						if (responseObject != null) {
94
						if (responseObject != null) {
95
 
95
 
96
							// Si la réponse est un tableau, alors c'est une liste de Structures qui a été retournée
96
							// Si la réponse est un tableau, alors c'est une liste de Structures qui a été retournée
97
							if (responseObject.get("structuresAPersonne").isArray() != null) {
97
							if (responseObject.get("structuresAPersonne").isArray() != null) {
98
 
98
 
99
								final JSONArray reponse = responseObject.get("structuresAPersonne").isArray();
99
								final JSONArray reponse = responseObject.get("structuresAPersonne").isArray();
100
								// Transformation du tableau JSON réponse en ListeInstitution
100
								// Transformation du tableau JSON réponse en ListeInstitution
101
								StructureAPersonneListe personnes = new StructureAPersonneListe(reponse);
101
								StructureAPersonneListe personnes = new StructureAPersonneListe(reponse);
102
								info.setDonnee(0, personnes);
102
								info.setDonnee(0, personnes);
103
								// et on met à jour le demandeur des données
103
								// et on met à jour le demandeur des données
104
								if (seqId != null)	{
104
								if (seqId != null)	{
105
									Reponse reponseRequete = new Reponse(info, seqId);
105
									Reponse reponseRequete = new Reponse(info, seqId);
106
									vueARafraichir.rafraichir(reponseRequete);
106
									vueARafraichir.rafraichir(reponseRequete);
107
								}
107
								}
108
								else	{
108
								else	{
109
									vueARafraichir.rafraichir(info);
109
									vueARafraichir.rafraichir(info);
110
								}
110
								}
111
								
111
								
112
							// Si la réponse est un objet, alors c'est une unique Structure qui a été retournée
112
							// Si la réponse est un objet, alors c'est une unique Structure qui a été retournée
113
							} else if (responseObject.get("structuresAPersonne").isObject() != null) {
113
							} else if (responseObject.get("structuresAPersonne").isObject() != null) {
114
								GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
114
								GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
115
							}
115
							}
116
						}
116
						}
117
					} else {
117
					} else {
118
						// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
118
						// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
119
						if (structureId == null) {
119
						if (structureId == null) {
120
							// 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
120
							// 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
121
							info.setMessage("Aucun personnel");
121
							info.setMessage("Aucun personnel");
122
							vueARafraichir.rafraichir(info);
122
							vueARafraichir.rafraichir(info);
123
						}
123
						}
124
					}
124
					}
125
				}
125
				}
126
			});
126
			});
127
		}
127
		}
128
	}	
128
	}	
129
 
129
 
130
 
130
 
131
	public void ajouter(String structureId, StructureAPersonne personnel) {		
131
	public void ajouter(String structureId, StructureAPersonne personnel) {		
132
		String postDonneesEncodees = construirePost(structureId, personnel);
132
		String postDonneesEncodees = construirePost(structureId, personnel);
133
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
133
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
134
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
134
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
135
			@Override
135
			@Override
136
			public void surReponse(JSONValue responseValue) {							
136
			public void surReponse(JSONValue responseValue) {							
137
				// Si la requête est un succès, reception d'une chaine
137
				// Si la requête est un succès, reception d'une chaine
138
				if (responseValue.isString() != null) {
138
				if (responseValue.isString() != null) {
139
					Information info = new Information("ajout_structure_a_personne");
139
					Information info = new Information("ajout_structure_a_personne");
140
					info.setMessage(responseValue.isString().stringValue());
140
					info.setMessage(responseValue.isString().stringValue());
141
					vueARafraichir.rafraichir(info);
141
					vueARafraichir.rafraichir(info);
142
				} else {
142
				} else {
143
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
143
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
144
				}
144
				}
145
			}
145
			}
146
		});		
146
		});		
147
	}
147
	}
148
	
148
	
149
	public void modifier(StructureAPersonne personnel) {
149
	public void modifier(StructureAPersonne personnel) {
150
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
150
		String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()};
151
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
151
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
152
		
152
		
153
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
153
		String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel);
154
		
154
		
155
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
155
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
156
			@Override
156
			@Override
157
			public void surReponse(JSONValue responseValue) {
157
			public void surReponse(JSONValue responseValue) {
158
				Information info = new Information("modif_structure_a_personne");
158
				Information info = new Information("modif_structure_a_personne");
159
				// Si la requête est un succès, reception d'une chaine
159
				// Si la requête est un succès, reception d'une chaine
160
				if (responseValue.isString() != null) {
160
				if (responseValue.isString() != null) {
161
					info.setMessage(responseValue.isString().stringValue());
161
					info.setMessage(responseValue.isString().stringValue());
162
					vueARafraichir.rafraichir(info);
162
					vueARafraichir.rafraichir(info);
163
				} else {
163
				} else {
164
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
164
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
165
				}
165
				}
166
			}
166
			}
167
		});
167
		});
168
	}
168
	}
169
	
169
	
170
	public void supprimer(String idStrAPer) {
170
	public void supprimer(String idStrAPer) {
171
		String[] parametres = {utilisateurId, idStrAPer};
171
		String[] parametres = {utilisateurId, idStrAPer};
172
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
172
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
173
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
173
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
174
			@Override
174
			@Override
175
			public void surReponse(JSONValue responseValue) {
175
			public void surReponse(JSONValue responseValue) {
176
				if (responseValue.isString() != null) {
176
				if (responseValue.isString() != null) {
177
					Information info = new Information("suppression_structure_a_personne");
177
					Information info = new Information("suppression_structure_a_personne");
178
					info.setMessage(responseValue.isString().stringValue());
178
					info.setMessage(responseValue.isString().stringValue());
179
					vueARafraichir.rafraichir(info);
179
					vueARafraichir.rafraichir(info);
180
				} else {
180
				} else {
181
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
181
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
182
				}
182
				}
183
			}
183
			}
184
		});
184
		});
185
	}
185
	}
186
	
186
	
187
	private String construirePost(String structureId, StructureAPersonne personnel) {
187
	private String construirePost(String structureId, StructureAPersonne personnel) {
188
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
188
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
189
		if (!personnel.getIdPersonne().equals("")) {
189
		if (!personnel.getIdPersonne().equals("")) {
190
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
190
			postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) +
191
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
191
				"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne());
192
		}
192
		}
193
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
193
		postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) +
194
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
194
			"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) +	
195
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
195
			"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) +
196
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
196
			"&csap_service=" + URL.encodeComponent(personnel.getService()) +
197
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
197
			"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) +
198
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
198
			"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) +
199
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
199
			"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) +
200
			"&cp_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +
-
 
201
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
200
			"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +
202
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
201
			"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +
203
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
202
			"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) +
204
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
203
			"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +
205
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
204
			"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +
206
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
205
			"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +
207
			"&cp_ce_deces=" + URL.encodeComponent(personnel.getDeces()) +
206
			"&cp_ce_deces=" + URL.encodeComponent(personnel.getDeces()) +
208
			"";
207
			"";
209
		return postDonnees;
208
		return postDonnees;
210
	}
209
	}
211
}
210
}