1
|
/**
|
2
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.cdm.app.mexico;
|
10
|
|
11
|
import java.net.URI;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
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;
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
* @date 16.06.2016
|
39
|
*
|
40
|
*/
|
41
|
public class MexicoConabioActivator {
|
42
|
private static final Logger logger = Logger.getLogger(MexicoConabioActivator.class);
|
43
|
|
44
|
//database validation status (create, update, validate ...)
|
45
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
46
|
|
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();
|
50
|
|
51
|
static final boolean doTaxa = true;
|
52
|
static final boolean doDistributions = true;
|
53
|
static final boolean doCommonNames = true;
|
54
|
|
55
|
//feature tree uuid
|
56
|
public static final UUID featureTreeUuid = UUID.fromString("d1f4ed29-9aae-4f6e-aa1e-4a3bf780e11d");
|
57
|
|
58
|
//classification
|
59
|
static final UUID classificationUuid = UUID.fromString("61968b43-e881-4043-b5c2-ba192e8f72dc");
|
60
|
private static final String classificationName = "Rubiaceae Conabio";
|
61
|
|
62
|
//check - import
|
63
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
64
|
|
65
|
private void doImport(ICdmDataSource cdmDestination){
|
66
|
|
67
|
URI source = conabio_rubiaceae();
|
68
|
|
69
|
//make Source
|
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);
|
78
|
|
79
|
config.setSource(source);
|
80
|
String fileName = source.toString();
|
81
|
fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
|
82
|
|
83
|
String message = "Start import from ("+ fileName + ") ...";
|
84
|
System.out.println(message);
|
85
|
logger.warn(message);
|
86
|
|
87
|
config.setSourceReference(getSourceReference());
|
88
|
config.setSecReference(getSecReference());
|
89
|
|
90
|
CdmDefaultImport<MexicoConabioImportConfigurator> myImport = new CdmDefaultImport<MexicoConabioImportConfigurator>();
|
91
|
|
92
|
myImport.invoke(config);
|
93
|
|
94
|
if (true){
|
95
|
FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController());
|
96
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
97
|
}
|
98
|
|
99
|
System.out.println("End import from ("+ source.toString() + ")...");
|
100
|
}
|
101
|
|
102
|
|
103
|
//Conabio Rubiaceae
|
104
|
public static URI conabio_rubiaceae() {
|
105
|
return URI.create("file:////BGBM-PESIHPC/Mexico/CONABIO-Rubiaceae.xlsx");
|
106
|
}
|
107
|
|
108
|
private Reference getSourceReference() {
|
109
|
Reference result = ReferenceFactory.newDatabase();
|
110
|
result.setTitleCache("CONABIO database", true);
|
111
|
TimePeriod tp = TimePeriodParser.parseString("2016");
|
112
|
tp.setStartMonth(5);
|
113
|
result.setDatePublished(tp);
|
114
|
Institution inst = Institution.NewNamedInstance("CONABIO");
|
115
|
result.setInstitution(inst);
|
116
|
return result;
|
117
|
}
|
118
|
|
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);
|
128
|
return result;
|
129
|
}
|
130
|
|
131
|
private FeatureTree makeFeatureNodes(ICdmRepository app){
|
132
|
|
133
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
134
|
result.setTitleCache("Mexico Rubiaceae Feature Tree", true);
|
135
|
FeatureNode root = result.getRoot();
|
136
|
FeatureNode newNode;
|
137
|
|
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);
|
144
|
|
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);
|
151
|
|
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);
|
158
|
|
159
|
return result;
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* @param args
|
164
|
*/
|
165
|
public static void main(String[] args) {
|
166
|
MexicoBorhidiActivator borhidi = new MexicoBorhidiActivator();
|
167
|
borhidi.doImport(cdmDestination);
|
168
|
|
169
|
MexicoConabioActivator conabio = new MexicoConabioActivator();
|
170
|
conabio.doImport(cdmDestination);
|
171
|
System.exit(0);
|
172
|
}
|
173
|
}
|