1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.test.function;
|
11
|
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.Ignore;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
19
|
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
|
20
|
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
|
21
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
22
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
23
|
import eu.etaxonomy.cdm.model.name.Rank;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
28
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
|
31
|
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
|
32
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
33
|
|
34
|
/**
|
35
|
* <h2>NOTE</h2>
|
36
|
* This is a test for sole development purposes, it is not
|
37
|
* touched by mvn test since it is not matching the "\/**\/*Test" pattern,
|
38
|
* but it should be annotate with @Ignore when running the project a s junit suite in eclipse
|
39
|
*
|
40
|
*/
|
41
|
@Ignore
|
42
|
public class TestTaxonFunction {
|
43
|
private static final Logger logger = Logger.getLogger(TestTaxonFunction.class);
|
44
|
|
45
|
private CdmApplicationController getCdmApplicationController(String strDataSource, DbSchemaValidation hbm2dll){
|
46
|
CdmApplicationController cdmApp= null;
|
47
|
try {
|
48
|
CdmPersistentDataSource dataSource = CdmPersistentDataSource.NewInstance(strDataSource);
|
49
|
cdmApp = CdmApplicationController.NewInstance(dataSource, hbm2dll);
|
50
|
} catch (DataSourceNotFoundException e) {
|
51
|
e.printStackTrace();
|
52
|
}
|
53
|
return cdmApp;
|
54
|
|
55
|
}
|
56
|
|
57
|
private UUID getRefUuid(){
|
58
|
return UUID.fromString("5d5363e2-f560-4da2-857d-dfa344b9f5ae");
|
59
|
}
|
60
|
|
61
|
private void initDatabase(){
|
62
|
logger.info("init Database start ...");
|
63
|
DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
64
|
CdmApplicationController cdmApp = getCdmApplicationController("defaultMySql", hbm2dll);
|
65
|
|
66
|
INonViralNameParser<?> parser = NonViralNameParserImpl.NewInstance();
|
67
|
Reference<?> sec = ReferenceFactory.newBook();
|
68
|
sec.setTitleCache("ConceptRef", true);
|
69
|
|
70
|
//root
|
71
|
String rootName = "Hieracium L.";
|
72
|
TaxonNameBase<?,?> botanicalName= parser.parseFullName(rootName);
|
73
|
sec.setUuid(getRefUuid());
|
74
|
Taxon genusTaxon = Taxon.NewInstance(botanicalName, sec);
|
75
|
|
76
|
//child1
|
77
|
String child1Name = "Hieracium asturianum Pau";
|
78
|
TaxonNameBase<?,?> botSpecies= parser.parseFullName(child1Name);
|
79
|
Taxon childTaxon = Taxon.NewInstance(botSpecies, sec);
|
80
|
childTaxon.setTaxonomicParent(genusTaxon, null, null);
|
81
|
|
82
|
//child2
|
83
|
String child2Name = "Hieracium wolffii Zahn";
|
84
|
TaxonNameBase<?,?> botSpecies2= parser.parseFullName(child2Name);
|
85
|
Taxon childTaxon2 = Taxon.NewInstance(botSpecies2, sec);
|
86
|
childTaxon2.setTaxonomicParent(childTaxon, null, null);
|
87
|
|
88
|
//synonym
|
89
|
String synonymName = "Acacium wolffii Syn.";
|
90
|
TaxonNameBase<?,?> botSynName= parser.parseFullName(synonymName);
|
91
|
|
92
|
Synonym synTaxon = Synonym.NewInstance(botSynName, sec);
|
93
|
childTaxon2.addSynonym(synTaxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
|
94
|
//save
|
95
|
cdmApp.getTaxonService().save(genusTaxon);
|
96
|
|
97
|
//other taxon
|
98
|
BotanicalName otherName = BotanicalName.NewInstance(Rank.GENUS());
|
99
|
otherName.setTitleCache("otherName", true);
|
100
|
Taxon otherTaxon = Taxon.NewInstance(otherName, sec);
|
101
|
|
102
|
cdmApp.getTaxonService().save(otherTaxon);
|
103
|
cdmApp.close();
|
104
|
logger.info("init Database end ...");
|
105
|
}
|
106
|
|
107
|
private boolean testHasTaxonomicChild(){
|
108
|
logger.info("testHasTaxonomicChild start ...");
|
109
|
if (false){
|
110
|
initDatabase();
|
111
|
}
|
112
|
CdmApplicationController cdmApp = getCdmApplicationController("defaultMySql", DbSchemaValidation.VALIDATE);
|
113
|
Reference<?> sec = cdmApp.getReferenceService().find(getRefUuid());
|
114
|
List<Taxon> rootList = cdmApp.getTaxonService().getRootTaxa(sec, CdmFetch.NO_FETCH(), false);
|
115
|
for (Taxon taxon:rootList){
|
116
|
System.out.println(taxon);
|
117
|
//taxon.getT
|
118
|
taxon.hasTaxonomicChildren();
|
119
|
Taxon child = taxon.getTaxonomicChildren().iterator().next();
|
120
|
logger.warn("Child has children: " + child.hasTaxonomicChildren());
|
121
|
Taxon child2 = child.getTaxonomicChildren().iterator().next();
|
122
|
logger.warn("Child2 has children: " + child2.hasTaxonomicChildren());
|
123
|
logger.warn("Child2 has synonym: " + child2.hasSynonyms());
|
124
|
Synonym syn = child2.getSynonyms().iterator().next();
|
125
|
logger.warn("Syn has reference: " + syn.getSec());
|
126
|
}
|
127
|
logger.info("testHasTaxonomicChild end . ..");
|
128
|
return true;
|
129
|
}
|
130
|
|
131
|
|
132
|
/**
|
133
|
* @param args
|
134
|
*/
|
135
|
public static void main(String[] args) {
|
136
|
TestTaxonFunction testClass = new TestTaxonFunction();
|
137
|
testClass.testHasTaxonomicChild();
|
138
|
System.out.println("End");
|
139
|
}
|
140
|
|
141
|
}
|