1 package org.manentia.kasai; 2 3 import java.sql.ResultSet ; 4 import java.sql.SQLException ; 5 import java.util.ArrayList ; 6 import java.util.Collection ; 7 import java.util.logging.Level ; 8 9 import org.manentia.kasai.util.Constants; 10 import org.manentia.kasai.exceptions.InvalidAttributesException; 11 12 import com.koala.commons.log.Log; 13 14 15 20 public class Role{ 21 22 private int id; 23 24 private String name; 25 26 private String description; 27 28 private Collection operatives; 29 30 private Collection objectsUsersRoles; 31 32 private Collection objectsGroupsRoles; 33 34 public Role() { 35 operatives = new ArrayList (); 36 objectsUsersRoles = new ArrayList (); 37 objectsGroupsRoles = new ArrayList (); 38 } 39 40 public Role (ResultSet rs) throws SQLException { 41 id = rs.getInt("id"); 42 name = rs.getString ("name"); 43 description = rs.getString("description"); 44 operatives = new ArrayList (); 45 objectsUsersRoles = new ArrayList (); 46 objectsGroupsRoles = new ArrayList (); 47 48 } 49 50 public int getId() { 51 return this.id; 52 } 53 54 public void setId(int id) { 55 this.id = id; 56 } 57 58 public String getName() { 59 return this.name; 60 } 61 62 public void setName(String name) { 63 this.name = name; 64 } 65 66 public String getDescription() { 67 return this.description; 68 } 69 70 public void setDescription(String description) { 71 this.description = description; 72 } 73 74 public Collection getOperatives() { 75 return operatives; 76 } 77 78 public void setOperatives(Collection operatives) { 79 this.operatives = operatives; 80 } 81 82 public void addOperative(Operative operative) { 83 if (operative != null) { 84 if(!operatives.contains(operative)){ 85 this.operatives.add(operative); 86 } 87 } 88 } 89 90 public void removeOperative (Operative operative){ 91 if (operative != null){ 92 this.operatives.remove(operative); 93 } 94 } 95 96 public Collection getObjectsGroupsRoles(){ 97 return objectsGroupsRoles; 98 } 99 100 public void setObjectsGroupsRoles(Collection objectGroupRole){ 101 this.objectsGroupsRoles = objectGroupRole; 102 } 103 104 public void addObjectGroupRole(ObjectGroupRole objectGroupRole) { 105 if (objectGroupRole != null) { 106 if(!objectsGroupsRoles.contains(objectGroupRole)){ 107 this.objectsGroupsRoles.add(objectGroupRole); 108 } 109 } 110 } 111 112 public void removeObjectGroupRole (ObjectGroupRole objectGroupRole){ 113 if (objectGroupRole != null){ 114 this.objectsGroupsRoles.remove(objectGroupRole); 115 } 116 } 117 118 public Collection getObjectsUsersRoles(){ 119 return objectsUsersRoles; 120 } 121 122 public void setObjectsUsersRoles(Collection objectUserRole){ 123 this.objectsUsersRoles = objectUserRole; 124 } 125 126 public void addObjectUserRole(ObjectUserRole objectUserRole) { 127 if (objectUserRole != null) { 128 if(!objectsUsersRoles.contains(objectUserRole)){ 129 this.objectsUsersRoles.add(objectUserRole); 130 } 131 } 132 } 133 134 public void removeObjectUserRole (ObjectUserRole objectUserRole){ 135 if (objectUserRole != null){ 136 this.objectsUsersRoles.remove(objectUserRole); 137 } 138 } 139 140 public void validate() throws InvalidAttributesException{ 141 142 Log.getInstance(Constants.PROPERTY_FILE).write(Role.class.getName(),"validate","Enter",Level.INFO); 143 144 if ((this.getName() == null) || (this.getName().length()==0)){ 145 Log.getInstance(Constants.PROPERTY_FILE).write(Role.class.getName(), "validate","Name was not specified",Level.WARNING); 146 throw new InvalidAttributesException(Role.class.getName() + ".emptyName"); 147 } 148 149 Log.getInstance(Constants.PROPERTY_FILE).write(Role.class.getName(),"validate","Exit",Level.INFO); 150 } 151 152 public boolean equals (java.lang.Object obj){ 153 boolean result = false; 154 155 try{ 156 if (obj instanceof Role){ 157 if (((Role)obj).getId() == this.id){ 158 result = true; 159 } 160 } 161 } 162 catch (Exception e){ 163 result = false; 164 } 165 return result; 166 } 167 } 168 | Popular Tags |