Project

General

Profile

Download (20.3 KB) Statistics
| Branch: | Tag: | Revision:
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.database.update.v50_51;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.database.update.ColumnAdder;
19
import eu.etaxonomy.cdm.database.update.ColumnNameChanger;
20
import eu.etaxonomy.cdm.database.update.ColumnRemover;
21
import eu.etaxonomy.cdm.database.update.ColumnTypeChanger;
22
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
23
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
24
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
25
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
26
import eu.etaxonomy.cdm.database.update.TableNameChanger;
27
import eu.etaxonomy.cdm.database.update.TermRepresentationUpdater;
28
import eu.etaxonomy.cdm.database.update.v47_50.SchemaUpdater_47_50;
29
import eu.etaxonomy.cdm.model.common.TermType;
30

    
31
/**
32
/**
33
 * @author a.mueller
34
 * @date 09.06.2017
35
 *
36
 */
37
public class SchemaUpdater_50_55 extends SchemaUpdaterBase {
38

    
39
	@SuppressWarnings("unused")
40
	private static final Logger logger = Logger.getLogger(SchemaUpdater_50_55.class);
41
	private static final String startSchemaVersion = "5.0.0.0.20180514";
42
	private static final String endSchemaVersion = "5.5.0.0.20190221";
43

    
44
	// ********************** FACTORY METHOD *************************************
45

    
46
	public static SchemaUpdater_50_55 NewInstance() {
47
		return new SchemaUpdater_50_55();
48
	}
49

    
50
	/**
51
	 * @param startSchemaVersion
52
	 * @param endSchemaVersion
53
	 */
54
	protected SchemaUpdater_50_55() {
55
		super(startSchemaVersion, endSchemaVersion);
56
	}
57

    
58
	@Override
59
	protected List<ISchemaUpdaterStep> getUpdaterList() {
60

    
61
		String stepName;
62
		String tableName;
63
		ISchemaUpdaterStep step;
64
		String newColumnName;
65
		String query;
66

    
67
		List<ISchemaUpdaterStep> stepList = new ArrayList<>();
68

    
69

    
70
		//#6699 delete term version
71
		//just in case not fixed before yet
72
		stepName = "Delete term version";
73
		query = "DELETE FROM @@CdmMetaData@@ WHERE propertyName = 'TERM_VERSION'";
74
		step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
75
        stepList.add(step);
76

    
77
        //#7414 remove mediaCreatedOld column
78
        stepName = "remove mediaCreatedOld column";
79
        tableName = "Media";
80
        String oldColumnName = "mediaCreatedOld";
81
        step = ColumnRemover.NewInstance(stepName, tableName, oldColumnName, INCLUDE_AUDIT);
82
        stepList.add(step);
83

    
84
        //TODO remove proparte and partial columns
85

    
86
        //#7772 rename TermBase_inverseRepresentation to DefinedTermBase_InverseRepresentation
87
        stepName = "Rename TermBase_inverseRepresentation to DefinedTermBase_InverseRepresentation";
88
        String oldName = "TermBase_inverseRepresentation";
89
        String newName = "DefinedTermBase_InverseRepresentation";
90
        step = TableNameChanger.NewInstance(stepName, oldName,
91
                newName, INCLUDE_AUDIT);
92
        stepList.add(step);
93

    
94
        //#7772 rename DefinedTermBase_InverseRepresentation.term_id to .definedTermBase_id
95
        stepName = "Rename TermBase_inverseRepresentation to DefinedTermBase_InverseRepresentation";
96
        tableName = "DefinedTermBase_InverseRepresentation";
97
        oldColumnName = "term_id";
98
        newColumnName = "definedTermBase_id";
99
        step = ColumnNameChanger.NewIntegerInstance(stepName, tableName, oldColumnName, newColumnName, INCLUDE_AUDIT);
100
        stepList.add(step);
101

    
102
        //#8004 add sortindex to description element
103
        stepName = "Add sortindex to description element";
104
        tableName = "DescriptionElementBase";
105
        newColumnName = "sortIndex";
106
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, null, !NOT_NULL);
107
        stepList.add(step);
108

    
109
        //#7682 update Point.precision from 0 to null
110
        stepName = "update Point.precision from 0 to null";
111
        query = "UPDATE @@GatheringEvent@@ SET exactLocation_errorRadius = null WHERE exactLocation_errorRadius = 0 ";
112
        tableName = "GatheringEvent";
113
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
114
        stepList.add(step);
115

    
116
        //#7859 CdmPreference.value as CLOB
117
        stepName = "Make CdmPreference.value a CLOB";
118
        String columnName = "value";
119
        tableName = "CdmPreference";
120
        // TODO check non MySQL and with existing data (probably does not exist)
121
        step = ColumnTypeChanger.NewClobInstance(stepName, tableName,
122
                columnName, INCLUDE_AUDIT);
123
        stepList.add(step);
124

    
125
        //#7857 update name realtionships
126
        updateNameRelationships(stepList);
127

    
128
        //#7683 allow null for ExternalLink_AUD.uuid
129
        stepName = "Allow null for ExternalLink_AUD.uuid ";
130
        columnName = "uuid";
131
        tableName = "ExternalLink_AUD";
132
        step = ColumnTypeChanger.NewStringSizeInstance(stepName, tableName, columnName, 36, !INCLUDE_AUDIT);
133
        stepList.add(step);
134

    
135
        //#7514 change symbols for pro parte synonyms and misapplied name relationship types
136
        updateConceptRelationshipSymbols(stepList);
137

    
138
        //#8006
139
        updateTaxonRelationshipLabels(stepList);
140

    
141
        //#7372
142
        stepName = "Add allowDuplicates to feature tree";
143
        tableName = "FeatureTree";
144
        newColumnName = "allowDuplicates";
145
        step = ColumnAdder.NewBooleanInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, false);
