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.logging.log4j.LogManager;
|
16
|
import org.apache.logging.log4j.Logger;
|
17
|
import org.joda.time.DateTime;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
20
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
21
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @since 12.05.2009
|
28
|
*/
|
29
|
public class DbLastActionMapper
|
30
|
extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>{
|
31
|
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = LogManager.getLogger();
|
34
|
|
35
|
public static final UUID uuidMarkerTypeHasNoLastAction = UUID.fromString("99652d5a-bc92-4251-b57d-0fec4d258ab7");
|
36
|
public static final UUID uuidAnnotationTypeLastAction = UUID.fromString("d0423ffd-d1dc-4571-ba05-eb724eec3c77");
|
37
|
public static final UUID uuidAnnotationTypeLastActionDate = UUID.fromString("f666fd60-b5dc-4950-9d6a-d3ded7d596d7");
|
38
|
|
39
|
boolean isActionType;
|
40
|
|
41
|
public static DbLastActionMapper NewInstance(String dbAttributeString, boolean isActionType){
|
42
|
return new DbLastActionMapper(dbAttributeString, null, isActionType);
|
43
|
}
|
44
|
|
45
|
private DbLastActionMapper(String dbAttributeString, String defaultValue, boolean isActionType) {
|
46
|
super("updated, created", dbAttributeString, defaultValue, false, false);
|
47
|
this.isActionType = isActionType;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
protected Object getValue(CdmBase cdmBase) {
|
52
|
if (cdmBase.isInstanceOf(VersionableEntity.class)){
|
53
|
//exclude objects marked as 'hasNoM
|
54
|
if (cdmBase.isInstanceOf(AnnotatableEntity.class)){
|
55
|
AnnotatableEntity annotatableEntity = CdmBase.deproxy(cdmBase, AnnotatableEntity.class);
|
56
|
UUID uuidType = isActionType ? uuidAnnotationTypeLastAction : uuidAnnotationTypeLastActionDate;
|
57
|
for (Annotation annotation : annotatableEntity.getAnnotations(uuidType)){
|
58
|
return annotation.getText();
|
59
|
}
|
60
|
if (annotatableEntity.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
|
@Override
|
94
|
protected int getSqlType() {
|
95
|
if (isActionType){
|
96
|
return Types.VARCHAR;
|
97
|
}else{
|
98
|
return Types.DATE;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public Class<?> getTypeClass() {
|
104
|
return DateTime.class;
|
105
|
}
|
106
|
|
107
|
}
|