001: package org.theospi.portfolio.shared.model;
002:
003: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
004: import org.sakaiproject.metaobj.shared.model.Artifact;
005: import org.sakaiproject.metaobj.shared.model.Id;
006: import org.sakaiproject.metaobj.shared.model.StructuredArtifact;
007:
008: import java.util.ArrayList;
009: import java.util.List;
010:
011: /**
012: * Created by IntelliJ IDEA.
013: * User: bbiltimier
014: * Date: Apr 18, 2006
015: * Time: 3:46:01 PM
016: * To change this template use File | Settings | File Templates.
017: */
018: public class AgentImplOsp implements
019: org.sakaiproject.metaobj.shared.model.Agent {
020: static public final String ID = "id";
021: static public final String REAL_NAME = "realName";
022: static public final String EMAIL = "email";
023: static public final String ROLES = "roles";
024:
025: private Id id;
026: private Id eid;
027: private StructuredArtifact profile;
028: private String[] roles;
029: private HomeFactory homeFactory;
030: private String displayName;
031: private String md5Password;
032: private String password;
033: private String role;
034: private boolean initialized = false;
035:
036: public AgentImplOsp() {
037:
038: }
039:
040: public AgentImplOsp(Id id) {
041: this .id = id;
042: }
043:
044: public AgentImplOsp(StructuredArtifact profile) {
045: this .profile = profile;
046: }
047:
048: public Id getId() {
049: return id;
050: }
051:
052: public void setId(Id id) {
053: this .id = id;
054: }
055:
056: public Id getEid() {
057: return eid;
058: }
059:
060: public void setEid(Id eid) {
061: this .eid = eid;
062: }
063:
064: public Artifact getProfile() {
065: return profile;
066: }
067:
068: public void setProfile(StructuredArtifact profile) {
069: this .profile = profile;
070: }
071:
072: public Object getProperty(String key) {
073: return profile.get(key);
074: }
075:
076: public String getDisplayName() {
077: return displayName;
078: }
079:
080: public boolean isInRole(String role) {
081:
082: for (int i = 0; i < getRoles().length; i++) {
083: if (role.equals(getRoles()[i])) {
084: return true;
085: }
086: }
087:
088: return false;
089: }
090:
091: public boolean isInitialized() {
092: return initialized;
093: }
094:
095: public void setInitialized(boolean initialized) {
096: this .initialized = initialized;
097: }
098:
099: public void setDisplayName(String displayName) {
100: this .displayName = displayName;
101: }
102:
103: /**
104: * I imagine this will probably move into a authz call and out of here
105: *
106: * @return
107: */
108: public String[] getRoles() {
109: /* if (roles == null) {
110: //TODO implement for multiple roles
111: roles = new String[1];
112: roles[0] = (String) profile.get("role");
113: }
114: */
115: roles = new String[1];
116: roles[0] = role;
117:
118: return roles;
119: }
120:
121: public void setRoles(String[] roles) {
122: this .roles = roles;
123: }
124:
125: public HomeFactory getHomeFactory() {
126: return homeFactory;
127: }
128:
129: public void setHomeFactory(HomeFactory homeFactory) {
130: this .homeFactory = homeFactory;
131: }
132:
133: public String getPassword() {
134: return password;
135: }
136:
137: public String getClearPassword() {
138: return password;
139: }
140:
141: public void setPassword(String password) {
142: this .password = password;
143: }
144:
145: public String getMd5Password() {
146: return md5Password;
147: }
148:
149: public void setMd5Password(String md5Password) {
150: this .md5Password = md5Password;
151: }
152:
153: public String getRole() {
154: return role;
155: }
156:
157: public List getWorksiteRoles(String worksiteId) {
158: return new ArrayList();
159: }
160:
161: public List getWorksiteRoles() {
162: return new ArrayList();
163: }
164:
165: public boolean isRole() {
166: return false;
167: }
168:
169: public void setRole(String role) {
170: this .role = role;
171: }
172:
173: public String naturalKey() {
174: return "" + displayName;
175: }
176:
177: public boolean equals(Object o) {
178: if (this == o) {
179: return true;
180: }
181: if (!(o instanceof org.theospi.portfolio.shared.model.AgentImplOsp)) {
182: return false;
183: }
184:
185: final org.theospi.portfolio.shared.model.AgentImplOsp agent = (org.theospi.portfolio.shared.model.AgentImplOsp) o;
186: return naturalKey().equals(agent.naturalKey());
187: }
188:
189: public int hashCode() {
190: return naturalKey().hashCode();
191: }
192:
193: /**
194: * Returns the name of this principal.
195: *
196: * @return the name of this principal.
197: */
198: public String getName() {
199: return getDisplayName();
200: }
201:
202: }
|