Project

General

Profile

Revision 712e8e67

ID712e8e67d9a9622c86db8e75e9931fd676e747ec
Parent 3e9af0ff
Child 2d4f2380

Added by Andreas Müller over 2 years ago

rename model version 4.9 to 5.0

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/CdmMetaData.java
60 60
	 */
61 61
//	private static final String dbSchemaVersion = "4.1.0.0.201607300000";
62 62
//  private static final String dbSchemaVersion = "4.7.0.0.201710040000";
63
     private static final String dbSchemaVersion = "4.9.0.0.20170710";
63
     private static final String dbSchemaVersion = "5.0.0.0.20180514";
64 64

  
65 65

  
66 66
	/* END OF CONFUSION */
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/CdmUpdater.java
17 17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18 18
import eu.etaxonomy.cdm.database.CdmDataSource;
19 19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.database.update.v47_49.SchemaUpdater_47_49;
20
import eu.etaxonomy.cdm.database.update.v47_50.SchemaUpdater_47_50;
21 21
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
22 22

  
23 23
/**
......
74 74
     * @return
75 75
     */
76 76
    private ISchemaUpdater getCurrentSchemaUpdater() {
77
        return SchemaUpdater_47_49.NewInstance();
77
        return SchemaUpdater_47_50.NewInstance();
78 78
    }
