Project

General

Profile

Download (3.76 KB) Statistics
| Branch: | Revision:
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.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.app.common.CdmDestinations;
17
import eu.etaxonomy.cdm.common.URI;
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.common.ImportResult;
24
import eu.etaxonomy.cdm.io.fact.categorical.in.CategoricalDataExcelImportConfigurator;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28

    
29
/**
30
 * Import for Flora of Uzbekistan habitats.
31
 *
32
 * https://dev.e-taxonomy.eu/redmine/issues/9049
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_uzbekistan();
46
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_uzbekistan();
47

    
48
    static DbSchemaValidation hbm2dll = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE;
49

    
50
    static final String fileName = "FoU_template_habitats_final.xlsx";
51

    
52
    static final UUID uuidHabitat = Feature.uuidHabitat;
53
    static final UUID uuidStateVocabulary = UUID.fromString("8c06bc6c-8f06-421d-990b-4faf6bf5840e");
54
    static final String stateVocabularyLabel = "Flora of Uzbekistan habitat states";
55

    
56
    static final UUID uuidSourceRef = UUID.fromString("6278112a-67c3-4ddf-9a81-2f8c1915d52a");
57

    
58
    //check - import
59
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
60

    
61
    private void doImport(ICdmDataSource cdmDestination){
62

    
63
        //make Source
64
        URI source = fileName();
65
//        URI source = uzbekistanChecklist_local();
66

    
67
        CategoricalDataExcelImportConfigurator config = CategoricalDataExcelImportConfigurator.NewInstance(source, cdmDestination);
68
        config.setCheck(check);
69
        config.setDbSchemaValidation(hbm2dll);
70
        config.setFeatureUuid(uuidHabitat);
71
        config.setStateVocabularyUuid(uuidStateVocabulary);
72
        config.setStateVocabularyLabel(stateVocabularyLabel);
73
        config.setSourceReference(getSourceReference());
74

    
75
        CdmDefaultImport<CategoricalDataExcelImportConfigurator> myImport = new CdmDefaultImport<>();
76
        ImportResult result = myImport.invoke(config);
77
        System.out.println(result.createReport());
78
    }
79

    
80
    private URI fileName(){
81
        return URI.create("file:////BGBM-PESIHPC/Uzbekistan/" + fileName);
82
    }
83
    @SuppressWarnings("unused")
84
    private URI fileName_local(){
85
        File file = new File("C:\\Users\\a.mueller\\BGBM\\Data\\Uzbekistan\\" + fileName);
86
        return URI.fromFile(file);
87
    }
88

    
89
    private Reference getSourceReference(){
90
        Reference result = ReferenceFactory.newGeneric();
91
        result.setTitle(fileName);
92
        result.setUuid(uuidSourceRef);
93
        return result;
94
    }
95

    
96
    public static void main(String[] args) {
97
        UzbekistanHabitatActivator me = new UzbekistanHabitatActivator();
98
        me.doImport(cdmDestination);
99
        System.exit(0);
100
    }
101
}
(3-3/5)