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.algaterra.validation;
|
12
|
|
13
|
import java.sql.ResultSet;
|
14
|
import java.sql.SQLException;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
|
19
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
20
|
import eu.etaxonomy.cdm.io.common.Source;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @created 26.02.2013
|
25
|
*/
|
26
|
public class AlgaTerraDnaImportValidator implements IOValidator<BerlinModelImportState> {
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(AlgaTerraDnaImportValidator.class);
|
29
|
|
30
|
/* (non-Javadoc)
|
31
|
* @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
|
32
|
*/
|
33
|
public boolean validate(BerlinModelImportState state) {
|
34
|
boolean result = true;
|
35
|
result &= checkDnaFactWithoutFact(state);
|
36
|
result &= checkDnaFactsWithMultipleFacts(state);
|
37
|
return result;
|
38
|
}
|
39
|
|
40
|
|
41
|
//******************************** CHECK *************************************************
|
42
|
|
43
|
private static boolean checkDnaFactWithoutFact(BerlinModelImportState state){
|
44
|
try {
|
45
|
boolean result = true;
|
46
|
Source source = state.getConfig().getSource();
|
47
|
String strQuery = " SELECT count(*) as n FROM DNAFact " +
|
48
|
" WHERE (DNAFactID NOT IN " +
|
49
|
" (SELECT ExtensionFk " +
|
50
|
" FROM dbo.Fact AS f " +
|
51
|
" WHERE (FactCategoryFk = 203))) " ;
|
52
|
|
53
|
ResultSet rs = source.getResultSet(strQuery);
|
54
|
|
55
|
rs.next();
|
56
|
int n = rs.getInt("n");
|
57
|
if (n > 0){
|
58
|
System.out.println("========================================================");
|
59
|
System.out.println("There " + n + " are DNAFacts with no facts referencing them!");
|
60
|
System.out.println(" SQL: " + strQuery);
|
61
|
System.out.println("========================================================");
|
62
|
result = false;
|
63
|
}
|
64
|
|
65
|
return result;
|
66
|
} catch (SQLException e) {
|
67
|
e.printStackTrace();
|
68
|
return false;
|
69
|
}
|
70
|
}
|
71
|
|
72
|
|
73
|
private static boolean checkDnaFactsWithMultipleFacts(BerlinModelImportState state){
|
74
|
try {
|
75
|
boolean result = true;
|
76
|
Source source = state.getConfig().getSource();
|
77
|
String strQuery = " SELECT count(*) as n FROM (" +
|
78
|
" SELECT ExtensionFk, COUNT(*) AS n " +
|
79
|
" FROM Fact AS f " +
|
80
|
" WHERE (FactCategoryFk = 203) " +
|
81
|
" GROUP BY ExtensionFk " +
|
82
|
" HAVING (COUNT(*) > 1) " +
|
83
|
") as tmp ";
|
84
|
|
85
|
ResultSet rs = source.getResultSet(strQuery);
|
86
|
|
87
|
rs.next();
|
88
|
int n = rs.getInt("n");
|
89
|
if (n > 0){
|
90
|
System.out.println("========================================================");
|
91
|
System.out.println("There " + n + " are DNAFacts with more then 1 fact referencing them!");
|
92
|
System.out.println(" SQL: " + strQuery);
|
93
|
System.out.println("========================================================");
|
94
|
result = false;
|
95
|
}
|
96
|
|
97
|
return result;
|
98
|
} catch (SQLException e) {
|
99
|
e.printStackTrace();
|
100
|
return false;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
|
105
|
}
|