Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1287 → Rev 1288

/branches/v1.0-syrah/src/org/tela_botanica/client/modeles/ValeurListeAsyncDao.java
5,9 → 5,12
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.util.Debug;
import org.tela_botanica.client.util.UtilDAO;
 
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONBoolean;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
14,49 → 17,190
 
public class ValeurListeAsyncDao {
private static HashMap<String, ValeurListe> ontologieCache = new HashMap<String, ValeurListe>();
private static HashMap<String, Object> ontologieCache = new HashMap<String, Object>();
private static HashMap<String, HashMap<Integer, Object>> pagedOntologieCache = new HashMap<String, HashMap<Integer, Object>>();
private static final String SERVICE_NOM = "CoelValeurListe";
private Rafraichissable vueARafraichir = null;
private static ValeurListe tempListe = new ValeurListe();
private int cptPage = 0;
private int limiteJREST = 150;
 
public ValeurListeAsyncDao(Rafraichissable vueCourante) {
vueARafraichir = vueCourante;
}
public void obtenirListe(Integer cle) {
selectionner("id", cle, null, null);
public static HashMap<String, Object> getOntologieCache() {
return ontologieCache;
}
 
public void chargerListe(boolean nextPage, String type, Integer cle, String abv, String idValeur, boolean pagination, String recherche, int start, int nbElements) {
/** Si nextpage est VRAI, alors cela signifie que la liste est plus grande
que la limite du JREST et l'on doit relancer une requete pour obtenir
la page suivante **/
if (nextPage) {
cptPage++;
selectionner(type, cle, abv, idValeur, pagination, recherche, cptPage*limiteJREST, limiteJREST);
}
/** Sinon cela signifie que le chargement de la liste est terminé et on peut
la mettre en cache et retourner la réponse au demandeur **/
else {
// on met en cache
String id = String.valueOf(cle);
String abreviationStr = "";
if (abv != null) {
abreviationStr = abv;
int indexPoint = abreviationStr.indexOf(".", 0);
abreviationStr = abreviationStr.substring(0, indexPoint);
id = id+abreviationStr;
}
// réinitialiser le compteur
cptPage = 0;
 
// et on met à jour le demandeur des données
if (ontologieCache.get(id) != null) {
vueARafraichir.rafraichir(ontologieCache.get(id));
}
}
}
public void obtenirListe(Integer cle) {
selectionner("id", cle, null, null, false, null, -1, -1);
}
public void obtenirListe(String type, String identifiantValeur) {
selectionner(type, null, null, identifiantValeur, false, null, -1, -1);
}
public void obtenirListe(Integer cle, boolean pagination, String recherche, int start, int limit) {
selectionner("nom", cle, null, null, pagination, recherche, start, limit);
}
public void selectionner(String type, Integer cle, String abv, String idValeur) {
selectionner(type, cle, abv, idValeur, false, null, -1, -1);
}
 
public void selectionner(final String type, final Integer cle, final String abv, final String idValeur, final boolean pagination, final String recherche, final int start, final int limit) {
 
// La cleParent en Integer est insuffisante pour les liste valeurs comme Région qui on plusieurs sections sur leur liste
// (ex : on ne sélectionne que les régions FR.__ puis les régions ES.__ sur la liste 1078 ....
final String cleParent = cle + (abv == null ? "" : abv);
final String cleParentPourCache = cle + (abv == null ? "" : abv);
final String cleParent = cle+"";
if (ontologieCache.containsKey(cleParent)) {
vueARafraichir.rafraichir(ontologieCache.get(cleParent));
} else {
String paramAbv = (type.equals("id") ? null : abv);
String[] parametres = {type, cleParent.toString(), paramAbv, idValeur};
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
String nom = "";
if ( (recherche == null) || (recherche.equals("")) ) nom = "";
else {
nom = recherche+"%";
}
 
String abreviation = "";
String paramAbv = "";
if (type.equals("ab") || type.equals("abv")) {
int positionPoint = abv.indexOf(".");
if (positionPoint != -1) abreviation = abv.substring(0, positionPoint)+"%";
else abreviation=abv+"%";
}
paramAbv = abreviation;
 
String[] parametres = {type, cleParent, paramAbv, idValeur, nom};
 
HashMap<String, String> restrictions = new HashMap<String, String>();
 
if (pagination) {
 
restrictions.put("limit", String.valueOf(limit));
restrictions.put("start", String.valueOf(start));
restrictions.put("orderby", "cmlv_nom");
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback()
{
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue.isObject() != null) {
final JSONObject reponse = responseValue.isObject();
JSONString listeId = reponse.get("id").isString();
JSONArray listeValeurs = reponse.get("valeurs").isArray();
if (listeId != null) {
// Transformation du tableau JSON réponse en Liste
ValeurListe liste = new ValeurListe(listeId, listeValeurs);
// Stockage en cache
ontologieCache.put(cleParent, liste);
// et on met à jour le demandeur des données
vueARafraichir.rafraichir(liste);
}
}
public void surReponse(JSONValue responseValue)
{
vueARafraichir.rafraichir(responseValue);
}
});
}
}
else
{
boolean nextPage = (start > 0);
if (nextPage)
{
restrictions.put("start", String.valueOf(start));
restrictions.put("limit", String.valueOf(limit));
restrictions.put("orderby", "cmlv_nom");
}
else
{
restrictions.put("orderby", "cmlv_nom");
}
// si l'on est pas dans un processus de récupération d'une liste
// et si le cache contient déjà la liste recherchée
if (ontologieCache.containsKey(cleParentPourCache) && !nextPage)
{
vueARafraichir.rafraichir(ontologieCache.get(cleParentPourCache));
}
else
{
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback()
{
@Override
public void surReponse(JSONValue responseValue)
{
if (responseValue.isObject() != null)
{
/** Récuperation des différents paramètres de la réponse JSON **/
final JSONObject reponse = responseValue.isObject();
JSONString listeId = reponse.get("id").isString();
JSONArray listeValeurs = reponse.get("valeurs").isArray();
JSONNumber nbElements = reponse.get("nbElements").isNumber();
JSONBoolean getNextPage = reponse.get("getNextPage").isBoolean();
/** Gestion de l'abreviation (pour la liste des régions) **/
String abreviationStr = "";
if (reponse.get("abreviation") != null) {
abreviationStr = reponse.get("abreviation").isString().stringValue();
int a = abreviationStr.indexOf("%", 1);
abreviationStr = abreviationStr.substring(1, a);
}
else {
abreviationStr = "";
}
 
/** si l'on a bien reçu une liste de valeurs **/
if (listeId != null)
{
/** Transformation du tableau JSON réponse en ValeurListe **/
String id = listeId.stringValue();
ValeurListe liste = new ValeurListe(new JSONString(id), abreviationStr, listeValeurs, nbElements);
 
/** Si la liste existe deja en cache **/
String identifiantCache = (abreviationStr=="") ? id : (id+abreviationStr);
if (ontologieCache.get(id) != null)
{
/** Alors on concatène la liste existante avec celle qu'on vient de recevoir **/
((ValeurListe)ontologieCache.get(identifiantCache)).concatenerListe(liste);
}
/** Sinon on l'insère simplement dans le cache **/
else {
ontologieCache.put(identifiantCache,liste);
}
 
/** Appel à la méthode qui gère le retour à l'appelant ou la suite du chargement **/
chargerListe(getNextPage.booleanValue(), type, liste.getId(), abv, idValeur, pagination, recherche, start, limit);
}
}
}
});
}
}
}
}
}
/branches/v1.0-syrah/src/org/tela_botanica/client/modeles/Valeur.java
3,6 → 3,9
import java.util.Iterator;
import java.util.Set;
 
