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.Marker;
|
20
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
21
|
|
22
|
|
23
|
/**
|
24
|
* Object creation mapper which creates a marker.
|
25
|
*
|
26
|
* @author a.mueller
|
27
|
* @since 11.03.2010
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class DbImportMarkerCreationMapper extends DbImportSupplementCreationMapperBase<Marker, AnnotatableEntity, DbImportStateBase<?, ?>, MarkerType> {
|
31
|
private static final Logger logger = Logger.getLogger(DbImportMarkerCreationMapper.class);
|
32
|
|
33
|
//************************** FACTORY METHODS ***************************************************************/
|
34
|
|
35
|
|
36
|
/**
|
37
|
* Creates a marker mapper which creates an empty marker.
|
38
|
*
|
39
|
* @param dbMarkedObjectAttribute
|
40
|
* @param markedObjectNamespace
|
41
|
* @return
|
42
|
*/
|
43
|
public static DbImportMarkerCreationMapper NewInstance(String dbMarkedObjectAttribute, String markedObjectNamespace){
|
44
|
return new DbImportMarkerCreationMapper(dbMarkedObjectAttribute, markedObjectNamespace, null, null, null);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Creates a marker mapper which creates a marker and sets the marker flag and the marker type and adds
|
49
|
* an Annotation holding the original source id
|
50
|
*
|
51
|
* @param dbMarkedObjectAttribute
|
52
|
* @param markedObjectNamespace
|
53
|
* @param dbMarkerValueAttribute
|
54
|
* @param dbIdAttribute
|
55
|
* @param markerType
|
56
|
* @return
|
57
|
*/
|
58
|
public static DbImportMarkerCreationMapper NewInstance(String dbMarkedObjectAttribute, String markedObjectNamespace, String dbMarkerValueAttribute, String dbIdAttribute, MarkerType markerType){
|
59
|
return new DbImportMarkerCreationMapper(dbMarkedObjectAttribute, markedObjectNamespace, dbMarkerValueAttribute, dbIdAttribute, markerType);
|
60
|
}
|
61
|
|
62
|
|
63
|
//********************************* CONSTRUCTOR ****************************************/
|
64
|
|
65
|
/**
|
66
|
* @param dbSupplementValueAttribute
|
67
|
* @param dbSupplementedObjectAttribute
|
68
|
* @param dbIdAttribute
|
69
|
* @param supplementedObjectNamespace
|
70
|
* @param supplementType
|
71
|
*/
|
72
|
protected DbImportMarkerCreationMapper(String dbSupplementedObjectAttribute, String supplementedObjectNamespace, String dbSupplementValueAttribute, String dbIdAttribute, MarkerType supplementType) {
|
73
|
super(dbSupplementValueAttribute, dbSupplementedObjectAttribute, dbIdAttribute, supplementedObjectNamespace, supplementType);
|
74
|
}
|
75
|
|
76
|
//************************************ METHODS *******************************************/
|
77
|
|
78
|
/* (non-Javadoc)
|
79
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#addSupplement(eu.etaxonomy.cdm.model.common.AnnotatableEntity, java.lang.String, eu.etaxonomy.cdm.model.common.AnnotatableEntity)
|
80
|
*/
|
81
|
@Override
|
82
|
protected boolean addSupplement(Marker marker, AnnotatableEntity annotatableEntity, String id) {
|
83
|
if (annotatableEntity != null){
|
84
|
annotatableEntity.addMarker(marker);
|
85
|
return true;
|
86
|
}else{
|
87
|
String warning = "Annotatable entity (" + id + ") for marker not found. Marker not created.";
|
88
|
logger.warn(warning);
|
89
|
return false;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/* (non-Javadoc)
|
94
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#setSupplementValue(java.lang.Object)
|
95
|
*/
|
96
|
@Override
|
97
|
protected void setSupplementValue(ResultSet rs, Marker marker) throws SQLException {
|
98
|
Boolean value = rs.getBoolean(dbSupplementValueAttribute);
|
99
|
marker.setFlag(value);
|
100
|
|
101
|
}
|
102
|
|
103
|
/* (non-Javadoc)
|
104
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
|
105
|
*/
|
106
|
@Override
|
107
|
protected Marker createObject(ResultSet rs) throws SQLException {
|
108
|
Marker marker = Marker.NewInstance();
|
109
|
marker.setMarkerType(supplementType);
|
110
|
return marker;
|
111
|
}
|
112
|
|
113
|
|
114
|
}
|