Project

General

Profile

Download (5.58 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 java.net.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.agent.Person;
26
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
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
/**
33
 * Activator to import phycobank higher classifications.
34
 * @author a.mueller
35
 * @since 2018-08-09
36
 */
37
public class PhycobankHigherClassificationActivator {
38
    @SuppressWarnings("unused")
39
    private static final Logger logger = Logger.getLogger(PhycobankHigherClassificationActivator.class);
40

    
41

    
42
    // ====================================================================================
43

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

    
47
    static ICdmDataSource cdmDestination = CdmDestinations.localH2();
48
//    static ICdmDataSource cdmDestination = CdmDestinations.cdm_local_test_mysql();
49
//    static ICdmDataSource cdmDestination = CdmDestinations.cdm_test_phycobank();
50
//TODO: Die 3 Syllabus noch richtig als 3 Referenzen anlegen (muss Henning machen), hier dann die jeweilige UUID
51
// verwenden und unten den worksheetNamen entsprechend anpassen
52
    static Reference secRef = getSecReference_Frey();
53
//    static Reference secRef = getSecReference_WoRMS();
54
//    static String worksheetName = secRef.equals(getSecReference_WoRMS())? "WoRMS" :
55
//        secRef.equals(getSecReference_Frey())? "HigherRanksEntwurfNeu" : null;
56
    static String worksheetName = "Syllabus2_1";
57

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

    
60
    //check - import
61
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
62

    
63
    private void doImport(ICdmDataSource cdmDestination){
64

    
65
        URI source = fileURI();
66
        Reference sourceRef = getSourceReference();
67

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

    
78
        CdmDefaultImport<PhycobankHigherClassificationImportConfigurator> myImport = new CdmDefaultImport<>();
79
        myImport.invoke(config);
80

    
81
        System.exit(0);
82

    
83
    }
84

    
85
    private static Reference getSecReference_Frey() {
86
        Reference result = ReferenceFactory.newBook();
87
        result.setTitle("Syllabus of the plant families");
88
        result.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2015));
89
        result.setPublisher("Borntraeger");
90
        result.setPlacePublished("Stuttgart");
91
        Person author = Person.NewInstance();
92
        author.setFamilyName("Frey");
93
        author.setInitials("W.");
94
        result.setAuthorship(author);
95
        result.setUuid(UUID.fromString("2b4a3a67-e432-4d6b-b716-081045179df9"));
96
        return result;
97
    }
98

    
99
    private static Reference getSecReference_WoRMS() {
100
        Reference result = ReferenceFactory.newDatabase();
101
        result.setTitle("WoRMS World Register of Marine Species");
102
        result.setDatePublished(TimePeriodParser.parseStringVerbatim("2018-04-20"));
103
        result.setUri(URI.create("http://www.marinespecies.org/index.php"));
104
        result.setUuid(UUID.fromString("b33daeb0-8770-4ee2-92d0-80aaa87bfba2"));
105
        return result;
106
    }
107

    
108
    private static Reference getPhycobankReference() {
109
        Reference result = ReferenceFactory.newWebPage();
110
        result.setTitle("Phycobank");
111
        result.setDatePublished(TimePeriodParser.parseStringVerbatim("2018+"));
112
        result.setUri(URI.create("https://www.phycobank.org/"));
113
        result.setUuid(uuidRefPhycobank);
114
        return result;
115
    }
116

    
117
    private Reference getSourceReference() {
118
        Reference result = ReferenceFactory.newDatabase();
119
        result.setTitle("Higher classification Excel import: " + fileName());
120
        result.setUri(fileURI());
121
        result.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(new Date(), null));
122
        return result;
123
    }
124

    
125
    public static String fileName(){
126
//        return "Algen_Syllabus_NormalImplied_Test.xlsx";
127
        return "Algen_Syllabus_Produktion_corr.xlsx";
128
    }
129
    public static String filePath(){
130
        return "file:////BGBM-PESIHPC/Phycobank/";
131
    }
132

    
133
    public static URI fileURI() {
134
        return URI.create(filePath() + fileName());
135
    }
136

    
137
    /**
138
     * @param args
139
     */
140
    public static void main(String[] args) {
141
        PhycobankHigherClassificationActivator me = new PhycobankHigherClassificationActivator();
142
        me.doImport(cdmDestination);
143
    }
144

    
145
}
(2-2/2)