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 1561
1
package org.tela_botanica.client.modeles.publication;
1
package org.tela_botanica.client.modeles.publication;
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.modeles.collection.CollectionAPublicationListe;
11
import org.tela_botanica.client.modeles.collection.CollectionAPublicationListe;
12
import org.tela_botanica.client.synchronisation.Reponse;
12
import org.tela_botanica.client.synchronisation.Reponse;
13
import org.tela_botanica.client.util.Debug;
13
import org.tela_botanica.client.util.Debug;
14
import org.tela_botanica.client.util.UtilDAO;
14
import org.tela_botanica.client.util.UtilDAO;
15
 
15
 
16
import com.extjs.gxt.ui.client.Registry;
16
import com.extjs.gxt.ui.client.Registry;
17
import com.extjs.gxt.ui.client.widget.Window;
17
import com.extjs.gxt.ui.client.widget.Window;
18
import com.google.gwt.core.client.GWT;
18
import com.google.gwt.core.client.GWT;
19
import com.google.gwt.http.client.URL;
19
import com.google.gwt.http.client.URL;
20
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONArray;
21
import com.google.gwt.json.client.JSONObject;
21
import com.google.gwt.json.client.JSONObject;
22
import com.google.gwt.json.client.JSONValue;
22
import com.google.gwt.json.client.JSONValue;
23
 
23
 
