2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.wp6
.cichorieae
;
14 import java
.net
.URISyntaxException
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
20 import eu
.etaxonomy
.cdm
.app
.berlinModelImport
.BerlinModelSources
;
21 import eu
.etaxonomy
.cdm
.app
.berlinModelImport
.TreeCreator
;
22 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
23 import eu
.etaxonomy
.cdm
.app
.images
.ImageImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
25 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
26 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelImportConfigurator
;
27 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
28 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
29 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
30 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
31 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.EDITOR
;
32 import eu
.etaxonomy
.cdm
.io
.common
.ImportResult
;
33 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
34 import eu
.etaxonomy
.cdm
.io
.wp6
.CichorieaeImageImport
;
35 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
36 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
37 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
38 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
39 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
43 * TODO add the following to a wiki page:
44 * 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
45 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
51 public class CichorieaeActivator
{
52 private static final Logger logger
= Logger
.getLogger(CichorieaeActivator
.class);
54 //database validation status (create, update, validate ...)
55 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
56 static final Source berlinModelSource
= BerlinModelSources
.EDIT_CICHORIEAE();
57 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_local_mysql_test();
59 static final UUID secUuid
= UUID
.fromString("6924c75d-e0d0-4a6d-afb7-3dd8c71195ca");
60 static final UUID classificationUuid
= UUID
.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");
61 // static final UUID treeUuid = UUID.fromString("00db28a7-50e1-4abc-86ec-b2a8ce870de9");
62 static final int sourceSecId
= 7800000;
64 static final UUID featureTreeUuid
= UUID
.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568");
65 static final Object
[] featureKeyList
= new Integer
[]{1, 43, 31, 4, 12, 98, 41};
67 /* --------- MEDIA recources ------------ */
68 static final boolean stopOnMediaErrors
= false;
69 static final String protologueUrlString
= "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";
71 //static final File protologuePath = new File("/Volumes/protolog/protolog/");
73 public static final String imageFolderString
= "//media/editwp6/photos";
74 static final File protologuePath
= new File("//media/editwp6/protolog");
75 // public static final File imageFolder = new File("/media/photos");
76 // static final File protologuePath = new File("/media/protolog");
77 /* -------------------------------------- */
79 // set to zero for unlimited nameFacts
80 static final int maximumNumberOfNameFacts
= 0;
81 static final int recordsPerTransaction
= 2000;
83 //should the other imports run as well?
84 static final boolean includeTaraxacum
= true;
85 static final boolean includeImages
= false;
89 static final CHECK check
= CHECK
.CHECK_AND_IMPORT
;
92 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
95 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
98 static final boolean ignoreNull
= true;
100 static boolean useClassification
= true;
103 // **************** ALL *********************
105 static final boolean doUser
= true;
107 static final boolean doAuthors
= true;
109 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
111 static final boolean doTaxonNames
= true;
112 static final boolean doRelNames
= true;
113 static final boolean doNameStatus
= true;
114 static final boolean doTypes
= true;
115 static final boolean doNameFacts
= true;
118 static final boolean doTaxa
= true;
119 static final boolean doRelTaxa
= true;
120 static final boolean doFacts
= false;
121 static final boolean doOccurences
= false;
122 static final boolean doCommonNames
= true;
125 static final boolean doMarker
= false;
128 // **************** SELECTED *********************
130 // static final boolean doUser = false;
132 // static final boolean doAuthors = false;
134 // static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
136 // static final boolean doTaxonNames = false;
137 // static final boolean doRelNames = false;
138 // static final boolean doNameStatus = false;
139 // static final boolean doTypes = false;
140 // static final boolean doNameFacts = false;
143 // static final boolean doTaxa = false;
144 // static final boolean doRelTaxa = false;
145 // static final boolean doCommonNames = false;
146 // static final boolean doFacts = false;
147 // static final boolean doOccurences = false;
150 // static final boolean doMarker = false;
153 private ImportResult
doInvoke(ICdmDataSource destination
){
154 ImportResult success
= new ImportResult();
155 Source source
= berlinModelSource
;
157 BerlinModelImportConfigurator bmImportConfigurator
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
159 bmImportConfigurator
.setClassificationUuid(classificationUuid
);
160 bmImportConfigurator
.setSourceSecId(sourceSecId
);
162 bmImportConfigurator
.setNomenclaturalCode(nomenclaturalCode
);
164 bmImportConfigurator
.setIgnoreNull(ignoreNull
);
165 bmImportConfigurator
.setDoAuthors(doAuthors
);
166 bmImportConfigurator
.setDoReferences(doReferences
);
167 bmImportConfigurator
.setDoTaxonNames(doTaxonNames
);
168 bmImportConfigurator
.setDoRelNames(doRelNames
);
169 bmImportConfigurator
.setDoNameStatus(doNameStatus
);
170 bmImportConfigurator
.setDoTypes(doTypes
);
171 bmImportConfigurator
.setDoNameFacts(doNameFacts
);
172 bmImportConfigurator
.setUseClassification(useClassification
);
174 bmImportConfigurator
.setDoTaxa(doTaxa
);
175 bmImportConfigurator
.setDoRelTaxa(doRelTaxa
);
176 bmImportConfigurator
.setDoFacts(doFacts
);
177 bmImportConfigurator
.setDoOccurrence(doOccurences
);
178 bmImportConfigurator
.setDoCommonNames(doCommonNames
);
180 bmImportConfigurator
.setDoMarker(doMarker
);
181 bmImportConfigurator
.setDoUser(doUser
);
182 bmImportConfigurator
.setEditor(editor
);
183 bmImportConfigurator
.setDbSchemaValidation(hbm2dll
);
184 bmImportConfigurator
.setRecordsPerTransaction(recordsPerTransaction
);
187 // protologueResourceLocations
188 if ( protologuePath
.exists() && protologuePath
.isDirectory()){
189 bmImportConfigurator
.setMediaUrl(protologueUrlString
);
190 bmImportConfigurator
.setMediaPath(protologuePath
);
192 if(stopOnMediaErrors
){
193 logger
.error("Could not configure protologue ResourceLocations -> will quit.");
196 logger
.error("Could not configure protologue ResourceLocations");
199 File imageFolder
= new File(imageFolderString
);
200 // also check the image source folder
201 if ( !imageFolder
.exists() || !imageFolder
.isDirectory()){
202 if(stopOnMediaErrors
){
203 logger
.error("Could not configure imageFolder -> will quit.");
206 logger
.error("Could not configure imageFolder");
209 // maximum number of name facts to import
210 bmImportConfigurator
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
213 bmImportConfigurator
.setCheck(check
);
214 bmImportConfigurator
.setEditor(editor
);
217 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<BerlinModelImportConfigurator
>();
218 success
= bmImport
.invoke(bmImportConfigurator
);
220 if (doFacts
&& (bmImportConfigurator
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || bmImportConfigurator
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ) ){
221 ICdmRepository app
= bmImport
.getCdmAppController();
222 ISourceable obj
= app
.getCommonService().getSourcedObjectByIdInSource(TaxonName
.class, "1000027", null);
226 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, bmImportConfigurator
.getFeatureMap(), featureKeyList
);
227 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
228 tree
.getRoot().addChild(imageNode
);
229 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
230 tree
.getRoot().addChild(distributionNode
, 2);
231 app
.getFeatureTreeService().saveOrUpdate(tree
);
234 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
238 if (includeTaraxacum
) {
239 System
.out
.println("Start Taraxacum import from BerlinModel ...");
240 TaraxacumActivator taraxacumActivator
= new TaraxacumActivator();
241 ImportResult successTaraxacum
= taraxacumActivator
.doImport(destination
, DbSchemaValidation
.UPDATE
);
242 success
.merge(successTaraxacum
);
243 logger
.warn("Taraxacum import still needs to be tested");
244 System
.out
.println("End Taraxacum import from BerlinModel ...");
246 } catch (Exception e
) {
247 success
.addException(e
);
248 logger
.error("Exception occurred during Taraxacum import.");
255 System
.out
.println("Start importing images ...");
256 CdmDefaultImport
<IImportConfigurator
> imageImporter
= new CdmDefaultImport
<IImportConfigurator
>();
257 URI imageFolderCichorieae
;
259 imageFolderCichorieae
= new URI(CichorieaeActivator
.imageFolderString
);
260 ImageImportConfigurator imageConfigurator
= ImageImportConfigurator
.NewInstance(
261 imageFolderCichorieae
, destination
, CichorieaeImageImport
.class);
262 imageConfigurator
.setSecUuid(secUuid
);
263 imageConfigurator
.setClassificationUuid(classificationUuid
);
264 ImportResult resultImageImport
= imageImporter
.invoke(imageConfigurator
);
265 success
.merge(resultImageImport
);
266 } catch (URISyntaxException e
) {
269 System
.out
.println("End importing images ...");
271 logger
.warn("!!!! NOTE: RefDetail notes and RelPTaxon notes are not imported automatically. Please check for these notes and import them manually.");
280 public static void main(String
[] args
) {
281 ICdmDataSource destination
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
283 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + destination
.getDatabase() + " ...");
284 CichorieaeActivator me
= new CichorieaeActivator();
285 me
.doInvoke(destination
);