2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.eflora
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.transaction
.TransactionStatus
;
19 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
20 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
22 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
23 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
24 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
.TermMatchMode
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
27 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
28 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
29 import eu
.etaxonomy
.cdm
.io
.eflora
.EfloraImportConfigurator
;
30 import eu
.etaxonomy
.cdm
.io
.eflora
.centralAfrica
.ericaceae
.CentralAfricaEricaceaeImportConfigurator
;
31 import eu
.etaxonomy
.cdm
.io
.eflora
.centralAfrica
.ericaceae
.CentralAfricaEricaceaeTransformer
;
32 import eu
.etaxonomy
.cdm
.io
.specimen
.excel
.in
.SpecimenCdmExcelImportConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
35 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
36 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
37 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
38 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
40 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
41 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaType
;
42 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
43 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
45 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermVocabulary
;
46 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
53 public class CentralAfricaEricaceaeActivator
{
54 private static final Logger logger
= Logger
.getLogger(CentralAfricaEricaceaeActivator
.class);
56 //database validation status (create, update, validate ...)
57 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
58 static final URI source
= EfloraSources
.ericacea_local();
60 static final URI specimenSource
= EfloraSources
.vittaria_specimen_pesiimport3();
63 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_flora_central_africa_local();
65 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview();
66 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
67 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
68 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
69 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
70 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_campanulaceae_production();
73 public static final UUID featureTreeUuid
= UUID
.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7");
75 public static UUID defaultLanguageUuid
= Language
.uuidFrench
;
78 static final UUID classificationUuid
= UUID
.fromString("10e5efcc-6e13-4abc-ad42-e0b46e50cbe7");
80 NomenclaturalCode nc
= NomenclaturalCode
.ICNAFP
;
83 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
85 static boolean doPrintKeys
= false;
88 private final boolean includeEricaceae
= false;
89 static final boolean doTaxa
= false;
90 static final boolean doDeduplicate
= false;
93 private final boolean doNewNamedAreas
= false;
94 private final boolean doFeatureTree
= false;
96 private final boolean doSpecimen
= true;
97 private final TermMatchMode specimenAreaMatchMode
= TermMatchMode
.UUID_ABBREVLABEL
;
100 private void doImport(ICdmDataSource cdmDestination
){
102 // CdmUpdater su = CdmUpdater.NewInstance();
103 // IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
106 // su.updateToCurrentVersion(cdmDestination, monitor);
107 // } catch (Exception e) {
108 // e.printStackTrace();
115 CentralAfricaEricaceaeImportConfigurator config
= CentralAfricaEricaceaeImportConfigurator
.NewInstance(source
, cdmDestination
);
116 config
.setClassificationUuid(classificationUuid
);
117 config
.setDoTaxa(doTaxa
);
118 config
.setCheck(check
);
119 config
.setDefaultLanguageUuid(defaultLanguageUuid
);
120 config
.setDoPrintKeys(doPrintKeys
);
121 config
.setDbSchemaValidation(hbm2dll
);
122 config
.setNomenclaturalCode(nc
);
124 CdmDefaultImport
<EfloraImportConfigurator
> myImport
= new CdmDefaultImport
<EfloraImportConfigurator
>();
128 if (includeEricaceae
){
129 System
.out
.println("Start import from ("+ source
.toString() + ") ...");
130 config
.setSourceReference(getSourceReference(config
.getSourceReferenceTitle()));
131 myImport
.invoke(config
);
132 System
.out
.println("End import from ("+ source
.toString() + ")...");
136 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
137 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
142 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
143 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
144 for(PolytomousKey key
: keys
){
145 key
.print(System
.out
);
146 System
.out
.println();
148 myImport
.getCdmAppController().commitTransaction(tx
);
153 ICdmRepository app
= myImport
.getCdmAppController();
155 app
= CdmApplicationController
.NewInstance(cdmDestination
, hbm2dll
, false);
157 app
.getAgentService().updateTitleCache(Team
.class, null, null, null);
159 // int count = app.getAgentService().deduplicate(Person.class, null, null);
161 // logger.warn("Deduplicated " + count + " persons.");
162 // count = app.getAgentService().deduplicate(Team.class, null, null);
163 //// logger.warn("Deduplicated " + count + " teams.");
164 // count = app.getReferenceService().deduplicate(Reference.class, null, null);
165 // logger.warn("Deduplicated " + count + " references.");
169 newNamedAreas(myImport
);
173 logger
.warn("Start specimen import");
174 ICdmRepository app
= myImport
.getCdmAppController();
175 SpecimenCdmExcelImportConfigurator specimenConfig
= SpecimenCdmExcelImportConfigurator
.NewInstance(specimenSource
, cdmDestination
);
176 specimenConfig
.setCdmAppController(app
);
177 specimenConfig
.setAreaMatchMode(specimenAreaMatchMode
);
178 specimenConfig
.setNomenclaturalCode(nc
);
180 config
.setDbSchemaValidation(DbSchemaValidation
.VALIDATE
);
181 specimenConfig
.setSourceReference(getSourceReference(specimenConfig
.getSourceReferenceTitle()));
183 CdmDefaultImport
<SpecimenCdmExcelImportConfigurator
> specimenImport
= new CdmDefaultImport
<SpecimenCdmExcelImportConfigurator
>();
184 specimenImport
.setCdmAppController(app
);
185 specimenImport
.invoke(specimenConfig
);
194 private void newNamedAreas(CdmDefaultImport
<EfloraImportConfigurator
> myImport
) {
195 ICdmRepository app
= myImport
.getCdmAppController();
197 app
= CdmApplicationController
.NewInstance(cdmDestination
, hbm2dll
, false);
199 TransactionStatus tx
= app
.startTransaction();
201 OrderedTermVocabulary
<NamedArea
> areaVoc
= OrderedTermVocabulary
.NewInstance(TermType
.NamedArea
, "Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions", null);
202 app
.getVocabularyService().save(areaVoc
);
204 NamedAreaLevel level
= NamedAreaLevel
.NewInstance("Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions");
205 ITermService termService
= app
.getTermService();
207 termService
.save(level
);
209 NamedArea area
= NamedArea
.NewInstance("C\u00F4tier", "C\u00F4tier", "I");
210 area
.setLevel(level
);
211 area
.setType(NamedAreaType
.NATURAL_AREA());
212 areaVoc
.addTerm(area
);
213 termService
.save(area
);
216 area
= NamedArea
.NewInstance("Mayumbe", "Mayumbe", "II");
217 area
.setLevel(level
);
218 area
.setType(NamedAreaType
.NATURAL_AREA());
219 areaVoc
.addTerm(area
);
220 termService
.save(area
);
222 area
= NamedArea
.NewInstance("Bas-Congo", "Bas-Congo", "III");
223 area
.setLevel(level
);
224 area
.setType(NamedAreaType
.NATURAL_AREA());
225 areaVoc
.addTerm(area
);
226 termService
.save(area
);
228 area
= NamedArea
.NewInstance("Kasai", "Kasai", "IV");
229 area
.setLevel(level
);
230 area
.setType(NamedAreaType
.NATURAL_AREA());
231 areaVoc
.addTerm(area
);
232 termService
.save(area
);
234 area
= NamedArea
.NewInstance("Bas-Katanga", "Bas-Katanga", "V");
235 area
.setLevel(level
);
236 area
.setType(NamedAreaType
.NATURAL_AREA());
237 areaVoc
.addTerm(area
);
238 termService
.save(area
);
240 area
= NamedArea
.NewInstance("Forestier Central", "Forestier Central", "VI");
241 area
.setLevel(level
);
242 area
.setType(NamedAreaType
.NATURAL_AREA());
243 areaVoc
.addTerm(area
);
244 termService
.save(area
);
246 area
= NamedArea
.NewInstance("Ubangi-Uele", "Ubangi-Uele", "VII");
247 area
.setLevel(level
);
248 area
.setType(NamedAreaType
.NATURAL_AREA());
249 areaVoc
.addTerm(area
);
250 termService
.save(area
);
252 area
= NamedArea
.NewInstance("Lac Albert", "Lac Albert", "VIII");
253 area
.setLevel(level
);
254 area
.setType(NamedAreaType
.NATURAL_AREA());
255 areaVoc
.addTerm(area
);
256 termService
.save(area
);
258 area
= NamedArea
.NewInstance("Lacs \u00C9douard et Kivu", "Lacs \u00C9douard et Kivu", "IX");
259 area
.setLevel(level
);
260 area
.setType(NamedAreaType
.NATURAL_AREA());
261 areaVoc
.addTerm(area
);
262 termService
.save(area
);
264 area
= NamedArea
.NewInstance("Rwanda-Burundi", "Rwanda-Burundi", "X");
265 area
.setLevel(level
);
266 area
.setType(NamedAreaType
.NATURAL_AREA());
267 areaVoc
.addTerm(area
);
268 termService
.save(area
);
270 area
= NamedArea
.NewInstance("Haut-Katanga", "Haut-Katanga", "XI");
271 area
.setLevel(level
);
272 area
.setType(NamedAreaType
.NATURAL_AREA());
273 areaVoc
.addTerm(area
);
274 termService
.save(area
);
276 app
.getVocabularyService().save(areaVoc
);
278 app
.commitTransaction(tx
);
282 private Reference
getSourceReference(String string
) {
283 Reference result
= ReferenceFactory
.newGeneric();
284 result
.setTitleCache(string
, true);
288 private FeatureTree
makeFeatureNode(ITermService service
){
289 CentralAfricaEricaceaeTransformer transformer
= new CentralAfricaEricaceaeTransformer();
291 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
292 result
.setTitleCache("Central Africa Ericaceae Feature Tree", true);
293 FeatureNode root
= result
.getRoot();
296 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
297 root
.addChild(newNode
);
299 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
301 addFeataureNodesByStringList(generellDescriptionsList
, root
, transformer
, service
);
304 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
305 root
.addChild(newNode
);
307 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
308 root
.addChild(newNode
);
309 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
311 newNode
= FeatureNode
.NewInstance(Feature
.USES());
312 root
.addChild(newNode
);
314 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
316 newNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
317 root
.addChild(newNode
);
319 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
320 root
.addChild(newNode
);
325 private static String
[] chomosomesList
= new String
[]{
330 private static String
[] habitatEcologyList
= new String
[]{
336 private static String
[] generellDescriptionsList
= new String
[]{
338 "Morphology and anatomy",
340 "Vegetative morphology and anatomy",
346 "Fruits and embryology",
350 "Chromosome numbers",
351 "Phytochemistry and Chemotaxonomy",
356 private static String
[] descriptionFeatureList
= new String
[]{
365 "Flowering branchlets",
372 "flower-bearing stems",
380 "Young inflorescences",
418 "Infructescences", //order not consistent (sometimes before "Flowers")
442 public void addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
444 for (String featureString
: featureStringList
){
446 featureUuid
= transformer
.getFeatureUuid(featureString
);
447 Feature feature
= (Feature
)termService
.find(featureUuid
);
448 if (feature
!= null){
449 FeatureNode child
= FeatureNode
.NewInstance(feature
);
450 root
.addChild(child
);
453 } catch (UndefinedTransformerMethodException e
) {
454 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
463 public static void main(String
[] args
) {
464 CentralAfricaEricaceaeActivator me
= new CentralAfricaEricaceaeActivator();
465 me
.doImport(cdmDestination
);