2 * Copyright (C) 2022 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.app
.additivity
;
11 import java
.util
.Collection
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.apache
.logging
.log4j
.LogManager
;
16 import org
.apache
.logging
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
19 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
20 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
21 import eu
.etaxonomy
.cdm
.filter
.VocabularyFilter
;
22 import eu
.etaxonomy
.cdm
.io
.cdm2cdm
.Cdm2CdmImportConfigurator
;
23 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.term
.VocabularyEnum
;
32 public class OntologyExportActivator
{
34 @SuppressWarnings("unused")
35 private static final Logger logger
= LogManager
.getLogger();
37 static final ICdmDataSource source
= CdmDestinations
.cdm_local_terms();
38 // static final ICdmDataSource source = CdmDestinations.cdm_production_cdmterms();
40 static final ICdmDataSource destination
= CdmDestinations
.cdm_local_greece();
41 // static final ICdmDataSource destination = CdmDestinations.cdm_local_cichorieae();
43 // static final ICdmDataSource destination = CdmDestinations.cdm_production_greece_checklist();
44 // static final ICdmDataSource destination = CdmDestinations.cdm_production_cichorieae();
46 static final DbSchemaValidation schemaValidation
= DbSchemaValidation
.VALIDATE
;
49 static final boolean updateExistingTermCollections
= true;
52 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
54 static final boolean doVocabularies
= true;
55 static final boolean addSources
= false;
56 static final boolean removeImportSources
= true;
57 static final boolean externallyManaged
= true;
60 static final boolean doTaxa
= false;
61 static final boolean doDescriptions
= false;
62 static final boolean doConcurrent
= false;
63 static final boolean registerAuditing
= true;
66 // ***************** ALL ************************************************//
68 // UUID uuidBupleurumTaxonNodeFilter = UUID.fromString("51e768cf-321b-4108-8bee-46143996b033");
70 private void doImport(ICdmDataSource source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
72 String importFrom
= " import from "+ source
.getDatabase() + " to "+ destination
.getDatabase() + " ...";
73 System
.out
.println("Start"+importFrom
);
75 Cdm2CdmImportConfigurator config
= Cdm2CdmImportConfigurator
.NewInstace(source
, destination
);
76 VocabularyFilter vocFilter
= VocabularyFilter
.NewInstance();
78 addVocFilters(vocFilter
, VocabularyEnum
.ontologyModifierVocabularyUuids());
79 config
.setVocabularyFilter(vocFilter
);
80 //structures, properties and states
81 Collection
<UUID
> graphFilter
= getGraphFilter();
82 config
.setGraphFilter(graphFilter
);
84 config
.setDoTaxa(doTaxa
);
85 config
.setDoDescriptions(doDescriptions
);
86 config
.setDoVocabularies(doVocabularies
);
88 config
.setAddSources(addSources
);
89 config
.setSourceReference(getSourceRefNull());
90 config
.setRemoveImportSources(removeImportSources
);
91 config
.setAddMissingTerms(updateExistingTermCollections
);
93 config
.setExternallyManaged(externallyManaged
);
95 config
.setDbSchemaValidation(hbm2dll
);
96 // config.getTaxonNodeFilter().orSubtree(uuidBupleurumTaxonNodeFilter);
97 // config.getTaxonNodeFilter().setOrder(ORDER.TREEINDEX);
99 config
.setCheck(check
);
101 config
.setRegisterAuditing(registerAuditing
);
104 CdmDefaultImport
<Cdm2CdmImportConfigurator
> myImport
= new CdmDefaultImport
<>();
105 myImport
.invoke(config
);
107 System
.out
.println("End" + importFrom
);
110 private List
<UUID
> getGraphFilter() {
111 return VocabularyEnum
.ontologyTreeUuids();
114 private void addVocFilters(VocabularyFilter vocFilter
, List
<UUID
> vocUuids
) {
115 for (UUID vocUuid
: vocUuids
) {
116 vocFilter
.orVocabulary(vocUuid
);
120 private Reference
getSourceRefNull() {
123 // private Reference getSourceRef() {
124 // Reference ref = ReferenceFactory.newDatabase();
125 // ref.setTitle(sourceRefTitle);
126 // ref.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(Calendar.getInstance()));
127 // ref.setUuid(sourceRefUuid);
131 public static void main(String
[] args
) {
132 ICdmDataSource cdmDB
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : destination
;
133 OntologyExportActivator myImport
= new OntologyExportActivator();
134 myImport
.doImport(source
, cdmDB
, schemaValidation
);