1
|
/* just for testing */
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.test.function;
|
12
|
|
13
|
import java.util.List;
|
14
|
import java.util.SortedSet;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Ignore;
|
20
|
import org.springframework.transaction.TransactionStatus;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
23
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
24
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
26
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
27
|
import eu.etaxonomy.cdm.model.agent.Person;
|
28
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
29
|
import eu.etaxonomy.cdm.model.common.Language;
|
30
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
31
|
import eu.etaxonomy.cdm.model.description.Feature;
|
32
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
33
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
36
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
37
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
40
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
41
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
42
|
|
43
|
|
44
|
|
45
|
/**
|
46
|
* <h2>NOTE</h2>
|
47
|
* This is a test for sole development purposes, it is not
|
48
|
* touched by mvn test since it is not matching the "\/**\/*Test" pattern,
|
49
|
* but it should be annotate with @Ignore when running the project a s junit suite in eclipse
|
50
|
*
|
51
|
*
|
52
|
*/
|
53
|
@Ignore
|
54
|
public class TestService {
|
55
|
static Logger logger = Logger.getLogger(TestService.class);
|
56
|
|
57
|
private static final UUID TEST_TAXON_UUID = UUID.fromString("b3084573-343d-4279-ba92-4ab01bb47db5");
|
58
|
private static CdmApplicationController appCtr;
|
59
|
|
60
|
public void testAppController() {
|
61
|
logger.info("Create name objects...");
|
62
|
NonViralName<?> nvn = TaxonNameBase.NewNonViralInstance(Rank.SPECIES());
|
63
|
|
64
|
BotanicalName bn = TaxonNameBase.NewBotanicalInstance(Rank.SUBSPECIES());
|
65
|
ZoologicalName zn = TaxonNameBase.NewZoologicalInstance(Rank.FAMILY());
|
66
|
|
67
|
logger.info("Create reference objects...");
|
68
|
|
69
|
Reference sec = ReferenceFactory.newJournal();
|
70
|
sec.setTitleCache("TestJournal", true);
|
71
|
|
72
|
logger.info("Create taxon objects...");
|
73
|
Taxon childTaxon = Taxon.NewInstance(nvn, sec);
|
74
|
Synonym syn = Synonym.NewInstance(bn, sec);
|
75
|
childTaxon.addSynonym(syn, SynonymType.SYNONYM_OF());
|
76
|
TransactionStatus txStatus = appCtr.startTransaction();
|
77
|
appCtr.getTaxonService().save(childTaxon);
|
78
|
appCtr.commitTransaction(txStatus);
|
79
|
|
80
|
|
81
|
Taxon parentTaxon = Taxon.NewInstance(zn, sec);
|
82
|
parentTaxon.setUuid(TEST_TAXON_UUID);
|
83
|
// parentTaxon.addTaxonomicChild(childTaxon, sec, null);
|
84
|
|
85
|
|
86
|
// test
|
87
|
nvn.setGenusOrUninomial("Nonvirala");
|
88
|
bn.setGenusOrUninomial("Abies");
|
89
|
|
90
|
logger.info("Create new Author agent...");
|
91
|
Person team= Person.NewInstance();
|
92
|
team.setTitleCache("AuthorAgent1", true);
|
93
|
nvn.setCombinationAuthorship(team);
|
94
|
|
95
|
logger.info("Save objects ...");
|
96
|
appCtr.getTaxonService().save(parentTaxon);
|
97
|
|
98
|
// load Name list
|
99
|
logger.info("Load existing names from db...");
|
100
|
List<TaxonNameBase> tnList = appCtr.getNameService().list(null,1000, 0,null,null);
|
101
|
for (TaxonNameBase tn2: tnList){
|
102
|
logger.info("Title: "+ tn2.getTitleCache() + " UUID: " + tn2.getUuid()+";");
|
103
|
}
|
104
|
}
|
105
|
|
106
|
public void testDeleteTaxa(){
|
107
|
ITaxonService taxonService = appCtr.getTaxonService();
|
108
|
TaxonNameBase<?,?> taxonName = TaxonNameBase.NewBotanicalInstance(Rank.SPECIES());
|
109
|
Reference ref = ReferenceFactory.newJournal();
|
110
|
Taxon taxon1 = Taxon.NewInstance(taxonName, ref);
|
111
|
Taxon taxon2 = Taxon.NewInstance(taxonName, null);
|
112
|
logger.info("Save taxon ...");
|
113
|
UUID uuidTaxon1 = taxonService.save(taxon1).getUuid();
|
114
|
logger.info(" UUID: " + uuidTaxon1);
|
115
|
UUID uuidTaxon2 = taxonService.save(taxon2).getUuid();
|
116
|
logger.info(" UUID: " + uuidTaxon2);
|
117
|
logger.info("Remove taxon ...");
|
118
|
UUID uuid = null;
|
119
|
|
120
|
DeleteResult result = taxonService.deleteTaxon(taxon1.getUuid(), null, null);
|
121
|
|
122
|
if(!result.isOk()){
|
123
|
Assert.fail();
|
124
|
}
|
125
|
logger.info(" UUID: " + uuid);
|
126
|
}
|
127
|
|
128
|
|
129
|
// public void testVocabularyLists(){
|
130
|
// TermVocabulary<NomenclaturalStatusType> voc = appCtr.getNameService().getStatusTypeVocabulary();
|
131
|
// Set<NomenclaturalStatusType> set = voc.getTermsOrderedByLabels(Language.DEFAULT());
|
132
|
// for (Object obj : set.toArray()){
|
133
|
// NomenclaturalStatusType nomStatusType = (NomenclaturalStatusType)obj;
|
134
|
// System.out.println(nomStatusType.getLabel());
|
135
|
// }
|
136
|
// TermVocabulary<NameRelationshipType> nameRelVoc = appCtr.getNameService().getNameRelationshipTypeVocabulary();
|
137
|
// Set<NameRelationshipType> nameRelSet = nameRelVoc.getTermsOrderedByLabels(Language.DEFAULT());
|
138
|
// for (Object obj : nameRelSet.toArray()){
|
139
|
// NameRelationshipType naemRelType = (NameRelationshipType)obj;
|
140
|
// System.out.println(naemRelType.getLabel());
|
141
|
// }
|
142
|
// System.out.println("=========== NAME LIST =================");
|
143
|
// List<TaxonNameBase> nameList = appCtr.getNameService().getNamesByName("Abies%");
|
144
|
// System.out.println("Size" + nameList.size());
|
145
|
// for (TaxonNameBase name : nameList){
|
146
|
// System.out.println("ABEIS: " + name.getTitleCache());
|
147
|
// }
|
148
|
// }
|
149
|
|
150
|
public void testDeleteRelationship(){
|
151
|
ITaxonService taxonService = appCtr.getTaxonService();
|
152
|
TaxonNameBase<?,?> taxonName = TaxonNameBase.NewBotanicalInstance(Rank.SPECIES());
|
153
|
Reference ref = ReferenceFactory.newJournal();
|
154
|
Taxon parent = Taxon.NewInstance(taxonName, ref);
|
155
|
Taxon child = Taxon.NewInstance(taxonName, null);
|
156
|
// parent.addTaxonomicChild(child, null, null);
|
157
|
|
158
|
logger.info("Save taxon ...");
|
159
|
UUID uuidTaxon1 = taxonService.save(parent).getUuid();
|
160
|
logger.info(" UUID: " + uuidTaxon1);
|
161
|
UUID uuidTaxon2 = taxonService.save(child).getUuid();
|
162
|
logger.info(" UUID: " + uuidTaxon2);
|
163
|
|
164
|
|
165
|
// Set<TaxonRelationship> set = parent.getRelationsToThisTaxon();
|
166
|
// for (TaxonRelationship rel : set){
|
167
|
// if (rel.getType().equals(ConceptRelationshipType.TAXONOMICALLY_INCLUDED_IN())){
|
168
|
// parent.removeTaxonRelation(rel);
|
169
|
// }
|
170
|
// }
|
171
|
|
172
|
}
|
173
|
|
174
|
public void testTransientRank(){
|
175
|
ITaxonService taxonService = appCtr.getTaxonService();
|
176
|
TaxonNameBase<?,?> taxonName = TaxonNameBase.NewBotanicalInstance(transientRank);
|
177
|
Reference ref = ReferenceFactory.newJournal();
|
178
|
Taxon taxon = Taxon.NewInstance(taxonName, ref);
|
179
|
|
180
|
logger.info("Save taxon ...");
|
181
|
UUID uuidTaxon1 = taxonService.save(taxon).getUuid();
|
182
|
logger.info(" UUID: " + uuidTaxon1);
|
183
|
|
184
|
}
|
185
|
|
186
|
public void testFeature(){
|
187
|
TransactionStatus tx = appCtr.startTransaction();
|
188
|
Language lang = Language.DEFAULT();
|
189
|
IDescriptionService descriptionService = appCtr.getDescriptionService();
|
190
|
TermVocabulary<Feature> voc = descriptionService.getDefaultFeatureVocabulary();
|
191
|
SortedSet<Feature> terms = voc.getTermsOrderedByLabels(lang);
|
192
|
for (DefinedTermBase term : terms){
|
193
|
logger.warn(term.getRepresentation(lang));
|
194
|
}
|
195
|
appCtr.commitTransaction(tx);
|
196
|
}
|
197
|
|
198
|
|
199
|
public void regenerateTaxonTitleCache(){
|
200
|
ITaxonService taxonService = appCtr.getTaxonService();
|
201
|
taxonService.updateTitleCache();
|
202
|
}
|
203
|
|
204
|
private void test(){
|
205
|
System.out.println("Start ...");
|
206
|
// testAppController();
|
207
|
//testRootTaxa();
|
208
|
//testTermApi();
|
209
|
//testDeleteTaxa();
|
210
|
//testDeleteRelationship();
|
211
|
//regenerateTaxonTitleCache();
|
212
|
//testVocabularyLists();
|
213
|
//testTransientRank();
|
214
|
testFeature();
|
215
|
System.out.println("\nEnd ...");
|
216
|
}
|
217
|
|
218
|
private static Rank transientRank = Rank.SPECIES();
|
219
|
|
220
|
private void init(){
|
221
|
try {
|
222
|
DbSchemaValidation dbSchemaValidation = DbSchemaValidation.CREATE;
|
223
|
//appCtr = CdmApplicationController.NewInstance(CdmPersistentDataSource.NewInstance("defaultMySql") , dbSchemaValidation);
|
224
|
appCtr = CdmApplicationController.NewInstance(dbSchemaValidation);
|
225
|
|
226
|
|
227
|
TaxonNameBase<?,?> name = TaxonNameBase.NewNonViralInstance(null);
|
228
|
name.setTitleCache("Abies alba", true);
|
229
|
|
230
|
TaxonNameBase<?,?> name2 = TaxonNameBase.NewNonViralInstance(null);
|
231
|
name2.setTitleCache("Abies beta", true);
|
232
|
|
233
|
//appCtr.getNameService().saveTaxonName(name);
|
234
|
//appCtr.getNameService().saveTaxonName(name2);
|
235
|
|
236
|
//appCtr = CdmApplicationController.NewInstance(CdmPersistentDataSource.NewInstance("rel1_1"));
|
237
|
//appCtr = new CdmApplicationController(HBM2DDL.CREATE);
|
238
|
} catch (Exception e) {
|
239
|
// TODO Auto-generated catch block
|
240
|
e.printStackTrace();
|
241
|
}
|
242
|
}
|
243
|
|
244
|
/**
|
245
|
* @param args
|
246
|
*/
|
247
|
public static void main(String[] args) {
|
248
|
TestService sc = new TestService();
|
249
|
sc.init();
|
250
|
sc.test();
|
251
|
appCtr.close();
|
252
|
}
|
253
|
|
254
|
}
|