146
        stepList.add(step);
147

    
148
        //#6794 add term type to feature tree
149
        stepName = "Add termType to feature tree";
150
        tableName = "FeatureTree";
151
        newColumnName = "termType";
152
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, 255, TermType.Feature.getKey(), INCLUDE_AUDIT)
153
                .setNotNull(NOT_NULL);
154
        stepList.add(step);
155

    
156
        //#6794 add term type to feature node
157
        stepName = "Add termType to feature node";
158
        tableName = "FeatureNode";
159
        newColumnName = "termType";
160
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, 255, TermType.Feature.getKey(), INCLUDE_AUDIT)
161
                .setNotNull(NOT_NULL);
162
        stepList.add(step);
163

    
164

    
165
        return stepList;
166

    
167
	}
168

    
169
    //8006 update taxon realtionships
170
    private void updateTaxonRelationshipLabels(List<ISchemaUpdaterStep> stepList) {
171

    
172
//        //7857 Update symmetrical for name relationships
173
//        String stepName = "Update symmetrical for name relationships";
174
//        String query = "UPDATE @@DefinedTermBase@@ "
175
//                + " SET symmetrical=0 "
176
//                + " WHERE uuid IN ('049c6358-1094-4765-9fae-c9972a0e7780', '6e23ad45-3f2a-462b-ad87-d2389cd6e26c', "
177
//                + " 'c6f9afcb-8287-4a2b-a6f6-4da3a073d5de', 'eeaea868-c4c1-497f-b9fe-52c9fc4aca53') ";
178
//        String tableName = "DefinedTermBase";
179
//        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
180
//        stepList.add(step);
181

    
182
        //Taxonomically Included in
183
        String stepName = "Taxonomically Included in => is taxonomically included in";
184
        UUID uuidTerm = UUID.fromString("d13fecdf-eb44-4dd7-9244-26679c05df1c");
185
        UUID uuidLanguage = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
186
        String label = "is taxonomically included in";
187
        ISchemaUpdaterStep step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
188
                label, label, null, uuidLanguage);
