1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.cdm.app.mexico;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
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.model.agent.Person;
|
24
|
import eu.etaxonomy.cdm.model.description.Feature;
|
25
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
26
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
* @date 16.06.2016
|
34
|
*
|
35
|
*/
|
36
|
public class MexicoConabioActivator {
|
37
|
private static final Logger logger = Logger.getLogger(MexicoConabioActivator.class);
|
38
|
|
39
|
//database validation status (create, update, validate ...)
|
40
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
41
|
|
42
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
43
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
44
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_mexico_rubiaceae_production();
|
45
|
|
46
|
static final boolean doTaxa = true;
|
47
|
static final boolean doDistributions = true;
|
48
|
static final boolean doCommonNames = true;
|
49
|
|
50
|
//feature tree uuid
|
51
|
public static final UUID featureTreeUuid = UUID.fromString("d1f4ed29-9aae-4f6e-aa1e-4a3bf780e11d");
|
52
|
|
53
|
//classification
|
54
|
static final UUID classificationUuid = UUID.fromString("61968b43-e881-4043-b5c2-ba192e8f72dc");
|
55
|
private static final String classificationName = "Rubiaceae Conabio";
|
56
|
|
57
|
static final String sourceReferenceTitle = "OchaXXX";
|
58
|
|
59
|
//check - import
|
60
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
61
|
|
62
|
private void doImport(ICdmDataSource cdmDestination){
|
63
|
|
64
|
URI source = conabio_rubiaceae();
|
65
|
|
66
|
//make Source
|
67
|
MexicoConabioImportConfigurator config= MexicoConabioImportConfigurator.NewInstance(source, cdmDestination);
|
68
|
config.setClassificationUuid(classificationUuid);
|
69
|
config.setClassificationName(classificationName);
|
70
|
config.setCheck(check);
|
71
|
config.setDoTaxa(doTaxa);
|
72
|
config.setDoDistributions(doDistributions);
|
73
|
config.setDoCommonNames(doCommonNames);
|
74
|
config.setDbSchemaValidation(hbm2dll);
|
75
|
config.setSourceReferenceTitle(sourceReferenceTitle);
|
76
|
|
77
|
config.setSource(source);
|
78
|
String fileName = source.toString();
|
79
|
fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
|
80
|
|
81
|
String message = "Start import from ("+ fileName + ") ...";
|
82
|
System.out.println(message);
|
83
|
logger.warn(message);
|
84
|
|
85
|
config.setSourceReference(getSourceReference(sourceReferenceTitle));
|
86
|
|
87
|
CdmDefaultImport<MexicoConabioImportConfigurator> myImport = new CdmDefaultImport<MexicoConabioImportConfigurator>();
|
88
|
|
89
|
myImport.invoke(config);
|
90
|
|
91
|
if (true){
|
92
|
FeatureTree tree = makeFeatureNodes();
|
93
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
94
|
}
|
95
|
|
96
|
System.out.println("End import from ("+ source.toString() + ")...");
|
97
|
|
98
|
}
|
99
|
|
100
|
|
101
|
//Conabio Rubiaceae
|
102
|
public static URI conabio_rubiaceae() {
|
103
|
return URI.create("file:////BGBM-PESIHPC/Mexico/CONABIO-Rubiaceae.xlsx");
|
104
|
}
|
105
|
|
106
|
private Reference getSourceReference(String string) {
|
107
|
Reference result = ReferenceFactory.newGeneric();
|
108
|
result.setTitleCache(string, true);
|
109
|
// result.setTitle("Rubiáceas de México");
|
110
|
// result.setPlacePublished("Budapest");
|
111
|
// result.setPublisher("Akadémiai Kiadó");
|
112
|
// result.setPages("512 pp.");
|
113
|
result.setDatePublished(TimePeriodParser.parseString("2016"));
|
114
|
Person author = Person.NewTitledInstance(string);
|
115
|
author.setFirstname("Helga");
|
116
|
result.setAuthorship(author);
|
117
|
// result.setUuid(MexicoConabioTransformer.uuidReferenceBorhidi);
|
118
|
return result;
|
119
|
}
|
120
|
|
121
|
private FeatureTree makeFeatureNodes(){
|
122
|
|
123
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
124
|
result.setTitleCache("Mexico Rubiaceae Feature Tree", true);
|
125
|
FeatureNode root = result.getRoot();
|
126
|
FeatureNode newNode;
|
127
|
|
128
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
129
|
root.addChild(newNode);
|
130
|
|
131
|
newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
132
|
root.addChild(newNode);
|
133
|
|
134
|
return result;
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* @param args
|
139
|
*/
|
140
|
public static void main(String[] args) {
|
141
|
MexicoBorhidiActivator borhidi = new MexicoBorhidiActivator();
|
142
|
borhidi.doImport(cdmDestination);
|
143
|
|
144
|
MexicoConabioActivator conabio = new MexicoConabioActivator();
|
145
|
conabio.doImport(cdmDestination);
|
146
|
System.exit(0);
|
147
|
}
|
148
|
}
|