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.algaterra.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
|
* @version 1.0
|
27
|
*/
|
28
|
public class AlgaTerraSpecimenImportValidator implements IOValidator<BerlinModelImportState> {
|
29
|
@SuppressWarnings("unused")
|
30
|
private static final Logger logger = Logger.getLogger(AlgaTerraSpecimenImportValidator.class);
|
31
|
|
32
|
|
33
|
@Override
|
34
|
public boolean validate(BerlinModelImportState state) {
|
35
|
boolean result = true;
|
36
|
BerlinModelImportConfigurator bmiConfig = state.getConfig();
|
37
|
result &= checkOrphanedEcologyFacts(bmiConfig);
|
38
|
//result &= checkPartOfJournal(bmiConfig);
|
39
|
System.out.println("Checking for Specimen not yet fully implemented");
|
40
|
return result;
|
41
|
}
|
42
|
|
43
|
|
44
|
//******************************** CHECK *************************************************
|
45
|
|
46
|
private static boolean checkOrphanedEcologyFacts(BerlinModelImportConfigurator config){
|
47
|
try {
|
48
|
boolean result = true;
|
49
|
Source source = config.getSource();
|
50
|
String strQuery = "SELECT * FROM Fact " +
|
51
|
" WHERE FactCategoryFk = 202 AND ExtensionFk NOT IN (SELECT EcoFactId FROM EcoFact) " +
|
52
|
" ORDER BY ExtensionFk ";
|
53
|
|
54
|
ResultSet resulSet = source.getResultSet(strQuery);
|
55
|
boolean firstRow = true;
|
56
|
while (resulSet.next()){
|
57
|
if (firstRow){
|
58
|
System.out.println("========================================================");
|
59
|
System.out.println("There EcologyFacts with pointing to non existing EcoFacts!");
|
60
|
System.out.println("========================================================");
|
61
|
}
|
62
|
int factId = resulSet.getInt("FactId");
|
63
|
int extensionFk = resulSet.getInt("ExtensionFk");
|
64
|
|
65
|
System.out.println("FactId:" + factId + "\n ExtensionFk: " + extensionFk);
|
66
|
|
67
|
result = firstRow = false;
|
68
|
}
|
69
|
|
70
|
return result;
|
71
|
} catch (SQLException e) {
|
72
|
e.printStackTrace();
|
73
|
return false;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
}
|