189
        stepList.add(step);
190

    
191
        stepName = "taxonomically includes => taxonomically includes";
192
        label = "taxonomically includes";
193
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
194
                label, label, null, uuidLanguage);
195
        stepList.add(step);
196

    
197
        //Misapplied Name for
198
        stepName = "Misapplied Name for => is misapplied name for";
199
        uuidTerm = UUID.fromString("1ed87175-59dd-437e-959e-0d71583d8417");
200
        label = "is misapplied name for";
201
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
202
                label, label, null, uuidLanguage);
203
        stepList.add(step);
204

    
205
        stepName = "Has Misapplied Name => has misapplied name";
206
        label = "has misapplied name";
207
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
208
                label, label, null, uuidLanguage);
209
        stepList.add(step);
210

    
211
        //Pro parte Misapplied Name for
212
        stepName = "Pro parte Misapplied Name for => is pro parte misapplied name for";
213
        uuidTerm = UUID.fromString("b59b4bd2-11ff-45d1-bae2-146efdeee206");
214
        label = "is pro parte misapplied name for";
215
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
216
                label, label, null, uuidLanguage);
217
        stepList.add(step);
218

    
219
        stepName = "Has Pro parte Misapplied Name => has pro parte misapplied name";
220
        label = "has pro parte misapplied name";
221
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
222
                label, label, null, uuidLanguage);
223
        stepList.add(step);
224

    
225
        //Partial Misapplied Name for
226
        stepName = "Partial Misapplied Name for => is partial misapplied name for";
227
        uuidTerm = UUID.fromString("859fb615-b0e8-440b-866e-8a19f493cd36");
228
        label = "is partial misapplied name for";
229
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
230
                label, label, null, uuidLanguage);
231
        stepList.add(step);
232

    
233
        stepName = "Has Partial Misapplied Name => has partial misapplied name";
234
        label = "has partial misapplied name";
235
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
236
                label, label, null, uuidLanguage);
237
        stepList.add(step);
238

    
239
        //Pro parte Synonym for
240
        stepName = "Pro parte Synonym for => is pro parte synonym for";
241
        uuidTerm = UUID.fromString("8a896603-0fa3-44c6-9cd7-df2d8792e577");
242
        label = "is pro parte synonym for";
243
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
244
                label, label, null, uuidLanguage);
245
        stepList.add(step);
246

    
247
        stepName = "Has Pro parte Synonym => has pro parte synonym";
248
        label = "has pro parte synonym";
249
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
250
                label, label, null, uuidLanguage);
251
        stepList.add(step);
252

    
253
        //Partial Synonym for
254
        stepName = "Partial Synonym for => is partial synonym for";
255
        uuidTerm = UUID.fromString("9d7a5e56-973c-474c-b6c3-a1cb00833a3c");
256
        label = "is partial synonym for";
257
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
258
                label, label, null, uuidLanguage);
259
        stepList.add(step);
260

    
261
        stepName = "Has Partial Synonym => has partial synonym";
262
        label = "has partial synonym";
263
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
264
                label, label, null, uuidLanguage);
265
        stepList.add(step);
266

    
267
        //Invalid Designation for
268
        stepName = "Invalid Designation for => is invalid designation for";
269
        uuidTerm = UUID.fromString("605b1d01-f2b1-4544-b2e0-6f08def3d6ed");
270
        label = "is invalid designation for";
271
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
272
                label, label, null, uuidLanguage);
273
        stepList.add(step);
274

    
275
        stepName = "Has Invalid Designation => has invalid designation";
276
        label = "has invalid designation";
277
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
278
                label, label, null, uuidLanguage);
279
        stepList.add(step);
280

    
281
        //Not yet worked on
282
        stepName = "Unclear => Not yet worked on";
283
        label = "Not yet worked on";
284
        uuidTerm = UUID.fromString("8d47e59a-790d-428f-8060-01d443519166");
285
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
286
                label, label, null, uuidLanguage);
