001: package org.manentia.kasai;
002:
003: import java.io.Serializable;
004: import java.sql.ResultSet;
005: import java.sql.SQLException;
006: import java.util.ArrayList;
007: import java.util.Collection;
008:
009: import org.apache.commons.lang.StringUtils;
010: import org.manentia.kasai.exceptions.InvalidAttributesException;
011:
012: import com.manentia.commons.log.Log;
013:
014: /**
015: *
016: * @author fpena
017: *
018: */
019: public class Role implements Serializable {
020:
021: /**
022: *
023: */
024: private static final long serialVersionUID = 3282853957984740860L;
025:
026: private int id;
027:
028: private String name;
029:
030: private String description;
031:
032: private Collection operatives;
033:
034: private Collection objectsUsersRoles;
035:
036: private Collection objectsGroupsRoles;
037:
038: public Role() {
039: operatives = new ArrayList();
040: objectsUsersRoles = new ArrayList();
041: objectsGroupsRoles = new ArrayList();
042: }
043:
044: public Role(ResultSet rs) throws SQLException {
045: id = rs.getInt("id");
046: name = rs.getString("name");
047: description = rs.getString("description");
048: operatives = new ArrayList();
049: objectsUsersRoles = new ArrayList();
050: objectsGroupsRoles = new ArrayList();
051:
052: }
053:
054: public int getId() {
055: return this .id;
056: }
057:
058: public void setId(int id) {
059: this .id = id;
060: }
061:
062: public String getName() {
063: return this .name;
064: }
065:
066: public void setName(String name) {
067: this .name = name;
068: }
069:
070: public String getDescription() {
071: return this .description;
072: }
073:
074: public void setDescription(String description) {
075: this .description = description;
076: }
077:
078: public Collection getOperatives() {
079: return operatives;
080: }
081:
082: public void setOperatives(Collection operatives) {
083: this .operatives = operatives;
084: }
085:
086: public void addOperative(Operative operative) {
087: if (operative != null) {
088: if (!operatives.contains(operative)) {
089: this .operatives.add(operative);
090: }
091: }
092: }
093:
094: public void removeOperative(Operative operative) {
095: if (operative != null) {
096: this .operatives.remove(operative);
097: }
098: }
099:
100: public Collection getObjectsGroupsRoles() {
101: return objectsGroupsRoles;
102: }
103:
104: public void setObjectsGroupsRoles(Collection objectGroupRole) {
105: this .objectsGroupsRoles = objectGroupRole;
106: }
107:
108: public void addObjectGroupRole(ObjectGroupRole objectGroupRole) {
109: if (objectGroupRole != null) {
110: if (!objectsGroupsRoles.contains(objectGroupRole)) {
111: this .objectsGroupsRoles.add(objectGroupRole);
112: }
113: }
114: }
115:
116: public void removeObjectGroupRole(ObjectGroupRole objectGroupRole) {
117: if (objectGroupRole != null) {
118: this .objectsGroupsRoles.remove(objectGroupRole);
119: }
120: }
121:
122: public Collection getObjectsUsersRoles() {
123: return objectsUsersRoles;
124: }
125:
126: public void setObjectsUsersRoles(Collection objectUserRole) {
127: this .objectsUsersRoles = objectUserRole;
128: }
129:
130: public void addObjectUserRole(ObjectUserRole objectUserRole) {
131: if (objectUserRole != null) {
132: if (!objectsUsersRoles.contains(objectUserRole)) {
133: this .objectsUsersRoles.add(objectUserRole);
134: }
135: }
136: }
137:
138: public String getDescriptionPrefix() {
139: String result = StringUtils.defaultString(description);
140:
141: if (result.length() > 60) {
142: result = result.substring(0, 57) + "...";
143: }
144:
145: return result;
146: }
147:
148: public String getObjectId() {
149: return "/kasai/role/" + this .getId();
150: }
151:
152: public void removeObjectUserRole(ObjectUserRole objectUserRole) {
153: if (objectUserRole != null) {
154: this .objectsUsersRoles.remove(objectUserRole);
155: }
156: }
157:
158: public void validate() throws InvalidAttributesException {
159:
160: Log.write("Enter", Log.INFO, "validate", Role.class);
161:
162: if ((this .getName() == null) || (this .getName().length() == 0)) {
163: Log.write("Name was not specified", Log.WARN, "validate",
164: Role.class);
165:
166: throw new InvalidAttributesException(Role.class.getName()
167: + ".emptyName");
168: }
169:
170: Log.write("Exit", Log.INFO, "validate", Role.class);
171: }
172:
173: public boolean equals(java.lang.Object obj) {
174: boolean result = false;
175:
176: try {
177: if (obj instanceof Role) {
178: if (((Role) obj).getId() == this .id) {
179: result = true;
180: }
181: }
182: } catch (Exception e) {
183: result = false;
184: }
185: return result;
186: }
187: }
|