24
public class PublicationAPersonneAsyncDao {
24
public class PublicationAPersonneAsyncDao {
25
 
25
 
26
	private static final String SERVICE_NOM = "CoelPublicationAPersonne";
26
	private static final String SERVICE_NOM = "CoelPublicationAPersonne";
27
	
27
	
28
	private String utilisateurId = null;
28
	private String utilisateurId = null;
29
	private Rafraichissable vueARafraichir = null;
29
	private Rafraichissable vueARafraichir = null;
30
	
30
	
31
	public PublicationAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
31
	public PublicationAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
32
		if (Mediateur.DEBUG) System.out.println("|| PublicationAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
32
		if (Mediateur.DEBUG) System.out.println("|| PublicationAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
33
		vueARafraichir = vueARafraichirCourrante;
33
		vueARafraichir = vueARafraichirCourrante;
34
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
34
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
35
	}
35
	}
36
	
36
	
37
	public void selectionner(final boolean paginationProgressive, String publicationId, String personnesId, String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
37
	public void selectionner(final boolean paginationProgressive, String publicationId, String personnesId, String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
38
 
38
 
39
		String[] parametres = {publicationId, personnesId, roleId};
39
		String[] parametres = {publicationId, personnesId, roleId};
40
		
40
		
41
		HashMap<String, String> restrictions = new HashMap<String, String>();
41
		HashMap<String, String> restrictions = new HashMap<String, String>();
42
		
42
		
43
		if (nbElements != -1)	{
43
		if (nbElements != -1)	{
44
			restrictions.put("limit", String.valueOf(nbElements));
44
			restrictions.put("limit", String.valueOf(nbElements));
45
		}
45
		}
46
		
46
		
47
		restrictions.put("orderby", "cpuap_ordre");
47
		restrictions.put("orderby", "cpuap_ordre");
48
 
48
 
49
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
49
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
50
		if (paginationProgressive) {
50
		if (paginationProgressive) {
51
 
51
 
52
			/** DEFINITION DU TUPLE DE DEPART **/
52
			/** DEFINITION DU TUPLE DE DEPART **/
53
			restrictions.put("start", String.valueOf(start));
53
			restrictions.put("start", String.valueOf(start));
54
			
54
			
55
			/** CONSTRUCTION DE LA REQUETE **/
55
			/** CONSTRUCTION DE LA REQUETE **/
56
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
56
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
57
    		
57
    		
58
    		/** ENVOI DE LA REQUETE **/
58
    		/** ENVOI DE LA REQUETE **/
59
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
59
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
60
    		{
60
    		{
61
    			/** RECEPTION DE LA REPONSE **/
61
    			/** RECEPTION DE LA REPONSE **/
62
    			public void surReponse(JSONValue responseValue)
62
    			public void surReponse(JSONValue responseValue)
63
    			{    				
63
    			{    				
64
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
64
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
65
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
65
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
66
    				
66
    				
67
					if (seqId != null)	{
67
					if (seqId != null)	{
68
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste paginée, retour au sequenceur");
68
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste paginée, retour au sequenceur");
69
						Reponse reponseRequete = new Reponse(responseValue, seqId);
69
						Reponse reponseRequete = new Reponse(responseValue, seqId);
70
						vueARafraichir.rafraichir(reponseRequete);
70
						vueARafraichir.rafraichir(reponseRequete);
71
					}
71
					}
72
					else	{
72
					else	{
73
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
73
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
74
						vueARafraichir.rafraichir(responseValue);
74
						vueARafraichir.rafraichir(responseValue);
75
					}
75
					}
76
    			}
76
    			}
77
    		});
77
    		});
78
		}
78
		}
79
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
79
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
80
		else {
80
		else {
81
			
81
			
82
			/** DEFINITION DU TUPLE DE DEPART **/
82
			/** DEFINITION DU TUPLE DE DEPART **/
83
			restrictions.put("start", String.valueOf(start*nbElements));
83
			restrictions.put("start", String.valueOf(start*nbElements));
84
			
84
			
85
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
85
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
86
			
86
			
87
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
87
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
88
				@Override
88
				@Override
89
				public void surReponse(JSONValue responseValue) {
89
				public void surReponse(JSONValue responseValue) {
90
 
90
 
91
					if (responseValue != null) {
91
					if (responseValue != null) {
92
 
92
 
93
						JSONObject responseObject = responseValue.isObject();
93
						JSONObject responseObject = responseValue.isObject();
94
						if (responseObject != null) {
94
						if (responseObject != null) {
95
							// Si la réponse est un tableau, alors c'est une liste de collections qui a été retournée
95
							// Si la réponse est un tableau, alors c'est une liste de collections qui a été retournée
96
							if (responseObject.get("publicationsAPersonne").isArray() != null) {
96
							if (responseObject.get("publicationsAPersonne").isArray() != null) {
97
 
97
 
98
								final JSONArray reponse = responseObject.get("publicationsAPersonne").isArray();
98
								final JSONArray reponse = responseObject.get("publicationsAPersonne").isArray();
99
								
99
								
100
								// Transformation du tableau JSON réponse en ListeInstitution
100
								// Transformation du tableau JSON réponse en ListeInstitution
101
								PublicationAPersonneListe publicationsAPersonneListe = new PublicationAPersonneListe(reponse);
101
								PublicationAPersonneListe publicationsAPersonneListe = new PublicationAPersonneListe(reponse);
102
								
102
								
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
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
105
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
106
									Reponse reponseRequete = new Reponse(publicationsAPersonneListe, seqId);
106
									Reponse reponseRequete = new Reponse(publicationsAPersonneListe, seqId);
107
									vueARafraichir.rafraichir(reponseRequete);
107
									vueARafraichir.rafraichir(reponseRequete);
108
								}
108
								}
109
								else	{
109
								else	{
110
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
110
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
111
									vueARafraichir.rafraichir(publicationsAPersonneListe);
111
									vueARafraichir.rafraichir(publicationsAPersonneListe);
112
								}
112
								}
113
							// Si la réponse est un objet, alors c'est une unique collection qui a été retournée
113
							// Si la réponse est un objet, alors c'est une unique collection qui a été retournée
114
							} else if (responseObject.get("publicationsAPersonne").isObject() != null) {
114
							} else if (responseObject.get("publicationsAPersonne").isObject() != null) {
115
								
115
								
116
								final JSONObject reponse = responseObject.get("publicationsAPersonne").isObject();
116
								final JSONObject reponse = responseObject.get("publicationsAPersonne").isObject();
117
								// Transformation du tableau JSON réponse en ListeInstitution
117
								// Transformation du tableau JSON réponse en ListeInstitution
118
								PublicationAPersonne publicationAPersonne = new PublicationAPersonne(reponse);						
118
								PublicationAPersonne publicationAPersonne = new PublicationAPersonne(reponse);						
119
								// et on met à jour le demandeur des données
119
								// et on met à jour le demandeur des données
120
								if (seqId!=null)	{
120
								if (seqId!=null)	{
121
									Reponse reponseRequete = new Reponse(publicationAPersonne, seqId);
121
									Reponse reponseRequete = new Reponse(publicationAPersonne, seqId);
122
									vueARafraichir.rafraichir(reponseRequete);
122
									vueARafraichir.rafraichir(reponseRequete);
123
								} else {
123
								} else {
124
									vueARafraichir.rafraichir(publicationAPersonne);
124
									vueARafraichir.rafraichir(publicationAPersonne);
125
								}
125
								}
126
							} else {
126
							} else {
127
								GWT.log("La réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString(), null);
127
								GWT.log("La réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString(), null);
128
							}
128
							}
129
						}
129
						}
130
					} else {					
130
					} else {					
131
						// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
131
						// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
132
						PublicationAPersonneListe publicationAPersonneListe = new PublicationAPersonneListe(0);
132
						PublicationAPersonneListe publicationAPersonneListe = new PublicationAPersonneListe(0);
133
						if (seqId!=null)	{
133
						if (seqId!=null)	{
134
							Reponse reponseRequete = new Reponse(publicationAPersonneListe, seqId);
134
							Reponse reponseRequete = new Reponse(publicationAPersonneListe, seqId);
135
							vueARafraichir.rafraichir(reponseRequete);
135
							vueARafraichir.rafraichir(reponseRequete);
136
						} else {
136
						} else {
137
							vueARafraichir.rafraichir(publicationAPersonneListe);
137
							vueARafraichir.rafraichir(publicationAPersonneListe);
138
						}
138
						}
139
					}
139
					}
140
				}
140
				}
141
			});
141
			});
