adding recordBasis to SpecimenOrObservationBase and removing some DerivedUnit classes...
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / update / v31_33 / SchemaUpdater_31_33.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.database.update.v31_33;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.database.update.ColumnAdder;
19 import eu.etaxonomy.cdm.database.update.ColumnRemover;
20 import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
21 import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
22 import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
23 import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
24 import eu.etaxonomy.cdm.database.update.TableDroper;
25 import eu.etaxonomy.cdm.database.update.v30_31.SchemaUpdater_30_301;
26
27
28 /**
29 * NOT YET USED
30 * @author a.mueller
31 * @created Oct 11, 2011
32 */
33 public class SchemaUpdater_31_33 extends SchemaUpdaterBase {
34
35
36 @SuppressWarnings("unused")
37 private static final Logger logger = Logger.getLogger(SchemaUpdater_31_33.class);
38 private static final String startSchemaVersion = "3.0.1.0.201104190000";
39 private static final String endSchemaVersion = "3.3.0.0.201306010000";
40
41 // ********************** FACTORY METHOD *******************************************
42
43 public static SchemaUpdater_31_33 NewInstance(){
44 return new SchemaUpdater_31_33();
45 }
46
47 /**
48 * @param startSchemaVersion
49 * @param endSchemaVersion
50 */
51 protected SchemaUpdater_31_33() {
52 super(startSchemaVersion, endSchemaVersion);
53 }
54
55 /* (non-Javadoc)
56 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getUpdaterList()
57 */
58 @Override
59 protected List<ISchemaUpdaterStep> getUpdaterList() {
60
61 List<ISchemaUpdaterStep> stepList = new ArrayList<ISchemaUpdaterStep>();
62
63 //TODO still needed? Does it throw exception if table does not exist?
64 //drop TypeDesignationBase_TaxonNameBase //from schemaUpdater 301_31
65 String stepName = "Drop duplicate TypeDesignation-TaxonName table";
66 String tableName = "TypeDesignationBase_TaxonNameBase";
67 ISchemaUpdaterStep step = TableDroper.NewInstance(stepName, tableName, INCLUDE_AUDIT);
68 stepList.add(step);
69
70 //create original source type column
71 stepName = "Create original source type column";
72 tableName = "OriginalSourceBase";
73 String columnName = "type";
74 //TODO NOT NULL unclear
75 step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, INCLUDE_AUDIT, true, null);
76 stepList.add(step);
77
78 //TODO ?? update original source type
79 updateOriginalSourceType(stepList);
80
81 //create and update elevenation max, remove error column
82 updateElevationMax(stepList);
83
84 //create taxon node tree index
85 stepName = "Create taxon node tree index";
86 tableName = "TaxonNode";
87 columnName = "treeIndex";
88 //TODO NOT NULL unclear
89 step = ColumnAdder.NewStringInstance(stepName, tableName, columnName, 255, INCLUDE_AUDIT);
90 stepList.add(step);
91
92 //TODO update tree index
93
94 //create original source type column
95 stepName = "Create taxon node sort index column";
96 tableName = "TaxonNode";
97 columnName = "sortIndex";
98 step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, INCLUDE_AUDIT, false, null);
99 stepList.add(step);
100
101 //TODO implement sorted behaviour in model first !!
102 //TODO update sortindex (similar updater exists already for FeatureNode#sortIndex in schema update 25_30
103
104 //create feature node tree index
105 stepName = "Create feature node tree index";
106 tableName = "FeatureNode";
107 columnName = "treeIndex";
108 //TODO NOT NULL unclear
109 step = ColumnAdder.NewStringInstance(stepName, tableName, columnName, 255, INCLUDE_AUDIT);
110 stepList.add(step);
111
112 //TODO update tree index for feature node
113
114 //update introduced: adventitious (casual) label
115 //#3540
116 stepName = "Update introduced: adventitious (casual) label";
117 String query = " UPDATE representation r " +
118 " SET r.abbreviatedlabel = 'ia' " +
119 " WHERE r.abbreviatedlabel = 'id' AND r.label = 'introduced: adventitious (casual)' ";
120 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
121 stepList.add(step);
122
123 //TODO update idInVocabulary for DefinedTerms
124
125 //TODO update termType for DefinedTerms and TermVocabulary, no type must be null
126
127 //TODO update DTYPE for modifiers (Stage, Scope, Sex, DeterminationModifier, Modifier -> DefinedTerm)
128
129
130 //TODO update rankClass (#3521)
131
132 //TODO change column type for DistanceToWaterSurface und DistanceToGround
133
134 //TODO add column for DistanceToWaterSurfaceMax/Text und DistanceToGroundMax/Text
135
136 //TODO update datatype of sequence.sequence (keeping data not necessary #3325)
137
138 //TODO update datatype->CLOB for URIs. (DefinedTerms, TermVocabulary, Reference
139 //Rights, MediaRepresentationPart, GenBankAccession, ) #3345
140
141 //TODO remove table Sequence_GenBankAccession
142
143 //TODO remove table GenBankAccession
144
145 //TODO add columns GenBankAccessionNumber(String) and GenBankUri (URI) to Sequence
146
147 //update Sicilia -> Sicily
148 //#3540
149 stepName = "Update Sicilia -> Sicily";
150 query = " UPDATE representation r " +
151 " SET r.label = 'Sicily', r.text = 'Sicily' " +
152 " WHERE (r.abbreviatedlabel = 'SIC-SI' OR r.abbreviatedlabel = 'SIC') AND r.label = 'Sicilia' ";
153 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
154 stepList.add(step);
155
156 //remove homotypical group form type designation base
157 stepName = "Remove column homotypical group in type designation base";
158 tableName = "TypeDesignationBase";
159 String oldColumnName = "homotypicalgroup_id";
160 step = ColumnRemover.NewInstance(stepName, tableName, oldColumnName, INCLUDE_AUDIT);
161 stepList.add(step);
162
163 //add publish flag to taxon
164 stepName = "Add publish flag column to taxon base";
165 tableName = "TaxonBase";
166 columnName = "publish";
167 step = ColumnAdder.NewBooleanInstance(stepName, tableName, columnName, INCLUDE_AUDIT, true);
168 stepList.add(step);
169
170 //add publish flag to specimen
171 stepName = "Add publish flag column to SpecimenOrObservationBase";
172 tableName = "SpecimenOrObservationBase";
173 columnName = "publish";
174 step = ColumnAdder.NewBooleanInstance(stepName, tableName, columnName, INCLUDE_AUDIT, true);
175 stepList.add(step);
176
177 //TODO add columns abbrevTitle, abbrevTitleCache and protectedAbbrevTitleCache to Reference
178
179
180 //add start number to PolytomousKey
181 stepName = "Add start number column to PolytomousKey";
182 tableName = "PolytomousKey";
183 columnName = "startNumber";
184 Integer defaultValue = 1;
185 step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, INCLUDE_AUDIT, defaultValue, true);
186 stepList.add(step);
187
188 //TODO add specimenOrObservation basis of record to SpecimenOrObservationBase
189
190 //add kindOfUnit to SpecimenOrObservationBase
191 stepName = "Add kindOfUnit column to SpecimenOrObservationBase";
192 tableName = "SpecimenOrObservationBase";
193 columnName = "kindOfUnit";
194 String relatedTable = "DefinedTermBase";
195 step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, INCLUDE_AUDIT, true, relatedTable);
196 stepList.add(step);
197
198
199 return stepList;
200 }
201
202 private void updateElevationMax(List<ISchemaUpdaterStep> stepList) {
203 //create column
204 String stepName = "Create absoluteElevationMax column";
205 String tableName = "GatheringEvent";
206 String columnName = "absoluteElevationMax";
207 ISchemaUpdaterStep step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, INCLUDE_AUDIT, false, null);
208 stepList.add(step);
209
210
211 //update max
212 stepName = "Update gathering elevation max";
213 //all audits to unknown type
214 String query = " UPDATE GatheringEvent ge " +
215 " SET ge.absoluteElevationMax = ge.elevation + ge.elevationErrorRadius, " +
216 " ge.absoluteElevation = ge.elevationErrorRadius - ge.elevationErrorRadius" +
217 " WHERE ge.elevationErrorRadius is not null ";
218 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
219 stepList.add(step);
220 //TODO same for AUD
221
222 //remove error column
223 stepName = "Remove elevationErrorRadius column";
224 tableName = "GatheringEvent";
225 columnName = "elevationErrorRadius";
226 step = ColumnRemover.NewInstance(stepName, tableName, columnName, INCLUDE_AUDIT);
227 stepList.add(step);
228
229
230 }
231
232 /**
233 * @param stepList
234 */
235 private void updateOriginalSourceType(List<ISchemaUpdaterStep> stepList) {
236 String stepName;
237 ISchemaUpdaterStep step;
238 stepName = "Create original source type column";
239 //all audits to unknown type
240 String query = "UPDATE OriginalSourceBase_AUD SET type = 0 ";
241 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
242 stepList.add(step);
243
244 //all data to unknown
245 query = "UPDATE OriginalSourceBase SET type = 0 ";
246 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
247 stepList.add(step);
248
249 //all imports recognized by idInSOurce and by missing nameInSource
250 query = "UPDATE OriginalSourceBase SET type = 3 WHERE " +
251 "((idInSource IS NOT NULL) OR (idNamespace IS NOT NULL)) AND " +
252 "( nameUsedInSource IS NULL AND originalNameString IS NULL ) ";
253 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
254 stepList.add(step);
255 //all imports recognized by idInSOurce and by missing nameInSource
256 query = "UPDATE OriginalSourceBase SET type = 1 WHERE " +
257 "(idInSource IS NULL AND idNamespace IS NULL) AND " +
258 "( citation IS NOT NULL ) ";
259 step = SimpleSchemaUpdaterStep.NewInstance(stepName, query);
260 stepList.add(step);
261 }
262
263 /* (non-Javadoc)
264 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getNextUpdater()
265 */
266 @Override
267 public ISchemaUpdater getNextUpdater() {
268 return null;
269 }
270
271 /* (non-Javadoc)
272 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getPreviousUpdater()
273 */
274 @Override
275 public ISchemaUpdater getPreviousUpdater() {
276 return SchemaUpdater_30_301.NewInstance();
277 }
278
279 }