9 |
benjamin |
1 |
package org.tela_botanica.del.client.utils;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Date;
|
55 |
gduche |
5 |
import java.util.HashMap;
|
|
|
6 |
import java.util.Iterator;
|
270 |
gduche |
7 |
import java.util.LinkedHashMap;
|
9 |
benjamin |
8 |
import java.util.List;
|
|
|
9 |
|
14 |
benjamin |
10 |
import org.tela_botanica.del.client.exceptions.ExceptionClient;
|
130 |
aurelien |
11 |
import org.tela_botanica.del.client.i18n.I18n;
|
141 |
aurelien |
12 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
154 |
benjamin |
13 |
import org.tela_botanica.del.client.modeles.Image;
|
9 |
benjamin |
14 |
import org.tela_botanica.del.client.modeles.Observation;
|
141 |
aurelien |
15 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
103 |
benjamin |
16 |
import org.tela_botanica.del.client.modeles.Protocole;
|
154 |
benjamin |
17 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
115 |
benjamin |
18 |
import org.tela_botanica.del.client.modeles.VoteProtocole;
|
9 |
benjamin |
19 |
|
56 |
benjamin |
20 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
21 |
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
|
|
22 |
|
159 |
benjamin |
23 |
public class MockDatasource {
|
9 |
benjamin |
24 |
|
|
|
25 |
static MockDatasource instance;
|
|
|
26 |
|
|
|
27 |
List<Observation> observations = new ArrayList<Observation>();
|
|
|
28 |
|
154 |
benjamin |
29 |
List<PropositionDetermination> observationValidationDatas = new ArrayList<PropositionDetermination>();
|
48 |
benjamin |
30 |
|
|
|
31 |
ArrayList<String> propositionsTaxonDatas = new ArrayList<String>();
|
115 |
benjamin |
32 |
|
107 |
benjamin |
33 |
List<Protocole> protocoles = new ArrayList<Protocole>();
|
159 |
benjamin |
34 |
|
154 |
benjamin |
35 |
List<Image> images = new ArrayList<Image>();
|
135 |
gduche |
36 |
|
154 |
benjamin |
37 |
List<String> pourcentagesConfiance = new ArrayList<String>();
|
48 |
benjamin |
38 |
|
9 |
benjamin |
39 |
private MockDatasource() {
|
|
|
40 |
|
270 |
gduche |
41 |
HashMap<String, String> auteurObs = new LinkedHashMap<String, String>();
|
|
|
42 |
auteurObs.put("01Juliette 1MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
43 |
auteurObs.put("02Robert 2LERAS", "Iris lutescens subsp. lutescens");
|
|
|
44 |
auteurObs.put("03Geneviève 3BOTTI", "Euphorbia dendroides L.");
|
|
|
45 |
auteurObs.put("04Robert 4LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
46 |
auteurObs.put("05Juliette 5MOUREAU", "Lavatera arborea L.");
|
|
|
47 |
auteurObs.put("06Robert 6LERAS", "Lavatera arborea L.");
|
|
|
48 |
auteurObs.put("07Juliette 7MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
49 |
auteurObs.put("08Benjamin 8LIENS", "Lonicera etrusca Santi");
|
|
|
50 |
auteurObs.put("09Aurélient 9PERONNET", "Ophrys scolopax Cav. ");
|
|
|
51 |
auteurObs.put("10Grégoire 10DUCHÉ", "Staehelina dubia L. ");
|
|
|
52 |
auteurObs.put("11Juliette 11MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
53 |
auteurObs.put("12Robert 12LERAS", "Iris lutescens subsp. lutescens");
|
|
|
54 |
auteurObs.put("13Geneviève 13BOTTI", "Euphorbia dendroides L.");
|
|
|
55 |
auteurObs.put("14Robert 14LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
56 |
auteurObs.put("15Juliette 15MOUREAU", "Lavatera arborea L.");
|
|
|
57 |
auteurObs.put("16Robert 16LERAS", "Lavatera arborea L.");
|
|
|
58 |
auteurObs.put("17Juliette 17MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
59 |
auteurObs.put("18Benjamin 18LIENS", "Lonicera etrusca Santi");
|
|
|
60 |
auteurObs.put("19Aurélient 19PERONNET", "Ophrys scolopax Cav. ");
|
|
|
61 |
auteurObs.put("20Grégoire 20DUCHÉ", "Staehelina dubia L. ");
|
55 |
gduche |
62 |
|
270 |
gduche |
63 |
auteurObs.put("21Juliette 1MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
64 |
auteurObs.put("22R2obert 2LERAS", "Iris lutescens subsp. lutescens");
|
|
|
65 |
auteurObs.put("23Ge3neviève 3BOTTI", "Euphorbia dendroides L.");
|
|
|
66 |
auteurObs.put("24Rob4ert 4LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
67 |
auteurObs.put("25Jul5iette 5MOUREAU", "Lavatera arborea L.");
|
|
|
68 |
auteurObs.put("26Rob6ert 6LERAS", "Lavatera arborea L.");
|
|
|
69 |
auteurObs.put("27J6ul7iette 7MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
70 |
auteurObs.put("28Ben8jamin 8LIENS", "Lonicera etrusca Santi");
|
|
|
71 |
auteurObs.put("29Auré9lient 9PERONNET", "Ophrys scolopax Cav. ");
|
|
|
72 |
auteurObs.put("30Gég10oire 10DUCHÉ", "Staehelina dubia L. ");
|
|
|
73 |
auteurObs.put("31Julie11tte 11MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
74 |
auteurObs.put("32Rober12t 12LERAS", "Iris lutescens subsp. lutescens");
|
|
|
75 |
auteurObs.put("33Genev13iève 13BOTTI", "Euphorbia dendroides L.");
|
|
|
76 |
auteurObs.put("34Robe14rt 14LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
77 |
auteurObs.put("35Julie15tte 15MOUREAU", "Lavatera arborea L.");
|
|
|
78 |
auteurObs.put("36Robe16rt 16LERAS", "Lavatera arborea L.");
|
|
|
79 |
auteurObs.put("37Julie17tte 17MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
80 |
auteurObs.put("38Benja1m11in 18LIENS", "Lonicera etrusca Santi");
|
|
|
81 |
auteurObs.put("39Auré1111lient 19PERONNET", "Ophrys scolopax Cav. ");
|
|
|
82 |
auteurObs.put("40Gr545égoire 20DUCHÉ", "Staehelina dubia L. ");
|
|
|
83 |
|
61 |
benjamin |
84 |
ArrayList<String> motsClefs = new ArrayList<String>();
|
|
|
85 |
motsClefs.add("plantnet");
|
|
|
86 |
motsClefs.add("fleur");
|
|
|
87 |
motsClefs.add("fruit");
|
|
|
88 |
|
55 |
gduche |
89 |
Iterator<String> auteurs = auteurObs.keySet().iterator();
|
|
|
90 |
|
103 |
benjamin |
91 |
Protocole protocol1 = new Protocole();
|
|
|
92 |
protocol1.setNom(Protocole.ESTHETISME);
|
100 |
benjamin |
93 |
protocol1.setId(1);
|
|
|
94 |
|
103 |
benjamin |
95 |
Protocole protocol2 = new Protocole();
|
|
|
96 |
protocol2.setNom(Protocole.IDENTIFICATION_AUTOMATIQUE);
|
100 |
benjamin |
97 |
protocol2.setId(2);
|
115 |
benjamin |
98 |
|
107 |
benjamin |
99 |
protocoles.add(protocol1);
|
|
|
100 |
protocoles.add(protocol2);
|
100 |
benjamin |
101 |
|
154 |
benjamin |
102 |
VoteDetermination voteDetermination = new VoteDetermination();
|
167 |
aurelien |
103 |
voteDetermination.setVote(1);
|
154 |
benjamin |
104 |
voteDetermination.setDate(new Date());
|
|
|
105 |
voteDetermination.setContributeur("benjamin");
|
9 |
benjamin |
106 |
|
154 |
benjamin |
107 |
PropositionDetermination observationValidationData = new PropositionDetermination();
|
|
|
108 |
observationValidationData.setEspece("Iris lutescens subsp. lutescens");
|
|
|
109 |
observationValidationData.setContributeur("contributeur test");
|
|
|
110 |
observationValidationData.setId("1");
|
48 |
benjamin |
111 |
|
227 |
aurelien |
112 |
observationValidationData.ajouterVoteDetermination(voteDetermination);
|
154 |
benjamin |
113 |
observationValidationData.setDate(new Date());
|
|
|
114 |
observationValidationDatas.add(observationValidationData);
|
48 |
benjamin |
115 |
|
154 |
benjamin |
116 |
PropositionDetermination observationValidationData2 = new PropositionDetermination();
|
|
|
117 |
observationValidationData2.setContributeur("contributeur test 2");
|
|
|
118 |
observationValidationData2.setEspece("Lavatera arborea L.");
|
|
|
119 |
observationValidationData2.setId("2");
|
227 |
aurelien |
120 |
observationValidationData2.ajouterVoteDetermination(voteDetermination);
|
154 |
benjamin |
121 |
observationValidationData2.setDate(new Date());
|
|
|
122 |
observationValidationDatas.add(observationValidationData2);
|
48 |
benjamin |
123 |
|
154 |
benjamin |
124 |
PropositionDetermination observationValidationData3 = new PropositionDetermination();
|
|
|
125 |
observationValidationData3.setEspece("Acer monsp. L.");
|
|
|
126 |
observationValidationData3.setContributeur("Léo Ferré");
|
159 |
benjamin |
127 |
Commentaire commentaire = new Commentaire("Greg", new Date(), "Avec le temps...");
|
|
|
128 |
Commentaire commentaireBis = new Commentaire("Benj", new Date(), "Pas d'accord avec Greg!");
|
|
|
129 |
commentaire.getListeCommentaires().add(commentaireBis);
|
154 |
benjamin |
130 |
observationValidationData3.getCommentaires().add(commentaire);
|
247 |
aurelien |
131 |
observationValidationData3.setId("3");
|
227 |
aurelien |
132 |
observationValidationData2.ajouterVoteDetermination(voteDetermination);
|
154 |
benjamin |
133 |
observationValidationData3.setDate(new Date());
|
|
|
134 |
observationValidationDatas.add(observationValidationData3);
|
115 |
benjamin |
135 |
|
154 |
benjamin |
136 |
PropositionDetermination observationValidationData4 = new PropositionDetermination();
|
|
|
137 |
observationValidationData4.setEspece("Acer aceras aus.");
|
|
|
138 |
observationValidationData4.setContributeur("Pierre Desproges");
|
159 |
benjamin |
139 |
Commentaire commentaire2 = new Commentaire("Greg", new Date(), "Public chéri mon amour...");
|
154 |
benjamin |
140 |
observationValidationData4.getCommentaires().add(commentaire2);
|
247 |
aurelien |
141 |
observationValidationData4.setId("4");
|
227 |
aurelien |
142 |
observationValidationData4.ajouterVoteDetermination(voteDetermination);
|
154 |
benjamin |
143 |
observationValidationData4.setDate(new Date());
|
|
|
144 |
observationValidationDatas.add(observationValidationData4);
|
|
|
145 |
|
|
|
146 |
PropositionDetermination observationValidationData5 = new PropositionDetermination();
|
|
|
147 |
observationValidationData5.setEspece("Acer monsp subsp. monsp.");
|
|
|
148 |
observationValidationData5.setContributeur("Louis Aragon");
|
159 |
benjamin |
149 |
Commentaire commentaire3 = new Commentaire("Greg", new Date(), "Tout est affaire de décor...");
|
154 |
benjamin |
150 |
observationValidationData5.getCommentaires().add(commentaire3);
|
247 |
aurelien |
151 |
observationValidationData5.setId("5");
|
227 |
aurelien |
152 |
observationValidationData5.ajouterVoteDetermination(voteDetermination);
|
154 |
benjamin |
153 |
observationValidationData5.setDate(new Date());
|
|
|
154 |
observationValidationDatas.add(observationValidationData5);
|
|
|
155 |
|
199 |
gduche |
156 |
int numobs = 44120;
|
224 |
aurelien |
157 |
for (int i = 0; i < 40; i++) {
|
48 |
benjamin |
158 |
|
103 |
benjamin |
159 |
Observation observation = new Observation();
|
|
|
160 |
String auteur = auteurs.next();
|
|
|
161 |
observation.setAuteur(auteur);
|
|
|
162 |
observation.setSpecies(auteurObs.get(auteur));
|
|
|
163 |
|
199 |
gduche |
164 |
numobs += i;
|
103 |
benjamin |
165 |
observation.setNumNomenclatural("num nomenclatural " + i);
|
|
|
166 |
observation.setDate(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(new Date()));
|
|
|
167 |
observation.setFamille("famille " + i);
|
|
|
168 |
observation.setLocalite("localite " + i);
|
135 |
gduche |
169 |
observation.setNomRetenu(auteurObs.get(auteur));
|
103 |
benjamin |
170 |
observation.setMotsClefs(motsClefs);
|
154 |
benjamin |
171 |
observation.setImageCelValidationDatas(observationValidationDatas);
|
103 |
benjamin |
172 |
|
154 |
benjamin |
173 |
Image image = new Image();
|
|
|
174 |
image.setIdImage("id image " + i);
|
199 |
gduche |
175 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "%s%.jpg");
|
154 |
benjamin |
176 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "CRS.jpg");
|
199 |
gduche |
177 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "XS.jpg");
|
154 |
benjamin |
178 |
observation.getImages().add(image);
|
|
|
179 |
image.setObservation(observation);
|
|
|
180 |
images.add(image);
|
|
|
181 |
|
199 |
gduche |
182 |
// nombre d'images aléatoires
|
|
|
183 |
int nbImagesAssociees = (int) Math.round(Math.random() * 10);
|
|
|
184 |
for (int j = 0; j < nbImagesAssociees; j++) {
|
|
|
185 |
numobs++;
|
|
|
186 |
image = new Image();
|
|
|
187 |
image.setIdImage("id image " + i);
|
|
|
188 |
image.setUrlFormat("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "%s%.jpg");
|
|
|
189 |
image.setUrl("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "CRS.jpg");
|
|
|
190 |
image.setMiniature("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "XS.jpg");
|
|
|
191 |
observation.getImages().add(image);
|
|
|
192 |
image.setObservation(observation);
|
|
|
193 |
images.add(image);
|
|
|
194 |
}
|
|
|
195 |
|
154 |
benjamin |
196 |
VoteProtocole voteProtocole = new VoteProtocole();
|
234 |
gduche |
197 |
voteProtocole.setProtocole(protocol1);
|
159 |
benjamin |
198 |
voteProtocole.setVote(3);
|
154 |
benjamin |
199 |
voteProtocole.setContributeur("aurelien");
|
|
|
200 |
voteProtocole.setDate(new Date());
|
|
|
201 |
|
|
|
202 |
image.getVoteProtocoles().add(voteProtocole);
|
|
|
203 |
|
159 |
benjamin |
204 |
VoteProtocole voteProtocole2 = new VoteProtocole();
|
234 |
gduche |
205 |
voteProtocole2.setProtocole(protocol2);
|
159 |
benjamin |
206 |
voteProtocole2.setVote(2);
|
|
|
207 |
voteProtocole2.setContributeur("jpm");
|
|
|
208 |
voteProtocole2.setDate(new Date());
|
|
|
209 |
|
|
|
210 |
image.getVoteProtocoles().add(voteProtocole2);
|
|
|
211 |
|
103 |
benjamin |
212 |
observations.add(observation);
|
|
|
213 |
}
|
199 |
gduche |
214 |
|
180 |
benjamin |
215 |
ajouterVotesAleatoires();
|
177 |
benjamin |
216 |
|
223 |
gduche |
217 |
pourcentagesConfiance.add(I18n.getVocabulary().confianceSimpleSuggestion());
|
|
|
218 |
pourcentagesConfiance.add(I18n.getVocabulary().confianceProbable());
|
|
|
219 |
pourcentagesConfiance.add(I18n.getVocabulary().confianceSurCent());
|
9 |
benjamin |
220 |
}
|
199 |
gduche |
221 |
|
167 |
aurelien |
222 |
public void ajouterVotesAleatoires() {
|
|
|
223 |
for (PropositionDetermination validation : observationValidationDatas) {
|
199 |
gduche |
224 |
int nbVotesAjoutes = (int) Math.round(Math.random() * 20);
|
|
|
225 |
|
167 |
aurelien |
226 |
for (int i = 0; i < nbVotesAjoutes; i++) {
|
|
|
227 |
VoteDetermination vd = new VoteDetermination();
|
199 |
gduche |
228 |
vd.setVote((int) Math.round(Math.random()));
|
167 |
aurelien |
229 |
vd.setDate(new Date());
|
|
|
230 |
vd.setContributeur("test");
|
199 |
gduche |
231 |
|
167 |
aurelien |
232 |
validation.ajouterVoteDetermination(vd);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
}
|
199 |
gduche |
236 |
|
182 |
benjamin |
237 |
public List<Observation> getObservations(HashMap<String, String> champsRecherche) {
|
199 |
gduche |
238 |
if (champsRecherche == null) {
|
|
|
239 |
return getObservations();
|
|
|
240 |
} else {
|
|
|
241 |
int nbResultats = (int) Math.round(Math.random() * 20);
|
|
|
242 |
List<Observation> resultatRecherche = new ArrayList<Observation>();
|
|
|
243 |
for (int i = 0; i < nbResultats; i++) {
|
|
|
244 |
int numeroResultat = (int) Math.round(Math.random() * (observations.size() - 1));
|
|
|
245 |
resultatRecherche.add(observations.get(numeroResultat));
|
|
|
246 |
}
|
|
|
247 |
return resultatRecherche;
|
|
|
248 |
}
|
182 |
benjamin |
249 |
}
|
9 |
benjamin |
250 |
|
|
|
251 |
public List<Observation> getObservations() {
|
|
|
252 |
return observations;
|
|
|
253 |
}
|
159 |
benjamin |
254 |
|
154 |
benjamin |
255 |
public List<Image> getImages() {
|
|
|
256 |
return images;
|
|
|
257 |
}
|
9 |
benjamin |
258 |
|
177 |
benjamin |
259 |
public List<VoteProtocole> getVote(String idImage) {
|
|
|
260 |
for (Image image : images) {
|
|
|
261 |
if (image.getIdImage().equals(idImage)) {
|
|
|
262 |
return image.getVoteProtocoles();
|
154 |
benjamin |
263 |
}
|
177 |
benjamin |
264 |
|
154 |
benjamin |
265 |
}
|
|
|
266 |
return null;
|
9 |
benjamin |
267 |
}
|
48 |
benjamin |
268 |
|
177 |
benjamin |
269 |
public List<VoteProtocole> getVoteByImageAndProtocol(String idImage, String protocolName) {
|
154 |
benjamin |
270 |
|
177 |
benjamin |
271 |
List<VoteProtocole> voteProtocolesLocal = new ArrayList<VoteProtocole>();
|
|
|
272 |
|
|
|
273 |
for (Image image : images) {
|
|
|
274 |
if (image.getIdImage().equals(idImage)) {
|
|
|
275 |
for (VoteProtocole voteProtocole : image.getVoteProtocoles()) {
|
234 |
gduche |
276 |
if (voteProtocole.getProtocole().getNom().equals(protocolName)) {
|
177 |
benjamin |
277 |
voteProtocolesLocal.add(voteProtocole);
|
154 |
benjamin |
278 |
}
|
|
|
279 |
}
|
|
|
280 |
}
|
177 |
benjamin |
281 |
|
103 |
benjamin |
282 |
}
|
177 |
benjamin |
283 |
return voteProtocolesLocal;
|
103 |
benjamin |
284 |
}
|
|
|
285 |
|
154 |
benjamin |
286 |
public List<Image> getImagesEfloreParTaxon(String nomTaxon) {
|
|
|
287 |
return images;
|
9 |
benjamin |
288 |
}
|
115 |
benjamin |
289 |
|
107 |
benjamin |
290 |
public Protocole getProtocole(String nomProtocole) {
|
|
|
291 |
for (Protocole protocole : protocoles) {
|
|
|
292 |
if (protocole.getNom().equals(nomProtocole)) {
|
|
|
293 |
return protocole;
|
|
|
294 |
}
|
|
|
295 |
}
|
|
|
296 |
return null;
|
|
|
297 |
}
|
159 |
benjamin |
298 |
|
177 |
benjamin |
299 |
public List<Protocole> getProtocoles() {
|
|
|
300 |
return protocoles;
|
|
|
301 |
}
|
|
|
302 |
|
159 |
benjamin |
303 |
public void saveVote(VoteProtocole voteProtocole) {
|
|
|
304 |
// TODO implement method
|
154 |
benjamin |
305 |
}
|
135 |
gduche |
306 |
|
154 |
benjamin |
307 |
public List<String> getPourcentagesConfiance() {
|
130 |
aurelien |
308 |
return pourcentagesConfiance;
|
|
|
309 |
}
|
9 |
benjamin |
310 |
|
141 |
aurelien |
311 |
public void saveValidationData(PropositionDetermination validationData) throws ExceptionClient {
|
154 |
benjamin |
312 |
observationValidationDatas.add(validationData);
|
48 |
benjamin |
313 |
}
|
|
|
314 |
|
9 |
benjamin |
315 |
public static MockDatasource getInstance() {
|
|
|
316 |
if (instance == null) {
|
|
|
317 |
instance = new MockDatasource();
|
|
|
318 |
}
|
|
|
319 |
return instance;
|
|
|
320 |
}
|
154 |
benjamin |
321 |
|
9 |
benjamin |
322 |
}
|