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.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
|
18
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
19
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
20
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
21
|
import eu.etaxonomy.cdm.model.common.Language;
|
22
|
|
23
|
|
24
|
/**
|
25
|
* Object creation mapper which creates a marker.
|
26
|
*
|
27
|
* @author a.mueller
|
28
|
* @created 11.03.2010
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class DbImportAnnotationCreationMapper extends DbImportSupplementCreationMapperBase<Annotation, AnnotatableEntity, DbImportStateBase<?, ?>, AnnotationType> {
|
32
|
private static final Logger logger = Logger.getLogger(DbImportAnnotationCreationMapper.class);
|
33
|
|
34
|
//************************** FACTORY METHODS ***************************************************************/
|
35
|
|
36
|
|
37
|
/**
|
38
|
* @param dbAnnotatedObjectAttribute
|
39
|
* @param annotatedObjectNamespace
|
40
|
* @return
|
41
|
*/
|
42
|
public static DbImportAnnotationCreationMapper NewInstance(String dbAnnotatedObjectAttribute, String annotatedObjectNamespace){
|
43
|
return new DbImportAnnotationCreationMapper(dbAnnotatedObjectAttribute, annotatedObjectNamespace, null, null, null, null);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Creates an annotation mapper which creates an annotation and sets the annotation text,
|
48
|
* the annotation language and annotation (added to this annotation) holding the original
|
49
|
* source id.
|
50
|
* If one of the attribute is null the according value is not set.
|
51
|
|
52
|
* @param dbAnnotatedObjectAttribute - obligatory
|
53
|
* @param annotatedObjectNamespace - obligatory
|
54
|
* @param dbAnnotationTextAttribute
|
55
|
* @param language
|
56
|
* @param dbIdAttribute
|
57
|
* @param annotationType
|
58
|
* @return
|
59
|
*/
|
60
|
public static DbImportAnnotationCreationMapper NewInstance(String dbAnnotatedObjectAttribute, String annotatedObjectNamespace, String dbAnnotationTextAttribute, Language language, String dbIdAttribute, AnnotationType annotationType){
|
61
|
return new DbImportAnnotationCreationMapper(dbAnnotatedObjectAttribute, annotatedObjectNamespace, dbAnnotationTextAttribute, language, dbIdAttribute, annotationType);
|
62
|
}
|
63
|
|
64
|
// ******************************* VARIABLES ****************************************/
|
65
|
|
66
|
protected Language language;
|
67
|
|
68
|
//********************************* CONSTRUCTOR ****************************************/
|
69
|
|
70
|
/**
|
71
|
* @param dbSupplementValueAttribute
|
72
|
* @param dbSupplementedObjectAttribute
|
73
|
* @param dbIdAttribute
|
74
|
* @param supplementedObjectNamespace
|
75
|
* @param supplementType
|
76
|
*/
|
77
|
protected DbImportAnnotationCreationMapper(String dbSupplementedObjectAttribute, String supplementedObjectNamespace, String dbSupplementValueAttribute, Language language, String dbIdAttribute, AnnotationType supplementType) {
|
78
|
super(dbSupplementValueAttribute, dbSupplementedObjectAttribute, dbIdAttribute, supplementedObjectNamespace, supplementType);
|
79
|
this.language = language;
|
80
|
}
|
81
|
|
82
|
//************************************ METHODS *******************************************/
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#addSupplement(eu.etaxonomy.cdm.model.common.AnnotatableEntity, java.lang.String, eu.etaxonomy.cdm.model.common.AnnotatableEntity)
|
86
|
*/
|
87
|
@Override
|
88
|
protected boolean addSupplement(Annotation annotation, AnnotatableEntity annotatableEntity, String id) {
|
89
|
if (annotatableEntity != null){
|
90
|
annotatableEntity.addAnnotation(annotation);
|
91
|
return true;
|
92
|
}else{
|
93
|
String warning = "Annotatable entity (" + id + ") for annotation not found. Annotation not created.";
|
94
|
logger.warn(warning);
|
95
|
return false;
|
96
|
}
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#setSupplementValue(java.lang.Object)
|
101
|
*/
|
102
|
@Override
|
103
|
protected void setSupplementValue(ResultSet rs, Annotation annotation) throws SQLException {
|
104
|
String value = rs.getString(dbSupplementValueAttribute);
|
105
|
annotation.setText(value);
|
106
|
|
107
|
}
|
108
|
|
109
|
/* (non-Javadoc)
|
110
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
|
111
|
*/
|
112
|
@Override
|
113
|
protected Annotation createObject(ResultSet rs) throws SQLException {
|
114
|
Annotation annotation = Annotation.NewInstance(null, supplementType, null);
|
115
|
if (language != null){
|
116
|
annotation.setLanguage(language);
|
117
|
}
|
118
|
return annotation;
|
119
|
}
|
120
|
|
121
|
|
122
|
}
|