1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.kuali.student.r2.common.entity; |
12 | |
|
13 | |
import java.util.Date; |
14 | |
|
15 | |
import javax.persistence.Column; |
16 | |
import javax.persistence.Embeddable; |
17 | |
import javax.persistence.MappedSuperclass; |
18 | |
import javax.persistence.Temporal; |
19 | |
import javax.persistence.TemporalType; |
20 | |
|
21 | |
import org.kuali.student.common.util.security.SecurityUtils; |
22 | |
import org.kuali.student.r2.common.dto.MetaInfo; |
23 | |
import org.kuali.student.r2.common.infc.HasMeta; |
24 | |
import org.kuali.student.r2.common.infc.Meta; |
25 | |
|
26 | |
@MappedSuperclass |
27 | |
@Embeddable |
28 | |
public abstract class MetaEntity extends BaseVersionEntity { |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
@Temporal(TemporalType.TIMESTAMP) |
34 | |
@Column(updatable = false) |
35 | |
private Date createTime; |
36 | |
@Column(updatable = false) |
37 | |
private String createId; |
38 | |
@Temporal(TemporalType.TIMESTAMP) |
39 | |
private Date updateTime; |
40 | |
private String updateId; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | protected MetaEntity() { |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public MetaEntity(HasMeta hasMeta) { |
54 | 0 | if (null != hasMeta) { |
55 | 0 | Meta meta = hasMeta.getMeta(); |
56 | 0 | if (null != meta) { |
57 | 0 | this.setCreateTime(meta.getCreateTime()); |
58 | 0 | this.setCreateId(meta.getCreateId()); |
59 | 0 | this.setUpdateTime(meta.getUpdateTime()); |
60 | 0 | this.setUpdateId(meta.getUpdateId()); |
61 | 0 | this.setVersionNumber(null != meta.getVersionInd() ? Long.valueOf(meta.getVersionInd()) : null); |
62 | |
} |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | |
public Date getCreateTime() { |
67 | 0 | return createTime; |
68 | |
} |
69 | |
|
70 | |
public void setCreateTime(Date createTime) { |
71 | 0 | this.createTime = createTime; |
72 | 0 | } |
73 | |
|
74 | |
public String getCreateId() { |
75 | 0 | return createId; |
76 | |
} |
77 | |
|
78 | |
public void setCreateId(String createId) { |
79 | 0 | this.createId = createId; |
80 | 0 | } |
81 | |
|
82 | |
public Date getUpdateTime() { |
83 | 0 | return updateTime; |
84 | |
} |
85 | |
|
86 | |
public void setUpdateTime(Date updateTime) { |
87 | 0 | this.updateTime = updateTime; |
88 | 0 | } |
89 | |
|
90 | |
public String getUpdateId() { |
91 | 0 | return updateId; |
92 | |
} |
93 | |
|
94 | |
public void setUpdateId(String updateId) { |
95 | 0 | this.updateId = updateId; |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
protected void onPrePersist() { |
100 | 0 | super.onPrePersist(); |
101 | 0 | if (createTime == null) { |
102 | 0 | setCreateTime(new Date()); |
103 | |
} |
104 | 0 | if (updateTime == null) { |
105 | 0 | setUpdateTime(new Date()); |
106 | |
} |
107 | 0 | if (createId == null) { |
108 | 0 | setCreateId(SecurityUtils.getCurrentUserId()); |
109 | |
} |
110 | 0 | if (updateId == null) { |
111 | 0 | setUpdateId(SecurityUtils.getCurrentUserId()); |
112 | |
} |
113 | |
|
114 | 0 | } |
115 | |
|
116 | |
@Override |
117 | |
protected void onPreUpdate() { |
118 | 0 | super.onPreUpdate(); |
119 | |
|
120 | |
|
121 | 0 | if (createTime == null) { |
122 | 0 | setCreateTime(new Date()); |
123 | |
} |
124 | 0 | if (updateTime == null) { |
125 | 0 | setUpdateTime(new Date()); |
126 | |
} |
127 | 0 | if (createId == null) { |
128 | 0 | setCreateId(SecurityUtils.getCurrentUserId()); |
129 | |
} |
130 | 0 | if (updateId == null) { |
131 | 0 | setUpdateId(SecurityUtils.getCurrentUserId()); |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
public MetaInfo toDTO() { |
136 | 0 | MetaInfo miInfo = new MetaInfo(); |
137 | 0 | miInfo.setCreateId(getCreateId()); |
138 | 0 | miInfo.setCreateTime(getCreateTime()); |
139 | 0 | miInfo.setUpdateId(getUpdateId()); |
140 | 0 | miInfo.setUpdateTime(getUpdateTime()); |
141 | 0 | if (null != getVersionNumber()) { |
142 | 0 | miInfo.setVersionInd(new Long(getVersionNumber()).toString()); |
143 | |
} |
144 | 0 | return miInfo; |
145 | |
} |
146 | |
} |