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