Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1517 → Rev 1535

/tags/v1.1-helium/src/org/tela_botanica/del/client/cache/CacheClient.java
New file
0,0 → 1,428
package org.tela_botanica.del.client.cache;
 
import java.util.Arrays;
import java.util.List;
 
import org.tela_botanica.del.client.config.Config;
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
import org.tela_botanica.del.client.modeles.Image;
import org.tela_botanica.del.client.modeles.InformationsRecherche;
import org.tela_botanica.del.client.modeles.ModeTri;
import org.tela_botanica.del.client.modeles.Observation;
import org.tela_botanica.del.client.modeles.Protocole;
import org.tela_botanica.del.client.modeles.Utilisateur;
import org.tela_botanica.del.client.utils.URLUtils;
 
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
 
public class CacheClient {
 
private List<Protocole> listeProtocoles;
private String home = ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS;
private Observation observationCourante;
private Image imageCourante;
private String taxonPourRechercheEflore;
private String idProtocoleEnAttente = null;
private Protocole protocoleCourant;
private String referentielCourant;
private int numPageRechercheImage = 0;
private int nbTotalImagesRecherchees = 0;
private boolean referentielNonModifiable = false;
 
private int pasPagination = 12;
private int pageCouranteRechercheImage = 1;
private int pageCouranteRechercheObservations = 1;
private InformationsRecherche informationsRechercheImage;
private InformationsRecherche informationsRechercheObservation;
private Utilisateur utilisateur;
private String pageCourante = home;
private String statut;
private String[] statutsPossibles = {ConstantesNavigation.PARAM_TYPE_TOUS,
ConstantesNavigation.PARAM_TYPE_A_DETERMINER,
ConstantesNavigation.PARAM_TYPE_EN_DISCUSSION,
ConstantesNavigation.PARAM_TYPE_VALIDEES};
public void supprimerFiltreStatut() {
this.statut = null;
}
public void setFiltreStatut(String statut) {
this.statut = statut;
}
public String getFiltreStatut() {
return this.statut;
}
public String getPageCourante() {
return pageCourante;
}
 
public void setPageCourante(String pageCourante) {
this.pageCourante = pageCourante;
}
 
private static CacheClient instance;
 
private CacheClient() {
instance = this;
}
 
public void initialiserAvecParametres() {
if(Location.getPath().contains("identiplante")) {
if(Location.getHash().contains(ConstantesNavigation.PAGE_VALIDATION)) {
setPageCourante(ConstantesNavigation.PAGE_VALIDATION+"~"+URLUtils.getURLSpecialParameterValue());
} else {
setPageCourante(ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS);
}
} else if(Location.getPath().contains("pictoflora")) {
if(Location.getHash().contains(ConstantesNavigation.PAGE_VALIDATION_PICTOFLORA)) {
setPageCourante(ConstantesNavigation.PAGE_VALIDATION+URLUtils.getURLSpecialParameterValue());
} else {
setPageCourante(ConstantesNavigation.PAGE_RECHERCHE_IMAGES);
}
}
String rechercheLibre = Location.getParameter("masque");
String famille = Location.getParameter("masque.famille");
String taxon = Location.getParameter("masque.ns");
String genre = Location.getParameter("masque.genre");
String commune = Location.getParameter("masque.commune");
String dept = Location.getParameter("masque.departement");
String auteur = Location.getParameter("masque.auteur");
String date = Location.getParameter("masque.date");
String tag = Location.getParameter("masque.tag");
String tagCel = Location.getParameter("masque.tag_cel");
String tagDel = Location.getParameter("masque.tag_pictoflora");
String referentiel = Location.getParameter("masque.referentiel");
String protocole = Location.getParameter("protocole");
String statutParam = Location.getParameter("masque.type");
String page = Location.getParameter("page");
Integer pageInt = null;
try {
pageInt = Integer.parseInt(page);
} catch (Exception e) {
pageInt = null;
}
String pas = Location.getParameter("pas");
Integer pasInt = null;
if(pas != null) {
try {
pasInt = Integer.parseInt(pas);
} catch (Exception e) {
pasInt = null;
}
}
InformationsRecherche rechercheParArguments = new InformationsRecherche();
rechercheParArguments.setRechercheLibre(rechercheLibre);
rechercheParArguments.setFamille(famille);
rechercheParArguments.setTaxon(taxon);
rechercheParArguments.setGenre(genre);
rechercheParArguments.setCommune(commune);
rechercheParArguments.setDepartement(dept);
rechercheParArguments.setAuteur(auteur);
rechercheParArguments.setDate(date);
rechercheParArguments.setTag(tag);
if(protocole != null && !protocole.equals("")) {
CacheClient.getInstance().setIdProtocoleEnAttente(protocole);
rechercheParArguments.setIdProtocoleSelectionne(protocole);
} else if(URLUtils.getURLSpecialParameterValue() != null) {
CacheClient.getInstance().setIdProtocoleEnAttente(URLUtils.getURLSpecialParameterValue());
rechercheParArguments.setIdProtocoleSelectionne(URLUtils.getURLSpecialParameterValue());
}
if(pasInt != null) setPasPagination(pasInt);
if(pageCourante.equals(ConstantesNavigation.PAGE_RECHERCHE_IMAGES)) {
rechercheParArguments.setMotClefCel(tagCel);
rechercheParArguments.setMotClefDel(tagDel);
if(pageInt != null) setPageCouranteRechercheImages(pageInt);
} else {
if(pageInt != null) setPageCouranteRechercheObservations(pageInt);
}
String tri = Location.getParameter("tri");
String ordre = Location.getParameter("ordre");
if(tri != null) {
ModeTri modeTri = ModeTri.TRI_ASCENDANT;
if(ordre != null && ordre.equals("asc")) {
modeTri = ModeTri.TRI_ASCENDANT;
}
if(ordre != null && ordre.equals("desc")) {
modeTri = ModeTri.TRI_DESCENDANT;
}
if(tri.equals("votes")) {
rechercheParArguments.setTriParNbVotes(modeTri);
}
if(tri.equals("tags")) {
rechercheParArguments.setTriParNbTags(modeTri);
}
if(tri.equals("date_observation")) {
rechercheParArguments.setTriParDate(modeTri);
}
}
rechercheParArguments.setMotClef(tag);
// si le référentiel est passé dans l'url alors il ne doit pas être modifiable
if(referentiel != null && !referentiel.equals("")) {
setReferentielCourant(referentiel);
rechercheParArguments.setReferentiel(referentiel);
referentielNonModifiable = true;
}
if(Location.getParameterMap().size() == 0) {
// par défaut l'application s'ouvre sur l'onglet à déterminer
statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
} else {
if(Arrays.asList(statutsPossibles).contains(statutParam)) {
statut = statutParam;
} else {
statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
}
}
informationsRechercheImage = rechercheParArguments;
informationsRechercheObservation = rechercheParArguments;
mettreAjourUrlCourante();
}
public void setIdProtocoleEnAttente(String idProtocole) {
idProtocoleEnAttente = idProtocole;
}
public String getIdProtocoleEnAttente() {
return idProtocoleEnAttente;
}
 
public Utilisateur getUtilisateur() {
if (this.utilisateur == null) {
this.utilisateur = new Utilisateur(null, null);
}
return this.utilisateur;
}
public void setUtilisateur(Utilisateur utilisateur) {
this.utilisateur = utilisateur;
}
public void setHome(String home) {
this.home = home;
setPageCourante(home);
}
public String getHome() {
return home;
}
public Observation getObservationCourante() {
return observationCourante;
}
 
public void setObservationCourante(Observation observationCourante) {
this.observationCourante = observationCourante;
}
 
public static CacheClient getInstance() {
if (instance == null) {
instance = new CacheClient();
}
return instance;
}
 
public String getTaxonPourRechercheEflore() {
return taxonPourRechercheEflore;
}
 
public void setTaxonPourRechercheEflore(String taxonPourRechercheEflore) {
this.taxonPourRechercheEflore = taxonPourRechercheEflore;
}
 
public int getNumPageRechercheImage() {
return numPageRechercheImage;
}
 
// Pour la recherche :
public int getPasPagination() {
return pasPagination;
}
 
public void setPasPagination(int pasPagination) {
this.pasPagination = pasPagination;
}
 
public void setPageCouranteRechercheImages(int pageCouranteRecherche) {
this.pageCouranteRechercheImage = pageCouranteRecherche;
}
 
public int getPageCouranteRechercheImage() {
return this.pageCouranteRechercheImage;
}
 
public void setNbTotalImagesRecherchees(int nbTotalImagesRecherchees) {
this.nbTotalImagesRecherchees = nbTotalImagesRecherchees;
}
 
public int getNbTotalImagesRecherchees() {
return this.nbTotalImagesRecherchees;
}
 
public Image getImageCourante() {
return imageCourante;
}
 
public void setImageCourante(Image imageCourante) {
this.imageCourante = imageCourante;
}
public void setListeProtocoles(List<Protocole> listeProtocole) {
this.listeProtocoles = listeProtocole;
}
public List<Protocole> getListeProtocoles() {
return this.listeProtocoles;
}
 
public Protocole getProtocoleCourant() {
return protocoleCourant;
}
 
public void setProtocoleCourant(Protocole protocoleCourant) {
this.protocoleCourant = protocoleCourant;
}
 
public InformationsRecherche getInformationsRechercheImage() {
if(informationsRechercheImage == null) {
informationsRechercheImage = new InformationsRecherche();
}
return informationsRechercheImage;
}
 
public InformationsRecherche getInformationsRechercheObservation() {
if(informationsRechercheObservation == null) {
informationsRechercheObservation = new InformationsRecherche();
}
return informationsRechercheObservation;
}
 
public void setInformationsRechercheImage(InformationsRecherche informationsRechercheImage) {
this.informationsRechercheImage = informationsRechercheImage;
}
 
public void setInformationsRechercheObservation(InformationsRecherche informationsRechercheObservation) {
this.informationsRechercheObservation = informationsRechercheObservation;
}
 
public int getPageCouranteRechercheObservations() {
return pageCouranteRechercheObservations;
}
 
public void setPageCouranteRechercheObservations(int pageCouranteRechercheObservations) {
this.pageCouranteRechercheObservations = pageCouranteRechercheObservations;
}
public void setReferentielCourant(String referentielCourant) {
this.referentielCourant = referentielCourant;
}
public String getReferentielCourant() {
return referentielCourant;
}
public void setReferentielNonModifiable(boolean referentielNonModifiable) {
this.referentielNonModifiable = referentielNonModifiable;
}
public boolean getReferentielNonModifiable() {
return referentielNonModifiable;
}
public String genererUrlCourante() {
String url = Window.Location.getHref();
String arguments = "";
String argumentsRecherche = "";
if (getPageCourante().equals(ConstantesNavigation.PAGE_RECHERCHE_IMAGES)) {
InformationsRecherche infoRecherche;
infoRecherche = getInformationsRechercheImage();
if (CacheClient.getInstance().getProtocoleCourant() != null) {
infoRecherche.setIdProtocoleSelectionne(""+CacheClient.getInstance().getProtocoleCourant().getId());
}
argumentsRecherche = infoRecherche.versChaineRequete();
if(!GWT.isScript()) {
argumentsRecherche += "&gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
}
argumentsRecherche += (argumentsRecherche.isEmpty()) ? "" : "&";
argumentsRecherche += "page="+getPageCouranteRechercheImage()+"&pas="+getPasPagination();
argumentsRecherche = (argumentsRecherche.isEmpty()) ? argumentsRecherche : "?" + argumentsRecherche;
arguments = argumentsRecherche;
url = new Config().getUrl("pictoflora") + arguments;
url += "#"+ConstantesNavigation.PAGE_RECHERCHE_IMAGES;
} else if (getPageCourante().equals(ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS) || getPageCourante().equals("")) {
InformationsRecherche infoRecherche;
infoRecherche = getInformationsRechercheObservation();
argumentsRecherche = "masque.type="+statut;
argumentsRecherche += "&page="+getPageCouranteRechercheObservations()+"&pas="+getPasPagination();
argumentsRecherche += "&"+infoRecherche.versChaineRequete();
if(!GWT.isScript()) {
argumentsRecherche += "&gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
}
arguments = "?"+argumentsRecherche;
url = new Config().getUrl("identiplante") + arguments;
url += "#"+ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS;
} else if (getPageCourante().contains(ConstantesNavigation.PAGE_VALIDATION) || getPageCourante().contains(ConstantesNavigation.PAGE_VALIDATION_PICTOFLORA)) {
url = new Config().getUrl("del");
if(getPageCourante().contains(ConstantesNavigation.PAGE_VALIDATION)) {
url = new Config().getUrl("identiplante");
} else {
url = new Config().getUrl("pictoflora");
}
if(!GWT.isScript()) {
url += "?gwt.codesvr="+Location.getParameter("gwt.codesvr");
}
url += "#"+getPageCourante();
}
// remplacements batards pour corriger l'url
// TODO: factoriser toute la fonction
url = url.replaceAll("&#", "#");
url = url.replaceAll("&&", "&");
url = url.replaceAll("\\?&", "?");
return url;
}
public void mettreAjourUrlCourante() {
mettreAJourUrlCouranteSansRecharger(genererUrlCourante());
}
private static native void mettreAJourUrlCouranteSansRecharger(String nouvelleUrl) /*-{
// javascript double negative trick
// pour plus d'info http://stackoverflow.com/questions/4686583/can-someone-explain-this-double-negative-trick
if(!!($wnd.history && $wnd.history.pushState)) {
$wnd.history.pushState(nouvelleUrl, "", nouvelleUrl);
}
}-*/;
}