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.pesi.erms.validation;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
18
|
import eu.etaxonomy.cdm.io.common.Source;
|
19
|
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportConfigurator;
|
20
|
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportState;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @since 17.02.2010
|
25
|
*/
|
26
|
public class ErmsTaxonImportValidator implements IOValidator<ErmsImportState>{
|
27
|
private static final Logger logger = Logger.getLogger(ErmsTaxonImportValidator.class);
|
28
|
|
29
|
@Override
|
30
|
public boolean validate(ErmsImportState state){
|
31
|
boolean result = true;
|
32
|
ErmsImportConfigurator config = state.getConfig();
|
33
|
logger.info("Checking for Taxa not yet fully implemented");
|
34
|
// result &= checkParentTaxonStatus(config);
|
35
|
result &= checkAccParentTaxonStatus(config);
|
36
|
result &= checkSynonymsAcceptedTaxonStatus(config);
|
37
|
return result;
|
38
|
}
|
39
|
|
40
|
private boolean checkAccParentTaxonStatus(ErmsImportConfigurator bmiConfig){
|
41
|
try {
|
42
|
boolean result = true;
|
43
|
Source source = bmiConfig.getSource();
|
44
|
String strSQL =
|
45
|
" SELECT myTaxon.id AS childId, childStatus.status_name AS childStatus, myTaxon.tu_status, " +
|
46
|
" myTaxon.tu_displayname AS childDisplayName, parent.id AS parentId, parent.tu_status AS parentStatusId, parentStatus.status_name AS parentStatus, " +
|
47
|
" parent.tu_displayname as parentName, parentAcc.id AS parentAccId, parentAccStatus.status_name AS parentAccStatus, parentAcc.tu_displayname AS parentAccName, " +
|
48
|
" parentAcc.tu_status AS Expr1 " +
|
49
|
" FROM status AS parentAccStatus INNER JOIN " +
|
50
|
" tu AS parentAcc ON parentAccStatus.status_id = parentAcc.tu_status RIGHT OUTER JOIN " +
|
51
|
" tu AS parent ON parentAcc.id = parent.tu_acctaxon RIGHT OUTER JOIN " +
|
52
|
" tu AS myTaxon ON parent.id = myTaxon.tu_parent LEFT OUTER JOIN " +
|
53
|
" status AS parentStatus ON parent.tu_status = parentStatus.status_id LEFT OUTER JOIN " +
|
54
|
" status AS childStatus ON myTaxon.tu_status = childStatus.status_id " +
|
55
|
" WHERE (myTaxon.tu_status = 1) AND (parent.tu_status <> 1) " +
|
56
|
" ORDER BY parentStatusId";
|
57
|
ResultSet rs = source.getResultSet(strSQL);
|
58
|
boolean firstRow = true;
|
59
|
int i = 0;
|
60
|
while (rs.next()){
|
61
|
i++;
|
62
|
if (firstRow){
|
63
|
System.out.println("========================================================");
|
64
|
logger.warn("There are accepted taxa that have an unaccepted parent and also the parents accepted taxon (tu_acctaxon) is not accepted. ");
|
65
|
System.out.println("========================================================");
|
66
|
}
|
67
|
int childId = rs.getInt("childId");
|
68
|
String childName = rs.getString("childDisplayName");
|
69
|
|
70
|
int parentId = rs.getInt("parentId");
|
71
|
String parentName = rs.getString("parentName");
|
72
|
String parentStatus = rs.getString("parentStatus");
|
73
|
|
74
|
int accParentId = rs.getInt("parentAccId");
|
75
|
String accParentName = rs.getString("parentAccName");
|
76
|
String accParentStatus = rs.getString("parentAccStatus");
|
77
|
|
78
|
System.out.println(
|
79
|
"ChildId:" + childId + "\n childName: " + childName +
|
80
|
"\n ParentId: " + parentId + "\n parentName: " + parentName + "\n parentStatus: " + parentStatus +
|
81
|
"\n ParentAccId: " + accParentId + "\n accParentName: " + accParentName + "\n accParentStatus: " + accParentStatus );
|
82
|
result = firstRow = false;
|
83
|
}
|
84
|
if (i > 0){
|
85
|
System.out.println(" ");
|
86
|
}
|
87
|
|
88
|
return result;
|
89
|
} catch (SQLException e) {
|
90
|
e.printStackTrace();
|
91
|
return false;
|
92
|
}
|
93
|
}
|
94
|
|
95
|
private boolean checkSynonymsAcceptedTaxonStatus(ErmsImportConfigurator bmiConfig){
|
96
|
try {
|
97
|
boolean result = true;
|
98
|
Source source = bmiConfig.getSource();
|
99
|
String strSQL =
|
100
|
" SELECT myTaxon.id AS synonymId, myTaxon.tu_displayname AS synonymName, synonymStatus.status_name AS synonymStatus, " +
|
101
|
" accTaxon.id AS acceptedId, accTaxon.tu_displayname AS acceptedName, acceptedStatus.status_name AS acceptedStatus " +
|
102
|
" FROM tu AS myTaxon INNER JOIN " +
|
103
|
" tu AS accTaxon ON myTaxon.tu_acctaxon = accTaxon.id INNER JOIN " +
|
104
|
" status AS synonymStatus ON myTaxon.tu_status = synonymStatus.status_id INNER JOIN " +
|
105
|
" status AS acceptedStatus ON accTaxon.tu_status = acceptedStatus.status_id " +
|
106
|
" WHERE (myTaxon.tu_status <> 1) AND (accTaxon.tu_status <> 1) " +
|
107
|
" ORDER BY myTaxon.tu_status, accTaxon.tu_status ";
|
108
|
ResultSet rs = source.getResultSet(strSQL);
|
109
|
boolean firstRow = true;
|
110
|
int i = 0;
|
111
|
while (rs.next()){
|
112
|
i++;
|
113
|
if (firstRow){
|
114
|
System.out.println("========================================================");
|
115
|
logger.warn("There are accepted synonyms that have an unaccepted taxon that has no status 'accepted'. ");
|
116
|
System.out.println("========================================================");
|
117
|
}
|
118
|
int synonymId = rs.getInt("synonymId");
|
119
|
String synonymName = rs.getString("synonymName");
|
120
|
String synonymStatus = rs.getString("synonymStatus");
|
121
|
|
122
|
int acceptedId = rs.getInt("acceptedId");
|
123
|
String acceptedName = rs.getString("acceptedName");
|
124
|
String acceptedStatus = rs.getString("acceptedStatus");
|
125
|
|
126
|
System.out.println(
|
127
|
"SynonymId:" + synonymId + "\n synonymName: " + synonymName + "\n synonymStatus: " + synonymStatus +
|
128
|
"\n AcceptedId: " + acceptedId + "\n acceptedName: " + acceptedName + "\n acceptedStatus: " + acceptedStatus
|
129
|
// + "\n parentAccId: " + acceptedId + "\n accParentName: " + accParentName + "\n accParentStatus: " + accParentStatus
|
130
|
);
|
131
|
result = firstRow = false;
|
132
|
}
|
133
|
if (i > 0){
|
134
|
System.out.println(" ");
|
135
|
}
|
136
|
|
137
|
return result;
|
138
|
} catch (SQLException e) {
|
139
|
e.printStackTrace();
|
140
|
return false;
|
141
|
}
|
142
|
}
|
143
|
}
|