142
		}
142
		}
143
	}
143
	}
144
	
144
	
145
	public void ajouter(String publicationId, String personnesId, String ordreAuteurs, String roleId,  final Integer seqId) {
145
	public void ajouter(String publicationId, String personnesId, String ordreAuteurs, String roleId,  final Integer seqId) {
146
		String postDonneesEncodees = "cpuap_id_publication="+URL.encodeComponent(publicationId)
146
		String postDonneesEncodees = "cpuap_id_publication="+URL.encodeQueryString(publicationId)
147
		+"&cpuap_id_auteur="+URL.encodeComponent(personnesId)
147
			+"&cpuap_id_auteur="+URL.encodeQueryString(personnesId)
148
		+"&cpuap_ordre="+URL.encodeComponent(ordreAuteurs)
148
			+"&cpuap_ordre="+URL.encodeQueryString(ordreAuteurs)
149
		+"&cpuap_id_role="+URL.encodeComponent(roleId)
149
			+"&cpuap_id_role="+URL.encodeQueryString(roleId)
150
		+"&cmhl_ce_modifier_par="+utilisateurId;		
150
			+"&cmhl_ce_modifier_par="+utilisateurId;
-
 
151
		
151
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
152
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
152
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
153
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
153
			@Override
154
			@Override
154
			public void surReponse(JSONValue reponseValeur) {
155
			public void surReponse(JSONValue reponseValeur) {
155
				traiterReponse(reponseValeur, "ajout_publication_a_personne", seqId);
156
				traiterReponse(reponseValeur, "ajout_publication_a_personne", seqId);
156
			}
157
			}
157
		});
158
		});
158
	}
159
	}
159
 
160
 
