Project

General

Profile

Download (9.1 KB) Statistics
| Branch: | Tag: | Revision:
1 e0a73a53 Andreas Müller
/**
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 a85a029f Andreas Müller
package eu.etaxonomy.cdm.app.wp6.palmae;
11 e0a73a53 Andreas Müller
12 09fa27d7 Andreas Müller
import java.io.File;
13 e0a73a53 Andreas Müller
import java.util.UUID;
14
15
import org.apache.log4j.Logger;
16
17 1f8bfd79 Andreas Müller
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
18 e0a73a53 Andreas Müller
import eu.etaxonomy.cdm.app.common.CdmDestinations;
19 d48709f7 Andreas Müller
import eu.etaxonomy.cdm.app.images.ImageImportConfigurator;
20 a85a029f Andreas Müller
import eu.etaxonomy.cdm.app.tcs.TcsSources;
21 09fa27d7 Andreas Müller
import eu.etaxonomy.cdm.app.wp6.palmae.config.PalmaeProtologueImportConfigurator;
22 e0a73a53 Andreas Müller
import eu.etaxonomy.cdm.database.DbSchemaValidation;
23
import eu.etaxonomy.cdm.database.ICdmDataSource;
24 d48709f7 Andreas Müller
import eu.etaxonomy.cdm.io.PalmaeImageImport;
25
import eu.etaxonomy.cdm.io.PalmaeProtologueImport;
26 e0a73a53 Andreas Müller
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
27 d48709f7 Andreas Müller
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
28 e0a73a53 Andreas Müller
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
29
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
30 c5290215 Andreas Müller
import eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator;
31 1f8bfd79 Andreas Müller
import eu.etaxonomy.cdm.model.description.Feature;
32
import eu.etaxonomy.cdm.model.description.FeatureNode;
33
import eu.etaxonomy.cdm.model.description.FeatureTree;
34 e0a73a53 Andreas Müller
35
/**
36
 * @author a.mueller
37
 * @created 20.06.2008
38
 * @version 1.0
39
 */
