Revision 165e1209
Added by Andreas Müller over 4 years ago
cdm-eflora/src/main/java/eu/etaxonomy/cdm/app/testUpdate/EricaceaeTestUpdateActivator.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 |
*/ |
... | ... | |
28 | 28 |
import eu.etaxonomy.cdm.io.eflora.EfloraImportConfigurator; |
29 | 29 |
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeImportConfigurator; |
30 | 30 |
import eu.etaxonomy.cdm.model.common.Language; |
31 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
31 | 32 |
import eu.etaxonomy.cdm.model.reference.Reference; |
32 | 33 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
33 |
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
|
34 |
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
|
34 |
import eu.etaxonomy.cdm.model.term.TermNode;
|
|
35 |
import eu.etaxonomy.cdm.model.term.TermTree;
|
|
35 | 36 |
|
36 | 37 |
/** |
37 | 38 |
* @author a.mueller |
... | ... | |
41 | 42 |
public class EricaceaeTestUpdateActivator { |
42 | 43 |
@SuppressWarnings("unused") |
43 | 44 |
private static final Logger logger = Logger.getLogger(EricaceaeTestUpdateActivator.class); |
44 |
|
|
45 |
|
|
45 | 46 |
//database validation status (create, update, validate ...) |
46 | 47 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE; |
47 | 48 |
static final URI source = EfloraSources.ericacea_local(); |
48 | 49 |
|
49 |
|
|
50 |
|
|
50 | 51 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM2(); |
51 | 52 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview(); |
52 | 53 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production(); |
53 | 54 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
54 | 55 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest(); |
55 |
|
|
56 |
|
|
56 | 57 |
|
57 | 58 |
//feature tree uuid |
58 | 59 |
public static final UUID featureTreeUuid = UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7"); |
59 |
|
|
60 |
|
|
60 | 61 |
public static UUID defaultLanguageUuid = Language.uuidEnglish; |
61 |
|
|
62 |
|
|
62 | 63 |
//classification |
63 | 64 |
static final UUID classificationUuid = UUID.fromString("10e5efcc-6e13-4abc-ad42-e0b46e50cbe7"); |
64 |
|
|
65 |
|
|
65 | 66 |
//check - import |
66 | 67 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
67 |
|
|
68 |
|
|
68 | 69 |
static boolean doPrintKeys = false; |
69 |
|
|
70 |
|
|
70 | 71 |
//taxa |
71 | 72 |
static final boolean doTaxa = false; |
72 | 73 |
|
73 | 74 |
private boolean includeEricaceae = true; |
74 | 75 |
|
75 | 76 |
|
76 |
|
|
77 |
|
|
77 | 78 |
private void doImport(ICdmDataSource cdmDestination){ |
78 |
|
|
79 |
|
|
79 | 80 |
CdmUpdater updater = new CdmUpdater(); |
80 | 81 |
updater.updateToCurrentVersion(cdmDestination, DefaultProgressMonitor.NewInstance()); |
81 |
|
|
82 |
|
|
82 | 83 |
//make Source |
83 | 84 |
CentralAfricaEricaceaeImportConfigurator config= CentralAfricaEricaceaeImportConfigurator.NewInstance(source, cdmDestination); |
84 | 85 |
config.setClassificationUuid(classificationUuid); |
... | ... | |
87 | 88 |
config.setDefaultLanguageUuid(defaultLanguageUuid); |
88 | 89 |
config.setDoPrintKeys(doPrintKeys); |
89 | 90 |
config.setDbSchemaValidation(hbm2dll); |
90 |
|
|
91 |
|
|
91 |
|
|
92 |
|
|
92 | 93 |
CdmDefaultImport<EfloraImportConfigurator> myImport = new CdmDefaultImport<EfloraImportConfigurator>(); |
93 |
|
|
94 |
|
|
94 | 95 |
ICdmRepository app = myImport.getCdmAppController(); |
95 |
|
|
96 |
|
|
96 |
|
|
97 |
|
|
97 | 98 |
// |
98 | 99 |
if (includeEricaceae){ |
99 | 100 |
System.out.println("Start import from ("+ source.toString() + ") ..."); |
... | ... | |
101 | 102 |
myImport.invoke(config); |
102 | 103 |
System.out.println("End import from ("+ source.toString() + ")..."); |
103 | 104 |
} |
104 |
|
|
105 |
|
|
105 | 106 |
app = myImport.getCdmAppController(); |
106 |
|
|
107 |
|
|
107 | 108 |
TransactionStatus tx = app.startTransaction(); |
108 |
List<FeatureTree> featureTrees = app.getFeatureTreeService().list(null, null, null, null, null);
|
|
109 |
for (FeatureTree tree :featureTrees){
|
|
109 |
List<TermTree<Feature>> featureTrees = app.getFeatureTreeService().list(null, null, null, null, null);
|
|
110 |
for (TermTree<Feature> tree :featureTrees){
|
|
110 | 111 |
if (tree.getClass().getSimpleName().equalsIgnoreCase("FeatureTree")){ |
111 | 112 |
moveChild(app, tree); |
112 | 113 |
} |
113 | 114 |
} |
114 | 115 |
app.commitTransaction(tx); |
115 |
|
|
116 |
|
|
117 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
118 | 119 |
} |
119 | 120 |
|
120 | 121 |
/** |
121 | 122 |
* @param app |
122 | 123 |
* @param tree |
123 | 124 |
*/ |
124 |
private void moveChild(ICdmRepository app, FeatureTree tree) {
|
|
125 |
FeatureNode root = tree.getRoot();
|
|
125 |
private void moveChild(ICdmRepository app, TermTree<Feature> tree) {
|
|
126 |
TermNode<Feature> root = tree.getRoot();
|
|
126 | 127 |
int count = root.getChildCount(); |
127 |
FeatureNode lastChild = root.getChildAt(count - 1);
|
|
128 |
TermNode<Feature> lastChild = root.getChildAt(count - 1);
|
|
128 | 129 |
root.removeChild(lastChild); |
129 | 130 |
root.addChild(lastChild, 1); |
130 | 131 |
app.getFeatureTreeService().saveOrUpdate(tree); |
131 | 132 |
} |
132 |
|
|
133 |
|
|
133 | 134 |
private Reference getSourceReference(String string) { |
134 | 135 |
Reference result = ReferenceFactory.newGeneric(); |
135 |
result.setTitleCache(string); |
|
136 |
result.setTitleCache(string, true);
|
|
136 | 137 |
return result; |
137 | 138 |
} |
138 | 139 |
|
... | ... | |
145 | 146 |
EricaceaeTestUpdateActivator me = new EricaceaeTestUpdateActivator(); |
146 | 147 |
me.doImport(cdmDestination); |
147 | 148 |
} |
148 |
|
|
149 |
|
|
149 | 150 |
} |
Also available in: Unified diff
ref #6794 , ref #7099 adapt app-import, pesi, eflora to modelchanges