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;
33 * A file tag. This is basically a many-to-many relationship between User and
34 * FileHeader, with an extra string which is the tag. For implementation
35 * details, see Java Persistence With Hibernate, p. 303.
40 public class FileTag implements Serializable{
43 * The composite ID of the object.
46 public static class FileTagId implements Serializable {
51 private static final long serialVersionUID = 1L;
56 @Column(name = "userId")
60 * The ID of the file header.
62 @Column(name = "fileId")
72 public boolean equals(final Object o) {
73 if (o != null && o instanceof FileTagId) {
74 final FileTagId that = (FileTagId) o;
75 return userId.equals(that.userId) && fileId.equals(that.fileId) && tag.equals(that.tag);
81 public int hashCode() {
82 return userId.hashCode() + fileId.hashCode() + tag.hashCode();
87 * Database id. Not to be set by user.
93 * No version field: immutable object.
97 * The audit information.
99 @SuppressWarnings("unused")
101 private AuditInfo auditInfo;
104 * The user who added this tag.
107 @JoinColumn(name = "userId", nullable = false, insertable=false, updatable=false)
111 * The file to which this tag belongs.
113 @ManyToOne(optional = true)
114 @JoinColumn(name = "fileId", nullable = false, insertable=false, updatable=false)
115 private FileHeader file;
118 * The name of the tag.
120 @Column(nullable=false, insertable=false, updatable=false)
124 * A default constructor.
131 * The proper constructor to call, which guarantees referential integrity.
133 * @param aUser The user who adds the tag
134 * @param aFile The file to which the tag is added
135 * @param aTag The tag itself
137 public FileTag(final User aUser, final FileHeader aFile, final String aTag) {
143 // Set identifier values
144 id = new FileTagId();
145 id.userId = aUser.getId();
146 id.fileId = aFile.getId();
149 // Guarantee referential integrity
150 aUser.getFileTags().add(this);
151 aFile.getFileTags().add(this);
153 final AuditInfo ai = new AuditInfo();
154 ai.setCreatedBy(aUser);
155 ai.setModifiedBy(aUser);
156 final Date now = new Date();
157 ai.setCreationDate(now);
158 ai.setModificationDate(now);
163 * Retrieve the FileTagId.
167 public FileTagId getId() {
176 public User getUser() {
181 * Retrieve the file header.
183 * @return the fileheader
185 public FileHeader getFile() {
190 * Retrieve the actual tag content.
194 public String getTag() {
199 * Modify the audit info.
201 * @param newAuditInfo the new audit info
203 public void setAuditInfo(final AuditInfo newAuditInfo) {
204 auditInfo = newAuditInfo;
211 * @param newUser the user to set
213 public void setUser(User newUser) {
221 * @param newFile the file to set
223 public void setFile(FileHeader newFile) {