8,6 → 8,8 |
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.modeles.projet.Projet; |
import org.tela_botanica.client.modeles.projet.ProjetListe; |
import org.tela_botanica.client.modeles.structure.StructureListe; |
import org.tela_botanica.client.synchronisation.Reponse; |
import org.tela_botanica.client.util.Debug; |
31,66 → 33,120 |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId(); |
} |
|
public void selectionner(final String publicationId, String projetId, String nomComplet, final int nbElements, final int pageCourante, final Integer seqId) { |
String[] parametres = {projetId, publicationId, nomComplet}; |
|
|
|
/** |
* @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 efficacement (on ne voit pas les enregistrement suivants) |
*/ |
public void selectionner(final boolean paginationProgressive, final String publicationId, String projetId, String nomComplet, final int start, final int nbElements, final Integer seqId) { |
|
String nom = (nomComplet == null) ? "%" : nomComplet+"%"; |
String[] param = {publicationId, projetId, nom}; |
|
HashMap<String, String> restrictions = new HashMap<String, String>(); |
restrictions.put("orderby", "cpu_titre"); |
restrictions.put("start", String.valueOf(pageCourante*nbElements)); |
if (nbElements != -1) { |
restrictions.put("orderby", "cpu_fmt_nom_complet"); |
|
if (nbElements != -1) { |
restrictions.put("limit", String.valueOf(nbElements)); |
} |
|
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions); |
rb.envoyerRequete(null, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
if (responseValue != null) { |
// Si la requête est un succès, réception d'un objet ou d'un tableau |
JSONArray responseArray = responseValue.isArray(); |
if (responseArray.get(1).isObject() != null) { |
final JSONObject reponse = responseArray.get(1).isObject(); |
// Transformation du tableau JSON réponse en ListeInstitution |
Publication publication = new Publication(reponse); |
// et on met à jour le demandeur des données |
if (seqId!=null) { |
Reponse reponseRequete = new Reponse(publication, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} else { |
vueARafraichir.rafraichir(publication); |
} |
/** 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, param, 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("<-- PublicationAsyncDao > Liste paginée, retour au sequenceur"); |
Reponse reponseRequete = new Reponse(responseValue, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} |
else { |
if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > 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, param, restrictions); |
|
rb.envoyerRequete(null, new JsonRestRequestCallback() { |
|
public void surReponse(JSONValue responseValue) { |
|
if (responseValue != null) { |
|
} else if (responseArray.get(1).isArray() != null) { |
final JSONArray reponse = responseValue.isArray(); |
PublicationListe publications; |
if (reponse.get(1).isObject() != null) { |
publications = new PublicationListe(reponse.get(1).isArray()); |
} else { |
publications = new PublicationListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir); |
} |
JSONObject responseObject = responseValue.isObject(); |
|
publications.setTaillePage(nbElements); |
publications.setPageCourante(pageCourante); |
|
if (seqId!=null) { |
Reponse reponseRequete = new Reponse(publications, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
if (responseObject != null) { |
|
// Si la réponse est un tableau, alors c'est une liste de projets qui a été retournée |
if (responseObject.get("publications").isArray() != null) { |
|
JSONArray reponse = responseObject.get("publications").isArray(); |
|
PublicationListe publications; |
publications = new PublicationListe(reponse, responseObject.get("nbElements").isNumber(), vueARafraichir); |
publications.setTaillePage(nbElements); |
publications.setPageCourante(start); |
|
if (seqId != null) { |
if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour au sequenceur"); |
Reponse retourRequete = new Reponse(publications, seqId); |
vueARafraichir.rafraichir(retourRequete); |
} else { |
if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour à "+vueARafraichir.getClass().toString()); |
vueARafraichir.rafraichir(publications); |
} |
|
// Si la réponse est un objet, alors c'est un unique projet qui a été retourné |
} else if (responseObject.get("publications").isObject() != null) { |
|
JSONObject reponse = responseObject.get("publications").isObject(); |
// Transformation du tableau JSON réponse en ListeInstitution |
Publication publication = new Publication(reponse); |
// et on met à jour le demandeur des données |
if (seqId!=null) { |
Reponse reponseRequete = new Reponse(publication, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} else { |
vueARafraichir.rafraichir(publication); |
} |
} |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString(), null); |
} |
} else { |
if (publicationId == null) { |
PublicationListe publications = new PublicationListe(0); |
vueARafraichir.rafraichir(publications); |
} |
|
} else { |
GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null); |
} |
} else { |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide |
if (publicationId == null) { |
PublicationListe publications = new PublicationListe(0); |
vueARafraichir.rafraichir(publications); |
} |
} |
} |
}); |
}); |
} |
} |
|
public void ajouter(Publication publication, final Integer seqId) { |
Property changes: |
Modified: svn:mergeinfo |
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java:r11-934 |
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java:r1417-1511 |