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
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
18 import eu
.etaxonomy
.cdm
.app
.berlinModelImport
.BerlinModelSources
;
19 import eu
.etaxonomy
.cdm
.app
.berlinModelImport
.TreeCreator
;
20 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
21 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
22 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
23 import eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
25 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
27 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
28 import eu
.etaxonomy
.cdm
.model
.common
.ISourceable
;
29 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
30 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
31 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
33 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
37 * TODO add the following to a wiki page:
38 * 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
39 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
45 public class CichorieaeActivator
{
46 private static final Logger logger
= Logger
.getLogger(CichorieaeActivator
.class);
48 //database validation status (create, update, validate ...)
49 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
50 static final Source berlinModelSource
= BerlinModelSources
.EDIT_CICHORIEAE();
51 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_andreasK2();
53 static final UUID secUuid
= UUID
.fromString("6924c75d-e0d0-4a6d-afb7-3dd8c71195ca");
54 static final int sourceSecId
= 7800000;
56 static final UUID featureTreeUuid
= UUID
.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568");
57 static final Object
[] featureKeyList
= new Integer
[]{1, 31, 4, 98};
59 static final String mediaUrlString
= "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";
61 //static final File mediaPath = new File("/Volumes/protolog/protolog/");
63 static final File mediaPath
= new File("\\\\Bgbm11\\Edit-WP6\\protolog");
64 // set to zero for unlimited nameFacts
65 static final int maximumNumberOfNameFacts
= 0;
69 static final CHECK check
= CHECK
.CHECK_AND_IMPORT
;
72 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICBN
;
75 static final boolean ignoreNull
= true;
78 // **************** ALL *********************
80 static final boolean doAuthors
= true;
82 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
84 static final boolean doTaxonNames
= true;
85 static final boolean doRelNames
= true;
86 static final boolean doNameStatus
= true;
87 static final boolean doTypes
= true;
88 static final boolean doNameFacts
= true;
91 static final boolean doTaxa
= true;
92 static final boolean doRelTaxa
= true;
93 static final boolean doFacts
= true;
94 static final boolean doOccurences
= true;
97 // **************** SELECTED *********************
100 // static final boolean doAuthors = false;
102 // static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
104 // static final boolean doTaxonNames = false;
105 // static final boolean doRelNames = false;
106 // static final boolean doNameStatus = false;
107 // static final boolean doTypes = false;
108 // static final boolean doNameFacts = false;
111 // static final boolean doTaxa = false;
112 // static final boolean doRelTaxa = false;
113 // static final boolean doFacts = false;
114 // static final boolean doOccurences = false;
119 public static void main(String
[] args
) {
120 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ...");
122 //make BerlinModel Source
123 Source source
= berlinModelSource
;
124 ICdmDataSource destination
= cdmDestination
;
126 BerlinModelImportConfigurator bmImportConfigurator
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
128 bmImportConfigurator
.setSecUuid(secUuid
);
129 bmImportConfigurator
.setSourceSecId(sourceSecId
);
131 bmImportConfigurator
.setNomenclaturalCode(nomenclaturalCode
);
133 bmImportConfigurator
.setIgnoreNull(ignoreNull
);
134 bmImportConfigurator
.setDoAuthors(doAuthors
);
135 bmImportConfigurator
.setDoReferences(doReferences
);
136 bmImportConfigurator
.setDoTaxonNames(doTaxonNames
);
137 bmImportConfigurator
.setDoRelNames(doRelNames
);
138 bmImportConfigurator
.setDoNameStatus(doNameStatus
);
139 bmImportConfigurator
.setDoTypes(doTypes
);
140 bmImportConfigurator
.setDoNameFacts(doNameFacts
);
142 bmImportConfigurator
.setDoTaxa(doTaxa
);
143 bmImportConfigurator
.setDoRelTaxa(doRelTaxa
);
144 bmImportConfigurator
.setDoFacts(doFacts
);
145 bmImportConfigurator
.setDoOccurrence(doOccurences
);
146 bmImportConfigurator
.setDbSchemaValidation(hbm2dll
);
148 // mediaResourceLocations
149 if ( mediaPath
.exists() && mediaPath
.isDirectory()){
150 bmImportConfigurator
.setMediaUrl(mediaUrlString
);
151 bmImportConfigurator
.setMediaPath(mediaPath
);
153 logger
.warn("Could not configure mediaResourceLocations");
156 // maximum number of name facts to import
157 bmImportConfigurator
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
160 bmImportConfigurator
.setCheck(check
);
163 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<BerlinModelImportConfigurator
>();
164 bmImport
.invoke(bmImportConfigurator
);
166 if (doFacts
&& bmImportConfigurator
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || bmImportConfigurator
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ){
167 CdmApplicationController app
= bmImport
.getCdmApp();
168 ISourceable obj
= app
.getCommonService().getSourcedObjectByIdInSource(ZoologicalName
.class, "1000027", null);
172 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, bmImportConfigurator
.getFeatureMap(), featureKeyList
);
173 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
174 tree
.getRoot().addChild(imageNode
);
175 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
176 tree
.getRoot().addChild(distributionNode
, 2);
177 app
.getDescriptionService().saveFeatureTree(tree
);
180 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");