import org.tela_botanica.client.util.Debug;
 
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.json.client.JSONObject;
 
public class Valeur extends aDonnee {
44,6 → 47,17
this.set("description", description);
}
public Valeur(ModelData model)
{
Debug.log("id_valeur = "+model.get("cmlv_id_valeur"));
Debug.log("nom = "+model.get("cmlv_nom"));
this.set("id_valeur", model.get("cmlv_id_valeur"));
this.set("nom", model.get("cmlv_nom"));
this.set("abreviation", model.get("cmlv_abreviation"));
this.set("description", model.get("cmlv_description"));
}
@Override
protected String getPrefixe() {
return PREFIXE;
/branches/v1.0-syrah/src/org/tela_botanica/client/modeles/ValeurListe.java
1,6 → 1,19
package org.tela_botanica.client.modeles;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.ListePaginable;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.util.Debug;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
 
18,7 → 31,13
*/
private static final long serialVersionUID = 7784635999621813450L;
private Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
private int nbElementsTotal;
// Id de la meta-liste dans la base de données
private int id = 0;
private String abv = "";
/**
* Constructeur sans paramètres
49,7 → 68,16
this.constuireObjet(listeValeurs);
}
private void constuireObjet(JSONArray liste) {
public ValeurListe(JSONString listeId, String abv, JSONArray listeValeurs, JSONNumber nbElements) {
super(listeValeurs.size());
this.setId(Integer.parseInt(listeId.stringValue()));
this.abv = abv;
this.setNbElementsTotal(nbElements.toString());
this.constuireObjet(listeValeurs);
}
protected void constuireObjet(JSONArray liste) {
final int taillemax = liste.size();
for (int i = 0; i < taillemax; i++) {
68,6 → 96,10
public void setId(int id) {
this.id = id;
}
public void setNbElementsTotal(String nbElements) {
this.nbElementsTotal = Integer.parseInt(nbElements);
}
 
/**
* @return l'identifiant de la liste
76,7 → 108,34
return id;
}
public String getFullId() {
return (id+abv);
}
public void ajouter(Valeur val) {
this.put(val.getId(), val);
}
public ValeurListe cloner()
{
ValeurListe l = new ValeurListe();
Iterator i = this.keySet().iterator();
while (i.hasNext())
{
String clef = (String)i.next();
Valeur valeur = this.get(clef);
l.put(clef, valeur);
}
 
return l;
}
public void concatenerListe(ValeurListe lv) {
this.putAll(lv);
this.setId(lv.getId());
}
 
}