287
        stepList.add(step);
288
    }
289

    
290

    
291
	//7514
292
    private void updateConceptRelationshipSymbols(List<ISchemaUpdaterStep> stepList) {
293

    
294
        //Update misapplied name symbols
295
        String stepName = "Update misapplied name symbols";
296
        String query = "UPDATE @@DefinedTermBase@@ "
297
                + " SET symbol='––' , inverseSymbol = '-' "
298
                + " WHERE uuid = '1ed87175-59dd-437e-959e-0d71583d8417' ";
299
        String tableName = "DefinedTermBase";
300
        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
301
        stepList.add(step);
302

    
303
        //Update pro parte misapplied name symbols
304
        stepName = "Update pro parte misapplied name symbols";
305
        query = "UPDATE @@DefinedTermBase@@ "
306
                + " SET symbol='––(p.p.)' , inverseSymbol = '-(p.p.)' "
307
                + " WHERE uuid = 'b59b4bd2-11ff-45d1-bae2-146efdeee206' ";
308
        tableName = "DefinedTermBase";
309
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
310
        stepList.add(step);
311

    
312
        //Update partial misapplied name symbols
313
        stepName = "Update partial misapplied name symbols";
314
        query = "UPDATE @@DefinedTermBase@@ "
315
                + " SET symbol='––(part.)' , inverseSymbol = '-(part.)' "
316
                + " WHERE uuid = '859fb615-b0e8-440b-866e-8a19f493cd36' ";
317
        tableName = "DefinedTermBase";
318
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
319
        stepList.add(step);
320

    
321
        //Update pro parte synonym symbols
322
        stepName = "Update pro parte synonym symbols";
323
        query = "UPDATE @@DefinedTermBase@@ "
324
                + " SET symbol='⊃p.p.' , inverseSymbol = 'p.p.' "
325
                + " WHERE uuid = '8a896603-0fa3-44c6-9cd7-df2d8792e577' ";
326
        tableName = "DefinedTermBase";
327
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
328
        stepList.add(step);
329

    
330
        //Update partial synonym symbols
331
        stepName = "Update partial synonym symbols";
332
        query = "UPDATE @@DefinedTermBase@@ "
333
                + " SET symbol='⊃part.' , inverseSymbol = 'part.' "
334
                + " WHERE uuid = '9d7a5e56-973c-474c-b6c3-a1cb00833a3c' ";
335
        tableName = "DefinedTermBase";
336
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
337
        stepList.add(step);
338

    
339
    }
340

    
341
    //7857 update name realtionships
342
    private void updateNameRelationships(List<ISchemaUpdaterStep> stepList) {
343

    
344
        //7857 Update symmetrical for name relationships
345
        String stepName = "Update symmetrical for name relationships";
346
        String query = "UPDATE @@DefinedTermBase@@ "
347
                + " SET symmetrical=0 "
348
                + " WHERE uuid IN ('049c6358-1094-4765-9fae-c9972a0e7780', '6e23ad45-3f2a-462b-ad87-d2389cd6e26c', "
349
                + " 'c6f9afcb-8287-4a2b-a6f6-4da3a073d5de', 'eeaea868-c4c1-497f-b9fe-52c9fc4aca53') ";
350
        String tableName = "DefinedTermBase";
351
        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
352
        stepList.add(step);
353

    
354
        //orthographic variant for
355
        stepName = "orthographic variant for => is orthographic variant for";
356
        UUID uuidTerm = UUID.fromString("eeaea868-c4c1-497f-b9fe-52c9fc4aca53");
357
        UUID uuidLanguage = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
358
        String label = "is orthographic variant for";
359
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
360
                label, label, null, uuidLanguage);
361
        stepList.add(step);
362

    
363
        //original spelling for
364
        stepName = "original spelling for => is original spelling for";
365
        uuidTerm = UUID.fromString("264d2be4-e378-4168-9760-a9512ffbddc4");
366
        label = "is original spelling for";
