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.v518_522;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21
|
import eu.etaxonomy.cdm.database.update.CaseType;
|
22
|
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
|
23
|
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
|
24
|
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @since 12.06.2020
|
29
|
*/
|
30
|
public class SecReference2SourceMover extends SchemaUpdaterStepBase {
|
31
|
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = LogManager.getLogger(SecReference2SourceMover.class);
|
34
|
|
35
|
private final String tableName;
|
36
|
private final String citationsIdAttr;
|
37
|
private final String detailAttr;
|
38
|
private final String sourcedAttr;
|
39
|
private final String sourceType;
|
40
|
private final String dtype;
|
41
|
|
42
|
public static final SecReference2SourceMover NewInstance(List<ISchemaUpdaterStep> stepList, String stepName, String tableName,
|
43
|
String citationsIdAttr, String detailAttr, String sourcedAttr, String dtype, String sourceType){
|
44
|
SecReference2SourceMover result = new SecReference2SourceMover(stepList, stepName, tableName, citationsIdAttr, detailAttr, sourcedAttr, sourceType, dtype);
|
45
|
|
46
|
return result;
|
47
|
}
|
48
|
|
49
|
protected SecReference2SourceMover(List<ISchemaUpdaterStep> stepList, String stepName, String tableName,
|
50
|
String citationsIdAttr, String detailAttr, String sourcedAttr, String sourceType, String dtype) {
|
51
|
super(stepList, stepName);
|
52
|
this.tableName = tableName;
|
53
|
this.citationsIdAttr = citationsIdAttr;
|
54
|
this.detailAttr = detailAttr;
|
55
|
this.sourcedAttr = sourcedAttr;
|
56
|
this.sourceType = sourceType == null? "PTS" : sourceType;
|
57
|
this.dtype = dtype == null? "DescriptionElementSource" : dtype;
|
58
|
this.stepName = stepName;
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public List<ISchemaUpdaterStep> getInnerSteps() {
|
63
|
List<ISchemaUpdaterStep> result = new ArrayList<>();
|
64
|
|
65
|
return result;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public void invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType,
|
70
|
SchemaUpdateResult result) throws SQLException {
|
71
|
|
72
|
boolean includeAudit = true;
|
73
|
int osbId = getMaxId1(datasource, "OriginalSourceBase", includeAudit, monitor, caseType, result);
|
74
|
|
75
|
String sql = "SELECT * "
|
76
|
+ " FROM "+caseType.transformTo(tableName)+" t "
|
77
|
+ " WHERE t."+this.citationsIdAttr+" IS NOT NULL OR t."+this.detailAttr+" IS NOT NULL ";
|
78
|
|
79
|
ResultSet rs = datasource.executeQuery(sql);
|
80
|
while(rs.next()){
|
81
|
int tnId = rs.getInt("id");
|
82
|
Integer citationId = nullSafeInt(rs, citationsIdAttr);
|
83
|
Integer createdById = nullSafeInt(rs, "createdBy_id");
|
84
|
String detail = rs.getString(detailAttr);
|
85
|
|
86
|
sql = "INSERT INTO @@OriginalSourceBase@@ (DTYPE, sourceType, uuid, id, citation_id, citationMicroReference, createdBy_id, created, "+sourcedAttr+")"
|
87
|
+ " VALUES ('"+dtype+"', '"+sourceType+"','"+UUID.randomUUID()+"'," + osbId + ", " + citationId + "," + nullSafeParam(detail) + "," + createdById + ",'" + this.getNowString() + "',"+tnId+")";
|
88
|
datasource.executeUpdate(caseType.replaceTableNames(sql));
|
89
|
|
90
|
osbId++;
|
91
|
}
|
92
|
}
|
93
|
}
|