ref #8508 adapt ERMS pipeline validator to taxon relationships
[cdmlib-apps.git] / cdm-pesi / src / main / java / eu / etaxonomy / cdm / io / pesi / erms / validation / ErmsAreaImportValidator.java
1 /**
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
10 package eu.etaxonomy.cdm.io.pesi.erms.validation;
11
12 import java.sql.ResultSet;
13 import java.sql.SQLException;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.io.common.IOValidator;
18 import eu.etaxonomy.cdm.io.common.Source;
19 import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportConfigurator;
20 import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportState;
21
22 /**
23 * @author a.mueller
24 * @since 17.02.2010
25 */
26 public class ErmsAreaImportValidator implements IOValidator<ErmsImportState>{
27 private static final Logger logger = Logger.getLogger(ErmsAreaImportValidator.class);
28
29 @Override
30 public boolean validate(ErmsImportState state){
31 boolean result = true;
32 ErmsImportConfigurator config = state.getConfig();
33 logger.info("Checking for Areas not yet implemented");
34 // result &= checkTaxonStatus(config);
35 return result;
36 }
37
38 private boolean checkTaxonStatus(ErmsImportConfigurator bmiConfig){
39 try {
40 boolean result = true;
41 Source source = bmiConfig.getSource();
42 String strSQL = " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache " +
43 " FROM RelPTaxon " +
44 " INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " +
45 " INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk " +
46 " INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " +
47 " WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) ";
48 ResultSet rs = source.getResultSet(strSQL);
49 boolean firstRow = true;
50 int i = 0;
51 while (rs.next()){
52 i++;
53 if (firstRow){
54 System.out.println("========================================================");
55 logger.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!");
56 System.out.println("========================================================");
57 }
58 int rIdentifier = rs.getInt("RIdentifier");
59 int nameFk = rs.getInt("PTNameFk");
60 int refFk = rs.getInt("PTRefFk");
61 int relPTaxonId = rs.getInt("relPTaxonId");
62 String taxonName = rs.getString("FullNameCache");
63
64 System.out.println("RIdentifier:" + rIdentifier + "\n name: " + nameFk +
65 "\n taxonName: " + taxonName + "\n refId: " + refFk + "\n RelPTaxonId: " + relPTaxonId );
66 result = firstRow = false;
67 }
68 if (i > 0){
69 System.out.println(" ");
70 }
71
72 return result;
73 } catch (SQLException e) {
74 e.printStackTrace();
75 return false;
76 }
77 }
78 }