79 79

  
80 80
    /**
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v41_47/SchemaUpdater_41_47.java
27 27
import eu.etaxonomy.cdm.database.update.TableNameChanger;
28 28
import eu.etaxonomy.cdm.database.update.UniqueIndexDropper;
29 29
import eu.etaxonomy.cdm.database.update.v40_41.SchemaUpdater_40_41;
30
import eu.etaxonomy.cdm.database.update.v47_49.SchemaUpdater_47_49;
30
import eu.etaxonomy.cdm.database.update.v47_50.SchemaUpdater_47_50;
31 31

  
32 32
/**
33 33
 * @author a.mueller
......
532 532

  
533 533
    @Override
534 534
	public ISchemaUpdater getNextUpdater() {
535
		return SchemaUpdater_47_49.NewInstance() ;
535
		return SchemaUpdater_47_50.NewInstance() ;
536 536
	}
537 537

  
538 538
	@Override
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_49/SchemaUpdater_47_49.java
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.v47_49;
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.ClassBaseTypeUpdater;
19
import eu.etaxonomy.cdm.database.update.ColumnAdder;
20
import eu.etaxonomy.cdm.database.update.ColumnNameChanger;
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.MnTableCreator;
25
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
26
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
27
import eu.etaxonomy.cdm.database.update.TableCreator;
28
import eu.etaxonomy.cdm.database.update.TableNameChanger;
29
import eu.etaxonomy.cdm.database.update.TermRepresentationUpdater;
30
import eu.etaxonomy.cdm.database.update.v41_47.SchemaUpdater_41_47;
31

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

  
40
	@SuppressWarnings("unused")
41
	private static final Logger logger = Logger.getLogger(SchemaUpdater_47_49.class);
42
	private static final String endSchemaVersion = "4.9.0.0.20170710";
43
	private static final String startSchemaVersion = "4.7.0.0.201710040000";
44

  
45
	// ********************** FACTORY METHOD *************************************
46

  
47
	public static SchemaUpdater_47_49 NewInstance() {
48
		return new SchemaUpdater_47_49();
49
	}
50

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

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

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

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

  
70
        //#6581 make nomenclatural reference and OriginalSource
71
        stepName = "Make nomenclatural reference and OriginalSource";
72
        tableName = "TaxonName";
73
        newColumnName = "nomenclaturalSource_id";
74
        String referencedTable = "OriginalSourceBase";
75
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
76
        stepList.add(step);
77

  
78
		//#7109 nom. valid => nom. val.
79
		stepName = "nom valid => nom. val. (abbrevLabel)";
80
		UUID uuidTerm = UUID.fromString("bd036217-5499-4ccd-8f4c-72e06158db93");
81
		UUID uuidLanguage = UUID.fromString("160a5b6c-87f5-4422-9bda-78cd404c179e");
82
		step = TermRepresentationUpdater.NewInstance(stepName, uuidTerm,
83
		        null, null, "nom. val.", uuidLanguage);
84
		stepList.add(step);
85

  
86
		//... idInVoc
87
		stepName = "nom valid => nom. val. (idInVocabulary)";
88
        query = "UPDATE @@DefinedTermBase@@ "
89
                + " SET idInVocabulary = 'nom. val.' "
90
                + " WHERE uuid = '" + uuidTerm + "'";
91
		tableName = "DefinedTermBase";
92
		step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
93
		stepList.add(step);
94

  
95
		//#6752 add Reference.datePublished_verbatimDate
96
	    stepName = "Add Reference.datePublished_verbatimDate";
97
	    tableName = "Reference";
98
	    newColumnName = "datePublished_verbatimDate";
99
	    step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT);
100
	    stepList.add(step);
101

  
102
		//#7096 Add second symbol attribute to DefinedTermBase
103
		stepName = "Add second symbol to DefinedTermBase";
104
		tableName = "DefinedTermBase";
105
		newColumnName = "symbol2";
106
		int length = 30;
107
		step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, length, INCLUDE_AUDIT);
108
		stepList.add(step);
109

  
110
		//#6879 Update uuid and name for admin user group
111
	    stepName = "Update uuid and name for admin user group";
112
        query = "UPDATE @@PermissionGroup@@ "
113
                + " SET uuid='1739df71-bf73-4dc6-8320-aaaf72cb555f', name='Admin' "
114
                + " WHERE  name='admin' or name='Admin'";
115
        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
116
        stepList.add(step);
117

  
118
        //#7405 Rename WorkingSet to DescriptiveDataSet
119
        String oldTableName = "WorkingSet";
120
        changeSingleWorkingSetTableName(stepList, oldTableName);
121

  
122
        oldTableName = "WorkingSet_Annotation";
123
        changeSingleWorkingSetTableName(stepList, oldTableName);
124

  
125
        oldTableName = "WorkingSet_DescriptionBase";
126
        changeSingleWorkingSetTableName(stepList, oldTableName);
127

  
128
        oldTableName = "WorkingSet_Marker";
129
        changeSingleWorkingSetTableName(stepList, oldTableName);
130

  
131
        oldTableName = "WorkingSet_NamedArea";
132
        changeSingleWorkingSetTableName(stepList, oldTableName);
133

  
134
        oldTableName = "WorkingSet_Representation";
135
        changeSingleWorkingSetTableName(stepList, oldTableName);
136

  
137
        oldTableName = "WorkingSet_TaxonNode";
138
        changeSingleWorkingSetTableName(stepList, oldTableName);
139

  
140
        //#2335 Make DescriptiveDataSet IdentifiableEntity
141
        stepName = "Make DescriptiveDataSet IdentifiableEntity";
142
        tableName = "DescriptiveDataSet";
143
        step = ClassBaseTypeUpdater.NewAnnotatableToIdentifiableInstance(stepName, tableName, INCLUDE_AUDIT);
144
        stepList.add(step);
145

  
146
        //TODO add titleCache updater, but maybe not necessary as real data does not really exist
147
        //except for Campanula test data, and it is easy to update via TaxEditor cache updater
148

  
149

  
150
        //#7374 Set titleCache of feature trees to protected
151
        stepName = "Set titleCache of feature trees to protected";
152
        query = "UPDATE @@FeatureTree@@ "
153
                + " SET protectedTitleCache = @TRUE@ ";
154
        tableName = "FeatureTree";
155
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
156
        stepList.add(step);
157

  
158

  
159
        //#7238 rename lastName and firstName
160
        stepName = "rename lastName";
161
        tableName = "AgentBase";
162
        String oldColumnName = "lastname";
163
        newColumnName = "familyName";
164
        int size = 255;
165
        step = ColumnNameChanger.NewVarCharInstance(stepName, tableName, oldColumnName, newColumnName, size, INCLUDE_AUDIT);
166
        stepList.add(step);
167

  
168
        //... firstName
169
        stepName = "rename firstName";
170
        tableName = "AgentBase";
171
        oldColumnName = "firstname";
172
        newColumnName = "givenName";
173
        size = 255;
174
        step = ColumnNameChanger.NewVarCharInstance(stepName, tableName, oldColumnName, newColumnName, size, INCLUDE_AUDIT);
175
        stepList.add(step);
176

  
177
        //#7210 Add salt field for User
178
        stepName = "Add salt field for User";
179
        tableName = "UserAccount";
180
        newColumnName = "salt";
181
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, length, INCLUDE_AUDIT);
182
        stepList.add(step);
183

  
184
        //#6943 Add combination 'in'-author
185
        stepName = "Add combination 'in'-author";
186
        tableName = "TaxonName";
187
        newColumnName = "inCombinationAuthorship_id";
188
        referencedTable = "AgentBase";
189
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
190
        stepList.add(step);
191

  
192
        //#6943 Add basionym 'in'-author
193
        stepName = "Add basionym 'in'-author";
194
        tableName = "TaxonName";
195
        newColumnName = "inBasionymAuthorship_id";
196
        referencedTable = "AgentBase";
197
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
198
        stepList.add(step);
199

  
200
        //#6916 Link IntextReference to OriginalSource
201
        stepName = "Link IntextReference to OriginalSource";
202
        tableName = "IntextReference";
203
        newColumnName = "source_id";
204
        referencedTable = "OriginalSourceBase";
205
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
206
        stepList.add(step);
207

  
208
        //#6720 Make individual count a string
209
        stepName = "Make individual count a string";
210
        tableName = "SpecimenOrObservationBase";
211
        String columnName = "individualCount";
212
        size = 255;
213
        step = ColumnTypeChanger.NewInt2StringInstance(stepName, tableName, columnName, size, INCLUDE_AUDIT, null, !NOT_NULL);
214
        stepList.add(step);
215

  
216
        updateSpecimenTypeDesignationStatusOrder(stepList);
217

  
218
        //#7144 Set Country area level
219
        stepName = "Set Country area level";
220
        query = " UPDATE @@DefinedTermBase@@ " +
221
                " SET level_id = ( SELECT id FROM (SELECT id FROM DefinedTermBase WHERE uuid = '79db63a4-1563-461e-8e41-48f5722feca4') as drv) " +
222
                " WHERE DTYPE = 'Country' ";
223
        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
224
        stepList.add(step);
225

  
226
        //#6588
227
        stepName = "Add ExternalLink table";
228
        tableName = "ExternalLink";
229
        String[] columnNames = new String[]{"linkType","uri","size"};
230
        String[] referencedTables = new String[]{null, null, null};
231
        String[] columnTypes = new String[]{"string_10","clob","int"};
232
        step = TableCreator.NewVersionableInstance(stepName, tableName,
233
                columnNames, columnTypes, referencedTables, INCLUDE_AUDIT);
234
        stepList.add(step);
235

  
236
        //add i18n description
237
        stepName= "Add i18n description to ExternalLink";
238
        String firstTableName = "ExternalLink";
239
        String attributeName = "description";
240
        step = MnTableCreator.NewDescriptionInstance(stepName, firstTableName, null, attributeName, INCLUDE_AUDIT);
241
        stepList.add(step);
242

  
243

  
244
//        //7276  Make User.emailAddress a unique field
245
//        //TODO H2 / PostGreSQL / SQL Server
246
//        //User.email unique
247
//        stepName = "Update User.emailAdress unique index";
248
//        tableName = "UserAccount";
249
//        columnName = "emailAddress";
250
//        step = UsernameConstraintUpdater.NewInstance(stepName, tableName, columnName);
251
//        stepList.add(step);
252

  
253
        return stepList;
254
    }
255

  
256
    /**
257
     * @param stepList
258
     */
