Project

General

Profile

« Previous | Next » 

Revision 7691ed2a

Added by Andreas Müller almost 5 years ago

ref #8257 remove factory method for term node creation in app-import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/EuroMedActivatorVibrant.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
32 32
import eu.etaxonomy.cdm.model.description.Feature;
33 33
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
34 34
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
35
import eu.etaxonomy.cdm.model.term.FeatureNode;
36 35
import eu.etaxonomy.cdm.model.term.FeatureTree;
37 36

  
38 37

  
39 38
/**
40 39
 * TODO add the following to a wiki page:
41
 * 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 
40
 * 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
42 41
 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
43
 * 
44
 * 
42
 *
43
 *
45 44
 * @author a.mueller
46 45
 *
47 46
 */
......
52 51
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
53 52
//	static final Source berlinModelSource = BerlinModelSources.euroMed();
54 53
	static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
55
	
54

  
56 55
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
57 56
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
58 57
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_test_mysql();
59
	
58

  
60 59
	static final boolean includePesiExport = false;
61
	
60

  
62 61
	static final int sourceSecId = 7000000; //500000
63 62
	static final UUID classificationUuid = UUID.fromString("5e05ebc5-6075-45ff-81df-4cefafafa4a3");
64 63
	static final boolean useSingleClassification = true;
65
	
64

  
66 65
	//from PESI-transformer
67 66
	static UUID uuidSourceRefEuroMed = UUID.fromString("0603a84a-f024-4454-ab92-9e2ac0139126");
68
	
67

  
69 68
	static final UUID featureTreeUuid = UUID.fromString("eff345e7-0619-4ec3-955d-997c1fafffc3");
70
	static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41}; 	
71
	
69
	static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
70

  
72 71
	// set to zero for unlimited nameFacts
73 72
	static final int maximumNumberOfNameFacts = 0;
74
	
73

  
75 74
	static final int partitionSize = 2500;
76
	
75

  
77 76
	//check - import
78 77
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
79 78

  
80 79
	//editor - import
81 80
	static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
82
	
81

  
83 82
	//NomenclaturalCode
84 83
	static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
85 84

  
86 85
	//ignore null
87 86
	static final boolean ignoreNull = true;
88
	
87

  
89 88
	static final boolean switchSpeciesGroup = true;
90
	
89

  
91 90
	static boolean useClassification = true;
92
	
93
	
91

  
92

  
94 93
	static String taxonTable = "v_cdm_exp_taxaAll";
95
	static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId; 
96
	static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " + 
94
	static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId;
95
	static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " +
97 96
					" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk ";
98 97
	static String nameIdTable = " v_cdm_exp_namesAll ";
99 98
	static String referenceIdTable = " v_cdm_exp_refAll ";
100 99
	static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll )";
101 100
	static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
102
	static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )"; 
101
	static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
103 102
	static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
104 103
	static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
105 104
	static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
106
	static String authorFilter = null;  // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) "; 
107
	
105
	static String authorFilter = null;  // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
106

  
108 107

  
109
	
110
// **************** ALL *********************	
108

  
109
// **************** ALL *********************
111 110

  
112 111
	static final boolean doUser = true;
113 112
	//authors
......
119 118
	static final boolean doRelNames = true;
120 119
	static final boolean doNameStatus = true;
121 120
	static final boolean doNameFacts = true;
122
	
121

  
123 122
	//taxa
124 123
	static final boolean doTaxa = true;
125 124
	static final boolean doRelTaxa = true;
......
128 127
	static final boolean doCommonNames = false;  //currently creates errors
129 128

  
130 129

  
131
	
130

  
132 131
// **************** SELECTED *********************
133 132

  
134 133
//	static final boolean doUser = true;
......
142 141
//	static final boolean doNameStatus = false;
143 142
//	static final boolean doTypes = false;
144 143
//	static final boolean doNameFacts = false;
145
//	
146
//	//taxa 
144
//
145
//	//taxa
147 146
//	static final boolean doTaxa = false;
148 147
//	static final boolean doRelTaxa = false;
149 148
//	static final boolean doFacts = false;
150 149
//	static final boolean doOccurences = false;
151 150
//	static final boolean doCommonNames = false;
152
//	
151
//
153 152
//	//etc.
154 153
//	static final boolean doMarker = false;
155 154

  
156 155
	//always false
157
	static final boolean doTypes = false;  
156
	static final boolean doTypes = false;
158 157
	static final boolean doMarker = false;
