1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.service;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Iterator;
|
16
|
import java.util.LinkedHashMap;
|
17
|
import java.util.List;
|
18
|
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
|
23
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager;
|
24
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.agent.Team;
|
27
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
28
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
29
|
import eu.etaxonomy.cdm.model.media.Media;
|
30
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
32
|
import eu.etaxonomy.cdm.model.name.Rank;
|
33
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
34
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
37
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
38
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
40
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
41
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
42
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
43
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
44
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
45
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
46
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
47
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
48
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
49
|
import eu.etaxonomy.cdm.test.TermTestBase;
|
50
|
|
51
|
/**
|
52
|
* @author a.kohlbecker, k.luther
|
53
|
* @since 03.09.2018
|
54
|
*/
|
55
|
public class TypeDesignationSetManagerTest extends TermTestBase{
|
56
|
|
57
|
private NameTypeDesignation ntd;
|
58
|
private NameTypeDesignation ntd_LT;
|
59
|
private SpecimenTypeDesignation std_IT;
|
60
|
private SpecimenTypeDesignation std_HT;
|
61
|
private SpecimenTypeDesignation std_LT;
|
62
|
private SpecimenTypeDesignation std_IT_2;
|
63
|
private SpecimenTypeDesignation std_IT_3;
|
64
|
private SpecimenTypeDesignation mtd_HT_published;
|
65
|
private SpecimenTypeDesignation mtd_IT_unpublished;
|
66
|
private Reference book;
|
67
|
private Team team;
|
68
|
|
69
|
@Before
|
70
|
public void init(){
|
71
|
|
72
|
Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
|
73
|
Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
|
74
|
Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
|
75
|
team = Team.NewInstance(person1, person2, person3);
|
76
|
|
77
|
book = ReferenceFactory.newBook();
|
78
|
book.setAuthorship(team);
|
79
|
book.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
|
80
|
|
81
|
ntd = NameTypeDesignation.NewInstance();
|
82
|
ntd.setId(1);
|
83
|
TaxonName typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
84
|
typeName.setTitleCache("Prionus coriatius L.", true);
|
85
|
ntd.setTypeName(typeName);
|
86
|
// Reference citation = ReferenceFactory.newGeneric();
|
87
|
// citation.setTitleCache("Species Plantarum", true);
|
88
|
// ntd.setCitation(citation);
|
89
|
// ntd.addPrimaryTaxonomicSource(citation, null);
|
90
|
|
91
|
ntd_LT = NameTypeDesignation.NewInstance();
|
92
|
ntd_LT.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
|
93
|
TaxonName typeName2 = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
94
|
typeName2.setTitleCache("Prionus arealus L.", true);
|
95
|
ntd_LT.setTypeName(typeName2);
|
96
|
ntd_LT.setCitation(book);
|
97
|
|
98
|
FieldUnit fu_1 = FieldUnit.NewInstance();
|
99
|
fu_1.setId(1);
|
100
|
fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
|
101
|
|
102
|
FieldUnit fu_2 = FieldUnit.NewInstance();
|
103
|
fu_2.setId(2);
|
104
|
fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
|
105
|
|
106
|
std_HT = SpecimenTypeDesignation.NewInstance();
|
107
|
std_HT.setId(1);
|
108
|
DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
109
|
specimen_HT.setTitleCache("OHA", true);
|
110
|
createDerivationEvent(fu_1, specimen_HT);
|
111
|
specimen_HT.getOriginals().add(fu_1);
|
112
|
std_HT.setTypeSpecimen(specimen_HT);
|
113
|
std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
114
|
|
115
|
std_IT = SpecimenTypeDesignation.NewInstance();
|
116
|
std_IT.setId(2);
|
117
|
DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
118
|
specimen_IT.setTitleCache("BER", true);
|
119
|
createDerivationEvent(fu_1, specimen_IT);
|
120
|
std_IT.setTypeSpecimen(specimen_IT);
|
121
|
std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
122
|
|
123
|
std_LT = SpecimenTypeDesignation.NewInstance();
|
124
|
DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
125
|
specimen_LT.setTitleCache("LEC", true);
|
126
|
createDerivationEvent(fu_1, specimen_LT);
|
127
|
std_LT.setTypeSpecimen(specimen_LT);
|
128
|
std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
|
129
|
std_LT.setCitation(book);
|
130
|
|
131
|
std_IT_2 = SpecimenTypeDesignation.NewInstance();
|
132
|
std_IT_2.setId(3);
|
133
|
DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
134
|
specimen_IT_2.setTitleCache("KEW", true);
|
135
|
createDerivationEvent(fu_1, specimen_IT_2);
|
136
|
std_IT_2.setTypeSpecimen(specimen_IT_2);
|
137
|
std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
138
|
|
139
|
std_IT_3 = SpecimenTypeDesignation.NewInstance();
|
140
|
std_IT_3.setId(4);
|
141
|
DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
142
|
specimen_IT_3.setTitleCache("M", true);
|
143
|
createDerivationEvent(fu_2, specimen_IT_3);
|
144
|
std_IT_3.setTypeSpecimen(specimen_IT_3);
|
145
|
std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
146
|
|
147
|
mtd_HT_published = SpecimenTypeDesignation.NewInstance();
|
148
|
mtd_HT_published.setId(5);
|
149
|
MediaSpecimen mediaSpecimen_published = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
|
150
|
Media media = Media.NewInstance();
|
151
|
Reference ref = ReferenceFactory.newGeneric();
|
152
|
ref.setTitleCache("A.K. & W.K (2008) Algae of the BGBM", true);
|
153
|
media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "p.33"));
|
154
|
mediaSpecimen_published.setMediaSpecimen(media);
|
155
|
createDerivationEvent(fu_1, mediaSpecimen_published);
|
156
|
mtd_HT_published.setTypeSpecimen(mediaSpecimen_published);
|
157
|
mtd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
158
|
|
159
|
mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
|
160
|
mtd_IT_unpublished.setId(6);
|
161
|
MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
|
162
|
eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
|
163
|
collection.setCode("B");
|
164
|
mediaSpecimen_unpublished.setCollection(collection);
|
165
|
mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
|
166
|
createDerivationEvent(fu_1, mediaSpecimen_unpublished);
|
167
|
mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
|
168
|
mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
169
|
}
|
170
|
|
171
|
protected void createDerivationEvent(FieldUnit fu_1, DerivedUnit specimen_IT_2) {
|
172
|
DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
|
173
|
derivationEvent_3.addOriginal(fu_1);
|
174
|
derivationEvent_3.addDerivative(specimen_IT_2);
|
175
|
}
|
176
|
|
177
|
@Test
|
178
|
public void test1() throws RegistrationValidationException{
|
179
|
|
180
|
@SuppressWarnings("rawtypes")
|
181
|
List<TypeDesignationBase> tds = new ArrayList<>();
|
182
|
tds.add(ntd);
|
183
|
tds.add(std_IT);
|
184
|
tds.add(std_HT);
|
185
|
tds.add(std_IT_2);
|
186
|
tds.add(std_IT_3);
|
187
|
|
188
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
|
189
|
typifiedName.setTitleCache("Prionus L.", true);
|
190
|
|
191
|
typifiedName.addTypeDesignation(ntd, false);
|
192
|
typifiedName.addTypeDesignation(std_HT, false);
|
193
|
typifiedName.addTypeDesignation(std_IT, false);
|
194
|
typifiedName.addTypeDesignation(std_IT_2, false);
|
195
|
typifiedName.addTypeDesignation(std_IT_3, false);
|
196
|
|
197
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(tds);
|
198
|
String result = typeDesignationManager.print(true, true, true);
|
199
|
|
200
|
// Logger.getLogger(this.getClass()).debug(result);
|
201
|
assertNotNull(result);
|
202
|
assertEquals(
|
203
|
"Prionus L.\u202F\u2013\u202FTypes: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 (isotype: M);"
|
204
|
+ " Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA; isotypes: BER, KEW);"
|
205
|
+ " Nametype: Prionus coriatius L."
|
206
|
, result
|
207
|
);
|
208
|
|
209
|
LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedTypeDesignations =
|
210
|
typeDesignationManager.getOrderedTypeDesignationWorkingSets();
|
211
|
Iterator<TypeDesignationWorkingSet> byStatusMapIterator = orderedTypeDesignations.values().iterator();
|
212
|
Iterator<TypeDesignationStatusBase<?>> keyIt_1 = byStatusMapIterator.next().keySet().iterator();
|
213
|
Iterator<TypeDesignationStatusBase<?>> keyIt_2 = byStatusMapIterator.next().keySet().iterator();
|
214
|
assertEquals("isotype", keyIt_1.next().getLabel());
|
215
|
assertEquals("holotype", keyIt_2.next().getLabel());
|
216
|
assertEquals("isotype", keyIt_2.next().getLabel());
|
217
|
}
|
218
|
|
219
|
@Test
|
220
|
public void test2() {
|
221
|
|
222
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
|
223
|
typifiedName.setTitleCache("Prionus L.", true);
|
224
|
|
225
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
|
226
|
String result = typeDesignationManager.print(true, true, true);
|
227
|
assertEquals(
|
228
|
"Prionus L."
|
229
|
, result
|
230
|
);
|
231
|
|
232
|
typifiedName.addTypeDesignation(ntd, false);
|
233
|
typeDesignationManager.addTypeDesigations(ntd);
|
234
|
|
235
|
assertEquals(
|
236
|
"Prionus L.\u202F\u2013\u202FNametype: Prionus coriatius L."
|
237
|
, typeDesignationManager.print(true, true, true)
|
238
|
);
|
239
|
|
240
|
typifiedName.addTypeDesignation(std_HT, false);
|
241
|
typeDesignationManager.addTypeDesigations(std_HT);
|
242
|
|
243
|
assertEquals(
|
244
|
"Prionus L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA); Nametype: Prionus coriatius L."
|
245
|
, typeDesignationManager.print(true, true, true)
|
246
|
);
|
247
|
}
|
248
|
|
249
|
//see #9262
|
250
|
@Test
|
251
|
public void test_desigby_fide(){
|
252
|
//specimen types
|
253
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
254
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
255
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
|
256
|
typeDesignationManager.addTypeDesigations(std_LT);
|
257
|
Reference citation = ReferenceFactory.newBook();
|
258
|
Reference inRef = ReferenceFactory.newBookSection();
|
259
|
inRef.setInBook(citation);
|
260
|
citation.setDatePublished(TimePeriodParser.parseStringVerbatim("1989"));
|
261
|
inRef.setAuthorship(Team.NewTitledInstance("Miller", "Mill."));
|
262
|
std_LT.addPrimaryTaxonomicSource(inRef, "55");
|
263
|
assertEquals("Prionus coriatius L.\u202F\u2013\u202FTestland, near Bughausen, A.Kohlbecker 81989, 2017 (lectotype: LEC designated by Decandolle & al. 1962 [fide Miller 1989: 55])",
|
264
|
typeDesignationManager.print(true, false, true));
|
265
|
assertEquals("Prionus coriatius L.\u202F\u2013\u202FTestland, near Bughausen, A.Kohlbecker 81989, 2017 (lectotype: LEC)",
|
266
|
typeDesignationManager.print(false, false, true));
|
267
|
assertEquals("Testland, near Bughausen, A.Kohlbecker 81989, 2017 (lectotype: LEC)",
|
268
|
typeDesignationManager.print(false, false, false));
|
269
|
|
270
|
//name types
|
271
|
typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
|
272
|
typifiedName.setTitleCache("Prionus L.", true);
|
273
|
typeDesignationManager = new TypeDesignationSetManager(typifiedName);
|
274
|
typeDesignationManager.addTypeDesigations(ntd_LT);
|
275
|
ntd_LT.addPrimaryTaxonomicSource(inRef, "66");
|
276
|
assertEquals("Prionus L.\u202F\u2013\u202FLectotype: Prionus arealus L. designated by Decandolle & al. 1962 [fide Miller 1989: 66]",
|
277
|
typeDesignationManager.print(true, false, true));
|
278
|
assertEquals("Prionus L.\u202F\u2013\u202FLectotype: Prionus arealus L.",
|
279
|
typeDesignationManager.print(false, false, true));
|
280
|
|
281
|
}
|
282
|
|
283
|
@Test
|
284
|
public void test_mediaType(){
|
285
|
|
286
|
for(int i = 0; i < 10; i++ ){
|
287
|
init();
|
288
|
// repeat 10 times to assure the order of typedesignations is fix in the representations
|
289
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
290
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
291
|
typifiedName.addTypeDesignation(mtd_HT_published, false);
|
292
|
typifiedName.addTypeDesignation(mtd_IT_unpublished, false);
|
293
|
|
294
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
|
295
|
typeDesignationManager.addTypeDesigations(mtd_HT_published);
|
296
|
typeDesignationManager.addTypeDesigations(mtd_IT_unpublished);
|
297
|
|
298
|
assertEquals("failed after repreating " + i + " times",
|
299
|
"Prionus coriatius L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: [icon] p.33 in A.K. & W.K (2008) Algae of the BGBM; isotype: [icon] B Slide A565656)"
|
300
|
, typeDesignationManager.print(true, true, true)
|
301
|
);
|
302
|
}
|
303
|
}
|
304
|
}
|