259
    private void updateSpecimenTypeDesignationStatusOrder(List<ISchemaUpdaterStep> stepList) {
260
        VocabularyOrderUpdater updater = VocabularyOrderUpdater.NewInstance(stepList);
261
        updater.add("a407dbc7-e60c-46ff-be11-eddf4c5a970d", 1);
262
        updater.add("05002d46-083e-4b27-8731-2e7c28a8825c", 2);
263
        updater.add("93ef8257-0a08-47bb-9b36-542417ae7560", 3);
264
        updater.add("7a1a8a53-78f4-4fc0-89f7-782e94992d08", 4);
265
        updater.add("f3b60bdb-4638-4ca9-a0c7-36e77d8459bb", 5);
266
        updater.add("052a5ff0-8e9a-4355-b24f-5e4bb6071f44", 6);
267
        updater.add("26e13359-8f77-4e40-a85a-56c01782fce0", 7);
268
        updater.add("7afc2f4f-f70a-4aa5-80a5-87764f746bde", 8);
269
        updater.add("989a2715-71d5-4fbe-aa9a-db9168353744", 9);
270
        updater.add("95b90696-e103-4bc0-b60b-c594983fb566", 10);
271
        updater.add("eb7df2e5-d9a7-479d-970c-c6f2b0a761d7", 11);
272
        updater.add("497137f3-b614-4183-8a22-97fcd6e2bdd8", 12);
273
        updater.add("7244bc51-14d8-41a6-9524-7dc5303bba29", 13);
274
        updater.add("0c39e2a5-2fe0-4d4f-819a-f609b5340339", 14);
275
        updater.add("01d91053-7004-4984-aa0d-9f4de59d6205", 15);
276
        updater.add("8d2fed1f-242e-4bcf-bbd7-e85133e479dc", 16);
277
        updater.add("49c96cae-6be6-401e-9b36-1bc12d9dc8f9", 17);
278
        updater.add("643513d0-32f5-46ba-840b-d9b9caf8160f", 18);
279
        updater.add("b7807acc-f559-474e-ad4a-e7a41e085e34", 19);
280
        updater.add("230fd762-b143-49de-ac2e-744bcc48a63b", 20);
281
        updater.add("7194020b-a326-4b47-9bfe-9f31a30aba7f", 21);
282
    }
