Project

General

Profile

« Previous | Next » 

Revision 9dc896c9

Added by Andreas Müller almost 7 years ago

fix #6368 rename table and class TaxonNameBase

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/mapping/DbImportNameTypeDesignationMapper.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
18 18
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
19 19
import eu.etaxonomy.cdm.model.common.CdmBase;
20 20
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
21
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22 22
import eu.etaxonomy.cdm.model.reference.Reference;
23 23

  
24 24
/**
......
35 35
 */
36 36
public class DbImportNameTypeDesignationMapper<STATE extends DbImportStateBase<?,?>, T extends IDbImportTransformed> extends DbImportMultiAttributeMapperBase<CdmBase, STATE> {
37 37
	private static final Logger logger = Logger.getLogger(DbImportNameTypeDesignationMapper.class);
38
	
38

  
39 39
//******************************** FACTORY METHOD ***************************************************/
40
	
40

  
41 41
	public static DbImportNameTypeDesignationMapper<?,?> NewInstance(String dbFromAttribute, String dbToAttribute, String relatedObjectNamespace, String desigStatusAttribute){
42 42
		return new DbImportNameTypeDesignationMapper(dbFromAttribute, dbToAttribute, null, relatedObjectNamespace, desigStatusAttribute);
43 43
	}
44
	
44

  
45 45
//******************************* ATTRIBUTES ***************************************/
46 46
	private String fromAttribute;
47 47
	private String toAttribute;
......
50 50
	private String citationAttribute;
51 51
	private String microCitationAttribute;
52 52
	private String designationStatusAttribute;
53
	
54
	
53

  
54

  
55 55
//********************************* CONSTRUCTOR ****************************************/
56 56
	/**
57
	 * @param relatedObjectNamespace 
57
	 * @param relatedObjectNamespace
58 58
	 * @param mappingImport
59 59
	 */
60 60
	protected DbImportNameTypeDesignationMapper(String fromAttribute, String toAttribute, NameTypeDesignationStatus designationStatus, String relatedObjectNamespace, String desigStatusAttribute) {
......
68 68
	}
69 69

  
70 70
//************************************ METHODS *******************************************/
71
	
71

  
72 72
	/* (non-Javadoc)
73 73
	 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#invoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.CdmBase)
74 74
	 */
75
	public CdmBase invoke(ResultSet rs, CdmBase cdmBase) throws SQLException {
75
	@Override
76
    public CdmBase invoke(ResultSet rs, CdmBase cdmBase) throws SQLException {
76 77
		STATE state = importMapperHelper.getState();
77 78
		CdmImportBase currentImport = state.getCurrentIO();
78 79
		if (currentImport instanceof ICheckIgnoreMapper){
......
81 82
				return cdmBase;
82 83
			}
83 84
		}
84
		
85

  
85 86
		CdmBase fromObject = getRelatedObject(rs, fromAttribute);
86 87
		CdmBase toObject = getRelatedObject(rs, toAttribute);
87 88
		//TODO cast
......
90 91
		if (citationAttribute != null){
91 92
			microCitation = rs.getString(microCitationAttribute);
92 93
		}
93
		
94

  
94 95
		Object designationStatusValue = null;
95 96
		if (citationAttribute != null){
96 97
			designationStatusValue = rs.getObject(designationStatusAttribute);
......
102 103
			logger.warn(warning);
103 104
			return cdmBase;
104 105
		}
105
		TaxonNameBase typifiedName = checkTaxonNameBaseType(fromObject);
106
		
106
		TaxonName typifiedName = checkTaxonNameType(fromObject);
107

  
107 108
		if (toObject == null){
108 109
			String warning  = "Species name could not be found. Name type not added to higher rank name";
109 110
			logger.warn(warning);
110 111
			return cdmBase;
111 112
		}
112
		TaxonNameBase typeName = checkTaxonNameBaseType(toObject);
113
		
113
		TaxonName typeName = checkTaxonNameType(toObject);
114

  
114 115
		boolean addToAllHomotypicNames = false; //TODO check if this is correct
115 116
		String originalNameString = null; //TODO what is this
116
		
117

  
117 118
		NameTypeDesignationStatus status = this.designationStatus;
118 119
		if (designationStatusValue != null){
119 120
			//FIXME this needs work in generics to remove casts. Or find an other solution
......
123 124
			}
124 125
		}
125 126
		typifiedName.addNameTypeDesignation(typeName, citation, microCitation, originalNameString, status, addToAllHomotypicNames);
126
		
127

  
127 128
		return typifiedName;
128 129
	}
129
	
130

  
130 131
	/**
131 132
	 *	//TODO copied from DbImportObjectMapper. Maybe these can be merged again in future
132 133
	 * @param rs
......
144 145
		}
145 146
		return result;
146 147
	}
147
	
148

  
148 149
	/**
149
	 * Checks if cdmBase is of type Taxon 
150
	 * Checks if cdmBase is of type Taxon
150 151
	 * @param fromObject
151 152
	 */
152
	private TaxonNameBase checkTaxonNameBaseType(CdmBase cdmBase) {
153
		if (! cdmBase.isInstanceOf(TaxonNameBase.class)){
154
			String warning = "Type name or typifier name is not of type TaxonNameBase but " + cdmBase.getClass().getName();
153
	private TaxonName checkTaxonNameType(CdmBase cdmBase) {
154
		if (! cdmBase.isInstanceOf(TaxonName.class)){
155
			String warning = "Type name or typifier name is not of type TaxonName but " + cdmBase.getClass().getName();
155 156
			logger.warn(warning);
156 157
			throw new IllegalArgumentException(warning);
157 158
		}
158
		return (cdmBase.deproxy(cdmBase, TaxonNameBase.class));
159
		return (cdmBase.deproxy(cdmBase, TaxonName.class));
159 160
	}
160 161

  
161 162

  

Also available in: Unified diff