New file |
0,0 → 1,211 |
package org.tela_botanica.client.modeles.personne; |
|
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.UtilDAO; |
|
import com.extjs.gxt.ui.client.Registry; |
import com.google.gwt.core.client.Callback; |
import com.google.gwt.core.client.GWT; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONObject; |
import com.google.gwt.json.client.JSONValue; |
|
public class PersonneAsyncDao { |
private static final String SERVICE_NOM = "CoelPersonne"; |
public static String tri = null; |
|
private String utilisateurId = null; |
private Rafraichissable vueARafraichir = null; |
|
public PersonneAsyncDao(Rafraichissable vue) { |
if (Mediateur.DEBUG) System.out.println("|| PersonneAsyncDao > vueARafraichir = "+vue.getClass().toString()); |
vueARafraichir = vue; |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId(); |
} |
|
/** |
* @param paginationProgressive : définit le mode de consultation de la base de données |
* - True : la consultation des données est progressive, ce qui signifie que la liste est chargée (paginée) au |
* fur et à mesure de la consultation des données par l'utilisateur. |
* - False : la consultation des données est classique : un seul appel à la base de données est effectué, le retour |
* est renvoyé à l'appelant |
* // FIXME : si la taille de la liste est supérieure à la limite du JREST (150), ce deuxieme mode ne fonctionne pas |
*/ |
public void selectionner(final boolean paginationProgressive, String personneId, String nomComplet, final int start, final int nbElements, final Integer seqId) { |
|
String nom = (nomComplet == null) ? "%" : "%"+nomComplet+"%"; |
String[] parametres = {personneId, nom}; |
|
HashMap<String, String> restrictions = new HashMap<String, String>(); |
|
if (nbElements != -1) { |
restrictions.put("limit", String.valueOf(nbElements)); |
} |
|
if(tri != null) { |
restrictions.put("orderby", tri); |
} |
|
/** 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("<-- PersonneAsyncDao > Liste paginée, retour au sequenceur"); |
Reponse reponseRequete = new Reponse(responseValue, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} |
else { |
if (Mediateur.DEBUG) System.out.println("<-- PersonneAsyncDao > 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 reponseObject = responseValue.isObject(); |
|
if (reponseObject.get("personnes").isArray() != null) { |
JSONArray reponse = responseValue.isArray(); |
|
// Transformation du tableau JSON réponse en ListePersonne |
Information info = new Information("liste_personne"); |
PersonneListe personnes; |
personnes = new PersonneListe(reponseObject.get("personnes").isArray(), reponseObject.get("nbElements").isNumber(), vueARafraichir); |
personnes.setTaillePage(nbElements); |
personnes.setPageCourante(start); |
info.setDonnee(0, personnes); |
|
// et on met à jour le demandeur des données |
if (seqId != null) { |
if (Mediateur.DEBUG) System.out.println("<-- PersonneAsyncDao > Liste non paginée, retour au sequenceur"); |
Reponse reponseRequete = new Reponse(info, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} |
else { |
if (Mediateur.DEBUG) System.out.println("<-- PersonneAsyncDao > Liste non paginée, retour à "+vueARafraichir.getClass().toString()); |
vueARafraichir.rafraichir(info); |
} |
} |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null); |
} |
} |
}); |
} |
} |
|
public void testerExistencePersonne(String nomComplet, final Callback<JSONObject, String> cb) { |
String[] parametres = {null, nomComplet}; |
|
/** CONSTRUCTION DE LA REQUETE **/ |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres); |
|
/** ENVOI DE LA REQUETE **/ |
rb.envoyerRequete(null, new JsonRestRequestCallback() |
{ |
/** RECEPTION DE LA REPONSE **/ |
public void surReponse(JSONValue responseValue) |
{ |
if (responseValue.isObject() != null) { |
cb.onSuccess(responseValue.isObject()); |
} |
} |
}); |
} |
|
public void ajouter(Personne personne) { |
String postDonneesEncodees = personne.obtenirChainePOST(); |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM); |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
if (responseValue.isString() != null) { |
Information info = new Information("ajout_personne"); |
String structureIdOuMessage = responseValue.isString().stringValue(); |
if (structureIdOuMessage.matches("^[0-9]+$")) { |
info.setDonnee(structureIdOuMessage); |
} else { |
info.setMessage(structureIdOuMessage); |
} |
vueARafraichir.rafraichir(info); |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null); |
} |
} |
}); |
} |
|
public void modifier(Personne personne) { |
String postDonneesEncodees = personne.obtenirChainePOST(); |
postDonneesEncodees += "&cmhl_ce_modifier_par=" + utilisateurId; |
GWT.log(postDonneesEncodees, null); |
String[] parametres = {personne.getId()}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres); |
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("modification_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 supprimer(String personnesId) { |
String[] parametres = {utilisateurId, personnesId}; |
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_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); |
} |
} |
}); |
} |
|
} |
Property changes: |
Added: svn:mergeinfo |
Merged /trunk/src/org/tela_botanica/client/modeles/personne/PersonneAsyncDao.java:r11-934,1209-1382 |
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/personne/PersonneAsyncDao.java:r1383-1511 |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/personne/PersonneAsyncDao.java:r1136-1368 |