Updates to BM import to integrate AlgaTerra
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / berlinModel / in / validation / BerlinModelFactsImportValidator.java
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.log4j.Logger;
17
18 import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
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 * @version 1.0
27 */
28 public class BerlinModelFactsImportValidator implements IOValidator<BerlinModelImportState> {
29 private static final Logger logger = Logger.getLogger(BerlinModelFactsImportValidator.class);
30
31 /* (non-Javadoc)
32 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
33 */
34 public boolean validate(BerlinModelImportState state) {
35 boolean result = true;
36 result &= checkDesignationRefsExist(state);
37 result &= checkFactsForSynonyms(state);
38 return result;
39 }
40
41
42 private boolean checkDesignationRefsExist(BerlinModelImportState state){
43 try {
44 boolean result = true;
45 Source source = state.getConfig().getSource();
46 String strQueryArticlesWithoutJournal = "SELECT Count(*) as n " +
47 " FROM Fact " +
48 " WHERE (NOT (PTDesignationRefFk IS NULL) ) OR " +
49 " (NOT (PTDesignationRefDetailFk IS NULL) )";
50 ResultSet rs = source.getResultSet(strQueryArticlesWithoutJournal);
51 rs.next();
52 int count = rs.getInt("n");
53 if (count > 0){
54 System.out.println("========================================================");
55 logger.warn("There are "+count+" Facts with not empty designation references. Designation references are not imported.");
56
57 System.out.println("========================================================");
58 }
59 return result;
60 } catch (SQLException e) {
61 e.printStackTrace();
62 return false;
63 }
64
65 }
66
67 private boolean checkFactsForSynonyms(BerlinModelImportState state){
68 try {
69 boolean result = true;
70 Source source = state.getConfig().getSource();
71 String strQueryArticlesWithoutJournal = "SELECT Count(*) as n " +
72 " FROM Fact " +
73 "INNER JOIN PTaxon ON Fact.PTNameFk = PTaxon.PTNameFk AND Fact.PTRefFk = PTaxon.PTRefFk" +
74 " WHERE PTaxon.StatusFk IN (2, 3, 4)";
75 ResultSet rs = source.getResultSet(strQueryArticlesWithoutJournal);
76 rs.next();
77 int count = rs.getInt("n");
78 if (count > 0){
79 System.out.println("========================================================");
80 logger.warn("There are "+count+" Facts with attached synonyms.");
81
82 System.out.println("========================================================");
83 }
84 return result;
85 } catch (SQLException e) {
86 e.printStackTrace();
87 return false;
88 }
89
90 }
91 }