2 * Copyright (C) 2016 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
.mexico
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
17 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
18 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
20 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
22 import eu
.etaxonomy
.cdm
.io
.mexico
.MexicoConabioImportConfigurator
;
23 import eu
.etaxonomy
.cdm
.io
.mexico
.MexicoConabioTransformer
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
29 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
30 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
31 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
34 import eu
.etaxonomy
.cdm
.strategy
.parser
.TimePeriodParser
;
41 public class MexicoConabioActivator
{
42 private static final Logger logger
= Logger
.getLogger(MexicoConabioActivator
.class);
44 //database validation status (create, update, validate ...)
45 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
47 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
48 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
49 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_mexico_rubiaceae_production();
51 static final boolean doTaxa
= true;
52 static final boolean doDistributions
= true;
53 static final boolean doCommonNames
= true;
56 public static final UUID featureTreeUuid
= UUID
.fromString("d1f4ed29-9aae-4f6e-aa1e-4a3bf780e11d");
59 static final UUID classificationUuid
= UUID
.fromString("61968b43-e881-4043-b5c2-ba192e8f72dc");
60 private static final String classificationName
= "Rubiaceae Conabio";
63 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
65 private void doImport(ICdmDataSource cdmDestination
){
67 URI source
= conabio_rubiaceae();
70 MexicoConabioImportConfigurator config
= MexicoConabioImportConfigurator
.NewInstance(source
, cdmDestination
);
71 config
.setClassificationUuid(classificationUuid
);
72 config
.setClassificationName(classificationName
);
73 config
.setCheck(check
);
74 config
.setDoTaxa(doTaxa
);
75 config
.setDoDistributions(doDistributions
);
76 config
.setDoCommonNames(doCommonNames
);
77 config
.setDbSchemaValidation(hbm2dll
);
79 config
.setSource(source
);
80 String fileName
= source
.toString();
81 fileName
= fileName
.substring(fileName
.lastIndexOf("/") + 1 );
83 String message
= "Start import from ("+ fileName
+ ") ...";
84 System
.out
.println(message
);
87 config
.setSourceReference(getSourceReference());
88 config
.setSecReference(getSecReference());
90 CdmDefaultImport
<MexicoConabioImportConfigurator
> myImport
= new CdmDefaultImport
<MexicoConabioImportConfigurator
>();
92 myImport
.invoke(config
);
95 FeatureTree tree
= makeFeatureNodes(myImport
.getCdmAppController());
96 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
99 System
.out
.println("End import from ("+ source
.toString() + ")...");
104 public static URI
conabio_rubiaceae() {
105 return URI
.create("file:////BGBM-PESIHPC/Mexico/CONABIO-Rubiaceae.xlsx");
108 private Reference
getSourceReference() {
109 Reference result
= ReferenceFactory
.newDatabase();
110 result
.setTitleCache("CONABIO database", true);
111 TimePeriod tp
= TimePeriodParser
.parseString("2016");
113 result
.setDatePublished(tp
);
114 Institution inst
= Institution
.NewNamedInstance("CONABIO");
115 result
.setInstitution(inst
);
119 private Reference
getSecReference() {
120 Reference result
= ReferenceFactory
.newDatabase();
121 result
.setTitle("Rubiáceas de México");
122 result
.setDatePublished(TimePeriodParser
.parseString("2016"));
123 Person author
= Person
.NewInstance();
124 author
.setFirstname("Helga");
125 author
.setLastname("Ochoterena Booth");
126 result
.setAuthorship(author
);
127 result
.setUuid(MexicoConabioTransformer
.uuidReferenceConabio
);
131 private FeatureTree
makeFeatureNodes(ICdmRepository app
){
133 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
134 result
.setTitleCache("Mexico Rubiaceae Feature Tree", true);
135 FeatureNode root
= result
.getRoot();
138 Feature distribution
= Feature
.DISTRIBUTION();
139 Representation rep
= Representation
.NewInstance("Distribución", "Distribución", null, Language
.SPANISH_CASTILIAN());
140 distribution
.addRepresentation(rep
);
141 app
.getTermService().saveOrUpdate(distribution
);
142 newNode
= FeatureNode
.NewInstance(distribution
);
143 root
.addChild(newNode
);
145 Feature commonName
= Feature
.COMMON_NAME();
146 rep
= Representation
.NewInstance("Nombres comunes", "Nombres comunes", null, Language
.SPANISH_CASTILIAN());
147 commonName
.addRepresentation(rep
);
148 app
.getTermService().saveOrUpdate(commonName
);
149 newNode
= FeatureNode
.NewInstance(commonName
);
150 root
.addChild(newNode
);
152 Feature notes
= Feature
.NOTES();
153 rep
= Representation
.NewInstance("Notas", "Notas", null, Language
.SPANISH_CASTILIAN());
154 notes
.addRepresentation(rep
);
155 app
.getTermService().saveOrUpdate(notes
);
156 newNode
= FeatureNode
.NewInstance(notes
);
157 root
.addChild(newNode
);
165 public static void main(String
[] args
) {
166 MexicoBorhidiActivator borhidi
= new MexicoBorhidiActivator();
167 borhidi
.doImport(cdmDestination
);
169 MexicoConabioActivator conabio
= new MexicoConabioActivator();
170 conabio
.doImport(cdmDestination
);