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.20190122";
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
        // TODO check non MySQL and with existing data (probably does not exist)
133
        step = ColumnTypeChanger.NewStringSizeInstance(stepName, tableName, columnName, 36, !INCLUDE_AUDIT);
134
        stepList.add(step);
135

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

    
139
        //8006
140
        updateTaxonRelationshipLabels(stepList);
141

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

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

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

    
165

    
166
        return stepList;
167

    
168
	}
169

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
291

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

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

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

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

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

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

    
340
    }
341

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
471
}
    (1-1/1)