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.io.berlinModel.in.validation;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
|
15
|
import org.apache.commons.lang.StringUtils;
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
19
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
|
20
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
21
|
import eu.etaxonomy.cdm.io.common.Source;
|
22
|
|
23
|
/**
|
24
|
* @author a.mueller
|
25
|
* @created 17.02.2010
|
26
|
*/
|
27
|
public class BerlinModelTaxonImportValidator implements IOValidator<BerlinModelImportState>{
|
28
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonImportValidator.class);
|
29
|
|
30
|
@Override
|
31
|
public boolean validate(BerlinModelImportState state){
|
32
|
boolean result = true;
|
33
|
BerlinModelImportConfigurator bmiConfig = state.getConfig();
|
34
|
// result &= checkTaxonStatus(bmiConfig); //handled by TaxonRelationValidator
|
35
|
result &= checkInactivated(bmiConfig);
|
36
|
return result;
|
37
|
}
|
38
|
|
39
|
private boolean checkTaxonStatus(BerlinModelImportConfigurator bmiConfig){
|
40
|
try {
|
41
|
boolean result = true;
|
42
|
Source source = bmiConfig.getSource();
|
43
|
String strSQL = " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache " +
|
44
|
" FROM RelPTaxon " +
|
45
|
" INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " +
|
46
|
" INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk " +
|
47
|
" INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " +
|
48
|
" WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) ";
|
49
|
ResultSet rs = source.getResultSet(strSQL);
|
50
|
boolean firstRow = true;
|
51
|
int i = 0;
|
52
|
while (rs.next()){
|
53
|
i++;
|
54
|
if (firstRow){
|
55
|
System.out.println("========================================================");
|
56
|
logger.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!");
|
57
|
System.out.println("========================================================");
|
58
|
}
|
59
|
int rIdentifier = rs.getInt("RIdentifier");
|
60
|
int nameFk = rs.getInt("PTNameFk");
|
61
|
int refFk = rs.getInt("PTRefFk");
|
62
|
int relPTaxonId = rs.getInt("relPTaxonId");
|
63
|
String taxonName = rs.getString("FullNameCache");
|
64
|
|
65
|
System.out.println("RIdentifier:" + rIdentifier + "\n name: " + nameFk +
|
66
|
"\n taxonName: " + taxonName + "\n refId: " + refFk + "\n RelPTaxonId: " + relPTaxonId );
|
67
|
result = firstRow = false;
|
68
|
}
|
69
|
if (i > 0){
|
70
|
System.out.println(" ");
|
71
|
}
|
72
|
|
73
|
return result;
|
74
|
} catch (SQLException e) {
|
75
|
e.printStackTrace();
|
76
|
return false;
|
77
|
}
|
78
|
}
|
79
|
|
80
|
private boolean checkInactivated(BerlinModelImportConfigurator config){
|
81
|
try {
|
82
|
boolean result = true;
|
83
|
Source source = config.getSource();
|
84
|
String strSQL = " SELECT * " +
|
85
|
" FROM PTaxon t " +
|
86
|
" INNER JOIN Name n ON t.PTNameFk = n.NameId " +
|
87
|
" WHERE (t.DoubtfulFlag = 'i') ";
|
88
|
|
89
|
if (StringUtils.isNotBlank(config.getTaxonTable())){
|
90
|
strSQL += String.format(" AND (t.RIdentifier IN " +
|
91
|
" (SELECT RIdentifier FROM %s ))" , config.getTaxonTable()) ;
|
92
|
}
|
93
|
strSQL += " ORDER BY t.ptRefFk, n.FullNameCache";
|
94
|
|
95
|
ResultSet rs = source.getResultSet(strSQL);
|
96
|
boolean firstRow = true;
|
97
|
int i = 0;
|
98
|
while (rs.next()){
|
99
|
i++;
|
100
|
if (firstRow){
|
101
|
System.out.println("========================================================");
|
102
|
System.out.println("There are taxa that have a doubtful flag 'i'(inactivated). Inactivated is not supported by CDM!");
|
103
|
System.out.println("========================================================");
|
104
|
}
|
105
|
int rIdentifier = rs.getInt("RIdentifier");
|
106
|
int nameFk = rs.getInt("PTNameFk");
|
107
|
int refFk = rs.getInt("PTRefFk");
|
108
|
String taxonName = rs.getString("FullNameCache");
|
109
|
|
110
|
System.out.println("RIdentifier:" + rIdentifier + "\n nameId: " + nameFk +
|
111
|
"\n taxonName: " + taxonName + "\n refId: " + refFk );
|
112
|
result = firstRow = false;
|
113
|
}
|
114
|
if (i > 0){
|
115
|
System.out.println(" ");
|
116
|
}
|
117
|
|
118
|
return result;
|
119
|
} catch (SQLException e) {
|
120
|
e.printStackTrace();
|
121
|
return false;
|
122
|
}
|
123
|
}
|
124
|
|
125
|
|
126
|
}
|