283

  
284
    /**
285
     * @param #6368
286
     */
287
    private void changeSingleWorkingSetTableName(List<ISchemaUpdaterStep> stepList, String oldTableName) {
288
        String stepName = "Rename " +  oldTableName;
289
        String newTableName = oldTableName.replace("WorkingSet", "DescriptiveDataSet");
290
        ISchemaUpdaterStep step = TableNameChanger.NewInstance(stepName, oldTableName, newTableName, INCLUDE_AUDIT);
291
        stepList.add(step);
292

  
293
        if (oldTableName.contains("_")){
294
            stepName = "Rename " +  oldTableName + ".workingSet_id";
295
            String oldColumnName = "WorkingSet_id";
296
            String newColumnName = "DescriptiveDataSet_id";
297
            if ("WorkingSet_DescriptionBase".equals(oldTableName)){
298
                oldColumnName = "WorkingSets_id";
299
                newColumnName = "DescriptiveDataSets_id";
300
            }
301
            step = ColumnNameChanger.NewIntegerInstance(stepName, newTableName, oldColumnName, newColumnName, INCLUDE_AUDIT);
302
            stepList.add(step);
303
        }
304
    }
305

  
306

  
307
    @Override
308
	public ISchemaUpdater getNextUpdater() {
309
		return null;
310
	}
311

  
312
	@Override
313
	public ISchemaUpdater getPreviousUpdater() {
314
		return SchemaUpdater_41_47.NewInstance();
315
	}
316

  
317
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_49/VocabularyOrderUpdater.java
1
/**
2
* Copyright (C) 2009 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
package eu.etaxonomy.cdm.database.update.v47_49;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18
import eu.etaxonomy.cdm.database.ICdmDataSource;
19
import eu.etaxonomy.cdm.database.update.CaseType;
20
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
21
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
22
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
23

  
24

  
25
/**
26
 * Updates the CdmPreference NomenclaturalCode  #3658
27
 *
28
 * @author a.mueller
29
 * @since 13.10.2016
30
 */
