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;
|
115 |
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>();
|
115 |
benjamin |
28 |
|
107 |
benjamin |
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 |
Protocole protocol1 = new Protocole();
|
|
|
63 |
protocol1.setNom(Protocole.ESTHETISME);
|
100 |
benjamin |
64 |
protocol1.setId(1);
|
|
|
65 |
|
103 |
benjamin |
66 |
Protocole protocol2 = new Protocole();
|
|
|
67 |
protocol2.setNom(Protocole.IDENTIFICATION_AUTOMATIQUE);
|
100 |
benjamin |
68 |
protocol2.setId(2);
|
115 |
benjamin |
69 |
|
107 |
benjamin |
70 |
protocoles.add(protocol1);
|
|
|
71 |
protocoles.add(protocol2);
|
100 |
benjamin |
72 |
|
14 |
benjamin |
73 |
ObservationValidation observationValidationData = new ObservationValidation();
|
104 |
aurelien |
74 |
observationValidationData.setEspece("Iris lutescens subsp. lutescens");
|
96 |
aurelien |
75 |
observationValidationData.setContributeur("contributeur test");
|
9 |
benjamin |
76 |
observationValidationData.setId("1");
|
|
|
77 |
observationValidationData.setIdImage("id image 1");
|
|
|
78 |
observationValidationData.setVote(4);
|
96 |
aurelien |
79 |
observationValidationData.setPourcentageConfiance(90);
|
61 |
benjamin |
80 |
observationValidationData.setDate(new Date());
|
100 |
benjamin |
81 |
observationValidationData.setProtocol(protocol1);
|
9 |
benjamin |
82 |
observationValidationDatas.add(observationValidationData);
|
|
|
83 |
|
14 |
benjamin |
84 |
ObservationValidation observationValidationData2 = new ObservationValidation();
|
96 |
aurelien |
85 |
observationValidationData2.setContributeur("contributeur test 2");
|
112 |
aurelien |
86 |
observationValidationData2.setEspece("Lavatera arborea L.");
|
9 |
benjamin |
87 |
observationValidationData2.setId("2");
|
|
|
88 |
observationValidationData2.setIdImage("id image 1");
|
|
|
89 |
observationValidationData2.setVote(2);
|
96 |
aurelien |
90 |
observationValidationData2.setPourcentageConfiance(50);
|
61 |
benjamin |
91 |
observationValidationData2.setDate(new Date());
|
103 |
benjamin |
92 |
observationValidationData2.setProtocol(protocol1);
|
9 |
benjamin |
93 |
observationValidationDatas.add(observationValidationData2);
|
48 |
benjamin |
94 |
|
96 |
aurelien |
95 |
ObservationValidation observationValidationData3 = new ObservationValidation();
|
|
|
96 |
observationValidationData3.setEspece("Acer monsp. L.");
|
|
|
97 |
observationValidationData3.setContributeur("Léo Ferré");
|
|
|
98 |
observationValidationData3.setCommentaire("Avec le temps...");
|
|
|
99 |
observationValidationData3.setId("1");
|
|
|
100 |
observationValidationData3.setIdImage("id image 1");
|
|
|
101 |
observationValidationData2.setVote(3);
|
|
|
102 |
observationValidationData3.setPourcentageConfiance(90);
|
|
|
103 |
observationValidationData3.setDate(new Date());
|
103 |
benjamin |
104 |
observationValidationData3.setProtocol(protocol1);
|
96 |
aurelien |
105 |
observationValidationDatas.add(observationValidationData3);
|
48 |
benjamin |
106 |
|
96 |
aurelien |
107 |
ObservationValidation observationValidationData4 = new ObservationValidation();
|
|
|
108 |
observationValidationData4.setEspece("Acer aceras aus.");
|
|
|
109 |
observationValidationData4.setContributeur("Pierre Desproges");
|
|
|
110 |
observationValidationData4.setCommentaire("Public chéri mon amour !");
|
|
|
111 |
observationValidationData4.setId("2");
|
|
|
112 |
observationValidationData4.setIdImage("id image 1");
|
103 |
benjamin |
113 |
observationValidationData4.setVote(1);
|
96 |
aurelien |
114 |
observationValidationData4.setPourcentageConfiance(30);
|
|
|
115 |
observationValidationData4.setDate(new Date());
|
103 |
benjamin |
116 |
observationValidationData4.setProtocol(protocol2);
|
96 |
aurelien |
117 |
observationValidationDatas.add(observationValidationData4);
|
48 |
benjamin |
118 |
|
96 |
aurelien |
119 |
ObservationValidation observationValidationData5 = new ObservationValidation();
|
|
|
120 |
observationValidationData5.setEspece("Acer monsp subsp. monsp.");
|
|
|
121 |
observationValidationData5.setContributeur("Louis Aragon");
|
|
|
122 |
observationValidationData5.setCommentaire("Tout est affaire de décor");
|
|
|
123 |
observationValidationData5.setId("2");
|
|
|
124 |
observationValidationData5.setIdImage("id image 1");
|
103 |
benjamin |
125 |
observationValidationData5.setVote(2);
|
96 |
aurelien |
126 |
observationValidationData5.setPourcentageConfiance(50);
|
|
|
127 |
observationValidationData5.setDate(new Date());
|
103 |
benjamin |
128 |
observationValidationData5.setProtocol(protocol2);
|
96 |
aurelien |
129 |
observationValidationDatas.add(observationValidationData5);
|
115 |
benjamin |
130 |
|
103 |
benjamin |
131 |
for (int i = 0; i < 20; i++) {
|
48 |
benjamin |
132 |
|
103 |
benjamin |
133 |
Observation observation = new Observation();
|
|
|
134 |
String auteur = auteurs.next();
|
|
|
135 |
observation.setAuteur(auteur);
|
|
|
136 |
observation.setSpecies(auteurObs.get(auteur));
|
|
|
137 |
|
|
|
138 |
int numobs = 44120 + i;
|
|
|
139 |
observation.setUrl("http://www.tela-botanica.org/appli:cel-img:0000" + String.valueOf(numobs) + "CRS.jpg");
|
|
|
140 |
observation.setNumNomenclatural("num nomenclatural " + i);
|
|
|
141 |
observation.setIdImage("id image " + i);
|
|
|
142 |
observation.setDate(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(new Date()));
|
|
|
143 |
observation.setFamille("famille " + i);
|
|
|
144 |
observation.setLocalite("localite " + i);
|
|
|
145 |
observation.setNomRetenu("nom retenu " + i);
|
|
|
146 |
observation.setMotsClefs(motsClefs);
|
|
|
147 |
observation.setImageCelValidationDatas(observationValidationDatas);
|
|
|
148 |
|
|
|
149 |
observations.add(observation);
|
|
|
150 |
}
|
9 |
benjamin |
151 |
}
|
|
|
152 |
|
|
|
153 |
public List<Observation> getObservations() {
|
40 |
aurelien |
154 |
|
9 |
benjamin |
155 |
return observations;
|
|
|
156 |
}
|
|
|
157 |
|
14 |
benjamin |
158 |
public List<ObservationValidation> getValidationData(String idImage) {
|
9 |
benjamin |
159 |
return observationValidationDatas;
|
|
|
160 |
}
|
48 |
benjamin |
161 |
|
103 |
benjamin |
162 |
public List<ObservationValidation> getValidationDataByImageAndProtocol(String idImage, String protocolName) {
|
|
|
163 |
List<ObservationValidation> validations = new ArrayList<ObservationValidation>();
|
|
|
164 |
for (ObservationValidation observationValidation : observationValidationDatas) {
|
|
|
165 |
if (observationValidation.getProtocol().getNom().equals(protocolName)) {
|
|
|
166 |
validations.add(observationValidation);
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
return validations;
|
|
|
170 |
}
|
|
|
171 |
|
48 |
benjamin |
172 |
public Observation getObservationCourante() {
|
|
|
173 |
return observations.get(0);
|
|
|
174 |
}
|
40 |
aurelien |
175 |
|
48 |
benjamin |
176 |
public List<Observation> getObservationsEfloreParTaxon(String nomTaxon) {
|
|
|
177 |
return observations;
|
9 |
benjamin |
178 |
}
|
115 |
benjamin |
179 |
|
107 |
benjamin |
180 |
public Protocole getProtocole(String nomProtocole) {
|
|
|
181 |
for (Protocole protocole : protocoles) {
|
|
|
182 |
if (protocole.getNom().equals(nomProtocole)) {
|
|
|
183 |
return protocole;
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
return null;
|
|
|
187 |
}
|
9 |
benjamin |
188 |
|
115 |
benjamin |
189 |
public void saveVote(VoteProtocole voteProtocole) {
|
107 |
benjamin |
190 |
CacheClient.getInstance().getCurrentObservation().getVoteProtocoles().add(voteProtocole);
|
115 |
benjamin |
191 |
}
|
107 |
benjamin |
192 |
|
48 |
benjamin |
193 |
public void saveValidationData(ObservationValidation validationData) throws ExceptionClient {
|
96 |
aurelien |
194 |
observationValidationDatas.add(validationData);
|
48 |
benjamin |
195 |
}
|
|
|
196 |
|
9 |
benjamin |
197 |
public static MockDatasource getInstance() {
|
|
|
198 |
if (instance == null) {
|
|
|
199 |
instance = new MockDatasource();
|
|
|
200 |
}
|
|
|
201 |
return instance;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
}
|