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 |
|
7 |
|
8 |
import com.extjs.gxt.ui.client.Registry;
|
8 |
import com.extjs.gxt.ui.client.Registry;
|
- |
|
9 |
import com.extjs.gxt.ui.client.widget.Info;
|
9 |
import com.google.gwt.core.client.GWT;
|
10 |
import com.google.gwt.core.client.GWT;
|
10 |
import com.google.gwt.http.client.Request;
|
11 |
import com.google.gwt.http.client.Request;
|
11 |
import com.google.gwt.http.client.RequestBuilder;
|
12 |
import com.google.gwt.http.client.RequestBuilder;
|
12 |
import com.google.gwt.http.client.RequestCallback;
|
13 |
import com.google.gwt.http.client.RequestCallback;
|
13 |
import com.google.gwt.http.client.RequestException;
|
14 |
import com.google.gwt.http.client.RequestException;
|
14 |
import com.google.gwt.http.client.Response;
|
15 |
import com.google.gwt.http.client.Response;
|
15 |
import com.google.gwt.json.client.JSONArray;
|
16 |
import com.google.gwt.json.client.JSONArray;
|
16 |
import com.google.gwt.json.client.JSONObject;
|
17 |
import com.google.gwt.json.client.JSONObject;
|
17 |
import com.google.gwt.json.client.JSONParser;
|
18 |
import com.google.gwt.json.client.JSONParser;
|
18 |
import com.google.gwt.json.client.JSONValue;
|
19 |
import com.google.gwt.json.client.JSONValue;
|
19 |
|
20 |
|
20 |
public class PublicationAsyncDao {
|
21 |
public class PublicationAsyncDao {
|
21 |
private static final String SERVICE_NOM = "CoelPublication";
|
22 |
private static final String SERVICE_NOM = "CoelPublication";
|
22 |
|
- |
|
23 |
private PublicationListe publications = null;
|
- |
|
24 |
private Rafraichissable vueARafraichir = null;
|
23 |
private Rafraichissable vueARafraichir = null;
|
25 |
|
24 |
|
26 |
public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
|
25 |
public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
|
27 |
vueARafraichir = vueARafraichirCourrante ;
|
26 |
vueARafraichir = vueARafraichirCourrante ;
|
28 |
}
|
27 |
}
|
29 |
|
28 |
|
30 |
public void selectionnerPublication(final String publicationId, String projetId, String nomComplet) {
|
29 |
public void selectionnerPublication(final String publicationId, String projetId, String nomComplet) {
|
31 |
// Ajout des paramètres et données à selectionner dans l'URL
|
30 |
// Ajout des paramètres et données à selectionner dans l'URL
|
32 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() +
|
31 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() +
|
33 |
SERVICE_NOM + "/" +
|
32 |
SERVICE_NOM + "/" +
|
34 |
(projetId == null ? "*" : projetId) + "/" +
|
33 |
(projetId == null ? "*" : projetId) + "/" +
|
35 |
(publicationId == null ? "*" : publicationId) + "/" +
|
34 |
(publicationId == null ? "*" : publicationId) + "/" +
|
36 |
(nomComplet == null ? "*" : nomComplet) + "/" +
|
35 |
(nomComplet == null ? "*" : nomComplet) + "/" +
|
37 |
"";
|
36 |
"";
|
38 |
|
37 |
|
39 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
|
38 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
|
40 |
|
39 |
|
41 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
40 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
42 |
@Override
|
41 |
@Override
|
43 |
public void surReponse(JSONValue responseValue) {
|
42 |
public void surReponse(JSONValue responseValue) {
|
44 |
if (responseValue != null) {
|
43 |
if (responseValue != null) {
|
45 |
// Si la requête est un succès, reception d'un objet ou d'un tableau
|
44 |
// Si la requête est un succès, reception d'un objet ou d'un tableau
|
46 |
if (responseValue.isObject() != null) {
|
45 |
if (responseValue.isObject() != null) {
|
47 |
final JSONObject reponse = responseValue.isObject();
|
46 |
final JSONObject reponse = responseValue.isObject();
|
48 |
// Transformation du tableau JSON réponse en ListeInstitution
|
47 |
// Transformation du tableau JSON réponse en ListeInstitution
|
49 |
Publication publication = new Publication(reponse);
|
48 |
Publication publication = new Publication(reponse);
|
50 |
// et on met à jour le demandeur des données
|
49 |
// et on met à jour le demandeur des données
|
51 |
vueARafraichir.rafraichir(publication);
|
50 |
vueARafraichir.rafraichir(publication);
|
52 |
} else if (responseValue.isArray() != null) {
|
51 |
} else if (responseValue.isArray() != null) {
|
53 |
final JSONArray reponse = responseValue.isArray();
|
52 |
final JSONArray reponse = responseValue.isArray();
|
54 |
PublicationListe publications = new PublicationListe(reponse);
|
53 |
PublicationListe publications = new PublicationListe(reponse);
|
55 |
vueARafraichir.rafraichir(publications);
|
54 |
vueARafraichir.rafraichir(publications);
|
56 |
} else {
|
55 |
} else {
|
57 |
GWT.log(url+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
|
56 |
GWT.log(url+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
|
58 |
}
|
57 |
}
|
59 |
} else {
|
58 |
} else {
|
60 |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
|
59 |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
|
61 |
if (publicationId == null) {
|
60 |
if (publicationId == null) {
|
62 |
PublicationListe publications = new PublicationListe(0);
|
61 |
PublicationListe publications = new PublicationListe(0);
|
63 |
vueARafraichir.rafraichir(publications);
|
62 |
vueARafraichir.rafraichir(publications);
|
64 |
}
|
63 |
}
|
65 |
}
|
64 |
}
|
66 |
}
|
65 |
}
|
67 |
});
|
66 |
});
|
68 |
}
|
67 |
}
|
69 |
|
68 |
|
70 |
public void modifierPublication(String utilisateurId, Publication pubAModifier) {
|
69 |
public void modifierPublication(String utilisateurId, Publication pubAModifier) {
|
71 |
// Demande de toutes les structures
|
70 |
// Demande de toutes les structures
|
72 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
71 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl()+SERVICE_NOM+"/"+pubAModifier.getId();
|
73 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+SERVICE_NOM+"/"+pubAModifier.getId());
|
- |
|
74 |
|
72 |
|
75 |
try {
|
- |
|
76 |
rb.sendRequest(pubAModifier.toReqString()+"&cmhl_ce_modifier_par="+utilisateurId, new RequestCallback() {
|
73 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
|
77 |
|
- |
|
78 |
public void onError(Request request, Throwable exception) {
|
74 |
String postDonneesEncodees = pubAModifier.toReqString();
|
79 |
// TODO Auto-generated method stub
|
- |
|
80 |
|
75 |
|
- |
|
76 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
81 |
}
|
77 |
@Override
|
82 |
|
- |
|
83 |
public void onResponseReceived(Request request, Response response) {
|
78 |
public void surReponse(JSONValue responseValue) {
|
84 |
Boolean defaut = true;
|
79 |
if (responseValue != null) {
|
85 |
if (response.getText().length() != 0 && response.getText() != null) {
|
- |
|
86 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
80 |
Information info = new Information("publication_valide");
|
87 |
|
81 |
|
88 |
// Si la requête est un succès, reception d'un tableau
|
82 |
// Si la requête est un succès, reception d'une chaine
|
89 |
if (responseValue.isArray() != null) {
|
83 |
if (responseValue.isString() != null) {
|
90 |
final JSONObject reponse = responseValue.isObject();
|
- |
|
91 |
// Transformation du tableau JSON réponse en ListeInstitution
|
84 |
info.setMessage(responseValue.isString().stringValue());
|
92 |
publications = new PublicationListe(reponse);
|
- |
|
93 |
// et on met à jour le demandeur des données
|
- |
|
94 |
vueARafraichir.rafraichir(publications);
|
85 |
} else {
|
95 |
// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
|
- |
|
96 |
defaut = false;
|
86 |
info.setDeboguage("La réponse n'est pas une chaine JSON.");
|
97 |
}
|
87 |
}
|
98 |
}
|
- |
|
99 |
if (defaut == true) {
|
- |
|
100 |
publications = new PublicationListe(0);
|
88 |
|
101 |
vueARafraichir.rafraichir(publications);
|
- |
|
102 |
}
|
89 |
vueARafraichir.rafraichir(info);
|
103 |
}
|
90 |
}
|
104 |
});
|
- |
|
105 |
} catch (RequestException e) {
|
- |
|
106 |
e.printStackTrace();
|
91 |
}
|
107 |
}
|
92 |
});
|
108 |
}
|
93 |
}
|
109 |
|
94 |
|
110 |
public void ajouterPublication(String utilisateurId, Publication pubAModifier) {
|
95 |
public void ajouterPublication(String utilisateurId, Publication pubAModifier) {
|
111 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
- |
|
112 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+SERVICE_NOM+"/");
|
- |
|
113 |
|
- |
|
114 |
try {
|
- |
|
115 |
rb.sendRequest(pubAModifier.toReqString()+"&cmhl_ce_modifier_par="+utilisateurId, new RequestCallback() {
|
- |
|
- |
|
96 |
|
- |
|
97 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl()+SERVICE_NOM+"/";
|
116 |
|
98 |
|
- |
|
99 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
|
- |
|
100 |
String postDonneesEncodees = pubAModifier.toReqString()+"&cmhl_ce_modifier_par="+utilisateurId;
|
117 |
public void onError(Request request, Throwable exception) {
|
101 |
|
118 |
// TODO Auto-generated method stub
|
- |
|
- |
|
102 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
119 |
|
- |
|
120 |
}
|
- |
|
121 |
|
- |
|
122 |
public void onResponseReceived(Request request, Response response) {
|
103 |
|
123 |
Boolean defaut = true;
|
104 |
public void surReponse(JSONValue responseValue) {
|
124 |
if (response.getText().length() != 0 && response.getText() != null) {
|
105 |
|
125 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
106 |
Information info = new Information("publication_valide");
|
126 |
|
107 |
|
127 |
// Si la requête est un succès, reception d'un tableau
|
- |
|
128 |
if (responseValue.isObject() != null) {
|
- |
|
129 |
final JSONObject reponse = responseValue.isObject();
|
- |
|
130 |
// Transformation du tableau JSON réponse en ListeInstitution
|
- |
|
131 |
publications = new PublicationListe(reponse);
|
- |
|
132 |
// et on met à jour le demandeur des données
|
- |
|
133 |
vueARafraichir.rafraichir(publications);
|
108 |
// Si la requête est un succès, reception d'une chaine
|
134 |
// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
|
- |
|
135 |
defaut = false;
|
- |
|
136 |
}
|
109 |
if (responseValue.isString() != null) {
|
137 |
}
|
- |
|
138 |
if (defaut == true) {
|
- |
|
139 |
publications = new PublicationListe(0);
|
110 |
info.setMessage(responseValue.isString().stringValue());
|
140 |
vueARafraichir.rafraichir(publications);
|
- |
|
141 |
}
|
- |
|
142 |
}
|
111 |
} else {
|
143 |
});
|
112 |
info.setDeboguage("La réponse n'est pas une chaine JSON.");
|
144 |
} catch (RequestException e) {
|
113 |
}
|
- |
|
114 |
vueARafraichir.rafraichir(info);
|
145 |
e.printStackTrace();
|
115 |
}
|
146 |
}
|
116 |
|
147 |
|
117 |
}) ;
|
148 |
}
|
118 |
}
|
149 |
|
119 |
|
150 |
public void supprimerPublication(String utilisateurId, String idPubs) {
|
120 |
public void supprimerPublication(String utilisateurId, String idPubs) {
|
151 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
121 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
152 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+SERVICE_NOM+"/"+utilisateurId+"/"+idPubs);
|
122 |
JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.POST, url+SERVICE_NOM+"/"+utilisateurId+"/"+idPubs);
|
153 |
|
- |
|
154 |
try {
|
- |
|
155 |
rb.sendRequest("action=DELETE", new RequestCallback() {
|
- |
|
156 |
|
- |
|
157 |
public void onError(Request request, Throwable exception) {
|
- |
|
158 |
|
- |
|
159 |
GWT.log("Erreur dans la requête de suppression", exception);
|
- |
|
160 |
|
- |
|
- |
|
123 |
|
- |
|
124 |
rb.envoyerRequete("action=DELETE", new JsonRestRequestCallback() {
|
161 |
}
|
125 |
|
162 |
|
126 |
@Override
|
163 |
public void onResponseReceived(Request request, Response response) {
|
- |
|
164 |
Boolean defaut = true;
|
127 |
public void surReponse(JSONValue responseValue) {
|
165 |
if (response.getText().length() != 0 && response.getText() != null) {
|
128 |
if (responseValue != null) {
|
166 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
129 |
Information info = new Information("suppression_publication");
|
167 |
|
130 |
|
168 |
// Si la requête est un succès, reception d'un tableau
|
- |
|
169 |
if (responseValue.isObject() != null) {
|
131 |
// Si la requête est un succès, reception d'une chaine
|
170 |
final JSONObject reponse = responseValue.isObject();
|
- |
|
171 |
// Transformation du tableau JSON réponse en ListeInstitution
|
- |
|
172 |
publications = new PublicationListe(reponse);
|
132 |
if (responseValue.isString() != null) {
|
173 |
// et on met à jour le demandeur des données
|
- |
|
174 |
vueARafraichir.rafraichir(publications);
|
133 |
info.setMessage(responseValue.isString().stringValue());
|
175 |
// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
|
134 |
} else {
|
176 |
defaut = false;
|
- |
|
177 |
}
|
- |
|
178 |
}
|
135 |
info.setDeboguage("La réponse n'est pas une chaine JSON.");
|
179 |
if (defaut == true) {
|
- |
|
180 |
publications = new PublicationListe(0);
|
136 |
}
|
181 |
vueARafraichir.rafraichir(publications);
|
137 |
|
182 |
}
|
- |
|
183 |
}
|
- |
|
184 |
});
|
138 |
vueARafraichir.rafraichir(info);
|
185 |
} catch (RequestException e) {
|
- |
|
186 |
e.printStackTrace();
|
139 |
}
|
187 |
}
|
140 |
}
|
188 |
|
141 |
});
|
189 |
}
|
142 |
}
|
190 |
|
143 |
|
191 |
}
|
144 |
}
|