root / src / gr / ebs / gss / server / domain / AuditInfo.java @ af6aa461
History | View | Annotate | Download (4.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.server.domain; |
20 |
|
21 |
import gr.ebs.gss.common.dto.AuditInfoDTO; |
22 |
|
23 |
import java.io.Serializable; |
24 |
import java.util.Date; |
25 |
|
26 |
import javax.persistence.Column; |
27 |
import javax.persistence.Embeddable; |
28 |
import javax.persistence.JoinColumn; |
29 |
import javax.persistence.ManyToOne; |
30 |
import javax.persistence.Temporal; |
31 |
import javax.persistence.TemporalType; |
32 |
|
33 |
import org.hibernate.annotations.Cache; |
34 |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
35 |
|
36 |
/**
|
37 |
* This class holds audit information pertaining to the associated domain
|
38 |
* object. This information includes the user that created the object, the
|
39 |
* creation time, the user that modified the object and the modification date.
|
40 |
*/
|
41 |
@Embeddable
|
42 |
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
43 |
public class AuditInfo implements Serializable{ |
44 |
|
45 |
/**
|
46 |
* The date the associated object was created. We can never change it after
|
47 |
* creation.
|
48 |
*/
|
49 |
@Temporal(TemporalType.TIMESTAMP)
|
50 |
@Column(updatable = false, nullable = false) |
51 |
private Date creationDate; |
52 |
|
53 |
/**
|
54 |
* The user that created the associated object. We can never change it after
|
55 |
* creation.
|
56 |
*/
|
57 |
@ManyToOne
|
58 |
@JoinColumn(updatable = false) |
59 |
private User createdBy;
|
60 |
|
61 |
/**
|
62 |
* The date the associated object was modified.
|
63 |
*/
|
64 |
@Temporal(TemporalType.TIMESTAMP)
|
65 |
@Column(nullable = false) |
66 |
private Date modificationDate; |
67 |
|
68 |
/**
|
69 |
* The user that modified the associated object.
|
70 |
*/
|
71 |
@ManyToOne
|
72 |
private User modifiedBy;
|
73 |
|
74 |
/**
|
75 |
* Retrieve the creation date for the associated object.
|
76 |
*
|
77 |
* @return the date of creation
|
78 |
*/
|
79 |
public Date getCreationDate() { |
80 |
return creationDate;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Modify the creation date for the associated object.
|
85 |
*
|
86 |
* @param _creationDate the new date of creation
|
87 |
*/
|
88 |
public void setCreationDate(final Date _creationDate) { |
89 |
creationDate = _creationDate; |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Retrieve the user that created the associated object.
|
94 |
*
|
95 |
* @return the user that created the associated object
|
96 |
*/
|
97 |
public User getCreatedBy() {
|
98 |
return createdBy;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Modify the user that created the associated object.
|
103 |
*
|
104 |
* @param _createdBy the new user that created the associated object
|
105 |
*/
|
106 |
public void setCreatedBy(final User _createdBy) { |
107 |
createdBy = _createdBy; |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Retrieve the modification date for the associated object.
|
112 |
*
|
113 |
* @return the date of modification
|
114 |
*/
|
115 |
public Date getModificationDate() { |
116 |
return modificationDate;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* Modify the modification date for the associated object.
|
121 |
*
|
122 |
* @param _modificationDate the new date of modification
|
123 |
*/
|
124 |
public void setModificationDate(final Date _modificationDate) { |
125 |
modificationDate = _modificationDate; |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Retrieve the user that modified the associated object.
|
130 |
*
|
131 |
* @return the user that modified the associated object
|
132 |
*/
|
133 |
public User getModifiedBy() {
|
134 |
return modifiedBy;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Modify the user that modified the associated object.
|
139 |
*
|
140 |
* @param _modifiedBy the new user that modified the associated object
|
141 |
*/
|
142 |
public void setModifiedBy(final User _modifiedBy) { |
143 |
modifiedBy = _modifiedBy; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* Retrieve the Data Transfer Object for this audit info, that pays
|
148 |
* particular attention to avoid any instances of java.sql.Timestamp in the
|
149 |
* creation and modification dates.
|
150 |
*
|
151 |
* @return a DTO object with audit info
|
152 |
*/
|
153 |
public AuditInfoDTO getDTO() {
|
154 |
final AuditInfoDTO dto = new AuditInfoDTO(); |
155 |
dto.setCreatedBy(createdBy.getDTO()); |
156 |
dto.setCreationDate(new Date(creationDate.getTime())); |
157 |
dto.setModificationDate(new Date(modificationDate.getTime())); |
158 |
dto.setModifiedBy(modifiedBy.getDTO()); |
159 |
return dto;
|
160 |
} |
161 |
} |