31
public class VocabularyOrderUpdater extends SchemaUpdaterStepBase {
32
    private static final Logger logger = Logger.getLogger(VocabularyOrderUpdater.class);
33

  
34
	private static final String stepName = "Update vocabulary order";
35

  
36
	private List<String[]> data = new ArrayList<>();
37

  
38
// **************************** STATIC METHODS ********************************/
39

  
40
	public static final VocabularyOrderUpdater NewInstance(List<ISchemaUpdaterStep> stepList){
41
		VocabularyOrderUpdater result = new VocabularyOrderUpdater();
42
		stepList.add(result);
43
		return result;
44
	}
45

  
46
	private VocabularyOrderUpdater() {
47
		super(stepName);
48
	}
49

  
50
	public void add(String uuid, Integer id){
51
	    data.add(new String[]{uuid, String.valueOf(id)});
52
	}
53

  
54
    @Override
55
    public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
56
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
57

  
58
        try{
59
            for (String[] dat : data){
60
                invokeSingle(datasource, monitor, caseType, result, dat);
61
            }
62

  
63
        } catch (Exception e) {
64
            String message = e.getMessage();
65
            monitor.warning(message, e);
66
            result.addException(e, message, this, "invoke");
67
        }
68

  
69
	    return;
70
	}
71

  
72
    /**
73
     * @param datasource
74
     * @param monitor
75
     * @param caseType
76
     * @param result
77
     * @param dat
78
     * @throws SQLException
79
     */
80
    private void invokeSingle(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType,
81
            SchemaUpdateResult result, String[] dat) throws SQLException {
82
        String query = "UPDATE DefinedTermBase "
83
                + " SET orderIndex = " + dat[1] + " "
84
                + " WHERE uuid = '" + dat[0] + "'";
85
        datasource.executeUpdate(query);
86

  
87
    }
88

  
89
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_50/SchemaUpdater_47_50.java
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.v47_50;
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.ClassBaseTypeUpdater;
19
import eu.etaxonomy.cdm.database.update.ColumnAdder;
20
import eu.etaxonomy.cdm.database.update.ColumnNameChanger;
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.MnTableCreator;
25
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
26
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
27
import eu.etaxonomy.cdm.database.update.TableCreator;
28
import eu.etaxonomy.cdm.database.update.TableNameChanger;
29
import eu.etaxonomy.cdm.database.update.TermRepresentationUpdater;
30
import eu.etaxonomy.cdm.database.update.v41_47.SchemaUpdater_41_47;
31

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

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

  
45
	// ********************** FACTORY METHOD *************************************
46

  
47
	public static SchemaUpdater_47_50 NewInstance() {
48
		return new SchemaUpdater_47_50();
49
	}
50

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

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

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

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

  
70
        //#6581 make nomenclatural reference and OriginalSource
71
        stepName = "Make nomenclatural reference and OriginalSource";
72
        tableName = "TaxonName";
73
        newColumnName = "nomenclaturalSource_id";
74
        String referencedTable = "OriginalSourceBase";
75
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
76
        stepList.add(step);
77

  
78
		//#7109 nom. valid => nom. val.
79
		stepName = "nom valid => nom. val. (abbrevLabel)";
80
		UUID uuidTerm = UUID.fromString("bd036217-5499-4ccd-8f4c-72e06158db93");
81
		UUID uuidLanguage = UUID.fromString("160a5b6c-87f5-4422-9bda-78cd404c179e");
82
		step = TermRepresentationUpdater.NewInstance(stepName, uuidTerm,
83
		        null, null, "nom. val.", uuidLanguage);
84
		stepList.add(step);
85

  
86
		//... idInVoc
87
		stepName = "nom valid => nom. val. (idInVocabulary)";
88
        query = "UPDATE @@DefinedTermBase@@ "
89
                + " SET idInVocabulary = 'nom. val.' "
90
                + " WHERE uuid = '" + uuidTerm + "'";
91
		tableName = "DefinedTermBase";
92
		step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
93
		stepList.add(step);
94

  
95
		//#6752 add Reference.datePublished_verbatimDate
96
	    stepName = "Add Reference.datePublished_verbatimDate";
97
	    tableName = "Reference";
98
	    newColumnName = "datePublished_verbatimDate";
99
	    step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT);
100
	    stepList.add(step);
101

  
102
		//#7096 Add second symbol attribute to DefinedTermBase
103
		stepName = "Add second symbol to DefinedTermBase";
104
		tableName = "DefinedTermBase";
105
		newColumnName = "symbol2";
106
		int length = 30;
107
		step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, length, INCLUDE_AUDIT);
108
		stepList.add(step);
109

  
110
		//#6879 Update uuid and name for admin user group
111
	    stepName = "Update uuid and name for admin user group";
112
        query = "UPDATE @@PermissionGroup@@ "
