Revision 0d76bb7d
Added by Andreas Müller over 5 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java | ||
---|---|---|
25 | 25 |
* @since 17.02.2010 |
26 | 26 |
*/ |
27 | 27 |
public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinModelImportState> { |
28 |
private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class); |
|
28 |
@SuppressWarnings("unused") |
|
29 |
private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class); |
|
29 | 30 |
|
30 | 31 |
@Override |
31 | 32 |
public boolean validate(BerlinModelImportState state) { |
32 | 33 |
boolean result = true; |
33 |
BerlinModelImportConfigurator bmiConfig = state.getConfig(); |
|
34 |
result &= checkTaxonIsAccepted(bmiConfig); |
|
35 |
//result &= checkPartOfJournal(bmiConfig); |
|
36 |
System.out.println("Checking for Occurrence not yet fully implemented"); |
|
34 |
BerlinModelImportConfigurator config = state.getConfig(); |
|
35 |
result &= checkTaxonIsAccepted(config); |
|
36 |
result &= checkSourcesWithWhitespace(config); |
|
37 | 37 |
return result; |
38 | 38 |
} |
39 | 39 |
|
... | ... | |
71 | 71 |
|
72 | 72 |
} |
73 | 73 |
int occurrenceId = resultSet.getInt("OccurrenceId"); |
74 |
// int statusFk = resulSet.getInt("StatusFk");
|
|
74 |
// int statusFk = resulSet.getInt("StatusFk");
|
|
75 | 75 |
String status = resultSet.getString("Status"); |
76 | 76 |
String fullNameCache = resultSet.getString("FullNameCache"); |
77 | 77 |
String ptRefFk = resultSet.getString("PTRefFk"); |
... | ... | |
92 | 92 |
} |
93 | 93 |
} |
94 | 94 |
|
95 |
private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){ |
|
96 |
try { |
|
97 |
boolean result = true; |
|
98 |
Source source = config.getSource(); |
|
99 |
String strSelect = "SELECT OccurrenceId, PTNameFk, PTRefFk, AreaFk, Sources, Created_When, Created_Who, Updated_When, Updated_Who, Notes, Occurrence "; |
|
100 |
String strCount = " count(*) "; |
|
101 |
String strQueryBase = |
|
102 |
" FROM emOccurrence " + |
|
103 |
" WHERE (Sources LIKE '% %') OR (Sources LIKE '% ') OR (Sources LIKE ' %') "; |
|
104 |
|
|
105 |
ResultSet rs = source.getResultSet(strCount + strQueryBase); |
|
106 |
rs.next(); |
|
107 |
int n = rs.getInt("n"); |
|
108 |
if (n > 0){ |
|
109 |
System.out.println("======================================================================="); |
|
110 |
System.out.println("There are "+n+" occurrences with source attribute has unexpected whitespace!"); |
|
111 |
System.out.println("---------------------------------------------------------------"); |
|
112 |
System.out.println(strSelect + strQueryBase); |
|
113 |
System.out.println("======================================================================="); |
|
114 |
} |
|
115 |
|
|
116 |
rs = source.getResultSet(strSelect + strQueryBase); |
|
117 |
while (rs.next()){ |
|
118 |
int occurrenceId = rs.getInt("OccurrenceId"); |
|
119 |
String sources = rs.getString("Sources"); |
|
120 |
|
|
121 |
System.out.println("OccurrenceSourceId:" + occurrenceId + |
|
122 |
"\n Sources: " + sources) |
|
123 |
; |
|
124 |
} |
|
125 |
return result; |
|
126 |
} catch (SQLException e) { |
|
127 |
e.printStackTrace(); |
|
128 |
return false; |
|
129 |
} |
|
130 |
} |
|
95 | 131 |
} |
Also available in: Unified diff
add tests for occurrences sources with unwanted whitespaces