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 |
|
107 |
benjamin |
9 |
import org.tela_botanica.del.client.cache.CacheClient;
|
14 |
benjamin |
10 |
import org.tela_botanica.del.client.exceptions.ExceptionClient;
|
130 |
aurelien |
11 |
import org.tela_botanica.del.client.i18n.I18n;
|
9 |
benjamin |
12 |
import org.tela_botanica.del.client.modeles.Observation;
|
14 |
benjamin |
13 |
import org.tela_botanica.del.client.modeles.ObservationValidation;
|
103 |
benjamin |
14 |
import org.tela_botanica.del.client.modeles.Protocole;
|
115 |
benjamin |
15 |
import org.tela_botanica.del.client.modeles.VoteProtocole;
|
9 |
benjamin |
16 |
|
56 |
benjamin |
17 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
18 |
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
|
|
19 |
|
96 |
aurelien |
20 |
public class MockDatasource extends GwtObservable {
|
9 |
benjamin |
21 |
|
|
|
22 |
static MockDatasource instance;
|
|
|
23 |
|
|
|
24 |
List<Observation> observations = new ArrayList<Observation>();
|
|
|
25 |
|
14 |
benjamin |
26 |
List<ObservationValidation> observationValidationDatas = new ArrayList<ObservationValidation>();
|
48 |
benjamin |
27 |
|
|
|
28 |
ArrayList<String> propositionsTaxonDatas = new ArrayList<String>();
|
115 |
benjamin |
29 |
|
107 |
benjamin |
30 |
List<Protocole> protocoles = new ArrayList<Protocole>();
|
135 |
gduche |
31 |
|
130 |
aurelien |
32 |
ArrayList<String> pourcentagesConfiance = new ArrayList<String>();
|
48 |
benjamin |
33 |
|
9 |
benjamin |
34 |
private MockDatasource() {
|
|
|
35 |
|
55 |
gduche |
36 |
HashMap<String, String> auteurObs = new HashMap<String, String>();
|
|
|
37 |
auteurObs.put("Juliette 1MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
38 |
auteurObs.put("Robert 2LERAS", "Iris lutescens subsp. lutescens");
|
|
|
39 |
auteurObs.put("Geneviève 3BOTTI", "Euphorbia dendroides L.");
|
|
|
40 |
auteurObs.put("Robert 4LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
41 |
auteurObs.put("Juliette 5MOUREAU", "Lavatera arborea L.");
|
|
|
42 |
auteurObs.put("Robert 6LERAS", "Lavatera arborea L.");
|
|
|
43 |
auteurObs.put("Juliette 7MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
44 |
auteurObs.put("Benjamin 8LIENS", "Lonicera etrusca Santi");
|
|
|
45 |
auteurObs.put("Aurélient 9PERONNET", "Ophrys scolopax Cav. ");
|
|
|
46 |
auteurObs.put("Grégoire 10DUCHÉ", "Staehelina dubia L. ");
|
|
|
47 |
auteurObs.put("Juliette 11MOUREAU", "Tragopogon porrifolius subsp. australis (Jord.) Nyman");
|
|
|
48 |
auteurObs.put("Robert 12LERAS", "Iris lutescens subsp. lutescens");
|
|
|
49 |
auteurObs.put("Geneviève 13BOTTI", "Euphorbia dendroides L.");
|
|
|
50 |
auteurObs.put("Robert 14LERAS", "Lonicera japonica Thunb. ex Murray");
|
|
|
51 |
auteurObs.put("Juliette 15MOUREAU", "Lavatera arborea L.");
|
|
|
52 |
auteurObs.put("Robert 16LERAS", "Lavatera arborea L.");
|
|
|
53 |
auteurObs.put("Juliette 17MOUREAU", "Serapias vomeracea (Burm.f.) Briq. ");
|
|
|
54 |
auteurObs.put("Benjamin 18LIENS", "Lonicera etrusca Santi");
|
|
|
55 |
auteurObs.put("Aurélient 19PERONNET", "Ophrys scolopax Cav. ");
|
|
|
56 |
auteurObs.put("Grégoire 20DUCHÉ", "Staehelina dubia L. ");
|
|
|
57 |
|
61 |
benjamin |
58 |
ArrayList<String> motsClefs = new ArrayList<String>();
|
|
|
59 |
motsClefs.add("plantnet");
|
|
|
60 |
motsClefs.add("fleur");
|
|
|
61 |
motsClefs.add("fruit");
|
|
|
62 |
|
55 |
gduche |
63 |
Iterator<String> auteurs = auteurObs.keySet().iterator();
|
|
|
64 |
|
103 |
benjamin |
65 |
Protocole protocol1 = new Protocole();
|
|
|
66 |
protocol1.setNom(Protocole.ESTHETISME);
|
100 |
benjamin |
67 |
protocol1.setId(1);
|
|
|
68 |
|
103 |
benjamin |
69 |
Protocole protocol2 = new Protocole();
|
|
|
70 |
protocol2.setNom(Protocole.IDENTIFICATION_AUTOMATIQUE);
|
100 |
benjamin |
71 |
protocol2.setId(2);
|
115 |
benjamin |
72 |
|
107 |
benjamin |
73 |
protocoles.add(protocol1);
|
|
|
74 |
protocoles.add(protocol2);
|
100 |
benjamin |
75 |
|
14 |
benjamin |
76 |
ObservationValidation observationValidationData = new ObservationValidation();
|
104 |
aurelien |
77 |
observationValidationData.setEspece("Iris lutescens subsp. lutescens");
|
96 |
aurelien |
78 |
observationValidationData.setContributeur("contributeur test");
|
9 |
benjamin |
79 |
observationValidationData.setId("1");
|
|
|
80 |
observationValidationData.setIdImage("id image 1");
|
|
|
81 |
observationValidationData.setVote(4);
|
130 |
aurelien |
82 |
observationValidationData.setPourcentageConfiance(I18n.getVocabulary().confiance_simple_suggestion());
|
61 |
benjamin |
83 |
observationValidationData.setDate(new Date());
|
100 |
benjamin |
84 |
observationValidationData.setProtocol(protocol1);
|
9 |
benjamin |
85 |
observationValidationDatas.add(observationValidationData);
|
|
|
86 |
|
14 |
benjamin |
87 |
ObservationValidation observationValidationData2 = new ObservationValidation();
|
96 |
aurelien |
88 |
observationValidationData2.setContributeur("contributeur test 2");
|
112 |
aurelien |
89 |
observationValidationData2.setEspece("Lavatera arborea L.");
|
9 |
benjamin |
90 |
observationValidationData2.setId("2");
|
|
|
91 |
observationValidationData2.setIdImage("id image 1");
|
|
|
92 |
observationValidationData2.setVote(2);
|
130 |
aurelien |
93 |
observationValidationData2.setPourcentageConfiance(I18n.getVocabulary().confiance_sur_cent());
|
61 |
benjamin |
94 |
observationValidationData2.setDate(new Date());
|
103 |
benjamin |
95 |
observationValidationData2.setProtocol(protocol1);
|
9 |
benjamin |
96 |
observationValidationDatas.add(observationValidationData2);
|
48 |
benjamin |
97 |
|
96 |
aurelien |
98 |
ObservationValidation observationValidationData3 = new ObservationValidation();
|
|
|
99 |
observationValidationData3.setEspece("Acer monsp. L.");
|
|
|
100 |
observationValidationData3.setContributeur("Léo Ferré");
|
|
|
101 |
observationValidationData3.setCommentaire("Avec le temps...");
|
|
|
102 |
observationValidationData3.setId("1");
|
|
|
103 |
observationValidationData3.setIdImage("id image 1");
|
|
|
104 |
observationValidationData2.setVote(3);
|
130 |
aurelien |
105 |
observationValidationData3.setPourcentageConfiance(I18n.getVocabulary().confiance_sur_cent());
|
96 |
aurelien |
106 |
observationValidationData3.setDate(new Date());
|
103 |
benjamin |
107 |
observationValidationData3.setProtocol(protocol1);
|
96 |
aurelien |
108 |
observationValidationDatas.add(observationValidationData3);
|
48 |
benjamin |
109 |
|
96 |
aurelien |
110 |
ObservationValidation observationValidationData4 = new ObservationValidation();
|
|
|
111 |
observationValidationData4.setEspece("Acer aceras aus.");
|
|
|
112 |
observationValidationData4.setContributeur("Pierre Desproges");
|
|
|
113 |
observationValidationData4.setCommentaire("Public chéri mon amour !");
|
|
|
114 |
observationValidationData4.setId("2");
|
|
|
115 |
observationValidationData4.setIdImage("id image 1");
|
103 |
benjamin |
116 |
observationValidationData4.setVote(1);
|
130 |
aurelien |
117 |
observationValidationData4.setPourcentageConfiance(I18n.getVocabulary().confiance_sur_cent());
|
96 |
aurelien |
118 |
observationValidationData4.setDate(new Date());
|
103 |
benjamin |
119 |
observationValidationData4.setProtocol(protocol2);
|
96 |
aurelien |
120 |
observationValidationDatas.add(observationValidationData4);
|
48 |
benjamin |
121 |
|
96 |
aurelien |
122 |
ObservationValidation observationValidationData5 = new ObservationValidation();
|
|
|
123 |
observationValidationData5.setEspece("Acer monsp subsp. monsp.");
|
|
|
124 |
observationValidationData5.setContributeur("Louis Aragon");
|
|
|
125 |
observationValidationData5.setCommentaire("Tout est affaire de décor");
|
|
|
126 |
observationValidationData5.setId("2");
|
|
|
127 |
observationValidationData5.setIdImage("id image 1");
|
103 |
benjamin |
128 |
observationValidationData5.setVote(2);
|
130 |
aurelien |
129 |
observationValidationData5.setPourcentageConfiance(I18n.getVocabulary().confiance_probable());
|
96 |
aurelien |
130 |
observationValidationData5.setDate(new Date());
|
103 |
benjamin |
131 |
observationValidationData5.setProtocol(protocol2);
|
96 |
aurelien |
132 |
observationValidationDatas.add(observationValidationData5);
|
115 |
benjamin |
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.setUrl("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "CRS.jpg");
|
|
|
143 |
observation.setNumNomenclatural("num nomenclatural " + i);
|
|
|
144 |
observation.setIdImage("id image " + i);
|
|
|
145 |
observation.setDate(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(new Date()));
|
|
|
146 |
observation.setFamille("famille " + i);
|
|
|
147 |
observation.setLocalite("localite " + i);
|
135 |
gduche |
148 |
observation.setNomRetenu(auteurObs.get(auteur));
|
103 |
benjamin |
149 |
observation.setMotsClefs(motsClefs);
|
|
|
150 |
observation.setImageCelValidationDatas(observationValidationDatas);
|
|
|
151 |
|
|
|
152 |
observations.add(observation);
|
|
|
153 |
}
|
135 |
gduche |
154 |
|
130 |
aurelien |
155 |
pourcentagesConfiance.add(I18n.getVocabulary().confiance_simple_suggestion());
|
|
|
156 |
pourcentagesConfiance.add(I18n.getVocabulary().confiance_probable());
|
|
|
157 |
pourcentagesConfiance.add(I18n.getVocabulary().confiance_sur_cent());
|
9 |
benjamin |
158 |
}
|
|
|
159 |
|
|
|
160 |
public List<Observation> getObservations() {
|
40 |
aurelien |
161 |
|
9 |
benjamin |
162 |
return observations;
|
|
|
163 |
}
|
|
|
164 |
|
14 |
benjamin |
165 |
public List<ObservationValidation> getValidationData(String idImage) {
|
9 |
benjamin |
166 |
return observationValidationDatas;
|
|
|
167 |
}
|
48 |
benjamin |
168 |
|
103 |
benjamin |
169 |
public List<ObservationValidation> getValidationDataByImageAndProtocol(String idImage, String protocolName) {
|
|
|
170 |
List<ObservationValidation> validations = new ArrayList<ObservationValidation>();
|
|
|
171 |
for (ObservationValidation observationValidation : observationValidationDatas) {
|
|
|
172 |
if (observationValidation.getProtocol().getNom().equals(protocolName)) {
|
|
|
173 |
validations.add(observationValidation);
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
return validations;
|
|
|
177 |
}
|
|
|
178 |
|
48 |
benjamin |
179 |
public Observation getObservationCourante() {
|
|
|
180 |
return observations.get(0);
|
|
|
181 |
}
|
40 |
aurelien |
182 |
|
48 |
benjamin |
183 |
public List<Observation> getObservationsEfloreParTaxon(String nomTaxon) {
|
|
|
184 |
return observations;
|
9 |
benjamin |
185 |
}
|
115 |
benjamin |
186 |
|
107 |
benjamin |
187 |
public Protocole getProtocole(String nomProtocole) {
|
|
|
188 |
for (Protocole protocole : protocoles) {
|
|
|
189 |
if (protocole.getNom().equals(nomProtocole)) {
|
|
|
190 |
return protocole;
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
return null;
|
|
|
194 |
}
|
135 |
gduche |
195 |
|
130 |
aurelien |
196 |
public ArrayList<String> getPourcentagesConfiance() {
|
|
|
197 |
return pourcentagesConfiance;
|
|
|
198 |
}
|
9 |
benjamin |
199 |
|
115 |
benjamin |
200 |
public void saveVote(VoteProtocole voteProtocole) {
|
107 |
benjamin |
201 |
CacheClient.getInstance().getCurrentObservation().getVoteProtocoles().add(voteProtocole);
|
115 |
benjamin |
202 |
}
|
107 |
benjamin |
203 |
|
48 |
benjamin |
204 |
public void saveValidationData(ObservationValidation validationData) throws ExceptionClient {
|
96 |
aurelien |
205 |
observationValidationDatas.add(validationData);
|
48 |
benjamin |
206 |
}
|
|
|
207 |
|
9 |
benjamin |
208 |
public static MockDatasource getInstance() {
|
|
|
209 |
if (instance == null) {
|
|
|
210 |
instance = new MockDatasource();
|
|
|
211 |
}
|
|
|
212 |
return instance;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
}
|