2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.server.domain;
21 import java.io.Serializable;
22 import java.util.Date;
24 import javax.persistence.Column;
25 import javax.persistence.Embeddable;
26 import javax.persistence.Embedded;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.ManyToOne;
32 import org.hibernate.annotations.Cache;
33 import org.hibernate.annotations.CacheConcurrencyStrategy;
36 * A file tag. This is basically a many-to-many relationship between User and
37 * FileHeader, with an extra string which is the tag. For implementation
38 * details, see Java Persistence With Hibernate, p. 303.
43 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
44 public class FileTag implements Serializable{
47 * The composite ID of the object.
50 public static class FileTagId implements Serializable {
55 private static final long serialVersionUID = 1L;
60 @Column(name = "userId")
64 * The ID of the file header.
66 @Column(name = "fileId")
76 public boolean equals(final Object o) {
77 if (o != null && o instanceof FileTagId) {
78 final FileTagId that = (FileTagId) o;
79 return userId.equals(that.userId) && fileId.equals(that.fileId) && tag.equals(that.tag);
85 public int hashCode() {
86 return userId.hashCode() + fileId.hashCode() + tag.hashCode();
91 * Database id. Not to be set by user.
97 * No version field: immutable object.
101 * The audit information.
103 @SuppressWarnings("unused")
105 private AuditInfo auditInfo;
108 * The user who added this tag.
111 @JoinColumn(name = "userId", nullable = false, insertable=false, updatable=false)
115 * The file to which this tag belongs.
117 @ManyToOne(optional = true)
118 @JoinColumn(name = "fileId", nullable = false, insertable=false, updatable=false)
119 private FileHeader file;
122 * The name of the tag.
124 @Column(nullable=false, insertable=false, updatable=false)
128 * A default constructor.
135 * The proper constructor to call, which guarantees referential integrity.
137 * @param aUser The user who adds the tag
138 * @param aFile The file to which the tag is added
139 * @param aTag The tag itself
141 public FileTag(final User aUser, final FileHeader aFile, final String aTag) {
147 // Set identifier values
148 id = new FileTagId();
149 id.userId = aUser.getId();
150 id.fileId = aFile.getId();
153 // Guarantee referential integrity
154 aUser.getFileTags().add(this);
155 aFile.getFileTags().add(this);
157 final AuditInfo ai = new AuditInfo();
158 ai.setCreatedBy(aUser);
159 ai.setModifiedBy(aUser);
160 final Date now = new Date();
161 ai.setCreationDate(now);
162 ai.setModificationDate(now);
167 * Retrieve the FileTagId.
171 public FileTagId getId() {
180 public User getUser() {
185 * Retrieve the file header.
187 * @return the fileheader
189 public FileHeader getFile() {
194 * Retrieve the actual tag content.
198 public String getTag() {
203 * Modify the audit info.
205 * @param newAuditInfo the new audit info
207 public void setAuditInfo(final AuditInfo newAuditInfo) {
208 auditInfo = newAuditInfo;
215 * @param newUser the user to set
217 public void setUser(User newUser) {
225 * @param newFile the file to set
227 public void setFile(FileHeader newFile) {