001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.roles;
017
018 import java.sql.Date;
019
020 import org.kuali.hr.core.KPMEConstants;
021 import org.kuali.hr.location.Location;
022 import org.kuali.hr.time.HrBusinessObject;
023 import org.kuali.hr.time.department.Department;
024 import org.kuali.hr.time.position.Position;
025 import org.kuali.hr.time.service.base.TkServiceLocator;
026 import org.kuali.hr.time.util.TKUtils;
027 import org.kuali.hr.time.workarea.WorkArea;
028 import org.kuali.kfs.coa.businessobject.Chart;
029 import org.kuali.rice.kim.api.identity.Person;
030 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
031
032 public class TkRole extends HrBusinessObject {
033
034 private static final long serialVersionUID = -2123815189941339343L;
035
036 public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "TkRole";
037
038 private String hrRolesId;
039 private String principalId;
040 private String roleName;
041 private String userPrincipalId;
042 private Long workArea;
043 private String department;
044 private String chart;
045 private Long hrDeptId;
046 private String positionNumber;
047 private Date expirationDate;
048
049 /**
050 * These objects are used by Lookups to provide links on the maintenance
051 * page. They are not necessarily going to be populated.
052 */
053 private Person person;
054 private Department departmentObj;
055 private WorkArea workAreaObj;
056 private Chart chartObj;
057 private Position positionObj;
058
059 private Location locationObj;
060
061 public Chart getChartObj() {
062 return chartObj;
063 }
064
065 public void setChartObj(Chart chartObj) {
066 this.chartObj = chartObj;
067 }
068
069 public Department getDepartmentObj() {
070 return departmentObj;
071 }
072
073 public void setDepartmentObj(Department departmentObj) {
074 this.departmentObj = departmentObj;
075 if (departmentObj != null) {
076 this.department = departmentObj.getDept();
077 this.workAreaObj= null;
078 this.workArea = null;
079 }
080 }
081
082 public WorkArea getWorkAreaObj() {
083 return workAreaObj;
084 }
085
086 public void setWorkAreaObj(WorkArea workAreaObj) {
087 this.workAreaObj = workAreaObj;
088 if (workAreaObj != null) {
089 this.workArea = workAreaObj.getWorkArea();
090 this.departmentObj = TkServiceLocator.getDepartmentService().getDepartment(workAreaObj.getDept(), TKUtils.getCurrentDate());
091 this.department = workAreaObj.getDept();
092 }
093 }
094
095 public String getHrRolesId() {
096 return hrRolesId;
097 }
098
099 public void setHrRolesId(String hrRolesId) {
100 this.hrRolesId = hrRolesId;
101 }
102
103 public String getPrincipalId() {
104 return principalId;
105 }
106
107 public void setPrincipalId(String principalId) {
108 this.principalId = principalId;
109 setPerson(KimApiServiceLocator.getPersonService().getPerson(this.principalId));
110 }
111
112 public String getRoleName() {
113 return roleName;
114 }
115
116 public void setRoleName(String roleName) {
117 this.roleName = roleName;
118 }
119
120 public String getUserPrincipalId() {
121 return userPrincipalId;
122 }
123
124 public void setUserPrincipalId(String userPrincipalId) {
125 this.userPrincipalId = userPrincipalId;
126 }
127
128 public Long getWorkArea() {
129 return workArea;
130 }
131
132 public void setWorkArea(Long workArea) {
133 this.workArea = workArea;
134 }
135
136 public String getDepartment() {
137 return department;
138 }
139
140 public void setDepartment(String department) {
141 this.department = department;
142 }
143
144 public Person getPerson() {
145 return person;
146 }
147
148 public void setPerson(Person person) {
149 this.person = person;
150 }
151
152 public Long getHrDeptId() {
153 return hrDeptId;
154 }
155
156 public void setHrDeptId(Long hrDeptId) {
157 this.hrDeptId = hrDeptId;
158 }
159
160 public String getChart() {
161 return chart;
162 }
163
164 public void setChart(String chart) {
165 this.chart = chart;
166 }
167
168 /**
169 * This method supports maintenance and lookup pages.
170 */
171 public String getUserName() {
172 if (person == null) {
173 person = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
174 }
175
176 return (person != null) ? person.getName() : "";
177 }
178
179 public void setPositionNumber(String positionNumber) {
180 this.positionNumber = positionNumber;
181 }
182
183 public String getPositionNumber() {
184 return positionNumber;
185 }
186
187 public Date getExpirationDate() {
188 return expirationDate;
189 }
190
191 public void setExpirationDate(Date expirationDate) {
192 this.expirationDate = expirationDate;
193 }
194
195 public void setPositionObj(Position positionObj) {
196 this.positionObj = positionObj;
197 }
198
199 public Position getPositionObj() {
200 return positionObj;
201 }
202
203 @Override
204 public String getUniqueKey() {
205 return principalId + "_" + positionNumber != null ? positionNumber.toString() : "" +"_"+
206 roleName + "_" + workArea != null ? workArea.toString() : "" + "_" +
207 department + "_" + chart;
208 }
209
210 @Override
211 public String getId() {
212 return getHrRolesId();
213 }
214
215 @Override
216 public void setId(String id) {
217 setHrRolesId(id);
218 }
219
220 public Location getLocationObj() {
221 return locationObj;
222 }
223
224 public void setLocationObj(Location locationObj) {
225 this.locationObj = locationObj;
226 }
227
228 @Override
229 public boolean equals(Object o) {
230 if (this == o) return true;
231 if (o == null || getClass() != o.getClass()) return false;
232
233 TkRole tkRole = (TkRole) o;
234
235 if (chart != null ? !chart.equals(tkRole.chart) : tkRole.chart != null) return false;
236 if (chartObj != null ? !chartObj.equals(tkRole.chartObj) : tkRole.chartObj != null) return false;
237 if (department != null ? !department.equals(tkRole.department) : tkRole.department != null) return false;
238 if (departmentObj != null ? !departmentObj.equals(tkRole.departmentObj) : tkRole.departmentObj != null)
239 return false;
240 if (expirationDate != null ? !expirationDate.equals(tkRole.expirationDate) : tkRole.expirationDate != null)
241 return false;
242 if (hrDeptId != null ? !hrDeptId.equals(tkRole.hrDeptId) : tkRole.hrDeptId != null) return false;
243 if (!hrRolesId.equals(tkRole.hrRolesId)) return false;
244 if (locationObj != null ? !locationObj.equals(tkRole.locationObj) : tkRole.locationObj != null) return false;
245 if (person != null ? !person.equals(tkRole.person) : tkRole.person != null) return false;
246 if (positionNumber != null ? !positionNumber.equals(tkRole.positionNumber) : tkRole.positionNumber != null)
247 return false;
248 if (positionObj != null ? !positionObj.equals(tkRole.positionObj) : tkRole.positionObj != null) return false;
249 if (principalId != null ? !principalId.equals(tkRole.principalId) : tkRole.principalId != null) return false;
250 if (roleName != null ? !roleName.equals(tkRole.roleName) : tkRole.roleName != null) return false;
251 if (userPrincipalId != null ? !userPrincipalId.equals(tkRole.userPrincipalId) : tkRole.userPrincipalId != null)
252 return false;
253 if (workArea != null ? !workArea.equals(tkRole.workArea) : tkRole.workArea != null) return false;
254 if (workAreaObj != null ? !workAreaObj.equals(tkRole.workAreaObj) : tkRole.workAreaObj != null) return false;
255
256 return true;
257 }
258 }