Project

General

Profile

Download (19.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.ColumnRemover;
20
import eu.etaxonomy.cdm.database.update.ColumnTypeChanger;
21
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
22
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
23
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
24
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
25
import eu.etaxonomy.cdm.database.update.TermRepresentationUpdater;
26
import eu.etaxonomy.cdm.database.update.v47_50.SchemaUpdater_47_50;
27
import eu.etaxonomy.cdm.model.common.TermType;
28

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

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

    
42
	// ********************** FACTORY METHOD *************************************
43

    
44
	public static SchemaUpdater_50_55 NewInstance() {
45
		return new SchemaUpdater_50_55();
46
	}
47

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

    
56
	@Override
57
	protected List<ISchemaUpdaterStep> getUpdaterList() {
58

    
59
		String stepName;
60
		String tableName;
61
		ISchemaUpdaterStep step;
62
		String newColumnName;
63
		String query;
64

    
65
		List<ISchemaUpdaterStep> stepList = new ArrayList<>();
66

    
67

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

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

    
82
        //TODO remove proparte and partial columns
83

    
84
        //#8004 add sortindex to description element
85
        stepName = "Add sortindex to description element";
86
        tableName = "DescriptionElementBase";
87
        newColumnName = "sortIndex";
88
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, null, !NOT_NULL);
89
        stepList.add(step);
90

    
91
        //7682 update Point.precision from 0 to null
92
        stepName = "update Point.precision from 0 to null";
93
        query = "UPDATE @@GatheringEvent@@ SET exactLocation_errorRadius = null WHERE exactLocation_errorRadius = 0 ";
94
        tableName = "GatheringEvent";
95
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
96
        stepList.add(step);
97

    
98
        //#7859 CdmPreference.value as CLOB
99
        stepName = "Make CdmPreference.value a CLOB";
100
        String columnName = "value";
101
        tableName = "CdmPreference";
102
        // TODO check non MySQL and with existing data (probably does not exist)
103
        step = ColumnTypeChanger.NewClobInstance(stepName, tableName,
104
                columnName, INCLUDE_AUDIT);
105
        stepList.add(step);
106

    
107
        //7857 update name realtionships
108
        updateNameRelationships(stepList);
109

    
110
        //#7683 allow null for ExternalLink_AUD.uuid
111
        stepName = "Allow null for ExternalLink_AUD.uuid ";
112
        columnName = "uuid";
113
        tableName = "ExternalLink_AUD";
114
        // TODO check non MySQL and with existing data (probably does not exist)
115
        step = ColumnTypeChanger.NewStringSizeInstance(stepName, tableName, columnName, 36, !INCLUDE_AUDIT);
116
        stepList.add(step);
117

    
118
        //7514 change symbols for pro parte synonyms and misapplied name relationship types
119
        updateConceptRelationshipSymbols(stepList);
120

    
121
        //8006
122
        updateTaxonRelationshipLabels(stepList);
123

    
124
        //#7372
125
        stepName = "Add allowDuplicates to feature tree";
126
        tableName = "FeatureTree";
127
        newColumnName = "allowDuplicates";
128
        step = ColumnAdder.NewBooleanInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, false);
129
        stepList.add(step);
130

    
131
        //#6794 add term type to feature tree
132
        stepName = "Add termType to feature tree";
133
        tableName = "FeatureTree";
134
        newColumnName = "termType";
135
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, 255, TermType.Feature.getKey(), INCLUDE_AUDIT)
136
                .setNotNull(NOT_NULL);
137
        stepList.add(step);
138

    
139
        //#6794 add term type to feature node
140
        stepName = "Add termType to feature node";
141
        tableName = "FeatureNode";
142
        newColumnName = "termType";
143
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, 255, TermType.Feature.getKey(), INCLUDE_AUDIT)
144
                .setNotNull(NOT_NULL);
145
        stepList.add(step);
146

    
147

    
148
        return stepList;
149

    
150
	}
151

    
152
    //8006 update taxon realtionships
