Project

General

Profile

Download (4.89 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.pesi;
11

    
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
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.IImportConfigurator.CHECK;
22
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
23
import eu.etaxonomy.cdm.io.common.Source;
24
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportConfigurator;
25
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
26
import eu.etaxonomy.cdm.model.common.ISourceable;
27
import eu.etaxonomy.cdm.model.name.ZoologicalName;
28

    
29

    
30
/**
31
 * TODO add the following to a wiki page:
32
 * 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 base under another operation systen 
33
 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
34
 * 
35
 * 
36
 * @author a.mueller
37
 *
38
 */
39
public class ErmsActivator {
40
	private static final Logger logger = Logger.getLogger(ErmsActivator.class);
41

    
42
	//database validation status (create, update, validate ...)
43
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
44
	static final Source ermsSource = PesiSources.PESI3_ERMS();
45
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_erms();
46
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_erms();
47
	static final UUID treeUuid = UUID.fromString("6fa988a9-10b7-48b0-a370-2586fbc066eb");
48
	
49
	//check - import
50
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
51

    
52
	static final int partitionSize = 5000;
53

    
54
	//ignore null
55
	static final boolean ignoreNull = true;
56
	
57
	static final boolean includeExport = true;
58
	
59
// ***************** ALL ************************************************//
60
	
61
	//references
62
	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
63
	
64
	//taxa
65
	static final boolean doTaxa = true;
66
	static final boolean doRelTaxa = true;
67
	static final boolean doLinks = true;
68
	static final boolean doOccurences = true;
69
	static final boolean doImages = true;
70
	
71
	
72
//******************** NONE ***************************************//
73
	
74

    
75
//	//references
76
//	static final DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
77
//	
78
//	//taxa
79
//	static final boolean doTaxa = false;
80
//	static final boolean doRelTaxa = false;
81
//	static final boolean doLinks = false;
82
//	static final boolean doOccurences = false;
83
//	
84
	
85
	
86
	private void doImport(Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
87
		System.out.println("Start import from ("+ ermsSource.getDatabase() + ") ...");
88
		
89
		//make ERMS Source
90
		
91
		ErmsImportConfigurator config = ErmsImportConfigurator.NewInstance(source,  destination);
92
		
93
		config.setClassificationUuid(treeUuid);
94
		
95
		config.setIgnoreNull(ignoreNull);
96
		config.setDoReferences(doReferences);
97
		
98
		config.setDoTaxa(doTaxa);
99
		config.setDoRelTaxa(doRelTaxa);
100
		config.setDoLinks(doLinks);
101
		config.setDoOccurrence(doOccurences);
102
		config.setDbSchemaValidation(hbm2dll);
103

    
104
		config.setCheck(check);
105
		config.setRecordsPerTransaction(partitionSize);
106
		config.setSourceRefUuid(PesiTransformer.uuidSourceRefErms);
107

    
108
		// invoke import
109
		CdmDefaultImport<ErmsImportConfigurator> ermsImport = new CdmDefaultImport<ErmsImportConfigurator>();
110
		ermsImport.invoke(config);
111
		
112
		if (config.getCheck().equals(CHECK.CHECK_AND_IMPORT)  || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK)    ){
113
			ICdmApplicationConfiguration app = ermsImport.getCdmAppController();
114
			ISourceable obj = app.getCommonService().getSourcedObjectByIdInSource(ZoologicalName.class, "1000027", null);
115
			logger.info(obj);
116
			
117
//			//make feature tree
118
//			FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, ermsImportConfigurator.getFeatureMap(), featureKeyList);
119
//			app = ermsImport.getCdmAppController();
120
//			app.getFeatureTreeService().saveOrUpdate(tree);
121
		}
122
		System.out.println("End import from ("+ source.getDatabase() + ")...");
123
	}
124
	
125
	/**
126
	 * @param args
127
	 */
128
	public static void main(String[] args) {
129
		ICdmDataSource cdmDB = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
130
		ErmsActivator ermsImport = new ErmsActivator();
131
		ermsImport.doImport(ermsSource, cdmDB, hbm2dll);
132
		
133
		if (includeExport){
134
			PesiExportActivatorERMS ermsExport = new PesiExportActivatorERMS();
135
			ermsExport.doExport(cdmDB);
136
		}
137
	}
138

    
139
}
(1-1/11)