1 |
package org.tela_botanica.client.modeles;
|
1 |
package org.tela_botanica.client.modeles;
|
2 |
|
2 |
|
3 |
import org.tela_botanica.client.RegistreId;
|
3 |
import org.tela_botanica.client.RegistreId;
|
4 |
import org.tela_botanica.client.http.JsonRestRequestBuilder;
|
4 |
import org.tela_botanica.client.http.JsonRestRequestBuilder;
|
5 |
import org.tela_botanica.client.http.JsonRestRequestCallback;
|
5 |
import org.tela_botanica.client.http.JsonRestRequestCallback;
|
6 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
6 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
7 |
import org.tela_botanica.client.util.UtilDAO;
|
7 |
import org.tela_botanica.client.util.UtilDAO;
|
8 |
|
8 |
|
9 |
import com.extjs.gxt.ui.client.Registry;
|
9 |
import com.extjs.gxt.ui.client.Registry;
|
10 |
import com.google.gwt.core.client.GWT;
|
10 |
import com.google.gwt.core.client.GWT;
|
11 |
import com.google.gwt.http.client.RequestBuilder;
|
11 |
import com.google.gwt.http.client.RequestBuilder;
|
12 |
import com.google.gwt.json.client.JSONArray;
|
12 |
import com.google.gwt.json.client.JSONArray;
|
13 |
import com.google.gwt.json.client.JSONObject;
|
13 |
import com.google.gwt.json.client.JSONObject;
|
14 |
import com.google.gwt.json.client.JSONValue;
|
14 |
import com.google.gwt.json.client.JSONValue;
|
15 |
|
15 |
|
16 |
public class PublicationAsyncDao {
|
16 |
public class PublicationAsyncDao {
|
17 |
private static final String SERVICE_NOM = "CoelPublication";
|
17 |
private static final String SERVICE_NOM = "CoelPublication";
|
18 |
private Rafraichissable vueARafraichir = null;
|
18 |
private Rafraichissable vueARafraichir = null;
|
19 |
|
19 |
|
20 |
public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
|
20 |
public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
|
21 |
vueARafraichir = vueARafraichirCourrante ;
|
21 |
vueARafraichir = vueARafraichirCourrante ;
|
22 |
}
|
22 |
}
|
23 |
|
23 |
|
24 |
public void selectionner(final String publicationId, String projetId, String nomComplet) {
|
24 |
public void selectionner(final String publicationId, String projetId, String nomComplet) {
|
25 |
String[] parametres = {projetId, publicationId, nomComplet};
|
25 |
String[] parametres = {projetId, publicationId, nomComplet};
|
26 |
|
26 |
|
27 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
|
27 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
|
28 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
28 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
29 |
@Override
|
29 |
@Override
|
30 |
public void surReponse(JSONValue responseValue) {
|
30 |
public void surReponse(JSONValue responseValue) {
|
31 |
if (responseValue != null) {
|
31 |
if (responseValue != null) {
|
32 |
// Si la requête est un succès, réception d'un objet ou d'un tableau
|
32 |
// Si la requête est un succès, réception d'un objet ou d'un tableau
|
33 |
if (responseValue.isObject() != null) {
|
33 |
if (responseValue.isObject() != null) {
|
34 |
final JSONObject reponse = responseValue.isObject();
|
34 |
final JSONObject reponse = responseValue.isObject();
|
35 |
// Transformation du tableau JSON réponse en ListeInstitution
|
35 |
// Transformation du tableau JSON réponse en ListeInstitution
|
36 |
Publication publication = new Publication(reponse);
|
36 |
Publication publication = new Publication(reponse);
|
37 |
// et on met à jour le demandeur des données
|
37 |
// et on met à jour le demandeur des données
|
38 |
vueARafraichir.rafraichir(publication);
|
38 |
vueARafraichir.rafraichir(publication);
|
39 |
} else if (responseValue.isArray() != null) {
|
39 |
} else if (responseValue.isArray() != null) {
|
40 |
final JSONArray reponse = responseValue.isArray();
|
40 |
final JSONArray reponse = responseValue.isArray();
|
41 |
PublicationListe publications = new PublicationListe(reponse);
|
41 |
PublicationListe publications = new PublicationListe(reponse);
|
42 |
vueARafraichir.rafraichir(publications);
|
42 |
vueARafraichir.rafraichir(publications);
|
43 |
} else {
|
43 |
} else {
|
44 |
GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
|
44 |
GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
|
45 |
}
|
45 |
}
|
46 |
} else {
|
46 |
} else {
|
47 |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
|
47 |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
|
48 |
if (publicationId == null) {
|
48 |
if (publicationId == null) {
|
49 |
PublicationListe publications = new PublicationListe(0);
|
49 |
PublicationListe publications = new PublicationListe(0);
|
50 |
vueARafraichir.rafraichir(publications);
|
50 |
vueARafraichir.rafraichir(publications);
|
51 |
}
|
51 |
}
|
52 |
}
|
52 |
}
|
53 |
}
|
53 |
}
|
54 |
});
|
54 |
});
|
55 |
}
|
55 |
}
|
56 |
|
56 |
|
57 |
public void modifier(String utilisateurId, Publication pubAModifier) {
|
57 |
public void ajouter(String utilisateurId, Publication publication) {
|
58 |
// Demande de toutes les structures
|
- |
|
59 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl()+SERVICE_NOM+"/"+pubAModifier.getId();
|
58 |
String postDonneesEncodees = publication.obtenirChainePOST()+"&cmhl_ce_modifier_par="+utilisateurId;
|
60 |
|
59 |
|
61 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.POST, url);
|
- |
|
62 |
String postDonneesEncodees = pubAModifier.toReqString();
|
- |
|
63 |
|
60 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
|
64 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
61 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
65 |
@Override
|
62 |
@Override
|
66 |
public void surReponse(JSONValue reponseValeur) {
|
63 |
public void surReponse(JSONValue reponseValeur) {
|
67 |
traiterReponse(reponseValeur, "publication_valide");
|
64 |
traiterReponse(reponseValeur, "publication_valide");
|
68 |
}
|
65 |
}
|
69 |
});
|
66 |
}) ;
|
70 |
}
|
67 |
}
|
71 |
|
68 |
|
72 |
public void ajouter(String utilisateurId, Publication publication) {
|
69 |
public void modifier(String utilisateurId, Publication publication) {
|
- |
|
70 |
String[] parametres = {publication.getId()};
|
- |
|
71 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
73 |
|
72 |
|
74 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl()+SERVICE_NOM+"/";
|
- |
|
75 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.POST, url);
|
- |
|
76 |
String postDonneesEncodees = publication.toReqString()+"&cmhl_ce_modifier_par="+utilisateurId;
|
73 |
String postDonneesEncodees = publication.obtenirChainePOST();
|
77 |
|
74 |
|
78 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
75 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
79 |
@Override
|
76 |
@Override
|
80 |
public void surReponse(JSONValue reponseValeur) {
|
77 |
public void surReponse(JSONValue reponseValeur) {
|
81 |
traiterReponse(reponseValeur, "publication_valide");
|
78 |
traiterReponse(reponseValeur, "publication_valide");
|
82 |
}
|
79 |
}
|
83 |
}) ;
|
80 |
});
|
84 |
}
|
81 |
}
|
85 |
|
82 |
|
86 |
public void supprimer(String utilisateurId, String idPubs) {
|
83 |
public void supprimer(String utilisateurId, String publicationsId) {
|
87 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
84 |
String[] parametres = {utilisateurId, publicationsId};
|
88 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.POST, url+SERVICE_NOM+"/"+utilisateurId+"/"+idPubs);
|
- |
|
89 |
|
85 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
90 |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
|
86 |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
|
91 |
@Override
|
87 |
@Override
|
92 |
public void surReponse(JSONValue reponseValeur) {
|
88 |
public void surReponse(JSONValue reponseValeur) {
|
93 |
traiterReponse(reponseValeur, "suppression_publication");
|
89 |
traiterReponse(reponseValeur, "suppression_publication");
|
94 |
}
|
90 |
}
|
95 |
});
|
91 |
});
|
96 |
}
|
92 |
}
|
97 |
|
93 |
|
98 |
private void traiterReponse(JSONValue reponseValeur, String type) {
|
94 |
private void traiterReponse(JSONValue reponseValeur, String type) {
|
99 |
Information info = new Information(type);
|
95 |
Information info = new Information(type);
|
100 |
// Si la requête est un succès, réception d'une chaîne
|
96 |
// Si la requête est un succès, réception d'une chaîne
|
101 |
if (reponseValeur.isString() != null) {
|
97 |
if (reponseValeur.isString() != null) {
|
102 |
info.setDonnee(reponseValeur.isString().stringValue());
|
98 |
info.setDonnee(reponseValeur.isString().stringValue());
|
103 |
} else {
|
99 |
} else {
|
104 |
info.setDeboguage("La réponse n'est pas une chaine JSON.");
|
100 |
info.setDeboguage("La réponse n'est pas une chaine JSON.");
|
105 |
}
|
101 |
}
|
106 |
vueARafraichir.rafraichir(info);
|
102 |
vueARafraichir.rafraichir(info);
|
107 |
}
|
103 |
}
|
108 |
|
104 |
|
109 |
}
|
105 |
}
|