Subversion Repositories eFlore/Applications.del

Rev

Rev 1982 | Rev 1995 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1934 aurelien 1
package org.tela_botanica.del.client.cache;
2
 
3
import java.util.Arrays;
4
import java.util.List;
1986 aurelien 5
import java.util.Map;
1934 aurelien 6
 
7
import org.tela_botanica.del.client.config.Config;
8
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
9
import org.tela_botanica.del.client.modeles.Image;
10
import org.tela_botanica.del.client.modeles.InformationsRecherche;
11
import org.tela_botanica.del.client.modeles.ModeTri;
12
import org.tela_botanica.del.client.modeles.Observation;
13
import org.tela_botanica.del.client.modeles.Protocole;
14
import org.tela_botanica.del.client.modeles.Utilisateur;
15
import org.tela_botanica.del.client.utils.URLUtils;
16
 
17
import com.google.gwt.core.client.GWT;
18
import com.google.gwt.user.client.Window;
19
import com.google.gwt.user.client.Window.Location;
20
 
21
public class CacheClient {
22
 
23
	private List<Protocole> listeProtocoles;
24
 
25
	private Observation observationCourante;
26
	private Image imageCourante;
27
	private String taxonPourRechercheEflore;
28
	private String idProtocoleEnAttente = null;
29
	private Protocole protocoleCourant;
30
	private String referentielCourant;
31
	private int numPageRechercheImage = 0;
32
	private int nbTotalImagesRecherchees = 0;
33
 
34
	private boolean referentielNonModifiable = false;
35
 
36
	private int pasPagination = 12;
37
	private int pageCouranteRechercheImage = 1;
38
	private int pageCouranteRechercheObservations = 1;
39
	private InformationsRecherche informationsRechercheImage;
40
	private InformationsRecherche informationsRechercheObservation;
41
	private Utilisateur utilisateur;
42
	private String pageCourante = "";
43
	private String statut;
44
	private String[] statutsPossibles = {
45
		ConstantesNavigation.PARAM_TYPE_TOUS,
46
		ConstantesNavigation.PARAM_TYPE_A_DETERMINER,
1982 aurelien 47
		ConstantesNavigation.PARAM_TYPE_A_CONFIRMER,
1934 aurelien 48
		ConstantesNavigation.PARAM_TYPE_VALIDEES
49
	};
50
	private ModeTri modeTri = ModeTri.TRI_ASCENDANT;
51
 
1986 aurelien 52
	private Map<String, String> listePays;
53
 
1934 aurelien 54
	public void supprimerFiltreStatut() {
55
		this.statut = null;
56
	}
57
 
58
	public void setFiltreStatut(String statut) {
59
		this.statut = statut;
60
	}
61
 
62
	public String getFiltreStatut() {
63
		return this.statut;
64
	}
65
 
66
	public String getPageCourante() {
67
		return pageCourante;
68
	}
69
 
70
	public void setPageCourante(String pageCourante) {
71
		pageCourante = pageCourante.replaceAll("#", "");
72
		pageCourante = pageCourante.replaceAll("page_validation", ConstantesNavigation.PAGE_DETAIL_OBS);
73
		pageCourante = pageCourante.replaceAll("page_validation_pictoflora", ConstantesNavigation.PAGE_DETAIL_IMG);
74
		this.pageCourante = pageCourante;
75
	}
76
 
77
	private static CacheClient instance;
78
 
79
	private CacheClient() {
80
		instance = this;
81
	}
82
 
83
	public void initialiserAvecParametres() {
84
		String urlCourante = Window.Location.getHref();
85
		Config config = new Config();
86
		String urlAppliImg = config.getUrl("pictoflora");
87
 
88
		setPageCourante(Location.getHash());
89
 
90
		String rechercheLibre = Location.getParameter("masque");
91
		String famille = Location.getParameter("masque.famille");
92
		String taxon = Location.getParameter("masque.ns");
93
		String genre = Location.getParameter("masque.genre");
94
		String commune = Location.getParameter("masque.commune");
95
		String dept = Location.getParameter("masque.departement");
96
		String auteur = Location.getParameter("masque.auteur");
97
		String date = Location.getParameter("masque.date");
98
		String tag = Location.getParameter("masque.tag");
99
		String tagCel = Location.getParameter("masque.tag_cel");
100
		String tagDel = Location.getParameter("masque.tag_pictoflora");
101
		String referentiel = Location.getParameter("masque.referentiel");
102
		String protocole = Location.getParameter("protocole");
103
		String statutParam = Location.getParameter("masque.type");
1986 aurelien 104
		String paysParam = Location.getParameter("masque.pays");
1934 aurelien 105
 
106
		String page = Location.getParameter("page");
107
		Integer pageInt = null;
108
		try {
109
			pageInt = Integer.parseInt(page);
110
		} catch (Exception e) {
111
			pageInt = null;
112
		}
113
 
114
		String pas = Location.getParameter("pas");
115
		Integer pasInt = null;
116
		if (pas != null) {
117
			try {
118
				pasInt = Integer.parseInt(pas);
119
			} catch (Exception e) {
120
				pasInt = null;
121
			}
122
		}
123
 
124
		InformationsRecherche rechercheParArguments = new InformationsRecherche();
125
		rechercheParArguments.setRechercheLibre(rechercheLibre);
126
		rechercheParArguments.setFamille(famille);
127
		rechercheParArguments.setTaxon(taxon);
128
		rechercheParArguments.setGenre(genre);
129
		rechercheParArguments.setCommune(commune);
130
		rechercheParArguments.setDepartement(dept);
131
		rechercheParArguments.setAuteur(auteur);
132
		rechercheParArguments.setDate(date);
133
		rechercheParArguments.setTag(tag);
1986 aurelien 134
		rechercheParArguments.setPays(paysParam);
1934 aurelien 135
 
136
		if (protocole != null && !protocole.equals("")) {
137
			CacheClient.getInstance().setIdProtocoleEnAttente(protocole);
138
			rechercheParArguments.setIdProtocoleSelectionne(protocole);
139
		} else if (URLUtils.getURLSpecialParameterValue() != null) {
140
			CacheClient.getInstance().setIdProtocoleEnAttente(URLUtils.getURLSpecialParameterValue());
141
			rechercheParArguments.setIdProtocoleSelectionne(URLUtils.getURLSpecialParameterValue());
142
		}
143
 
144
		if (pasInt != null) {
145
			setPasPagination(pasInt);
146
		}
147
 
148
		if (urlCourante.contains(urlAppliImg)) {
149
			rechercheParArguments.setMotClefCel(tagCel);
150
			rechercheParArguments.setMotClefDel(tagDel);
151
			if (pageInt != null) {
152
				setPageCouranteRechercheImages(pageInt);
153
			}
154
		} else {
155
			if (pageInt != null) {
156
				setPageCouranteRechercheObservations(pageInt);
157
			}
158
		}
159
 
160
		definirOrdreTriCourantParUrl();
161
		String tri = Location.getParameter("tri");
162
		if (urlCourante.contains(urlAppliImg)) {
163
			if (tri != null) {
164
				// Pour PictoFlora
165
				if (tri.equals("moyenne-arithmetique")) {
166
					rechercheParArguments.setTriParMoyenneArithmetique(modeTri);
167
				} else if (tri.equals("points")) {
168
					rechercheParArguments.setTriParNbPoints(modeTri);
169
				} else if (tri.equals("tags")) {
170
					rechercheParArguments.setTriParNbTags(modeTri);
171
				} else {
172
					rechercheParArguments.setTriParDatePublication(modeTri);
173
				}
174
			} else {
175
				// Tri par défaut pour PictoFlora
176
				rechercheParArguments.setTriParDatePublication(ModeTri.TRI_DESCENDANT);
177
			}
178
		} else {
179
			// Pour IdentiPlante
180
			if (tri != null && tri.equals("date_observation")) {
181
				rechercheParArguments.setTriParDateObservation(modeTri);
182
			} else if(tri != null && tri.equals("nb_commentaires")) {
183
				rechercheParArguments.setTriParNbCommentaires(modeTri);
184
			} else {
185
				// Tri par défaut pour IdentiPlante
186
				rechercheParArguments.setTriParDatePublication(ModeTri.TRI_DESCENDANT);
187
			}
188
		}
189
 
190
		rechercheParArguments.setMotClef(tag);
191
 
192
		// si le référentiel est passé dans l'url alors il ne doit pas être modifiable
193
		if (referentiel != null && !referentiel.equals("")) {
194
			setReferentielCourant(referentiel);
195
			rechercheParArguments.setReferentiel(referentiel);
196
			referentielNonModifiable = true;
197
		}
198
 
199
		if (Location.getParameterMap().size() == 0) {
200
			// par défaut l'application s'ouvre sur l'onglet à déterminer
201
			statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
202
		} else {
203
			if (Arrays.asList(statutsPossibles).contains(statutParam)) {
204
				statut = statutParam;
205
			} else {
206
				statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
207
			}
208
		}
209
 
210
		informationsRechercheImage = rechercheParArguments;
211
		informationsRechercheObservation = rechercheParArguments;
212
 
213
		mettreAjourUrlCourante();
214
	}
215
 
216
	private void definirOrdreTriCourantParUrl() {
217
		String ordre = Location.getParameter("ordre");
218
		if (ordre != null) {
219
			if (ordre.equals("asc")) {
220
				this.modeTri = ModeTri.TRI_ASCENDANT;
221
			} else if (ordre.equals("desc")) {
222
				this.modeTri = ModeTri.TRI_DESCENDANT;
223
			}
224
		}
225
	}
226
 
227
	public void setIdProtocoleEnAttente(String idProtocole) {
228
		idProtocoleEnAttente = idProtocole;
229
	}
230
 
231
	public String getIdProtocoleEnAttente() {
232
		return idProtocoleEnAttente;
233
	}
234
 
235
	public Utilisateur getUtilisateur() {
236
		if (this.utilisateur == null) {
237
			this.utilisateur = new Utilisateur(null, null);
238
		}
239
		return this.utilisateur;
240
	}
241
 
242
	public void setUtilisateur(Utilisateur utilisateur) {
243
		this.utilisateur = utilisateur;
244
	}
245
 
246
	public void setHome(String home) {
247
		setPageCourante(home);
248
	}
249
 
250
	public String getHome() {
251
		return "";
252
	}
253
 
254
	public Observation getObservationCourante() {
255
		return observationCourante;
256
	}
257
 
258
	public void setObservationCourante(Observation observationCourante) {
259
		this.observationCourante = observationCourante;
260
	}
261
 
262
	public static CacheClient getInstance() {
263
		if (instance == null) {
264
			instance = new CacheClient();
265
		}
266
		return instance;
267
	}
268
 
269
	public String getTaxonPourRechercheEflore() {
270
		return taxonPourRechercheEflore;
271
	}
272
 
273
	public void setTaxonPourRechercheEflore(String taxonPourRechercheEflore) {
274
		this.taxonPourRechercheEflore = taxonPourRechercheEflore;
275
	}
276
 
277
	public int getNumPageRechercheImage() {
278
		return numPageRechercheImage;
279
	}
280
 
281
	// Pour la recherche :
282
	public int getPasPagination() {
283
		return pasPagination;
284
	}
285
 
286
	public void setPasPagination(int pasPagination) {
287
		this.pasPagination = pasPagination;
288
	}
289
 
290
	public void setPageCouranteRechercheImages(int pageCouranteRecherche) {
291
		this.pageCouranteRechercheImage = pageCouranteRecherche;
292
	}
293
 
294
	public int getPageCouranteRechercheImage() {
295
		return this.pageCouranteRechercheImage;
296
	}
297
 
298
	public void setNbTotalImagesRecherchees(int nbTotalImagesRecherchees) {
299
		this.nbTotalImagesRecherchees = nbTotalImagesRecherchees;
300
	}
301
 
302
	public int getNbTotalImagesRecherchees() {
303
		return this.nbTotalImagesRecherchees;
304
	}
305
 
306
	public Image getImageCourante() {
307
		return imageCourante;
308
	}
309
 
310
	public void setImageCourante(Image imageCourante) {
311
		this.imageCourante = imageCourante;
312
	}
313
 
314
	public void setListeProtocoles(List<Protocole> listeProtocole) {
315
		this.listeProtocoles = listeProtocole;
316
	}
317
 
318
	public List<Protocole> getListeProtocoles() {
319
		return this.listeProtocoles;
320
	}
321
 
322
	public Protocole getProtocoleCourant() {
323
		return protocoleCourant;
324
	}
325
 
326
	public void setProtocoleCourant(Protocole protocoleCourant) {
327
		this.protocoleCourant = protocoleCourant;
328
	}
329
 
330
	public InformationsRecherche getInformationsRechercheImage() {
331
		if (informationsRechercheImage == null) {
332
			informationsRechercheImage = new InformationsRecherche();
333
		}
334
		return informationsRechercheImage;
335
	}
336
 
337
	public InformationsRecherche getInformationsRechercheObservation() {
338
		if (informationsRechercheObservation == null) {
339
			informationsRechercheObservation = new InformationsRecherche();
340
		}
341
		return informationsRechercheObservation;
342
	}
343
 
344
	public void setInformationsRechercheImage(InformationsRecherche informationsRechercheImage) {
345
		this.informationsRechercheImage = informationsRechercheImage;
346
	}
347
 
348
	public void setInformationsRechercheObservation(InformationsRecherche informationsRechercheObservation) {
349
		this.informationsRechercheObservation = informationsRechercheObservation;
350
	}
351
 
352
	public int getPageCouranteRechercheObservations() {
353
		return pageCouranteRechercheObservations;
354
	}
355
 
356
	public void setPageCouranteRechercheObservations(int pageCouranteRechercheObservations) {
357
		this.pageCouranteRechercheObservations = pageCouranteRechercheObservations;
358
	}
359
 
360
	public void setReferentielCourant(String referentielCourant) {
361
		this.referentielCourant = referentielCourant;
362
	}
363
 
364
	public String getReferentielCourant() {
365
		return referentielCourant;
366
	}
367
 
368
	public void setReferentielNonModifiable(boolean referentielNonModifiable) {
369
		this.referentielNonModifiable = referentielNonModifiable;
370
	}
371
 
372
	public boolean getReferentielNonModifiable() {
373
		return referentielNonModifiable;
374
	}
375
 
376
	public String getUrlPageSignalerMauvaiseId(String id) {
377
		Config config = new Config();
378
		String urlSignalerMauvaiseId = config.getUrl("identiplante");
379
		if (!GWT.isScript()) {
380
			urlSignalerMauvaiseId += "?gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
381
		}
382
		return urlSignalerMauvaiseId+"#"+ConstantesNavigation.PAGE_DETAIL_OBS+"~"+id;
383
 
384
	}
385
 
1986 aurelien 386
	public void setListePays(Map<String, String> listePays) {
387
		this.listePays = listePays;
388
	}
389
 
390
	public Map<String, String> getListePays() {
391
		return listePays;
392
	}
393
 
1934 aurelien 394
	public String genererUrlCourante() {
395
		String urlCourante = Window.Location.getHref();
396
		Config config = new Config();
397
		String urlAppliObs = config.getUrl("identiplante");
398
		String urlAppliImg = config.getUrl("pictoflora");
399
		String url = urlCourante;
400
		String arguments = "";
401
 
402
		if (urlCourante.contains(urlAppliImg)) {
403
			InformationsRecherche infoRecherche;
404
			infoRecherche = getInformationsRechercheImage();
405
 
406
			if (CacheClient.getInstance().getProtocoleCourant() != null) {
407
				infoRecherche.setIdProtocoleSelectionne("" + CacheClient.getInstance().getProtocoleCourant().getId());
408
			}
409
 
410
			arguments = infoRecherche.versChaineRequete();
411
			arguments += (arguments.isEmpty()) ? "" : "&";
412
			arguments += "page="+getPageCouranteRechercheImage()+"&pas="+getPasPagination();
413
 
414
			url = config.getUrl("pictoflora");
415
		} else if (urlCourante.contains(urlAppliObs)) {
416
			InformationsRecherche infoRecherche;
417
			infoRecherche = getInformationsRechercheObservation();
418
 
419
			arguments = "masque.type="+statut;
420
			arguments += "&page="+getPageCouranteRechercheObservations()+"&pas="+getPasPagination();
421
			arguments += "&"+infoRecherche.versChaineRequete();
422
 
423
			url = config.getUrl("identiplante");
424
		}
425
 
426
		if (!GWT.isScript()) {
427
			arguments += "&gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
428
		}
429
		arguments = (arguments.isEmpty()) ? "" : "?" + arguments;
430
		String signet = getPageCourante().equals("") ? "" : "#" + getPageCourante();
431
		url += arguments + signet;
432
 
433
		// remplacements batards pour corriger l'url
434
		// TODO: factoriser toute la fonction
435
		url = url.replaceAll("&#", "#");
436
		url = url.replaceAll("&&", "&");
437
		url = url.replaceAll("\\?&", "?");
438
		if (url.endsWith("&")) {
439
			url = url.substring(0, url.length()-1);
440
		}
441
 
442
		return url;
443
	}
444
 
445
	public void mettreAjourUrlCourante() {
446
		mettreAJourUrlCouranteSansRecharger(genererUrlCourante());
447
	}
448
 
449
	private static native void mettreAJourUrlCouranteSansRecharger(String nouvelleUrl) /*-{
450
		// javascript double negative trick
451
		// pour plus d'info http://stackoverflow.com/questions/4686583/can-someone-explain-this-double-negative-trick
452
		if (!!($wnd.history && $wnd.history.pushState)) {
453
			var currentState = $wnd.history.state;
454
			if (currentState != nouvelleUrl) {
455
				$wnd.history.pushState(nouvelleUrl, "", nouvelleUrl);
456
			}
457
		}
458
	}-*/;
459
}