153
    private void updateTaxonRelationshipLabels(List<ISchemaUpdaterStep> stepList) {
154

    
155
//        //7857 Update symmetrical for name relationships
156
//        String stepName = "Update symmetrical for name relationships";
157
//        String query = "UPDATE @@DefinedTermBase@@ "
158
//                + " SET symmetrical=0 "
159
//                + " WHERE uuid IN ('049c6358-1094-4765-9fae-c9972a0e7780', '6e23ad45-3f2a-462b-ad87-d2389cd6e26c', "
160
//                + " 'c6f9afcb-8287-4a2b-a6f6-4da3a073d5de', 'eeaea868-c4c1-497f-b9fe-52c9fc4aca53') ";
161
//        String tableName = "DefinedTermBase";
162
//        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
163
//        stepList.add(step);
164

    
165
        //Taxonomically Included in
166
        String stepName = "Taxonomically Included in => is taxonomically included in";
167
        UUID uuidTerm = UUID.fromString("d13fecdf-eb44-4dd7-9244-26679c05df1c");
168
        UUID uuidLanguage = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
169
        String label = "is taxonomically included in";
170
        ISchemaUpdaterStep step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
171
                label, label, null, uuidLanguage);
172
        stepList.add(step);
173

    
174
        stepName = "taxonomically includes => taxonomically includes";
175
        label = "taxonomically includes";
176
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
177
                label, label, null, uuidLanguage);
178
        stepList.add(step);
179

    
180
        //Misapplied Name for
181
        stepName = "Misapplied Name for => is misapplied name for";
182
        uuidTerm = UUID.fromString("1ed87175-59dd-437e-959e-0d71583d8417");
183
        label = "is misapplied name for";
184
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
185
                label, label, null, uuidLanguage);
186
        stepList.add(step);
187

    
188
        stepName = "Has Misapplied Name => has misapplied name";
189
        label = "has misapplied name";
190
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
191
                label, label, null, uuidLanguage);
192
        stepList.add(step);
193

    
194
        //Pro parte Misapplied Name for
195
        stepName = "Pro parte Misapplied Name for => is pro parte misapplied name for";
196
        uuidTerm = UUID.fromString("b59b4bd2-11ff-45d1-bae2-146efdeee206");
197
        label = "is pro parte misapplied name for";
198
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
199
                label, label, null, uuidLanguage);
200
        stepList.add(step);
201

    
202
        stepName = "Has Pro parte Misapplied Name => has pro parte misapplied name";
203
        label = "has pro parte misapplied name";
204
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
205
                label, label, null, uuidLanguage);
206
        stepList.add(step);
207

    
208
        //Partial Misapplied Name for
209
        stepName = "Partial Misapplied Name for => is partial misapplied name for";
210
        uuidTerm = UUID.fromString("859fb615-b0e8-440b-866e-8a19f493cd36");
211
        label = "is partial misapplied name for";
212
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
213
                label, label, null, uuidLanguage);
214
        stepList.add(step);
215

    
216
        stepName = "Has Partial Misapplied Name => has partial misapplied name";
217
        label = "has partial misapplied name";
218
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
219
                label, label, null, uuidLanguage);
220
        stepList.add(step);
221

    
222
        //Pro parte Synonym for
223
        stepName = "Pro parte Synonym for => is pro parte synonym for";
224
        uuidTerm = UUID.fromString("8a896603-0fa3-44c6-9cd7-df2d8792e577");
225
        label = "is pro parte synonym for";
226
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
227
                label, label, null, uuidLanguage);
228
        stepList.add(step);
229

    
230
        stepName = "Has Pro parte Synonym => has pro parte synonym";
231
        label = "has pro parte synonym";
232
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
233
                label, label, null, uuidLanguage);
234
        stepList.add(step);
235

    
236
        //Partial Synonym for
237
        stepName = "Partial Synonym for => is partial synonym for";
238
        uuidTerm = UUID.fromString("9d7a5e56-973c-474c-b6c3-a1cb00833a3c");
239
        label = "is partial synonym for";
240
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
241
                label, label, null, uuidLanguage);
242
        stepList.add(step);
243

    
244
        stepName = "Has Partial Synonym => has partial synonym";
245
        label = "has partial synonym";
246
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
247
                label, label, null, uuidLanguage);
248
        stepList.add(step);
249

    
250
        //Invalid Designation for
251
        stepName = "Invalid Designation for => is invalid designation for";
252
        uuidTerm = UUID.fromString("605b1d01-f2b1-4544-b2e0-6f08def3d6ed");
253
        label = "is invalid designation for";
254
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
255
                label, label, null, uuidLanguage);
