Subversion Repositories eFlore/Applications.coel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1942 → Rev 1943

/branches/v1.11-okuzgozu/src/org/tela_botanica/client/modeles/collection/CollectionAPersonneAsyncDao.java
New file
0,0 → 1,189
package org.tela_botanica.client.modeles.collection;
 
import java.util.HashMap;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.http.JsonRestRequestBuilder;
import org.tela_botanica.client.http.JsonRestRequestCallback;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.synchronisation.Reponse;
import org.tela_botanica.client.util.Debug;
import org.tela_botanica.client.util.UtilDAO;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
 
public class CollectionAPersonneAsyncDao {
private static final String SERVICE_NOM = "CoelCollectionAPersonne";
 
private String utilisateurId = null;
private Rafraichissable vueARafraichir = null;
 
public CollectionAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
if (Mediateur.DEBUG) System.out.println("|| CollectionAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
vueARafraichir = vueARafraichirCourrante;
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
}
public void selectionner(final boolean paginationProgressive, final String collectionId, final String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
 
String[] parametres = {collectionId, roleId};
HashMap<String, String> restrictions = new HashMap<String, String>();
if (nbElements != -1) {
restrictions.put("limit", String.valueOf(nbElements));
}
restrictions.put("orderby", "cp_nom");
 
/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
if (paginationProgressive) {
 
/** DEFINITION DU TUPLE DE DEPART **/
restrictions.put("start", String.valueOf(start));
/** CONSTRUCTION DE LA REQUETE **/
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
/** ENVOI DE LA REQUETE **/
rb.envoyerRequete(null, new JsonRestRequestCallback()
{
/** RECEPTION DE LA REPONSE **/
public void surReponse(JSONValue responseValue)
{
/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
* On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
if (seqId != null) {
if (Mediateur.DEBUG) System.out.println("<-- CollectionAPersonneAsyncDao > Liste paginée, retour au sequenceur");
Reponse reponseRequete = new Reponse(responseValue, seqId);
vueARafraichir.rafraichir(reponseRequete);
}
else {
if (Mediateur.DEBUG) System.out.println("<-- CollectionAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
vueARafraichir.rafraichir(responseValue);
}
}
});
}
/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
else {
/** DEFINITION DU TUPLE DE DEPART **/
restrictions.put("start", String.valueOf(start*nbElements));
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue != null) {
 
JSONObject responseObject = responseValue.isObject();
Information info = new Information("liste_collection_a_personne");
 
if (responseObject != null) {
// Si la réponse est un tableau, alors c'est une liste de collections qui a été retournée
if (responseObject.get("collectionsAPersonne").isArray() != null) {
final JSONArray reponse = responseObject.get("collectionsAPersonne").isArray();
// Transformation du tableau JSON réponse en ListeInstitution
CollectionAPersonneListe personnes = new CollectionAPersonneListe(reponse);
info.setDonnee(0, personnes);
// et on met à jour le demandeur des données
if (seqId != null) {
Reponse reponseRequete = new Reponse(info, seqId);
vueARafraichir.rafraichir(reponseRequete);
}
else {
vueARafraichir.rafraichir(info);
}
// Si la réponse est un objet, alors c'est une unique collection qui a été retournée
} else if (responseObject.get("collectionsAPersonne").isObject() != null) {
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
}
}
} else {
// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
if (collectionId == null) {
// Dans le cas, où nous demandons toutes les relations Collection à Personne et qu'il n'y en a pas, nous retournons un message d'information
Information info = new Information("liste_collection_a_personne");
info.setMessage("Aucune relations entre la collection et les personnes");
vueARafraichir.rafraichir(info);
}
}
}
});
}
}
 
public void ajouter(String collectionId, CollectionAPersonne personnes) {
String postDonneesEncodees = construirePost(collectionId, personnes);
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
// Si la requête est un succès, reception d'une chaine
if (responseValue.isString() != null) {
Information info = new Information("ajout_collection_a_personne");
info.setMessage(responseValue.isString().stringValue());
vueARafraichir.rafraichir(info);
} else {
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
}
}
});
}
public void modifier(CollectionAPersonne personnes) {
String[] parametres = {personnes.getIdCollection(), personnes.getIdPersonne(), personnes.getIdRole()};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
String postDonneesEncodees = construirePost(personnes.getIdCollection(), personnes);
 
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
Information info = new Information("modif_collection_a_personne");
// Si la requête est un succès, reception d'une chaine
if (responseValue.isString() != null) {
info.setMessage(responseValue.isString().stringValue());
vueARafraichir.rafraichir(info);
} else {
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
}
}
});
}
public void supprimer(String idCollectionAPersonne) {
String[] parametres = {utilisateurId, idCollectionAPersonne};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue.isString() != null) {
Information info = new Information("suppression_collection_a_personne");
info.setMessage(responseValue.isString().stringValue());
vueARafraichir.rafraichir(info);
} else {
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
}
}
});
}
private String construirePost(String collectionId, CollectionAPersonne personne) {
String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId) +
"&ccap_id_collection=" + URL.encodeComponent(collectionId) +
"&ccap_id_personne=" + URL.encodeComponent(personne.getIdPersonne()) +
"&ccap_id_role=" + URL.encodeComponent(personne.getIdRole());
return postDonnees;
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/collection/CollectionAPersonneAsyncDao.java:r1383-1511
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/collection/CollectionAPersonneAsyncDao.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/collection/CollectionAPersonneAsyncDao.java:r11-934,1209-1382