40
public class PalmaeActivator {
41 d48709f7 Andreas Müller
	private static final Logger logger = Logger.getLogger(PalmaeActivator.class);
42 e0a73a53 Andreas Müller
	
43
	//database validation status (create, update, validate ...)
44
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
45
	static final String tcsSource = TcsSources.arecaceae_local();
46 6837d5b7 Andreas Kohlbecker
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_edit_palmae_a();
47
	
48
	// set the webserver path to the images
49
	private static final String imageUrlString = "http://wp5.e-taxonomy.eu/media/palmae/photos/";
50
	// set the webserver path to the protologues
51
	private static final String protologueUrlString = "http://wp5.e-taxonomy.eu/media/palmae/protologe/";
52 8d42a7a8 Andreas Müller
53 179de47f Andreas Müller
	public static final UUID featureTreeUuid = UUID.fromString("72ccce05-7cc8-4dab-8e47-bf3f5fd848a0");
54 1f8bfd79 Andreas Müller
		
55 c7f32ae6 Andreas Müller
	static final UUID treeUuid = UUID.fromString("1adb71d4-cce6-45e1-b578-e668778d9ec6");
56 e0a73a53 Andreas Müller
	static final UUID secUuid = UUID.fromString("5f32b8af-0c97-48ac-8d33-6099ed68c625");
57 cb1a9cd6 Andreas Müller
	static final String sourceSecId = "palm_pub_ed_999999";
58 eee89325 Andreas Müller
	static final boolean pubishReferencesInBibliography = false;
59 d48709f7 Andreas Müller
	
60 eee89325 Andreas Müller
	//should the other imports run as well?
61 1cb56f66 Andreas Müller
	static final boolean includeTaxonX = true;
62 d48709f7 Andreas Müller
	static final boolean includeImages = true;
63 1cb56f66 Andreas Müller
	static final boolean includeExcelProtologue = true;
64
	static final boolean includeMediaProtologue = true;
65 179de47f Andreas Müller
	static final boolean updateFeatureTree = true;
66 e0a73a53 Andreas Müller
	
67
	//check - import
68 866f364f Andreas Kohlbecker
	static final CHECK check = CHECK.CHECK_AND_IMPORT;
69
	
70
	static boolean useTaxonomicTree = true;
71 e0a73a53 Andreas Müller
	
72
	//authors
73 047e5ee9 Andreas Müller
	static final boolean doAuthors = true;
74 e0a73a53 Andreas Müller
	//references
75 7c8fe913 Andreas Müller
	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
76 e0a73a53 Andreas Müller
	//names
77 cb1a9cd6 Andreas Müller
	static final boolean doTaxonNames = true;
78 047e5ee9 Andreas Müller
	static final boolean doRelNames = true;
79 e0a73a53 Andreas Müller
	
80
	//taxa
81 047e5ee9 Andreas Müller
	static final boolean doTaxa = true;
82
	static final boolean doRelTaxa = true;
83
	static final boolean doFacts = true;
84 e0a73a53 Andreas Müller
85
	
86 748af7d1 n.hoffmann
	private boolean doImport(ICdmDataSource destination){
87 9b53887a Andreas Müller
		boolean success = true;
88 e0a73a53 Andreas Müller
		System.out.println("Start import from Tcs("+ tcsSource.toString() + ") ...");
89
		
90
		//make BerlinModel Source
91
		String source = tcsSource;
92
		
93 c5290215 Andreas Müller
		TcsRdfImportConfigurator tcsImportConfigurator = TcsRdfImportConfigurator.NewInstance(source,  destination);
94 e0a73a53 Andreas Müller
		
95 c7f32ae6 Andreas Müller
		tcsImportConfigurator.setTreeUuid(treeUuid);
96 e0a73a53 Andreas Müller
		tcsImportConfigurator.setSecUuid(secUuid);
97
		tcsImportConfigurator.setSourceSecId(sourceSecId);
98
		
99
		tcsImportConfigurator.setDoAuthors(doAuthors);
100
		tcsImportConfigurator.setDoReferences(doReferences);
101
		tcsImportConfigurator.setDoTaxonNames(doTaxonNames);
102
		tcsImportConfigurator.setDoRelNames(doRelNames);
103
		
104
		tcsImportConfigurator.setDoTaxa(doTaxa);
105
		tcsImportConfigurator.setDoRelTaxa(doRelTaxa);
106
		tcsImportConfigurator.setDoFacts(doFacts);
107 866f364f Andreas Kohlbecker
		tcsImportConfigurator.setUseTaxonomicTree(useTaxonomicTree);
108 eee89325 Andreas Müller
		tcsImportConfigurator.setPublishReferences(pubishReferencesInBibliography);
109 e0a73a53 Andreas Müller
		
110
		tcsImportConfigurator.setCheck(check);
111
		tcsImportConfigurator.setDbSchemaValidation(hbm2dll);
112
113
		// invoke import
114 c5290215 Andreas Müller
		CdmDefaultImport<TcsRdfImportConfigurator> tcsImport = new CdmDefaultImport<TcsRdfImportConfigurator>();
115 e0a73a53 Andreas Müller
		//new Test().invoke(tcsImportConfigurator);
116 9b53887a Andreas Müller
		success &= tcsImport.invoke(tcsImportConfigurator);
117 1f8bfd79 Andreas Müller
		
118
		//make feature tree
119
		logger.info("Make feature tree");
120 26236a3f Andreas Müller
		CdmApplicationController app = tcsImport.getCdmAppController();
121 1f8bfd79 Andreas Müller
		
122
		FeatureTree tree = getFeatureTree();
123 b3a398e6 Andreas Müller
		app.getFeatureTreeService().saveOrUpdate(tree);
124 e0a73a53 Andreas Müller
		System.out.println("End import from TCS ("+ source.toString() + ")...");
125 9b53887a Andreas Müller
		
126
		return success;
127 e0a73a53 Andreas Müller
	}
128 1f8bfd79 Andreas Müller
	
129
	
130
	private FeatureTree getFeatureTree(){
131
		
132
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
133
		FeatureNode root = result.getRoot();
134
		
135 e1133354 Andreas Müller
		FeatureNode newNode;
136
		newNode = FeatureNode.NewInstance(Feature.INTRODUCTION());
137 1f8bfd79 Andreas Müller
		root.addChild(newNode);
138
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
139
		root.addChild(newNode);
140
		newNode = FeatureNode.NewInstance(Feature.BIOLOGY_ECOLOGY());
141
		root.addChild(newNode);
142
		newNode = FeatureNode.NewInstance(Feature.CONSERVATION());
143
		root.addChild(newNode);
144
		newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
145
		root.addChild(newNode);
146 e1133354 Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.ETYMOLOGY());
147
		root.addChild(newNode);
148 1f8bfd79 Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.USES());
149
		root.addChild(newNode);
150
		newNode = FeatureNode.NewInstance(Feature.CULTIVATION());
151
		root.addChild(newNode);
152 e1133354 Andreas Müller
		// "anatomy", "fossil record" "relationships"
153
		//for future
154 1f8bfd79 Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.DISCUSSION());
155
		root.addChild(newNode);
156 e1133354 Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.DIAGNOSIS());
157
		root.addChild(newNode);
158
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
159
		root.addChild(newNode);
