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