1
|
/**
|
2
|
* Copyright (C) 2021 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.name;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.junit.Assert;
|
15
|
import org.junit.Before;
|
16
|
import org.junit.Test;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.agent.Team;
|
21
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
22
|
import eu.etaxonomy.cdm.model.media.Media;
|
23
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
24
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
27
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
29
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
30
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.OccurrenceStatus;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
39
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
40
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
41
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
42
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
43
|
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
|
44
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
45
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
46
|
import eu.etaxonomy.cdm.test.TermTestBase;
|
47
|
|
48
|
/**
|
49
|
* @author a.mueller
|
50
|
* @since 30.03.2021
|
51
|
*/
|
52
|
public class TypeDesignationSetFormatterTest extends TermTestBase{
|
53
|
|
54
|
//variables and setup were copied from TypeDesignationSetContainerTest
|
55
|
//not all of them are in use yet
|
56
|
private NameTypeDesignation ntd;
|
57
|
private NameTypeDesignation ntd_LT;
|
58
|
private SpecimenTypeDesignation std_IT;
|
59
|
private SpecimenTypeDesignation std_HT;
|
60
|
private SpecimenTypeDesignation std_LT;
|
61
|
private SpecimenTypeDesignation std_IT_2;
|
62
|
private SpecimenTypeDesignation std_IT_3;
|
63
|
private SpecimenTypeDesignation mstd_HT_published;
|
64
|
private SpecimenTypeDesignation mtd_IT_unpublished;
|
65
|
private Reference book;
|
66
|
private Team team;
|
67
|
|
68
|
@Before
|
69
|
public void setUp() throws Exception {
|
70
|
Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
|
71
|
Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
|
72
|
Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
|
73
|
team = Team.NewInstance(person1, person2, person3);
|
74
|
|
75
|
book = ReferenceFactory.newBook();
|
76
|
book.setAuthorship(team);
|
77
|
book.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
|
78
|
|
79
|
ntd = NameTypeDesignation.NewInstance();
|
80
|
ntd.setId(1);
|
81
|
TaxonName typeName = TaxonNameFactory.PARSED_BOTANICAL("Prionus coriatius L.");
|
82
|
ntd.setTypeName(typeName);
|
83
|
// Reference citation = ReferenceFactory.newGeneric();
|
84
|
// citation.setTitleCache("Species Plantarum", true);
|
85
|
// ntd.setCitation(citation);
|
86
|
// ntd.addPrimaryTaxonomicSource(citation, null);
|
87
|
|
88
|
ntd_LT = NameTypeDesignation.NewInstance();
|
89
|
ntd_LT.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
|
90
|
TaxonName typeName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
91
|
typeName2.setTitleCache("Prionus arealus L.", true);
|
92
|
ntd_LT.setTypeName(typeName2);
|
93
|
ntd_LT.setCitation(book);
|
94
|
|
95
|
FieldUnit fu_1 = FieldUnit.NewInstance();
|
96
|
fu_1.setId(1);
|
97
|
fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
|
98
|
|
99
|
FieldUnit fu_2 = FieldUnit.NewInstance();
|
100
|
fu_2.setId(2);
|
101
|
fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
|
102
|
|
103
|
std_HT = SpecimenTypeDesignation.NewInstance();
|
104
|
std_HT.setId(1);
|
105
|
DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
106
|
Collection collection_OHA = Collection.NewInstance("OHA", null);
|
107
|
specimen_HT.setCollection(collection_OHA);
|
108
|
specimen_HT.setAccessionNumber("OHA 1234");
|
109
|
createDerivationEvent(fu_1, specimen_HT);
|
110
|
specimen_HT.getOriginals().add(fu_1);
|
111
|
std_HT.setTypeSpecimen(specimen_HT);
|
112
|
std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
113
|
|
114
|
std_IT = SpecimenTypeDesignation.NewInstance();
|
115
|
std_IT.setId(2);
|
116
|
DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
117
|
specimen_IT.setTitleCache("BER", true);
|
118
|
createDerivationEvent(fu_1, specimen_IT);
|
119
|
std_IT.setTypeSpecimen(specimen_IT);
|
120
|
std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
121
|
|
122
|
std_LT = SpecimenTypeDesignation.NewInstance();
|
123
|
DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
124
|
specimen_LT.setTitleCache("LEC", true);
|
125
|
createDerivationEvent(fu_1, specimen_LT);
|
126
|
std_LT.setTypeSpecimen(specimen_LT);
|
127
|
std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
|
128
|
std_LT.setCitation(book);
|
129
|
|
130
|
std_IT_2 = SpecimenTypeDesignation.NewInstance();
|
131
|
std_IT_2.setId(3);
|
132
|
DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
133
|
specimen_IT_2.setTitleCache("KEW", true);
|
134
|
createDerivationEvent(fu_1, specimen_IT_2);
|
135
|
std_IT_2.setTypeSpecimen(specimen_IT_2);
|
136
|
std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
137
|
|
138
|
std_IT_3 = SpecimenTypeDesignation.NewInstance();
|
139
|
std_IT_3.setId(4);
|
140
|
DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
141
|
specimen_IT_3.setTitleCache("M", true);
|
142
|
createDerivationEvent(fu_2, specimen_IT_3);
|
143
|
std_IT_3.setTypeSpecimen(specimen_IT_3);
|
144
|
std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
145
|
|
146
|
mstd_HT_published = SpecimenTypeDesignation.NewInstance();
|
147
|
mstd_HT_published.setId(5);
|
148
|
MediaSpecimen mediaSpecimen_published = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
|
149
|
Media media = Media.NewInstance();
|
150
|
Reference ref = ReferenceFactory.newGeneric();
|
151
|
ref.setTitleCache("A.K. & W.K (2008) Algae of the BGBM", true);
|
152
|
media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "p.33"));
|
153
|
mediaSpecimen_published.setMediaSpecimen(media);
|
154
|
createDerivationEvent(fu_1, mediaSpecimen_published);
|
155
|
mstd_HT_published.setTypeSpecimen(mediaSpecimen_published);
|
156
|
mstd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
157
|
|
158
|
mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
|
159
|
mtd_IT_unpublished.setId(6);
|
160
|
MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
|
161
|
eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
|
162
|
collection.setCode("B");
|
163
|
mediaSpecimen_unpublished.setCollection(collection);
|
164
|
mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
|
165
|
createDerivationEvent(fu_1, mediaSpecimen_unpublished);
|
166
|
mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
|
167
|
mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
168
|
}
|
169
|
|
170
|
protected void createDerivationEvent(FieldUnit fu_1, DerivedUnit specimen_IT_2) {
|
171
|
DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
|
172
|
derivationEvent_3.addOriginal(fu_1);
|
173
|
derivationEvent_3.addDerivative(specimen_IT_2);
|
174
|
}
|
175
|
|
176
|
@Test
|
177
|
public void testNameTypeDesignationTaggedText() throws TypeDesignationSetException {
|
178
|
|
179
|
@SuppressWarnings("rawtypes")
|
180
|
List<TypeDesignationBase> tds = new ArrayList<>();
|
181
|
tds.add(ntd);
|
182
|
|
183
|
TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
184
|
typifiedName.setTitleCache("Prionus L.", true);
|
185
|
|
186
|
typifiedName.addTypeDesignation(ntd, false);
|
187
|
|
188
|
TypeDesignationSetContainer manager = TypeDesignationSetContainer.NewDefaultInstance(tds);
|
189
|
TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(true, true, true);
|
190
|
String text = formatter.format(manager);
|
191
|
Assert.assertEquals("Prionus L.\u202F\u2013\u202FNametype: Prionus coriatius L.", text);
|
192
|
|
193
|
List<TaggedText> taggedText = formatter.toTaggedText(manager);
|
194
|
Assert.assertEquals("first entry should be the typified name",
|
195
|
new TaggedText(TagEnum.name, "Prionus L.",TypedEntityReference.fromEntity(typifiedName, false)), taggedText.get(0));
|
196
|
Assert.assertEquals("fourth entry should be the name type nameCache",
|
197
|
new TaggedText(TagEnum.name, "Prionus"), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
198
|
Assert.assertEquals("fourth entry should be the name type nameCache",
|
199
|
new TaggedText(TagEnum.name, "coriatius"), taggedText.get(4)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
200
|
Assert.assertEquals("fifth entry should be the name type authorship cache",
|
201
|
new TaggedText(TagEnum.authors, "L."), taggedText.get(5));
|
202
|
|
203
|
//protected titleCache
|
204
|
ntd.getTypeName().setTitleCache("Prionus coriatius L.", true);
|
205
|
taggedText = formatter.toTaggedText(manager);
|
206
|
Assert.assertEquals("fourth entry should be the name type titleCache",
|
207
|
new TaggedText(TagEnum.name, "Prionus coriatius L."), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
208
|
Assert.assertEquals("there should be 4 tags only", 4, taggedText.size());
|
209
|
}
|
210
|
|
211
|
@Test
|
212
|
public void testSpecimenTypeDesignationTaggedTextWithStatus() throws TypeDesignationSetException {
|
213
|
|
214
|
@SuppressWarnings("rawtypes")
|
215
|
List<TypeDesignationBase> tds = new ArrayList<>();
|
216
|
tds.add(std_HT);
|
217
|
|
218
|
TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
219
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
220
|
|
221
|
typifiedName.addTypeDesignation(std_HT, false);
|
222
|
Reference statusSource = ReferenceFactory.newBook(); //TODO not yet handled in cache strategy as we do not have tagged text here
|
223
|
statusSource.setTitle("Status test");
|
224
|
std_HT.getTypeSpecimen().addStatus(OccurrenceStatus.NewInstance(DefinedTerm.getTermByUuid(DefinedTerm.uuidDestroyed), statusSource, "335"));
|
225
|
|
226
|
TypeDesignationSetContainer container = TypeDesignationSetContainer.NewDefaultInstance(tds);
|
227
|
TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(true, true, true);
|
228
|
|
229
|
String text = formatter.format(container);
|
230
|
Assert.assertEquals("Prionus coriatius L.\u202F\u2013\u202FType: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA 1234, destroyed)", text);
|
231
|
|
232
|
List<TaggedText> taggedText = formatter.toTaggedText(container);
|
233
|
Assert.assertEquals("first entry should be the typified name",
|
234
|
new TaggedText(TagEnum.name, "Prionus coriatius L.",TypedEntityReference.fromEntity(typifiedName, false)), taggedText.get(0));
|
235
|
// Assert.assertEquals("fourth entry should be the name type nameCache",
|
236
|
// new TaggedText(TagEnum.name, "Prionus"), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
237
|
// Assert.assertEquals("fourth entry should be the name type nameCache",
|
238
|
// new TaggedText(TagEnum.name, "coriatius"), taggedText.get(4)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
239
|
// Assert.assertEquals("fifth entry should be the name type authorship cache",
|
240
|
// new TaggedText(TagEnum.authors, "L."), taggedText.get(5));
|
241
|
//
|
242
|
// //protected titleCache
|
243
|
// ntd.getTypeName().setTitleCache("Prionus coriatius L.", true);
|
244
|
// taggedText = formatter.toTaggedText(manager);
|
245
|
// Assert.assertEquals("fourth entry should be the name type titleCache",
|
246
|
// new TaggedText(TagEnum.name, "Prionus coriatius L."), taggedText.get(3)); //maybe in future the entityReference should be TypedEntityReference.fromEntity(ntd.getTypeName(), false)
|
247
|
// Assert.assertEquals("there should be 4 tags only", 4, taggedText.size());
|
248
|
}
|
249
|
|
250
|
//#10089
|
251
|
@Test
|
252
|
public void testOrderedByStatusNotBaseEntity() throws TypeDesignationSetException {
|
253
|
|
254
|
@SuppressWarnings("rawtypes")
|
255
|
List<TypeDesignationBase> tds = new ArrayList<>();
|
256
|
tds.add(std_HT);
|
257
|
tds.add(std_IT_3);
|
258
|
|
259
|
TaxonName typifiedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
260
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
261
|
|
262
|
typifiedName.addTypeDesignation(std_HT, false);
|
263
|
typifiedName.addTypeDesignation(std_IT_3, false);
|
264
|
|
265
|
TypeDesignationSetContainer container = TypeDesignationSetContainer.NewDefaultInstance(tds);
|
266
|
TypeDesignationSetFormatter formatter = new TypeDesignationSetFormatter(false, false, false);
|
267
|
String text = formatter.format(container);
|
268
|
int holotypeIndex = text.indexOf("holotype");
|
269
|
Assert.assertTrue("Holotype must be first, isotype second", holotypeIndex>0 && (holotypeIndex < text.indexOf("isotype")) );
|
270
|
}
|
271
|
}
|