2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.server.domain;
\r
21 import gr.ebs.gss.server.domain.dto.PermissionDTO;
\r
23 import java.io.Serializable;
\r
24 import java.util.Collection;
\r
26 import javax.persistence.Entity;
\r
27 import javax.persistence.GeneratedValue;
\r
28 import javax.persistence.Id;
\r
29 import javax.persistence.ManyToOne;
\r
30 import javax.persistence.Version;
\r
33 * Class representing a permission. A permission belongs to a Folder or
\r
34 * FileHeader on one side, and a User or GroupDefinition on the other. It is
\r
35 * actually a "group of permissions": <code>boolean</code>s represent each
\r
36 * individual permission.
\r
39 public class Permission implements Serializable {
\r
42 * Database id. Not to be set by user.
\r
49 * Database record version. Used by hibernate, not to be used by user.
\r
51 @SuppressWarnings("unused")
\r
53 private int version;
\r
56 * The user to whom this permission belongs, if it is a user permission.
\r
63 * The group to which this permission belongs, if it is a group permission.
\r
67 private Group group;
\r
72 private boolean read;
\r
77 private boolean write;
\r
80 * Modify ACL permission.
\r
82 private boolean modifyACL;
\r
87 * @return User The user
\r
89 public User getUser() {
\r
96 * @param _user User The user to set
\r
98 public void setUser(final User _user) {
\r
105 * @return Group The group
\r
107 public Group getGroup() {
\r
114 * @param _group Group The group to set
\r
116 public void setGroup(final Group _group) {
\r
121 * Get the Read permission.
\r
123 * @return boolean The Read permission
\r
125 public boolean getRead() {
\r
130 * Get the Read permission.
\r
132 * @return boolean The Read permission
\r
134 public boolean hasRead() {
\r
139 * Set the Read permission.
\r
141 * @param _read boolean The Read permission.
\r
143 public void setRead(final boolean _read) {
\r
148 * Get the Write permission.
\r
150 * @return boolean The Write permission
\r
152 public boolean getWrite() {
\r
157 * Get the Write permission.
\r
159 * @return boolean The Write permission
\r
161 public boolean hasWrite() {
\r
166 * Set the Write permission.
\r
168 * @param newWrite the new write permission
\r
170 public void setWrite(final boolean newWrite) {
\r
175 * Get the modify ACL permission.
\r
177 * @return boolean The modify ACL permission
\r
179 public boolean getModifyACL() {
\r
184 * Get the modify ACL permission.
\r
186 * @return boolean The modify ACL permission
\r
188 public boolean hasModifyACL() {
\r
193 * Set the modify ACL permission.
\r
195 * @param newModifyACL the new modify ACL permission
\r
197 public void setModifyACL(final boolean newModifyACL) {
\r
198 modifyACL = newModifyACL;
\r
201 // ********************** Business Methods ********************** //
\r
204 * Merge an initial Permission object with a collection of individual
\r
205 * permissions and produce an aggregate Permission object. Aggregate object
\r
206 * has a permission if at least one of the individual objects has said
\r
209 * @param initialPermission Permission The initial Permission object
\r
210 * @param permissions Collection Permissions with which to merge
\r
211 * @return Permission Aggregate permission object
\r
213 private Permission mergePermissions(final Permission initialPermission, final Collection<Permission> permissions) {
\r
214 if (permissions != null)
\r
215 for (final Permission perm : permissions) {
\r
216 initialPermission.setRead(initialPermission.hasRead() || perm.hasRead());
\r
217 initialPermission.setWrite(initialPermission.hasWrite() || perm.hasWrite());
\r
218 initialPermission.setModifyACL(initialPermission.hasModifyACL() || perm.hasModifyACL());
\r
220 return initialPermission;
\r
224 * Merge with a collection of individual permissions and produce an
\r
225 * aggregate Permission object. Aggregate object has a permission if at
\r
226 * least one of the individual objects has said permission.
\r
228 * @param permissions Collection Permissions with which to merge
\r
229 * @return Permission Aggregate permission object
\r
231 public Permission mergePermissions(final Collection<Permission> permissions) {
\r
232 return mergePermissions(this, permissions);
\r
236 * Return a new Data Transfer Object for this object.
\r
238 * @return a new DTO with the same contents as this object
\r
240 public PermissionDTO getDTO() {
\r
241 final PermissionDTO p = new PermissionDTO();
\r
244 p.setGroup(group.getDTO());
\r
246 p.setUser(user.getDTO());
\r
249 p.setModifyACL(modifyACL);
\r