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.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
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
|
* @since 17.02.2010
|
25
|
*/
|
26
|
public class BerlinModelOccurrenceSourceImportValidator implements IOValidator<BerlinModelImportState> {
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceSourceImportValidator.class);
|
29
|
|
30
|
@Override
|
31
|
public boolean validate(BerlinModelImportState state) {
|
32
|
boolean result = true;
|
33
|
BerlinModelImportConfigurator config = state.getConfig();
|
34
|
result &= checkSourcesWithWhitespace(config);
|
35
|
return result;
|
36
|
}
|
37
|
|
38
|
|
39
|
//******************************** CHECK *************************************************
|
40
|
|
41
|
private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){
|
42
|
try {
|
43
|
boolean result = true;
|
44
|
Source source = config.getSource();
|
45
|
String strSelect = " SELECT OccurrenceSourceId, OccurrenceFk, Source, SourceNumber, OldName, OldNameFk, PreferredReferenceFlag ";
|
46
|
String strCount = " SELECT count(*) as n";
|
47
|
String strQueryBase =
|
48
|
" FROM emOccurrenceSource " +
|
49
|
" WHERE SourceNumber LIKE '% %' ";
|
50
|
|
51
|
ResultSet rs = source.getResultSet(strCount + strQueryBase);
|
52
|
rs.next();
|
53
|
int n = rs.getInt("n");
|
54
|
if (n > 0){
|
55
|
System.out.println("=======================================================================");
|
56
|
System.out.println("There are "+n+" occurrence source numbers with whitespace!");
|
57
|
System.out.println("---------------------------------------------------------------");
|
58
|
System.out.println(strSelect + strQueryBase);
|
59
|
System.out.println("=======================================================================");
|
60
|
}
|
61
|
|
62
|
rs = source.getResultSet(strSelect + strQueryBase);
|
63
|
while (rs.next()){
|
64
|
int occurrenceSourceId = rs.getInt("OccurrenceSourceId");
|
65
|
String sourceNumber = rs.getString("SourceNumber");
|
66
|
String Source = rs.getString("Source");
|
67
|
|
68
|
System.out.println("OccurrenceSourceId:" + occurrenceSourceId +
|
69
|
"\n Source Number: " + sourceNumber +
|
70
|
"\n Source: " + Source)
|
71
|
;
|
72
|
}
|
73
|
|
74
|
return result;
|
75
|
} catch (SQLException e) {
|
76
|
e.printStackTrace();
|
77
|
return false;
|
78
|
}
|
79
|
}
|
80
|
|
81
|
|
82
|
}
|