Project

General

Profile

Download (5.07 KB) Statistics
| Branch: | Tag: | 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.common.mapping;
11

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

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

    
19
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
22
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
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
 * @since 11.03.2010
30
 */
31
public class DbImportDescriptionElementSourceCreationMapper extends DbImportObjectCreationMapperBase<DescriptionElementSource, DbImportStateBase<?,?>> {
32

    
33
    @SuppressWarnings("unused")
34
	private static final Logger logger = LogManager.getLogger();
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,
47
	        String descriptionElementNamespace, String dbReferenceFkAttribute, String referenceNamespace){
48
		String dbMicroReferenceAttribute = null;
49
		return new DbImportDescriptionElementSourceCreationMapper(dbDescriptionElementFkAttribute, descriptionElementNamespace, dbReferenceFkAttribute, referenceNamespace, dbMicroReferenceAttribute);
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
//******************************* VARIABLES ***********************************************/
66

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

    
73
//******************************* CONSTRUCTOR ***********************************************/
74

    
75
	protected DbImportDescriptionElementSourceCreationMapper(String dbDescriptionElementFkAttribute,
76
	        String descriptionElementNamespace, String dbReferenceFkAttribute, String referenceNamespace, String dbMicroReferenceAttribute) {
77
		super(null, null);  // idAttribute and objectToCreateNamespace not needed
78
		this.descriptionElementNamespace = descriptionElementNamespace;
79
		this.dbDescriptionElementFkAttribute = dbDescriptionElementFkAttribute;
80
		this.dbReferenceFkAttribute = dbReferenceFkAttribute;
81
		this.referenceNamespace = referenceNamespace;
82
		this.dbMicroReferenceAttribute = dbMicroReferenceAttribute;
83
	}
84

    
85
//******************************* METHODS ***********************************************/
86

    
87
	@Override
88
	protected DescriptionElementSource createObject(ResultSet rs)throws SQLException {
89
		DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
90
		return source;
91
	}
92

    
93
	@Override
94
	protected DescriptionElementSource doInvoke(ResultSet rs, DescriptionElementSource source) throws SQLException {
95
		setCitation(rs, source);
96
		setMicroCitation(rs, source);
97
		setDescriptionElement(rs, source);
98
		return source;
99
	}
100

    
101
	private void setDescriptionElement(ResultSet rs,
102
			DescriptionElementSource source) throws SQLException {
103
		DescriptionElementBase descriptionElement = (DescriptionElementBase)getRelatedObject(rs, descriptionElementNamespace, dbDescriptionElementFkAttribute);
104
		descriptionElement.addSource(source);
105
	}
106

    
107
	private void setMicroCitation(ResultSet rs, DescriptionElementSource source) throws SQLException {
108
		String microReference = null;
109
		if (StringUtils.isNotBlank(dbMicroReferenceAttribute)){
110
			microReference = rs.getString(dbMicroReferenceAttribute);
111
		}
112
		source.setCitationMicroReference(microReference);
113
	}
114

    
115
	private void setCitation(ResultSet rs, DescriptionElementSource source) throws SQLException {
116
		Reference citation = (Reference)getRelatedObject(rs, referenceNamespace, dbReferenceFkAttribute);
117
		source.setCitation(citation);
118
	}
119
}
(11-11/53)