commit 0d76bb7da68666fba6f91d0396e626c354c7b580
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Mon Sep 3 10:44:14 2018 +0200

    add tests for occurrences sources with unwanted whitespaces

diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java
index 22dd58a5..c429a908 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java
@@ -25,15 +25,15 @@ import eu.etaxonomy.cdm.io.common.Source;
  * @since 17.02.2010
  */
 public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinModelImportState> {
-	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class);
+	@SuppressWarnings("unused")
+    private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class);
 
 	@Override
 	public boolean validate(BerlinModelImportState state) {
 		boolean result = true;
-		BerlinModelImportConfigurator bmiConfig = state.getConfig();
-		result &= checkTaxonIsAccepted(bmiConfig);
-		//result &= checkPartOfJournal(bmiConfig);
-		System.out.println("Checking for Occurrence not yet fully implemented");
+		BerlinModelImportConfigurator config = state.getConfig();
+		result &= checkTaxonIsAccepted(config);
+		result &= checkSourcesWithWhitespace(config);
 		return result;
 	}
 
@@ -71,7 +71,7 @@ public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinM
 
 				}
 				int occurrenceId = resultSet.getInt("OccurrenceId");
-//					int statusFk = resulSet.getInt("StatusFk");
+//			    int statusFk = resulSet.getInt("StatusFk");
 				String status = resultSet.getString("Status");
 				String fullNameCache = resultSet.getString("FullNameCache");
 				String ptRefFk = resultSet.getString("PTRefFk");
@@ -92,4 +92,40 @@ public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinM
 		}
 	}
 
+    private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){
+        try {
+            boolean result = true;
+            Source source = config.getSource();
+            String strSelect = "SELECT OccurrenceId, PTNameFk, PTRefFk, AreaFk, Sources, Created_When, Created_Who, Updated_When, Updated_Who, Notes, Occurrence ";
+            String strCount = " count(*) ";
+            String strQueryBase =
+                    " FROM emOccurrence " +
+                    " WHERE (Sources LIKE '%  %') OR (Sources LIKE '% ') OR (Sources LIKE ' %') ";
+
+            ResultSet rs = source.getResultSet(strCount + strQueryBase);
+            rs.next();
+            int n = rs.getInt("n");
+            if (n > 0){
+                System.out.println("=======================================================================");
+                System.out.println("There are "+n+" occurrences with source attribute has unexpected whitespace!");
+                System.out.println("---------------------------------------------------------------");
+                System.out.println(strSelect + strQueryBase);
+                System.out.println("=======================================================================");
+            }
+
+            rs = source.getResultSet(strSelect + strQueryBase);
+            while (rs.next()){
+                int occurrenceId = rs.getInt("OccurrenceId");
+                String sources = rs.getString("Sources");
+
+                System.out.println("OccurrenceSourceId:" + occurrenceId +
+                        "\n  Sources: " + sources)
+                        ;
+            }
+            return result;
+        } catch (SQLException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
 }
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceSourceImportValidator.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceSourceImportValidator.java
index bbaa0174..5a45f9e4 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceSourceImportValidator.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceSourceImportValidator.java
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -26,60 +26,56 @@ import eu.etaxonomy.cdm.io.common.Source;
 public class BerlinModelOccurrenceSourceImportValidator implements IOValidator<BerlinModelImportState> {
 	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceSourceImportValidator.class);
 
-	/* (non-Javadoc)
-	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
-	 */
-	public boolean validate(BerlinModelImportState state) {
+	@Override
+    public boolean validate(BerlinModelImportState state) {
 		boolean result = true;
-		BerlinModelImportConfigurator bmiConfig = state.getConfig();
-//		result &= checkTaxonIsAccepted(bmiConfig);
-		//result &= checkPartOfJournal(bmiConfig);
-		System.out.println("Checking for OccurrenceSources not yet implemented");
+		BerlinModelImportConfigurator config = state.getConfig();
+        result &= checkSourcesWithWhitespace(config);
 		return result;
 	}
-	
-	
+
+
 	//******************************** CHECK *************************************************
-		
-		private static boolean checkTaxonIsAccepted(BerlinModelImportConfigurator bmiConfig){
-			try {
-				boolean result = true;
-				Source source = bmiConfig.getSource();
-				String strQuery = "SELECT emOccurrence.OccurrenceId, PTaxon.StatusFk, Name.FullNameCache, Status.Status, PTaxon.PTRefFk, Reference.RefCache " + 
-							" FROM emOccurrence INNER JOIN " +
-								" PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk INNER JOIN " + 
-				                " Name ON PTaxon.PTNameFk = Name.NameId INNER JOIN " +
-				                " Status ON PTaxon.StatusFk = Status.StatusId LEFT OUTER JOIN " +
-				                " Reference ON PTaxon.PTRefFk = Reference.RefId " + 
-							" WHERE (PTaxon.StatusFk <> 1)  ";
-				
-				ResultSet resulSet = source.getResultSet(strQuery);
-				boolean firstRow = true;
-				while (resulSet.next()){
-					if (firstRow){
-						System.out.println("========================================================");
-						logger.warn("There are Occurrences for a taxon that is not accepted!");
-						System.out.println("========================================================");
-					}
-					int occurrenceId = resulSet.getInt("OccurrenceId");
-					int statusFk = resulSet.getInt("StatusFk");
-					String status = resulSet.getString("Status");
-					String fullNameCache = resulSet.getString("FullNameCache");
-					String ptRefFk = resulSet.getString("PTRefFk");
-					String ptRef = resulSet.getString("RefCache");
-					
-					System.out.println("OccurrenceId:" + occurrenceId + "\n  Status: " + status + 
-							"\n  FullNameCache: " + fullNameCache +  "\n  ptRefFk: " + ptRefFk +
-							"\n  sec: " + ptRef );
-					
-					result = firstRow = false;
-				}
-				
-				return result;
-			} catch (SQLException e) {
-				e.printStackTrace();
-				return false;
-			}
-		}
+
+    private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){
+        try {
+            boolean result = true;
+            Source source = config.getSource();
+            String strSelect = " SELECT OccurrenceSourceId, OccurrenceFk, Source, SourceNumber, OldName, OldNameFk, PreferredReferenceFlag ";
+            String strCount = " count(*) ";
+            String strQueryBase =
+                    " FROM emOccurrenceSource " +
+                    " WHERE SourceNumber LIKE '% %' ";
+
+            ResultSet rs = source.getResultSet(strCount + strQueryBase);
+            rs.next();
+            int n = rs.getInt("n");
+            if (n > 0){
+                System.out.println("=======================================================================");
+                System.out.println("There are "+n+" occurrence source numbers with whitespace!");
+                System.out.println("---------------------------------------------------------------");
+                System.out.println(strSelect + strQueryBase);
+                System.out.println("=======================================================================");
+            }
+
+            rs = source.getResultSet(strSelect + strQueryBase);
+            while (rs.next()){
+                int occurrenceSourceId = rs.getInt("OccurrenceSourceId");
+                String sourceNumber = rs.getString("SourceNumber");
+                String Source = rs.getString("Source");
+
+                System.out.println("OccurrenceSourceId:" + occurrenceSourceId +
+                        "\n  Source Number: " + sourceNumber +
+                        "\n  Source: " + Source)
+                        ;
+            }
+
+            return result;
+        } catch (SQLException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
 
 }
