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.
9 package eu
.etaxonomy
.cdm
.app
.eflora
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.apache
.logging
.log4j
.LogManager
;
15 import org
.apache
.logging
.log4j
.Logger
;
16 import org
.springframework
.transaction
.TransactionStatus
;
18 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
21 import eu
.etaxonomy
.cdm
.common
.URI
;
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
.PolytomousKey
;
37 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
38 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaType
;
40 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
41 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
42 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
43 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermVocabulary
;
44 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
45 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
46 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
52 public class CentralAfricaEricaceaeActivator
{
54 private static Logger logger
= LogManager
.getLogger();
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 TermTree
<Feature
> tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
137 myImport
.getCdmAppController().getTermTreeService().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().updateCaches(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
);
190 private void newNamedAreas(CdmDefaultImport
<EfloraImportConfigurator
> myImport
) {
191 ICdmRepository app
= myImport
.getCdmAppController();
193 app
= CdmApplicationController
.NewInstance(cdmDestination
, hbm2dll
, false);
195 TransactionStatus tx
= app
.startTransaction();
197 OrderedTermVocabulary
<NamedArea
> areaVoc
= OrderedTermVocabulary
.NewOrderedInstance(TermType
.NamedArea
, NamedArea
.class, "Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions", null);
198 app
.getVocabularyService().save(areaVoc
);
200 NamedAreaLevel level
= NamedAreaLevel
.NewInstance("Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions");
201 ITermService termService
= app
.getTermService();
203 termService
.save(level
);
205 NamedArea area
= NamedArea
.NewInstance("C\u00F4tier", "C\u00F4tier", "I");
206 area
.setLevel(level
);
207 area
.setType(NamedAreaType
.NATURAL_AREA());
208 areaVoc
.addTerm(area
);
209 termService
.save(area
);
212 area
= NamedArea
.NewInstance("Mayumbe", "Mayumbe", "II");
213 area
.setLevel(level
);
214 area
.setType(NamedAreaType
.NATURAL_AREA());
215 areaVoc
.addTerm(area
);
216 termService
.save(area
);
218 area
= NamedArea
.NewInstance("Bas-Congo", "Bas-Congo", "III");
219 area
.setLevel(level
);
220 area
.setType(NamedAreaType
.NATURAL_AREA());
221 areaVoc
.addTerm(area
);
222 termService
.save(area
);
224 area
= NamedArea
.NewInstance("Kasai", "Kasai", "IV");
225 area
.setLevel(level
);
226 area
.setType(NamedAreaType
.NATURAL_AREA());
227 areaVoc
.addTerm(area
);
228 termService
.save(area
);
230 area
= NamedArea
.NewInstance("Bas-Katanga", "Bas-Katanga", "V");
231 area
.setLevel(level
);
232 area
.setType(NamedAreaType
.NATURAL_AREA());
233 areaVoc
.addTerm(area
);
234 termService
.save(area
);
236 area
= NamedArea
.NewInstance("Forestier Central", "Forestier Central", "VI");
237 area
.setLevel(level
);
238 area
.setType(NamedAreaType
.NATURAL_AREA());
239 areaVoc
.addTerm(area
);
240 termService
.save(area
);
242 area
= NamedArea
.NewInstance("Ubangi-Uele", "Ubangi-Uele", "VII");
243 area
.setLevel(level
);
244 area
.setType(NamedAreaType
.NATURAL_AREA());
245 areaVoc
.addTerm(area
);
246 termService
.save(area
);
248 area
= NamedArea
.NewInstance("Lac Albert", "Lac Albert", "VIII");
249 area
.setLevel(level
);
250 area
.setType(NamedAreaType
.NATURAL_AREA());
251 areaVoc
.addTerm(area
);
252 termService
.save(area
);
254 area
= NamedArea
.NewInstance("Lacs \u00C9douard et Kivu", "Lacs \u00C9douard et Kivu", "IX");
255 area
.setLevel(level
);
256 area
.setType(NamedAreaType
.NATURAL_AREA());
257 areaVoc
.addTerm(area
);
258 termService
.save(area
);
260 area
= NamedArea
.NewInstance("Rwanda-Burundi", "Rwanda-Burundi", "X");
261 area
.setLevel(level
);
262 area
.setType(NamedAreaType
.NATURAL_AREA());
263 areaVoc
.addTerm(area
);
264 termService
.save(area
);
266 area
= NamedArea
.NewInstance("Haut-Katanga", "Haut-Katanga", "XI");
267 area
.setLevel(level
);
268 area
.setType(NamedAreaType
.NATURAL_AREA());
269 areaVoc
.addTerm(area
);
270 termService
.save(area
);
272 app
.getVocabularyService().save(areaVoc
);
274 app
.commitTransaction(tx
);
278 private Reference
getSourceReference(String string
) {
279 Reference result
= ReferenceFactory
.newGeneric();
280 result
.setTitleCache(string
, true);
284 private TermTree
<Feature
> makeFeatureNode(ITermService service
){
285 CentralAfricaEricaceaeTransformer transformer
= new CentralAfricaEricaceaeTransformer();
287 TermTree
<Feature
> result
= TermTree
.NewFeatureInstance(featureTreeUuid
);
288 result
.setTitleCache("Central Africa Ericaceae Feature Tree", true);
289 TermNode
<Feature
> root
= result
.getRoot();
291 TermNode
<Feature
> newNode
= root
.addChild(Feature
.DESCRIPTION());
293 addFeatureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
295 addFeatureNodesByStringList(generellDescriptionsList
, root
, transformer
, service
);
297 newNode
= root
.addChild(Feature
.DISTRIBUTION());
299 newNode
= root
.addChild(Feature
.ECOLOGY());
300 addFeatureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
302 newNode
= root
.addChild(Feature
.USES());
304 addFeatureNodesByStringList(chomosomesList
, root
, transformer
, service
);
306 newNode
= root
.addChild(Feature
.COMMON_NAME());
308 newNode
= root
.addChild(Feature
.CITATION());
313 private static String
[] chomosomesList
= new String
[]{
318 private static String
[] habitatEcologyList
= new String
[]{
324 private static String
[] generellDescriptionsList
= new String
[]{
326 "Morphology and anatomy",
328 "Vegetative morphology and anatomy",
334 "Fruits and embryology",
338 "Chromosome numbers",
339 "Phytochemistry and Chemotaxonomy",
344 private static String
[] descriptionFeatureList
= new String
[]{
353 "Flowering branchlets",
360 "flower-bearing stems",
368 "Young inflorescences",
406 "Infructescences", //order not consistent (sometimes before "Flowers")
430 public void addFeatureNodesByStringList(String
[] featureStringList
, TermNode
<Feature
> root
, IInputTransformer transformer
, ITermService termService
){
432 for (String featureString
: featureStringList
){
434 featureUuid
= transformer
.getFeatureUuid(featureString
);
435 Feature feature
= (Feature
)termService
.find(featureUuid
);
436 if (feature
!= null){
437 TermNode
<Feature
> child
= root
.addChild(feature
);
440 } catch (UndefinedTransformerMethodException e
) {
441 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
450 public static void main(String
[] args
) {
451 CentralAfricaEricaceaeActivator me
= new CentralAfricaEricaceaeActivator();
452 me
.doImport(cdmDestination
);