367
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
368
                label, label, null, uuidLanguage);
369
        stepList.add(step);
370

    
371
        //misspelling for
372
        stepName = "misspelling for => is misspelling for";
373
        uuidTerm = UUID.fromString("c6f9afcb-8287-4a2b-a6f6-4da3a073d5de");
374
        label = "is misspelling for";
375
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
376
                label, label, null, uuidLanguage);
377
        stepList.add(step);
378

    
379
        //later homonym for
380
        stepName = "later homonym for => is later homonym for";
381
        uuidTerm = UUID.fromString("80f06f65-58e0-4209-b811-cb40ad7220a6");
382
        label = "is later homonym for";
383
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
384
                label, label, null, uuidLanguage);
385
        stepList.add(step);
386

    
387
        //treated as later homonym for
388
        stepName = " => is treated as later homonym for";
389
        uuidTerm = UUID.fromString("2990a884-3302-4c8b-90b2-dfd31aaa2778");
390
        label = "is treated as later homonym for";
391
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
392
                label, label, null, uuidLanguage);
393
        stepList.add(step);
394

    
395
        //alternative name for
396
        stepName = "alternative name for => is alternative name for";
397
        uuidTerm = UUID.fromString("049c6358-1094-4765-9fae-c9972a0e7780");
398
        label = "is alternative name for";
399
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
400
                label, label, null, uuidLanguage);
401
        stepList.add(step);
402

    
403
        //basionym for
404
        stepName = "basionym for => is basionym for";
405
        uuidTerm = UUID.fromString("25792738-98de-4762-bac1-8c156faded4a");
406
        label = "is basionym for";
407
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
408
                label, label, null, uuidLanguage);
409
        stepList.add(step);
410

    
411
        //replaced synonym for
412
        stepName = "replaced synonym for => is replaced synonym for";
413
        uuidTerm = UUID.fromString("71c67c38-d162-445b-b0c2-7aba56106696");
414
        label = "is replaced synonym for";
415
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
416
                label, label, null, uuidLanguage);
417
        stepList.add(step);
418

    
419
        //conserved against
420
        stepName = "conserved against => is conserved against";
421
        uuidTerm = UUID.fromString("e6439f95-bcac-4ebb-a8b5-69fa5ce79e6a");
422
        label = "is conserved against";
423
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
424
                label, label, null, uuidLanguage);
425
        stepList.add(step);
426

    
427
        //validated by
428
        stepName = "validated by => is validated by";
429
        uuidTerm = UUID.fromString("a176c9ad-b4c2-4c57-addd-90373f8270eb");
430
        label = "is validated by";
431
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
432
                label, label, null, uuidLanguage);
433
        stepList.add(step);
434

    
435
        //later validated by
436
        stepName = "later validated by => is later validated by";
437
        uuidTerm = UUID.fromString("a25ee4c1-863a-4dab-9499-290bf9b89639");
438
        label = "is later validated by";
439
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
440
                label, label, null, uuidLanguage);
441
        stepList.add(step);
442

    
443
        //blocking name for
444
        stepName = "blocking name for => is blocking name for";
445
        uuidTerm = UUID.fromString("1dab357f-2e12-4511-97a4-e5153589e6a6");
446
        label = "blocking name for";
447
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
448
                label, label, null, uuidLanguage);
449
        stepList.add(step);
450

    
451
        //emendation for
452
        stepName = "emendation for => is emendation for";
453
        uuidTerm = UUID.fromString("6e23ad45-3f2a-462b-ad87-d2389cd6e26c");
454
        label = "is emendation for";
455
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
456
                label, label, null, uuidLanguage);
457
        stepList.add(step);
458
    }
459

    
460
    @Override
461
	public ISchemaUpdater getNextUpdater() {
462
		return null;
463
	}
464

    
465
	@Override
466
	public ISchemaUpdater getPreviousUpdater() {
467
		return SchemaUpdater_47_50.NewInstance();
468
	}
469

    
470
}
    (1-1/1)