160 1f8bfd79 Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.MATERIALS_EXAMINED());
161
		root.addChild(newNode);
162 72e1baac Andreas Müller
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
163
		root.addChild(newNode);
164 1f8bfd79 Andreas Müller
		return result;
165
		
166
167
	}
168 e0a73a53 Andreas Müller
169 c6f7a771 Andreas Müller
	/**
170
	 * @param args
171
	 */
172
	public static void main(String[] args) {
173 9b53887a Andreas Müller
		boolean success = true;
174
		
175
		logger.debug("start");
176 748af7d1 n.hoffmann
		ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
177 b71e637b Katja Luther
		
178 c6f7a771 Andreas Müller
		PalmaeActivator me = new PalmaeActivator();
179 748af7d1 n.hoffmann
		me.doImport(destination);
180 c6f7a771 Andreas Müller
		
181 d48709f7 Andreas Müller
		if (includeImages){
182
			System.out.println("Start importing images ...");
183
			CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();
184
			ImageImportConfigurator imageConfigurator = ImageImportConfigurator.NewInstance(
185 6837d5b7 Andreas Kohlbecker
					PalmaeImageActivator.sourceFolder, destination, imageUrlString, PalmaeImageImport.class);
186 d48709f7 Andreas Müller
			imageConfigurator.setSecUuid(secUuid);
187
			success &= imageImporter.invoke(imageConfigurator);
188
			System.out.println("End importing images ...");
189
		}
190
191 09fa27d7 Andreas Müller
		if (includeExcelProtologue){
192 d48709f7 Andreas Müller
			System.out.println("Start importing protologues ...");
193
			ImageImportConfigurator imageConfigurator = ImageImportConfigurator.NewInstance(
194 6837d5b7 Andreas Kohlbecker
					PalmaeExcelProtologueActivator.sourceFile, destination, protologueUrlString, PalmaeProtologueImport.class);
195 d48709f7 Andreas Müller
			imageConfigurator.setSecUuid(secUuid);
196
			
197
			CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();
198
			imageImporter.invoke(imageConfigurator);
199
			System.out.println("End importing protologues ...");
200
		}
201 09fa27d7 Andreas Müller
		if (includeMediaProtologue){
202
			System.out.println("Start importing protologues from \\\\media...");
203
			String protologueSource = "\\\\media\\EditWP6\\palmae\\protologe";
204 eee89325 Andreas Müller
			String urlString = "http://wp5.e-taxonomy.eu/media/palmae/protologe/";
205 09fa27d7 Andreas Müller
			File source = new File (protologueSource);
206
207 748af7d1 n.hoffmann
			PalmaeProtologueImportConfigurator protologConfig = PalmaeProtologueImportConfigurator.NewInstance(protologueSource, destination, urlString);
208 09fa27d7 Andreas Müller
			CdmDefaultImport<IImportConfigurator> cdmImport = new CdmDefaultImport<IImportConfigurator>();
209
			
210
			//protologConfig.setDoFacts(doDescriptions);
211
			protologConfig.setCheck(check);
212 e9a2f337 a.babadshanjan
			protologConfig.setDbSchemaValidation(DbSchemaValidation.UPDATE);
213 09fa27d7 Andreas Müller
214
			protologConfig.setSource(source);
215
			success &= cdmImport.invoke(protologConfig);
216
217
			System.out.println("End importing protologues ...");
218
		}
219 d48709f7 Andreas Müller
		
220 9b53887a Andreas Müller
		if (includeTaxonX){
221 d48709f7 Andreas Müller
			System.out.println("Start importing taxonX ...");
222 9b53887a Andreas Müller
			PalmaeTaxonXImportActivator taxonXimporter = new PalmaeTaxonXImportActivator();
223 748af7d1 n.hoffmann
			PalmaeTaxonXImportActivator.cdmDestination = destination;
224 9b53887a Andreas Müller
			success &= taxonXimporter.runImport();
225 d48709f7 Andreas Müller
			System.out.println("End importing taxonX ...");
226 9b53887a Andreas Müller
		}
227
		
228 52276a0f Andreas Müller
		PalmaePostImportUpdater updater = new PalmaePostImportUpdater();
229 179de47f Andreas Müller
		if (updateFeatureTree){
230 748af7d1 n.hoffmann
			updater.updateMissingFeatures(destination);
231 179de47f Andreas Müller
		}
232
		
233 9b53887a Andreas Müller
		String strSuccess = "";
234
		if (success == false){
235
			strSuccess = "not ";
236
		}
237
		System.out.println("Import " + strSuccess + "successful");
238
		
239 c6f7a771 Andreas Müller
	}
240 e0a73a53 Andreas Müller
	
241
}