Project

General

Profile

Download (3.23 KB) Statistics
| Branch: | Revision:
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.berlinModel.in.validation;
11

    
12
import java.sql.ResultSet;
13
import java.sql.SQLException;
14

    
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
19
import eu.etaxonomy.cdm.io.common.IOValidator;
20
import eu.etaxonomy.cdm.io.common.Source;
21

    
22
/**
23
 * @author a.mueller
24
 * @since 17.02.2010
25
 */
26
public class BerlinModelTaxonNameImportValidator implements IOValidator<BerlinModelImportState> {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameImportValidator.class);
29

    
30
	@Override
31
	public boolean validate(BerlinModelImportState state) {
32
		boolean result = true;
33
		result &= checkNamesWithJournalReferences(state);
34
		//result &= checkPartOfJournal(bmiConfig);
35
		
36
		return result;
37
	}
38
	
39
	
40
	private boolean checkNamesWithJournalReferences(BerlinModelImportState state){
41
		try {
42
			boolean result = true;
43
			Source source = state.getConfig().getSource();
44
			String strQuery = " SELECT n.NameId, n.FullNameCache, n.Created_Who, cat.RefCategoryAbbrev, r.NomRefCache, r.RefCache, r.Title, r.Edition, r.Volume, r.Series, r.RefYear " +
45
						" FROM RefCategory AS cat INNER JOIN Reference AS r ON cat.RefCategoryId = r.RefCategoryFk " + 
46
						" INNER JOIN Name AS n ON r.RefId = n.NomRefFk " +
47
						" WHERE (r.RefCategoryFk = 9) ";
48
			if (StringUtils.isNotBlank(state.getConfig().getNameIdTable())){
49
				strQuery += String.format(" AND (n.NameId IN " +
50
                        " (SELECT NameId FROM %s ))" , state.getConfig().getNameIdTable()) ; 
51
			}
52
						
53
			ResultSet rs = source.getResultSet(strQuery);
54
			boolean firstRow = true;
55
			while (rs.next()){
56
				if (firstRow){
57
					System.out.println("========================================================");
58
					System.out.println("There are names with journals as nomencl. reference !");
59
					System.out.println("========================================================");
60
				}
61
				int nameId = rs.getInt("nameId");
62
				String cat = rs.getString("RefCategoryAbbrev");
63
				String fullNameCache = rs.getString("fullNameCache");
64
				String createdWho = rs.getString("Created_Who");
65
				
66
				String nomRefCache = rs.getString("nomRefCache");
67
				String refCache = rs.getString("RefCache");
68
				String title = rs.getString("title");
69
				String edition = rs.getString("Edition");
70
				String volume = rs.getString("Volume");
71
				String series = rs.getString("Series");
72
					
73
				System.out.println("NameID:" + nameId + "\n  cat: " + cat + 
74
						"\n  fullNameCache: " + fullNameCache + "\n  created_who: " + createdWho + 
75
						"\n  nomRefCache: " + nomRefCache + "\n  refCache: " + refCache + "\n  title: " + title + 
76
						"\n  edition: " + edition + "\n  volume: " + volume + 
77
						"\n  series: " + series );
78
				result = firstRow = false;
79
			}
80
			
81
			return result;
82
		} catch (SQLException e) {
83
			e.printStackTrace();
84
			return false;
85
		}
86
		
87
	}
88
	
89
}
(13-13/19)