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.berlinModel.in.validation;
|
12
|
|
13
|
import java.sql.ResultSet;
|
14
|
import java.sql.SQLException;
|
15
|
|
16
|
import org.apache.commons.lang.StringUtils;
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
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
|
*/
|
27
|
public class BerlinModelTaxonNameImportValidator implements IOValidator<BerlinModelImportState> {
|
28
|
@SuppressWarnings("unused")
|
29
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameImportValidator.class);
|
30
|
|
31
|
@Override
|
32
|
public boolean validate(BerlinModelImportState state) {
|
33
|
boolean result = true;
|
34
|
result &= checkNamesWithJournalReferences(state);
|
35
|
//result &= checkPartOfJournal(bmiConfig);
|
36
|
|
37
|
return result;
|
38
|
}
|
39
|
|
40
|
|
41
|
private boolean checkNamesWithJournalReferences(BerlinModelImportState state){
|
42
|
try {
|
43
|
boolean result = true;
|
44
|
Source source = state.getConfig().getSource();
|
45
|
String strQuery = " SELECT n.NameId, n.FullNameCache, n.Created_Who, cat.RefCategoryAbbrev, r.NomRefCache, r.RefCache, r.Title, r.Edition, r.Volume, r.Series, r.RefYear " +
|
46
|
" FROM RefCategory AS cat INNER JOIN Reference AS r ON cat.RefCategoryId = r.RefCategoryFk " +
|
47
|
" INNER JOIN Name AS n ON r.RefId = n.NomRefFk " +
|
48
|
" WHERE (r.RefCategoryFk = 9) ";
|
49
|
if (StringUtils.isNotBlank(state.getConfig().getNameIdTable())){
|
50
|
strQuery += String.format(" AND (n.NameId IN " +
|
51
|
" (SELECT NameId FROM %s ))" , state.getConfig().getNameIdTable()) ;
|
52
|
}
|
53
|
|
54
|
ResultSet rs = source.getResultSet(strQuery);
|
55
|
boolean firstRow = true;
|
56
|
while (rs.next()){
|
57
|
if (firstRow){
|
58
|
System.out.println("========================================================");
|
59
|
System.out.println("There are names with journals as nomencl. reference !");
|
60
|
System.out.println("========================================================");
|
61
|
}
|
62
|
int nameId = rs.getInt("nameId");
|
63
|
String cat = rs.getString("RefCategoryAbbrev");
|
64
|
String fullNameCache = rs.getString("fullNameCache");
|
65
|
String createdWho = rs.getString("Created_Who");
|
66
|
|
67
|
String nomRefCache = rs.getString("nomRefCache");
|
68
|
String refCache = rs.getString("RefCache");
|
69
|
String title = rs.getString("title");
|
70
|
String edition = rs.getString("Edition");
|
71
|
String volume = rs.getString("Volume");
|
72
|
String series = rs.getString("Series");
|
73
|
|
74
|
System.out.println("NameID:" + nameId + "\n cat: " + cat +
|
75
|
"\n fullNameCache: " + fullNameCache + "\n created_who: " + createdWho +
|
76
|
"\n nomRefCache: " + nomRefCache + "\n refCache: " + refCache + "\n title: " + title +
|
77
|
"\n edition: " + edition + "\n volume: " + volume +
|
78
|
"\n series: " + series );
|
79
|
result = firstRow = false;
|
80
|
}
|
81
|
|
82
|
return result;
|
83
|
} catch (SQLException e) {
|
84
|
e.printStackTrace();
|
85
|
return false;
|
86
|
}
|
87
|
|
88
|
}
|
89
|
|
90
|
}
|