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;import org.apache.logging.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
|
19
|
import eu.etaxonomy.cdm.model.common.Language;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.TextData;
|
22
|
import eu.etaxonomy.cdm.model.description.TextFormat;
|
23
|
|
24
|
/**
|
25
|
* This Mapper creates a text data element and adds it to a taxon.
|
26
|
* @author a.mueller
|
27
|
* @since 11.03.2010
|
28
|
*/
|
29
|
public class DbImportTextDataCreationMapper<STATE extends DbImportStateBase<?,?>>
|
30
|
extends DbImportDescriptionElementCreationMapperBase<TextData, DbImportStateBase<?,?>> {
|
31
|
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = LogManager.getLogger(DbImportTextDataCreationMapper.class);
|
34
|
|
35
|
//******************************** FACTORY METHOD ***************************************************/
|
36
|
|
37
|
/**
|
38
|
* Creates a TextData and adds it to the description of a taxon.
|
39
|
* @param dbIdAttribute
|
40
|
* @param objectToCreateNamespace
|
41
|
* @param dbTaxonFkAttribute
|
42
|
* @param taxonNamespace
|
43
|
* @return
|
44
|
*/
|
45
|
public static DbImportTextDataCreationMapper<?> NewInstance(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace){
|
46
|
Feature feature = null;
|
47
|
Language language = null;
|
48
|
TextFormat format = null;
|
49
|
String dbTextAttribute = null;
|
50
|
return new DbImportTextDataCreationMapper<>(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, dbTextAttribute, language, feature, format);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Creates a TextData, adds the the in the language and the format defined and then adds it to the description of a taxon.
|
55
|
* If language is <code>null</code> the default language is taken instead.
|
56
|
* @param dbIdAttribute
|
57
|
* @param objectToCreateNamespace
|
58
|
* @param dbTaxonFkAttribute
|
59
|
* @param taxonNamespace
|
60
|
* @param status
|
61
|
* @return
|
62
|
*/
|
63
|
public static DbImportTextDataCreationMapper<?> NewInstance(String dbIdAttribute, String objectToCreateNamespace, String dbTaxonFkAttribute, String taxonNamespace, String dbTextAttribute, Language language, Feature feature, TextFormat format){
|
64
|
return new DbImportTextDataCreationMapper<>(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, dbTextAttribute, language, feature, format);
|
65
|
}
|
66
|
|
67
|
//******************************* ATTRIBUTES ***************************************/
|
68
|
|
69
|
protected Feature defaultFeature;
|
70
|
protected Language defaultLanguage;
|
71
|
protected TextFormat defaultFormat;
|
72
|
protected String dbTextAttribute;
|
73
|
|
74
|
//********************************* CONSTRUCTOR ****************************************/
|
75
|
/**
|
76
|
* @param dbIdAttribute
|
77
|
* @param objectToCreateNamespace
|
78
|
* @param dbTaxonFkAttribute
|
79
|
* @param taxonNamespace
|
80
|
*/
|
81
|
protected DbImportTextDataCreationMapper(String dbIdAttribute, String objectToCreateNamespace,
|
82
|
String dbTaxonFkAttribute, String taxonNamespace, String dbTextAttribute, Language language,
|
83
|
Feature feature, TextFormat format) {
|
84
|
super(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace);
|
85
|
this.defaultFeature = feature;
|
86
|
this.dbTextAttribute = dbTextAttribute;
|
87
|
this.defaultLanguage = language;
|
88
|
this.defaultFormat = format;
|
89
|
}
|
90
|
|
91
|
//************************************ METHODS *******************************************/
|
92
|
|
93
|
@Override
|
94
|
protected TextData createObject(ResultSet rs) throws SQLException {
|
95
|
TextData textData = TextData.NewInstance();
|
96
|
String text = null;
|
97
|
if (StringUtils.isNotBlank(dbTextAttribute)){
|
98
|
text = rs.getString(dbTextAttribute);
|
99
|
}
|
100
|
if (text != null){
|
101
|
Language language = this.defaultLanguage;
|
102
|
if (language == null){
|
103
|
language = Language.DEFAULT();
|
104
|
}
|
105
|
textData.putText(language, text);
|
106
|
}
|
107
|
TextFormat format = this.defaultFormat;
|
108
|
textData.setFormat(format);
|
109
|
|
110
|
Feature feature = this.defaultFeature;
|
111
|
textData.setFeature(feature);
|
112
|
return textData;
|
113
|
}
|
114
|
}
|