1
2
3
4
5
6
7
8
9
10
11 package eu.etaxonomy.cdm.io.berlinModel.out.mapper;
12
13 import java.sql.PreparedStatement;
14 import java.sql.SQLException;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.common.CdmUtils;
19 import eu.etaxonomy.cdm.io.common.DbExportStateBase;
20 import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
21 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
22 import eu.etaxonomy.cdm.model.common.Annotation;
23 import eu.etaxonomy.cdm.model.common.AnnotationType;
24 import eu.etaxonomy.cdm.model.common.CdmBase;
25
26
27
28
29
30
31 public class CreatedAndNotesMapper extends MultipleAttributeMapperBase<DbSingleAttributeExportMapperBase<DbExportStateBase<?>>> implements IDbExportMapper<DbExportStateBase<?>>{
32 @SuppressWarnings("unused")
33 private static final Logger logger = Logger.getLogger(CreatedAndNotesMapper.class);
34
35 public static CreatedAndNotesMapper NewInstance(){
36 return new CreatedAndNotesMapper(true);
37 }
38
39 public static CreatedAndNotesMapper NewInstance(boolean withUpdate){
40 return new CreatedAndNotesMapper(withUpdate);
41 }
42
43
44
45
46
47
48 private CreatedAndNotesMapper(boolean withUpdate) {
49 singleMappers.add(DbUserMapper.NewInstance("createdBy", "Created_Who"));
50 singleMappers.add(DbDateMapper.NewInstance("created", "Created_When"));
51 singleMappers.add(MethodMapper.NewInstance("Notes", this.getClass(), "getNotes", AnnotatableEntity.class));
52 if (withUpdate){
53 singleMappers.add(DbUserMapper.NewInstance("updatedBy", "Updated_Who"));
54 singleMappers.add(DbDateMapper.NewInstance("updated", "Updated_When"));
55 }
56 }
57
58
59
60
61
62 public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase<?> state, String tableName) {
63 for (DbSingleAttributeExportMapperBase<DbExportStateBase<?>> mapper : singleMappers){
64 mapper.initialize(stmt, index, state, tableName);
65 }
66 }
67
68
69
70
71
72 public boolean invoke(CdmBase cdmBase) throws SQLException {
73 boolean result = true;
74 for (DbSingleAttributeExportMapperBase<DbExportStateBase<?>> mapper : singleMappers){
75 result &= mapper.invoke(cdmBase);
76 }
77 return result;
78 }
79
80
81 @SuppressWarnings("unused")
82 private static String getNotes(AnnotatableEntity obj){
83 String result = "";
84 String separator = ";";
85 for (Annotation annotation :obj.getAnnotations()){
86 if (! AnnotationType.TECHNICAL().equals(annotation.getAnnotationType())){
87 if (! ( annotation.getText() != null && annotation.getText().startsWith("ORDER:"))){
88 result = CdmUtils.concat(separator, result, annotation.getText());
89 }
90 }
91 }
92 return (result.trim().equals("")? null : result);
93 }
94
95 }