160
	public void modifier(String publicationId, String personnesId, String ordreAuteurs, String roleId, final Integer seqId) {
161
	public void modifier(String publicationId, String personnesId, String ordreAuteurs, String roleId, final Integer seqId) {
161
		String[] parametres = {publicationId, personnesId, roleId};
162
		String[] parametres = {publicationId, personnesId, roleId};
162
		
163
		
163
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
164
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
164
		
165
		
165
		String postDonneesEncodees = "cpuap_id_publication="+URL.encodeComponent(publicationId)
166
		String postDonneesEncodees = "cpuap_id_publication="+URL.encodeQueryString(publicationId)
166
		+"&cpuap_id_auteur="+URL.encodeComponent(personnesId)
167
			+"&cpuap_id_auteur="+URL.encodeQueryString(personnesId)
167
		+"&cpuap_id_role="+URL.encodeComponent(roleId)
168
			+"&cpuap_id_role="+URL.encodeQueryString(roleId)
168
		+"&cpuap_ordre="+URL.encodeComponent(ordreAuteurs)
169
			+"&cpuap_ordre="+URL.encodeQueryString(ordreAuteurs)
169
		+"&cmhl_ce_modifier_par="+utilisateurId;	
170
			+"&cmhl_ce_modifier_par="+utilisateurId;
170
		
171
		
171
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
172
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
172
			@Override
173
			@Override
173
			public void surReponse(JSONValue reponseValeur) {
174
			public void surReponse(JSONValue reponseValeur) {
174
				traiterReponse(reponseValeur, "modif_publication_a_personne", seqId);
175
				traiterReponse(reponseValeur, "modif_publication_a_personne", seqId);
175
			}
176
			}
176
		});
177
		});
177
	}
178
	}
178
	
179
	
179
	public void supprimer(String idPublicationAPersonne) {
180
	public void supprimer(String idPublicationAPersonne) {
180
		String[] parametres = {utilisateurId, idPublicationAPersonne};
181
		String[] parametres = {utilisateurId, idPublicationAPersonne};
181
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);		
182
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);		
182
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
183
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
183
			@Override
184
			@Override
184
			public void surReponse(JSONValue responseValue) {
185
			public void surReponse(JSONValue responseValue) {
185
				if (responseValue.isString() != null) {
186
				if (responseValue.isString() != null) {
186
					Information info = new Information("suppression_publication_a_personne");
187
					Information info = new Information("suppression_publication_a_personne");
187
					info.setMessage(responseValue.isString().stringValue());
188
					info.setMessage(responseValue.isString().stringValue());
188
					vueARafraichir.rafraichir(info);
189
					vueARafraichir.rafraichir(info);
189
				} else {
190
				} else {
190
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
191
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
191
				}
192
				}
192
			}
193
			}
193
		});
194
		});
194
	}
195
	}
195
	
196
	
196
	private void traiterReponse(JSONValue reponseValeur, String type, Integer seqId) {
197
	private void traiterReponse(JSONValue reponseValeur, String type, Integer seqId) {
197
		Information info = new Information(type);
198
		Information info = new Information(type);
198
		// Si la requête est un succès, réception d'une chaîne
199
		// Si la requête est un succès, réception d'une chaîne
199
		if (reponseValeur.isBoolean() != null) {
200
		if (reponseValeur.isBoolean() != null) {
200
			info.setDonnee(reponseValeur.isBoolean().booleanValue());
201
			info.setDonnee(reponseValeur.isBoolean().booleanValue());
201
		} else if (reponseValeur.isString() != null) {
202
		} else if (reponseValeur.isString() != null) {
202
			info.setDonnee(reponseValeur.isString().stringValue());
203
			info.setDonnee(reponseValeur.isString().stringValue());
203
		} else {
204
		} else {
204
			info.setDeboguage("La réponse n'est pas une chaine JSON.");
205
			info.setDeboguage("La réponse n'est pas une chaine JSON.");
205
		}
206
		}
206
		
207
		
207
		if (seqId != null)	{
208
		if (seqId != null)	{
208
			Reponse retourRequete = new Reponse(info, seqId);
209
			Reponse retourRequete = new Reponse(info, seqId);
209
			vueARafraichir.rafraichir(retourRequete);
210
			vueARafraichir.rafraichir(retourRequete);
210
		} else {
211
		} else {
211
			vueARafraichir.rafraichir(info);
212
			vueARafraichir.rafraichir(info);
212
		}
213
		}
213
		
214
		
214
	}
215
	}
215
}
216
}