3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.validation
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
16 import org
.apache
.commons
.lang
.StringUtils
;
17 import org
.apache
.log4j
.Logger
;
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
.Source
;
29 public class BerlinModelOccurrenceImportValidator
implements IOValidator
<BerlinModelImportState
> {
30 private static final Logger logger
= Logger
.getLogger(BerlinModelOccurrenceImportValidator
.class);
33 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
35 public boolean validate(BerlinModelImportState state
) {
36 boolean result
= true;
37 BerlinModelImportConfigurator bmiConfig
= state
.getConfig();
38 result
&= checkTaxonIsAccepted(bmiConfig
);
39 //result &= checkPartOfJournal(bmiConfig);
40 System
.out
.println("Checking for Occurrence not yet fully implemented");
45 //******************************** CHECK *************************************************
47 private static boolean checkTaxonIsAccepted(BerlinModelImportConfigurator config
){
49 boolean result
= true;
50 Source source
= config
.getSource();
51 String strQuery
= "SELECT emOccurrence.OccurrenceId, PTaxon.StatusFk, Name.FullNameCache, Status.Status, PTaxon.PTRefFk, Reference.RefCache " +
52 " FROM emOccurrence INNER JOIN " +
53 " PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk INNER JOIN " +
54 " Name ON PTaxon.PTNameFk = Name.NameId INNER JOIN " +
55 " Status ON PTaxon.StatusFk = Status.StatusId LEFT OUTER JOIN " +
56 " Reference ON PTaxon.PTRefFk = Reference.RefId " +
57 " WHERE (PTaxon.StatusFk NOT IN ( 1, 5)) ";
59 if (StringUtils
.isNotBlank(config
.getOccurrenceFilter())){
60 strQuery
+= String
.format(" AND (%s) ", config
.getOccurrenceFilter()) ;
64 ResultSet resulSet
= source
.getResultSet(strQuery
);
65 boolean firstRow
= true;
66 while (resulSet
.next()){
68 System
.out
.println("========================================================");
69 System
.out
.println("There are Occurrences for a taxon that is not accepted!");
70 System
.out
.println("========================================================");
72 int occurrenceId
= resulSet
.getInt("OccurrenceId");
73 // int statusFk = resulSet.getInt("StatusFk");
74 String status
= resulSet
.getString("Status");
75 String fullNameCache
= resulSet
.getString("FullNameCache");
76 String ptRefFk
= resulSet
.getString("PTRefFk");
77 String ptRef
= resulSet
.getString("RefCache");
79 System
.out
.println("OccurrenceId:" + occurrenceId
+ "\n Status: " + status
+
80 "\n FullNameCache: " + fullNameCache
+ "\n ptRefFk: " + ptRefFk
+
83 result
= firstRow
= false;
87 } catch (SQLException e
) {