113
                + " SET uuid='1739df71-bf73-4dc6-8320-aaaf72cb555f', name='Admin' "
114
                + " WHERE  name='admin' or name='Admin'";
115
        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
116
        stepList.add(step);
117

  
118
        //#7405 Rename WorkingSet to DescriptiveDataSet
119
        String oldTableName = "WorkingSet";
120
        changeSingleWorkingSetTableName(stepList, oldTableName);
121

  
122
        oldTableName = "WorkingSet_Annotation";
123
        changeSingleWorkingSetTableName(stepList, oldTableName);
124

  
125
        oldTableName = "WorkingSet_DescriptionBase";
126
        changeSingleWorkingSetTableName(stepList, oldTableName);
127

  
128
        oldTableName = "WorkingSet_Marker";
129
        changeSingleWorkingSetTableName(stepList, oldTableName);
130

  
131
        oldTableName = "WorkingSet_NamedArea";
132
        changeSingleWorkingSetTableName(stepList, oldTableName);
133

  
134
        oldTableName = "WorkingSet_Representation";
135
        changeSingleWorkingSetTableName(stepList, oldTableName);
136

  
137
        oldTableName = "WorkingSet_TaxonNode";
138
        changeSingleWorkingSetTableName(stepList, oldTableName);
139

  
140
        //#2335 Make DescriptiveDataSet IdentifiableEntity
141
        stepName = "Make DescriptiveDataSet IdentifiableEntity";
142
        tableName = "DescriptiveDataSet";
143
        step = ClassBaseTypeUpdater.NewAnnotatableToIdentifiableInstance(stepName, tableName, INCLUDE_AUDIT);
144
        stepList.add(step);
145

  
146
        //TODO add titleCache updater, but maybe not necessary as real data does not really exist
147
        //except for Campanula test data, and it is easy to update via TaxEditor cache updater
148

  
149

  
150
        //#7374 Set titleCache of feature trees to protected
151
        stepName = "Set titleCache of feature trees to protected";
152
        query = "UPDATE @@FeatureTree@@ "
153
                + " SET protectedTitleCache = @TRUE@ ";
154
        tableName = "FeatureTree";
155
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, tableName, -99);
156
        stepList.add(step);
157

  
158

  
159
        //#7238 rename lastName and firstName
160
        stepName = "rename lastName";
161
        tableName = "AgentBase";
162
        String oldColumnName = "lastname";
163
        newColumnName = "familyName";
164
        int size = 255;
165
        step = ColumnNameChanger.NewVarCharInstance(stepName, tableName, oldColumnName, newColumnName, size, INCLUDE_AUDIT);
166
        stepList.add(step);
167

  
168
        //... firstName
169
        stepName = "rename firstName";
170
        tableName = "AgentBase";
171
        oldColumnName = "firstname";
172
        newColumnName = "givenName";
173
        size = 255;
174
        step = ColumnNameChanger.NewVarCharInstance(stepName, tableName, oldColumnName, newColumnName, size, INCLUDE_AUDIT);
175
        stepList.add(step);
176

  
177
        //#7210 Add salt field for User
178
        stepName = "Add salt field for User";
179
        tableName = "UserAccount";
180
        newColumnName = "salt";
181
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, length, INCLUDE_AUDIT);
182
        stepList.add(step);
183

  
184
        //#6943 Add combination 'in'-author
185
        stepName = "Add combination 'in'-author";
186
        tableName = "TaxonName";
187
        newColumnName = "inCombinationAuthorship_id";
188
        referencedTable = "AgentBase";
189
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
190
        stepList.add(step);
191

  
192
        //#6943 Add basionym 'in'-author
193
        stepName = "Add basionym 'in'-author";
194
        tableName = "TaxonName";
195
        newColumnName = "inBasionymAuthorship_id";
196
        referencedTable = "AgentBase";
197
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
198
        stepList.add(step);
199

  
200
        //#6916 Link IntextReference to OriginalSource
201
        stepName = "Link IntextReference to OriginalSource";
202
        tableName = "IntextReference";
203
        newColumnName = "source_id";
204
        referencedTable = "OriginalSourceBase";
205
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
206
        stepList.add(step);
207

  
208
        //#6720 Make individual count a string
