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