256
        stepList.add(step);
257

    
258
        stepName = "Has Invalid Designation => has invalid designation";
259
        label = "has invalid designation";
260
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
261
                label, label, null, uuidLanguage);
262
        stepList.add(step);
263

    
264
        //Not yet worked on
265
        stepName = "Unclear => Not yet worked on";
266
        label = "Not yet worked on";
267
        uuidTerm = UUID.fromString("8d47e59a-790d-428f-8060-01d443519166");
268
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
269
                label, label, null, uuidLanguage);
270
        stepList.add(step);
271
    }
272

    
273

    
274
	//7514
275
    private void updateConceptRelationshipSymbols(List<ISchemaUpdaterStep> stepList) {
276

    
277
        //Update misapplied name symbols
278
        String stepName = "Update misapplied name symbols";
279
        String query = "UPDATE @@DefinedTermBase@@ "
280
                + " SET symbol='––' , inverseSymbol = '-' "
281
                + " WHERE uuid = '1ed87175-59dd-437e-959e-0d71583d8417' ";
282
        String tableName = "DefinedTermBase";
283
        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
284
        stepList.add(step);
285

    
286
        //Update pro parte misapplied name symbols
287
        stepName = "Update pro parte misapplied name symbols";
288
        query = "UPDATE @@DefinedTermBase@@ "
289
                + " SET symbol='––(p.p.)' , inverseSymbol = '-(p.p.)' "
290
                + " WHERE uuid = 'b59b4bd2-11ff-45d1-bae2-146efdeee206' ";
291
        tableName = "DefinedTermBase";
292
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
293
        stepList.add(step);
294

    
295
        //Update partial misapplied name symbols
296
        stepName = "Update partial misapplied name symbols";
297
        query = "UPDATE @@DefinedTermBase@@ "
298
                + " SET symbol='––(part.)' , inverseSymbol = '-(part.)' "
299
                + " WHERE uuid = '859fb615-b0e8-440b-866e-8a19f493cd36' ";
300
        tableName = "DefinedTermBase";
301
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
302
        stepList.add(step);
303

    
304
        //Update pro parte synonym symbols
305
        stepName = "Update pro parte synonym symbols";
306
        query = "UPDATE @@DefinedTermBase@@ "
307
                + " SET symbol='⊃p.p.' , inverseSymbol = 'p.p.' "
308
                + " WHERE uuid = '8a896603-0fa3-44c6-9cd7-df2d8792e577' ";
309
        tableName = "DefinedTermBase";
310
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
311
        stepList.add(step);
312

    
313
        //Update partial synonym symbols
314
        stepName = "Update partial synonym symbols";
315
        query = "UPDATE @@DefinedTermBase@@ "
316
                + " SET symbol='⊃part.' , inverseSymbol = 'part.' "
317
                + " WHERE uuid = '9d7a5e56-973c-474c-b6c3-a1cb00833a3c' ";
318
        tableName = "DefinedTermBase";
319
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
320
        stepList.add(step);
321

    
322
    }
323

    
324
    //7857 update name realtionships
325
    private void updateNameRelationships(List<ISchemaUpdaterStep> stepList) {
326

    
327
        //7857 Update symmetrical for name relationships
328
        String stepName = "Update symmetrical for name relationships";
329
        String query = "UPDATE @@DefinedTermBase@@ "
330
                + " SET symmetrical=0 "
331
                + " WHERE uuid IN ('049c6358-1094-4765-9fae-c9972a0e7780', '6e23ad45-3f2a-462b-ad87-d2389cd6e26c', "
332
                + " 'c6f9afcb-8287-4a2b-a6f6-4da3a073d5de', 'eeaea868-c4c1-497f-b9fe-52c9fc4aca53') ";
333
        String tableName = "DefinedTermBase";
334
        ISchemaUpdaterStep step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
335
        stepList.add(step);
336

    
337
        //orthographic variant for
338
        stepName = "orthographic variant for => is orthographic variant for";
339
        UUID uuidTerm = UUID.fromString("eeaea868-c4c1-497f-b9fe-52c9fc4aca53");
340
        UUID uuidLanguage = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
341
        String label = "is orthographic variant for";
342
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
343
                label, label, null, uuidLanguage);
344
        stepList.add(step);
345

    
346
        //original spelling for
347
        stepName = "original spelling for => is original spelling for";
