Project

General

Profile

Download (4.53 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.iapt;
11

    
12
import java.io.File;
13
import java.net.URI;
14
import java.util.UUID;
15

    
16
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
17
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
18
import org.apache.log4j.Appender;
19
import org.apache.log4j.Logger;
20

    
21
import eu.etaxonomy.cdm.app.common.CdmDestinations;
22
import eu.etaxonomy.cdm.database.DbSchemaValidation;
23
import eu.etaxonomy.cdm.database.ICdmDataSource;
24
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
25
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
26
import eu.etaxonomy.cdm.io.iapt.IAPTImportConfigurator;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import org.apache.log4j.RollingFileAppender;
30

    
31

    
32
/**
33
 * @author a.kohlbecker
34
 * @date Jul 26, 2016
35
 *
36
 */
37
public class IAPTActivator {
38
    private static final Logger logger = Logger.getLogger(IAPTActivator.class);
39

    
40
    //database validation status (create, update, validate ...)
41
    static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
42

    
43
    static ICdmDataSource cdmDestination = null;
44
    static {
45
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
46
        String cdmServer = "127.0.0.1";
47
        String cdmDB = "cdm_algea_registry";
48
        String cdmUserName = "edit";
49
        cdmDestination =  CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
50
        // cdmDestination = CdmDestinations.localH2();
51
    }
52

    
53
    static boolean invers = true;
54

    
55
    static boolean include = !invers;
56

    
57
    //classification
58
    static final UUID classificationUuid = UUID.fromString("8c51efb4-3d67-4bea-8f87-4bc1cba1310d");
59
    private static final String classificationName = "IAPT";
60
    static final String sourceReferenceTitle = "IAPT Import";
61

    
62
    //check - import
63
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
64

    
65
    static final boolean doTaxa = false;
66

    
67

    
68
    private void doImport(ICdmDataSource cdmDestination){
69

    
70
        URI source = iapt();  //just any
71

    
72
        Reference secRef = ReferenceFactory.newDatabase();
73
        secRef.setTitle("IAPT");
74

    
75
        //make Source
76
        IAPTImportConfigurator config= IAPTImportConfigurator.NewInstance(source, cdmDestination);
77
        config.setClassificationUuid(classificationUuid);
78
        config.setClassificationName(classificationName);
79
        config.setCheck(check);
80
        config.setDbSchemaValidation(hbm2dll);
81
        config.setSourceReferenceTitle(sourceReferenceTitle);
82
        config.setSecReference(secRef);
83
        config.setProgressMonitor(DefaultProgressMonitor.NewInstance());
84
        // config.setBatchSize(100); // causes Error during managed flush [Don't change the reference to a collection with delete-orphan enabled : eu.etaxonomy.cdm.model.taxon.TaxonNode.annotations]
85

    
86
        CdmDefaultImport<IAPTImportConfigurator> myImport = new CdmDefaultImport<>();
87

    
88
        doSingleSource(iapt(), config, myImport);
89

    
90
        System.exit(0);
91

    
92
    }
93

    
94
    /**
95
     * @param source
96
     * @param config
97
     * @param myImport
98
     */
99
    private void doSingleSource(URI source, IAPTImportConfigurator config, CdmDefaultImport<IAPTImportConfigurator> myImport) {
100
        config.setSource(source);
101
        String fileName = source.toString();
102
        fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
103

    
104
        String message = "Start import from ("+ fileName + ") ...";
105
        System.out.println(message);
106
        logger.warn(message);
107
        config.setSourceReference(getSourceReference(fileName));
108
        myImport.invoke(config);
109

    
110
        System.out.println("End import from ("+ source.toString() + ")...");
111
    }
112

    
113
    private final Reference inRef = ReferenceFactory.newGeneric();
114
    private Reference getSourceReference(String string) {
115
        Reference result = ReferenceFactory.newGeneric();
116
        result.setTitleCache(string, true);
117
        result.setInReference(inRef);
118
        inRef.setTitleCache(sourceReferenceTitle, true);
119
        return result;
120
    }
121

    
122

    
123

    
124
    public static URI iapt() {
125
        File f = new File(System.getProperty("user.home") + "/data/Projekte/Algea Name Registry/registry/sources/IAPT/iapt-100.xls");
126
        return f.toURI();
127
    }
128

    
129
    /**
130
     * @param args
131
     */
132
    public static void main(String[] args) {
133

    
134
        IAPTActivator me = new IAPTActivator();
135
        me.doImport(cdmDestination);
136
    }
137

    
138
}
    (1-1/1)