Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
14   140   12   1.27
2   51   0.86   5.5
11     1.09  
2    
 
 
  Permission       Line # 33 13 11 0% 0.0
  Permission.PermissionPropertiesComparator       Line # 135 1 1 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.model;
20   
21    import org.apache.commons.lang.builder.CompareToBuilder;
22    import org.apache.commons.lang.builder.ToStringBuilder;
23   
24    /**
25    * A user permission on a project.
26    *
27    * <p>
28    * The permission type tells what kind of action the user is allowed perform.
29    * </p>
30    *
31    * @author ready
32    */
 
33    public class Permission extends AbstractEntity {
34   
35    /**
36    * Comparator for comparing the main properties type, user, project
37    */
38    public static final PermissionPropertiesComparator PERMISSION_PROPERTIES_COMPARATOR = new PermissionPropertiesComparator();
39    /**
40    *
41    */
42    private static final long serialVersionUID = 1L;
43   
44    /**
45    * The type of permission granted. TODO: use PermissionType enum
46    */
47    private Integer type;
48   
49    /**
50    * The project on which this permission is granted. May be <tt>null</tt>
51    * to indicate the permission is granted on all projects.
52    */
53    private Project project;
54   
55    /** The user who's granted this permission. */
56    private User user;
57   
58    /**
59    * Default constructor (required by Hibernate).
60    *
61    * <p>
62    * PENDING: should be <code>private</code> so that it can only be used by
63    * Hibernate, to ensure that the fields which form an instance's identity
64    * are always initialized/never <tt>null</tt>.
65    * </p>
66    */
 
67  0 toggle public Permission() {
68    }
69   
70    /**
71    * Grants permissions on all projects to the given user.
72    *
73    * @param type
74    * permission type
75    * @param user
76    * grantee
77    */
 
78  0 toggle public Permission(Integer type, User user) {
79  0 this(type, user, null);
80    }
81   
82    /**
83    * Grants permissions on all projects to the given user.
84    *
85    * @param type
86    * permission type
87    * @param user
88    * grantee
89    * @param project
90    * on which permission is granted, or <tt>null</tt> for all
91    * projects
92    */
 
93  0 toggle public Permission(Integer type, User user, Project project) {
94  0 setPermissionType(type);
95  0 setUser(user);
96  0 setProject(project);
97    }
98   
 
99  0 toggle public Integer getPermissionType() {
100  0 return type;
101    }
102   
 
103  0 toggle public void setPermissionType(Integer type) {
104  0 this.type = type;
105    }
106   
 
107  0 toggle public User getUser() {
108  0 return user;
109    }
110   
 
111  0 toggle public void setUser(User user) {
112  0 if (user == null) {
113  0 throw new IllegalArgumentException("null user");
114    }
115  0 this.user = user;
116    }
117   
 
118  0 toggle public Project getProject() {
119  0 return project;
120    }
121   
122    /** May be null to indicate a permission on all projects. */
 
123  0 toggle public void setProject(Project project) {
124  0 this.project = project;
125    }
126   
127   
 
128  0 toggle @Override
129    public String toString() {
130  0 return new ToStringBuilder(this).append("id", getId()).append("type", getPermissionType())
131    .append("user", getUser()).append("project", getProject()).toString();
132    }
133   
134   
 
135    public static final class PermissionPropertiesComparator implements java.util.Comparator<Permission> {
 
136  0 toggle public int compare(Permission lhs, Permission rhs) {
137  0 return new CompareToBuilder().append(lhs.type, rhs.type).append(lhs.user, rhs.user, User.NAME_COMPARATOR).append(lhs.project, rhs.project, Project.PROJECT_COMPARATOR).toComparison();
138    }
139    }
140    }