Project

General

Profile

« Previous | Next » 

Revision 1698cd08

Added by Andreas Müller over 1 year ago

ref #9771 add OntologyExportActivator

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/additivity/OntologyExportActivator.java
1
/**
2
* Copyright (C) 2022 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.additivity;
10

  
11
import java.util.UUID;
12

  
13
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.Logger;
15

  
16
import eu.etaxonomy.cdm.app.common.CdmDestinations;
17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18
import eu.etaxonomy.cdm.database.DbSchemaValidation;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.filter.VocabularyFilter;
21
import eu.etaxonomy.cdm.io.cdm2cdm.Cdm2CdmImportConfigurator;
22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25

  
26
/**
27
 * @author a.mueller
28
 * @since 31.08.2022
29
 */
30
public class OntologyExportActivator {
31

  
32
    @SuppressWarnings("unused")
33
    private static final Logger logger = LogManager.getLogger();
34

  
35
//    static final ICdmDataSource source = CdmDestinations.cdm_production_greece_bupleurum();
36
    static final ICdmDataSource source = CdmDestinations.cdm_local_greece_bupleurum();
37

  
38
    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_terms();
39
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_cdmtest_mysql();
40

  
41
//    static final String sourceRefTitle = "Flora of Greece";
42
//    static final UUID sourceRefUuid = UUID.fromString("f88e33e5-1f6a-463e-b6fd-220d5e93d810");
43

  
44
    static final DbSchemaValidation schemaValidation = DbSchemaValidation.VALIDATE;
45

  
46
    static final UUID uuidGenericStructures = UUID.fromString("4c13949e-50f5-461b-83df-21fec53437e8");
47
    static final UUID uuidTermporalModifiers = UUID.fromString("004a0b82-feb1-4c96-8542-26f72c740555");
48

  
49
    //check - import
50
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
51

  
52
    static final int partitionSize = 5000;
53

  
54
    static final boolean doVocabularies = true;
55
    static final boolean addSources = false;
56
    static final boolean removeImportSources = true;
57

  
58
    //defaults
59
    static final boolean doTaxa = false;
60
    static final boolean doDescriptions = false;
61
    static final boolean doConcurrent = false;
62
    static final boolean registerAuditing = true;
63

  
64
// ***************** ALL ************************************************//
65

  
66
//    UUID uuidBupleurumTaxonNodeFilter = UUID.fromString("51e768cf-321b-4108-8bee-46143996b033");
67

  
68
    private void doImport(ICdmDataSource source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
69

  
70
        String importFrom = " import from "+ source.getDatabase() + " to "+ destination.getDatabase() + " ...";
71
        System.out.println("Start"+importFrom);
72

  
73
        Cdm2CdmImportConfigurator config = Cdm2CdmImportConfigurator.NewInstace(source, destination);
74
        VocabularyFilter vocFilter = VocabularyFilter.NewInstance();
75
        vocFilter.orVocabulary(uuidGenericStructures);
76
//        vocFilter.orVocabulary(uuidTermporalModifiers);
77
        config.setVocabularyFilter(vocFilter);
78

  
79

  
80
        config.setDoTaxa(doTaxa);
81
        config.setDoDescriptions(doDescriptions);
82
        config.setDoVocabularies(doVocabularies);
83
        config.setAddSources(addSources);
84
        config.setSourceReference(getSourceRefNull());
85
        config.setRemoveImportSources(removeImportSources);
86

  
87
        IProgressMonitor monitor = config.getProgressMonitor();
88

  
89
        config.setDbSchemaValidation(hbm2dll);
90
//        config.getTaxonNodeFilter().orSubtree(uuidBupleurumTaxonNodeFilter);
91
//        config.getTaxonNodeFilter().setOrder(ORDER.TREEINDEX);
92

  
93
        config.setCheck(check);
94
//        config.setRecordsPerTransaction(partitionSize);
95

  
96
        config.setRegisterAuditing(registerAuditing);
97

  
98
        // invoke import
99
        CdmDefaultImport<Cdm2CdmImportConfigurator> myImport = new CdmDefaultImport<>();
100
        myImport.invoke(config);
101

  
102
        System.out.println("End" + importFrom);
103
    }
104

  
105

  
106
    private Reference getSourceRefNull() {
107
        return null;
108
    }
109
//    private Reference getSourceRef() {
110
//        Reference ref = ReferenceFactory.newDatabase();
111
//        ref.setTitle(sourceRefTitle);
112
//        ref.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(Calendar.getInstance()));
113
//        ref.setUuid(sourceRefUuid);
114
//        return ref;
115
//    }
116

  
117
    public static void main(String[] args) {
118
        ICdmDataSource cdmDB = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
119
        OntologyExportActivator myImport = new OntologyExportActivator();
120
        myImport.doImport(source, cdmDB, schemaValidation);
121
        System.exit(0);
122
    }
123
}
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java
97 97
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
98 98
    }
99 99

  
100
    public static ICdmDataSource cdm_local_terms(){
101
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
102
        String cdmServer = "127.0.0.1";
103
        String cdmDB = "cdm_local_terms";
104
        String cdmUserName = "edit";
105
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
106
    }
107

  
108
    public static ICdmDataSource cdm_local_greece_bupleurum(){
109
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
110
        String cdmServer = "127.0.0.1";
111
        String cdmDB = "cdm_local_greece_bupleurum";
112
        String cdmUserName = "edit";
113
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
114
    }
115

  
100 116
    public static ICdmDataSource cdm_local_uzbekistan(){
101 117
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
102 118
        String cdmServer = "127.0.0.1";
......
417 433
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
418 434
    }
419 435

  
436
    public static ICdmDataSource cdm_production_greece_bupleurum(){
437
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
438
        String cdmServer = "160.45.63.171";
439
        String cdmDB = "cdm_production_greece_bupleurum";
440
        String cdmUserName = "edit";
441
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
442
    }
443

  
420 444
    public static ICdmDataSource cdm_production_lichenes(){
421 445
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
422 446
        String cdmServer = "160.45.63.171";

Also available in: Unified diff