Revision 965ce443
Added by Andreas Müller about 4 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/uzbekistan/UzbekistanHabitatActivator.java | ||
---|---|---|
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.uzbekistan; |
|
10 |
|
|
11 |
import java.io.File; |
|
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.DatabaseTypeEnum; |
|
19 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
20 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
21 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
22 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
23 |
import eu.etaxonomy.cdm.io.fact.categorical.in.CategoricalDataExcelImportConfigurator; |
|
24 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
25 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
26 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* Import for Flora of Uzbekistan habitats. |
|
31 |
* |
|
32 |
* https://dev.e-taxonomy.eu/redmine/issues/9041 |
|
33 |
* |
|
34 |
* @author a.mueller |
|
35 |
* @since 28.05.2020 |
|
36 |
*/ |
|
37 |
public class UzbekistanHabitatActivator { |
|
38 |
|
|
39 |
@SuppressWarnings("unused") |
|
40 |
private static final Logger logger = Logger.getLogger(UzbekistanHabitatActivator.class); |
|
41 |
|
|
42 |
//database validation status (create, update, validate ...) |
|
43 |
|
|
44 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
45 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_cdmtest_mysql(); |
|
46 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_uzbekistan(); |
|
47 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_uzbekistan(); |
|
48 |
|
|
49 |
static DbSchemaValidation hbm2dll = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE; |
|
50 |
|
|
51 |
static final String fileName = "FoU_template_habitats_final.xlsx"; |
|
52 |
|
|
53 |
static final UUID uuidHabitat = Feature.uuidHabitat; |
|
54 |
static final UUID uuidStateVocabulary = UUID.fromString("8c06bc6c-8f06-421d-990b-4faf6bf5840e"); |
|
55 |
static final String stateVocabularyLabel = "Flora of Uzbekistan habitat states"; |
|
56 |
|
|
57 |
static final UUID uuidSourceRef = UUID.fromString("6278112a-67c3-4ddf-9a81-2f8c1915d52a"); |
|
58 |
|
|
59 |
//check - import |
|
60 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
|
61 |
|
|
62 |
private void doImport(ICdmDataSource cdmDestination){ |
|
63 |
|
|
64 |
//make Source |
|
65 |
URI source = fileName(); |
|
66 |
// URI source = uzbekistanChecklist_local(); |
|
67 |
|
|
68 |
CategoricalDataExcelImportConfigurator config = CategoricalDataExcelImportConfigurator.NewInstance(source, cdmDestination); |
|
69 |
config.setCheck(check); |
|
70 |
config.setDbSchemaValidation(hbm2dll); |
|
71 |
config.setFeatureUuid(uuidHabitat); |
|
72 |
config.setStateVocabularyUuid(uuidStateVocabulary); |
|
73 |
config.setStateVocabularyLabel(stateVocabularyLabel); |
|
74 |
config.setSourceReference(getSourceReference()); |
|
75 |
|
|
76 |
CdmDefaultImport<CategoricalDataExcelImportConfigurator> myImport = new CdmDefaultImport<>(); |
|
77 |
myImport.invoke(config); |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
private URI fileName(){ |
|
82 |
return URI.create("file:////BGBM-PESIHPC/Uzbekistan/" + fileName); |
|
83 |
} |
|
84 |
@SuppressWarnings("unused") |
|
85 |
private URI fileName_local(){ |
|
86 |
File file = new File("C:\\Users\\a.mueller\\BGBM\\Data\\Uzbekistan\\" + fileName); |
|
87 |
return file.toURI(); |
|
88 |
} |
|
89 |
|
|
90 |
private Reference getSourceReference(){ |
|
91 |
Reference result = ReferenceFactory.newGeneric(); |
|
92 |
result.setTitle(fileName); |
|
93 |
result.setUuid(uuidSourceRef); |
|
94 |
return result; |
|
95 |
} |
|
96 |
|
|
97 |
public static void main(String[] args) { |
|
98 |
UzbekistanHabitatActivator me = new UzbekistanHabitatActivator(); |
|
99 |
me.doImport(cdmDestination); |
|
100 |
System.exit(0); |
|
101 |
} |
|
102 |
} |
Also available in: Unified diff
ref #9049 add Fl. Uzbekistan habitat import activator