209
        stepName = "Make individual count a string";
210
        tableName = "SpecimenOrObservationBase";
211
        String columnName = "individualCount";
212
        size = 255;
213
        step = ColumnTypeChanger.NewInt2StringInstance(stepName, tableName, columnName, size, INCLUDE_AUDIT, null, !NOT_NULL);
214
        stepList.add(step);
215

  
216
        updateSpecimenTypeDesignationStatusOrder(stepList);
217

  
218
        //#7144 Set Country area level
219
        stepName = "Set Country area level";
220
        query = " UPDATE @@DefinedTermBase@@ " +
221
                " SET level_id = ( SELECT id FROM (SELECT id FROM DefinedTermBase WHERE uuid = '79db63a4-1563-461e-8e41-48f5722feca4') as drv) " +
222
                " WHERE DTYPE = 'Country' ";
223
        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
224
        stepList.add(step);
225

  
226
        //#6588
227
        stepName = "Add ExternalLink table";
228
        tableName = "ExternalLink";
229
        String[] columnNames = new String[]{"linkType","uri","size"};
230
        String[] referencedTables = new String[]{null, null, null};
231
        String[] columnTypes = new String[]{"string_10","clob","int"};
232
        step = TableCreator.NewVersionableInstance(stepName, tableName,
233
                columnNames, columnTypes, referencedTables, INCLUDE_AUDIT);
234
        stepList.add(step);
235

  
236
        //add i18n description
237
        stepName= "Add i18n description to ExternalLink";
238
        String firstTableName = "ExternalLink";
239
        String attributeName = "description";
240
        step = MnTableCreator.NewDescriptionInstance(stepName, firstTableName, null, attributeName, INCLUDE_AUDIT);
241
        stepList.add(step);
242

  
243

  
244
//        //7276  Make User.emailAddress a unique field
245
//        //TODO H2 / PostGreSQL / SQL Server
246
//        //User.email unique
247
//        stepName = "Update User.emailAdress unique index";
248
//        tableName = "UserAccount";
249
//        columnName = "emailAddress";
250
//        step = UsernameConstraintUpdater.NewInstance(stepName, tableName, columnName);
251
//        stepList.add(step);
252

  
253
        return stepList;
254
    }
255

  
256
    /**
257
     * @param stepList
258
     */
259
    private void updateSpecimenTypeDesignationStatusOrder(List<ISchemaUpdaterStep> stepList) {
260
        VocabularyOrderUpdater updater = VocabularyOrderUpdater.NewInstance(stepList);
261
        updater.add("a407dbc7-e60c-46ff-be11-eddf4c5a970d", 1);
262
        updater.add("05002d46-083e-4b27-8731-2e7c28a8825c", 2);
263
        updater.add("93ef8257-0a08-47bb-9b36-542417ae7560", 3);
264
        updater.add("7a1a8a53-78f4-4fc0-89f7-782e94992d08", 4);
265
        updater.add("f3b60bdb-4638-4ca9-a0c7-36e77d8459bb", 5);
266
        updater.add("052a5ff0-8e9a-4355-b24f-5e4bb6071f44", 6);
267
        updater.add("26e13359-8f77-4e40-a85a-56c01782fce0", 7);
268
        updater.add("7afc2f4f-f70a-4aa5-80a5-87764f746bde", 8);
269
        updater.add("989a2715-71d5-4fbe-aa9a-db9168353744", 9);
270
        updater.add("95b90696-e103-4bc0-b60b-c594983fb566", 10);
271
        updater.add("eb7df2e5-d9a7-479d-970c-c6f2b0a761d7", 11);
272
        updater.add("497137f3-b614-4183-8a22-97fcd6e2bdd8", 12);
273
        updater.add("7244bc51-14d8-41a6-9524-7dc5303bba29", 13);
274
        updater.add("0c39e2a5-2fe0-4d4f-819a-f609b5340339", 14);
275
        updater.add("01d91053-7004-4984-aa0d-9f4de59d6205", 15);
276
        updater.add("8d2fed1f-242e-4bcf-bbd7-e85133e479dc", 16);
277
        updater.add("49c96cae-6be6-401e-9b36-1bc12d9dc8f9", 17);
278
        updater.add("643513d0-32f5-46ba-840b-d9b9caf8160f", 18);
279
        updater.add("b7807acc-f559-474e-ad4a-e7a41e085e34", 19);
280
        updater.add("230fd762-b143-49de-ac2e-744bcc48a63b", 20);
281
        updater.add("7194020b-a326-4b47-9bfe-9f31a30aba7f", 21);
282
    }
