1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.ext.geo;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.junit.Before;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
|
21
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
22
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.common.TermType;
|
24
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
25
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
26
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
27
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
* @date 07.04.2016
|
32
|
*
|
33
|
*/
|
34
|
public class FloraCubaCondensedDistributionComposerTest {
|
35
|
|
36
|
private static OrderedTermVocabulary<PresenceAbsenceTerm> statusVoc;
|
37
|
private static OrderedTermVocabulary<NamedArea> cubaAreasVocabualary;
|
38
|
private static NamedArea cuba;
|
39
|
private static NamedArea westernCuba;
|
40
|
private static NamedArea eastCuba;
|
41
|
private static NamedArea centralCuba;
|
42
|
private static NamedArea pinarDelRio;
|
43
|
private static NamedArea holguin;
|
44
|
private static NamedArea guantanamo;
|
45
|
|
46
|
private static NamedArea bahamas;
|
47
|
private static NamedArea oldWorld;
|
48
|
|
49
|
private static UUID uuidStatusOccasionallyCultivated = UUID.fromString("936c3f9a-6099-4322-9792-0a72c6c2ce25");
|
50
|
private static UUID uuidStatusNotNativButNaturalised = UUID.fromString("a1e26234-831e-4190-9fe3-011aca09ddba");
|
51
|
private static UUID uuidStatusDoubtfullyNativeError = UUID.fromString("71b72e24-c2b6-44a5-bdab-39f083bf0f06");
|
52
|
|
53
|
|
54
|
/**
|
55
|
* @throws java.lang.Exception
|
56
|
*/
|
57
|
@SuppressWarnings("unchecked")
|
58
|
@BeforeClass
|
59
|
public static void setUpBeforeClass() throws Exception {
|
60
|
DefaultTermInitializer initializer = new DefaultTermInitializer();
|
61
|
initializer.initialize();
|
62
|
|
63
|
statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm);
|
64
|
statusVoc.addTerm(makeStatusTerm("occasionally cultivated","(c)",false, uuidStatusOccasionallyCultivated));
|
65
|
statusVoc.addTerm(makeStatusTerm("not native but possibly naturalised","p",false,uuidStatusNotNativButNaturalised));
|
66
|
statusVoc.addTerm(makeStatusTerm("doubtfully native: reported in error","-d",false,uuidStatusDoubtfullyNativeError));
|
67
|
|
68
|
makeAreas();
|
69
|
}
|
70
|
|
71
|
|
72
|
/**
|
73
|
* @throws java.lang.Exception
|
74
|
*/
|
75
|
@Before
|
76
|
public void setUp() throws Exception {
|
77
|
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* Test method for {@link eu.etaxonomy.cdm.ext.geo.FloraCubaCondensedDistributionComposer#createCondensedDistribution(java.util.Collection, java.util.List)}.
|
82
|
*/
|
83
|
@Test
|
84
|
public void testCreateCondensedDistribution() {
|
85
|
FloraCubaCondensedDistributionComposer composer = new FloraCubaCondensedDistributionComposer();
|
86
|
|
87
|
Set<Distribution> filteredDistributions = new HashSet<Distribution>();
|
88
|
filteredDistributions.add(Distribution.NewInstance(cuba, PresenceAbsenceTerm.NATURALISED()));
|
89
|
filteredDistributions.add(Distribution.NewInstance(eastCuba, statusVoc.findTermByUuid(uuidStatusOccasionallyCultivated)));
|
90
|
filteredDistributions.add(Distribution.NewInstance(pinarDelRio, PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR()));
|
91
|
filteredDistributions.add(Distribution.NewInstance(holguin, PresenceAbsenceTerm.NATURALISED()));
|
92
|
filteredDistributions.add(Distribution.NewInstance(bahamas, PresenceAbsenceTerm.NATIVE()));
|
93
|
filteredDistributions.add(Distribution.NewInstance(oldWorld, PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE()));
|
94
|
|
95
|
CondensedDistribution condensedDistribution = composer.createCondensedDistribution(filteredDistributions, null);
|
96
|
String condensedString = condensedDistribution.toString();
|
97
|
System.out.println(condensedString);
|
98
|
}
|
99
|
|
100
|
|
101
|
|
102
|
private static boolean makeAreas(){
|
103
|
|
104
|
//vocabulary
|
105
|
UUID cubaAreasVocabularyUuid = UUID.fromString("c81e3c7b-3c01-47d1-87cf-388de4b1908c");
|
106
|
String label = "Cuba Areas";
|
107
|
String abbrev = null;
|
108
|
cubaAreasVocabualary = OrderedTermVocabulary.NewInstance(TermType.NamedArea, label, label, abbrev, null);
|
109
|
cubaAreasVocabualary.setUuid(cubaAreasVocabularyUuid);
|
110
|
|
111
|
//Cuba
|
112
|
label = "Cuba";
|
113
|
abbrev = "Cu";
|
114
|
UUID uuid = UUID.randomUUID();
|
115
|
cuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
116
|
|
117
|
//Western Cuba
|
118
|
label = "Western Cuba";
|
119
|
abbrev = "CuW";
|
120
|
uuid = UUID.randomUUID();
|
121
|
westernCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
122
|
cuba.addIncludes(westernCuba);
|
123
|
|
124
|
//Central Cuba
|
125
|
label = "Central Cuba";
|
126
|
abbrev = "CuC";
|
127
|
uuid = UUID.randomUUID();
|
128
|
centralCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
129
|
cuba.addIncludes(centralCuba);
|
130
|
|
131
|
//East Cuba
|
132
|
label = "East Cuba";
|
133
|
abbrev = "CuE";
|
134
|
uuid = UUID.randomUUID();
|
135
|
eastCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
136
|
cuba.addIncludes(eastCuba);
|
137
|
|
138
|
//Pinar del Río PR
|
139
|
label = "Pinar del Río";
|
140
|
abbrev = "PR*";
|
141
|
uuid = UUID.randomUUID();
|
142
|
pinarDelRio = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
143
|
westernCuba.addIncludes(pinarDelRio);
|
144
|
|
145
|
//Artemisa
|
146
|
label = "Artemisa";
|
147
|
abbrev = "Art";
|
148
|
uuid = UUID.randomUUID();
|
149
|
NamedArea area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
150
|
westernCuba.addIncludes(area);
|
151
|
|
152
|
//Ciudad de la Habana
|
153
|
label = "Ciudad de la Habana";
|
154
|
abbrev = "Hab*";
|
155
|
uuid = UUID.randomUUID();
|
156
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
157
|
westernCuba.addIncludes(area);
|
158
|
|
159
|
//Ciudad de la Habana
|
160
|
label = "Mayabeque";
|
161
|
abbrev = "May";
|
162
|
uuid = UUID.randomUUID();
|
163
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
164
|
westernCuba.addIncludes(area);
|
165
|
|
166
|
//Matanzas Mat
|
167
|
label = "Matanzas";
|
168
|
abbrev = "Mat";
|
169
|
uuid = UUID.randomUUID();
|
170
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
171
|
westernCuba.addIncludes(area);
|
172
|
|
173
|
//Isla de la Juventud IJ
|
174
|
label = "Isla de la Juventud";
|
175
|
abbrev = "IJ";
|
176
|
uuid = UUID.randomUUID();
|
177
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
178
|
westernCuba.addIncludes(area);
|
179
|
|
180
|
//Provinces - Central
|
181
|
//Villa Clara VC
|
182
|
label = "Villa Clara";
|
183
|
abbrev = "VC";
|
184
|
uuid = UUID.randomUUID();
|
185
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
186
|
centralCuba.addIncludes(area);
|
187
|
|
188
|
//Cienfuegos Ci VC
|
189
|
label = "Cienfuegos";
|
190
|
abbrev = "Ci";
|
191
|
uuid = UUID.randomUUID();
|
192
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
193
|
centralCuba.addIncludes(area);
|
194
|
|
195
|
//Sancti Spiritus SS
|
196
|
label = "Sancti Spíritus";
|
197
|
abbrev = "SS";
|
198
|
uuid = UUID.randomUUID();
|
199
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
200
|
centralCuba.addIncludes(area);
|
201
|
|
202
|
//Ciego de Ávila CA
|
203
|
label = "Ciego de Ávila";
|
204
|
abbrev = "CA";
|
205
|
uuid = UUID.randomUUID();
|
206
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
207
|
centralCuba.addIncludes(area);
|
208
|
|
209
|
//Camagüey Cam
|
210
|
label = "Camagüey";
|
211
|
abbrev = "Cam";
|
212
|
uuid = UUID.randomUUID();
|
213
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
214
|
centralCuba.addIncludes(area);
|
215
|
|
216
|
//Las Tunas LT
|
217
|
label = "Las Tunas";
|
218
|
abbrev = "LT";
|
219
|
uuid = UUID.randomUUID();
|
220
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
221
|
centralCuba.addIncludes(area);
|
222
|
|
223
|
//Provinces - East
|
224
|
//Granma Gr
|
225
|
label = "Granma";
|
226
|
abbrev = "Gr";
|
227
|
uuid = UUID.randomUUID();
|
228
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
229
|
eastCuba.addIncludes(area);
|
230
|
|
231
|
//Holguín Ho
|
232
|
label = "Holguín";
|
233
|
abbrev = "Ho";
|
234
|
uuid = UUID.randomUUID();
|
235
|
holguin = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
236
|
eastCuba.addIncludes(holguin);
|
237
|
|
238
|
//Santiago de Cuba SC
|
239
|
label = "Santiago de Cuba";
|
240
|
abbrev = "SC";
|
241
|
uuid = UUID.randomUUID();
|
242
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
243
|
eastCuba.addIncludes(area);
|
244
|
|
245
|
//Guantánamo Gu
|
246
|
label = "Guantánamo";
|
247
|
abbrev = "Gu";
|
248
|
uuid = UUID.randomUUID();
|
249
|
guantanamo = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
250
|
eastCuba.addIncludes(guantanamo);
|
251
|
|
252
|
//other Greater Antilles (Cuba, Española, Jamaica, Puerto Rico)
|
253
|
//Española Esp (=Haiti + Dominican Republic)
|
254
|
label = "Española";
|
255
|
abbrev = "Esp";
|
256
|
uuid = UUID.randomUUID();
|
257
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
258
|
|
259
|
//Jamaica Ja
|
260
|
label = "Jamaica";
|
261
|
abbrev = "Ja";
|
262
|
uuid = UUID.randomUUID();
|
263
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
264
|
|
265
|
//Puerto Rico PR
|
266
|
label = "Puerto Rico";
|
267
|
abbrev = "PRc";
|
268
|
uuid = UUID.randomUUID();
|
269
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
270
|
|
271
|
//Lesser Antilles Men
|
272
|
label = "Lesser Antilles";
|
273
|
abbrev = "Men";
|
274
|
uuid = UUID.randomUUID();
|
275
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
276
|
|
277
|
//Bahamas
|
278
|
label = "Bahamas";
|
279
|
abbrev = "Bah";
|
280
|
uuid = UUID.randomUUID();
|
281
|
bahamas = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
282
|
|
283
|
//Cayman Islands
|
284
|
label = "Cayman Islands"; //[Trinidad, Tobago, Curaçao, Margarita, ABC Isl. => S. America];
|
285
|
abbrev = "Cay";
|
286
|
uuid = UUID.randomUUID();
|
287
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
288
|
|
289
|
//World
|
290
|
//N America
|
291
|
label = "N America"; //(incl. Mexico)
|
292
|
abbrev = "AmN";
|
293
|
uuid = UUID.randomUUID();
|
294
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
295
|
|
296
|
//Central America
|
297
|
label = "Central America";
|
298
|
abbrev = "AmC";
|
299
|
uuid = UUID.randomUUID();
|
300
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
301
|
|
302
|
|
303
|
//S America
|
304
|
label = "S America";
|
305
|
abbrev = "AmS";
|
306
|
uuid = UUID.randomUUID();
|
307
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
308
|
|
309
|
//Old World
|
310
|
label = "Old World ";
|
311
|
abbrev = "VM";
|
312
|
uuid = UUID.randomUUID();
|
313
|
oldWorld = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
314
|
|
315
|
return true;
|
316
|
}
|
317
|
|
318
|
private static NamedArea getNamedArea(UUID uuid, String label, String abbrev, TermVocabulary<NamedArea> vocabulary) {
|
319
|
NamedArea result = NamedArea.NewInstance(label, label, abbrev);
|
320
|
result.setUuid(uuid);
|
321
|
vocabulary.addTerm(result);
|
322
|
result.setIdInVocabulary(abbrev);
|
323
|
return result;
|
324
|
|
325
|
}
|
326
|
|
327
|
|
328
|
private static PresenceAbsenceTerm makeStatusTerm(String desc, String abbrev, boolean absent, UUID uuid) {
|
329
|
PresenceAbsenceTerm result = PresenceAbsenceTerm.NewPresenceInstance(desc, desc, abbrev);
|
330
|
result.setAbsenceTerm(absent);
|
331
|
result.setUuid(uuid);
|
332
|
return result;
|
333
|
}
|
334
|
|
335
|
|
336
|
}
|