bc116c84f92d3e77b7657b1f5544ff1b242641e0
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / caryophyllales / NonReferencedObjectsDeleteActivator.java
1 /**
2 * Copyright (C) 2017 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.caryophyllales;
10
11 import org.apache.logging.log4j.LogManager;
12 import org.apache.logging.log4j.Logger;
13
14 import eu.etaxonomy.cdm.app.common.CdmDestinations;
15 import eu.etaxonomy.cdm.database.DbSchemaValidation;
16 import eu.etaxonomy.cdm.database.ICdmDataSource;
17 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
18 import eu.etaxonomy.cdm.io.common.ImportResult;
19 import eu.etaxonomy.cdm.io.operation.NonReferencedObjectsDeleterConfigurator;
20
21 /**
22 * @author k.luther
23 * @since 2015
24 */
25 public class NonReferencedObjectsDeleteActivator {
26
27 @SuppressWarnings("unused")
28 private static final Logger logger = LogManager.getLogger();
29
30 //database validation status (create, update, validate ...)
31 static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
32 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_caryo();
33 static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_caryophyllales_spp();
34
35 boolean doAuthors = true;
36 boolean doReferences = true;
37
38 private ImportResult doInvoke(ICdmDataSource destination){
39 ImportResult result = new ImportResult();
40
41 NonReferencedObjectsDeleterConfigurator config = NonReferencedObjectsDeleterConfigurator.NewInstance(destination);
42 config.setDbSchemaValidation(hbm2dll);
43 config.setDoReferences(doReferences);
44 config.setDoAuthors(doAuthors);
45
46 // invoke import
47 CdmDefaultImport<NonReferencedObjectsDeleterConfigurator> myImport = new CdmDefaultImport<>();
48 result = myImport.invoke(config);
49 System.out.println(result.getReports());
50 return result;
51 }
52
53 public static void main(String[] args) {
54 ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
55
56 System.out.println("Start deleting non referenced objects for "+ destination.getDatabase() + "...");
57 NonReferencedObjectsDeleteActivator me = new NonReferencedObjectsDeleteActivator();
58 me.doInvoke(destination);
59 System.exit(0);
60 }
61 }