1 16 17 package info.jtrac.domain; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.HashSet ; 22 import java.util.Set ; 23 import org.acegisecurity.GrantedAuthority; 24 25 34 public class UserSpaceRole implements GrantedAuthority, Serializable { 35 36 private long id; 37 private User user; 38 private Space space; 39 private String roleKey; 40 41 public UserSpaceRole() { 42 } 44 45 public UserSpaceRole(User user, Space space, String roleKey) { 46 this.user = user; 47 this.space = space; 48 this.roleKey = roleKey; 49 } 50 51 public boolean isAbleToCreateNewItem() { 52 if (space == null) { 53 return false; 54 } 55 return user.getPermittedTransitions(space, State.NEW).size() > 0; 56 } 57 58 60 public String getAuthority() { 61 if (space != null) { 62 return roleKey + "_" + space.getPrefixCode(); 63 } 64 return roleKey; 65 } 66 67 69 public User getUser() { 70 return user; 71 } 72 73 public void setUser(User user) { 74 this.user = user; 75 } 76 77 public String getRoleKey() { 78 return roleKey; 79 } 80 81 public void setRoleKey(String roleKey) { 82 this.roleKey = roleKey; 83 } 84 85 public Space getSpace() { 86 return space; 87 } 88 89 public void setSpace(Space space) { 90 this.space = space; 91 } 92 93 public long getId() { 94 return id; 95 } 96 97 public void setId(long id) { 98 this.id = id; 99 } 100 101 @Override 102 public boolean equals(Object o) { 103 if (this == o) { 104 return true; 105 } 106 if (!(o instanceof UserSpaceRole)) { 107 return false; 108 } 109 final UserSpaceRole usr = (UserSpaceRole) o; 110 return (space == usr.getSpace() || space.equals(usr.getSpace()) 111 && user.equals(usr.getUser()) 112 && roleKey.equals(usr.getRoleKey())); 113 } 114 115 @Override 116 public int hashCode() { 117 int hash = 7; 118 hash = hash * 31 + user.hashCode(); 119 hash = hash * 31 + (space == null ? 0 : space.hashCode()); 120 hash = hash * 31 + roleKey.hashCode(); 121 return hash; 122 } 123 124 @Override 125 public String toString() { 126 return getAuthority(); 127 } 128 129 } 130 | Popular Tags |