Project

General

Profile

Download (4.27 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.app.phycobank;
11

    
12
import eu.etaxonomy.cdm.common.URI;
13
import java.util.Date;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.app.common.CdmDestinations;
19
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
20
import eu.etaxonomy.cdm.database.DbSchemaValidation;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
24
import eu.etaxonomy.cdm.io.phycobank.PhycobankHigherClassificationImportConfigurator;
25
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
29

    
30

    
31
/**
32
 * Activator to import phycobank higher classifications.
33
 * @author a.mueller
34
 * @since 2018-08-09
35
 */
36
public class PhycobankHigherClassificationActivator {
37
    @SuppressWarnings("unused")
38
    private static final Logger logger = Logger.getLogger(PhycobankHigherClassificationActivator.class);
39

    
40

    
41
    // ====================================================================================
42

    
43
    //database validation status (create, update, validate ...)
44
    static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;  //
45

    
46
//    static ICdmDataSource cdmDestination = CdmDestinations.localH2();
47
//    static ICdmDataSource cdmDestination = CdmDestinations.cdm_local_test_mysql();
48
//    static ICdmDataSource cdmDestination = CdmDestinations.cdm_test_phycobank();
49
    static ICdmDataSource cdmDestination = CdmDestinations.cdm_phycobank_production();
50

    
51
    static String worksheetName = "Syllabus2_1";
52

    
53
    static UUID uuidRefPhycobank = UUID.fromString("8058a5ec-60ee-4a04-8c17-5623e3a4795c");
54

    
55
    //check - import
56
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
57

    
58

    
59
    private void doImport(ICdmDataSource cdmDestination){
60
        hbm2dll = (cdmDestination == CdmDestinations.cdm_phycobank_production()|| cdmDestination == CdmDestinations.cdm_test_phycobank())?
61
                DbSchemaValidation.VALIDATE : hbm2dll;
62

    
63
        URI source = fileURI();
64
        Reference sourceRef = getSourceReference();
65

    
66
        //make Source
67
        PhycobankHigherClassificationImportConfigurator config= PhycobankHigherClassificationImportConfigurator.NewInstance(source, cdmDestination);
68
        config.setWorksheetName(worksheetName);
69
        config.setCheck(check);
70
        config.setDbSchemaValidation(hbm2dll);
71
        config.setSourceReference(sourceRef);
72
        config.setPhycobankReference(getPhycobankReference());
73
        config.setProgressMonitor(DefaultProgressMonitor.NewInstance());
74

    
75
        CdmDefaultImport<PhycobankHigherClassificationImportConfigurator> myImport = new CdmDefaultImport<>();
76
        myImport.invoke(config);
77

    
78
        System.exit(0);
79
    }
80

    
81
    private static Reference getPhycobankReference() {
82
        Reference result = ReferenceFactory.newWebPage();
83
        result.setTitle("Phycobank");
84
        result.setDatePublished(TimePeriodParser.parseStringVerbatim("2018+"));
85
        result.setUri(URI.create("https://www.phycobank.org/"));
86
        result.setUuid(uuidRefPhycobank);
87
        return result;
88
    }
89

    
90
    private Reference getSourceReference() {
91
        Reference result = ReferenceFactory.newDatabase();
92
        result.setTitle("Higher classification Excel import: " + fileName());
93
        result.setUri(fileURI());
94
        result.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(new Date(), null));
95
        return result;
96
    }
97

    
98
    public static String fileName(){
99
        return "Algen_Syllabus_Produktion_2019-01-08_Import_2.xlsx";
100
    }
101
    public static String filePath(){
102
        return "file:////BGBM-PESIHPC/Phycobank/";
103
    }
104

    
105
    public static URI fileURI() {
106
        return URI.create(filePath() + fileName());
107
    }
108

    
109
    /**
110
     * @param args
111
     */
112
    public static void main(String[] args) {
113
        PhycobankHigherClassificationActivator me = new PhycobankHigherClassificationActivator();
114
        me.doImport(cdmDestination);
115
    }
116

    
117
}
(2-2/2)