Project

General

Profile

« Previous | Next » 

Revision 9c80e7d1

Added by Andreas Müller almost 10 years ago

Some updates for AlgaTerra Types import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/validation/AlgaTerraSpecimenImportValidator.java
10 10

  
11 11
package eu.etaxonomy.cdm.io.algaterra.validation;
12 12

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

  
16
import org.apache.commons.lang.StringUtils;
13 17
import org.apache.log4j.Logger;
14 18

  
15 19
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
16 20
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
17 21
import eu.etaxonomy.cdm.io.common.IOValidator;
22
import eu.etaxonomy.cdm.io.common.Source;
18 23

  
19 24
/**
20 25
 * @author a.mueller
......
22 27
 * @version 1.0
23 28
 */
24 29
public class AlgaTerraSpecimenImportValidator implements IOValidator<BerlinModelImportState> {
30
	@SuppressWarnings("unused")
25 31
	private static final Logger logger = Logger.getLogger(AlgaTerraSpecimenImportValidator.class);
26 32

  
27
	/* (non-Javadoc)
28
	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
29
	 */
33

  
34
	@Override
30 35
	public boolean validate(BerlinModelImportState state) {
31 36
		boolean result = true;
32 37
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
33
//		result &= checkTaxonIsAccepted(bmiConfig);
38
		result &= checkOrphanedEcologyFacts(bmiConfig);
34 39
		//result &= checkPartOfJournal(bmiConfig);
35 40
		System.out.println("Checking for Specimen not yet fully implemented");
36 41
		return result;
......
39 44
	
40 45
	//******************************** CHECK *************************************************
41 46
		
42
//		private static boolean checkTaxonIsAccepted(BerlinModelImportConfigurator config){
43
//			try {
44
//				boolean result = true;
45
//				Source source = config.getSource();
46
//				String strQuery = "SELECT emOccurrence.OccurrenceId, PTaxon.StatusFk, Name.FullNameCache, Status.Status, PTaxon.PTRefFk, Reference.RefCache " + 
47
//							" FROM emOccurrence INNER JOIN " +
48
//								" PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk INNER JOIN " + 
49
//				                " Name ON PTaxon.PTNameFk = Name.NameId INNER JOIN " +
50
//				                " Status ON PTaxon.StatusFk = Status.StatusId LEFT OUTER JOIN " +
51
//				                " Reference ON PTaxon.PTRefFk = Reference.RefId " + 
52
//							" WHERE (PTaxon.StatusFk <> 1)  ";
53
//
54
//				if (StringUtils.isNotBlank(config.getOccurrenceFilter())){
55
//					strQuery += String.format(" AND (%s) ", config.getOccurrenceFilter()) ; 
56
//				}
57
//
58
//				
59
//				ResultSet resulSet = source.getResultSet(strQuery);
60
//				boolean firstRow = true;
61
//				while (resulSet.next()){
62
//					if (firstRow){
63
//						System.out.println("========================================================");
64
//						System.out.println("There are Occurrences for a taxon that is not accepted!");
65
//						System.out.println("========================================================");
66
//					}
67
//					int occurrenceId = resulSet.getInt("OccurrenceId");
68
////					int statusFk = resulSet.getInt("StatusFk");
69
//					String status = resulSet.getString("Status");
70
//					String fullNameCache = resulSet.getString("FullNameCache");
71
//					String ptRefFk = resulSet.getString("PTRefFk");
72
//					String ptRef = resulSet.getString("RefCache");
73
//					
74
//					System.out.println("OccurrenceId:" + occurrenceId + "\n  Status: " + status + 
75
//							"\n  FullNameCache: " + fullNameCache +  "\n  ptRefFk: " + ptRefFk +
76
//							"\n  sec: " + ptRef );
77
//					
78
//					result = firstRow = false;
79
//				}
80
//				
81
//				return result;
82
//			} catch (SQLException e) {
83
//				e.printStackTrace();
84
//				return false;
85
//			}
86
//		}
47
		private static boolean checkOrphanedEcologyFacts(BerlinModelImportConfigurator config){
48
			try {
49
				boolean result = true;
50
				Source source = config.getSource();
51
				String strQuery = "SELECT * FROM Fact " + 
52
						" WHERE FactCategoryFk = 202 AND ExtensionFk NOT IN (SELECT EcoFactId FROM EcoFact) " +
53
						" ORDER BY ExtensionFk  ";
54

  
55
				ResultSet resulSet = source.getResultSet(strQuery);
56
				boolean firstRow = true;
57
				while (resulSet.next()){
58
					if (firstRow){
59
						System.out.println("========================================================");
60
						System.out.println("There EcologyFacts with pointing to non existing EcoFacts!");
61
						System.out.println("========================================================");
62
					}
63
					int factId = resulSet.getInt("FactId");
64
					int extensionFk = resulSet.getInt("ExtensionFk");
65
					
66
					System.out.println("FactId:" + factId + "\n  ExtensionFk: " + extensionFk);
67
					
68
					result = firstRow = false;
69
				}
70
				
71
				return result;
72
			} catch (SQLException e) {
73
				e.printStackTrace();
74
				return false;
75
			}
76
		}
87 77

  
88 78
}

Also available in: Unified diff