ref #7664 adapt app-import to typified return types
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / wp6 / cichorieae / CichorieaeCacheUpdater.java
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.wp6.cichorieae;
11
12 import java.util.Arrays;
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.app.common.CdmDestinations;
18 import eu.etaxonomy.cdm.database.DbSchemaValidation;
19 import eu.etaxonomy.cdm.database.ICdmDataSource;
20 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
21 import eu.etaxonomy.cdm.io.common.ImportResult;
22 import eu.etaxonomy.cdm.io.operation.config.CacheUpdaterConfigurator;
23 import eu.etaxonomy.cdm.model.name.TaxonName;
24 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
25
26
27 /**
28 * TODO add the following to a wiki page:
29 * HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
30 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
31 *
32 *
33 * @author a.mueller
34 *
35 */
36 public class CichorieaeCacheUpdater {
37 private static final Logger logger = Logger.getLogger(CichorieaeCacheUpdater.class);
38
39 //database validation status (create, update, validate ...)
40 static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
41 static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_cichorieae();
42
43 static final List<String> classListStrings = Arrays.asList(new String[]{
44 //IdentifiableEntity.class.getName(),
45 // IdentifiableEntity.class.getName(),
46 TaxonName.class.getName(),
47 TaxonBase.class.getName()
48 });
49 //new ArrayList<Class<? extends IdentifiableEntity>>();
50
51 // **************** ALL *********************
52
53 // //DescriptionBase
54 // static final boolean doTaxonDescription = true;
55 // static final boolean doSpecimenDescription = true;
56 // static final boolean doNameDescription = true;
57 //
58 // //AgentBase
59 // static final boolean doPerson = true;
60 // static final boolean doTeam = true;
61 // static final boolean doInstitution = true;
62 //
63 // //MediaEntities
64 // static final boolean doCollection = true;
65 // static final boolean doReferenceBase = true;
66 //
67 // //SpecimenOrObservationBase
68 // static final boolean doFieldObservation = true;
69 // static final boolean doDeriveUnit = true;
70 // static final boolean doLivingBeing = true;
71 // static final boolean doObservation = true;
72 // static final boolean doSpecimen = true;
73 //
74 // //Media
75 // static final boolean doMedia = true;
76 // static final boolean doMediaKey = true;
77 // static final boolean doFigure = true;
78 // static final boolean doPhylogenticTree = true;
79 //
80 //
81 // //TaxonBase
82 // static final boolean doTaxon = true;
83 // static final boolean doSynonym = true;
84 //
85 // static final boolean doSequence = true;
86 //
87 // //Names
88 // static final boolean doViralName = true;
89 // static final boolean doNonViralName = true;
90 // static final boolean doBotanicalName = true;
91 // static final boolean doZoologicalName = true;
92 // static final boolean doCultivarPlantName = true;
93 //
94 // static final boolean doClassification = true;
95 //
96 // //TermBase
97 // static final boolean doFeatureTree = true;
98 // static final boolean doPolytomousKey = true;
99 //
100 // static final boolean doTermVocabulary = true;
101 // static final boolean doDefinedTermBase = true;
102 //
103
104
105 private ImportResult doInvoke(ICdmDataSource destination){
106 ImportResult success;
107
108 CacheUpdaterConfigurator config;
109 try {
110 config = CacheUpdaterConfigurator.NewInstance(destination, classListStrings);
111
112 // invoke import
113 CdmDefaultImport<CacheUpdaterConfigurator> myImport = new CdmDefaultImport<CacheUpdaterConfigurator>();
114 success = myImport.invoke(config);
115 String successString = success.isSuccess() ? "successful" : " with errors ";
116 System.out.println("End updating caches for "+ destination.getDatabase() + "..." + successString);
117 return success;
118 } catch (ClassNotFoundException e) {
119 logger.error(e);
120 success = new ImportResult();
121 success.addException(e);
122 return success;
123 }
124 }
125
126 /**
127 * @param args
128 */
129 public static void main(String[] args) {
130 ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
131
132 System.out.println("Start updating caches for "+ destination.getDatabase() + "...");
133 CichorieaeCacheUpdater me = new CichorieaeCacheUpdater();
134 me.doInvoke(destination);
135
136 }
137
138 }