Project

General

Profile

Revision d7bb67dd

IDd7bb67dd266c7fa483435a39c4bd175b7ae4f2a2
Parent 662d3c82
Child 5a3638fe

Added by Andreas Müller about 1 month ago

fix #9124 add meter to altitude (update script)

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v515_518/RecommendedMeasurementUnitAdder.java
1
/**
2
* Copyright (C) 2020 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.v515_518;
10

  
11
import java.sql.SQLException;
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.common.monitor.IProgressMonitor;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.database.update.CaseType;
21
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
22
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
23
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
24

  
25
/**
26
 * @author a.mueller
27
 * @since 12.06.2020
28
 */
29
public class RecommendedMeasurementUnitAdder  extends SchemaUpdaterStepBase {
30

  
31
    @SuppressWarnings("unused")
32
    private static final Logger logger = Logger.getLogger(RecommendedMeasurementUnitAdder.class);
33

  
34
    private final UUID uuidFeature;
35
    private final UUID uuidUnit;
36

  
37
    public static final RecommendedMeasurementUnitAdder NewInstance(List<ISchemaUpdaterStep> stepList,
38
            String stepName, UUID uuidFeature, UUID uuidUnit){
39
        RecommendedMeasurementUnitAdder result = new RecommendedMeasurementUnitAdder(
40
                stepList, stepName, uuidFeature, uuidUnit);
41
        return result;
42
    }
43

  
44
    protected RecommendedMeasurementUnitAdder(List<ISchemaUpdaterStep> stepList, String stepName, UUID uuidFeature, UUID uuidUnit) {
45
        super(stepList, stepName);
46
        this.uuidFeature = uuidFeature;
47
        this.uuidUnit = uuidUnit;
48
    }
49

  
50
    @Override
51
    public List<ISchemaUpdaterStep> getInnerSteps() {
52
        List<ISchemaUpdaterStep> result = new ArrayList<>();
53
        return result;
54
    }
55

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

  
60
        boolean includeAudit = true;
61

  
62
        //find IDs
63
        String sql = "SELECT id "
64
                + " FROM "+caseType.transformTo("DefinedTermBase")+" t "
65
                + " WHERE t.uuid = '"+uuidFeature+"'";
66
        Integer idFeature = (Integer)datasource.getSingleValue(sql);
67

  
68
        sql = "SELECT id "
69
                + " FROM "+caseType.transformTo("DefinedTermBase")+" smv "
70
                + " WHERE smv.uuid = '"+uuidUnit+"'";
71
        Integer idUnit = (Integer)datasource.getSingleValue(sql);
72

  
73
        sql = "SELECT count(*) "
74
                + "FROM @@DefinedTermBase_StatisticalMeasure@@ "
75
                + " WHERE Feature_id = "+idFeature+" AND recommendedStatisticalMeasures_id = " + idUnit;
76
        Long count = (Long)datasource.getSingleValue(caseType.replaceTableNames(sql));
77
        if (count > 0){
78
            return;
79
        }
80

  
81
        //insert records
82
        sql = "INSERT INTO @@DefinedTermBase_StatisticalMeasure@@ (Feature_id, recommendedStatisticalMeasures_id)"
83
           + " VALUES (" + idFeature + "," + idUnit + ")";
84
        datasource.executeUpdate(caseType.replaceTableNames(sql));
85

  
86
        if (includeAudit){
87
            Integer rev;
88
            try {
89
                sql = "SELECT MAX(REV) "
90
                        + " FROM "+caseType.transformTo("DefinedTermBase_AUD")+" t "
91
                        + " WHERE t.uuid = '"+uuidFeature+"'";
92
                rev = (Integer)datasource.getSingleValue(sql);
93
            } catch (Exception e) {
94
                //TODO we could also create a new AUDIT event
95
                result.addWarning("Revision number for adding measurement unit to feature could not be defined. Adding is not audited.", this, "");
96
                includeAudit = false;
97
                return;
98
            }
99
            sql = "INSERT INTO @@DefinedTermBase_StatisticalMeasure_AUD@@ (REV, Feature_id, recommendedStatisticalMeasures_id, REVTYPE)"
100
                    + " VALUES ("+rev+"," + idFeature + "," + idUnit + ","+0+")";
101
            datasource.executeUpdate(caseType.replaceTableNames(sql));
102
        }
103
    }
104
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v515_518/SchemaUpdater_5152_5180.java
10 10

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

  
14 15
import org.apache.log4j.Logger;
15 16

  
......
20 21
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
21 22
import eu.etaxonomy.cdm.database.update.v512_515.Reference2SourceMover;
22 23
import eu.etaxonomy.cdm.database.update.v512_515.SchemaUpdater_5151_5152;
24
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
23 25
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.CdmVersion;
24 26

  
25 27
/**
......
194 196
                + " WHERE uuid = '03710cb5-606e-444a-a3e6-594268e3cc47' AND supportedDataTypes NOT LIKE '%#TED#%' ";
195 197
        SimpleSchemaUpdaterStep.NewAuditedInstance(stepList, stepName, sql, tableName, 99);
196 198

  
199
        //#9124
200
        //add meter to altitude
201
        stepName = "Add measurement unit [m] to feature altitude";
202
        UUID uuidAltitude = Feature.uuidAltitude;
203
        UUID uuidMeter = MeasurementUnit.uuidMeter;
204
        RecommendedMeasurementUnitAdder.NewInstance(stepList, stepName, uuidAltitude, uuidMeter);
205

  
197 206
        return stepList;
198 207
    }
199 208

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)