1
|
/**
|
2
|
* Copyright (C) 2007 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.assertFalse;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import static org.junit.Assert.assertNull;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import java.io.FileNotFoundException;
|
18
|
import java.util.ArrayList;
|
19
|
import java.util.Arrays;
|
20
|
import java.util.Collections;
|
21
|
import java.util.Iterator;
|
22
|
import java.util.List;
|
23
|
import java.util.Set;
|
24
|
import java.util.UUID;
|
25
|
import java.util.stream.Collectors;
|
26
|
|
27
|
import org.junit.Assert;
|
28
|
import org.junit.Before;
|
29
|
import org.junit.Test;
|
30
|
import org.unitils.dbunit.annotation.DataSet;
|
31
|
import org.unitils.spring.annotation.SpringBeanByType;
|
32
|
|
33
|
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
|
34
|
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
|
35
|
import eu.etaxonomy.cdm.api.service.config.SubtreeCloneConfigurator;
|
36
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
37
|
import eu.etaxonomy.cdm.compare.taxon.TaxonNodeNaturalComparator;
|
38
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
39
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
40
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
41
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
42
|
import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
|
43
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
44
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
45
|
import eu.etaxonomy.cdm.model.name.Rank;
|
46
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
47
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
48
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
49
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
50
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
51
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
52
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
53
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
54
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
55
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
56
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
57
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
58
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
59
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
60
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
61
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
62
|
|
63
|
/**
|
64
|
* @author n.hoffmann
|
65
|
* @since Dec 16, 2010
|
66
|
*/
|
67
|
public class TaxonNodeServiceImplTest extends CdmTransactionalIntegrationTest{
|
68
|
|
69
|
@SpringBeanByType
|
70
|
private ITaxonNodeService taxonNodeService;
|
71
|
|
72
|
@SpringBeanByType
|
73
|
private IClassificationService classificationService;
|
74
|
|
75
|
@SpringBeanByType
|
76
|
private IReferenceService referenceService;
|
77
|
|
78
|
@SpringBeanByType
|
79
|
private IAgentService agentService;
|
80
|
|
81
|
@SpringBeanByType
|
82
|
private ITermService termService;
|
83
|
|
84
|
@SpringBeanByType
|
85
|
private INameService nameService;
|
86
|
|
87
|
@SpringBeanByType
|
88
|
private ITaxonService taxonService;
|
89
|
|
90
|
@SpringBeanByType
|
91
|
private IClassificationDao classificationDao;
|
92
|
|
93
|
@SpringBeanByType
|
94
|
private IReferenceDao referenceDao;
|
95
|
|
96
|
@SpringBeanByType
|
97
|
private IPolytomousKeyService polKeyService;
|
98
|
|
99
|
@SpringBeanByType
|
100
|
private IPolytomousKeyNodeService polKeyNodeService;
|
101
|
|
102
|
private static final UUID uuidRefNewSec = UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7");
|
103
|
|
104
|
private static final UUID t1Uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
|
105
|
private static final UUID t2Uuid = UUID.fromString("2659a7e0-ff35-4ee4-8493-b453756ab955");
|
106
|
private static final UUID classificationUuid = UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878");
|
107
|
private static final UUID classification2Uuid = UUID.fromString("43d67247-936f-42a3-a739-bbcde372e334");
|
108
|
private static final UUID referenceUuid = UUID.fromString("de7d1205-291f-45d9-9059-ca83fc7ade14");
|
109
|
private static final UUID node1Uuid= UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
110
|
private static final UUID node2Uuid = UUID.fromString("2d41f0c2-b785-4f73-a436-cc2d5e93cc5b");
|
111
|
|
112
|
private static final UUID node4Uuid = UUID.fromString("2fbf7bf5-22dd-4c1a-84e4-c8c93d1f0342");
|
113
|
private static final UUID node5Uuid = UUID.fromString("c4d5170a-7967-4dac-ab76-ae2019eefde5");
|
114
|
private static final UUID node6Uuid = UUID.fromString("b419ba5e-9c8b-449c-ad86-7abfca9a7340");
|
115
|
private static final UUID rootNodeUuid = UUID.fromString("324a1a77-689c-44be-8e65-347d835f4111");
|
116
|
private static final UUID person1uuid = UUID.fromString("fe660517-8d8e-4dac-8bbb-4fb8f4f4a72e");
|
117
|
|
118
|
private Taxon t1;
|
119
|
private Taxon t2;
|
120
|
private Taxon t4;
|
121
|
private SynonymType synonymType;
|
122
|
private Reference reference;
|
123
|
private String referenceDetail;
|
124
|
private Classification classification;
|
125
|
private TaxonNode node1;
|
126
|
private TaxonNode node2;
|
127
|
|
128
|
private TaxonNode node4;
|
129
|
|
130
|
@Before
|
131
|
public void setUp() throws Exception {
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
136
|
*/
|
137
|
@Test
|
138
|
@DataSet
|
139
|
public final void testMakeTaxonNodeASynonymOfAnotherTaxonNode() {
|
140
|
classification = classificationService.load(classificationUuid);
|
141
|
node1 = taxonNodeService.load(node1Uuid);
|
142
|
node2 = taxonNodeService.load(node2Uuid);
|
143
|
node4 = taxonNodeService.load(node4Uuid);
|
144
|
reference = referenceService.load(referenceUuid);
|
145
|
synonymType = CdmBase.deproxy(termService.load(SynonymType.uuidHomotypicSynonymOf), SynonymType.class) ;
|
146
|
referenceDetail = "test";
|
147
|
|
148
|
//TODO
|
149
|
|
150
|
// descriptions
|
151
|
t1 = node1.getTaxon();
|
152
|
PolytomousKey polKey = PolytomousKey.NewInstance();
|
153
|
PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
|
154
|
keyNode.setKey(polKey);
|
155
|
polKeyNodeService.save(keyNode);
|
156
|
polKeyService.save(polKey);
|
157
|
|
158
|
//nameRelations
|
159
|
|
160
|
TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
161
|
t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null, null );
|
162
|
|
163
|
//taxonRelations
|
164
|
Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
165
|
t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
|
166
|
Synonym synonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
167
|
taxonService.save(t1);
|
168
|
taxonService.save(relatedTaxon);
|
169
|
nameService.save(relatedName);
|
170
|
|
171
|
t1.addHomotypicSynonym(synonym);
|
172
|
taxonService.saveOrUpdate(t1);
|
173
|
t1 =(Taxon) taxonService.load(t1.getUuid());
|
174
|
t1 = HibernateProxyHelper.deproxy(t1);
|
175
|
TaxonName nameT1 = t1.getName();
|
176
|
t2 = node2.getTaxon();
|
177
|
assertEquals(2, t1.getDescriptions().size());
|
178
|
Assert.assertTrue(t2.getSynonyms().isEmpty());
|
179
|
Assert.assertTrue(t2.getDescriptions().size() == 0);
|
180
|
assertEquals(2,t1.getSynonyms().size());
|
181
|
DeleteResult result;
|
182
|
|
183
|
t4 = node4.getTaxon();
|
184
|
UUID uuidT4 = t4.getUuid();
|
185
|
t4 = (Taxon) taxonService.find(uuidT4);
|
186
|
TaxonName name4 = nameService.find(t4.getName().getUuid());
|
187
|
result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node4, node2, synonymType, reference, referenceDetail, null, true);
|
188
|
if (result.isError() || result.isAbort()){
|
189
|
Assert.fail();
|
190
|
}
|
191
|
t4 = (Taxon)taxonService.find(uuidT4);
|
192
|
assertNull(t4);
|
193
|
|
194
|
//Taxon can't be deleted because of the polytomous key node
|
195
|
result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymType, reference, referenceDetail,null, true);
|
196
|
if (result.isError() || result.isAbort()){
|
197
|
Assert.fail();
|
198
|
}
|
199
|
commitAndStartNewTransaction(new String[]{/*"TaxonNode"*/});
|
200
|
t1 = (Taxon)taxonService.find(t1Uuid);
|
201
|
assertNotNull(t1);//because of the polytomous key node
|
202
|
node1 = taxonNodeService.load(node1Uuid);
|
203
|
assertNull(node1);
|
204
|
|
205
|
Set<CdmBase> updatedObjects = result.getUpdatedObjects();
|
206
|
Iterator<CdmBase> it = updatedObjects.iterator();
|
207
|
Taxon taxon;
|
208
|
while (it.hasNext()) {
|
209
|
CdmBase updatedObject = it.next();
|
210
|
if(updatedObject.isInstanceOf(Taxon.class)){
|
211
|
taxon = HibernateProxyHelper.deproxy(updatedObject, Taxon.class);
|
212
|
Set<Synonym> syns = taxon.getSynonyms();
|
213
|
assertNotNull(syns);
|
214
|
if (taxon.equals(t2)){
|
215
|
assertEquals(4,syns.size());
|
216
|
Set<TaxonName> typifiedNames =taxon.getHomotypicGroup().getTypifiedNames();
|
217
|
assertEquals(typifiedNames.size(),4);
|
218
|
assertTrue(taxon.getHomotypicGroup().equals( nameT1.getHomotypicalGroup()));
|
219
|
|
220
|
assertEquals(taxon, t2);
|
221
|
}
|
222
|
|
223
|
}
|
224
|
|
225
|
}
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
230
|
*/
|
231
|
@Test
|
232
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
233
|
public final void testMakeTaxonNodeAHeterotypicSynonymOfAnotherTaxonNode() {
|
234
|
|
235
|
//create data
|
236
|
classification = classificationService.load(classificationUuid);
|
237
|
node1 = taxonNodeService.load(node1Uuid);
|
238
|
node2 = taxonNodeService.load(node2Uuid);
|
239
|
reference = referenceService.load(referenceUuid);
|
240
|
synonymType = CdmBase.deproxy(termService.load(SynonymType.uuidHeterotypicSynonymOf), SynonymType.class) ;
|
241
|
referenceDetail = "test";
|
242
|
|
243
|
// descriptions
|
244
|
t1 = node1.getTaxon();
|
245
|
PolytomousKey polKey = PolytomousKey.NewInstance();
|
246
|
PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
|
247
|
keyNode.setKey(polKey);
|
248
|
polKeyNodeService.save(keyNode);
|
249
|
polKeyService.save(polKey);
|
250
|
|
251
|
//nameRelations
|
252
|
TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
253
|
t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null, null );
|
254
|
TaxonName name1 = t1.getName();
|
255
|
UUID name1UUID = name1.getUuid();
|
256
|
//taxonRelations
|
257
|
Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
258
|
t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
|
259
|
Synonym t1HomotypSynonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
260
|
|
261
|
t1.addHomotypicSynonym(t1HomotypSynonym);
|
262
|
TaxonName nameT1 = t1.getName();
|
263
|
t2 = node2.getTaxon();
|
264
|
assertEquals("taxon 1 must have 2 descriptions", 2, t1.getDescriptions().size());
|
265
|
assertEquals("taxon 1 must have 2 synonyms", 2, t1.getSynonyms().size());
|
266
|
Assert.assertTrue("taxon 2 must have no synonyms", t2.getSynonyms().isEmpty());
|
267
|
Assert.assertTrue("taxon 2 must have no descriptions", t2.getDescriptions().size() == 0);
|
268
|
|
269
|
//save
|
270
|
taxonService.save(t1HomotypSynonym);
|
271
|
taxonService.save(relatedTaxon);
|
272
|
nameService.save(relatedName);
|
273
|
|
274
|
//do it
|
275
|
DeleteResult result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode
|
276
|
(node1, node2, synonymType, reference, referenceDetail, null, true);
|
277
|
|
278
|
//post conditions
|
279
|
if (!result.getUpdatedObjects().iterator().hasNext()){
|
280
|
Assert.fail("Some updates must have taken place");
|
281
|
}
|
282
|
assertEquals(3, result.getUpdatedObjects().size());
|
283
|
assertNotNull("Old taxon should not have been deleted as it is referenced by key node", taxonService.find(t1Uuid));
|
284
|
assertNull("Old taxon node should not exist anymore", taxonNodeService.find(node1Uuid));
|
285
|
|
286
|
t1HomotypSynonym = (Synonym)taxonService.find(t1HomotypSynonym.getUuid());
|
287
|
assertNotNull(t1HomotypSynonym);
|
288
|
|
289
|
keyNode.setTaxon(null);
|
290
|
polKeyNodeService.saveOrUpdate(keyNode);
|
291
|
t2 =HibernateProxyHelper.deproxy(t2);
|
292
|
HibernateProxyHelper.deproxy(t2.getHomotypicGroup());
|
293
|
t2.setName(HibernateProxyHelper.deproxy(t2.getName()));
|
294
|
|
295
|
termService.saveOrUpdate(synonymType);
|
296
|
assertFalse("taxon 2 must have a synonym now", t2.getSynonyms().isEmpty());
|
297
|
assertEquals("taxon 2 must have 3 synonyms now, the old taxon 1 and it's 2 synonyms", 3, t2.getSynonyms().size());
|
298
|
assertEquals("taxon 2 must have 2 descriptions now, taken form taxon 1", 2, t2.getDescriptions().size());
|
299
|
|
300
|
result = taxonService.deleteTaxon(t1.getUuid(), null, null);
|
301
|
if (result.isAbort() || result.isError()){
|
302
|
Assert.fail();
|
303
|
}
|
304
|
assertNull(taxonService.find(t1Uuid));
|
305
|
assertNull(taxonNodeService.find(node1Uuid));
|
306
|
name1 = nameService.find(name1UUID);
|
307
|
assertNotNull("taxon name 1 should still exist", name1);
|
308
|
assertEquals("... but being used for the new synonym only as taxon 1 is deleted", 1, name1.getTaxonBases().size());
|
309
|
t1HomotypSynonym = (Synonym)taxonService.find(t1HomotypSynonym.getUuid());
|
310
|
assertNotNull(t1HomotypSynonym);
|
311
|
|
312
|
Synonym newSynonym =(Synonym) name1.getTaxonBases().iterator().next();
|
313
|
|
314
|
Taxon newAcceptedTaxon = CdmBase.deproxy(taxonService.find(t2.getUuid()), Taxon.class);
|
315
|
assertEquals("The new synonym (old accepted taxon) and it's homotypic synonym should still be homotypic", newSynonym.getHomotypicGroup(), t1HomotypSynonym.getName().getHomotypicalGroup());
|
316
|
assertFalse("The new accepted taxon must not be homotypic to ", newAcceptedTaxon.getHomotypicGroup().equals(newSynonym.getName().getHomotypicalGroup()));
|
317
|
|
318
|
assertEquals("The new accepted taxon is taxon 2", newAcceptedTaxon, t2);
|
319
|
assertEquals("The new synonyms name must be the same as the old accepted taxon's name", newSynonym.getName(), nameT1);
|
320
|
}
|
321
|
|
322
|
|
323
|
@Test
|
324
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
325
|
public final void testIndexCreateNode() {
|
326
|
Taxon taxon = Taxon.NewInstance(null, null);
|
327
|
classification = classificationService.load(classificationUuid);
|
328
|
node2 = taxonNodeService.load(node2Uuid);
|
329
|
String oldTreeIndex = node2.treeIndex();
|
330
|
|
331
|
TaxonNode newNode = node2.addChildTaxon(taxon, null, null);
|
332
|
taxonNodeService.saveOrUpdate(newNode);
|
333
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
334
|
newNode = taxonNodeService.load(newNode.getUuid());
|
335
|
Assert.assertEquals("", oldTreeIndex + newNode.getId() + "#", newNode.treeIndex());
|
336
|
}
|
337
|
|
338
|
|
339
|
@Test
|
340
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
341
|
public final void testIndexMoveNode() {
|
342
|
//in classification
|
343
|
classification = classificationService.load(classificationUuid);
|
344
|
node1 = taxonNodeService.load(node1Uuid);
|
345
|
node2 = taxonNodeService.load(node2Uuid);
|
346
|
node2.addChildNode(node1, null, null);
|
347
|
taxonNodeService.saveOrUpdate(node1);
|
348
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
349
|
TaxonNode node6 = taxonNodeService.load(node6Uuid);
|
350
|
Assert.assertEquals("Node6 treeindex is not correct", node2.treeIndex() + "2#4#6#", node6.treeIndex());
|
351
|
|
352
|
//root of new classification
|
353
|
Classification classification2 = classificationService.load(classification2Uuid);
|
354
|
node1 = taxonNodeService.load(node1Uuid);
|
355
|
classification2.setRootNode(HibernateProxyHelper.deproxy(classification2.getRootNode(),TaxonNode.class));
|
356
|
classification2.addChildNode(node1, null, null);
|
357
|
taxonNodeService.saveOrUpdate(node1);
|
358
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
359
|
node1 = taxonNodeService.load(node1Uuid);
|
360
|
Assert.assertEquals("Node1 treeindex is not correct", "#t2#8#2#", node1.treeIndex());
|
361
|
node6 = taxonNodeService.load(node6Uuid);
|
362
|
Assert.assertEquals("Node6 treeindex is not correct", "#t2#8#2#4#6#", node6.treeIndex());
|
363
|
|
364
|
//into new classification
|
365
|
node2 = taxonNodeService.load(node2Uuid);
|
366
|
TaxonNode node5 = taxonNodeService.load(node5Uuid);
|
367
|
node2 =node5.addChildNode(node2, null, null);
|
368
|
taxonNodeService.saveOrUpdate(node2);
|
369
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
370
|
node2 = taxonNodeService.load(node2Uuid);
|
371
|
Assert.assertEquals("Node3 treeindex is not correct", "#t2#8#2#5#3#", node2.treeIndex());
|
372
|
|
373
|
}
|
374
|
|
375
|
@Test
|
376
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
377
|
public final void testIndexDeleteNode() {
|
378
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
379
|
node1 = taxonNodeService.load(node1Uuid);
|
380
|
TaxonNode node4 = taxonNodeService.load(node4Uuid);
|
381
|
String treeIndex = node1.treeIndex();
|
382
|
TaxonNode node6 = taxonNodeService.load(node6Uuid);
|
383
|
treeIndex= node6.treeIndex();
|
384
|
|
385
|
HibernateProxyHelper.deproxy(node1, TaxonNode.class);
|
386
|
node1.deleteChildNode(node4, false);
|
387
|
TaxonNode node5 = taxonNodeService.load(node5Uuid);
|
388
|
treeIndex = node5.treeIndex();
|
389
|
|
390
|
node6 = taxonNodeService.load(node6Uuid);
|
391
|
|
392
|
treeIndex = node6.treeIndex();
|
393
|
Taxon newTaxon= Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
394
|
UUID taxonNewUuid = taxonService.save(newTaxon).getUuid();
|
395
|
|
396
|
node5.addChildTaxon(newTaxon, null, null);
|
397
|
String node5TreeIndex =node5.treeIndex();
|
398
|
taxonNodeService.saveOrUpdate(node5);
|
399
|
|
400
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
401
|
node5 = taxonNodeService.load(node5Uuid);
|
402
|
List<TaxonNode> children = node5.getChildNodes();
|
403
|
TaxonNode node = children.get(0);
|
404
|
int id = node.getId();
|
405
|
Assert.assertEquals("Node6 treeindex is not correct", "#t1#1#2#6#", treeIndex);
|
406
|
Assert.assertEquals("new node treeindex is not correct", node5TreeIndex + id +"#", node.treeIndex());
|
407
|
}
|
408
|
|
409
|
|
410
|
@Test
|
411
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
412
|
public final void testDeleteNode(){
|
413
|
classification = classificationService.load(classificationUuid);
|
414
|
node1 = taxonNodeService.load(node1Uuid);
|
415
|
node2 = taxonNodeService.load(rootNodeUuid);
|
416
|
node1 = HibernateProxyHelper.deproxy(node1);
|
417
|
|
418
|
TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), null, null);
|
419
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
420
|
newNode = taxonNodeService.load(uuidNewNode);
|
421
|
UUID taxUUID = newNode.getTaxon().getUuid();
|
422
|
UUID nameUUID = newNode.getTaxon().getName().getUuid();
|
423
|
|
424
|
DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
|
425
|
if (!result.isOk()){
|
426
|
Assert.fail();
|
427
|
}
|
428
|
newNode = taxonNodeService.load(uuidNewNode);
|
429
|
node1 = taxonNodeService.load(node1Uuid);
|
430
|
assertNull(newNode);
|
431
|
assertNull(node1);
|
432
|
|
433
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
434
|
assertNull(t1);
|
435
|
Taxon newTaxon = (Taxon)taxonService.load(taxUUID);
|
436
|
assertNull(newTaxon);
|
437
|
IBotanicalName name = nameService.load(nameUUID);
|
438
|
assertNull(name);
|
439
|
|
440
|
|
441
|
}
|
442
|
|
443
|
@Test
|
444
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
445
|
|
446
|
public final void testDeleteNodeWithReusedTaxon(){
|
447
|
classification = classificationService.load(classificationUuid);
|
448
|
node1 = taxonNodeService.load(node1Uuid);
|
449
|
node2 = taxonNodeService.load(rootNodeUuid);
|
450
|
node1 = HibernateProxyHelper.deproxy(node1);
|
451
|
|
452
|
|
453
|
Classification classification2 = Classification.NewInstance("Classification2");
|
454
|
TaxonNode nodeClassification2 =classification2.addChildTaxon(node1.getTaxon(), null, null);
|
455
|
assertEquals(node1.getTaxon().getUuid(), t1Uuid);
|
456
|
classificationService.save(classification2);
|
457
|
List<TaxonNode> nodesOfClassification2 = taxonNodeService.listAllNodesForClassification(classification2, null, null);
|
458
|
UUID nodeUUID = nodesOfClassification2.get(0).getUuid();
|
459
|
assertEquals(nodeUUID, nodeClassification2.getUuid());
|
460
|
Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
461
|
taxonService.save(newTaxon);
|
462
|
TaxonNode newNode = node1.addChildTaxon(newTaxon,null, null);
|
463
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
464
|
newNode = taxonNodeService.load(uuidNewNode);
|
465
|
UUID taxUUID = newNode.getTaxon().getUuid();
|
466
|
UUID nameUUID = newNode.getTaxon().getName().getUuid();
|
467
|
|
468
|
DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
|
469
|
if (!result.isOk()){
|
470
|
Assert.fail();
|
471
|
}
|
472
|
//taxonService.getSession().flush();
|
473
|
newNode = taxonNodeService.load(uuidNewNode);
|
474
|
node1 = taxonNodeService.load(node1Uuid);
|
475
|
assertNull(newNode);
|
476
|
assertNull(node1);
|
477
|
List<String> propertyPath = new ArrayList<>();
|
478
|
propertyPath.add("taxon.name.*");
|
479
|
nodeClassification2 =taxonNodeService.load(nodeUUID, propertyPath);
|
480
|
assertNotNull(nodeClassification2);
|
481
|
assertNotNull(nodeClassification2.getTaxon());
|
482
|
assertNotNull(nodeClassification2.getTaxon().getName());
|
483
|
|
484
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
485
|
assertNotNull(t1);
|
486
|
newTaxon = (Taxon)taxonService.load(taxUUID);
|
487
|
assertNull(newTaxon);
|
488
|
IBotanicalName name = nameService.load(nameUUID);
|
489
|
assertNull(name);
|
490
|
}
|
491
|
|
492
|
@Test
|
493
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
494
|
public final void testDeleteNodes(){
|
495
|
classification = classificationService.load(classificationUuid);
|
496
|
node1 = taxonNodeService.load(node1Uuid);
|
497
|
node2 = taxonNodeService.load(rootNodeUuid);
|
498
|
node1 = HibernateProxyHelper.deproxy(node1);
|
499
|
node2 = HibernateProxyHelper.deproxy(node2);
|
500
|
TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), null, null);
|
501
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
502
|
List<TaxonNode> treeNodes = new ArrayList<>();
|
503
|
treeNodes.add(node1);
|
504
|
treeNodes.add(node2);
|
505
|
|
506
|
taxonNodeService.deleteTaxonNodes(treeNodes, null);
|
507
|
|
508
|
newNode = taxonNodeService.load(uuidNewNode);
|
509
|
node1 = taxonNodeService.load(node1Uuid);
|
510
|
assertNull(newNode);
|
511
|
assertNull(node1);
|
512
|
//taxonService.getSession().flush();
|
513
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
514
|
assertNull(t1);
|
515
|
t2 = (Taxon) taxonService.load(t2Uuid);
|
516
|
assertNull(t2);
|
517
|
}
|
518
|
|
519
|
@Test
|
520
|
@DataSet
|
521
|
public void testMoveTaxonNode(){
|
522
|
classification = classificationService.load(classificationUuid);
|
523
|
// Set<TaxonNode> nodes = classification.getAllNodes();
|
524
|
List<TaxonNode> nodes = classification.getChildNodes();
|
525
|
System.out.println(nodes.size());
|
526
|
classification.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), nodes.size(), null, null);
|
527
|
nodes = classification.getChildNodes();
|
528
|
System.out.println(nodes.size());
|
529
|
}
|
530
|
|
531
|
@Test
|
532
|
public void testCompareNaturalOrder() {
|
533
|
/*
|
534
|
* Classification
|
535
|
* * Abies
|
536
|
* `- Abies alba
|
537
|
* - Abies balsamea
|
538
|
* * Pinus
|
539
|
* `- Pinus pampa
|
540
|
*/
|
541
|
Classification classification = Classification.NewInstance("Classification");
|
542
|
IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
543
|
abiesName.setGenusOrUninomial("Abies");
|
544
|
Taxon abies = Taxon.NewInstance(abiesName, null);
|
545
|
IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
546
|
abiesAlbaName.setGenusOrUninomial("Abies");
|
547
|
abiesAlbaName.setSpecificEpithet("alba");
|
548
|
Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
549
|
IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
550
|
pinusName.setGenusOrUninomial("Pinus");
|
551
|
Taxon pinus = Taxon.NewInstance(pinusName, null);
|
552
|
IBotanicalName pinusPampaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
553
|
pinusPampaName.setGenusOrUninomial("Pinus");
|
554
|
pinusPampaName.setSpecificEpithet("pampa");
|
555
|
Taxon pinusPampa = Taxon.NewInstance(pinusPampaName, null);
|
556
|
|
557
|
IBotanicalName abiesBalsameaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
558
|
abiesBalsameaName.setGenusOrUninomial("Abies");
|
559
|
abiesBalsameaName.setSpecificEpithet("balsamea");
|
560
|
Taxon abiesBalsamea = Taxon.NewInstance(abiesBalsameaName, null);
|
561
|
|
562
|
List<TaxonNode> nodes = new ArrayList<>();
|
563
|
nodes.add(classification.addChildTaxon(abies, null, null));
|
564
|
TaxonNode abiesAlbaNode = classification.addParentChild(abies, abiesAlba, null, null);
|
565
|
TaxonNode balsameaNode = classification.addParentChild(abies, abiesBalsamea, null, null);
|
566
|
nodes.add(balsameaNode);
|
567
|
nodes.add(abiesAlbaNode);
|
568
|
nodes.add(classification.addChildTaxon(pinus, null, null));
|
569
|
nodes.add(classification.addParentChild(pinus, pinusPampa, null, null));
|
570
|
this.taxonNodeService.save(nodes);
|
571
|
classificationService.saveClassification(classification);
|
572
|
commitAndStartNewTransaction();
|
573
|
|
574
|
classification = classificationDao.load(classification.getUuid());
|
575
|
TaxonNodeNaturalComparator comparator = new TaxonNodeNaturalComparator();
|
576
|
List<TaxonNode> allNodes = new ArrayList<>(classification.getAllNodes());
|
577
|
Collections.sort(allNodes, comparator);
|
578
|
|
579
|
Assert.assertEquals(allNodes.get(0).getTaxon(), abies );
|
580
|
Assert.assertEquals(allNodes.get(2).getTaxon(), abiesBalsamea );
|
581
|
Assert.assertEquals(allNodes.get(1).getTaxon(), abiesAlba );
|
582
|
|
583
|
taxonNodeService.moveTaxonNode(balsameaNode.getUuid(), abiesAlbaNode.getUuid(),1, SecReferenceHandlingEnum.KeepOrWarn, null);
|
584
|
commitAndStartNewTransaction();
|
585
|
|
586
|
classification = classificationService.load(classification.getUuid());
|
587
|
allNodes = new ArrayList<>(classification.getAllNodes());
|
588
|
Collections.sort(allNodes, comparator);
|
589
|
|
590
|
Assert.assertEquals(abies, allNodes.get(0).getTaxon());
|
591
|
Assert.assertEquals(abiesBalsamea, allNodes.get(1).getTaxon());
|
592
|
Assert.assertEquals(abiesAlba, allNodes.get(2).getTaxon());
|
593
|
}
|
594
|
|
595
|
@Test
|
596
|
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonNodeServiceImplTest.testGetUuidAndTitleCacheHierarchy.xml")
|
597
|
public void testGetUuidAndTitleCacheHierarchy(){
|
598
|
UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
|
599
|
UUID abiesUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
|
600
|
UUID abiesAlbaUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
|
601
|
UUID abiesAlbaSubBrotaUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
|
602
|
UUID abiesPalmaUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
|
603
|
UUID pinusUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
|
604
|
// /*
|
605
|
// * Checklist
|
606
|
// * - Abies
|
607
|
// * - Abies alba
|
608
|
// * - Abieas alba subs. brota
|
609
|
// * - Abies palma
|
610
|
// * -Pinus
|
611
|
// */
|
612
|
// Classification checklist = Classification.NewInstance("Checklist");
|
613
|
// checklist.setUuid(classificationUuid);
|
614
|
//
|
615
|
// BotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
616
|
// abiesName.setGenusOrUninomial("Abies");
|
617
|
// Taxon abies = Taxon.NewInstance(abiesName, null);
|
618
|
//
|
619
|
// BotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
620
|
// abiesAlbaName.setGenusOrUninomial("Abies");
|
621
|
// abiesAlbaName.setSpecificEpithet("alba");
|
622
|
// Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
623
|
//
|
624
|
// BotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
|
625
|
// abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
|
626
|
// abiesAlbaSubBrotaName.setSpecificEpithet("alba");
|
627
|
// abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
|
628
|
// Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
|
629
|
//
|
630
|
// BotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
631
|
// abiesPalmaName.setGenusOrUninomial("Abies");
|
632
|
// abiesPalmaName.setSpecificEpithet("palma");
|
633
|
// Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
|
634
|
//
|
635
|
// BotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
636
|
// pinusName.setGenusOrUninomial("Pinus");
|
637
|
// Taxon pinus = Taxon.NewInstance(pinusName, null);
|
638
|
//
|
639
|
// checklist.addParentChild(null, abies, null, null);
|
640
|
// checklist.addParentChild(abies, abiesAlba, null, null);
|
641
|
// checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
|
642
|
// checklist.addParentChild(abies, abiesPalma, null, null);
|
643
|
// checklist.addParentChild(null, pinus, null, null);
|
644
|
//
|
645
|
//
|
646
|
// setComplete();
|
647
|
// endTransaction();
|
648
|
//
|
649
|
// String fileNameAppendix = "testGetUuidAndTitleCacheHierarchy";
|
650
|
//
|
651
|
// writeDbUnitDataSetFile(new String[] {
|
652
|
// "TAXONBASE", "TAXONNAME",
|
653
|
// "TAXONRELATIONSHIP",
|
654
|
// "HOMOTYPICALGROUP",
|
655
|
// "CLASSIFICATION", "TAXONNODE",
|
656
|
// "HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
657
|
// },
|
658
|
// fileNameAppendix );
|
659
|
Classification classification = classificationService.load(classificationUuid);
|
660
|
|
661
|
List<TaxonNode> expectedChildTaxonNodes = classification.getChildNodes();
|
662
|
List<TaxonNodeDto> childNodesUuidAndTitleCache = taxonNodeService.listChildNodesAsTaxonNodeDto(classification.getRootNode());
|
663
|
assertNotNull("child UuidAndTitleCache list is null", childNodesUuidAndTitleCache);
|
664
|
|
665
|
compareChildren(expectedChildTaxonNodes, childNodesUuidAndTitleCache);
|
666
|
|
667
|
//test taxon parent of sub species
|
668
|
Taxon abiesAlbaSubBrota = HibernateProxyHelper.deproxy(taxonService.load(abiesAlbaSubBrotaUuid), Taxon.class);
|
669
|
TaxonNode abiesAlbaSubBrotaNode = abiesAlbaSubBrota.getTaxonNodes().iterator().next();
|
670
|
TaxonNode expectedTaxonParent = HibernateProxyHelper.deproxy(abiesAlbaSubBrotaNode.getParent(), TaxonNode.class);
|
671
|
TaxonNodeDto taxonParent = taxonNodeService.getParentUuidAndTitleCache(abiesAlbaSubBrotaNode);
|
672
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getUuid(), taxonParent.getUuid());
|
673
|
assertEquals("Taxon Nodes do not match. ", (Integer)expectedTaxonParent.getId(), taxonParent.getId());
|
674
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getTaxon().getTitleCache(), taxonParent.getTitleCache());
|
675
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent, taxonNodeService.load(taxonParent.getUuid()));
|
676
|
|
677
|
//test classification parent
|
678
|
Taxon abies = HibernateProxyHelper.deproxy(taxonService.load(abiesUuid), Taxon.class);
|
679
|
TaxonNode abiesNode = abies.getTaxonNodes().iterator().next();
|
680
|
TaxonNode expectedClassificationParent = HibernateProxyHelper.deproxy(abiesNode.getParent(), TaxonNode.class);
|
681
|
TaxonNodeDto classificationParent= taxonNodeService.getParentUuidAndTitleCache(abiesNode);
|
682
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getUuid(), classificationParent.getUuid());
|
683
|
assertEquals("Taxon Nodes do not match. ", (Integer)expectedClassificationParent.getId(), classificationParent.getId());
|
684
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getClassification().getTitleCache(), classificationParent.getTitleCache());
|
685
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent, taxonNodeService.load(classificationParent.getUuid()));
|
686
|
}
|
687
|
|
688
|
private void compareChildren(List<TaxonNode> expectedChildTaxonNodes, List<TaxonNodeDto> childNodesDto){
|
689
|
assertEquals("Number of children does not match", expectedChildTaxonNodes.size(), childNodesDto.size());
|
690
|
TaxonNodeDto foundMatch = null;
|
691
|
for (TaxonNode taxonNode : expectedChildTaxonNodes) {
|
692
|
foundMatch = null;
|
693
|
for (TaxonNodeDto uuidAndTitleCache : childNodesDto) {
|
694
|
if(uuidAndTitleCache.getUuid().equals(taxonNode.getUuid())){
|
695
|
Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
|
696
|
String titleCache = taxon.getTitleCache();
|
697
|
if(uuidAndTitleCache.getTaxonTitleCache().equals(titleCache)){
|
698
|
foundMatch = uuidAndTitleCache;
|
699
|
break;
|
700
|
}
|
701
|
}
|
702
|
}
|
703
|
assertTrue(String.format("no matching UuidAndTitleCache found for child %s", taxonNode), foundMatch!=null);
|
704
|
compareChildren(taxonNode.getChildNodes(), taxonNodeService.listChildNodesAsTaxonNodeDto(foundMatch));
|
705
|
}
|
706
|
}
|
707
|
//
|
708
|
// private UuidAndTitleCache<TaxonNode> findMatchingUuidAndTitleCache(List<UuidAndTitleCache<TaxonNode>> childNodesUuidAndTitleCache,
|
709
|
// UuidAndTitleCache<TaxonNode> foundMatch, TaxonNode taxonNode) {
|
710
|
// for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : childNodesUuidAndTitleCache) {
|
711
|
// if(uuidAndTitleCache.getUuid().equals(taxonNode.getUuid())){
|
712
|
// String titleCache = taxonNode.getTaxon().getTitleCache();
|
713
|
// if(uuidAndTitleCache.getTitleCache().equals(titleCache)){
|
714
|
// foundMatch = uuidAndTitleCache;
|
715
|
// break;
|
716
|
// }
|
717
|
// }
|
718
|
// }
|
719
|
// return foundMatch;
|
720
|
// }
|
721
|
|
722
|
@Test
|
723
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
724
|
public void testSetSecundumForSubtree(){
|
725
|
Reference newSec = referenceService.find(uuidRefNewSec);
|
726
|
Reference refSpPl = referenceService.find(referenceUuid);
|
727
|
|
728
|
//assert current state
|
729
|
Assert.assertNotNull(newSec);
|
730
|
Assert.assertNull(taxonService.find(1).getSec());
|
731
|
Assert.assertNull(taxonService.find(2).getSec());
|
732
|
Assert.assertNull(taxonService.find(3).getSec());
|
733
|
Assert.assertNull(taxonService.find(4).getSec());
|
734
|
Taxon taxon5 = (Taxon)taxonService.find(5);
|
735
|
Assert.assertNotNull(taxon5.getSec());
|
736
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
737
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
738
|
Assert.assertEquals(1, taxon5.getMisappliedNameRelations().size());
|
739
|
Assert.assertEquals(refSpPl, taxon5.getMisappliedNameRelations().iterator().next().getSource().getCitation());
|
740
|
Assert.assertEquals(1, taxon5.getProParteAndPartialSynonymRelations().size());
|
741
|
Assert.assertNull(taxon5.getProParteAndPartialSynonymRelations().iterator().next().getSource());
|
742
|
|
743
|
//set secundum
|
744
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(node1Uuid, null, null, true);
|
745
|
config.setIncludeMisapplications(true);
|
746
|
config.setIncludeProParteSynonyms(true);
|
747
|
config.setNewSecundum(newSec);
|
748
|
UpdateResult result = taxonNodeService.setSecundumForSubtree(config);
|
749
|
Assert.assertTrue(result.getExceptions().isEmpty());
|
750
|
Assert.assertTrue(result.isOk());
|
751
|
Assert.assertEquals(6, result.getUpdatedObjects().size()); //should be 5 without workaround for #9627,#6359
|
752
|
|
753
|
commitAndStartNewTransaction(/*new String[]{"TaxonBase","TaxonBase_AUD"}*/);
|
754
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
755
|
Assert.assertNull(taxonService.find(2).getSec());
|
756
|
Assert.assertEquals(newSec, taxonService.find(3).getSec());
|
757
|
Assert.assertNull(taxonService.find(4).getSec());
|
758
|
taxon5 = (Taxon)taxonService.find(5);
|
759
|
Assert.assertEquals(newSec, taxon5.getSec());
|
760
|
Assert.assertNull(taxon5.getSecMicroReference());
|
761
|
Assert.assertEquals(newSec, taxon5.getMisappliedNameRelations().iterator().next().getSource().getCitation());
|
762
|
Assert.assertEquals(newSec, taxon5.getProParteAndPartialSynonymRelations().iterator().next().getSource().getCitation());
|
763
|
Taxon taxon2 = (Taxon)taxonService.find(2);
|
764
|
Assert.assertEquals(1, taxon2.getProParteAndPartialSynonymRelations().size());
|
765
|
Assert.assertNull(taxon2.getProParteAndPartialSynonymRelations().iterator().next().getSource());
|
766
|
|
767
|
result = taxonNodeService.setSecundumForSubtree(config);
|
768
|
Assert.assertTrue(result.getExceptions().isEmpty() && result.isOk());
|
769
|
Assert.assertEquals(0, result.getUpdatedObjects().size());
|
770
|
|
771
|
}
|
772
|
|
773
|
@Test
|
774
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
775
|
public void testSetSecundumForSubtreeNoOverwrite(){
|
776
|
Reference newSec = referenceService.find(uuidRefNewSec);
|
777
|
Reference refSpPl = referenceService.find(referenceUuid);
|
778
|
|
779
|
//assert current state
|
780
|
Assert.assertNotNull(newSec);
|
781
|
Assert.assertNull(taxonService.find(1).getSec());
|
782
|
Assert.assertNull(taxonService.find(2).getSec());
|
783
|
Assert.assertNull(taxonService.find(3).getSec());
|
784
|
Assert.assertNull(taxonService.find(4).getSec());
|
785
|
Taxon taxon5 = (Taxon)taxonService.find(5);
|
786
|
Assert.assertNotNull(taxon5.getSec());
|
787
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
788
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
789
|
Assert.assertEquals(1, taxon5.getMisappliedNameRelations().size());
|
790
|
Assert.assertEquals(refSpPl, taxon5.getMisappliedNameRelations().iterator().next().getSource().getCitation());
|
791
|
Assert.assertEquals(1, taxon5.getProParteAndPartialSynonymRelations().size());
|
792
|
Assert.assertNull(taxon5.getProParteAndPartialSynonymRelations().iterator().next().getSource());
|
793
|
|
794
|
//set secundum
|
795
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(node1Uuid, newSec, null, true);
|
796
|
config.setOverwriteExisting(false);
|
797
|
UpdateResult result = taxonNodeService.setSecundumForSubtree(config);
|
798
|
Assert.assertTrue(result.getExceptions().isEmpty());
|
799
|
Assert.assertTrue(result.isOk());
|
800
|
Assert.assertEquals(4, result.getUpdatedObjects().size()); //should be 3 without workaround for #9627,#6359
|
801
|
|
802
|
commitAndStartNewTransaction(); //new String[]{"TaxonBase","TaxonBase_AUD"}
|
803
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
804
|
Assert.assertNull(taxonService.find(2).getSec());
|
805
|
Assert.assertEquals(newSec, taxonService.find(3).getSec());
|
806
|
Assert.assertNull(taxonService.find(4).getSec());
|
807
|
Reference oldTaxon5Sec = taxon5.getSec();
|
808
|
taxon5 = (Taxon)taxonService.find(5);
|
809
|
Assert.assertEquals(oldTaxon5Sec, taxon5.getSec());
|
810
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
811
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
812
|
Assert.assertEquals("Should not override MAN source", refSpPl, taxon5.getMisappliedNameRelations().iterator().next().getSource().getCitation());
|
813
|
Assert.assertEquals(newSec, taxon5.getProParteAndPartialSynonymRelations().iterator().next().getSource().getCitation());
|
814
|
Taxon taxon2 = (Taxon)taxonService.find(2);
|
815
|
Assert.assertEquals("taxon2 is not part of subtree therefore should not be updated", 1, taxon2.getProParteAndPartialSynonymRelations().size());
|
816
|
Assert.assertNull(taxon2.getProParteAndPartialSynonymRelations().iterator().next().getSource());
|
817
|
}
|
818
|
|
819
|
@Test
|
820
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
821
|
public void testSetSecundumForSubtreeOnlyAccepted(){
|
822
|
Reference newSec = referenceService.find(uuidRefNewSec);
|
823
|
|
824
|
//assert current state
|
825
|
Assert.assertNotNull(newSec);
|
826
|
Assert.assertNull(taxonService.find(1).getSec());
|
827
|
Assert.assertNull(taxonService.find(2).getSec());
|
828
|
Assert.assertNull(taxonService.find(3).getSec());
|
829
|
Assert.assertNull(taxonService.find(4).getSec());
|
830
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
831
|
Assert.assertNotNull(taxon5.getSec());
|
832
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
833
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
834
|
|
835
|
//set secundum
|
836
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(node1Uuid, newSec, null, false);
|
837
|
config.setIncludeSynonyms(false);
|
838
|
taxonNodeService.setSecundumForSubtree(config);
|
839
|
|
840
|
// commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
841
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
842
|
Assert.assertNull(taxonService.find(2).getSec());
|
843
|
Assert.assertNull(taxonService.find(3).getSec());
|
844
|
Assert.assertNull(taxonService.find(4).getSec());
|
845
|
taxon5 = taxonService.find(5);
|
846
|
Assert.assertEquals(newSec, taxon5.getSec());
|
847
|
Assert.assertNull(taxon5.getSecMicroReference());
|
848
|
}
|
849
|
|
850
|
@Test
|
851
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
852
|
public void testSetSecundumForSubtreeOnlySynonyms(){
|
853
|
Reference newSec = referenceService.find(uuidRefNewSec);
|
854
|
|
855
|
//assert current state
|
856
|
Assert.assertNotNull(newSec);
|
857
|
Assert.assertNull(taxonService.find(1).getSec());
|
858
|
Assert.assertNull(taxonService.find(2).getSec());
|
859
|
Assert.assertNull(taxonService.find(3).getSec());
|
860
|
Assert.assertNull(taxonService.find(4).getSec());
|
861
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
862
|
Assert.assertNotNull(taxon5.getSec());
|
863
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
864
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
865
|
|
866
|
//set secundum
|
867
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(node1Uuid, newSec, null, false);
|
868
|
config.setIncludeAcceptedTaxa(false);
|
869
|
taxonNodeService.setSecundumForSubtree(config);
|
870
|
|
871
|
commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
872
|
Assert.assertNull(taxonService.find(1).getSec());
|
873
|
Assert.assertNull(taxonService.find(2).getSec());
|
874
|
Assert.assertEquals("Synonym should be updated", newSec, taxonService.find(3).getSec());
|
875
|
Assert.assertNull(taxonService.find(4).getSec());
|
876
|
Reference oldTaxon5Sec = taxon5.getSec();
|
877
|
taxon5 = taxonService.find(5);
|
878
|
Assert.assertEquals(oldTaxon5Sec, taxon5.getSec());
|
879
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
880
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
881
|
}
|
882
|
|
883
|
@Test
|
884
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
885
|
public void testSetSecundumForSubtreeNoShared(){
|
886
|
Reference newSec = referenceService.find(uuidRefNewSec);
|
887
|
|
888
|
//assert current state
|
889
|
Assert.assertNotNull(newSec);
|
890
|
Assert.assertNull(taxonService.find(1).getSec());
|
891
|
Assert.assertNull(taxonService.find(2).getSec());
|
892
|
Assert.assertNull(taxonService.find(3).getSec());
|
893
|
Assert.assertNull(taxonService.find(4).getSec());
|
894
|
Taxon taxon5 = (Taxon)taxonService.find(5);
|
895
|
Assert.assertNotNull(taxon5.getSec());
|
896
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
897
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
898
|
Taxon taxon1 = (Taxon)taxonService.find(1);
|
899
|
taxon1.addMisappliedName(taxon5, null, null);
|
900
|
Assert.assertEquals(1, taxon1.getMisappliedNameRelations().size());
|
901
|
commitAndStartNewTransaction();
|
902
|
|
903
|
//set secundum
|
904
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(node1Uuid, newSec, null, true);
|
905
|
config.setIncludeSharedTaxa(false);
|
906
|
taxonNodeService.setSecundumForSubtree(config);
|
907
|
|
908
|
commitAndStartNewTransaction(); //new String[]{"TaxonBase","TaxonBase_AUD"}
|
909
|
taxon1 = (Taxon)taxonService.find(1);
|
910
|
Assert.assertNull("Shared taxon must not be set", taxonService.find(1).getSec());
|
911
|
Assert.assertNull(taxonService.find(2).getSec());
|
912
|
Assert.assertNull("Synonym of shared taxon must not be set", taxonService.find(3).getSec());
|
913
|
Assert.assertNull(taxonService.find(4).getSec());
|
914
|
taxon5 = (Taxon)taxonService.find(5);
|
915
|
Assert.assertEquals(newSec, taxon5.getSec());
|
916
|
Assert.assertNull(taxon5.getSecMicroReference());
|
917
|
Assert.assertNull("without share no citation should be set", taxon1.getMisappliedNameRelations().iterator().next().getSource());
|
918
|
config.setIncludeSharedTaxa(true);
|
919
|
taxonNodeService.setSecundumForSubtree(config);
|
920
|
taxon1 = (Taxon)taxonService.find(1);
|
921
|
Assert.assertEquals("With shared taxa citation should be set", newSec, taxon1.getMisappliedNameRelations().iterator().next().getSource().getCitation());
|
922
|
}
|
923
|
|
924
|
@Test
|
925
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
926
|
public void testSetPublishForSubtree(){
|
927
|
|
928
|
assertStartingStateForSetPublish();
|
929
|
|
930
|
boolean publish = false;
|
931
|
PublishForSubtreeConfigurator config = PublishForSubtreeConfigurator.NewInstance(
|
932
|
node1Uuid, publish, null);
|
933
|
config.setIncludeAcceptedTaxa(true);
|
934
|
config.setIncludeSynonyms(true);
|
935
|
config.setIncludeSharedTaxa(true);
|
936
|
config.setIncludeHybrids(false);
|
937
|
taxonNodeService.setPublishForSubtree(config);
|
938
|
|
939
|
commitAndStartNewTransaction();
|
940
|
|
941
|
Assert.assertEquals(publish, taxonService.find(1).isPublish());
|
942
|
Assert.assertEquals("Taxon2 is not in subtree", true, taxonService.find(2).isPublish());
|
943
|
Assert.assertEquals("Synonym3 not yet updated because it is hybrid", true, taxonService.find(3).isPublish());
|
944
|
Assert.assertEquals("Synonym4 is not in subtree", true, taxonService.find(4).isPublish());
|
945
|
Assert.assertEquals(true, taxonService.find(5).isPublish());
|
946
|
Assert.assertEquals(publish, taxonService.find(6).isPublish());
|
947
|
Assert.assertEquals("Synonym7 is not in subtree", true, taxonService.find(7).isPublish());
|
948
|
|
949
|
config.setIncludeHybrids(true);
|
950
|
taxonNodeService.setPublishForSubtree(config);
|
951
|
|
952
|
commitAndStartNewTransaction();
|
953
|
Assert.assertEquals(publish, taxonService.find(3).isPublish());
|
954
|
Assert.assertEquals(publish, taxonService.find(5).isPublish());
|
955
|
Assert.assertEquals(publish, taxonService.find(7).isPublish());
|
956
|
|
957
|
}
|
958
|
|
959
|
@Test
|
960
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
961
|
public void testSetPublishForSubtreeOnlyAccepted(){
|
962
|
|
963
|
assertStartingStateForSetPublish();
|
964
|
|
965
|
boolean publish = false;
|
966
|
PublishForSubtreeConfigurator config = PublishForSubtreeConfigurator.NewInstance(node1Uuid, publish, null);
|
967
|
config.setIncludeAcceptedTaxa(true);
|
968
|
config.setIncludeSynonyms(false);
|
969
|
config.setIncludeMisapplications(false);
|
970
|
config.setIncludeProParteSynonyms(false);
|
971
|
config.setIncludeSharedTaxa(true);
|
972
|
taxonNodeService.setPublishForSubtree(config);
|
973
|
|
974
|
|
975
|
commitAndStartNewTransaction();
|
976
|
Assert.assertEquals(publish, taxonService.find(1).isPublish());
|
977
|
Assert.assertEquals("Taxon2 not in subtree", true, taxonService.find(2).isPublish());
|
978
|
Assert.assertEquals("Synonym3 should not be updated", true, taxonService.find(3).isPublish());
|
979
|
Assert.assertEquals("Synonym3 should not be updated", true, taxonService.find(4).isPublish());
|
980
|
Assert.assertEquals("Accepted in subtree should be udpated", publish, taxonService.find(5).isPublish());
|
981
|
Assert.assertEquals("Misapplied should not be updated", true, taxonService.find(6).isPublish());
|
982
|
Assert.assertEquals("Pro parte synonym should not be updated", true, taxonService.find(7).isPublish());
|
983
|
|
984
|
config.setIncludeMisapplications(true);
|
985
|
taxonNodeService.setPublishForSubtree(config);
|
986
|
commitAndStartNewTransaction();
|
987
|
Assert.assertEquals("Misapplied should be updated now", publish, taxonService.find(6).isPublish());
|
988
|
Assert.assertEquals("Pro parte synonym should not yet be updated", true, taxonService.find(7).isPublish());
|
989
|
|
990
|
config.setIncludeProParteSynonyms(true);
|
991
|
config.setIncludeHybrids(false);
|
992
|
taxonNodeService.setPublishForSubtree(config);
|
993
|
commitAndStartNewTransaction();
|
994
|
Assert.assertEquals("Pro parte synonym should not yet be updated because it is a hybrid", true, taxonService.find(7).isPublish());
|
995
|
|
996
|
config.setIncludeHybrids(true);
|
997
|
taxonNodeService.setPublishForSubtree(config);
|
998
|
commitAndStartNewTransaction();
|
999
|
Assert.assertEquals("Pro parte synonym should be updated now", publish, taxonService.find(7).isPublish());
|
1000
|
|
1001
|
}
|
1002
|
|
1003
|
@Test
|
1004
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
1005
|
public void testSetPublishForSubtreeOnlySynonyms(){
|
1006
|
|
1007
|
//assert current state
|
1008
|
assertStartingStateForSetPublish();
|
1009
|
|
1010
|
boolean publish = false;
|
1011
|
|
1012
|
PublishForSubtreeConfigurator config = PublishForSubtreeConfigurator.NewInstance(
|
1013
|
node1Uuid, publish, null);
|
1014
|
config.setIncludeAcceptedTaxa(false);
|
1015
|
config.setIncludeSynonyms(true);
|
1016
|
config.setIncludeSharedTaxa(true); //should have no effect
|
1017
|
config.setIncludeMisapplications(false);
|
1018
|
config.setIncludeProParteSynonyms(false);
|
1019
|
taxonNodeService.setPublishForSubtree(config);
|
1020
|
|
1021
|
commitAndStartNewTransaction(new String[]{});
|
1022
|
Assert.assertEquals(true, taxonService.find(1).isPublish());
|
1023
|
Assert.assertEquals(true, taxonService.find(2).isPublish());
|
1024
|
//Synonym should be false
|
1025
|
Assert.assertEquals(publish, taxonService.find(3).isPublish());
|
1026
|
Assert.assertEquals(true, taxonService.find(4).isPublish());
|
1027
|
Assert.assertEquals(true, taxonService.find(5).isPublish());
|
1028
|
Assert.assertEquals(true, taxonService.find(6).isPublish());
|
1029
|
Assert.assertEquals(true, taxonService.find(7).isPublish());
|
1030
|
|
1031
|
config.setIncludeMisapplications(true);
|
1032
|
taxonNodeService.setPublishForSubtree(config);
|
1033
|
commitAndStartNewTransaction();
|
1034
|
Assert.assertEquals("Misapplied should be updated now", publish, taxonService.find(6).isPublish());
|
1035
|
Assert.assertEquals("Pro parte synonym should not yet be updated", true, taxonService.find(7).isPublish());
|
1036
|
|
1037
|
config.setIncludeProParteSynonyms(true);
|
1038
|
taxonNodeService.setPublishForSubtree(config);
|
1039
|
commitAndStartNewTransaction();
|
1040
|
Assert.assertEquals("Pro parte synonym should be updated now", publish, taxonService.find(7).isPublish());
|
1041
|
|
1042
|
}
|
1043
|
|
1044
|
private void assertStartingStateForSetPublish() {
|
1045
|
Assert.assertTrue(taxonService.find(1).isPublish());
|
1046
|
Assert.assertTrue(taxonService.find(2).isPublish());
|
1047
|
Assert.assertTrue(taxonService.find(3).isPublish());
|
1048
|
Assert.assertTrue(taxonService.find(4).isPublish());
|
1049
|
Assert.assertTrue(taxonService.find(5).isPublish());
|
1050
|
Assert.assertTrue(taxonService.find(6).isPublish());
|
1051
|
Assert.assertTrue(taxonService.find(7).isPublish());
|
1052
|
}
|
1053
|
|
1054
|
|
1055
|
@Test
|
1056
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
1057
|
public void testSetPublishForSubtreeNoShared(){
|
1058
|
|
1059
|
assertStartingStateForSetPublish();
|
1060
|
|
1061
|
boolean publish = false;
|
1062
|
PublishForSubtreeConfigurator config = PublishForSubtreeConfigurator.NewInstance(
|
1063
|
node1Uuid, publish, null);
|
1064
|
config.setIncludeAcceptedTaxa(true);
|
1065
|
config.setIncludeSynonyms(true);
|
1066
|
config.setIncludeSharedTaxa(false);
|
1067
|
taxonNodeService.setPublishForSubtree(config);
|
1068
|
|
1069
|
commitAndStartNewTransaction();
|
1070
|
Assert.assertEquals("Shared taxon must not be set", true, taxonService.find(1).isPublish());
|
1071
|
Assert.assertEquals("Taxon2 is not in subtree", true, taxonService.find(2).isPublish());
|
1072
|
Assert.assertEquals("Synonym of shared taxon must not be set", true, taxonService.find(3).isPublish());
|
1073
|
Assert.assertEquals("Synonym4 belongs to Taxon2 which is not in subtree", true, taxonService.find(4).isPublish());
|
1074
|
Assert.assertEquals("Taxon5 is in subtree and not shared => should be set to unpublished", publish, taxonService.find(5).isPublish());
|
1075
|
Assert.assertEquals("Misapplied exists as taxon in classification 2 and should not be updated"
|
1076
|
+ " though related to taxon 5 which is updated", true, taxonService.find(6).isPublish());
|
1077
|
Assert.assertEquals("Pro parte synonym7 should not be updated, as it is "
|
1078
|
+ "related to updated taxon5 but also to taxon2 which is not updated because not in subtree",
|
1079
|
true, taxonService.find(7).isPublish());
|
1080
|
|
1081
|
taxonService.find(2).setPublish(false);
|
1082
|
taxonNodeService.setPublishForSubtree(config);
|
1083
|
commitAndStartNewTransaction();
|
1084
|
Assert.assertEquals("Pro parte synonym7 should be updated now, as taxon2 is now unpublished"
|
1085
|
+ " and therefore the noShared function is not relevant anymore",
|
1086
|
publish, taxonService.find(7).isPublish());
|
1087
|
}
|
1088
|
|
1089
|
|
1090
|
@Test
|
1091
|
@DataSet("TaxonNodeServiceImplTest.xml")
|
1092
|
public void testGetTaxonDistributionDTO(){
|
1093
|
List<UUID> uuidList = Arrays.asList(node1Uuid, node2Uuid, node4Uuid);
|
1094
|
List<TaxonDistributionDTO> dtos = this.taxonNodeService.getTaxonDistributionDTO(uuidList, null, true);
|
1095
|
Assert.assertEquals("Children should be deduplicated", 3, dtos.size());
|
1096
|
//note: the following ordering is not given by definition (as the method does not guarantee a certain order)
|
1097
|
// but is used as pseudo test here for the correctnes of the algorithm as it is currently expected
|
1098
|
Assert.assertEquals("First node comes first", node1Uuid, dtos.get(0).getTaxonNodeDto().getUuid());
|
1099
|
Assert.assertEquals("Child of first node comes second", node4Uuid, dtos.get(1).getTaxonNodeDto().getUuid());
|
1100
|
Assert.assertEquals("Second node comes third", node2Uuid, dtos.get(2).getTaxonNodeDto().getUuid());
|
1101
|
//third node is child of firt node and therefore came second already
|
1102
|
}
|
1103
|
|
1104
|
@Test
|
1105
|
@DataSet("TaxonNodeServiceImplTest-testFindCommonParentNode.xml")
|
1106
|
public void testFindCommonParentNode(){
|
1107
|
UUID checklist2Uuid = UUID.fromString("c6e3a598-3b6c-4ef5-8b01-5bdb3de5a9fd");
|
1108
|
UUID campanulaNodeUuid = UUID.fromString("62fa918d-a1d8-4284-ae4b-93478bde8656");
|
1109
|
UUID campanulaPersicifoliaNodeUuid = UUID.fromString("dce3defa-5123-44a7-8008-0cc9b27461f6");
|
1110
|
|
1111
|
UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
|
1112
|
UUID abiesNodeUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
|
1113
|
UUID abiesAlbaNodeUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
|
1114
|
UUID abiesAlbaSubBrotaNodeUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
|
1115
|
UUID abiesPalmaNodeUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
|
1116
|
|
1117
|
UUID pinusNodeUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
|
1118
|
|
1119
|
// /*
|
1120
|
// * Checklist2
|
1121
|
// * - Campanula
|
1122
|
// * - Campanula persicifolia
|
1123
|
// * Checklist
|
1124
|
// * - Abies
|
1125
|
// * - Abies alba
|
1126
|
// * - Abieas alba subs. brota
|
1127
|
// * - Abies palma
|
1128
|
// * -Pinus
|
1129
|
// */
|
1130
|
// Classification checklist2 = Classification.NewInstance("Checklist2");
|
1131
|
// checklist2.setUuid(checklist2Uuid);
|
1132
|
//
|
1133
|
// IBotanicalName campanulaName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1134
|
// campanulaName.setGenusOrUninomial("Campanula");
|
1135
|
// Taxon campanula = Taxon.NewInstance(campanulaName, null);
|
1136
|
//
|
1137
|
// IBotanicalName campanulaPersicifoliaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1138
|
// campanulaPersicifoliaName.setGenusOrUninomial("Campanula");
|
1139
|
// campanulaPersicifoliaName.setSpecificEpithet("persicifolia");
|
1140
|
// Taxon campanulaPersicifolia = Taxon.NewInstance(campanulaPersicifoliaName, null);
|
1141
|
//
|
1142
|
// TaxonNode campanulaNode = checklist2.addChildTaxon(campanula, null, null);
|
1143
|
// campanulaNode.setUuid(campanulaNodeUuid);
|
1144
|
// TaxonNode campanulaPersicifoliaNode = checklist2.addParentChild(campanula, campanulaPersicifolia, null, null);
|
1145
|
// campanulaPersicifoliaNode.setUuid(campanulaPersicifoliaNodeUuid);
|
1146
|
//
|
1147
|
// Classification checklist = Classification.NewInstance("Checklist");
|
1148
|
// checklist.setUuid(classificationUuid);
|
1149
|
//
|
1150
|
// IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1151
|
// abiesName.setGenusOrUninomial("Abies");
|
1152
|
// Taxon abies = Taxon.NewInstance(abiesName, null);
|
1153
|
//
|
1154
|
// IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1155
|
// abiesAlbaName.setGenusOrUninomial("Abies");
|
1156
|
// abiesAlbaName.setSpecificEpithet("alba");
|
1157
|
// Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
1158
|
//
|
1159
|
// IBotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
|
1160
|
// abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
|
1161
|
// abiesAlbaSubBrotaName.setSpecificEpithet("alba");
|
1162
|
// abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
|
1163
|
// Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
|
1164
|
//
|
1165
|
// IBotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1166
|
// abiesPalmaName.setGenusOrUninomial("Abies");
|
1167
|
// abiesPalmaName.setSpecificEpithet("palma");
|
1168
|
// Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
|
1169
|
//
|
1170
|
// IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1171
|
// pinusName.setGenusOrUninomial("Pinus");
|
1172
|
// Taxon pinus = Taxon.NewInstance(pinusName, null);
|
1173
|
//
|
1174
|
// TaxonNode abiesNode = checklist.addChildTaxon(abies, null, null);
|
1175
|
// abiesNode.setUuid(abiesNodeUuid);
|
1176
|
// TaxonNode abiesAlbaNode = checklist.addParentChild(abies, abiesAlba, null, null);
|
1177
|
// abiesAlbaNode.setUuid(abiesAlbaNodeUuid);
|
1178
|
// TaxonNode abiesAlbaSubBrotaNode = checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
|
1179
|
// abiesAlbaSubBrotaNode.setUuid(abiesAlbaSubBrotaNodeUuid);
|
1180
|
// TaxonNode abiesPalmaNode = checklist.addParentChild(abies, abiesPalma, null, null);
|
1181
|
// abiesPalmaNode.setUuid(abiesPalmaNodeUuid);
|
1182
|
// TaxonNode pinusNode = checklist.addChildTaxon(pinus, null, null);
|
1183
|
// pinusNode.setUuid(pinusNodeUuid);
|
1184
|
//
|
1185
|
// taxonService.saveOrUpdate(campanula);
|
1186
|
// taxonService.saveOrUpdate(campanulaPersicifolia);
|
1187
|
// classificationService.saveOrUpdate(checklist2);
|
1188
|
//
|
1189
|
// taxonService.saveOrUpdate(abies);
|
1190
|
// taxonService.saveOrUpdate(abiesAlba);
|
1191
|
// taxonService.saveOrUpdate(abiesAlbaSubBrota);
|
1192
|
// taxonService.saveOrUpdate(abiesPalma);
|
1193
|
// taxonService.saveOrUpdate(pinus);
|
1194
|
// classificationService.saveOrUpdate(checklist);
|
1195
|
//
|
1196
|
//
|
1197
|
// setComplete();
|
1198
|
// endTransaction();
|
1199
|
//
|
1200
|
// String fileNameAppendix = "testFindCommonParentNode";
|
1201
|
//
|
1202
|
// writeDbUnitDataSetFile(new String[] {
|
1203
|
// "TAXONBASE", "TAXONNAME",
|
1204
|
// "TAXONRELATIONSHIP",
|
1205
|
// "HOMOTYPICALGROUP",
|
1206
|
// "CLASSIFICATION", "TAXONNODE",
|
1207
|
// "LANGUAGESTRING",
|
1208
|
// "HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
1209
|
// },
|
1210
|
// fileNameAppendix );
|
1211
|
|
1212
|
Classification classification = classificationService.load(classificationUuid);
|
1213
|
|
1214
|
TaxonNode campanula = taxonNodeService.load(campanulaNodeUuid);
|
1215
|
TaxonNode campanulaPersicifolia = taxonNodeService.load(campanulaPersicifoliaNodeUuid);
|
1216
|
TaxonNode abies = taxonNodeService.load(abiesNodeUuid);
|
1217
|
TaxonNode abiesAlba = taxonNodeService.load(abiesAlbaNodeUuid);
|
1218
|
TaxonNode abiesPalma = taxonNodeService.load(abiesPalmaNodeUuid);
|
1219
|
TaxonNode pinus = taxonNodeService.load(pinusNodeUuid);
|
1220
|
|
1221
|
//check initial state
|
1222
|
assertTrue(campanula!=null);
|
1223
|
assertTrue(campanulaPersicifolia!=null);
|
1224
|
assertTrue(abies!=null);
|
1225
|
assertTrue(abiesAlba!=null);
|
1226
|
assertTrue(abiesPalma!=null);
|
1227
|
assertTrue(pinus!=null);
|
1228
|
|
1229
|
TaxonNodeDto classificationRootNodeDto = new TaxonNodeDto(classification.getRootNode());
|
1230
|
TaxonNodeDto campanulaDto = new TaxonNodeDto(campanula);
|
1231
|
TaxonNodeDto campanulaPersicifoliaDto = new TaxonNodeDto(campanulaPersicifolia);
|
1232
|
TaxonNodeDto abiesDto = new TaxonNodeDto(abies);
|
1233
|
TaxonNodeDto abiesAlbaDto = new TaxonNodeDto(abiesAlba);
|
1234
|
TaxonNodeDto abiesPalmaDto = new TaxonNodeDto(abiesPalma);
|
1235
|
TaxonNodeDto pinusDto = new TaxonNodeDto(pinus);
|
1236
|
|
1237
|
List<TaxonNodeDto> nodes = new ArrayList<>();
|
1238
|
nodes.add(campanulaDto);
|
1239
|
TaxonNodeDto commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
|
1240
|
assertEquals(campanulaDto.getUuid(), commonParentNodeDto.getUuid());
|
1241
|
|
1242
|
nodes = new ArrayList<>();
|
1243
|
nodes.add(campanulaDto);
|
1244
|
nodes.add(campanulaPersicifoliaDto);
|
1245
|
commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
|
1246
|
assertEquals(campanulaDto.getUuid(), commonParentNodeDto.getUuid());
|
1247
|
|
1248
|
nodes = new ArrayList<>();
|
1249
|
nodes.add(campanulaDto);
|
1250
|
nodes.add(abiesAlbaDto);
|
1251
|
commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
|
1252
|
assertNull(commonParentNodeDto);
|
1253
|
|
1254
|
nodes = new ArrayList<>();
|
1255
|
nodes.add(abiesAlbaDto);
|
1256
|
nodes.add(abiesPalmaDto);
|
1257
|
commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
|
1258
|
assertEquals(abiesDto.getUuid(), commonParentNodeDto.getUuid());
|
1259
|
|
1260
|
nodes = new ArrayList<>();
|
1261
|
nodes.add(abiesDto);
|
1262
|
nodes.add(pinusDto);
|
1263
|
commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
|
1264
|
assertEquals(classificationRootNodeDto.getUuid(), commonParentNodeDto.getUuid());
|
1265
|
}
|
1266
|
|
1267
|
@Test
|
1268
|
@DataSet("ClassificationServiceImplTest.xml")
|
1269
|
public final void testCloneClassification(){
|
1270
|
|
1271
|
Classification originalClassification = classificationDao.load(ClassificationServiceImplTest.CLASSIFICATION_UUID);
|
1272
|
|
1273
|
SubtreeCloneConfigurator config = SubtreeCloneConfigurator.NewBaseInstance(
|
1274
|
originalClassification.getRootNode().getUuid(), "Cloned classification");
|
1275
|
|
1276
|
Classification classificationClone = (Classification) taxonNodeService.cloneSubtree(config).getCdmEntity();
|
1277
|
|
1278
|
assertEquals("# of direct children does not match", originalClassification.getChildNodes().size(), classificationClone.getChildNodes().size());
|
1279
|
assertEquals("# of all nodes does not match", originalClassification.getAllNodes().size(), classificationClone.getAllNodes().size());
|
1280
|
|
1281
|
Set<UUID> originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet());
|
1282
|
for (TaxonNode clonedTaxonNode : classificationClone.getChildNodes()) {
|
1283
|
//test no reuse of taxon
|
1284
|
Taxon clonedTaxon = clonedTaxonNode.getTaxon();
|
1285
|
TaxonNode originalNode = originalClassification.getNode(clonedTaxon);
|
1286
|
assertNull(originalNode);
|
1287
|
|
1288
|
//check relationship
|
1289
|
assertEquals(0, clonedTaxon.getRelationsFromThisTaxon().size());
|
1290
|
|
1291
|
//test taxon sec
|
1292
|
assertTrue(originalTaxonSecUuids.contains(clonedTaxon.getSec().getUuid()));
|
1293
|
}
|
1294
|
commitAndStartNewTransaction();
|
1295
|
|
1296
|
//test reuse taxon
|
1297
|
config.setReuseTaxa(true);
|
1298
|
classificationClone = (Classification) taxonNodeService.cloneSubtree(config).getCdmEntity();
|
1299
|
assertEquals("# of direct children does not match", originalClassification.getChildNodes().size(), classificationClone.getChildNodes().size());
|
1300
|
originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet());
|
1301
|
for (TaxonNode taxonNode : classificationClone.getChildNodes()) {
|
1302
|
//test no reuse of taxon
|
1303
|
Taxon clonedTaxon = taxonNode.getTaxon();
|
1304
|
TaxonNode originalNode = originalClassification.getNode(clonedTaxon);
|
1305
|
assertNotNull(originalNode);
|
1306
|
Taxon originalTaxon = originalNode.getTaxon();
|
1307
|
assertNotNull(originalTaxon);
|
1308
|
|
1309
|
//check relationship
|
1310
|
assertEquals(0, clonedTaxon.getRelationsFromThisTaxon().size());
|
1311
|
|
1312
|
//test taxon sec
|
1313
|
assertEquals(originalTaxon.getSec().getUuid(), clonedTaxon.getSec().getUuid());
|
1314
|
}
|
1315
|
commitAndStartNewTransaction();
|
1316
|
|
1317
|
config.setReuseTaxa(false); //reset
|
1318
|
config.setRelationTypeToOldTaxon(TaxonRelationshipType.CONGRUENT_TO());
|
1319
|
Reference sec = referenceDao.findByUuid(UUID.fromString("719d136b-409e-40d0-9561-46f6999465b4"));
|
1320
|
config.setTaxonSecundumUuid(sec.getUuid());
|
1321
|
classificationClone = (Classification) taxonNodeService.cloneSubtree(config).getCdmEntity();
|
1322
|
originalTaxonSecUuids = originalClassification.getAllNodes().stream().map(tn -> tn.getTaxon().getSec().getUuid()).collect(Collectors.toSet());
|
1323
|
for (TaxonNode taxonNode : classificationClone.getChildNodes()) {
|
1324
|
//test no reuse of taxon
|
1325
|
Taxon clonedTaxon = taxonNode.getTaxon();
|
1326
|
TaxonNode originalNode = originalClassification.getNode(clonedTaxon);
|
1327
|
assertNull(originalNode);
|
1328
|
|
1329
|
//check relationship
|
1330
|
TaxonRelationship relShip = clonedTaxon.getRelationsFromThisTaxon().iterator().next();
|
1331
|
Taxon relatedTaxon = relShip.getToTaxon();
|
1332
|
Taxon relatedOriginalTaxon = originalClassification.getNode(relatedTaxon).getTaxon();
|
1333
|
assertEquals(relatedOriginalTaxon.getName(), clonedTaxon.getName());
|
1334
|
assertTrue(relShip.getType().equals(TaxonRelationshipType.CONGRUENT_TO()));
|
1335
|
|
1336
|
//test taxon sec
|
1337
|
assertEquals(relatedOriginalTaxon.getSec().getUuid(), clonedTaxon.getSec().getUuid());
|
1338
|
}
|
1339
|
commitAndStartNewTransaction();
|
1340
|
|
1341
|
//no recursive for root
|
1342
|
config = SubtreeCloneConfigurator.NewBaseInstance(
|
1343
|
originalClassification.getRootNode().getUuid(), "Cloned classification");
|
1344
|
config.setDoRecursive(false);
|
1345
|
classificationClone = (Classification) taxonNodeService.cloneSubtree(config).getCdmEntity();
|
1346
|
Assert.assertTrue(classificationClone.getRootNode().getChildNodes().isEmpty());
|
1347
|
|
1348
|
//no recursive for root
|
1349
|
config = SubtreeCloneConfigurator.NewBaseInstance(
|
1350
|
UUID.fromString("26cc5c08-72df-45d4-84ea-ce81e7e53114"), "Cloned classification");
|
1351
|
config.setDoRecursive(false);
|
1352
|
classificationClone = (Classification) taxonNodeService.cloneSubtree(config).getCdmEntity();
|
1353
|
List<TaxonNode> nodes = classificationClone.getRootNode().getChildNodes();
|
1354
|
Assert.assertEquals(1, nodes.size());
|
1355
|
Taxon clonedTaxon = nodes.iterator().next().getTaxon();
|
1356
|
Assert.assertEquals("Name should be the same as for the original taxon", UUID.fromString("301e2bf0-85a4-442a-93f6-63d3b9ee8c3d"), clonedTaxon.getName().getUuid());
|
1357
|
Assert.assertTrue(nodes.iterator().next().getChildNodes().isEmpty());
|
1358
|
}
|
1359
|
|
1360
|
@Override
|
1361
|
// @Test
|
1362
|
public void createTestDataSet() throws FileNotFoundException {
|
1363
|
UUID checklist2Uuid = UUID.fromString("c6e3a598-3b6c-4ef5-8b01-5bdb3de5a9fd");
|
1364
|
UUID campanulaNodeUuid = UUID.fromString("62fa918d-a1d8-4284-ae4b-93478bde8656");
|
1365
|
UUID campanulaPersicifoliaNodeUuid = UUID.fromString("dce3defa-5123-44a7-8008-0cc9b27461f6");
|
1366
|
|
1367
|
UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
|
1368
|
UUID abiesNodeUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
|
1369
|
UUID abiesAlbaNodeUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
|
1370
|
UUID abiesAlbaSubBrotaNodeUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
|
1371
|
UUID abiesPalmaNodeUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
|
1372
|
|
1373
|
UUID pinusNodeUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
|
1374
|
|
1375
|
/*
|
1376
|
* Checklist2
|
1377
|
* - Campanula
|
1378
|
* - Campanula persicifolia
|
1379
|
* Checklist
|
1380
|
* - Abies
|
1381
|
* - Abies alba
|
1382
|
* - Abieas alba subs. brota
|
1383
|
* - Abies palma
|
1384
|
* -Pinus
|
1385
|
*/
|
1386
|
Classification checklist2 = Classification.NewInstance("Checklist2");
|
1387
|
checklist2.setUuid(checklist2Uuid);
|
1388
|
|
1389
|
IBotanicalName campanulaName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1390
|
campanulaName.setGenusOrUninomial("Campanula");
|
1391
|
Taxon campanula = Taxon.NewInstance(campanulaName, null);
|
1392
|
|
1393
|
IBotanicalName campanulaPersicifoliaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1394
|
campanulaPersicifoliaName.setGenusOrUninomial("Campanula");
|
1395
|
campanulaPersicifoliaName.setSpecificEpithet("persicifolia");
|
1396
|
Taxon campanulaPersicifolia = Taxon.NewInstance(campanulaPersicifoliaName, null);
|
1397
|
|
1398
|
TaxonNode campanulaNode = checklist2.addChildTaxon(campanula, null, null);
|
1399
|
campanulaNode.setUuid(campanulaNodeUuid);
|
1400
|
TaxonNode campanulaPersicifoliaNode = checklist2.addParentChild(campanula, campanulaPersicifolia, null, null);
|
1401
|
campanulaPersicifoliaNode.setUuid(campanulaPersicifoliaNodeUuid);
|
1402
|
|
1403
|
Classification checklist = Classification.NewInstance("Checklist");
|
1404
|
checklist.setUuid(classificationUuid);
|
1405
|
|
1406
|
IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1407
|
abiesName.setGenusOrUninomial("Abies");
|
1408
|
Taxon abies = Taxon.NewInstance(abiesName, null);
|
1409
|
|
1410
|
IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1411
|
abiesAlbaName.setGenusOrUninomial("Abies");
|
1412
|
abiesAlbaName.setSpecificEpithet("alba");
|
1413
|
Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
1414
|
|
1415
|
IBotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
|
1416
|
abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
|
1417
|
abiesAlbaSubBrotaName.setSpecificEpithet("alba");
|
1418
|
abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
|
1419
|
Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
|
1420
|
|
1421
|
IBotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1422
|
abiesPalmaName.setGenusOrUninomial("Abies");
|
1423
|
abiesPalmaName.setSpecificEpithet("palma");
|
1424
|
Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
|
1425
|
|
1426
|
IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1427
|
pinusName.setGenusOrUninomial("Pinus");
|
1428
|
Taxon pinus = Taxon.NewInstance(pinusName, null);
|
1429
|
|
1430
|
TaxonNode abiesNode = checklist.addChildTaxon(abies, null, null);
|
1431
|
abiesNode.setUuid(abiesNodeUuid);
|
1432
|
TaxonNode abiesAlbaNode = checklist.addParentChild(abies, abiesAlba, null, null);
|
1433
|
abiesAlbaNode.setUuid(abiesAlbaNodeUuid);
|
1434
|
TaxonNode abiesAlbaSubBrotaNode = checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
|
1435
|
abiesAlbaSubBrotaNode.setUuid(abiesAlbaSubBrotaNodeUuid);
|
1436
|
TaxonNode abiesPalmaNode = checklist.addParentChild(abies, abiesPalma, null, null);
|
1437
|
abiesPalmaNode.setUuid(abiesPalmaNodeUuid);
|
1438
|
TaxonNode pinusNode = checklist.addChildTaxon(pinus, null, null);
|
1439
|
pinusNode.setUuid(pinusNodeUuid);
|
1440
|
|
1441
|
taxonService.saveOrUpdate(campanula);
|
1442
|
taxonService.saveOrUpdate(campanulaPersicifolia);
|
1443
|
classificationService.saveOrUpdate(checklist2);
|
1444
|
|
1445
|
taxonService.saveOrUpdate(abies);
|
1446
|
taxonService.saveOrUpdate(abiesAlba);
|
1447
|
taxonService.saveOrUpdate(abiesAlbaSubBrota);
|
1448
|
taxonService.saveOrUpdate(abiesPalma);
|
1449
|
taxonService.saveOrUpdate(pinus);
|
1450
|
classificationService.saveOrUpdate(checklist);
|
1451
|
|
1452
|
setComplete();
|
1453
|
endTransaction();
|
1454
|
|
1455
|
String fileNameAppendix = "testFindCommonParentNode";
|
1456
|
|
1457
|
writeDbUnitDataSetFile(new String[] {
|
1458
|
"TAXONBASE", "TAXONNAME",
|
1459
|
"TAXONRELATIONSHIP",
|
1460
|
"HOMOTYPICALGROUP",
|
1461
|
"CLASSIFICATION", "TAXONNODE",
|
1462
|
"LANGUAGESTRING",
|
1463
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
1464
|
},
|
1465
|
fileNameAppendix, true );
|
1466
|
}
|
1467
|
}
|