Revision d28cf137
Added by Andreas Müller over 8 years ago
cdm-eflora/src/main/java/eu/etaxonomy/cdm/app/eflora/CentralAfricaFernsActivator.java | ||
---|---|---|
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 |
|
|
10 |
package eu.etaxonomy.cdm.app.eflora; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
17 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
18 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
19 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
20 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
21 |
import eu.etaxonomy.cdm.io.common.Source; |
|
22 |
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportConfigurator; |
|
23 |
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer; |
|
24 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
25 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
|
26 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
28 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author a.mueller |
|
32 |
* @created 20.06.2008 |
|
33 |
* @version 1.0 |
|
34 |
*/ |
|
35 |
public class CentralAfricaFernsActivator { |
|
36 |
@SuppressWarnings("unused") |
|
37 |
private static final Logger logger = Logger.getLogger(CentralAfricaFernsActivator.class); |
|
38 |
|
|
39 |
//database validation status (create, update, validate ...) |
|
40 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE; |
|
41 |
static final Source mySource = CdmImportSources.AFRICA_FERNS_ACCESS(); |
|
42 |
|
|
43 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM2(); |
|
44 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview(); |
|
45 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production(); |
|
46 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
47 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest(); |
|
48 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql(); |
|
49 |
|
|
50 |
//feature tree uuid |
|
51 |
public static final UUID featureTreeUuid = UUID.fromString("62d930cb-aabb-461c-ad16-0fdbd2bae592"); |
|
52 |
|
|
53 |
public static final String sourceReference = "Flora of Central Africa"; |
|
54 |
|
|
55 |
public static final String classificationName = "Flora of Central Africa - Ferns"; |
|
56 |
|
|
57 |
//classification |
|
58 |
static final UUID classificationUuid = UUID.fromString("a90fa160-8f33-4a19-9c5a-ab05a1553017"); |
|
59 |
|
|
60 |
//check - import |
|
61 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
|
62 |
|
|
63 |
// static boolean doPrintKeys = false; |
|
64 |
|
|
65 |
//taxa |
|
66 |
static final boolean doTaxa = true; |
|
67 |
|
|
68 |
// private boolean includeSapindaceae1 = true; |
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
private void doImport(ICdmDataSource cdmDestination){ |
|
73 |
|
|
74 |
|
|
75 |
//make Source |
|
76 |
Source source = mySource; |
|
77 |
|
|
78 |
// mySource.getResultSet("SELECT * FROM tmp"); |
|
79 |
CentralAfricaFernsImportConfigurator config= CentralAfricaFernsImportConfigurator.NewInstance(source, cdmDestination); |
|
80 |
config.setClassificationUuid(classificationUuid); |
|
81 |
config.setClassificationName(classificationName); |
|
82 |
config.setDoTaxa(doTaxa); |
|
83 |
config.setCheck(check); |
|
84 |
// configsetDoPrintKeys(doPrintKeys); |
|
85 |
config.setDbSchemaValidation(hbm2dll); |
|
86 |
|
|
87 |
CdmDefaultImport<CentralAfricaFernsImportConfigurator> myImport = new CdmDefaultImport<CentralAfricaFernsImportConfigurator>(); |
|
88 |
|
|
89 |
|
|
90 |
// if (includeSapindaceae1){ |
|
91 |
System.out.println("Start import from ("+ source.toString() + ") ..."); |
|
92 |
config.setSourceReference(getSourceReference(sourceReference)); |
|
93 |
myImport.invoke(config); |
|
94 |
System.out.println("End import from ("+ source.toString() + ")..."); |
|
95 |
// } |
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService()); |
|
100 |
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree); |
|
101 |
|
|
102 |
//check keys |
|
103 |
// if (doPrintKeys){ |
|
104 |
// TransactionStatus tx = myImport.getCdmAppController().startTransaction(); |
|
105 |
// List<FeatureTree> keys = myImport.getCdmAppController().getFeatureTreeService().list(PolytomousKey.class, null, null, null, null); |
|
106 |
// for(FeatureTree key : keys){ |
|
107 |
// ((PolytomousKey)key).print(System.out); |
|
108 |
// System.out.println(); |
|
109 |
// } |
|
110 |
// myImport.getCdmAppController().commitTransaction(tx); |
|
111 |
// } |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
private Reference getSourceReference(String string) { |
|
116 |
Reference result = ReferenceFactory.newGeneric(); |
|
117 |
result.setTitleCache(string); |
|
118 |
return result; |
|
119 |
} |
|
120 |
|
|
121 |
private FeatureTree makeFeatureNode(ITermService service){ |
|
122 |
FloraMalesianaTransformer transformer = new FloraMalesianaTransformer(); |
|
123 |
|
|
124 |
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid); |
|
125 |
result.setTitleCache("Flora Malesiana Presentation Feature Tree"); |
|
126 |
FeatureNode root = result.getRoot(); |
|
127 |
FeatureNode newNode; |
|
128 |
|
|
129 |
newNode = FeatureNode.NewInstance(Feature.CITATION()); |
|
130 |
root.addChild(newNode); |
|
131 |
|
|
132 |
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION()); |
|
133 |
root.addChild(newNode); |
|
134 |
|
|
135 |
return result; |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* @param args |
|
142 |
*/ |
|
143 |
public static void main(String[] args) { |
|
144 |
CentralAfricaFernsActivator me = new CentralAfricaFernsActivator(); |
|
145 |
me.doImport(cdmDestination); |
|
146 |
} |
|
147 |
|
|
148 |
} |
|
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 |
|
|
10 |
package eu.etaxonomy.cdm.app.eflora; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
17 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
18 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
19 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
20 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
21 |
import eu.etaxonomy.cdm.io.common.Source; |
|
22 |
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportConfigurator; |
|
23 |
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer; |
|
24 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
25 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
|
26 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
28 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author a.mueller |
|
32 |
* @created 20.06.2008 |
|
33 |
* @version 1.0 |
|
34 |
*/ |
|
35 |
public class CentralAfricaFernsActivator { |
|
36 |
@SuppressWarnings("unused") |
|
37 |
private static final Logger logger = Logger.getLogger(CentralAfricaFernsActivator.class); |
|
38 |
|
|
39 |
//database validation status (create, update, validate ...) |
|
40 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE; |
|
41 |
static final Source mySource = CdmImportSources.AFRICA_FERNS_ACCESS(); |
|
42 |
|
|
43 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM2(); |
|
44 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview(); |
|
45 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production(); |
|
46 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
47 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest(); |
|
48 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql(); |
|
49 |
|
|
50 |
//feature tree uuid |
|
51 |
public static final UUID featureTreeUuid = UUID.fromString("62d930cb-aabb-461c-ad16-0fdbd2bae592"); |
|
52 |
|
|
53 |
public static final String sourceReference = "Flora of Central Africa"; |
|
54 |
|
|
55 |
public static final String classificationName = "Flora of Central Africa - Ferns"; |
|
56 |
|
|
57 |
//classification |
|
58 |
static final UUID classificationUuid = UUID.fromString("a90fa160-8f33-4a19-9c5a-ab05a1553017"); |
|
59 |
|
|
60 |
//check - import |
|
61 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
|
62 |
|
|
63 |
// static boolean doPrintKeys = false; |
|
64 |
|
|
65 |
//taxa |
|
66 |
static final boolean doTaxa = true; |
|
67 |
|
|
68 |
// private boolean includeSapindaceae1 = true; |
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
private void doImport(ICdmDataSource cdmDestination){ |
|
73 |
|
|
74 |
|
|
75 |
//make Source |
|
76 |
Source source = mySource; |
|
77 |
|
|
78 |
// mySource.getResultSet("SELECT * FROM tmp"); |
|
79 |
CentralAfricaFernsImportConfigurator config= CentralAfricaFernsImportConfigurator.NewInstance(source, cdmDestination); |
|
80 |
config.setClassificationUuid(classificationUuid); |
|
81 |
config.setClassificationName(classificationName); |
|
82 |
config.setDoTaxa(doTaxa); |
|
83 |
config.setCheck(check); |
|
84 |
// configsetDoPrintKeys(doPrintKeys); |
|
85 |
config.setDbSchemaValidation(hbm2dll); |
|
86 |
|
|
87 |
CdmDefaultImport<CentralAfricaFernsImportConfigurator> myImport = new CdmDefaultImport<CentralAfricaFernsImportConfigurator>(); |
|
88 |
|
|
89 |
|
|
90 |
// if (includeSapindaceae1){ |
|
91 |
System.out.println("Start import from ("+ source.toString() + ") ..."); |
|
92 |
config.setSourceReference(getSourceReference(sourceReference)); |
|
93 |
myImport.invoke(config); |
|
94 |
System.out.println("End import from ("+ source.toString() + ")..."); |
|
95 |
// } |
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService()); |
|
100 |
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree); |
|
101 |
|
|
102 |
//check keys |
|
103 |
// if (doPrintKeys){ |
|
104 |
// TransactionStatus tx = myImport.getCdmAppController().startTransaction(); |
|
105 |
// List<FeatureTree> keys = myImport.getCdmAppController().getFeatureTreeService().list(PolytomousKey.class, null, null, null, null); |
|
106 |
// for(FeatureTree key : keys){ |
|
107 |
// ((PolytomousKey)key).print(System.out); |
|
108 |
// System.out.println(); |
|
109 |
// } |
|
110 |
// myImport.getCdmAppController().commitTransaction(tx); |
|
111 |
// } |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
private Reference getSourceReference(String string) { |
|
116 |
Reference result = ReferenceFactory.newGeneric(); |
|
117 |
result.setTitleCache(string, true); |
|
118 |
return result; |
|
119 |
} |
|
120 |
|
|
121 |
private FeatureTree makeFeatureNode(ITermService service){ |
|
122 |
FloraMalesianaTransformer transformer = new FloraMalesianaTransformer(); |
|
123 |
|
|
124 |
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid); |
|
125 |
result.setTitleCache("Flora Malesiana Presentation Feature Tree", true); |
|
126 |
FeatureNode root = result.getRoot(); |
|
127 |
FeatureNode newNode; |
|
128 |
|
|
129 |
newNode = FeatureNode.NewInstance(Feature.CITATION()); |
|
130 |
root.addChild(newNode); |
|
131 |
|
|
132 |
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION()); |
|
133 |
root.addChild(newNode); |
|
134 |
|
|
135 |
return result; |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* @param args |
|
142 |
*/ |
|
143 |
public static void main(String[] args) { |
|
144 |
CentralAfricaFernsActivator me = new CentralAfricaFernsActivator(); |
|
145 |
me.doImport(cdmDestination); |
|
146 |
} |
|
147 |
|
|
148 |
} |
Also available in: Unified diff
Remove use of deprecated methods