348
        uuidTerm = UUID.fromString("264d2be4-e378-4168-9760-a9512ffbddc4");
349
        label = "is original spelling for";
350
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
351
                label, label, null, uuidLanguage);
352
        stepList.add(step);
353

    
354
        //misspelling for
355
        stepName = "misspelling for => is misspelling for";
356
        uuidTerm = UUID.fromString("c6f9afcb-8287-4a2b-a6f6-4da3a073d5de");
357
        label = "is misspelling for";
358
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
359
                label, label, null, uuidLanguage);
360
        stepList.add(step);
361

    
362
        //later homonym for
363
        stepName = "later homonym for => is later homonym for";
364
        uuidTerm = UUID.fromString("80f06f65-58e0-4209-b811-cb40ad7220a6");
365
        label = "is later homonym for";
366
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
367
                label, label, null, uuidLanguage);
368
        stepList.add(step);
369

    
370
        //treated as later homonym for
371
        stepName = " => is treated as later homonym for";
372
        uuidTerm = UUID.fromString("2990a884-3302-4c8b-90b2-dfd31aaa2778");
373
        label = "is treated as later homonym for";
374
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
375
                label, label, null, uuidLanguage);
376
        stepList.add(step);
377

    
378
        //alternative name for
379
        stepName = "alternative name for => is alternative name for";
380
        uuidTerm = UUID.fromString("049c6358-1094-4765-9fae-c9972a0e7780");
381
        label = "is alternative name for";
382
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
383
                label, label, null, uuidLanguage);
384
        stepList.add(step);
385

    
386
        //basionym for
387
        stepName = "basionym for => is basionym for";
388
        uuidTerm = UUID.fromString("25792738-98de-4762-bac1-8c156faded4a");
389
        label = "is basionym for";
390
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
391
                label, label, null, uuidLanguage);
392
        stepList.add(step);
393

    
394
        //replaced synonym for
395
        stepName = "replaced synonym for => is replaced synonym for";
396
        uuidTerm = UUID.fromString("71c67c38-d162-445b-b0c2-7aba56106696");
397
        label = "is replaced synonym for";
398
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
399
                label, label, null, uuidLanguage);
400
        stepList.add(step);
401

    
402
        //conserved against
403
        stepName = "conserved against => is conserved against";
404
        uuidTerm = UUID.fromString("e6439f95-bcac-4ebb-a8b5-69fa5ce79e6a");
405
        label = "is conserved against";
406
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
407
                label, label, null, uuidLanguage);
408
        stepList.add(step);
409

    
410
        //validated by
411
        stepName = "validated by => is validated by";
412
        uuidTerm = UUID.fromString("a176c9ad-b4c2-4c57-addd-90373f8270eb");
413
        label = "is validated by";
414
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
415
                label, label, null, uuidLanguage);
416
        stepList.add(step);
417

    
418
        //later validated by
419
        stepName = "later validated by => is later validated by";
420
        uuidTerm = UUID.fromString("a25ee4c1-863a-4dab-9499-290bf9b89639");
421
        label = "is later validated by";
422
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
423
                label, label, null, uuidLanguage);
424
        stepList.add(step);
425

    
426
        //blocking name for
427
        stepName = "blocking name for => is blocking name for";
428
        uuidTerm = UUID.fromString("1dab357f-2e12-4511-97a4-e5153589e6a6");
429
        label = "blocking name for";
430
        step = TermRepresentationUpdater.NewInstanceWithTitleCache(stepName, uuidTerm,
431
                label, label, null, uuidLanguage);
432
        stepList.add(step);
433

    
434
        //emendation for
435
        stepName = "emendation for => is emendation for";
436
        uuidTerm = UUID.fromString("6e23ad45-3f2a-462b-ad87-d2389cd6e26c");
437
        label = "is emendation for";
438
        step = TermRepresentationUpdater.NewReverseInstance(stepName, uuidTerm,
439
                label, label, null, uuidLanguage);
440
        stepList.add(step);
441
    }
442

    
443
    @Override
444
	public ISchemaUpdater getNextUpdater() {
445
		return null;
446
	}
447

    
448
	@Override
449
	public ISchemaUpdater getPreviousUpdater() {
450
		return SchemaUpdater_47_50.NewInstance();
451
	}
452

    
453
}
    (1-1/1)