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