Project

General

Profile

Download (5.63 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10

    
11
package eu.etaxonomy.cdm.io.common.mapping;
12

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

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

    
19
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
20
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
21
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
22
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24

    
25
/**
26
 * This mapper creates an description element source that is added to the according description element.
27
 * It adds the reference and the microReference.
28
 * @author a.mueller
29
 * @created 11.03.2010
30
 * @version 1.0
31
 */
32
public class DbImportDescriptionElementSourceCreationMapper extends DbImportObjectCreationMapperBase<DescriptionElementSource, DbImportStateBase<?,?>> {
33
	@SuppressWarnings("unused")
34
	private static final Logger logger = Logger.getLogger(DbImportDescriptionElementSourceCreationMapper.class);
35

    
36
//**************************** FACTORY METHOD ***********************************************/
37

    
38
	/**
39
	 * Returns an description element source creation mapper.
40
	 * @param dbDescriptionElementFkAttribute
41
	 * @param descriptionElementNamespace
42
	 * @param dbReferenceFkAttribute
43
	 * @param referenceNamespace
44
	 * @return
45
	 */
46
	public static DbImportDescriptionElementSourceCreationMapper NewInstance(String dbDescriptionElementFkAttribute, String descriptionElementNamespace, String dbReferenceFkAttribute, String referenceNamespace){
47
		String dbMicroReferenceAttribute = null;
48
		return new DbImportDescriptionElementSourceCreationMapper(dbDescriptionElementFkAttribute, descriptionElementNamespace, dbReferenceFkAttribute, referenceNamespace, dbMicroReferenceAttribute);
49
	}
50

    
51

    
52
	/**
53
	 * Returns an description element source creation mapper.
54
	 * @param dbDescriptionElementFkAttribute
55
	 * @param descriptionElementNamespace
56
	 * @param dbReferenceFkAttribute
57
	 * @param referenceNamespace
58
	 * @param dbMicroReferenceAttribute
59
	 * @return
60
	 */
61
	public static DbImportDescriptionElementSourceCreationMapper NewInstance(String dbDescriptionElementFkAttribute, String descriptionElementNamespace, String dbReferenceFkAttribute, String referenceNamespace, String dbMicroReferenceAttribute){
62
		return new DbImportDescriptionElementSourceCreationMapper(dbDescriptionElementFkAttribute, descriptionElementNamespace, dbReferenceFkAttribute, referenceNamespace, dbMicroReferenceAttribute);
63
	}
64

    
65

    
66
//******************************* VARIABLES ***********************************************/
67

    
68
	protected String descriptionElementNamespace;
69
	protected String dbDescriptionElementFkAttribute;
70
	protected String referenceNamespace;
71
	protected String dbReferenceFkAttribute;
72
	protected String dbMicroReferenceAttribute;
73

    
74

    
75
//******************************* CONSTRUCTOR ***********************************************/
76

    
77
	/**
78
	 * @param dbIdAttribute
79
	 * @param objectToCreateNamespace
80
	 */
81
	protected DbImportDescriptionElementSourceCreationMapper(String dbDescriptionElementFkAttribute, String descriptionElementNamespace, String dbReferenceFkAttribute, String referenceNamespace, String dbMicroReferenceAttribute) {
82
		super(null, null);  // idAttribute and objectToCreateNamespace not needed
83
		this.descriptionElementNamespace = descriptionElementNamespace;
84
		this.dbDescriptionElementFkAttribute = dbDescriptionElementFkAttribute;
85
		this.dbReferenceFkAttribute = dbReferenceFkAttribute;
86
		this.referenceNamespace = referenceNamespace;
87
		this.dbMicroReferenceAttribute = dbMicroReferenceAttribute;
88
	}
89

    
90
//******************************* METHODS ***********************************************/
91

    
92
	/* (non-Javadoc)
93
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
94
	 */
95
	@Override
96
	protected DescriptionElementSource createObject(ResultSet rs)throws SQLException {
97
		DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
98
		return source;
99
	}
100

    
101
	/* (non-Javadoc)
102
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#doInvoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.VersionableEntity)
103
	 */
104
	@Override
105
	protected DescriptionElementSource doInvoke(ResultSet rs, DescriptionElementSource source) throws SQLException {
106
		addCitation(rs, source);
107
		addMicroCitation(rs, source);
108
		setDescriptionElement(rs, source);
109
		return source;
110
	}
111

    
112
	/**
113
	 * @param rs
114
	 * @param source
115
	 * @throws SQLException
116
	 */
117
	private void setDescriptionElement(ResultSet rs,
118
			DescriptionElementSource source) throws SQLException {
119
		DescriptionElementBase descriptionElement = (DescriptionElementBase)getRelatedObject(rs, descriptionElementNamespace, dbDescriptionElementFkAttribute);
120
		descriptionElement.addSource(source);
121
	}
122

    
123
	/**
124
	 * @param rs
125
	 * @param source
126
	 * @throws SQLException
127
	 */
128
	private void addMicroCitation(ResultSet rs, DescriptionElementSource source) throws SQLException {
129
		String microReference = null;
130
		if (StringUtils.isNotBlank(dbMicroReferenceAttribute)){
131
			microReference = rs.getString(dbMicroReferenceAttribute);
132
		}
133
		source.setCitationMicroReference(microReference);
134
	}
135

    
136
	/**
137
	 * @param rs
138
	 * @param source
139
	 * @throws SQLException
140
	 */
141
	private void addCitation(ResultSet rs, DescriptionElementSource source) throws SQLException {
142
		Reference citation = (Reference)getRelatedObject(rs, referenceNamespace, dbReferenceFkAttribute);
143
		source.setCitation(citation);
144
	}
145

    
146
}
(11-11/51)