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.out;
|
11
|
|
12
|
import java.sql.Types;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.joda.time.DateTime;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
19
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
20
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
21
|
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
|
22
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
* @since 12.05.2009
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class DbLastActionMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer> {
|
30
|
@SuppressWarnings("unused")
|
31
|
private static final Logger logger = Logger.getLogger(DbLastActionMapper.class);
|
32
|
|
33
|
public static final UUID uuidMarkerTypeHasNoLastAction = UUID.fromString("99652d5a-bc92-4251-b57d-0fec4d258ab7");
|
34
|
boolean isActionType;
|
35
|
|
36
|
public static DbLastActionMapper NewInstance(String dbAttributeString, boolean isActionType){
|
37
|
return new DbLastActionMapper(dbAttributeString, null, true, isActionType);
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* @param dbAttributeString
|
42
|
* @param cdmAttributeString
|
43
|
*/
|
44
|
private DbLastActionMapper(String dbAttributeString, String defaultValue, boolean obligatory, boolean isActionType) {
|
45
|
super("updated, created", dbAttributeString, defaultValue, false);
|
46
|
this.isActionType = isActionType;
|
47
|
}
|
48
|
|
49
|
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue(eu.etaxonomy.cdm.model.common.CdmBase)
|
53
|
*/
|
54
|
@Override
|
55
|
protected Object getValue(CdmBase cdmBase) {
|
56
|
if (cdmBase.isInstanceOf(VersionableEntity.class)){
|
57
|
//exclude objects marked as 'hasNoM
|
58
|
if (cdmBase.isInstanceOf(AnnotatableEntity.class)){
|
59
|
IAnnotatableEntity annoEnti = cdmBase.deproxy(cdmBase, AnnotatableEntity.class);
|
60
|
if (annoEnti.hasMarker(uuidMarkerTypeHasNoLastAction, true)){
|
61
|
return null;
|
62
|
}
|
63
|
}
|
64
|
//return updated or created
|
65
|
VersionableEntity versionable = CdmBase.deproxy(cdmBase, VersionableEntity.class);
|
66
|
if (versionable.getUpdated() != null){
|
67
|
return makeChanged(versionable);
|
68
|
}else{
|
69
|
return makeCreated(cdmBase);
|
70
|
}
|
71
|
}else{
|
72
|
//return created
|
73
|
return makeCreated(cdmBase);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
private Object makeChanged(VersionableEntity versionable) {
|
78
|
if (isActionType){
|
79
|
return "changed";
|
80
|
}else{
|
81
|
return versionable.getUpdated();
|
82
|
}
|
83
|
}
|
84
|
|
85
|
private Object makeCreated(CdmBase cdmBase) {
|
86
|
if (isActionType){
|
87
|
return "created";
|
88
|
}else{
|
89
|
return cdmBase.getCreated();
|
90
|
}
|
91
|
}
|
92
|
|
93
|
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
|
97
|
*/
|
98
|
@Override
|
99
|
protected int getSqlType() {
|
100
|
if (isActionType){
|
101
|
return Types.VARCHAR;
|
102
|
}else{
|
103
|
return Types.DATE;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
|
108
|
/* (non-Javadoc)
|
109
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
110
|
*/
|
111
|
@Override
|
112
|
public Class<?> getTypeClass() {
|
113
|
return DateTime.class;
|
114
|
}
|
115
|
|
116
|
}
|