159 158

  
160
	
159

  
161 160
	public void importEm2CDM (Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
162 161
		System.out.println("Start import from BerlinModel("+ source.getDatabase() + ") to " + destination.getDatabase() + " ...");
163 162
		//make BerlinModel Source
164
		
163

  
165 164
		logger.warn("REMIND: Set publishFlag = 1 filter in 'v_cdm_exp_taxaDirect' view !! ");
166
		
165

  
167 166
		BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source,  destination);
168
		
167

  
169 168
		config.setClassificationUuid(classificationUuid);
170 169
		config.setSourceSecId(sourceSecId);
171
		
170

  
172 171
		config.setNomenclaturalCode(nomenclaturalCode);
173 172

  
174 173
		try {
......
178 177
			e.printStackTrace();
179 178
			return;
180 179
		}
181
		
182
		
180

  
181

  
183 182
		config.setIgnoreNull(ignoreNull);
184 183
		config.setDoAuthors(doAuthors);
185 184
		config.setDoReferences(doReferences);
......
190 189
		config.setDoNameFacts(doNameFacts);
191 190
		config.setUseClassification(useClassification);
192 191
		config.setSourceRefUuid(uuidSourceRefEuroMed);
193
		
192

  
194 193
		config.setDoTaxa(doTaxa);
195 194
		config.setDoRelTaxa(doRelTaxa);
196 195
		config.setDoFacts(doFacts);
197 196
		config.setDoOccurrence(doOccurences);
198 197
		config.setDoCommonNames(doCommonNames);
199
		
198

  
200 199
		config.setDoMarker(doMarker);
201 200
		config.setDoUser(doUser);
202 201
		config.setEditor(editor);
203 202
		config.setDbSchemaValidation(hbm2dll);
204
		
203

  
205 204
		// maximum number of name facts to import
206 205
		config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
207
		
206

  
208 207
//		filter
209 208
		config.setTaxonTable(taxonTable);
210 209
		config.setClassificationQuery(classificationQuery);
......
219 218
		config.setOccurrenceSourceFilter(occurrenceSourceFilter);
220 219
		config.setWebMarkerFilter(webMarkerFilter);
221 220
		config.setUseSingleClassification(useSingleClassification);
222
		
221

  
223 222
		config.setCheck(check);
224 223
		config.setEditor(editor);
225 224
		config.setRecordsPerTransaction(partitionSize);
226
		
225

  
227 226
		config.setSwitchSpeciesGroup(switchSpeciesGroup);
228
		
227

  
229 228
		// invoke import
230 229
		CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
231 230
		bmImport.invoke(config);
232
		
231

  
233 232
		if (doFacts && config.getCheck().equals(CHECK.CHECK_AND_IMPORT)  || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK)    ){
234 233
			ICdmRepository app = bmImport.getCdmAppController();
235
			
234

  
236 235
			//make feature tree
237
			FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
238
			FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
239
			tree.getRoot().addChild(imageNode);
240
			FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
241
			tree.getRoot().addChild(distributionNode, 2); 
236
			FeatureTree<Feature> tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
237
			tree.getRoot().addChild(Feature.IMAGE());
238
			tree.getRoot().addChild(Feature.DISTRIBUTION(), 2);
242 239
			app.getFeatureTreeService().saveOrUpdate(tree);
243 240
		}
244
		
241

  
245 242
		System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
246 243

  
247 244
		logger.warn("REMIND: Set publishFlag back to <= 1  in 'v_cdm_exp_taxaDirect' view !! ");
248 245

  
249
		
246

  
250 247
	}
251
	
248

  
252 249
	/**
253 250
	 * @param args
254 251
	 */
......
256 253
		EuroMedActivatorVibrant importActivator = new EuroMedActivatorVibrant();
257 254
		Source source = berlinModelSource;
258 255
		ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
259
		
256

  
260 257
		importActivator.importEm2CDM(source, cdmRepository, hbm2dll);
261 258
	}
262
	
259

  
263 260
	private static final String URLbase = "http://ww2.bgbm.org/EuroPlusMed/PTaxonDetail.asp?";
264 261
	public static Method makeUrlForTaxon(TaxonBase<?> taxon, ResultSet rs){
265 262
		Method result = null;
......
277 274
		} catch (SQLException e) {
278 275
			logger.warn("Exception when trying to access result set for url creation.");
279 276
		}
280
		
277

  
281 278
		return result;
282 279
	}
283 280

  

Also available in: Unified diff