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
|
import java.util.HashSet;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.apache.log4j.Logger;
|
20
|
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
|
23
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelReferenceImport;
|
24
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
25
|
import eu.etaxonomy.cdm.io.common.Source;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @created 17.02.2010
|
30
|
*/
|
31
|
public class BerlinModelReferenceImportValidator implements IOValidator<BerlinModelImportState> {
|
32
|
private static final Logger logger = Logger.getLogger(BerlinModelReferenceImportValidator.class);
|
33
|
|
34
|
public boolean validate(BerlinModelImportState state, BerlinModelReferenceImport refImport){
|
35
|
boolean result = true;
|
36
|
BerlinModelImportConfigurator config = state.getConfig();
|
37
|
result &= checkArticlesWithoutJournal(config);
|
38
|
result &= checkPartOfJournal(config);
|
39
|
result &= checkPartOfUnresolved(config);
|
40
|
result &= checkPartOfPartOf(config);
|
41
|
result &= checkPartOfArticle(config);
|
42
|
result &= checkJournalsWithSeries(config);
|
43
|
result &= checkObligatoryAttributes(config, refImport);
|
44
|
result &= checkPartOfWithVolume(config);
|
45
|
result &= checkArticleWithEdition(config);
|
46
|
|
47
|
if (result == false ){System.out.println("========================================================");}
|
48
|
|
49
|
return result;
|
50
|
|
51
|
}
|
52
|
|
53
|
|
54
|
//******************************** CHECK *************************************************
|
55
|
|
56
|
private static boolean checkArticlesWithoutJournal(BerlinModelImportConfigurator config){
|
57
|
try {
|
58
|
boolean result = true;
|
59
|
Source source = config.getSource();
|
60
|
String strQuery = "SELECT Reference.RefId, InRef.RefId AS InRefID, Reference.RefCategoryFk, InRef.RefCategoryFk AS InRefCatFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, RefCategory.RefCategoryAbbrev, InRefCategory.RefCategoryAbbrev AS InRefCat, InRef.Title AS InRefTitle " +
|
61
|
" FROM Reference INNER JOIN Reference AS InRef ON Reference.InRefFk = InRef.RefId INNER JOIN RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId INNER JOIN RefCategory AS InRefCategory ON InRef.RefCategoryFk = InRefCategory.RefCategoryId " +
|
62
|
" WHERE (Reference.RefCategoryFk = 1) AND (InRef.RefCategoryFk <> 9) ";
|
63
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
64
|
strQuery += String.format(" AND (reference.refId IN " +
|
65
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
66
|
}
|
67
|
|
68
|
ResultSet rs = source.getResultSet(strQuery);
|
69
|
boolean firstRow = true;
|
70
|
while (rs.next()){
|
71
|
if (firstRow){
|
72
|
System.out.println("========================================================");
|
73
|
System.out.println("There are Articles with wrong inRef type!");
|
74
|
System.out.println("========================================================");
|
75
|
}
|
76
|
int refId = rs.getInt("RefId");
|
77
|
//int categoryFk = resulSetarticlesWithoutJournal.getInt("RefCategoryFk");
|
78
|
String cat = rs.getString("RefCategoryAbbrev");
|
79
|
int inRefFk = rs.getInt("InRefId");
|
80
|
//int inRefCategoryFk = resulSetarticlesWithoutJournal.getInt("InRefCatFk");
|
81
|
String inRefCat = rs.getString("InRefCat");
|
82
|
String refCache = rs.getString("RefCache");
|
83
|
String nomRefCache = rs.getString("nomRefCache");
|
84
|
String title = rs.getString("title");
|
85
|
String inRefTitle = rs.getString("InRefTitle");
|
86
|
|
87
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
88
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache + "\n title: " + title +
|
89
|
"\n inRefFk: " + inRefFk + "\n inRefCategory: " + inRefCat +
|
90
|
"\n inRefTitle: " + inRefTitle );
|
91
|
result = firstRow = false;
|
92
|
}
|
93
|
|
94
|
return result;
|
95
|
} catch (SQLException e) {
|
96
|
e.printStackTrace();
|
97
|
return false;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
private static boolean checkPartOfJournal(BerlinModelImportConfigurator config){
|
102
|
try {
|
103
|
boolean result = true;
|
104
|
Source source = config.getSource();
|
105
|
String strQuery = "SELECT Reference.RefId, InRef.RefId AS InRefID, Reference.RefCategoryFk, InRef.RefCategoryFk AS InRefCatFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, RefCategory.RefCategoryAbbrev, InRefCategory.RefCategoryAbbrev AS InRefCat, InRef.Title AS InRefTitle " +
|
106
|
" FROM Reference INNER JOIN Reference AS InRef ON Reference.InRefFk = InRef.RefId INNER JOIN RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId INNER JOIN RefCategory AS InRefCategory ON InRef.RefCategoryFk = InRefCategory.RefCategoryId " +
|
107
|
" WHERE (Reference.RefCategoryFk = 2) AND (InRef.RefCategoryFk = 9) ";
|
108
|
|
109
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
110
|
strQuery += String.format(" AND (reference.refId IN " +
|
111
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
112
|
}
|
113
|
|
114
|
|
115
|
ResultSet rs = source.getResultSet(strQuery);
|
116
|
boolean firstRow = true;
|
117
|
while (rs.next()){
|
118
|
if (firstRow){
|
119
|
System.out.println("========================================================");
|
120
|
System.out.println("There are part-of-references that have a Journal as in-reference!");
|
121
|
System.out.println("========================================================");
|
122
|
}
|
123
|
int refId = rs.getInt("RefId");
|
124
|
//int categoryFk = rs.getInt("RefCategoryFk");
|
125
|
String cat = rs.getString("RefCategoryAbbrev");
|
126
|
int inRefFk = rs.getInt("InRefId");
|
127
|
//int inRefCategoryFk = rs.getInt("InRefCatFk");
|
128
|
String inRefCat = rs.getString("InRefCat");
|
129
|
String refCache = rs.getString("RefCache");
|
130
|
String nomRefCache = rs.getString("nomRefCache");
|
131
|
String title = rs.getString("title");
|
132
|
String inRefTitle = rs.getString("InRefTitle");
|
133
|
|
134
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
135
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache + "\n title: " + title +
|
136
|
"\n inRefFk: " + inRefFk + "\n inRefCategory: " + inRefCat +
|
137
|
"\n inRefTitle: " + inRefTitle );
|
138
|
result = firstRow = false;
|
139
|
}
|
140
|
|
141
|
return result;
|
142
|
} catch (SQLException e) {
|
143
|
e.printStackTrace();
|
144
|
return false;
|
145
|
}
|
146
|
}
|
147
|
|
148
|
|
149
|
private static boolean checkPartOfUnresolved(BerlinModelImportConfigurator config){
|
150
|
try {
|
151
|
boolean result = true;
|
152
|
Source source = config.getSource();
|
153
|
String strQuery = "SELECT Reference.RefId, InRef.RefId AS InRefID, Reference.RefCategoryFk, InRef.RefCategoryFk AS InRefCatFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, RefCategory.RefCategoryAbbrev, InRefCategory.RefCategoryAbbrev AS InRefCat, InRef.Title AS InRefTitle " +
|
154
|
" FROM Reference INNER JOIN Reference AS InRef ON Reference.InRefFk = InRef.RefId INNER JOIN RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId INNER JOIN RefCategory AS InRefCategory ON InRef.RefCategoryFk = InRefCategory.RefCategoryId " +
|
155
|
" WHERE (Reference.RefCategoryFk = 2) AND (InRef.RefCategoryFk = 10) ";
|
156
|
|
157
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
158
|
strQuery += String.format(" AND (reference.refId IN " +
|
159
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
160
|
}
|
161
|
|
162
|
ResultSet rs = source.getResultSet(strQuery);
|
163
|
boolean firstRow = true;
|
164
|
while (rs.next()){
|
165
|
if (firstRow){
|
166
|
System.out.println("========================================================");
|
167
|
System.out.println("There are part-of-references that have an 'unresolved' in-reference!");
|
168
|
System.out.println("========================================================");
|
169
|
}
|
170
|
int refId = rs.getInt("RefId");
|
171
|
//int categoryFk = rs.getInt("RefCategoryFk");
|
172
|
String cat = rs.getString("RefCategoryAbbrev");
|
173
|
int inRefFk = rs.getInt("InRefId");
|
174
|
//int inRefCategoryFk = rs.getInt("InRefCatFk");
|
175
|
String inRefCat = rs.getString("InRefCat");
|
176
|
String refCache = rs.getString("RefCache");
|
177
|
String nomRefCache = rs.getString("nomRefCache");
|
178
|
String title = rs.getString("title");
|
179
|
String inRefTitle = rs.getString("InRefTitle");
|
180
|
|
181
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
182
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache + "\n title: " + title +
|
183
|
"\n inRefFk: " + inRefFk + "\n inRefCategory: " + inRefCat +
|
184
|
"\n inRefTitle: " + inRefTitle );
|
185
|
result = firstRow = false;
|
186
|
}
|
187
|
if (result == false){
|
188
|
System.out.println("\nChoose a specific type from the following reference types: \n" +
|
189
|
" 1) Article \n 2) Book \n 3) BookSection \n 4) CdDvd \n 5) ConferenceProceeding \n 6) Database\n" +
|
190
|
" 7) Generic \n 7) InProceedings \n 8) Journal \n 9) Map \n 10) Patent \n 11) PersonalCommunication\n" +
|
191
|
" 12) PrintSeries \n 13) Proceedings \n 14) Report \n 15) Thesis \n 16) WebPage");
|
192
|
}
|
193
|
return result;
|
194
|
} catch (SQLException e) {
|
195
|
e.printStackTrace();
|
196
|
return false;
|
197
|
}
|
198
|
}
|
199
|
|
200
|
private static boolean checkPartOfPartOf(BerlinModelImportConfigurator config){
|
201
|
try {
|
202
|
boolean result = true;
|
203
|
Source source = config.getSource();
|
204
|
String strQuery = "SELECT Reference.RefId, InRef.RefId AS InRefID, Reference.RefCategoryFk, InRef.RefCategoryFk AS InRefCatFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, RefCategory.RefCategoryAbbrev, InRefCategory.RefCategoryAbbrev AS InRefCat, InRef.Title AS InRefTitle, InRef.InRefFk as InInRefId, InInRef.Title as inInRefTitle, InInRef.RefCategoryFk as inInRefCategory " +
|
205
|
" FROM Reference " +
|
206
|
" INNER JOIN Reference AS InRef ON Reference.InRefFk = InRef.RefId " +
|
207
|
" INNER JOIN RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId " +
|
208
|
" INNER JOIN RefCategory AS InRefCategory ON InRef.RefCategoryFk = InRefCategory.RefCategoryId " +
|
209
|
" INNER JOIN Reference AS InInRef ON InRef.InRefFk = InInRef.RefId " +
|
210
|
" WHERE (Reference.RefCategoryFk = 2) AND (InRef.RefCategoryFk = 2) ";
|
211
|
|
212
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
213
|
strQuery += String.format(" AND (reference.refId IN " +
|
214
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
215
|
}
|
216
|
|
217
|
ResultSet rs = source.getResultSet(strQuery);
|
218
|
boolean firstRow = true;
|
219
|
while (rs.next()){
|
220
|
if (firstRow){
|
221
|
System.out.println("========================================================");
|
222
|
System.out.println("There are part-of-references that are part of an other 'part-of' reference!\n" +
|
223
|
" This is invalid or ambigous. Please try to determine the reference types more detailed ");
|
224
|
System.out.println("========================================================");
|
225
|
}
|
226
|
int refId = rs.getInt("RefId");
|
227
|
//int categoryFk = rs.getInt("RefCategoryFk");
|
228
|
String cat = rs.getString("RefCategoryAbbrev");
|
229
|
int inRefFk = rs.getInt("InRefId");
|
230
|
//int inRefCategoryFk = rs.getInt("InRefCatFk");
|
231
|
String inRefCat = rs.getString("InRefCat");
|
232
|
String refCache = rs.getString("RefCache");
|
233
|
String nomRefCache = rs.getString("nomRefCache");
|
234
|
String title = rs.getString("title");
|
235
|
String inRefTitle = rs.getString("InRefTitle");
|
236
|
int inInRefId = rs.getInt("InInRefId");
|
237
|
String inInRefTitle = rs.getString("inInRefTitle");
|
238
|
int inInRefCategory = rs.getInt("inInRefCategory");
|
239
|
|
240
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
241
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache + "\n title: " + title +
|
242
|
"\n inRefFk: " + inRefFk + "\n inRefCategory: " + inRefCat +
|
243
|
"\n inRefTitle: " + inRefTitle + "\n inInRefId: " + inInRefId + "\n inInRefTitle: " + inInRefTitle +
|
244
|
"\n inInRefCategory: " + inInRefCategory );
|
245
|
result = firstRow = false;
|
246
|
}
|
247
|
if (result == false){
|
248
|
System.out.println("\nChoose a specific type from the following reference types: \n" +
|
249
|
" 1) BookSection - Book - PrintSeries \n" +
|
250
|
" 2) InProceedings - pProceedings - PrintSeries");
|
251
|
}
|
252
|
return result;
|
253
|
} catch (SQLException e) {
|
254
|
e.printStackTrace();
|
255
|
return false;
|
256
|
}
|
257
|
}
|
258
|
|
259
|
|
260
|
private static boolean checkPartOfArticle(BerlinModelImportConfigurator config){
|
261
|
try {
|
262
|
boolean result = true;
|
263
|
Source source = config.getSource();
|
264
|
String strQuery = "SELECT Reference.RefId, InRef.RefId AS InRefID, Reference.RefCategoryFk, InRef.RefCategoryFk AS InRefCatFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, Reference.NomTitleAbbrev as nomTitleAbbrev, RefCategory.RefCategoryAbbrev, InRefCategory.RefCategoryAbbrev AS InRefCat, InRef.Title AS InRefTitle, InRef.nomTitleAbbrev AS inRefnomTitleAbbrev, InRef.refCache AS inRefCache, InRef.nomRefCache AS inRefnomRefCache, " +
|
265
|
" InInRefCategory.RefCategoryAbbrev AS InInRefCat, InInRef.refCache AS inInRefCache, InInRef.nomRefCache AS inInRefNomRefCache " +
|
266
|
" FROM Reference " +
|
267
|
" INNER JOIN Reference AS InRef ON Reference.InRefFk = InRef.RefId " +
|
268
|
" INNER JOIN Reference AS InInRef ON InRef.InRefFk = InInRef.RefId " +
|
269
|
" INNER JOIN RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId " +
|
270
|
" INNER JOIN RefCategory AS InRefCategory ON InRef.RefCategoryFk = InRefCategory.RefCategoryId " +
|
271
|
" INNER JOIN RefCategory AS InInRefCategory ON InInRef.RefCategoryFk = InInRefCategory.RefCategoryId " +
|
272
|
" WHERE (Reference.RefCategoryFk = 2) AND (InRef.RefCategoryFk = 1) ";
|
273
|
|
274
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
275
|
strQuery += String.format(" AND (reference.refId IN " +
|
276
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
277
|
}
|
278
|
ResultSet rs = source.getResultSet(strQuery);
|
279
|
boolean firstRow = true;
|
280
|
while (rs.next()){
|
281
|
if (firstRow){
|
282
|
System.out.println("========================================================");
|
283
|
System.out.println("There are part-of-references that have an article as in-reference! " +
|
284
|
" This is not necessarily wrong if the article is part of journal.");
|
285
|
System.out.println("========================================================");
|
286
|
}
|
287
|
int refId = rs.getInt("RefId");
|
288
|
//int categoryFk = rs.getInt("RefCategoryFk");
|
289
|
String cat = rs.getString("RefCategoryAbbrev");
|
290
|
int inRefFk = rs.getInt("InRefId");
|
291
|
//int inRefCategoryFk = rs.getInt("InRefCatFk");
|
292
|
String inRefCat = rs.getString("InRefCat");
|
293
|
String refCache = rs.getString("RefCache");
|
294
|
String nomRefCache = rs.getString("nomRefCache");
|
295
|
String title = rs.getString("title");
|
296
|
String nomTitleAbbrev = rs.getString("nomTitleAbbrev");
|
297
|
String inRefTitle = rs.getString("InRefTitle");
|
298
|
String inRefnomTitleAbbrev = rs.getString("inRefnomTitleAbbrev");
|
299
|
String inRefnomRefCache = rs.getString("inRefnomRefCache");
|
300
|
String inRefCache = rs.getString("inRefCache");
|
301
|
String inInRefCat = rs.getString("inInRefCat");
|
302
|
String inInRefCache = rs.getString("inInRefCache");
|
303
|
String inInRefNomRefCache = rs.getString("inInRefNomRefCache");
|
304
|
|
305
|
|
306
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
307
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache + "\n title: " + title + "\n titleAbbrev: " + nomTitleAbbrev +
|
308
|
"\n inRefFk: " + inRefFk + "\n inRefCategory: " + inRefCat +
|
309
|
"\n inRefTitle: " + inRefTitle + "\n inRefTitleAbbrev: " + inRefnomTitleAbbrev +
|
310
|
"\n inRefnomRefCache: " + inRefnomRefCache + "\n inRefCache: " + inRefCache +
|
311
|
"\n inInRefCat: " + inInRefCat + "\n inInRefCache: " + inInRefCache +
|
312
|
"\n inInRefNomRefCache: " + inInRefNomRefCache
|
313
|
|
314
|
);
|
315
|
result = firstRow = false;
|
316
|
}
|
317
|
|
318
|
return result;
|
319
|
} catch (SQLException e) {
|
320
|
e.printStackTrace();
|
321
|
return false;
|
322
|
}
|
323
|
}
|
324
|
|
325
|
private static boolean checkJournalsWithSeries(BerlinModelImportConfigurator config){
|
326
|
try {
|
327
|
boolean result = true;
|
328
|
Source source = config.getSource();
|
329
|
String strQuery = "SELECT Reference.RefId, Reference.RefCategoryFk, Reference.RefCache, Reference.NomRefCache, Reference.Title, Reference.NomTitleAbbrev, Reference.Series, RefCategory.RefCategoryAbbrev " +
|
330
|
" FROM Reference INNER JOIN " +
|
331
|
" RefCategory ON Reference.RefCategoryFk = RefCategory.RefCategoryId " +
|
332
|
" WHERE (Reference.RefCategoryFk = 9) AND ( Reference.series is not null AND Reference.series <>'') ";
|
333
|
|
334
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
335
|
strQuery += String.format(" AND (reference.refId IN " +
|
336
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
337
|
}
|
338
|
|
339
|
ResultSet rs = source.getResultSet(strQuery);
|
340
|
boolean firstRow = true;
|
341
|
while (rs.next()){
|
342
|
if (firstRow){
|
343
|
System.out.println("========================================================");
|
344
|
System.out.println("There are Journals with series! Series should be part of the according articles.");
|
345
|
System.out.println("========================================================");
|
346
|
}
|
347
|
int refId = rs.getInt("RefId");
|
348
|
//int categoryFk = rs.getInt("RefCategoryFk");
|
349
|
String cat = rs.getString("RefCategoryAbbrev");
|
350
|
String nomRefCache = rs.getString("nomRefCache");
|
351
|
String refCache = rs.getString("refCache");
|
352
|
String title = rs.getString("title");
|
353
|
String nomTitleAbbrev = rs.getString("nomTitleAbbrev");
|
354
|
String series = rs.getString("series");
|
355
|
|
356
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
357
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache +
|
358
|
"\n title: " + title + "\n nomTitleAbbrev: " + nomTitleAbbrev +
|
359
|
"\n series: " + series );
|
360
|
result = firstRow = false;
|
361
|
}
|
362
|
|
363
|
return result;
|
364
|
} catch (SQLException e) {
|
365
|
e.printStackTrace();
|
366
|
return false;
|
367
|
}
|
368
|
}
|
369
|
|
370
|
private static boolean checkPartOfWithVolume(BerlinModelImportConfigurator config){
|
371
|
try {
|
372
|
boolean result = true;
|
373
|
Source source = config.getSource();
|
374
|
String strQuery = "SELECT Ref.RefId as refId, RefCategory.RefCategoryAbbrev as refCategoryAbbrev, Ref.nomRefCache as nomRefCache, Ref.refCache as refCache,Ref.volume as volume, Ref.Series as series, Ref.Edition as edition, Ref.title as title, Ref.nomTitleAbbrev as nomTitleAbbrev,InRef.RefCache as inRefRefCache, InRef.NomRefCache as inRefNomRefCache, InRef.RefId as inRefId, InRef.Volume as inRefVol, InRef.Series as inRefSeries, InRef.Edition as inRefEdition" +
|
375
|
" FROM Reference AS Ref " +
|
376
|
" INNER JOIN RefCategory ON Ref.RefCategoryFk = RefCategory.RefCategoryId " +
|
377
|
" LEFT OUTER JOIN Reference AS InRef ON Ref.InRefFk = InRef.RefId " +
|
378
|
" WHERE (Ref.RefCategoryFk = 2) AND ((Ref.Volume IS NOT NULL) OR (Ref.Series IS NOT NULL) OR (Ref.Edition IS NOT NULL)) " ;
|
379
|
|
380
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
381
|
strQuery += String.format(" AND (Ref.refId IN " +
|
382
|
" (SELECT refId FROM %s ))" , config.getReferenceIdTable()) ;
|
383
|
}
|
384
|
|
385
|
ResultSet rs = source.getResultSet(strQuery);
|
386
|
boolean firstRow = true;
|
387
|
while (rs.next()){
|
388
|
if (firstRow){
|
389
|
System.out.println("========================================================");
|
390
|
System.out.println("There are PartOfOtherTitles with volumes, editions or series !");
|
391
|
System.out.println("========================================================");
|
392
|
}
|
393
|
int refId = rs.getInt("refId");
|
394
|
String cat = rs.getString("refCategoryAbbrev");
|
395
|
String nomRefCache = rs.getString("nomRefCache");
|
396
|
String refCache = rs.getString("refCache");
|
397
|
String title = rs.getString("title");
|
398
|
String nomTitleAbbrev = rs.getString("nomTitleAbbrev");
|
399
|
String volume = rs.getString("volume");
|
400
|
String edition = rs.getString("edition");
|
401
|
String series = rs.getString("series");
|
402
|
String inRefRefCache = rs.getString("inRefRefCache");
|
403
|
String inRefNomRefCache = rs.getString("inRefNomRefCache");
|
404
|
int inRefId = rs.getInt("inRefId");
|
405
|
String inRefVolume = rs.getString("inRefVol");
|
406
|
String inRefSeries = rs.getString("inRefSeries");
|
407
|
String inRefEdition = rs.getString("inRefEdition");
|
408
|
|
409
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
410
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache +
|
411
|
"\n title: " + title + "\n nomTitleAbbrev: " + nomTitleAbbrev + "\n volume: " + volume + "\n series: " + series +"\n edition: " + edition +
|
412
|
"\n inRef-ID:" + inRefId + "\n inRef-cache: " + inRefRefCache +
|
413
|
"\n inRef-nomCache: " + inRefNomRefCache + "\n inRef-volume: " + inRefVolume +"\n inRef-series: " + inRefSeries +"\n inRef-edition: " + inRefEdition +
|
414
|
"" );
|
415
|
result = firstRow = false;
|
416
|
}
|
417
|
|
418
|
return result;
|
419
|
} catch (SQLException e) {
|
420
|
e.printStackTrace();
|
421
|
return false;
|
422
|
}
|
423
|
}
|
424
|
|
425
|
private static boolean checkArticleWithEdition(BerlinModelImportConfigurator config){
|
426
|
try {
|
427
|
boolean result = true;
|
428
|
Source source = config.getSource();
|
429
|
String strQuery = "SELECT Ref.RefId as refId, RefCategory.RefCategoryAbbrev as refCategoryAbbrev, Ref.nomRefCache as nomRefCache, Ref.refCache as refCache,Ref.edition as edition, Ref.title as title, Ref.nomTitleAbbrev as nomTitleAbbrev,InRef.RefCache as inRefRefCache, InRef.NomRefCache as inRefNomRefCache, InRef.RefId as inRefId, InRef.Edition as inRefEdition" +
|
430
|
" FROM Reference AS Ref " +
|
431
|
" INNER JOIN RefCategory ON Ref.RefCategoryFk = RefCategory.RefCategoryId " +
|
432
|
" LEFT OUTER JOIN Reference AS InRef ON Ref.InRefFk = InRef.RefId " +
|
433
|
" WHERE (Ref.RefCategoryFk = 1) AND (NOT (Ref.Edition IS NULL)) ";
|
434
|
|
435
|
if (StringUtils.isNotBlank(config.getReferenceIdTable())){
|
436
|
strQuery += String.format(" AND (Ref.refId IN " +
|
437
|
" (SELECT refId FROM %s )) " , config.getReferenceIdTable()) ;
|
438
|
}
|
439
|
strQuery += " ORDER BY InRef.RefId ";
|
440
|
|
441
|
|
442
|
ResultSet rs = source.getResultSet(strQuery);
|
443
|
boolean firstRow = true;
|
444
|
while (rs.next()){
|
445
|
if (firstRow){
|
446
|
System.out.println("========================================================");
|
447
|
System.out.println("There are Articles with editions !");
|
448
|
System.out.println("========================================================");
|
449
|
}
|
450
|
int refId = rs.getInt("refId");
|
451
|
String cat = rs.getString("refCategoryAbbrev");
|
452
|
String nomRefCache = rs.getString("nomRefCache");
|
453
|
String refCache = rs.getString("refCache");
|
454
|
String title = rs.getString("title");
|
455
|
String nomTitleAbbrev = rs.getString("nomTitleAbbrev");
|
456
|
String edition = rs.getString("edition");
|
457
|
String inRefRefCache = rs.getString("inRefRefCache");
|
458
|
String inRefNomRefCache = rs.getString("inRefNomRefCache");
|
459
|
int inRefId = rs.getInt("inRefId");
|
460
|
String inRefEdition = rs.getString("inRefEdition");
|
461
|
|
462
|
System.out.println("RefID:" + refId + "\n cat: " + cat +
|
463
|
"\n refCache: " + refCache + "\n nomRefCache: " + nomRefCache +
|
464
|
"\n title: " + title + "\n nomTitleAbbrev: " + nomTitleAbbrev + "\n edition: " + edition +
|
465
|
"\n inRef-ID:" + inRefId + "\n inRef-cache: " + inRefRefCache +
|
466
|
"\n inRef-nomCache: " + inRefNomRefCache + "\n inRef-edition: " + inRefEdition +
|
467
|
"" );
|
468
|
result = firstRow = false;
|
469
|
}
|
470
|
|
471
|
return result;
|
472
|
} catch (SQLException e) {
|
473
|
e.printStackTrace();
|
474
|
return false;
|
475
|
}
|
476
|
}
|
477
|
|
478
|
protected boolean checkObligatoryAttributes(BerlinModelImportConfigurator config, BerlinModelReferenceImport refImport){
|
479
|
boolean result = true;
|
480
|
|
481
|
try {
|
482
|
String strQuery = " SELECT Reference.* " +
|
483
|
" FROM Reference " +
|
484
|
// " INNER JOIN Reference ON Reference.RefId = RefDetail.RefFk " +
|
485
|
" WHERE (1=0) ";
|
486
|
Source source = config.getSource();
|
487
|
ResultSet rs = source.getResultSet(strQuery);
|
488
|
int colCount = rs.getMetaData().getColumnCount();
|
489
|
Set<String> existingAttributes = new HashSet<String>();
|
490
|
for (int c = 0; c < colCount ; c++){
|
491
|
existingAttributes.add(rs.getMetaData().getColumnLabel(c+1).toLowerCase());
|
492
|
}
|
493
|
Set<String> obligatoryAttributes = refImport.getObligatoryAttributes(true, config);
|
494
|
|
495
|
obligatoryAttributes.removeAll(existingAttributes);
|
496
|
for (String attr : obligatoryAttributes){
|
497
|
System.out.println("Missing attribute: " + attr);
|
498
|
}
|
499
|
|
500
|
//additional Attributes
|
501
|
obligatoryAttributes = refImport.getObligatoryAttributes(true, config);
|
502
|
|
503
|
existingAttributes.removeAll(obligatoryAttributes);
|
504
|
for (String attr : existingAttributes){
|
505
|
System.out.println("Additional attribute: " + attr);
|
506
|
}
|
507
|
} catch (SQLException e) {
|
508
|
logger.error(e);
|
509
|
e.printStackTrace();
|
510
|
result = false;
|
511
|
}
|
512
|
return result;
|
513
|
}
|
514
|
|
515
|
protected boolean checkRefDetailUnimplementedAttributes(BerlinModelImportConfigurator config){
|
516
|
boolean result = true;
|
517
|
|
518
|
try {
|
519
|
String strQuery = " SELECT Count(*) as n" +
|
520
|
" FROM RefDetail " +
|
521
|
// " INNER JOIN Reference ON Reference.RefId = RefDetail.RefFk " +
|
522
|
" WHERE SecondarySources is not NULL AND SecondarySources <> '' ";
|
523
|
Source source = config.getSource();
|
524
|
ResultSet rs = source.getResultSet(strQuery);
|
525
|
|
526
|
rs.next();
|
527
|
int count = rs.getInt("n");
|
528
|
if (count > 0){
|
529
|
System.out.println("========================================================");
|
530
|
System.out.println("There are "+ count + " RefDetails with SecondarySources <> NULL ! Secondary sources are not yet implemented for Berlin Model Import");
|
531
|
System.out.println("========================================================");
|
532
|
|
533
|
}
|
534
|
strQuery = " SELECT Count(*) as n" +
|
535
|
" FROM RefDetail " +
|
536
|
// " INNER JOIN Reference ON Reference.RefId = RefDetail.RefFk " +
|
537
|
" WHERE IdInSource is not NULL AND IdInSource <> '' ";
|
538
|
rs = source.getResultSet(strQuery);
|
539
|
|
540
|
rs.next();
|
541
|
count = rs.getInt("n");
|
542
|
if (count > 0){
|
543
|
System.out.println("========================================================");
|
544
|
System.out.println("There are "+ count + " RefDetails with IdInSource <> NULL ! IdInSource are not yet implemented for Berlin Model Import");
|
545
|
System.out.println("========================================================");
|
546
|
|
547
|
}
|
548
|
|
549
|
} catch (SQLException e) {
|
550
|
logger.error(e);
|
551
|
e.printStackTrace();
|
552
|
result = false;
|
553
|
}
|
554
|
return result;
|
555
|
}
|
556
|
|
557
|
|
558
|
/* (non-Javadoc)
|
559
|
* @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
|
560
|
*/
|
561
|
@Deprecated //use validate(state, import) instead
|
562
|
public boolean validate(BerlinModelImportState state) {
|
563
|
logger.warn("BerlinModelReferenceImport uses wrong validation method");
|
564
|
return false;
|
565
|
}
|
566
|
|
567
|
|
568
|
|
569
|
}
|