283

  
284
    /**
285
     * @param #6368
286
     */
287
    private void changeSingleWorkingSetTableName(List<ISchemaUpdaterStep> stepList, String oldTableName) {
288
        String stepName = "Rename " +  oldTableName;
289
        String newTableName = oldTableName.replace("WorkingSet", "DescriptiveDataSet");
290
        ISchemaUpdaterStep step = TableNameChanger.NewInstance(stepName, oldTableName, newTableName, INCLUDE_AUDIT);
291
        stepList.add(step);
292

  
293
        if (oldTableName.contains("_")){
294
            stepName = "Rename " +  oldTableName + ".workingSet_id";
295
            String oldColumnName = "WorkingSet_id";
296
            String newColumnName = "DescriptiveDataSet_id";
297
            if ("WorkingSet_DescriptionBase".equals(oldTableName)){
298
                oldColumnName = "WorkingSets_id";
299
                newColumnName = "DescriptiveDataSets_id";
300
            }
301
            step = ColumnNameChanger.NewIntegerInstance(stepName, newTableName, oldColumnName, newColumnName, INCLUDE_AUDIT);
302
            stepList.add(step);
303
        }
304
    }
305

  
306

  
307
    @Override
308
	public ISchemaUpdater getNextUpdater() {
309
		return null;
310
	}
311

  
312
	@Override
313
	public ISchemaUpdater getPreviousUpdater() {
314
		return SchemaUpdater_41_47.NewInstance();
315
	}
316

  
317
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_50/VocabularyOrderUpdater.java
1
/**
2
* Copyright (C) 2009 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
package eu.etaxonomy.cdm.database.update.v47_50;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18
import eu.etaxonomy.cdm.database.ICdmDataSource;
19
import eu.etaxonomy.cdm.database.update.CaseType;
20
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
21
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
22
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
23

  
24

  
25
/**
26
 * Updates the CdmPreference NomenclaturalCode  #3658
27
 *
28
 * @author a.mueller
29
 * @since 13.10.2016
30
 */
31
public class VocabularyOrderUpdater extends SchemaUpdaterStepBase {
32
    private static final Logger logger = Logger.getLogger(VocabularyOrderUpdater.class);
33

  
34
	private static final String stepName = "Update vocabulary order";
35

  
36
	private List<String[]> data = new ArrayList<>();
37

  
38
// **************************** STATIC METHODS ********************************/
39

  
40
	public static final VocabularyOrderUpdater NewInstance(List<ISchemaUpdaterStep> stepList){
41
		VocabularyOrderUpdater result = new VocabularyOrderUpdater();
42
		stepList.add(result);
43
		return result;
44
	}
45

  
46
	private VocabularyOrderUpdater() {
47
		super(stepName);
48
	}
49

  
50
	public void add(String uuid, Integer id){
51
	    data.add(new String[]{uuid, String.valueOf(id)});
52
	}
53

  
54
    @Override
55
    public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
56
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
57

  
58
        try{
59
            for (String[] dat : data){
60
                invokeSingle(datasource, monitor, caseType, result, dat);
61
            }
62

  
63
        } catch (Exception e) {
64
            String message = e.getMessage();
65
            monitor.warning(message, e);
66
            result.addException(e, message, this, "invoke");
67
        }
68

  
69
	    return;
70
	}
71

  
72
    /**
73
     * @param datasource
74
     * @param monitor
75
     * @param caseType
76
     * @param result
77
     * @param dat
78
     * @throws SQLException
79
     */
80
    private void invokeSingle(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType,
81
            SchemaUpdateResult result, String[] dat) throws SQLException {
82
        String query = "UPDATE DefinedTermBase "
83
                + " SET orderIndex = " + dat[1] + " "
84
                + " WHERE uuid = '" + dat[0] + "'";
85
        datasource.executeUpdate(query);
86

  
87
    }
88

  
89
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)