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