1 |
5dd8e8b0
|
Andreas Müller
|
/**
|
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 |
|
|
package eu.etaxonomy.cdm.io.berlinModel.in.validation;
|
10 |
|
|
|
11 |
|
|
import java.sql.ResultSet;
|
12 |
|
|
import java.sql.SQLException;
|
13 |
|
|
import java.util.Map;
|
14 |
|
|
|
15 |
|
|
import org.apache.log4j.Logger;
|
16 |
|
|
import org.springframework.stereotype.Component;
|
17 |
|
|
|
18 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase;
|
19 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
20 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
|
21 |
|
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
22 |
|
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
23 |
|
|
import eu.etaxonomy.cdm.io.common.Source;
|
24 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* For validating general consistencies like existence of tables, etc.
|
29 |
|
|
* @author a.mueller
|
30 |
a13538c8
|
Andreas Müller
|
* @since 10.06.2009
|
31 |
5dd8e8b0
|
Andreas Müller
|
*/
|
32 |
|
|
@Component
|
33 |
|
|
public class BerlinModelGeneralImportValidator extends BerlinModelImportBase implements IOValidator<BerlinModelImportState> {
|
34 |
|
|
private static final Logger logger = Logger.getLogger(BerlinModelGeneralImportValidator.class);
|
35 |
|
|
|
36 |
|
|
public BerlinModelGeneralImportValidator(){
|
37 |
|
|
super(null, null);
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
@Override
|
41 |
|
|
protected boolean doCheck(BerlinModelImportState state){
|
42 |
|
|
return validate(state);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
@Override
|
47 |
|
|
public boolean validate(BerlinModelImportState state) {
|
48 |
|
|
boolean result = true;
|
49 |
|
|
BerlinModelImportConfigurator bmiConfig = state.getConfig();
|
50 |
|
|
result &= checkRelAuthorsExist(bmiConfig);
|
51 |
|
|
result &= checkRelReferenceExist(bmiConfig);
|
52 |
|
|
|
53 |
|
|
return result;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
protected void doInvoke(BerlinModelImportState state){
|
57 |
|
|
//do nothing
|
58 |
|
|
return;
|
59 |
|
|
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
private boolean checkRelAuthorsExist(BerlinModelImportConfigurator config){
|
63 |
|
|
|
64 |
|
|
try {
|
65 |
|
|
boolean result = true;
|
66 |
|
|
Source source = config.getSource();
|
67 |
|
|
String strQuery = "SELECT Count(*) as n " +
|
68 |
|
|
" FROM RelAuthor "
|
69 |
|
|
;
|
70 |
|
|
ResultSet rs = source.getResultSet(strQuery);
|
71 |
|
|
rs.next();
|
72 |
|
|
int count = rs.getInt("n");
|
73 |
|
|
if (count > 0){
|
74 |
|
|
System.out.println("========================================================");
|
75 |
|
|
logger.warn("There are "+count+" RelAuthors, but RelAuthors are not implemented for CDM yet.");
|
76 |
|
|
System.out.println("========================================================");
|
77 |
|
|
}
|
78 |
|
|
return result;
|
79 |
|
|
} catch (SQLException e) {
|
80 |
|
|
e.printStackTrace();
|
81 |
|
|
return false;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
private boolean checkRelReferenceExist(BerlinModelImportConfigurator config){
|
87 |
|
|
|
88 |
|
|
try {
|
89 |
|
|
boolean result = true;
|
90 |
|
|
Source source = config.getSource();
|
91 |
|
|
String strQuery = "SELECT Count(*) as n " +
|
92 |
|
|
" FROM RelReference "
|
93 |
|
|
;
|
94 |
|
|
ResultSet rs = source.getResultSet(strQuery);
|
95 |
|
|
rs.next();
|
96 |
|
|
int count = rs.getInt("n");
|
97 |
|
|
if (count > 0){
|
98 |
|
|
System.out.println("========================================================");
|
99 |
|
|
logger.warn("There are "+count+" RelReferences, but RelReferences are not implemented for CDM yet.");
|
100 |
|
|
System.out.println("========================================================");
|
101 |
|
|
}
|
102 |
|
|
return result;
|
103 |
|
|
} catch (SQLException e) {
|
104 |
|
|
e.printStackTrace();
|
105 |
|
|
return false;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
|
111 |
7c778a7e
|
Andreas Müller
|
@Override
|
112 |
5dd8e8b0
|
Andreas Müller
|
protected boolean isIgnore(BerlinModelImportState state){
|
113 |
|
|
return false;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
@Override
|
117 |
|
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
118 |
|
|
// TODO Auto-generated method stub
|
119 |
|
|
return null;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
7c778a7e
|
Andreas Müller
|
@Override
|
123 |
5dd8e8b0
|
Andreas Müller
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
124 |
|
|
return true; // not needed
|
125 |
|
|
}
|
126 |
|
|
|
127 |
7c778a7e
|
Andreas Müller
|
|
128 |
|
|
@Override
|
129 |
|
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
130 |
5dd8e8b0
|
Andreas Müller
|
return null; // not needed
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
}
|