Project

General

Profile

Download (6.59 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
package eu.etaxonomy.cdm.app.berlinModelImport;
10

    
11

    
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.api.application.ICdmRepository;
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.berlinModel.in.BerlinModelImportConfigurator;
21
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
22
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
24
import eu.etaxonomy.cdm.io.common.Source;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.cdm.model.description.FeatureNode;
27
import eu.etaxonomy.cdm.model.description.FeatureTree;
28
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
29

    
30
public class MTStandardlisteActivator {
31
	
32

    
33

    
34
	/**
35
	 * TODO add the following to a wiki page:
36
	 * 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 
37
	 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
38
	 * 
39
	 * 
40
	 * @author a.mueller
41
	 *
42
	 */
43

    
44
		private static final Logger logger = Logger.getLogger(MTStandardlisteActivator.class);
45

    
46
		//database validation status (create, update, validate ...)
47
		static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
48
		static final Source berlinModelSource = BerlinModelSources.MT_Standardliste();
49
		static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_standardliste();
50
//		static final ICdmDataSource cdmDestination = CdmDestinations.cdm_mt_standardliste();
51
		
52
		static final UUID treeUuid = UUID.fromString("70549f1a-3d30-42ae-8257-c8367e2703b0");
53
		static final int sourceSecId = 7331;
54
		static final UUID sourceRefUuid = UUID.fromString("33baaf62-f5c4-4260-aacb-090fe4d24206");
55
		
56
		static final UUID featureTreeUuid = UUID.fromString("2b592057-de3a-4782-a6f3-90a87e2a004d");
57
		static final Object[] featureKeyList = new Integer[]{7,201,202,203,204,205,206,207}; 
58
		
59
		static final boolean includeFlatClassifications = true; 
60

    
61
		
62
		//check - import
63
		static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
64

    
65
		
66

    
67
		//NomenclaturalCode
68
		static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
69

    
70
	// ****************** ALL *****************************************
71
		
72
		//authors
73
		static final boolean doAuthors = true;
74
		//references
75
		static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
76
		//names
77
		static final boolean doTaxonNames = true;
78
		static final boolean doRelNames = true;
79
		static final boolean doNameStatus = false;
80
		static final boolean doTypes = false;  
81
		static final boolean doNameFacts = false;   
82
		
83
		//taxa
84
		static final boolean doTaxa = true;
85
		static final boolean doRelTaxa = true;
86
		static final boolean doFacts = false;
87
		static final boolean doOccurences = false;
88
		static final boolean doCommonNames = false;
89

    
90
		private static final boolean includeAllNonMisappliedRelatedClassifications = true;
91

    
92

    
93
	// ************************ NONE **************************************** //
94
		
95
//		//authors
96
//		static final boolean doAuthors = false;
97
//		//references
98
//		static final DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
99
//		//names
100
//		static final boolean doTaxonNames = false;
101
//		static final boolean doRelNames = false;
102
//		static final boolean doNameStatus = false;
103
//		static final boolean doTypes = false;
104
//		static final boolean doNameFacts = false;
105
	//	
106
//		//taxa
107
//		static final boolean doTaxa = false;
108
//		static final boolean doRelTaxa = false;
109
//		static final boolean doFacts = false;
110
//		static final boolean doOccurences = false;
111
//		static final boolean doCommonNames = false;
112
		
113
		
114
		public void invoke(String[] args){
115
			System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") ...");
116
			logger.debug("Start");
117
			//make BerlinModel Source
118
			Source source = berlinModelSource;
119
			ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
120
			
121
			BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source,  destination);
122
			
123
			config.setClassificationUuid(treeUuid);
124
			config.setSourceSecId(sourceSecId);
125
			config.setNomenclaturalCode(nomenclaturalCode);
126

    
127
			config.setDoAuthors(doAuthors);
128
			config.setDoReferences(doReferences);
129
			config.setDoTaxonNames(doTaxonNames);
130
			config.setDoRelNames(doRelNames);
131
			config.setDoNameStatus(doNameStatus);
132
			config.setDoTypes(doTypes);
133
			config.setDoNameFacts(doNameFacts);
134
			
135
			config.setDoTaxa(doTaxa);
136
			config.setDoRelTaxa(doRelTaxa);
137
			config.setDoFacts(doFacts);
138
			config.setDoOccurrence(doOccurences);
139
			config.setDoCommonNames(doCommonNames);
140
			config.setSourceRefUuid(sourceRefUuid);
141
			
142
			config.setDbSchemaValidation(hbm2dll);
143
			config.setIncludeFlatClassifications(includeFlatClassifications);
144
			config.setIncludeAllNonMisappliedRelatedClassifications(includeAllNonMisappliedRelatedClassifications);
145

    
146
			config.setCheck(check);
147
			
148
			// invoke import
149
			CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
150
			bmImport.invoke(config);
151

    
152
			if (doFacts && (config.getCheck().equals(CHECK.CHECK_AND_IMPORT)  || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) )   ){
153
				ICdmRepository app = bmImport.getCdmAppController();
154
				
155
				//make feature tree
156
				FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
157
				FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
158
				tree.getRoot().addChild(imageNode);
159
				FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
160
				tree.getRoot().addChild(distributionNode, 2); 
161
				app.getFeatureTreeService().saveOrUpdate(tree);
162
			}
163
			
164
			
165
			System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
166
		}
167
		
168
		
169
		/**
170
		 * @param args
171
		 */
172
		public static void main(String[] args) {
173
			MTStandardlisteActivator activator = new MTStandardlisteActivator();
174
			activator.invoke(args);
175
		}
176

    
177
	}
178

    
(8-8/12)